3 Luci diag - Diagnostics controller module
4 (c) 2009 Daniel Dickinson
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.luci_diag.devinfo_common", package.seeall)
20 require("luci.model.uci")
22 local translate = luci.i18n.translate
23 local DummyValue = luci.cbi.DummyValue
24 local SimpleSection = luci.cbi.SimpleSection
30 function run_processes(outnets, cmdfunc)
31 i = next(outnets, nil)
33 outnets[i]["output"] = luci.sys.exec(cmdfunc(outnets, i))
38 function parse_output(devmap, outnets, haslink, type, mini, debug)
39 local curnet = next(outnets, nil)
41 luci.i18n.loadc("diag_devinfo")
44 local output = outnets[curnet]["output"]
45 local subnet = outnets[curnet]["subnet"]
46 local ports = outnets[curnet]["ports"]
47 local interface = outnets[curnet]["interface"]
49 devlines = luci.util.split(output)
52 table.insert(devlines, output)
58 local found_a_device = false
61 if devlines[j] and ( devlines[j] ~= "" ) then
65 devtable = luci.util.split(devlines[j], ' | ')
66 row["ip"] = devtable[1]
68 row["mac"] = devtable[2]
70 if ( devtable[4] == 'unknown' ) then
71 row["vendor"] = devtable[3]
73 row["vendor"] = devtable[4]
75 row["type"] = devtable[5]
77 row["model"] = devtable[6]
80 row["config_page"] = devtable[7]
84 row["raw"] = devlines[j]
86 table.insert(netdevs, row)
90 if not found_a_device then
96 if (type == "smap") then
97 row["vendor"] = luci.i18n.translate("No SIP devices")
99 row["vendor"] = luci.i18n.translate("No devices detected")
101 row["type"] = luci.i18n.translate("check other networks")
106 row["config_page"] = ""
111 table.insert(netdevs, row)
114 if (type == "smap") then
116 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("SIP devices discovered for") .. " " .. curnet)
118 local interfacestring = ""
119 if ( interface ~= "" ) then
120 interfacestring = ", " .. interface
122 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("SIP devices discovered for") .. " " .. curnet .. " (" .. subnet .. ":" .. ports .. interfacestring .. ")")
124 s.template = "diag/smapsection"
127 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("Devices discovered for") .. " " .. curnet)
129 local interfacestring = ""
130 if ( interface ~= "" ) then
131 interfacestring = ", " .. interface
133 s = devmap:section(luci.cbi.Table, netdevs, luci.i18n.translate("Devices discovered for") .. " " .. curnet .. " (" .. subnet .. interfacestring .. ")")
136 s:option(DummyValue, "ip", translate("IP Address"))
138 s:option(DummyValue, "mac", translate("MAC Address"))
140 s:option(DummyValue, "vendor", translate("Vendor"))
141 s:option(DummyValue, "type", translate("Device Type"))
143 s:option(DummyValue, "model", translate("Model"))
146 s:option(DummyValue, "config_page", translate("Link to Device"))
149 s:option(DummyValue, "raw", translate("Raw"))
151 curnet = next(outnets, curnet)
155 function get_network_device(interface)
156 local state = luci.model.uci.cursor_state()
157 state:load("network")
160 return state:get("network", interface, "ifname")
164 function cbi_add_networks(field)
165 uci.cursor():foreach("network", "interface",
167 if section[".name"] ~= "loopback" then
168 field:value(section[".name"])
172 field.titleref = luci.dispatcher.build_url("admin", "network", "network")
175 function config_devinfo_scan(map, scannet)
177 o = scannet:option(luci.cbi.Flag, "enable", translate("Enable"))
181 o = scannet:option(luci.cbi.Value, "interface", translate("Interface"))
183 luci.controller.luci_diag.devinfo_common.cbi_add_networks(o)
186 scansubnet = scannet:option(luci.cbi.Value, "subnet", translate("Subnet"))
187 scansubnet.optional = false
189 o = scannet:option(luci.cbi.Value, "timeout", translate("Timeout"), translate("Time to wait for responses in seconds (default 10)"))
192 o = scannet:option(luci.cbi.Value, "repeat_count", translate("Repeat Count"), translate("Number of times to send requests (default 1)"))
195 o = scannet:option(luci.cbi.Value, "sleepreq", translate("Sleep Between Requests"), translate("Milliseconds to sleep between requests (default 100)"))