5470b8a241d1463067bf9500e0252947e11cf877
[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                 m.uci:load("firewall")
53                 m.uci:foreach("firewall", "zone",
54                         function (section)
55                                 fwzone:value(section.name)
56                         end
57                 )
58                 
59                 function fwzone.write(self, section, value)     
60                         local zone = luci.tools.webadmin.firewall_find_zone(value)
61                         local stat
62                         
63                         if not zone then
64                                 stat = m.uci:section("firewall", "zone", nil, {
65                                         name = value,
66                                         network = section
67                                 })
68                         else
69                                 local net = m.uci:get("firewall", zone, "network")
70                                 net = (net or value) .. " " .. section
71                                 stat = m.uci:set("firewall", zone, "network", net)
72                         end
73                         
74                         if stat then
75                                 self.render = function() end
76                         end
77                 end
78         else
79                 fwzone = s:option(DummyValue, "_fwzone", translate("zone"))
80                 fwzone.value = table.concat(zones, ", ")
81         end
82         fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
83         m.uci:unload("firewall")
84 end
85
86 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
87 ipaddr.rmempty = true
88 ipaddr:depends("proto", "static")
89
90 nm = s:option(Value, "netmask", translate("netmask"))
91 nm.rmempty = true
92 nm:depends("proto", "static")
93 nm:value("255.255.255.0")
94 nm:value("255.255.0.0")
95 nm:value("255.0.0.0")
96
97 gw = s:option(Value, "gateway", translate("gateway"))
98 gw:depends("proto", "static")
99 gw.rmempty = true
100
101 bcast = s:option(Value, "bcast", translate("broadcast"))
102 bcast:depends("proto", "static")
103 bcast.optional = true
104
105 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
106 ip6addr.optional = true
107 ip6addr:depends("proto", "static")
108
109 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
110 ip6gw:depends("proto", "static")
111 ip6gw.optional = true
112
113 dns = s:option(Value, "dns", translate("dnsserver"))
114 dns:depends("proto", "static")
115 dns.optional = true
116
117 mtu = s:option(Value, "mtu", "MTU")
118 mtu.optional = true
119 mtu.isinteger = true
120
121 mac = s:option(Value, "macaddr", translate("macaddress"))
122 mac.optional = true
123
124
125 srv = s:option(Value, "server", translate("network_interface_server"))
126 srv:depends("proto", "pptp")
127 srv.rmempty = true
128
129 user = s:option(Value, "username", translate("username"))
130 user.rmempty = true
131 user:depends("proto", "pptp")
132 user:depends("proto", "pppoe")
133
134 pass = s:option(Value, "password", translate("password"))
135 pass.rmempty = true
136 pass:depends("proto", "pptp")
137 pass:depends("proto", "pppoe")
138
139 ka = s:option(Value, "keepalive",
140  translate("network_interface_keepalive"),
141  translate("network_interface_keepalive_desc")
142 )
143 ka.rmempty = true
144 ka:depends("proto", "pptp")
145 ka:depends("proto", "pppoe")
146
147 demand = s:option(Value, "demand", 
148  translate("network_interface_demand"),
149  translate("network_interface_demand_desc")
150 )
151 demand.rmempty = true
152 demand:depends("proto", "pptp")
153 demand:depends("proto", "pppoe")
154
155
156
157
158 s2 = m:section(TypedSection, "alias", translate("aliases"))
159 s2.addremove = true
160
161 s2:depends("interface", arg[1])
162 s2.defaults.interface = arg[1]
163
164
165 s2.defaults.proto = "static"
166
167 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
168 ipaddr.rmempty = true
169
170 nm = s2:option(Value, "netmask", translate("netmask"))
171 nm.rmempty = true
172 nm:value("255.255.255.0")
173 nm:value("255.255.0.0")
174 nm:value("255.0.0.0")
175
176 gw = s2:option(Value, "gateway", translate("gateway"))
177 gw.rmempty = true
178
179 bcast = s2:option(Value, "bcast", translate("broadcast"))
180 bcast.optional = true
181
182 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
183 ip6addr.optional = true
184
185 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
186 ip6gw.optional = true
187
188 dns = s2:option(Value, "dns", translate("dnsserver"))
189 dns.optional = true
190
191 return m