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 network_get_addresses(net)
34 local ipv4 = luci.model.uci.get_statevalue("network", net, "ipaddr")
35 local mav4 = luci.model.uci.get_statevalue("network", net, "netmask")
36 local ipv6 = luci.model.uci.get_statevalue("network", net, "ip6addr")
39 ipv4 = luci.ip.IPv4(ipv4, mav4)
42 table.insert(addr, ipv4:string())
47 table.insert(addr, ipv6)
50 luci.model.uci.foreach("network", "alias",
52 if section.interface == net then
53 if section.ipaddr and section.netmask then
54 local ipv4 = luci.ip.IPv4(section.ipaddr, section.netmask)
57 table.insert(addr, ipv4:string())
61 if section.ip6addr then
62 table.insert(addr, section.ip6addr)
71 function cbi_add_networks(field)
72 luci.model.uci.foreach("network", "interface",
74 if section[".name"] ~= "loopback" then
75 field:value(section[".name"])
79 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
82 function cbi_add_knownips(field)
83 for i, dataset in ipairs(luci.sys.net.arptable()) do
84 field:value(dataset["IP address"])
88 function network_get_zones(net)
89 if not luci.model.uci.load("firewall") then
95 luci.model.uci.foreach("firewall", "zone",
97 local znet = section.network or section.name
98 if luci.util.contains(luci.util.split(znet, " "), net) then
99 table.insert(zones, section.name)
107 function firewall_find_zone(name)
110 luci.model.uci.foreach("firewall", "zone",
112 if section.name == name then
113 find = section[".name"]
121 function iface_get_network(iface)
124 luci.model.uci.foreach("network", "interface",
126 local ifname = luci.model.uci.get_statevalue(
127 "network", section[".name"], "ifname"
130 if iface == ifname then
131 net = section[".name"]