modules/admin-full: only display protocol related options if required software is...
[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@leipzig.freifunk.net>
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 require("luci.tools.webadmin")
17 arg[1] = arg[1] or ""
18
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")
24
25 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
26
27 s = m:section(NamedSection, arg[1], "interface")
28 s.addremove = true
29
30 back = s:option(DummyValue, "_overview", translate("overview"))
31 back.value = ""
32 back.titleref = luci.dispatcher.build_url("admin", "network", "network")
33
34 p = s:option(ListValue, "proto", translate("protocol"))
35 p.override_scheme = true
36 p.default = "static"
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
45 if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
46         p.description = translate("network_interface_prereq")
47 end
48
49 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
50 br.enabled = "bridge"
51 br.rmempty = true
52
53 ifname = s:option(Value, "ifname", translate("interface"))
54 ifname.rmempty = true
55 for i,d in ipairs(luci.sys.net.devices()) do
56         if d ~= "lo" then
57                 ifname:value(d)
58         end
59 end
60
61 local zones = luci.tools.webadmin.network_get_zones(arg[1])
62 if zones then
63         if #zones == 0 then
64                 m:chain("firewall")
65
66                 fwzone = s:option(Value, "_fwzone",
67                         translate("network_interface_fwzone"),
68                         translate("network_interface_fwzone_desc"))
69                 fwzone.rmempty = true
70                 fwzone:value("", "- " .. translate("none") .. " -")
71                 fwzone:value(arg[1])
72                 m.uci:load("firewall")
73                 m.uci:foreach("firewall", "zone",
74                         function (section)
75                                 fwzone:value(section.name)
76                         end
77                 )
78
79                 function fwzone.write(self, section, value)
80                         local zone = luci.tools.webadmin.firewall_find_zone(value)
81                         local stat
82
83                         if not zone then
84                                 stat = m.uci:section("firewall", "zone", nil, {
85                                         name = value,
86                                         network = section
87                                 })
88                         else
89                                 local net = m.uci:get("firewall", zone, "network")
90                                 net = (net or value) .. " " .. section
91                                 stat = m.uci:set("firewall", zone, "network", net)
92                         end
93
94                         if stat then
95                                 self.render = function() end
96                         end
97                 end
98         else
99                 fwzone = s:option(DummyValue, "_fwzone", translate("zone"))
100                 fwzone.value = table.concat(zones, ", ")
101         end
102         fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
103         m.uci:unload("firewall")
104 end
105
106 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
107 ipaddr.rmempty = true
108 ipaddr:depends("proto", "static")
109
110 nm = s:option(Value, "netmask", translate("netmask"))
111 nm.rmempty = true
112 nm:depends("proto", "static")
113 nm:value("255.255.255.0")
114 nm:value("255.255.0.0")
115 nm:value("255.0.0.0")
116
117 gw = s:option(Value, "gateway", translate("gateway"))
118 gw:depends("proto", "static")
119 gw.rmempty = true
120
121 bcast = s:option(Value, "bcast", translate("broadcast"))
122 bcast:depends("proto", "static")
123 bcast.optional = true
124
125 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
126 ip6addr.optional = true
127 ip6addr:depends("proto", "static")
128
129 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
130 ip6gw:depends("proto", "static")
131 ip6gw.optional = true
132
133 dns = s:option(Value, "dns", translate("dnsserver"))
134 dns.optional = true
135
136 mtu = s:option(Value, "mtu", "MTU")
137 mtu.optional = true
138 mtu.isinteger = true
139
140 mac = s:option(Value, "macaddr", translate("macaddress"))
141 mac.optional = true
142
143
144 srv = s:option(Value, "server", translate("network_interface_server"))
145 srv:depends("proto", "pptp")
146 srv.rmempty = true
147
148 if has_3g then
149         service = s:option(ListValue, "service", translate("network_interface_service"))
150         service:value("", translate("cbi_select"))
151         service:value("umts", "UMTS/GPRS")
152         service:value("cdma", "CDMA")
153         service:value("evdo", "EV-DO")
154         service:depends("proto", "3g")
155         service.rmempty = true
156
157         apn = s:option(Value, "apn", translate("network_interface_apn"))
158         apn:depends("proto", "3g")
159
160         pincode = s:option(Value, "pincode",
161          translate("network_interface_pincode"),
162          translate("network_interface_pincode_desc")
163         )
164         pincode:depends("proto", "3g")
165 end
166
167 if has_pppd or has_pppoe or has_3g or has_pptp then
168         user = s:option(Value, "username", translate("username"))
169         user.rmempty = true
170         user:depends("proto", "pptp")
171         user:depends("proto", "pppoe")
172         user:depends("proto", "ppp")
173         user:depends("proto", "3g")
174
175         pass = s:option(Value, "password", translate("password"))
176         pass.rmempty = true
177         pass.password = true
178         pass:depends("proto", "pptp")
179         pass:depends("proto", "pppoe")
180         pass:depends("proto", "ppp")
181         pass:depends("proto", "3g")
182
183         ka = s:option(Value, "keepalive",
184          translate("network_interface_keepalive"),
185          translate("network_interface_keepalive_desc")
186         )
187         ka.optional = true
188         ka:depends("proto", "pptp")
189         ka:depends("proto", "pppoe")
190         ka:depends("proto", "ppp")
191         ka:depends("proto", "3g")
192
193         demand = s:option(Value, "demand",
194          translate("network_interface_demand"),
195          translate("network_interface_demand_desc")
196         )
197         demand.optional = true
198         demand:depends("proto", "pptp")
199         demand:depends("proto", "pppoe")
200         demand:depends("proto", "ppp")
201         demand:depends("proto", "3g")
202 end
203
204 if has_pppd or has_3g then
205         device = s:option(Value, "device",
206          translate("network_interface_device"),
207          translate("network_interface_device_desc")
208         )
209         device:depends("proto", "ppp")
210         device:depends("proto", "3g")
211
212         defaultroute = s:option(Flag, "defaultroute",
213          translate("network_interface_defaultroute"),
214          translate("network_interface_defaultroute_desc")
215         )
216         defaultroute:depends("proto", "ppp")
217         defaultroute:depends("proto", "3g")
218
219         peerdns = s:option(Flag, "peerdns",
220          translate("network_interface_peerdns"),
221          translate("network_interface_peerdns_desc")
222         )
223         peerdns:depends("proto", "ppp")
224
225         ipv6 = s:option(Flag, "ipv6", translate("network_interface_ipv6") )
226         ipv6:depends("proto", "ppp")
227         --ipv6:depends("proto", "3g")
228
229         connect = s:option(Value, "connect",
230          translate("network_interface_connect"),
231          translate("network_interface_connect_desc")
232         )
233         connect.optional = true
234         connect:depends("proto", "ppp")
235         connect:depends("proto", "3g")
236
237         disconnect = s:option(Value, "disconnect",
238          translate("network_interface_disconnect"),
239          translate("network_interface_disconnect_desc")
240         )
241         disconnect.optional = true
242         disconnect:depends("proto", "ppp")
243         disconnect:depends("proto", "3g")
244
245         pppd_options = s:option(Value, "pppd_options",
246          translate("network_interface_pppd_options"),
247          translate("network_interface_pppd_options_desc")
248         )
249         pppd_options.optional = true
250         pppd_options:depends("proto", "ppp")
251         pppd_options:depends("proto", "3g")
252
253         maxwait = s:option(Value, "maxwait",
254          translate("network_interface_maxwait"),
255          translate("network_interface_maxwait_desc")
256         )
257         maxwait.optional = true
258         maxwait:depends("proto", "3g")
259 end
260
261 s2 = m:section(TypedSection, "alias", translate("aliases"))
262 s2.addremove = true
263
264 s2:depends("interface", arg[1])
265 s2.defaults.interface = arg[1]
266
267
268 s2.defaults.proto = "static"
269
270 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
271 ipaddr.rmempty = true
272
273 nm = s2:option(Value, "netmask", translate("netmask"))
274 nm.rmempty = true
275 nm:value("255.255.255.0")
276 nm:value("255.255.0.0")
277 nm:value("255.0.0.0")
278
279 gw = s2:option(Value, "gateway", translate("gateway"))
280 gw.rmempty = true
281
282 bcast = s2:option(Value, "bcast", translate("broadcast"))
283 bcast.optional = true
284
285 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
286 ip6addr.optional = true
287
288 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
289 ip6gw.optional = true
290
291 dns = s2:option(Value, "dns", translate("dnsserver"))
292 dns.optional = true
293
294 return m