mini: Force network interface to not be removable
[project/luci.git] / modules / admin-mini / luasrc / model / cbi / mini / network.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 require("luci.sys")
17
18 local network = luci.model.uci.cursor_state():get_all("network")
19
20 local netstat = luci.sys.net.deviceinfo()
21 local ifaces = {}
22
23 for k, v in pairs(network) do
24         if v[".type"] == "interface" and k ~= "loopback" then
25                 table.insert(ifaces, v)
26         end
27 end
28
29 m = Map("network", translate("network"))
30 s = m:section(Table, ifaces, translate("status"))
31 s.parse = function() end
32
33 s:option(DummyValue, ".name", translate("network"))
34
35 hwaddr = s:option(DummyValue, "_hwaddr",
36  translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc"))
37 function hwaddr.cfgvalue(self, section)
38         local ix = self.map:get(section, "ifname") or ""
39         return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
40 end
41
42
43 s:option(DummyValue, "ipaddr", translate("ipaddress"))
44
45 s:option(DummyValue, "netmask", translate("netmask"))
46
47
48 txrx = s:option(DummyValue, "_txrx",
49  translate("network_interface_txrx"), translate("network_interface_txrx_desc"))
50
51 function txrx.cfgvalue(self, section)
52         local ix = self.map:get(section, "ifname")
53         
54         local rx = netstat and netstat[ix] and netstat[ix][1]
55         rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
56         
57         local tx = netstat and netstat[ix] and netstat[ix][9]
58         tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
59         
60         return string.format("%s / %s", tx, rx)
61 end
62
63 errors = s:option(DummyValue, "_err",
64  translate("network_interface_err"), translate("network_interface_err_desc"))
65
66 function errors.cfgvalue(self, section)
67         local ix = self.map:get(section, "ifname")
68         
69         local rx = netstat and netstat[ix] and netstat[ix][3]
70         local tx = netstat and netstat[ix] and netstat[ix][11]
71         
72         rx = rx and tostring(rx) or "-"
73         tx = tx and tostring(tx) or "-"
74         
75         return string.format("%s / %s", tx, rx)
76 end
77
78
79
80 s = m:section(NamedSection, "lan", "interface", translate("m_n_local"))
81 s.addremove = false
82 s:option(Value, "ipaddr", translate("ipaddress"))
83
84 nm = s:option(Value, "netmask", translate("netmask"))
85 nm:value("255.255.255.0")
86 nm:value("255.255.0.0")
87 nm:value("255.0.0.0")
88
89 gw = s:option(Value, "gateway", translate("gateway") .. translate("cbi_optional"))
90 gw.rmempty = true
91 dns = s:option(Value, "dns", translate("dnsserver") .. translate("cbi_optional"))
92 dns.rmempty = true
93
94
95 s = m:section(NamedSection, "wan", "interface", translate("m_n_inet"))
96 s.addremove = false
97 p = s:option(ListValue, "proto", translate("protocol"))
98 p:value("none", "disabled")
99 p:value("static", translate("manual", "manual"))
100 p:value("dhcp", translate("automatic", "automatic"))
101 p:value("pppoe", "PPPoE")
102 p:value("pptp", "PPTP")
103
104 ip = s:option(Value, "ipaddr", translate("ipaddress"))
105 ip:depends("proto", "static")
106
107 nm = s:option(Value, "netmask", translate("netmask"))
108 nm:depends("proto", "static")
109
110 gw = s:option(Value, "gateway", translate("gateway"))
111 gw:depends("proto", "static")
112 gw.rmempty = true
113
114 dns = s:option(Value, "dns", translate("dnsserver"))
115 dns:depends("proto", "static")
116 dns.rmempty = true
117
118 usr = s:option(Value, "username", translate("username"))
119 usr:depends("proto", "pppoe")
120 usr:depends("proto", "pptp")
121
122 pwd = s:option(Value, "password", translate("password"))
123 pwd:depends("proto", "pppoe")
124 pwd:depends("proto", "pptp")
125
126 kea = s:option(Flag, "keepalive", translate("m_n_keepalive"))
127 kea:depends("proto", "pppoe")
128 kea:depends("proto", "pptp")
129 kea.rmempty = true
130 kea.enabled = "10"
131
132
133 cod = s:option(Value, "demand", translate("m_n_dialondemand"), "s")
134 cod:depends("proto", "pppoe")
135 cod:depends("proto", "pptp")
136 cod.rmempty = true
137
138 srv = s:option(Value, "server", translate("m_n_pptp_server"))
139 srv:depends("proto", "pptp")
140 srv.rmempty = true
141
142
143
144 return m