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