1 -- Copyright 2009 Daniel Dickinson
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.controller.luci_diag.devinfo_common", package.seeall)
10 require("luci.model.uci")
12 local translate = luci.i18n.translate
13 local DummyValue = luci.cbi.DummyValue
14 local SimpleSection = luci.cbi.SimpleSection
20 function run_processes(outnets, cmdfunc)
21 i = next(outnets, nil)
23 outnets[i]["output"] = luci.sys.exec(cmdfunc(outnets, i))
28 function parse_output(devmap, outnets, haslink, type, mini, debug)
29 local curnet = next(outnets, nil)
32 local output = outnets[curnet]["output"]
33 local subnet = outnets[curnet]["subnet"]
34 local ports = outnets[curnet]["ports"]
35 local interface = outnets[curnet]["interface"]
37 devlines = luci.util.split(output)
40 table.insert(devlines, output)
46 local found_a_device = false
49 if devlines[j] and ( devlines[j] ~= "" ) then
53 devtable = luci.util.split(devlines[j], ' | ')
54 row["ip"] = devtable[1]
56 row["mac"] = devtable[2]
58 if ( devtable[4] == 'unknown' ) then
59 row["vendor"] = devtable[3]
61 row["vendor"] = devtable[4]
63 row["type"] = devtable[5]
65 row["model"] = devtable[6]
68 row["config_page"] = devtable[7]
72 row["raw"] = devlines[j]
74 table.insert(netdevs, row)
78 if not found_a_device then
84 if (type == "smap") then
85 row["vendor"] = luci.i18n.translate("No SIP devices")
87 row["vendor"] = luci.i18n.translate("No devices detected")
89 row["type"] = luci.i18n.translate("check other networks")
94 row["config_page"] = ""
99 table.insert(netdevs, row)
102 if (type == "smap") then
104 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("SIP devices discovered for") .. " " .. curnet)
106 local interfacestring = ""
107 if ( interface ~= "" ) then
108 interfacestring = ", " .. interface
110 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("SIP devices discovered for") .. " " .. curnet .. " (" .. subnet .. ":" .. ports .. interfacestring .. ")")
112 s.template = "diag/smapsection"
115 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("Devices discovered for") .. " " .. curnet)
117 local interfacestring = ""
118 if ( interface ~= "" ) then
119 interfacestring = ", " .. interface
121 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("Devices discovered for") .. " " .. curnet .. " (" .. subnet .. interfacestring .. ")")
124 s:option(DummyValue, "ip", translate("IP Address"))
126 s:option(DummyValue, "mac", translate("MAC Address"))
128 s:option(DummyValue, "vendor", translate("Vendor"))
129 s:option(DummyValue, "type", translate("Device Type"))
131 s:option(DummyValue, "model", translate("Model"))
134 s:option(DummyValue, "config_page", translate("Link to Device"))
137 s:option(DummyValue, "raw", translate("Raw"))
139 curnet = next(outnets, curnet)
143 function get_network_device(interface)
144 local state = luci.model.uci.cursor_state()
145 state:load("network")
148 return state:get("network", interface, "ifname")
152 function cbi_add_networks(field)
153 uci.cursor():foreach("network", "interface",
155 if section[".name"] ~= "loopback" then
156 field:value(section[".name"])
160 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
163 function config_devinfo_scan(map, scannet)
165 o = scannet:option(luci.cbi.Flag, "enable", translate("Enable"))
169 o = scannet:option(luci.cbi.Value, "interface", translate("Interface"))
171 luci.controller.luci_diag.devinfo_common.cbi_add_networks(o)
174 scansubnet = scannet:option(luci.cbi.Value, "subnet", translate("Subnet"))
175 scansubnet.optional = false
177 o = scannet:option(luci.cbi.Value, "timeout", translate("Timeout"), translate("Time to wait for responses in seconds (default 10)"))
180 o = scannet:option(luci.cbi.Value, "repeat_count", translate("Repeat Count"), translate("Number of times to send requests (default 1)"))
183 o = scannet:option(luci.cbi.Value, "sleepreq", translate("Sleep Between Requests"), translate("Milliseconds to sleep between requests (default 100)"))