smap_common.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. -- Copyright 2009 Daniel Dickinson
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.controller.luci_diag.smap_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 smapnets_uci = luci.model.uci.cursor()
  17. smapnets_uci:load("luci_devinfo")
  18. local nettable = smapnets_uci:get_all("luci_devinfo")
  19. local i
  20. local subnet
  21. local smapout
  22. local outnets = {}
  23. i = next(nettable, nil)
  24. while (i) do
  25. if (smapnets_uci:get("luci_devinfo", i) == "smap_scannet") then
  26. local scannet = smapnets_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["subnet"] = scannet["subnet"]
  31. ports = "5060"
  32. if scannet["ports"] and ( scannet["ports"] ~= "" ) then
  33. ports = scannet["ports"]
  34. end
  35. outrow["timeout"] = 10
  36. local timeout = tonumber(scannet["timeout"])
  37. if timeout and ( timeout > 0 ) then
  38. outrow["timeout"] = scannet["timeout"]
  39. end
  40. outrow["repeat_count"] = 1
  41. local repcount = tonumber(scannet["repeat_count"])
  42. if repcount and ( repcount > 0 ) then
  43. outrow["repeat_count"] = scannet["repeat_count"]
  44. end
  45. outrow["sleepreq"] = 100
  46. local repcount = tonumber(scannet["sleepreq"])
  47. if repcount and ( repcount > 0 ) then
  48. outrow["sleepreq"] = scannet["sleepreq"]
  49. end
  50. if scannet["interface"] and ( scannet["interface"] ~= "" ) then
  51. outrow["interface"] = scannet["interface"]
  52. else
  53. outrow["interface"] = ""
  54. end
  55. outrow["ports"] = ports
  56. outrow["output"] = output
  57. outnets[i] = outrow
  58. end
  59. end
  60. i = next(nettable, i)
  61. end
  62. return outnets
  63. end
  64. function command_function(outnets, i)
  65. local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
  66. return "/usr/bin/netsmap-to-devinfo -r " .. outnets[i]["subnet"] .. " -t " .. outnets[i]["timeout"] .. " -i " .. interface .. " -x -p " .. outnets[i]["ports"] .. " -c " .. outnets[i]["repeat_count"] .. " -s " .. outnets[i]["sleepreq"] .. " </dev/null"
  67. end
  68. function action_links(smapmap, mini)
  69. s = smapmap:section(SimpleSection, "", translate("Actions"))
  70. b = s:option(DummyValue, "_config", translate("Configure Scans"))
  71. b.value = ""
  72. if (mini) then
  73. b.titleref = luci.dispatcher.build_url("mini", "voice", "phones", "phone_scan_config")
  74. else
  75. b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "smap_devinfo_config")
  76. end
  77. b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
  78. b.value = ""
  79. if (mini) then
  80. b.titleref = luci.dispatcher.build_url("mini", "diag", "phone_scan")
  81. else
  82. b.titleref = luci.dispatcher.build_url("admin", "status", "smap_devinfo")
  83. end
  84. end