| 1 | --[[ |
|---|
| 2 | |
|---|
| 3 | Luci diag - Diagnostics controller module |
|---|
| 4 | (c) 2009 Daniel Dickinson |
|---|
| 5 | |
|---|
| 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 |
|---|
| 9 | |
|---|
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 11 | |
|---|
| 12 | ]]-- |
|---|
| 13 | |
|---|
| 14 | module("luci.controller.luci_diag.netdiscover_common", package.seeall) |
|---|
| 15 | |
|---|
| 16 | require("luci.i18n") |
|---|
| 17 | require("luci.util") |
|---|
| 18 | require("luci.sys") |
|---|
| 19 | require("luci.cbi") |
|---|
| 20 | require("luci.model.uci") |
|---|
| 21 | |
|---|
| 22 | local translate = luci.i18n.translate |
|---|
| 23 | local DummyValue = luci.cbi.DummyValue |
|---|
| 24 | local SimpleSection = luci.cbi.SimpleSection |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | function get_params() |
|---|
| 28 | |
|---|
| 29 | local netdiscover_uci = luci.model.uci.cursor() |
|---|
| 30 | netdiscover_uci:load("luci_devinfo") |
|---|
| 31 | local nettable = netdiscover_uci:get_all("luci_devinfo") |
|---|
| 32 | |
|---|
| 33 | local i |
|---|
| 34 | local subnet |
|---|
| 35 | local netdout |
|---|
| 36 | |
|---|
| 37 | local outnets = {} |
|---|
| 38 | |
|---|
| 39 | i = next(nettable, nil) |
|---|
| 40 | |
|---|
| 41 | while (i) do |
|---|
| 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 |
|---|
| 45 | local output = "" |
|---|
| 46 | local outrow = {} |
|---|
| 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"] |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 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"] |
|---|
| 58 | end |
|---|
| 59 | |
|---|
| 60 | outrow["sleepreq"] = 100 |
|---|
| 61 | local repcount = tonumber(scannet["sleepreq"]) |
|---|
| 62 | if repcount and ( repcount > 0 ) then |
|---|
| 63 | outrow["sleepreq"] = scannet["sleepreq"] |
|---|
| 64 | end |
|---|
| 65 | |
|---|
| 66 | outrow["subnet"] = scannet["subnet"] |
|---|
| 67 | outrow["output"] = output |
|---|
| 68 | outnets[i] = outrow |
|---|
| 69 | end |
|---|
| 70 | end |
|---|
| 71 | i = next(nettable, i) |
|---|
| 72 | end |
|---|
| 73 | return outnets |
|---|
| 74 | end |
|---|
| 75 | |
|---|
| 76 | function command_function(outnets, i) |
|---|
| 77 | local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"]) |
|---|
| 78 | |
|---|
| 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" |
|---|
| 80 | end |
|---|
| 81 | |
|---|
| 82 | function action_links(netdiscovermap, mini) |
|---|
| 83 | luci.i18n.loadc("diag_devinfo") |
|---|
| 84 | s = netdiscovermap:section(SimpleSection, "", translate("l_d_d_nc_netdiscover_actions")) |
|---|
| 85 | b = s:option(DummyValue, "_config", translate("l_d_d_nc_config_scan")) |
|---|
| 86 | b.value = "" |
|---|
| 87 | if (mini) then |
|---|
| 88 | b.titleref = luci.dispatcher.build_url("mini", "network", "netdiscover_devinfo_config") |
|---|
| 89 | else |
|---|
| 90 | b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "netdiscover_devinfo_config") |
|---|
| 91 | end |
|---|
| 92 | b = s:option(DummyValue, "_scans", translate("l_d_d_nc_redo_scans")) |
|---|
| 93 | b.value = "" |
|---|
| 94 | if (mini) then |
|---|
| 95 | b.titleref = luci.dispatcher.build_url("mini", "diag", "netdiscover_devinfo") |
|---|
| 96 | else |
|---|
| 97 | b.titleref = luci.dispatcher.build_url("admin", "status", "netdiscover_devinfo") |
|---|
| 98 | end |
|---|
| 99 | end |
|---|