* luci/modules/admin-full: make custom dns servers selectable for any interface protocol
[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 service = s:option(ListValue, "service", translate("network_interface_service"))
149 service:value("umts", "UMTS/GPRS")
150 service:value("cdma", "CDMA")
151 service:value("evdo", "EV-DO")
152 service:depends("proto", "3g")
153
154 apn = s:option(Value, "apn", translate("network_interface_apn"))
155 apn:depends("proto", "3g")
156
157 pincode = s:option(Value, "pincode",
158 translate("network_interface_pincode"),
159 translate("network_interface_pincode_desc")
160 )
161 pincode:depends("proto", "3g")
162
163 user = s:option(Value, "username", translate("username"))
164 user.rmempty = true
165 user:depends("proto", "pptp")
166 user:depends("proto", "pppoe")
167 user:depends("proto", "ppp")
168 user:depends("proto", "3g")
169
170 pass = s:option(Value, "password", translate("password"))
171 pass.rmempty = true
172 pass.password = true
173 pass:depends("proto", "pptp")
174 pass:depends("proto", "pppoe")
175 pass:depends("proto", "ppp")
176 pass:depends("proto", "3g")
177
178 ka = s:option(Value, "keepalive",
179 translate("network_interface_keepalive"),
180 translate("network_interface_keepalive_desc")
181 )
182 ka.optional = true
183 ka:depends("proto", "pptp")
184 ka:depends("proto", "pppoe")
185 ka:depends("proto", "ppp")
186 ka:depends("proto", "3g")
187
188 demand = s:option(Value, "demand",
189 translate("network_interface_demand"),
190 translate("network_interface_demand_desc")
191 )
192 demand.optional = true
193 demand:depends("proto", "pptp")
194 demand:depends("proto", "pppoe")
195 demand:depends("proto", "ppp")
196 demand:depends("proto", "3g")
197
198 device = s:option(Value, "device",
199 translate("network_interface_device"),
200 translate("network_interface_device_desc")
201 )
202 device:depends("proto", "ppp")
203 device:depends("proto", "3g")
204
205 defaultroute = s:option(Flag, "defaultroute",
206 translate("network_interface_defaultroute"),
207 translate("network_interface_defaultroute_desc")
208 )
209 defaultroute:depends("proto", "ppp")
210 defaultroute:depends("proto", "3g")
211
212 peerdns = s:option(Flag, "peerdns",
213 translate("network_interface_peerdns"),
214 translate("network_interface_peerdns_desc")
215 )
216 peerdns:depends("proto", "ppp")
217
218 ipv6 = s:option(Flag, "ipv6", translate("network_interface_ipv6") )
219 ipv6:depends("proto", "ppp")
220 --ipv6:depends("proto", "3g")
221
222 connect = s:option(Value, "connect",
223 translate("network_interface_connect"),
224 translate("network_interface_connect_desc")
225 )
226 connect.optional = true
227 connect:depends("proto", "ppp")
228 connect:depends("proto", "3g")
229
230 disconnect = s:option(Value, "disconnect",
231 translate("network_interface_disconnect"),
232 translate("network_interface_disconnect_desc")
233 )
234 disconnect.optional = true
235 disconnect:depends("proto", "ppp")
236 disconnect:depends("proto", "3g")
237
238 pppd_options = s:option(Value, "pppd_options",
239 translate("network_interface_pppd_options"),
240 translate("network_interface_pppd_options_desc")
241 )
242 pppd_options.optional = true
243 pppd_options:depends("proto", "ppp")
244 pppd_options:depends("proto", "3g")
245
246 maxwait = s:option(Value, "maxwait",
247 translate("network_interface_maxwait"),
248 translate("network_interface_maxwait_desc")
249 )
250 maxwait.optional = true
251 maxwait:depends("proto", "3g")
252
253
254 s2 = m:section(TypedSection, "alias", translate("aliases"))
255 s2.addremove = true
256
257 s2:depends("interface", arg[1])
258 s2.defaults.interface = arg[1]
259
260
261 s2.defaults.proto = "static"
262
263 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
264 ipaddr.rmempty = true
265
266 nm = s2:option(Value, "netmask", translate("netmask"))
267 nm.rmempty = true
268 nm:value("255.255.255.0")
269 nm:value("255.255.0.0")
270 nm:value("255.0.0.0")
271
272 gw = s2:option(Value, "gateway", translate("gateway"))
273 gw.rmempty = true
274
275 bcast = s2:option(Value, "bcast", translate("broadcast"))
276 bcast.optional = true
277
278 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
279 ip6addr.optional = true
280
281 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
282 ip6gw.optional = true
283
284 dns = s2:option(Value, "dns", translate("dnsserver"))
285 dns.optional = true
286
287 return m