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("On this page you can configure the network interfaces. You can bridge several interfaces by ticking the \"bridge interfaces\" field and enter the names of several network interfaces separated by spaces. You can also use <abbr title=\"Virtual Local Area Network\">VLAN</abbr> notation <samp>INTERFACE.VLANNR</samp> (<abbr title=\"for example\">e.g.</abbr>: <samp>eth0.1</samp>)."))
36 s = m:section(NamedSection, arg[1], "interface")
39 s:tab("general", translate("General Setup"))
40 if has_ipv6 then s:tab("ipv6", translate("IPv6 Setup")) end
41 if has_pppd then s:tab("ppp", translate("PPP Settings")) end
42 s:tab("physical", translate("Physical Settings"))
43 s:tab("firewall", translate("Firewall Settings"))
46 back = s:taboption("general", DummyValue, "_overview", translate("Overview"))
48 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
51 p = s:taboption("general", ListValue, "proto", translate("Protocol"))
52 p.override_scheme = true
54 p:value("static", translate("static"))
55 p:value("dhcp", "DHCP")
56 if has_pppd then p:value("ppp", "PPP") end
57 if has_pppoe then p:value("pppoe", "PPPoE") end
58 if has_pppoa then p:value("pppoa", "PPPoA") end
59 if has_3g then p:value("3g", "UMTS/3G") end
60 if has_pptp then p:value("pptp", "PPTP") end
61 p:value("none", translate("none"))
63 if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
64 p.description = translate("You need to install \"comgt\" for UMTS/GPRS, \"ppp-mod-pppoe\" for PPPoE, \"ppp-mod-pppoa\" for PPPoA or \"pptp\" for PPtP support")
67 br = s:taboption("physical", Flag, "type", translate("Bridge interfaces"), translate("creates a bridge over specified interface(s)"))
71 stp = s:taboption("physical", Flag, "stp", translate("Enable <abbr title=\"Spanning Tree Protocol\">STP</abbr>"),
72 translate("Enables the Spanning Tree Protocol on this bridge"))
73 stp:depends("type", "1")
76 ifname_single = s:taboption("physical", Value, "ifname_single", translate("Interface"))
77 ifname_single.template = "cbi/network_ifacelist"
78 ifname_single.widget = "radio"
79 ifname_single.nobridges = true
80 ifname_single.network = arg[1]
81 ifname_single.rmempty = true
82 ifname_single:depends("type", "")
84 function ifname_single.cfgvalue(self, s)
85 return self.map.uci:get("network", s, "ifname")
88 function ifname_single.write(self, s, val)
89 local n = nw:get_network(s)
92 for _, i in ipairs(n:get_interfaces()) do
100 ifname_multi = s:taboption("physical", MultiValue, "ifname_multi", translate("Interface"))
101 ifname_multi.template = "cbi/network_ifacelist"
102 ifname_multi.nobridges = true
103 ifname_multi.network = arg[1]
104 ifname_multi.widget = "checkbox"
105 ifname_multi:depends("type", "1")
106 ifname_multi.cfgvalue = ifname_single.cfgvalue
107 ifname_multi.write = ifname_single.write
110 for _, d in ipairs(nw:get_interfaces()) do
111 if not d:is_bridge() then
112 ifname_single:value(d:name())
113 ifname_multi:value(d:name())
118 local fwd_to, fwd_from
120 fwzone = s:taboption("firewall", Value, "_fwzone",
121 translate("Create / Assign firewall-zone"),
122 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."))
124 fwzone.template = "cbi/firewall_zonelist"
125 fwzone.network = arg[1]
126 fwzone.rmempty = false
128 function fwzone.cfgvalue(self, section)
130 local z = fw:get_zone_by_network(section)
131 return z and z:name()
134 function fwzone.write(self, section, value)
135 local zone = fw:get_zone(value)
137 if not zone and value == '-' then
138 value = m:formvalue(self:cbid(section) .. ".newzone")
139 if value and #value > 0 then
140 zone = fw:add_zone(value)
142 fw:del_network(section)
147 fw:del_network(section)
148 zone:add_network(section)
153 ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
154 ipaddr.rmempty = true
155 ipaddr:depends("proto", "static")
157 nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
159 nm:depends("proto", "static")
160 nm:value("255.255.255.0")
161 nm:value("255.255.0.0")
162 nm:value("255.0.0.0")
164 gw = s:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
165 gw:depends("proto", "static")
168 bcast = s:taboption("general", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
169 bcast:depends("proto", "static")
172 ip6addr = s:taboption("ipv6", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
173 ip6addr:depends("proto", "static")
175 ip6gw = s:taboption("ipv6", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
176 ip6gw:depends("proto", "static")
179 dns = s:taboption("general", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
180 dns:depends("peerdns", "")
182 mtu = s:taboption("physical", Value, "mtu", "MTU")
185 mac = s:taboption("physical", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
188 srv = s:taboption("general", Value, "server", translate("<abbr title=\"Point-to-Point Tunneling Protocol\">PPTP</abbr>-Server"))
189 srv:depends("proto", "pptp")
193 service = s:taboption("general", ListValue, "service", translate("Service type"))
194 service:value("", translate("-- Please choose --"))
195 service:value("umts", "UMTS/GPRS")
196 service:value("cdma", "CDMA")
197 service:value("evdo", "EV-DO")
198 service:depends("proto", "3g")
199 service.rmempty = true
201 apn = s:taboption("general", Value, "apn", translate("Access point (APN)"))
202 apn:depends("proto", "3g")
204 pincode = s:taboption("general", Value, "pincode",
205 translate("PIN code"),
206 translate("Make sure that you provide the correct pin code here or you might lock your sim card!")
208 pincode:depends("proto", "3g")
211 if has_pppd or has_pppoe or has_pppoa or has_3g or has_pptp then
212 user = s:taboption("general", Value, "username", translate("Username"))
214 user:depends("proto", "pptp")
215 user:depends("proto", "pppoe")
216 user:depends("proto", "pppoa")
217 user:depends("proto", "ppp")
218 user:depends("proto", "3g")
220 pass = s:taboption("general", Value, "password", translate("Password"))
223 pass:depends("proto", "pptp")
224 pass:depends("proto", "pppoe")
225 pass:depends("proto", "pppoa")
226 pass:depends("proto", "ppp")
227 pass:depends("proto", "3g")
229 ka = s:taboption("ppp", Value, "keepalive",
230 translate("Keep-Alive"),
231 translate("Number of failed connection tests to initiate automatic reconnect")
233 ka:depends("proto", "pptp")
234 ka:depends("proto", "pppoe")
235 ka:depends("proto", "pppoa")
236 ka:depends("proto", "ppp")
237 ka:depends("proto", "3g")
239 demand = s:taboption("ppp", Value, "demand",
240 translate("Automatic Disconnect"),
241 translate("Time (in seconds) after which an unused connection will be closed")
243 demand:depends("proto", "pptp")
244 demand:depends("proto", "pppoe")
245 demand:depends("proto", "pppoa")
246 demand:depends("proto", "ppp")
247 demand:depends("proto", "3g")
251 encaps = s:taboption("ppp", ListValue, "encaps", translate("PPPoA Encapsulation"))
252 encaps:depends("proto", "pppoa")
253 encaps:value("", translate("-- Please choose --"))
254 encaps:value("vc", "VC")
255 encaps:value("llc", "LLC")
257 vpi = s:taboption("ppp", Value, "vpi", "VPI")
258 vpi:depends("proto", "pppoa")
260 vci = s:taboption("ppp", Value, "vci", "VCI")
261 vci:depends("proto", "pppoa")
264 if has_pptp or has_pppd or has_pppoe or has_pppoa or has_3g then
265 device = s:taboption("general", Value, "device",
266 translate("Modem device"),
267 translate("The device node of your modem, e.g. /dev/ttyUSB0")
269 device:depends("proto", "ppp")
270 device:depends("proto", "3g")
272 defaultroute = s:taboption("ppp", Flag, "defaultroute",
273 translate("Replace default route"),
274 translate("Let pppd replace the current default route to use the PPP interface after successful connect")
276 defaultroute:depends("proto", "ppp")
277 defaultroute:depends("proto", "pppoa")
278 defaultroute:depends("proto", "pppoe")
279 defaultroute:depends("proto", "pptp")
280 defaultroute:depends("proto", "3g")
281 defaultroute.rmempty = false
282 function defaultroute.cfgvalue(...)
283 return ( AbstractValue.cfgvalue(...) or '1' )
286 peerdns = s:taboption("ppp", Flag, "peerdns",
287 translate("Use peer DNS"),
288 translate("Configure the local DNS server to use the name servers adverticed by the PPP peer")
290 peerdns:depends("proto", "ppp")
291 peerdns:depends("proto", "pppoa")
292 peerdns:depends("proto", "pppoe")
293 peerdns:depends("proto", "pptp")
294 peerdns:depends("proto", "3g")
295 peerdns.rmempty = false
296 function peerdns.cfgvalue(...)
297 return ( AbstractValue.cfgvalue(...) or '1' )
301 ipv6 = s:taboption("ppp", Flag, "ipv6", translate("Enable IPv6 on PPP link") )
302 ipv6:depends("proto", "ppp")
303 ipv6:depends("proto", "pppoa")
304 ipv6:depends("proto", "pppoe")
305 ipv6:depends("proto", "pptp")
306 ipv6:depends("proto", "3g")
309 connect = s:taboption("ppp", Value, "connect",
310 translate("Connect script"),
311 translate("Let pppd run this script after establishing the PPP link")
313 connect:depends("proto", "ppp")
314 connect:depends("proto", "pppoe")
315 connect:depends("proto", "pppoa")
316 connect:depends("proto", "pptp")
317 connect:depends("proto", "3g")
319 disconnect = s:taboption("ppp", Value, "disconnect",
320 translate("Disconnect script"),
321 translate("Let pppd run this script before tearing down the PPP link")
323 disconnect:depends("proto", "ppp")
324 disconnect:depends("proto", "pppoe")
325 disconnect:depends("proto", "pppoa")
326 disconnect:depends("proto", "pptp")
327 disconnect:depends("proto", "3g")
329 pppd_options = s:taboption("ppp", Value, "pppd_options",
330 translate("Additional pppd options"),
331 translate("Specify additional command line arguments for pppd here")
333 pppd_options:depends("proto", "ppp")
334 pppd_options:depends("proto", "pppoa")
335 pppd_options:depends("proto", "pppoe")
336 pppd_options:depends("proto", "pptp")
337 pppd_options:depends("proto", "3g")
339 maxwait = s:taboption("ppp", Value, "maxwait",
340 translate("Setup wait time"),
341 translate("Seconds to wait for the modem to become ready before attempting to connect")
343 maxwait:depends("proto", "3g")
346 s2 = m:section(TypedSection, "alias", translate("Aliases"))
349 s2:depends("interface", arg[1])
350 s2.defaults.interface = arg[1]
352 s2:tab("general", translate("General Setup"))
354 s2.defaults.proto = "static"
356 s2:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address")).rmempty = true
358 nm = s2:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
360 nm:value("255.255.255.0")
361 nm:value("255.255.0.0")
362 nm:value("255.0.0.0")
364 s2:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway")).rmempty = true
365 s2:taboption("general", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
366 s2:taboption("general", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
369 s2:tab("ipv6", translate("IPv6 Setup"))
370 s2:taboption("ipv6", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
371 s2:taboption("ipv6", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))