1 -- Copyright 2009 Daniel Dickinson
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.controller.luci_diag.smap_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
22 local smapnets_uci = luci.model.uci.cursor()
23 smapnets_uci:load("luci_devinfo")
24 local nettable = smapnets_uci:get_all("luci_devinfo")
32 i = next(nettable, nil)
35 if (smapnets_uci:get("luci_devinfo", i) == "smap_scannet") then
36 local scannet = smapnets_uci:get_all("luci_devinfo", i)
37 if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
40 outrow["subnet"] = scannet["subnet"]
42 if scannet["ports"] and ( scannet["ports"] ~= "" ) then
43 ports = scannet["ports"]
45 outrow["timeout"] = 10
46 local timeout = tonumber(scannet["timeout"])
47 if timeout and ( timeout > 0 ) then
48 outrow["timeout"] = scannet["timeout"]
51 outrow["repeat_count"] = 1
52 local repcount = tonumber(scannet["repeat_count"])
53 if repcount and ( repcount > 0 ) then
54 outrow["repeat_count"] = scannet["repeat_count"]
57 outrow["sleepreq"] = 100
58 local repcount = tonumber(scannet["sleepreq"])
59 if repcount and ( repcount > 0 ) then
60 outrow["sleepreq"] = scannet["sleepreq"]
63 if scannet["interface"] and ( scannet["interface"] ~= "" ) then
64 outrow["interface"] = scannet["interface"]
66 outrow["interface"] = ""
69 outrow["ports"] = ports
70 outrow["output"] = output
79 function command_function(outnets, i)
81 local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
83 return "/usr/bin/netsmap-to-devinfo -r " .. outnets[i]["subnet"] .. " -t " .. outnets[i]["timeout"] .. " -i " .. interface .. " -x -p " .. outnets[i]["ports"] .. " -c " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
86 function action_links(smapmap, mini)
87 s = smapmap:section(SimpleSection, "", translate("Actions"))
88 b = s:option(DummyValue, "_config", translate("Configure Scans"))
91 b.titleref = luci.dispatcher.build_url("mini", "voice", "phones", "phone_scan_config")
93 b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "smap_devinfo_config")
95 b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
98 b.titleref = luci.dispatcher.build_url("mini", "diag", "phone_scan")
100 b.titleref = luci.dispatcher.build_url("admin", "status", "smap_devinfo")