123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- --[[
- LuCI - Lua Configuration Interface
- Copyright 2014 Nils Schneider <nils@nilsschneider.net>
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- $Id$
- ]]--
- local uci = require("simple-uci").cursor()
- local lutil = require 'luci.util'
- local sysconfig = require 'gluon.sysconfig'
- local util = require 'gluon.util'
- local wan = uci:get_all("network", "wan")
- local wan6 = uci:get_all("network", "wan6")
- local dns = uci:get_first("gluon-wan-dnsmasq", "static")
- local f = SimpleForm("portconfig", translate("WAN connection"))
- local s
- local o
- s = f:section(SimpleSection, nil, nil)
- o = s:option(ListValue, "ipv4", translate("IPv4"))
- o:value("dhcp", translate("Automatic (DHCP)"))
- o:value("static", translate("Static"))
- o:value("none", translate("Disabled"))
- o.default = wan.proto
- o = s:option(Value, "ipv4_addr", translate("IP address"))
- o:depends("ipv4", "static")
- o.value = wan.ipaddr
- o.datatype = "ip4addr"
- o.rmempty = false
- o = s:option(Value, "ipv4_netmask", translate("Netmask"))
- o:depends("ipv4", "static")
- o.value = wan.netmask or "255.255.255.0"
- o.datatype = "ip4addr"
- o.rmempty = false
- o = s:option(Value, "ipv4_gateway", translate("Gateway"))
- o:depends("ipv4", "static")
- o.value = wan.gateway
- o.datatype = "ip4addr"
- o.rmempty = false
- s = f:section(SimpleSection, nil, nil)
- o = s:option(ListValue, "ipv6", translate("IPv6"))
- o:value("dhcpv6", translate("Automatic (RA/DHCPv6)"))
- o:value("static", translate("Static"))
- o:value("none", translate("Disabled"))
- o.default = wan6.proto
- o = s:option(Value, "ipv6_addr", translate("IP address"))
- o:depends("ipv6", "static")
- o.value = wan6.ip6addr
- o.datatype = "ip6addr"
- o.rmempty = false
- o = s:option(Value, "ipv6_gateway", translate("Gateway"))
- o:depends("ipv6", "static")
- o.value = wan6.ip6gw
- o.datatype = "ip6addr"
- o.rmempty = false
- if dns then
- s = f:section(SimpleSection, nil, nil)
- o = s:option(DynamicList, "dns", translate("Static DNS servers"))
- o:write(nil, uci:get("gluon-wan-dnsmasq", dns, "server"))
- o.datatype = "ipaddr"
- end
- s = f:section(SimpleSection, nil, nil)
- o = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
- o.default = uci:get_bool("network", "mesh_wan", "auto") and o.enabled or o.disabled
- o.rmempty = false
- if sysconfig.lan_ifname then
- o = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
- o.default = uci:get_bool("network", "mesh_lan", "auto") and o.enabled or o.disabled
- o.rmempty = false
- end
- if uci:get('system', 'gpio_switch_poe_passthrough') then
- s = f:section(SimpleSection, nil, nil)
- o = s:option(Flag, "poe_passthrough", translate("Enable PoE passthrough"))
- o.default = uci:get_bool("system", "gpio_switch_poe_passthrough", "value") and o.enabled or o.disabled
- o.rmempty = false
- end
- function f.handle(self, state, data)
- if state == FORM_VALID then
- uci:set("network", "wan", "proto", data.ipv4)
- if data.ipv4 == "static" then
- uci:set("network", "wan", "ipaddr", data.ipv4_addr:trim())
- uci:set("network", "wan", "netmask", data.ipv4_netmask:trim())
- uci:set("network", "wan", "gateway", data.ipv4_gateway:trim())
- else
- uci:delete("network", "wan", "ipaddr")
- uci:delete("network", "wan", "netmask")
- uci:delete("network", "wan", "gateway")
- end
- uci:set("network", "wan6", "proto", data.ipv6)
- if data.ipv6 == "static" then
- uci:set("network", "wan6", "ip6addr", data.ipv6_addr:trim())
- uci:set("network", "wan6", "ip6gw", data.ipv6_gateway:trim())
- else
- uci:delete("network", "wan6", "ip6addr")
- uci:delete("network", "wan6", "ip6gw")
- end
- uci:set("network", "mesh_wan", "auto", data.mesh_wan)
- if sysconfig.lan_ifname then
- uci:set("network", "mesh_lan", "auto", data.mesh_lan)
- local interfaces = uci:get_list("network", "client", "ifname")
- for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
- if data.mesh_lan == '1' then
- util.remove_from_set(interfaces, lanif)
- else
- util.add_to_set(interfaces, lanif)
- end
- end
- uci:set_list("network", "client", "ifname", interfaces)
- end
- uci:save("network")
- uci:commit("network")
- if uci:get('system', 'gpio_switch_poe_passthrough') then
- uci:set('system', 'gpio_switch_poe_passthrough', 'value', data.poe_passthrough)
- uci:save('system')
- uci:commit('system')
- end
- if dns then
- if #data.dns > 0 then
- uci:set("gluon-wan-dnsmasq", dns, "server", data.dns)
- else
- uci:delete("gluon-wan-dnsmasq", dns, "server")
- end
- uci:save("gluon-wan-dnsmasq")
- uci:commit("gluon-wan-dnsmasq")
- end
- end
- return true
- end
- return f
|