all: change most translate statements to new format, some need manual cleanup
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / ifaces.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
6
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
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local fs = require "nixio.fs"
17 local nw = require "luci.model.network"
18 local fw = require "luci.model.firewall"
19
20 arg[1] = arg[1] or ""
21
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")
28
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>)."))
30 m:chain("firewall")
31 m:chain("wireless")
32
33 nw.init(m.uci)
34 fw.init(m.uci)
35
36 s = m:section(NamedSection, arg[1], "interface")
37 s.addremove = false
38
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"))
44
45 --[[
46 back = s:taboption("general", DummyValue, "_overview", translate("Overview"))
47 back.value = ""
48 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
49 ]]
50
51 p = s:taboption("general", ListValue, "proto", translate("Protocol"))
52 p.override_scheme = true
53 p.default = "static"
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"))
62
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")
65 end
66
67 br = s:taboption("physical", Flag, "type", translate("Bridge interfaces"), translate("creates a bridge over specified interface(s)"))
68 br.enabled = "bridge"
69 br.rmempty = true
70
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")
74 stp.rmempty = true
75
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", "")
83
84 function ifname_single.cfgvalue(self, s)
85         return self.map.uci:get("network", s, "ifname")
86 end
87
88 function ifname_single.write(self, s, val)
89         local n = nw:get_network(s)
90         if n then
91                 local i
92                 for _, i in ipairs(n:get_interfaces()) do
93                         n:del_interface(i)
94                 end
95                 n:add_interface(val)
96         end
97 end
98
99
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
108
109
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())
114         end
115 end
116
117
118 local fwd_to, fwd_from
119
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."))
123
124 fwzone.template = "cbi/firewall_zonelist"
125 fwzone.network = arg[1]
126 fwzone.rmempty = false
127
128 function fwzone.cfgvalue(self, section)
129         self.iface = section
130         local z = fw:get_zone_by_network(section)
131         return z and z:name()
132 end
133
134 function fwzone.write(self, section, value)
135         local zone = fw:get_zone(value)
136
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)
141                 else
142                         fw:del_network(section)
143                 end
144         end
145
146         if zone then
147                 fw:del_network(section)
148                 zone:add_network(section)
149         end
150 end
151
152
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")
156
157 nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
158 nm.rmempty = true
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")
163
164 gw = s:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
165 gw:depends("proto", "static")
166 gw.rmempty = true
167
168 bcast = s:taboption("general", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
169 bcast:depends("proto", "static")
170
171 if has_ipv6 then
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")
174
175         ip6gw = s:taboption("ipv6", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
176         ip6gw:depends("proto", "static")
177 end
178
179 dns = s:taboption("general", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
180 dns:depends("peerdns", "")
181
182 mtu = s:taboption("physical", Value, "mtu", "MTU")
183 mtu.isinteger = true
184
185 mac = s:taboption("physical", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
186
187
188 srv = s:taboption("general", Value, "server", translate("<abbr title=\"Point-to-Point Tunneling Protocol\">PPTP</abbr>-Server"))
189 srv:depends("proto", "pptp")
190 srv.rmempty = true
191
192 if has_3g then
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
200
201         apn = s:taboption("general", Value, "apn", translate("Access point (APN)"))
202         apn:depends("proto", "3g")
203
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!")
207         )
208         pincode:depends("proto", "3g")
209 end
210
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"))
213         user.rmempty = true
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")
219
220         pass = s:taboption("general", Value, "password", translate("Password"))
221         pass.rmempty = true
222         pass.password = true
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")
228
229         ka = s:taboption("ppp", Value, "keepalive",
230          translate("Keep-Alive"),
231          translate("Number of failed connection tests to initiate automatic reconnect")
232         )
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")
238
239         demand = s:taboption("ppp", Value, "demand",
240          translate("Automatic Disconnect"),
241          translate("Time (in seconds) after which an unused connection will be closed")
242         )
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")
248 end
249
250 if has_pppoa then
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")
256
257         vpi = s:taboption("ppp", Value, "vpi", "VPI")
258         vpi:depends("proto", "pppoa")
259
260         vci = s:taboption("ppp", Value, "vci", "VCI")
261         vci:depends("proto", "pppoa")
262 end
263
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")
268         )
269         device:depends("proto", "ppp")
270         device:depends("proto", "3g")
271
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")
275         )
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' )
284         end
285
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")
289         )
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' )
298         end
299
300         if has_ipv6 then
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")
307         end
308
309         connect = s:taboption("ppp", Value, "connect",
310          translate("Connect script"),
311          translate("Let pppd run this script after establishing the PPP link")
312         )
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")
318
319         disconnect = s:taboption("ppp", Value, "disconnect",
320          translate("Disconnect script"),
321          translate("Let pppd run this script before tearing down the PPP link")
322         )
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")
328
329         pppd_options = s:taboption("ppp", Value, "pppd_options",
330          translate("Additional pppd options"),
331          translate("Specify additional command line arguments for pppd here")
332         )
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")
338
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")
342         )
343         maxwait:depends("proto", "3g")
344 end
345
346 s2 = m:section(TypedSection, "alias", translate("Aliases"))
347 s2.addremove = true
348
349 s2:depends("interface", arg[1])
350 s2.defaults.interface = arg[1]
351
352 s2:tab("general", translate("General Setup"))
353
354 s2.defaults.proto = "static"
355
356 s2:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address")).rmempty = true
357
358 nm = s2:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
359 nm.rmempty = true
360 nm:value("255.255.255.0")
361 nm:value("255.255.0.0")
362 nm:value("255.0.0.0")
363
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"))
367
368 if has_ipv6 then
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"))
372 end
373
374 return m