modules/admin-full: Added support for interface aliases
[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
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
15
16 s = m:section(TypedSection, "interface", translate("interfaces"))
17 function s.filter(self, section)
18         return section ~= "loopback" and
19          (not arg or not arg[1] or arg[1] == section)
20 end
21
22 if not arg or not arg[1] then
23         s.addremove = true
24 end
25 s:depends("proto", "static")
26 s:depends("proto", "dhcp")
27
28 p = s:option(ListValue, "proto", translate("protocol"))
29 p:value("static", translate("static"))
30 p:value("dhcp", "DHCP")
31 p.default = "static"
32
33 br = s:option(Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
34 br.enabled = "bridge"
35 br.rmempty = true
36
37 ifname = s:option(Value, "ifname", translate("interface"))
38 ifname.rmempty = true
39 for i,d in ipairs(luci.sys.net.devices()) do
40         if d ~= "lo" then
41                 ifname:value(d)
42         end
43 end
44
45
46 ipaddr = s:option(Value, "ipaddr", translate("ipaddress"))
47 ipaddr.rmempty = true
48 ipaddr:depends("proto", "static")
49
50 nm = s:option(Value, "netmask", translate("netmask"))
51 nm.rmempty = true
52 nm:depends("proto", "static")
53 nm:value("255.255.255.0")
54 nm:value("255.255.0.0")
55 nm:value("255.0.0.0")
56
57 gw = s:option(Value, "gateway", translate("gateway"))
58 gw:depends("proto", "static")
59 gw.rmempty = true
60
61 bcast = s:option(Value, "bcast", translate("broadcast"))
62 bcast:depends("proto", "static")
63 bcast.optional = true
64
65 ip6addr = s:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
66 ip6addr.optional = true
67 ip6addr:depends("proto", "static")
68
69 ip6gw = s:option(Value, "ip6gw", translate("gateway6"))
70 ip6gw:depends("proto", "static")
71 ip6gw.optional = true
72
73 dns = s:option(Value, "dns", translate("dnsserver"))
74 dns:depends("proto", "static")
75 dns.optional = true
76
77 mtu = s:option(Value, "mtu", "MTU")
78 mtu.optional = true
79 mtu.isinteger = true
80
81 mac = s:option(Value, "macaddr", translate("macaddress"))
82 mac.optional = true
83
84
85
86
87 s2 = m:section(TypedSection, "alias", translate("aliases"))
88 s2.addremove = true
89
90 if arg and arg[1] and luci.model.uci.get("network", arg[1]) then
91         s2:depends("interface", arg[1])
92         s2.defaults.interface = arg[1]
93 else
94         parent = s2:option(ListValue, "interface", translate("interface"))
95         luci.model.uci.foreach("network", "interface",
96                 function (section)
97                         if section[".name"] ~= "loopback" then
98                                 parent:value(section[".name"])
99                         end
100                 end
101         )
102 end
103
104
105 s2.defaults.proto = "static"
106
107 ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
108 ipaddr.rmempty = true
109
110 nm = s2:option(Value, "netmask", translate("netmask"))
111 nm.rmempty = true
112 nm:value("255.255.255.0")
113 nm:value("255.255.0.0")
114 nm:value("255.0.0.0")
115
116 gw = s2:option(Value, "gateway", translate("gateway"))
117 gw.rmempty = true
118
119 bcast = s2:option(Value, "bcast", translate("broadcast"))
120 bcast.optional = true
121
122 ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
123 ip6addr.optional = true
124
125 ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
126 ip6gw.optional = true
127
128 dns = s2:option(Value, "dns", translate("dnsserver"))
129 dns.optional = true
130
131 return m