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