* luci-0.8: backport dns server fix
[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.optional = true
121
122 mtu = s:option(Value, "mtu", "MTU")
123 mtu.optional = true
124 mtu.isinteger = true
125
126 mac = s:option(Value, "macaddr", translate("macaddress"))
127 mac.optional = true
128
129
130 srv = s:option(Value, "server", translate("network_interface_server"))
131 srv:depends("proto", "pptp")
132 srv.rmempty = true
133
134 service = s:option(ListValue, "service", translate("network_interface_service"))
135 service:value("umts", "UMTS/GPRS")
136 service:value("cdma", "CDMA")
137 service:value("evdo", "EV-DO")
138 service:depends("proto", "3g")
139
140 apn = s:option(Value, "apn", translate("network_interface_apn"))
141 apn:depends("proto", "3g")
142
143 pincode = s:option(Value, "pincode",
144  translate("network_interface_pincode"),
145  translate("network_interface_pincode_desc")
146 )
147 pincode:depends("proto", "3g")
148
149 user = s:option(Value, "username", translate("username"))
150 user.rmempty = true
151 user:depends("proto", "pptp")
152 user:depends("proto", "pppoe")
153 user:depends("proto", "ppp")
154 user:depends("proto", "3g")
155
156 pass = s:option(Value, "password", translate("password"))
157 pass.rmempty = true
158 pass:depends("proto", "pptp")
159 pass:depends("proto", "pppoe")
160 pass:depends("proto", "ppp")
161 pass:depends("proto", "3g")
162
163 ka = s:option(Value, "keepalive",
164  translate("network_interface_keepalive"),
165  translate("network_interface_keepalive_desc")
166 )
167 ka.optional = true
168 ka:depends("proto", "pptp")
169 ka:depends("proto", "pppoe")
170 ka:depends("proto", "ppp")
171 ka:depends("proto", "3g")
172
173 demand = s:option(Value, "demand",
174  translate("network_interface_demand"),
175  translate("network_interface_demand_desc")
176 )
177 demand.optional = true
178 demand:depends("proto", "pptp")
179 demand:depends("proto", "pppoe")
180 demand:depends("proto", "ppp")
181 demand:depends("proto", "3g")
182
183 device = s:option(Value, "device",
184  translate("network_interface_device"),
185  translate("network_interface_device_desc")
186 )
187 device:depends("proto", "ppp")
188 device:depends("proto", "3g")
189
190 defaultroute = s:option(Flag, "defaultroute",
191  translate("network_interface_defaultroute"),
192  translate("network_interface_defaultroute_desc")
193 )
194 defaultroute:depends("proto", "ppp")
195 defaultroute:depends("proto", "3g")
196
197 peerdns = s:option(Flag, "peerdns",
198  translate("network_interface_peerdns"),
199  translate("network_interface_peerdns_desc")
200 )
201 peerdns:depends("proto", "ppp")
202
203 ipv6 = s:option(Flag, "ipv6", translate("network_interface_ipv6") )
204 ipv6:depends("proto", "ppp")
205 --ipv6:depends("proto", "3g")
206
207 connect = s:option(Value, "connect",
208  translate("network_interface_connect"),
209  translate("network_interface_connect_desc")
210 )
211 connect.optional = true
212 connect:depends("proto", "ppp")
213 connect:depends("proto", "3g")
214
215 disconnect = s:option(Value, "disconnect",
216  translate("network_interface_disconnect"),
217  translate("network_interface_disconnect_desc")
218 )
219 disconnect.optional = true
220 disconnect:depends("proto", "ppp")
221 disconnect:depends("proto", "3g")
222
223 pppd_options = s:option(Value, "pppd_options",
224  translate("network_interface_pppd_options"),
225  translate("network_interface_pppd_options_desc")
226 )
227 pppd_options.optional = true
228 pppd_options:depends("proto", "ppp")
229 pppd_options:depends("proto", "3g")
230
231 maxwait = s:option(Value, "maxwait",
232  translate("network_interface_maxwait"),
233  translate("network_interface_maxwait_desc")
234 )
235 maxwait.optional = true
236 maxwait:depends("proto", "3g")
237
238
239 s2 = m:section(TypedSection, "alias", translate("aliases"))
240 s2.addremove = true
241
242 s2:depends("interface", arg[1])
243 s2.defaults.interface = arg[1]
244
245
246 s2.defaults.proto = "static"
247
248 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
249 ipaddr.rmempty = true
250
251 nm = s2:option(Value, "netmask", translate("netmask"))
252 nm.rmempty = true
253 nm:value("255.255.255.0")
254 nm:value("255.255.0.0")
255 nm:value("255.0.0.0")
256
257 gw = s2:option(Value, "gateway", translate("gateway"))
258 gw.rmempty = true
259
260 bcast = s2:option(Value, "bcast", translate("broadcast"))
261 bcast.optional = true
262
263 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
264 ip6addr.optional = true
265
266 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
267 ip6gw.optional = true
268
269 dns = s2:option(Value, "dns", translate("dnsserver"))
270 dns.optional = true
271
272 return m