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