Globally reduce copyright headers
[project/luci.git] / applications / luci-app-diag-devinfo / luasrc / controller / luci_diag / smap_common.lua
1 -- Copyright 2009 Daniel Dickinson
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.controller.luci_diag.smap_common", package.seeall)
5
6 require("luci.i18n")
7 require("luci.util")
8 require("luci.sys")
9 require("luci.cbi")
10 require("luci.model.uci")
11
12 local translate = luci.i18n.translate
13 local DummyValue = luci.cbi.DummyValue
14 local SimpleSection = luci.cbi.SimpleSection
15
16 function index()
17         return -- no-op
18 end
19
20 function get_params()
21
22    local smapnets_uci = luci.model.uci.cursor()
23    smapnets_uci:load("luci_devinfo")
24    local nettable = smapnets_uci:get_all("luci_devinfo")
25
26    local i 
27    local subnet
28    local smapout
29
30    local outnets = {}
31
32    i = next(nettable, nil)
33
34    while (i) do
35       if (smapnets_uci:get("luci_devinfo", i) == "smap_scannet") then 
36          local scannet = smapnets_uci:get_all("luci_devinfo", i)
37          if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
38             local output = ""
39             local outrow = {}
40             outrow["subnet"] = scannet["subnet"]
41             ports = "5060"
42             if scannet["ports"] and ( scannet["ports"] ~= "" ) then
43                ports = scannet["ports"]          
44             end
45             outrow["timeout"] = 10
46             local timeout = tonumber(scannet["timeout"]) 
47             if timeout and ( timeout > 0 ) then
48                outrow["timeout"] = scannet["timeout"]
49             end
50
51             outrow["repeat_count"] = 1
52             local repcount = tonumber(scannet["repeat_count"]) 
53             if repcount and ( repcount > 0 ) then
54                outrow["repeat_count"] = scannet["repeat_count"]
55             end
56
57             outrow["sleepreq"] = 100
58             local repcount = tonumber(scannet["sleepreq"]) 
59             if repcount and ( repcount > 0 ) then
60                outrow["sleepreq"] = scannet["sleepreq"]
61             end
62
63             if scannet["interface"] and ( scannet["interface"] ~= "" ) then
64                outrow["interface"] = scannet["interface"]
65             else
66                outrow["interface"] = ""
67             end
68
69             outrow["ports"] = ports
70             outrow["output"] = output
71             outnets[i] = outrow
72          end
73       end
74       i = next(nettable, i)
75    end
76    return outnets
77 end
78
79 function command_function(outnets, i) 
80
81    local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
82
83    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"
84 end
85
86 function action_links(smapmap, mini) 
87    s = smapmap:section(SimpleSection, "", translate("Actions")) 
88    b = s:option(DummyValue, "_config", translate("Configure Scans"))
89    b.value = ""
90    if (mini) then
91       b.titleref = luci.dispatcher.build_url("mini", "voice", "phones", "phone_scan_config")
92    else
93       b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "smap_devinfo_config")
94    end
95    b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
96    b.value = ""
97    if (mini) then
98       b.titleref = luci.dispatcher.build_url("mini", "diag", "phone_scan")
99    else
100       b.titleref = luci.dispatcher.build_url("admin", "status", "smap_devinfo")
101    end
102 end