dhcp.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local ipc = require "luci.ip"
  4. m = Map("dhcp", translate("DHCP and DNS"),
  5. translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" ..
  6. "\">DHCP</abbr>-Server and <abbr title=\"Domain Name System\">DNS</abbr>-" ..
  7. "Forwarder for <abbr title=\"Network Address Translation\">NAT</abbr> " ..
  8. "firewalls"))
  9. s = m:section(TypedSection, "dnsmasq", translate("Server Settings"))
  10. s.anonymous = true
  11. s.addremove = false
  12. s:tab("general", translate("General Settings"))
  13. s:tab("files", translate("Resolv and Hosts Files"))
  14. s:tab("tftp", translate("TFTP Settings"))
  15. s:tab("advanced", translate("Advanced Settings"))
  16. s:taboption("general", Flag, "domainneeded",
  17. translate("Domain required"),
  18. translate("Don't forward <abbr title=\"Domain Name System\">DNS</abbr>-Requests without " ..
  19. "<abbr title=\"Domain Name System\">DNS</abbr>-Name"))
  20. s:taboption("general", Flag, "authoritative",
  21. translate("Authoritative"),
  22. translate("This is the only <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
  23. "abbr> in the local network"))
  24. s:taboption("files", Flag, "readethers",
  25. translate("Use <code>/etc/ethers</code>"),
  26. translate("Read <code>/etc/ethers</code> to configure the <abbr title=\"Dynamic Host " ..
  27. "Configuration Protocol\">DHCP</abbr>-Server"))
  28. s:taboption("files", Value, "leasefile",
  29. translate("Leasefile"),
  30. translate("file where given <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
  31. "abbr>-leases will be stored"))
  32. s:taboption("files", Flag, "noresolv",
  33. translate("Ignore resolve file")).optional = true
  34. rf = s:taboption("files", Value, "resolvfile",
  35. translate("Resolve file"),
  36. translate("local <abbr title=\"Domain Name System\">DNS</abbr> file"))
  37. rf:depends("noresolv", "")
  38. rf.optional = true
  39. s:taboption("files", Flag, "nohosts",
  40. translate("Ignore <code>/etc/hosts</code>")).optional = true
  41. s:taboption("files", DynamicList, "addnhosts",
  42. translate("Additional Hosts files")).optional = true
  43. s:taboption("advanced", Flag, "boguspriv",
  44. translate("Filter private"),
  45. translate("Do not forward reverse lookups for local networks"))
  46. s:taboption("advanced", Flag, "filterwin2k",
  47. translate("Filter useless"),
  48. translate("Do not forward requests that cannot be answered by public name servers"))
  49. s:taboption("advanced", Flag, "localise_queries",
  50. translate("Localise queries"),
  51. translate("Localise hostname depending on the requesting subnet if multiple IPs are available"))
  52. s:taboption("general", Value, "local",
  53. translate("Local server"),
  54. translate("Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only"))
  55. s:taboption("general", Value, "domain",
  56. translate("Local domain"),
  57. translate("Local domain suffix appended to DHCP names and hosts file entries"))
  58. s:taboption("advanced", Flag, "expandhosts",
  59. translate("Expand hosts"),
  60. translate("Add local domain suffix to names served from hosts files"))
  61. s:taboption("advanced", Flag, "nonegcache",
  62. translate("No negative cache"),
  63. translate("Do not cache negative replies, e.g. for not existing domains"))
  64. s:taboption("advanced", Flag, "strictorder",
  65. translate("Strict order"),
  66. translate("<abbr title=\"Domain Name System\">DNS</abbr> servers will be queried in the " ..
  67. "order of the resolvfile")).optional = true
  68. bn = s:taboption("advanced", DynamicList, "bogusnxdomain", translate("Bogus NX Domain Override"),
  69. translate("List of hosts that supply bogus NX domain results"))
  70. bn.optional = true
  71. bn.placeholder = "67.215.65.132"
  72. s:taboption("general", Flag, "logqueries",
  73. translate("Log queries"),
  74. translate("Write received DNS requests to syslog")).optional = true
  75. df = s:taboption("general", DynamicList, "server", translate("DNS forwardings"),
  76. translate("List of <abbr title=\"Domain Name System\">DNS</abbr> " ..
  77. "servers to forward requests to"))
  78. df.optional = true
  79. df.placeholder = "/example.org/10.1.2.3"
  80. rp = s:taboption("general", Flag, "rebind_protection",
  81. translate("Rebind protection"),
  82. translate("Discard upstream RFC1918 responses"))
  83. rp.rmempty = false
  84. rl = s:taboption("general", Flag, "rebind_localhost",
  85. translate("Allow localhost"),
  86. translate("Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services"))
  87. rl:depends("rebind_protection", "1")
  88. rd = s:taboption("general", DynamicList, "rebind_domain",
  89. translate("Domain whitelist"),
  90. translate("List of domains to allow RFC1918 responses for"))
  91. rd:depends("rebind_protection", "1")
  92. rd.datatype = "host"
  93. rd.placeholder = "ihost.netflix.com"
  94. pt = s:taboption("advanced", Value, "port",
  95. translate("<abbr title=\"Domain Name System\">DNS</abbr> server port"),
  96. translate("Listening port for inbound DNS queries"))
  97. pt.optional = true
  98. pt.datatype = "port"
  99. pt.placeholder = 53
  100. qp = s:taboption("advanced", Value, "queryport",
  101. translate("<abbr title=\"Domain Name System\">DNS</abbr> query port"),
  102. translate("Fixed source port for outbound DNS queries"))
  103. qp.optional = true
  104. qp.datatype = "port"
  105. qp.placeholder = translate("any")
  106. lm = s:taboption("advanced", Value, "dhcpleasemax",
  107. translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Dynamic Host Configuration " ..
  108. "Protocol\">DHCP</abbr> leases"),
  109. translate("Maximum allowed number of active DHCP leases"))
  110. lm.optional = true
  111. lm.datatype = "uinteger"
  112. lm.placeholder = translate("unlimited")
  113. em = s:taboption("advanced", Value, "ednspacket_max",
  114. translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Extension Mechanisms for " ..
  115. "Domain Name System\">EDNS0</abbr> packet size"),
  116. translate("Maximum allowed size of EDNS.0 UDP packets"))
  117. em.optional = true
  118. em.datatype = "uinteger"
  119. em.placeholder = 1280
  120. cq = s:taboption("advanced", Value, "dnsforwardmax",
  121. translate("<abbr title=\"maximal\">Max.</abbr> concurrent queries"),
  122. translate("Maximum allowed number of concurrent DNS queries"))
  123. cq.optional = true
  124. cq.datatype = "uinteger"
  125. cq.placeholder = 150
  126. s:taboption("tftp", Flag, "enable_tftp",
  127. translate("Enable TFTP server")).optional = true
  128. tr = s:taboption("tftp", Value, "tftp_root",
  129. translate("TFTP server root"),
  130. translate("Root directory for files served via TFTP"))
  131. tr.optional = true
  132. tr:depends("enable_tftp", "1")
  133. tr.placeholder = "/"
  134. db = s:taboption("tftp", Value, "dhcp_boot",
  135. translate("Network boot image"),
  136. translate("Filename of the boot image advertised to clients"))
  137. db.optional = true
  138. db:depends("enable_tftp", "1")
  139. db.placeholder = "pxelinux.0"
  140. m:section(SimpleSection).template = "admin_network/lease_status"
  141. s = m:section(TypedSection, "host", translate("Static Leases"),
  142. translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
  143. "DHCP clients. They are also required for non-dynamic interface configurations where " ..
  144. "only hosts with a corresponding lease are served.") .. "<br />" ..
  145. translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
  146. "indentifies the host, the <em>IPv4-Address</em> specifies to the fixed address to " ..
  147. "use and the <em>Hostname</em> is assigned as symbolic name to the requesting host."))
  148. s.addremove = true
  149. s.anonymous = true
  150. s.template = "cbi/tblsection"
  151. name = s:option(Value, "name", translate("Hostname"))
  152. name.datatype = "hostname"
  153. name.rmempty = true
  154. mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
  155. mac.datatype = "list(macaddr)"
  156. mac.rmempty = true
  157. ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
  158. ip.datatype = "or(ip4addr,'ignore')"
  159. hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
  160. ipc.neighbors({ family = 4 }, function(n)
  161. if n.mac and n.dest then
  162. ip:value(n.dest:string())
  163. mac:value(n.mac, "%s (%s)" %{ n.mac, n.dest:string() })
  164. end
  165. end)
  166. function ip.validate(self, value, section)
  167. local m = mac:formvalue(section) or ""
  168. local n = name:formvalue(section) or ""
  169. if value and #n == 0 and #m == 0 then
  170. return nil, translate("One of hostname or mac address must be specified!")
  171. end
  172. return Value.validate(self, value, section)
  173. end
  174. return m