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
29 local netdiscover_uci = luci.model.uci.cursor()
30 netdiscover_uci:load("luci_devinfo")
31 local nettable = netdiscover_uci:get_all("luci_devinfo")
39 i = next(nettable, nil)
42 if (netdiscover_uci:get("luci_devinfo", i) == "netdiscover_scannet") then
43 local scannet = netdiscover_uci:get_all("luci_devinfo", i)
44 if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
47 outrow["interface"] = scannet["interface"]
48 outrow["timeout"] = 10
49 local timeout = tonumber(scannet["timeout"])
50 if timeout and ( timeout > 0 ) then
51 outrow["timeout"] = scannet["timeout"]
54 outrow["repeat_count"] = 1
55 local repcount = tonumber(scannet["repeat_count"])
56 if repcount and ( repcount > 0 ) then
57 outrow["repeat_count"] = scannet["repeat_count"]
60 outrow["sleepreq"] = 100
61 local repcount = tonumber(scannet["sleepreq"])
62 if repcount and ( repcount > 0 ) then
63 outrow["sleepreq"] = scannet["sleepreq"]
66 outrow["subnet"] = scannet["subnet"]
67 outrow["output"] = output
76 function command_function(outnets, i)
77 local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
79 return "/usr/bin/netdiscover-to-devinfo " .. outnets[i]["subnet"] .. " " .. interface .. " " .. outnets[i]["timeout"] .. " -r " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
82 function action_links(netdiscovermap, mini)
83 luci.i18n.loadc("diag_devinfo")
84 s = netdiscovermap:section(SimpleSection, "", translate("Actions"))
85 b = s:option(DummyValue, "_config", translate("Configure Scans"))
88 b.titleref = luci.dispatcher.build_url("mini", "network", "netdiscover_devinfo_config")
90 b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "netdiscover_devinfo_config")
92 b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
95 b.titleref = luci.dispatcher.build_url("mini", "diag", "netdiscover_devinfo")
97 b.titleref = luci.dispatcher.build_url("admin", "status", "netdiscover_devinfo")