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)
60 luci.model.uci.load_state("network")
62 local ipv4 = luci.model.uci.get("network", net, "ipaddr")
63 local mav4 = luci.model.uci.get("network", net, "netmask")
64 local ipv6 = luci.model.uci.get("network", net, "ip6addr")
67 ipv4 = luci.ip.IPv4(ipv4, mav4)
70 table.insert(addr, ipv4:string())
75 table.insert(addr, ipv6)
78 luci.model.uci.foreach("network", "alias",
80 if section.interface == net then
81 if section.ipaddr and section.netmask then
82 local ipv4 = luci.ip.IPv4(section.ipaddr, section.netmask)
85 table.insert(addr, ipv4:string())
89 if section.ip6addr then
90 table.insert(addr, section.ip6addr)
99 function cbi_add_networks(field)
100 luci.model.uci.foreach("network", "interface",
102 if section[".name"] ~= "loopback" then
103 field:value(section[".name"])
107 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
110 function cbi_add_knownips(field)
111 for i, dataset in ipairs(luci.sys.net.arptable()) do
112 field:value(dataset["IP address"])
116 function network_get_zones(net)
117 if not luci.model.uci.load_state("firewall") then
123 luci.model.uci.foreach("firewall", "zone",
125 local znet = section.network or section.name
126 if luci.util.contains(luci.util.split(znet, " "), net) then
127 table.insert(zones, section.name)
135 function firewall_find_zone(name)
138 luci.model.uci.foreach("firewall", "zone",
140 if section.name == name then
141 find = section[".name"]
149 function iface_get_network(iface)
150 luci.model.uci.load_state("network")
153 luci.model.uci.foreach("network", "interface",
155 local ifname = luci.model.uci.get(
156 "network", section[".name"], "ifname"
159 if iface == ifname then
160 net = section[".name"]