| 146 | | local fwd_to, fwd_from |
| 147 | | |
| 148 | | fwzone = s:taboption("firewall", Value, "_fwzone", |
| 149 | | translate("Create / Assign firewall-zone"), |
| 150 | | translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) |
| 151 | | |
| 152 | | fwzone.template = "cbi/firewall_zonelist" |
| 153 | | fwzone.network = arg[1] |
| 154 | | fwzone.rmempty = false |
| 155 | | |
| 156 | | function fwzone.cfgvalue(self, section) |
| 157 | | self.iface = section |
| 158 | | local z = fw:get_zone_by_network(section) |
| 159 | | return z and z:name() |
| 160 | | end |
| 161 | | |
| 162 | | function fwzone.write(self, section, value) |
| 163 | | local zone = fw:get_zone(value) |
| 164 | | |
| 165 | | if not zone and value == '-' then |
| 166 | | value = m:formvalue(self:cbid(section) .. ".newzone") |
| 167 | | if value and #value > 0 then |
| 168 | | zone = fw:add_zone(value) |
| 169 | | else |
| | 152 | if has_firewall then |
| | 153 | fwzone = s:taboption("firewall", Value, "_fwzone", |
| | 154 | translate("Create / Assign firewall-zone"), |
| | 155 | translate("Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>create</em> field to define a new zone and attach the interface to it.")) |
| | 156 | |
| | 157 | fwzone.template = "cbi/firewall_zonelist" |
| | 158 | fwzone.network = arg[1] |
| | 159 | fwzone.rmempty = false |
| | 160 | |
| | 161 | function fwzone.cfgvalue(self, section) |
| | 162 | self.iface = section |
| | 163 | local z = fw:get_zone_by_network(section) |
| | 164 | return z and z:name() |
| | 165 | end |
| | 166 | |
| | 167 | function fwzone.write(self, section, value) |
| | 168 | local zone = fw:get_zone(value) |
| | 169 | |
| | 170 | if not zone and value == '-' then |
| | 171 | value = m:formvalue(self:cbid(section) .. ".newzone") |
| | 172 | if value and #value > 0 then |
| | 173 | zone = fw:add_zone(value) |
| | 174 | else |
| | 175 | fw:del_network(section) |
| | 176 | end |
| | 177 | end |
| | 178 | |
| | 179 | if zone then |
| 519 | | end) |
| 520 | | |
| 521 | | if not has_section then |
| 522 | | m2.uci:section("dhcp", "dhcp", nil, { interface = arg[1], ignore = "1" }) |
| 523 | | m2.uci:save("dhcp") |
| 524 | | end |
| 525 | | end |
| 526 | | |
| 527 | | s = m2:section(TypedSection, "dhcp", translate("DHCP Server")) |
| 528 | | s.addremove = false |
| 529 | | s.anonymous = true |
| 530 | | s:tab("general", translate("General Setup")) |
| 531 | | s:tab("advanced", translate("Advanced Settings")) |
| 532 | | |
| 533 | | function s.filter(self, section) |
| 534 | | return m2.uci:get("dhcp", section, "interface") == arg[1] |
| 535 | | end |
| 536 | | |
| 537 | | local ignore = s:taboption("general", Flag, "ignore", |
| 538 | | translate("Ignore interface"), |
| 539 | | translate("Disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " .. |
| 540 | | "this interface.")) |
| 541 | | |
| 542 | | ignore.rmempty = false |
| 543 | | |
| 544 | | local start = s:taboption("general", Value, "start", translate("Start"), |
| 545 | | translate("Lowest leased address as offset from the network address.")) |
| 546 | | start.optional = true |
| 547 | | start.datatype = "uinteger" |
| 548 | | start.default = "100" |
| 549 | | |
| 550 | | local limit = s:taboption("general", Value, "limit", translate("Limit"), |
| 551 | | translate("Maximum number of leased addresses.")) |
| 552 | | limit.optional = true |
| 553 | | limit.datatype = "uinteger" |
| 554 | | limit.default = "150" |
| 555 | | |
| 556 | | local ltime = s:taboption("general", Value, "leasetime", translate("Leasetime"), |
| 557 | | translate("Expiry time of leased addresses, minimum is 2 Minutes (<code>2m</code>).")) |
| 558 | | ltime.rmempty = true |
| 559 | | ltime.default = "12h" |
| 560 | | |
| 561 | | local dd = s:taboption("advanced", Flag, "dynamicdhcp", |
| 562 | | translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"), |
| 563 | | translate("Dynamically allocate DHCP addresses for clients. If disabled, only " .. |
| 564 | | "clients having static leases will be served.")) |
| 565 | | |
| 566 | | dd.rmempty = false |
| 567 | | function dd.cfgvalue(self, section) |
| 568 | | return Flag.cfgvalue(self, section) or "1" |
| 569 | | end |
| 570 | | |
| 571 | | s:taboption("advanced", Flag, "force", translate("Force"), |
| 572 | | translate("Force DHCP on this network even if another server is detected.")) |
| 573 | | |
| 574 | | -- XXX: is this actually useful? |
| 575 | | --s:taboption("advanced", Value, "name", translate("Name"), |
| 576 | | -- translate("Define a name for this network.")) |
| 577 | | |
| 578 | | mask = s:taboption("advanced", Value, "netmask", |
| 579 | | translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"), |
| 580 | | translate("Override the netmask sent to clients. Normally it is calculated " .. |
| 581 | | "from the subnet that is served.")) |
| 582 | | |
| 583 | | mask.optional = true |
| 584 | | mask.datatype = "ip4addr" |
| 585 | | |
| 586 | | s:taboption("advanced", DynamicList, "dhcp_option", translate("DHCP-Options"), |
| 587 | | translate("Define additional DHCP options, for example \"<code>6,192.168.2.1," .. |
| 588 | | "192.168.2.2</code>\" which advertises different DNS servers to clients.")) |
| 589 | | |
| 590 | | for i, n in ipairs(s.children) do |
| 591 | | if n ~= ignore then |
| 592 | | n:depends("ignore", "") |
| | 536 | end |
| | 537 | |
| | 538 | s = m2:section(TypedSection, "dhcp", translate("DHCP Server")) |
| | 539 | s.addremove = false |
| | 540 | s.anonymous = true |
| | 541 | s:tab("general", translate("General Setup")) |
| | 542 | s:tab("advanced", translate("Advanced Settings")) |
| | 543 | |
| | 544 | function s.filter(self, section) |
| | 545 | return m2.uci:get("dhcp", section, "interface") == arg[1] |
| | 546 | end |
| | 547 | |
| | 548 | local ignore = s:taboption("general", Flag, "ignore", |
| | 549 | translate("Ignore interface"), |
| | 550 | translate("Disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " .. |
| | 551 | "this interface.")) |
| | 552 | |
| | 553 | ignore.rmempty = false |
| | 554 | |
| | 555 | local start = s:taboption("general", Value, "start", translate("Start"), |
| | 556 | translate("Lowest leased address as offset from the network address.")) |
| | 557 | start.optional = true |
| | 558 | start.datatype = "uinteger" |
| | 559 | start.default = "100" |
| | 560 | |
| | 561 | local limit = s:taboption("general", Value, "limit", translate("Limit"), |
| | 562 | translate("Maximum number of leased addresses.")) |
| | 563 | limit.optional = true |
| | 564 | limit.datatype = "uinteger" |
| | 565 | limit.default = "150" |
| | 566 | |
| | 567 | local ltime = s:taboption("general", Value, "leasetime", translate("Leasetime"), |
| | 568 | translate("Expiry time of leased addresses, minimum is 2 Minutes (<code>2m</code>).")) |
| | 569 | ltime.rmempty = true |
| | 570 | ltime.default = "12h" |
| | 571 | |
| | 572 | local dd = s:taboption("advanced", Flag, "dynamicdhcp", |
| | 573 | translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"), |
| | 574 | translate("Dynamically allocate DHCP addresses for clients. If disabled, only " .. |
| | 575 | "clients having static leases will be served.")) |
| | 576 | |
| | 577 | dd.rmempty = false |
| | 578 | function dd.cfgvalue(self, section) |
| | 579 | return Flag.cfgvalue(self, section) or "1" |
| | 580 | end |
| | 581 | |
| | 582 | s:taboption("advanced", Flag, "force", translate("Force"), |
| | 583 | translate("Force DHCP on this network even if another server is detected.")) |
| | 584 | |
| | 585 | -- XXX: is this actually useful? |
| | 586 | --s:taboption("advanced", Value, "name", translate("Name"), |
| | 587 | -- translate("Define a name for this network.")) |
| | 588 | |
| | 589 | mask = s:taboption("advanced", Value, "netmask", |
| | 590 | translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"), |
| | 591 | translate("Override the netmask sent to clients. Normally it is calculated " .. |
| | 592 | "from the subnet that is served.")) |
| | 593 | |
| | 594 | mask.optional = true |
| | 595 | mask.datatype = "ip4addr" |
| | 596 | |
| | 597 | s:taboption("advanced", DynamicList, "dhcp_option", translate("DHCP-Options"), |
| | 598 | translate("Define additional DHCP options, for example \"<code>6,192.168.2.1," .. |
| | 599 | "192.168.2.2</code>\" which advertises different DNS servers to clients.")) |
| | 600 | |
| | 601 | for i, n in ipairs(s.children) do |
| | 602 | if n ~= ignore then |
| | 603 | n:depends("ignore", "") |
| | 604 | end |