2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
11 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.tools.webadmin", package.seeall)
17 require("luci.model.uci")
21 function byte_format(byte)
22 local suff = {"B", "KB", "MB", "GB", "TB"}
24 if byte > 1024 and i < 5 then
27 return string.format("%.2f %s", byte, suff[i])
32 function date_format(secs)
33 local suff = {"min", "h", "d"}
38 secs = math.floor(tonumber(secs))
40 mins = math.floor(secs / 60)
45 hour = math.floor(mins / 60)
50 days = math.floor(hour / 24)
55 return string.format("%dd %02dh %02dmin %02ds", days, hour, mins, secs)
57 return string.format("%02dh %02dmin %02ds", hour, mins, secs)
61 function network_get_addresses(net)
62 luci.model.uci.load_state("network")
64 local ipv4 = luci.model.uci.get("network", net, "ipaddr")
65 local mav4 = luci.model.uci.get("network", net, "netmask")
66 local ipv6 = luci.model.uci.get("network", net, "ip6addr")
69 ipv4 = luci.ip.IPv4(ipv4, mav4)
72 table.insert(addr, ipv4:string())
77 table.insert(addr, ipv6)
80 luci.model.uci.foreach("network", "alias",
82 if section.interface == net then
83 if section.ipaddr and section.netmask then
84 local ipv4 = luci.ip.IPv4(section.ipaddr, section.netmask)
87 table.insert(addr, ipv4:string())
91 if section.ip6addr then
92 table.insert(addr, section.ip6addr)
101 function cbi_add_networks(field)
102 luci.model.uci.foreach("network", "interface",
104 if section[".name"] ~= "loopback" then
105 field:value(section[".name"])
109 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
112 function cbi_add_knownips(field)
113 for i, dataset in ipairs(luci.sys.net.arptable()) do
114 field:value(dataset["IP address"])
118 function network_get_zones(net)
119 if not luci.model.uci.load_state("firewall") then
125 luci.model.uci.foreach("firewall", "zone",
127 local znet = section.network or section.name
128 if luci.util.contains(luci.util.split(znet, " "), net) then
129 table.insert(zones, section.name)
137 function firewall_find_zone(name)
140 luci.model.uci.foreach("firewall", "zone",
142 if section.name == name then
143 find = section[".name"]
151 function iface_get_network(iface)
152 luci.model.uci.load_state("network")
155 luci.model.uci.foreach("network", "interface",
157 local ifname = luci.model.uci.get(
158 "network", section[".name"], "ifname"
161 if iface == ifname then
162 net = section[".name"]