2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
16 local fs = require "nixio.fs"
17 local nw = require "luci.model.network"
18 local fw = require "luci.model.firewall"
22 local has_3g = fs.access("/usr/bin/gcom")
23 local has_pptp = fs.access("/usr/sbin/pptp")
24 local has_pppd = fs.access("/usr/sbin/pppd")
25 local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")()
26 local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")()
27 local has_ipv6 = fs.access("/proc/net/ipv6_route")
29 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
35 s = m:section(NamedSection, arg[1], "interface")
38 s:tab("general", translate("a_n_general", "General Setup"))
39 if has_ipv6 then s:tab("ipv6", translate("a_n_ipv6", "IPv6 Setup")) end
40 if has_pppd then s:tab("ppp", translate("a_n_ppp", "PPP Settings")) end
41 s:tab("physical", translate("a_n_physical", "Physical Settings"))
44 back = s:taboption("general", DummyValue, "_overview", translate("overview"))
46 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
49 p = s:taboption("general", ListValue, "proto", translate("protocol"))
50 p.override_scheme = true
52 p:value("static", translate("static"))
53 p:value("dhcp", "DHCP")
54 if has_pppd then p:value("ppp", "PPP") end
55 if has_pppoe then p:value("pppoe", "PPPoE") end
56 if has_pppoa then p:value("pppoa", "PPPoA") end
57 if has_3g then p:value("3g", "UMTS/3G") end
58 if has_pptp then p:value("pptp", "PPTP") end
59 p:value("none", translate("none"))
61 if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
62 p.description = translate("network_interface_prereq")
65 br = s:taboption("physical", Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
69 stp = s:taboption("physical", Flag, "stp", translate("a_n_i_stp"),
70 translate("a_n_i_stp1", "Enables the Spanning Tree Protocol on this bridge"))
71 stp:depends("type", "1")
74 ifname_single = s:taboption("physical", Value, "ifname_single", translate("interface"))
75 ifname_single.template = "cbi/network_ifacelist"
76 ifname_single.widget = "radio"
77 ifname_single.nobridges = true
78 ifname_single.rmempty = true
79 ifname_single:depends("type", "")
81 function ifname_single.cfgvalue(self, s)
82 return self.map.uci:get("network", s, "ifname")
85 function ifname_single.write(self, s, val)
86 local n = nw:get_network(s)
87 if n then n:ifname(val) end
91 ifname_multi = s:taboption("physical", MultiValue, "ifname_multi", translate("interface"))
92 ifname_multi.template = "cbi/network_ifacelist"
93 ifname_multi.nobridges = true
94 ifname_multi.widget = "checkbox"
95 ifname_multi:depends("type", "1")
96 ifname_multi.cfgvalue = ifname_single.cfgvalue
97 ifname_multi.write = ifname_single.write
99 for _, d in ipairs(nw:get_interfaces()) do
100 if not d:is_bridge() then
101 ifname_single:value(d:name())
102 ifname_multi:value(d:name())
107 fwzone = s:taboption("general", Value, "_fwzone",
108 translate("network_interface_fwzone"),
109 translate("network_interface_fwzone_desc"))
111 fwzone.template = "cbi/firewall_zonelist"
112 fwzone.rmempty = false
114 function fwzone.cfgvalue(self, section)
116 local z = fw:get_zone_by_network(section)
117 return z and z:name()
120 function fwzone.write(self, section, value)
121 local zone = fw:get_zone(value)
123 if not zone and value == '-' then
124 value = m:formvalue(self:cbid(section) .. ".newzone")
125 if value and #value > 0 then
126 zone = fw:add_zone(value)
128 fw:del_network(section)
133 fw:del_network(section)
134 zone:add_network(section)
138 ipaddr = s:taboption("general", Value, "ipaddr", translate("ipaddress"))
139 ipaddr.rmempty = true
140 ipaddr:depends("proto", "static")
142 nm = s:taboption("general", Value, "netmask", translate("netmask"))
144 nm:depends("proto", "static")
145 nm:value("255.255.255.0")
146 nm:value("255.255.0.0")
147 nm:value("255.0.0.0")
149 gw = s:taboption("general", Value, "gateway", translate("gateway"))
150 gw:depends("proto", "static")
153 bcast = s:taboption("general", Value, "bcast", translate("broadcast"))
154 bcast:depends("proto", "static")
157 ip6addr = s:taboption("ipv6", Value, "ip6addr", translate("ip6address"), translate("cidr6"))
158 ip6addr:depends("proto", "static")
160 ip6gw = s:taboption("ipv6", Value, "ip6gw", translate("gateway6"))
161 ip6gw:depends("proto", "static")
164 dns = s:taboption("general", Value, "dns", translate("dnsserver"))
165 dns:depends("peerdns", "")
167 mtu = s:taboption("physical", Value, "mtu", "MTU")
170 mac = s:taboption("physical", Value, "macaddr", translate("macaddress"))
173 srv = s:taboption("general", Value, "server", translate("network_interface_server"))
174 srv:depends("proto", "pptp")
178 service = s:taboption("general", ListValue, "service", translate("network_interface_service"))
179 service:value("", translate("cbi_select"))
180 service:value("umts", "UMTS/GPRS")
181 service:value("cdma", "CDMA")
182 service:value("evdo", "EV-DO")
183 service:depends("proto", "3g")
184 service.rmempty = true
186 apn = s:taboption("general", Value, "apn", translate("network_interface_apn"))
187 apn:depends("proto", "3g")
189 pincode = s:taboption("general", Value, "pincode",
190 translate("network_interface_pincode"),
191 translate("network_interface_pincode_desc")
193 pincode:depends("proto", "3g")
196 if has_pppd or has_pppoe or has_pppoa or has_3g or has_pptp then
197 user = s:taboption("general", Value, "username", translate("username"))
199 user:depends("proto", "pptp")
200 user:depends("proto", "pppoe")
201 user:depends("proto", "pppoa")
202 user:depends("proto", "ppp")
203 user:depends("proto", "3g")
205 pass = s:taboption("general", Value, "password", translate("password"))
208 pass:depends("proto", "pptp")
209 pass:depends("proto", "pppoe")
210 pass:depends("proto", "pppoa")
211 pass:depends("proto", "ppp")
212 pass:depends("proto", "3g")
214 ka = s:taboption("ppp", Value, "keepalive",
215 translate("network_interface_keepalive"),
216 translate("network_interface_keepalive_desc")
218 ka:depends("proto", "pptp")
219 ka:depends("proto", "pppoe")
220 ka:depends("proto", "pppoa")
221 ka:depends("proto", "ppp")
222 ka:depends("proto", "3g")
224 demand = s:taboption("ppp", Value, "demand",
225 translate("network_interface_demand"),
226 translate("network_interface_demand_desc")
228 demand:depends("proto", "pptp")
229 demand:depends("proto", "pppoe")
230 demand:depends("proto", "pppoa")
231 demand:depends("proto", "ppp")
232 demand:depends("proto", "3g")
236 encaps = s:taboption("ppp", ListValue, "encaps", translate("network_interface_encaps"))
237 encaps:depends("proto", "pppoa")
238 encaps:value("", translate("cbi_select"))
239 encaps:value("vc", "VC")
240 encaps:value("llc", "LLC")
242 vpi = s:taboption("ppp", Value, "vpi", "VPI")
243 vpi:depends("proto", "pppoa")
245 vci = s:taboption("ppp", Value, "vci", "VCI")
246 vci:depends("proto", "pppoa")
249 if has_pptp or has_pppd or has_pppoe or has_pppoa or has_3g then
250 device = s:taboption("general", Value, "device",
251 translate("network_interface_device"),
252 translate("network_interface_device_desc")
254 device:depends("proto", "ppp")
255 device:depends("proto", "3g")
257 defaultroute = s:taboption("ppp", Flag, "defaultroute",
258 translate("network_interface_defaultroute"),
259 translate("network_interface_defaultroute_desc")
261 defaultroute:depends("proto", "ppp")
262 defaultroute:depends("proto", "pppoa")
263 defaultroute:depends("proto", "pppoe")
264 defaultroute:depends("proto", "pptp")
265 defaultroute:depends("proto", "3g")
266 defaultroute.rmempty = false
267 function defaultroute.cfgvalue(...)
268 return ( AbstractValue.cfgvalue(...) or '1' )
271 peerdns = s:taboption("ppp", Flag, "peerdns",
272 translate("network_interface_peerdns"),
273 translate("network_interface_peerdns_desc")
275 peerdns:depends("proto", "ppp")
276 peerdns:depends("proto", "pppoa")
277 peerdns:depends("proto", "pppoe")
278 peerdns:depends("proto", "pptp")
279 peerdns:depends("proto", "3g")
280 peerdns.rmempty = false
281 function peerdns.cfgvalue(...)
282 return ( AbstractValue.cfgvalue(...) or '1' )
286 ipv6 = s:taboption("ppp", Flag, "ipv6", translate("network_interface_ipv6") )
287 ipv6:depends("proto", "ppp")
288 ipv6:depends("proto", "pppoa")
289 ipv6:depends("proto", "pppoe")
290 ipv6:depends("proto", "pptp")
291 ipv6:depends("proto", "3g")
294 connect = s:taboption("ppp", Value, "connect",
295 translate("network_interface_connect"),
296 translate("network_interface_connect_desc")
298 connect:depends("proto", "ppp")
299 connect:depends("proto", "pppoe")
300 connect:depends("proto", "pppoa")
301 connect:depends("proto", "pptp")
302 connect:depends("proto", "3g")
304 disconnect = s:taboption("ppp", Value, "disconnect",
305 translate("network_interface_disconnect"),
306 translate("network_interface_disconnect_desc")
308 disconnect:depends("proto", "ppp")
309 disconnect:depends("proto", "pppoe")
310 disconnect:depends("proto", "pppoa")
311 disconnect:depends("proto", "pptp")
312 disconnect:depends("proto", "3g")
314 pppd_options = s:taboption("ppp", Value, "pppd_options",
315 translate("network_interface_pppd_options"),
316 translate("network_interface_pppd_options_desc")
318 pppd_options:depends("proto", "ppp")
319 pppd_options:depends("proto", "pppoa")
320 pppd_options:depends("proto", "pppoe")
321 pppd_options:depends("proto", "pptp")
322 pppd_options:depends("proto", "3g")
324 maxwait = s:taboption("ppp", Value, "maxwait",
325 translate("network_interface_maxwait"),
326 translate("network_interface_maxwait_desc")
328 maxwait:depends("proto", "3g")
331 s2 = m:section(TypedSection, "alias", translate("aliases"))
334 s2:depends("interface", arg[1])
335 s2.defaults.interface = arg[1]
337 s2:tab("general", translate("a_n_general", "General Setup"))
339 s2.defaults.proto = "static"
341 s2:taboption("general", Value, "ipaddr", translate("ipaddress")).rmempty = true
343 nm = s2:taboption("general", Value, "netmask", translate("netmask"))
345 nm:value("255.255.255.0")
346 nm:value("255.255.0.0")
347 nm:value("255.0.0.0")
349 s2:taboption("general", Value, "gateway", translate("gateway")).rmempty = true
350 s2:taboption("general", Value, "bcast", translate("broadcast"))
351 s2:taboption("general", Value, "dns", translate("dnsserver"))
354 s2:tab("ipv6", translate("a_n_ipv6", "IPv6 Setup"))
355 s2:taboption("ipv6", Value, "ip6addr", translate("ip6address"), translate("cidr6"))
356 s2:taboption("ipv6", Value, "ip6gw", translate("gateway6"))