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