1 -- Copyright 2009 Daniel Dickinson
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.controller.luci_diag.netdiscover_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 netdiscover_uci = luci.model.uci.cursor()
23 netdiscover_uci:load("luci_devinfo")
24 local nettable = netdiscover_uci:get_all("luci_devinfo")
32 i = next(nettable, nil)
35 if (netdiscover_uci:get("luci_devinfo", i) == "netdiscover_scannet") then
36 local scannet = netdiscover_uci:get_all("luci_devinfo", i)
37 if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
40 outrow["interface"] = scannet["interface"]
41 outrow["timeout"] = 10
42 local timeout = tonumber(scannet["timeout"])
43 if timeout and ( timeout > 0 ) then
44 outrow["timeout"] = scannet["timeout"]
47 outrow["repeat_count"] = 1
48 local repcount = tonumber(scannet["repeat_count"])
49 if repcount and ( repcount > 0 ) then
50 outrow["repeat_count"] = scannet["repeat_count"]
53 outrow["sleepreq"] = 100
54 local repcount = tonumber(scannet["sleepreq"])
55 if repcount and ( repcount > 0 ) then
56 outrow["sleepreq"] = scannet["sleepreq"]
59 outrow["subnet"] = scannet["subnet"]
60 outrow["output"] = output
69 function command_function(outnets, i)
70 local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
72 return "/usr/bin/netdiscover-to-devinfo " .. outnets[i]["subnet"] .. " " .. interface .. " " .. outnets[i]["timeout"] .. " -r " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
75 function action_links(netdiscovermap, mini)
76 s = netdiscovermap:section(SimpleSection, "", translate("Actions"))
77 b = s:option(DummyValue, "_config", translate("Configure Scans"))
80 b.titleref = luci.dispatcher.build_url("mini", "network", "netdiscover_devinfo_config")
82 b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "netdiscover_devinfo_config")
84 b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
87 b.titleref = luci.dispatcher.build_url("mini", "diag", "netdiscover_devinfo")
89 b.titleref = luci.dispatcher.build_url("admin", "status", "netdiscover_devinfo")