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.netdiscover_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
32 local netdiscover_uci = luci.model.uci.cursor()
33 netdiscover_uci:load("luci_devinfo")
34 local nettable = netdiscover_uci:get_all("luci_devinfo")
42 i = next(nettable, nil)
45 if (netdiscover_uci:get("luci_devinfo", i) == "netdiscover_scannet") then
46 local scannet = netdiscover_uci:get_all("luci_devinfo", i)
47 if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
50 outrow["interface"] = scannet["interface"]
51 outrow["timeout"] = 10
52 local timeout = tonumber(scannet["timeout"])
53 if timeout and ( timeout > 0 ) then
54 outrow["timeout"] = scannet["timeout"]
57 outrow["repeat_count"] = 1
58 local repcount = tonumber(scannet["repeat_count"])
59 if repcount and ( repcount > 0 ) then
60 outrow["repeat_count"] = scannet["repeat_count"]
63 outrow["sleepreq"] = 100
64 local repcount = tonumber(scannet["sleepreq"])
65 if repcount and ( repcount > 0 ) then
66 outrow["sleepreq"] = scannet["sleepreq"]
69 outrow["subnet"] = scannet["subnet"]
70 outrow["output"] = output
79 function command_function(outnets, i)
80 local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
82 return "/usr/bin/netdiscover-to-devinfo " .. outnets[i]["subnet"] .. " " .. interface .. " " .. outnets[i]["timeout"] .. " -r " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
85 function action_links(netdiscovermap, mini)
86 luci.i18n.loadc("diag_devinfo")
87 s = netdiscovermap:section(SimpleSection, "", translate("Actions"))
88 b = s:option(DummyValue, "_config", translate("Configure Scans"))
91 b.titleref = luci.dispatcher.build_url("mini", "network", "netdiscover_devinfo_config")
93 b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "netdiscover_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", "netdiscover_devinfo")
100 b.titleref = luci.dispatcher.build_url("admin", "status", "netdiscover_devinfo")