netdiscover_common.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. -- Copyright 2009 Daniel Dickinson
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.controller.luci_diag.netdiscover_common", package.seeall)
  4. require("luci.i18n")
  5. require("luci.util")
  6. require("luci.sys")
  7. require("luci.cbi")
  8. require("luci.model.uci")
  9. local translate = luci.i18n.translate
  10. local DummyValue = luci.cbi.DummyValue
  11. local SimpleSection = luci.cbi.SimpleSection
  12. function index()
  13. return -- no-op
  14. end
  15. function get_params()
  16. local netdiscover_uci = luci.model.uci.cursor()
  17. netdiscover_uci:load("luci_devinfo")
  18. local nettable = netdiscover_uci:get_all("luci_devinfo")
  19. local i
  20. local subnet
  21. local netdout
  22. local outnets = {}
  23. i = next(nettable, nil)
  24. while (i) do
  25. if (netdiscover_uci:get("luci_devinfo", i) == "netdiscover_scannet") then
  26. local scannet = netdiscover_uci:get_all("luci_devinfo", i)
  27. if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
  28. local output = ""
  29. local outrow = {}
  30. outrow["interface"] = scannet["interface"]
  31. outrow["timeout"] = 10
  32. local timeout = tonumber(scannet["timeout"])
  33. if timeout and ( timeout > 0 ) then
  34. outrow["timeout"] = scannet["timeout"]
  35. end
  36. outrow["repeat_count"] = 1
  37. local repcount = tonumber(scannet["repeat_count"])
  38. if repcount and ( repcount > 0 ) then
  39. outrow["repeat_count"] = scannet["repeat_count"]
  40. end
  41. outrow["sleepreq"] = 100
  42. local repcount = tonumber(scannet["sleepreq"])
  43. if repcount and ( repcount > 0 ) then
  44. outrow["sleepreq"] = scannet["sleepreq"]
  45. end
  46. outrow["subnet"] = scannet["subnet"]
  47. outrow["output"] = output
  48. outnets[i] = outrow
  49. end
  50. end
  51. i = next(nettable, i)
  52. end
  53. return outnets
  54. end
  55. function command_function(outnets, i)
  56. local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
  57. return "/usr/bin/netdiscover-to-devinfo " .. outnets[i]["subnet"] .. " " .. interface .. " " .. outnets[i]["timeout"] .. " -r " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
  58. end
  59. function action_links(netdiscovermap, mini)
  60. s = netdiscovermap:section(SimpleSection, "", translate("Actions"))
  61. b = s:option(DummyValue, "_config", translate("Configure Scans"))
  62. b.value = ""
  63. if (mini) then
  64. b.titleref = luci.dispatcher.build_url("mini", "network", "netdiscover_devinfo_config")
  65. else
  66. b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "netdiscover_devinfo_config")
  67. end
  68. b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
  69. b.value = ""
  70. if (mini) then
  71. b.titleref = luci.dispatcher.build_url("mini", "diag", "netdiscover_devinfo")
  72. else
  73. b.titleref = luci.dispatcher.build_url("admin", "status", "netdiscover_devinfo")
  74. end
  75. end