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 mins = math.floor(secs / 60)
43 hour = math.floor(mins / 60)
48 days = math.floor(hours / 24)
53 return string.format("%dd %02dh %02dmin %02ds", days, hour, mins, secs)
55 return string.format("%02dh %02dmin %02ds", hour, mins, secs)
59 function network_get_addresses(net)
61 local ipv4 = luci.model.uci.get_statevalue("network", net, "ipaddr")
62 local mav4 = luci.model.uci.get_statevalue("network", net, "netmask")
63 local ipv6 = luci.model.uci.get_statevalue("network", net, "ip6addr")
66 ipv4 = luci.ip.IPv4(ipv4, mav4)
69 table.insert(addr, ipv4:string())
74 table.insert(addr, ipv6)
77 luci.model.uci.foreach("network", "alias",
79 if section.interface == net then
80 if section.ipaddr and section.netmask then
81 local ipv4 = luci.ip.IPv4(section.ipaddr, section.netmask)
84 table.insert(addr, ipv4:string())
88 if section.ip6addr then
89 table.insert(addr, section.ip6addr)
98 function cbi_add_networks(field)
99 luci.model.uci.foreach("network", "interface",
101 if section[".name"] ~= "loopback" then
102 field:value(section[".name"])
106 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
109 function cbi_add_knownips(field)
110 for i, dataset in ipairs(luci.sys.net.arptable()) do
111 field:value(dataset["IP address"])
115 function network_get_zones(net)
116 if not luci.model.uci.load("firewall") then
122 luci.model.uci.foreach("firewall", "zone",
124 local znet = section.network or section.name
125 if luci.util.contains(luci.util.split(znet, " "), net) then
126 table.insert(zones, section.name)
134 function firewall_find_zone(name)
137 luci.model.uci.foreach("firewall", "zone",
139 if section.name == name then
140 find = section[".name"]
148 function iface_get_network(iface)
151 luci.model.uci.foreach("network", "interface",
153 local ifname = luci.model.uci.get_statevalue(
154 "network", section[".name"], "ifname"
157 if iface == ifname then
158 net = section[".name"]