luci-app-mwan3: bugfix
[project/luci.git] / applications / luci-app-mwan3 / luasrc / controller / mwan3.lua
index 64ee9f5..d5fc4a3 100644 (file)
@@ -56,7 +56,7 @@ function index()
                arcombine(cbi("mwan/rule"), cbi("mwan/ruleconfig")),
                _("Rules"), 40).leaf = true
        entry({"admin", "network", "mwan", "notify"},
-               cbi("mwan/notify"),
+               form("mwan/notify"),
                _("Notification"), 50).leaf = true
 end
 
@@ -85,7 +85,8 @@ function diagnosticsData(interface, task)
        function getInterfaceNumber(interface)
                local number = 0
                local interfaceNumber
-               uci.cursor():foreach("mwan3", "interface",
+               local uci = require "luci.model.uci".cursor()
+               uci:foreach("mwan3", "interface",
                        function (section)
                                number = number+1
                                if section[".name"] == interface then
@@ -98,7 +99,7 @@ function diagnosticsData(interface, task)
 
        function diag_command(cmd, addr)
                if addr and addr:match("^[a-zA-Z0-9%-%.:_]+$") then
-                       local util = io.popen(cmd % addr)
+                       local util = io.popen(cmd % ut.shellquote(addr))
                        if util then
                                while true do
                                        local ln = util:read("*l")
@@ -130,7 +131,7 @@ function diagnosticsData(interface, task)
        local results = ""
        local number = getInterfaceNumber(interface)
 
-       local uci = uci.cursor(nil, "/var/state")
+       local uci = require "luci.model.uci".cursor(nil, "/var/state")
        local device = uci:get("network", interface, "ifname")
 
        luci.http.prepare_content("text/plain")
@@ -138,7 +139,7 @@ function diagnosticsData(interface, task)
                if task == "ping_gateway" then
                        local gateway = get_gateway(interface)
                        if gateway ~= nil then
-                               diag_command("ping -c 5 -W 1 %q 2>&1", gateway)
+                               diag_command("ping -c 5 -W 1 %s 2>&1", gateway)
                        else
                                luci.http.prepare_content("text/plain")
                                luci.http.write(string.format("No gateway for interface %s found.", interface))
@@ -147,7 +148,7 @@ function diagnosticsData(interface, task)
                        local trackips = uci:get("mwan3", interface, "track_ip")
                        if #trackips > 0 then
                                for i in pairs(trackips) do
-                                       diag_command("ping -c 5 -W 1 %q 2>&1", trackips[i])
+                                       diag_command("ping -c 5 -W 1 %s 2>&1", trackips[i])
                                end
                        else
                                luci.http.write(string.format("No tracking Hosts for interface %s defined.", interface))
@@ -185,10 +186,10 @@ function diagnosticsData(interface, task)
                                luci.http.write(string.format("Routing table %s for interface %s not found", number, interface))
                        end
                elseif task == "hotplug_ifup" then
-                       os.execute(string.format("/usr/sbin/mwan3 ifup %s", interface))
+                       os.execute(string.format("/usr/sbin/mwan3 ifup %s", ut.shellquote(interface)))
                        luci.http.write(string.format("Hotplug ifup sent to interface %s", interface))
                elseif task == "hotplug_ifdown" then
-                       os.execute(string.format("/usr/sbin/mwan3 ifdown %s", interface))
+                       os.execute(string.format("/usr/sbin/mwan3 ifdown %s", ut.shellquote(interface)))
                        luci.http.write(string.format("Hotplug ifdown sent to interface %s", interface))
                else
                        luci.http.write("Unknown task")