2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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 require("luci.tools.webadmin")
19 local has_3g = luci.fs.mtime("/usr/bin/gcom")
20 local has_pptp = luci.fs.mtime("/usr/sbin/pptp")
21 local has_pppd = luci.fs.mtime("/usr/sbin/pppd")
22 local has_pppoe = luci.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")
23 local has_pppoa = luci.fs.glob("/usr/lib/pppd/*/pppoatm.so")
25 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
27 s = m:section(NamedSection, arg[1], "interface")
30 back = s:option(DummyValue, "_overview", translate("overview"))
32 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
34 p = s:option(ListValue, "proto", translate("protocol"))
35 p.override_scheme = true
37 p:value("static", translate("static"))
38 p:value("dhcp", "DHCP")
39 if has_pppd then p:value("ppp", "PPP") end
40 if has_pppoe then p:value("pppoe", "PPPoE") end
41 if has_pppoa then p:value("pppoa", "PPPoA") end
42 if has_3g then p:value("3g", "UMTS/3G") end
43 if has_pptp then p:value("pptp", "PPTP") end
44 p:value("none", translate("none"))
46 if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
47 p.description = translate("network_interface_prereq")
50 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
54 stp = s:option(Flag, "stp", translate("a_n_i_stp"),
55 translate("a_n_i_stp1", "Enables the Spanning Tree Protocol on this bridge"))
56 stp:depends("type", "1")
59 ifname = s:option(Value, "ifname", translate("interface"))
61 for i,d in ipairs(luci.sys.net.devices()) do
67 local zones = luci.tools.webadmin.network_get_zones(arg[1])
72 fwzone = s:option(Value, "_fwzone",
73 translate("network_interface_fwzone"),
74 translate("network_interface_fwzone_desc"))
76 fwzone:value("", "- " .. translate("none") .. " -")
78 m.uci:load("firewall")
79 m.uci:foreach("firewall", "zone",
81 fwzone:value(section.name)
85 function fwzone.write(self, section, value)
86 local zone = luci.tools.webadmin.firewall_find_zone(value)
90 stat = m.uci:section("firewall", "zone", nil, {
95 local net = m.uci:get("firewall", zone, "network")
96 net = (net or value) .. " " .. section
97 stat = m.uci:set("firewall", zone, "network", net)
101 self.render = function() end
105 fwzone = s:option(DummyValue, "_fwzone", translate("zone"))
106 fwzone.value = table.concat(zones, ", ")
108 fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
109 m.uci:unload("firewall")
112 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
113 ipaddr.rmempty = true
114 ipaddr:depends("proto", "static")
116 nm = s:option(Value, "netmask", translate("netmask"))
118 nm:depends("proto", "static")
119 nm:value("255.255.255.0")
120 nm:value("255.255.0.0")
121 nm:value("255.0.0.0")
123 gw = s:option(Value, "gateway", translate("gateway"))
124 gw:depends("proto", "static")
127 bcast = s:option(Value, "bcast", translate("broadcast"))
128 bcast:depends("proto", "static")
129 bcast.optional = true
131 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
132 ip6addr.optional = true
133 ip6addr:depends("proto", "static")
135 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
136 ip6gw:depends("proto", "static")
137 ip6gw.optional = true
139 dns = s:option(Value, "dns", translate("dnsserver"))
142 mtu = s:option(Value, "mtu", "MTU")
146 mac = s:option(Value, "macaddr", translate("macaddress"))
150 srv = s:option(Value, "server", translate("network_interface_server"))
151 srv:depends("proto", "pptp")
155 service = s:option(ListValue, "service", translate("network_interface_service"))
156 service:value("", translate("cbi_select"))
157 service:value("umts", "UMTS/GPRS")
158 service:value("cdma", "CDMA")
159 service:value("evdo", "EV-DO")
160 service:depends("proto", "3g")
161 service.rmempty = true
163 apn = s:option(Value, "apn", translate("network_interface_apn"))
164 apn:depends("proto", "3g")
166 pincode = s:option(Value, "pincode",
167 translate("network_interface_pincode"),
168 translate("network_interface_pincode_desc")
170 pincode:depends("proto", "3g")
173 if has_pppd or has_pppoe or has_pppoa or has_3g or has_pptp then
174 user = s:option(Value, "username", translate("username"))
176 user:depends("proto", "pptp")
177 user:depends("proto", "pppoe")
178 user:depends("proto", "pppoa")
179 user:depends("proto", "ppp")
180 user:depends("proto", "3g")
182 pass = s:option(Value, "password", translate("password"))
185 pass:depends("proto", "pptp")
186 pass:depends("proto", "pppoe")
187 pass:depends("proto", "pppoa")
188 pass:depends("proto", "ppp")
189 pass:depends("proto", "3g")
191 ka = s:option(Value, "keepalive",
192 translate("network_interface_keepalive"),
193 translate("network_interface_keepalive_desc")
196 ka:depends("proto", "pptp")
197 ka:depends("proto", "pppoe")
198 ka:depends("proto", "pppoa")
199 ka:depends("proto", "ppp")
200 ka:depends("proto", "3g")
202 demand = s:option(Value, "demand",
203 translate("network_interface_demand"),
204 translate("network_interface_demand_desc")
206 demand.optional = true
207 demand:depends("proto", "pptp")
208 demand:depends("proto", "pppoe")
209 demand:depends("proto", "pppoa")
210 demand:depends("proto", "ppp")
211 demand:depends("proto", "3g")
215 encaps = s:option(ListValue, "encaps", translate("network_interface_encaps"))
216 encaps.optional = false
217 encaps:depends("proto", "pppoa")
218 encaps:value("", translate("cbi_select"))
219 encaps:value("vc", "VC")
220 encaps:value("llc", "LLC")
222 vpi = s:option(Value, "vpi", "VPI")
224 vpi:depends("proto", "pppoa")
226 vci = s:option(Value, "vci", "VCI")
228 vci:depends("proto", "pppoa")
231 if has_pptp or has_pppd or has_pppoe or has_pppoa or has_3g then
232 device = s:option(Value, "device",
233 translate("network_interface_device"),
234 translate("network_interface_device_desc")
236 device:depends("proto", "ppp")
237 device:depends("proto", "3g")
239 defaultroute = s:option(Flag, "defaultroute",
240 translate("network_interface_defaultroute"),
241 translate("network_interface_defaultroute_desc")
243 defaultroute:depends("proto", "ppp")
244 defaultroute:depends("proto", "pppoa")
245 defaultroute:depends("proto", "pppoe")
246 defaultroute:depends("proto", "pptp")
247 defaultroute:depends("proto", "3g")
248 defaultroute.rmempty = false
249 function defaultroute.cfgvalue(...)
250 return ( AbstractValue.cfgvalue(...) or '1' )
253 peerdns = s:option(Flag, "peerdns",
254 translate("network_interface_peerdns"),
255 translate("network_interface_peerdns_desc")
257 peerdns:depends("proto", "ppp")
258 peerdns:depends("proto", "pppoa")
259 peerdns:depends("proto", "pppoe")
260 peerdns:depends("proto", "pptp")
261 peerdns:depends("proto", "3g")
262 peerdns.rmempty = false
263 function peerdns.cfgvalue(...)
264 return ( AbstractValue.cfgvalue(...) or '1' )
267 ipv6 = s:option(Flag, "ipv6", translate("network_interface_ipv6") )
268 ipv6:depends("proto", "ppp")
269 ipv6:depends("proto", "pppoa")
270 ipv6:depends("proto", "pppoe")
271 ipv6:depends("proto", "pptp")
272 ipv6:depends("proto", "3g")
274 connect = s:option(Value, "connect",
275 translate("network_interface_connect"),
276 translate("network_interface_connect_desc")
278 connect.optional = true
279 connect:depends("proto", "ppp")
280 connect:depends("proto", "pppoe")
281 connect:depends("proto", "pppoa")
282 connect:depends("proto", "pptp")
283 connect:depends("proto", "3g")
285 disconnect = s:option(Value, "disconnect",
286 translate("network_interface_disconnect"),
287 translate("network_interface_disconnect_desc")
289 disconnect.optional = true
290 disconnect:depends("proto", "ppp")
291 disconnect:depends("proto", "pppoe")
292 disconnect:depends("proto", "pppoa")
293 disconnect:depends("proto", "pptp")
294 disconnect:depends("proto", "3g")
296 pppd_options = s:option(Value, "pppd_options",
297 translate("network_interface_pppd_options"),
298 translate("network_interface_pppd_options_desc")
300 pppd_options.optional = true
301 pppd_options:depends("proto", "ppp")
302 pppd_options:depends("proto", "pppoa")
303 pppd_options:depends("proto", "pppoe")
304 pppd_options:depends("proto", "pptp")
305 pppd_options:depends("proto", "3g")
307 maxwait = s:option(Value, "maxwait",
308 translate("network_interface_maxwait"),
309 translate("network_interface_maxwait_desc")
311 maxwait.optional = true
312 maxwait:depends("proto", "3g")
315 s2 = m:section(TypedSection, "alias", translate("aliases"))
318 s2:depends("interface", arg[1])
319 s2.defaults.interface = arg[1]
322 s2.defaults.proto = "static"
324 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
325 ipaddr.rmempty = true
327 nm = s2:option(Value, "netmask", translate("netmask"))
329 nm:value("255.255.255.0")
330 nm:value("255.255.0.0")
331 nm:value("255.0.0.0")
333 gw = s2:option(Value, "gateway", translate("gateway"))
336 bcast = s2:option(Value, "bcast", translate("broadcast"))
337 bcast.optional = true
339 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
340 ip6addr.optional = true
342 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
343 ip6gw.optional = true
345 dns = s2:option(Value, "dns", translate("dnsserver"))