Minor bugfixes
[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 luci.model.uci.load_state("network")
19 local network = luci.model.uci.get_all("network")
20 luci.model.uci.unload("network")
21
22 local netstat = luci.sys.net.deviceinfo()
23 local ifaces = {}
24
25 for k, v in pairs(network) do
26         if v[".type"] == "interface" and k ~= "loopback" then
27                 table.insert(ifaces, v)
28         end
29 end
30
31 m = Map("network", translate("network"))
32 s = m:section(Table, ifaces, translate("status"))
33 s.parse = function() end
34
35 s:option(DummyValue, ".name", translate("network"))
36
37 hwaddr = s:option(DummyValue, "_hwaddr",
38  translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc"))
39 function hwaddr.cfgvalue(self, section)
40         local ix = self.map:get(section, "ifname") or ""
41         return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
42 end
43
44
45 s:option(DummyValue, "ipaddr", translate("ipaddress"))
46
47 s:option(DummyValue, "netmask", translate("netmask"))
48
49
50 txrx = s:option(DummyValue, "_txrx",
51  translate("network_interface_txrx"), translate("network_interface_txrx_desc"))
52
53 function txrx.cfgvalue(self, section)
54         local ix = self.map:get(section, "ifname")
55         
56         local rx = netstat and netstat[ix] and netstat[ix][1]
57         rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
58         
59         local tx = netstat and netstat[ix] and netstat[ix][9]
60         tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
61         
62         return string.format("%s / %s", tx, rx)
63 end
64
65 errors = s:option(DummyValue, "_err",
66  translate("network_interface_err"), translate("network_interface_err_desc"))
67
68 function errors.cfgvalue(self, section)
69         local ix = self.map:get(section, "ifname")
70         
71         local rx = netstat and netstat[ix] and netstat[ix][3]
72         local tx = netstat and netstat[ix] and netstat[ix][11]
73         
74         rx = rx and tostring(rx) or "-"
75         tx = tx and tostring(tx) or "-"
76         
77         return string.format("%s / %s", tx, rx)
78 end
79
80
81
82 s = m:section(NamedSection, "lan", "interface", translate("m_n_local"))
83 s:option(Value, "ipaddr", translate("ipaddress"))
84
85 nm = s:option(Value, "netmask", translate("netmask"))
86 nm:value("255.255.255.0")
87 nm:value("255.255.0.0")
88 nm:value("255.0.0.0")
89
90 gw = s:option(Value, "gateway", translate("gateway") .. translate("cbi_optional"))
91 gw.rmempty = true
92 dns = s:option(Value, "dns", translate("dnsserver") .. translate("cbi_optional"))
93 dns.rmempty = true
94
95
96 s = m:section(NamedSection, "wan", "interface", translate("m_n_inet"))
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