1a41ed271e0fdf680b993210f0df143c1767886e
[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 p = s:option(ListValue, "proto", translate("protocol"))
23 p:value("static", translate("static"))
24 p:value("dhcp", "DHCP")
25 p:value("pppoe", "PPPoE")
26 p:value("pptp", "PPTP")
27 p.default = "static"
28
29 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
30 br.enabled = "bridge"
31 br.rmempty = true
32
33 ifname = s:option(Value, "ifname", translate("interface"))
34 ifname.rmempty = true
35 for i,d in ipairs(luci.sys.net.devices()) do
36         if d ~= "lo" then
37                 ifname:value(d)
38         end
39 end
40
41 local zones = luci.tools.webadmin.network_get_zones(arg[1])
42 if zones then 
43         if #zones == 0 then
44                 m:chain("firewall")
45                 
46                 fwzone = s:option(Value, "_fwzone", 
47                         translate("network_interface_fwzone"),
48                         translate("network_interface_fwzone_desc"))
49                 fwzone.rmempty = true
50                 fwzone:value("", "- " .. translate("none") .. " -")
51                 fwzone:value(arg[1])
52                 luci.model.uci.foreach("firewall", "zone",
53                         function (section)
54                                 fwzone:value(section.name)
55                         end
56                 )
57                 
58                 function fwzone.write(self, section, value)     
59                         local zone = luci.tools.webadmin.firewall_find_zone(value)
60                         local stat
61                         
62                         if not zone then
63                                 stat = luci.model.uci.section("firewall", "zone", nil, {
64                                         name = value,
65                                         network = section
66                                 })
67                         else
68                                 local net = luci.model.uci.get("firewall", zone, "network")
69                                 net = (net or value) .. " " .. section
70                                 stat = luci.model.uci.set("firewall", zone, "network", net)
71                         end
72                         
73                         if stat then
74                                 self.render = function() end
75                         end
76                 end
77         else
78                 fwzone = s:option(DummyValue, "_fwzone", translate("zone"))
79                 fwzone.value = table.concat(zones, ", ")
80         end
81         fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
82 end
83
84 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
85 ipaddr.rmempty = true
86 ipaddr:depends("proto", "static")
87
88 nm = s:option(Value, "netmask", translate("netmask"))
89 nm.rmempty = true
90 nm:depends("proto", "static")
91 nm:value("255.255.255.0")
92 nm:value("255.255.0.0")
93 nm:value("255.0.0.0")
94
95 gw = s:option(Value, "gateway", translate("gateway"))
96 gw:depends("proto", "static")
97 gw.rmempty = true
98
99 bcast = s:option(Value, "bcast", translate("broadcast"))
100 bcast:depends("proto", "static")
101 bcast.optional = true
102
103 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
104 ip6addr.optional = true
105 ip6addr:depends("proto", "static")
106
107 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
108 ip6gw:depends("proto", "static")
109 ip6gw.optional = true
110
111 dns = s:option(Value, "dns", translate("dnsserver"))
112 dns:depends("proto", "static")
113 dns.optional = true
114
115 mtu = s:option(Value, "mtu", "MTU")
116 mtu.optional = true
117 mtu.isinteger = true
118
119 mac = s:option(Value, "macaddr", translate("macaddress"))
120 mac.optional = true
121
122
123 srv = s:option(Value, "server", translate("network_interface_server"))
124 srv:depends("proto", "pptp")
125 srv.rmempty = true
126
127 user = s:option(Value, "username", translate("username"))
128 user.rmempty = true
129 user:depends("proto", "pptp")
130 user:depends("proto", "pppoe")
131
132 pass = s:option(Value, "password", translate("password"))
133 pass.rmempty = true
134 pass:depends("proto", "pptp")
135 pass:depends("proto", "pppoe")
136
137 ka = s:option(Value, "keepalive",
138  translate("network_interface_keepalive"),
139  translate("network_interface_keepalive_desc")
140 )
141 ka.rmempty = true
142 ka:depends("proto", "pptp")
143 ka:depends("proto", "pppoe")
144
145 demand = s:option(Value, "demand", 
146  translate("network_interface_demand"),
147  translate("network_interface_demand_desc")
148 )
149 demand.rmempty = true
150 demand:depends("proto", "pptp")
151 demand:depends("proto", "pppoe")
152
153
154
155
156 s2 = m:section(TypedSection, "alias", translate("aliases"))
157 s2.addremove = true
158
159 s2:depends("interface", arg[1])
160 s2.defaults.interface = arg[1]
161
162
163 s2.defaults.proto = "static"
164
165 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
166 ipaddr.rmempty = true
167
168 nm = s2:option(Value, "netmask", translate("netmask"))
169 nm.rmempty = true
170 nm:value("255.255.255.0")
171 nm:value("255.255.0.0")
172 nm:value("255.0.0.0")
173
174 gw = s2:option(Value, "gateway", translate("gateway"))
175 gw.rmempty = true
176
177 bcast = s2:option(Value, "bcast", translate("broadcast"))
178 bcast.optional = true
179
180 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
181 ip6addr.optional = true
182
183 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
184 ip6gw.optional = true
185
186 dns = s2:option(Value, "dns", translate("dnsserver"))
187 dns.optional = true
188
189 return m