all: change most translate statements to new format, some need manual cleanup
[project/luci.git] / applications / luci-diag-devinfo / luasrc / controller / luci_diag / smap_common.lua
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.smap_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 function get_params()
27
28    local smapnets_uci = luci.model.uci.cursor()
29    smapnets_uci:load("luci_devinfo")
30    local nettable = smapnets_uci:get_all("luci_devinfo")
31
32    local i 
33    local subnet
34    local smapout
35
36    local outnets = {}
37
38    i = next(nettable, nil)
39
40    while (i) do
41       if (smapnets_uci:get("luci_devinfo", i) == "smap_scannet") then 
42          local scannet = smapnets_uci:get_all("luci_devinfo", i)
43          if scannet["subnet"] and (scannet["subnet"] ~= "") and scannet["enable"] and ( scannet["enable"] == "1") then
44             local output = ""
45             local outrow = {}
46             outrow["subnet"] = scannet["subnet"]
47             ports = "5060"
48             if scannet["ports"] and ( scannet["ports"] ~= "" ) then
49                ports = scannet["ports"]          
50             end
51             outrow["timeout"] = 10
52             local timeout = tonumber(scannet["timeout"]) 
53             if timeout and ( timeout > 0 ) then
54                outrow["timeout"] = scannet["timeout"]
55             end
56
57             outrow["repeat_count"] = 1
58             local repcount = tonumber(scannet["repeat_count"]) 
59             if repcount and ( repcount > 0 ) then
60                outrow["repeat_count"] = scannet["repeat_count"]
61             end
62
63             outrow["sleepreq"] = 100
64             local repcount = tonumber(scannet["sleepreq"]) 
65             if repcount and ( repcount > 0 ) then
66                outrow["sleepreq"] = scannet["sleepreq"]
67             end
68
69             if scannet["interface"] and ( scannet["interface"] ~= "" ) then
70                outrow["interface"] = scannet["interface"]
71             else
72                outrow["interface"] = ""
73             end
74
75             outrow["ports"] = ports
76             outrow["output"] = output
77             outnets[i] = outrow
78          end
79       end
80       i = next(nettable, i)
81    end
82    return outnets
83 end
84
85 function command_function(outnets, i) 
86
87    local interface = luci.controller.luci_diag.devinfo_common.get_network_device(outnets[i]["interface"])
88
89    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"
90 end
91
92 function action_links(smapmap, mini) 
93    luci.i18n.loadc("diag_devinfo")
94    s = smapmap:section(SimpleSection, "", translate("Actions")) 
95    b = s:option(DummyValue, "_config", translate("Configure Scans"))
96    b.value = ""
97    if (mini) then
98       b.titleref = luci.dispatcher.build_url("mini", "voice", "phones", "phone_scan_config")
99    else
100       b.titleref = luci.dispatcher.build_url("admin", "network", "diag_config", "smap_devinfo_config")
101    end
102    b = s:option(DummyValue, "_scans", translate("Repeat Scans (this can take a few minutes)"))
103    b.value = ""
104    if (mini) then
105       b.titleref = luci.dispatcher.build_url("mini", "diag", "phone_scan")
106    else
107       b.titleref = luci.dispatcher.build_url("admin", "status", "smap_devinfo")
108    end
109 end