- -- software versions
- local wrtRelease = ut.trim(ver.distversion)
- if wrtRelease ~= "" then
- wrtRelease = "OpenWrt - " .. wrtRelease
- else
- wrtRelease = "OpenWrt - unknown"
- end
- local luciRelease = ut.trim(ver.luciversion)
- if luciRelease ~= "" then
- luciRelease = "\nLuCI - " .. luciRelease
- else
- luciRelease = "\nLuCI - unknown"
- end
- local mwanVersion = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk '{print $2}'"))
- if mwanVersion ~= "" then
- mwanVersion = "\n\nmwan3 - " .. mwanVersion
- else
- mwanVersion = "\n\nmwan3 - unknown"
- end
- local mwanLuciVersion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk '{print $2}'"))
- if mwanLuciVersion ~= "" then
- mwanLuciVersion = "\nmwan3-luci - " .. mwanLuciVersion
+ local uci = uci.cursor(nil, "/var/state")
+ local device = uci:get("network", interface, "ifname")
+
+ luci.http.prepare_content("text/plain")
+ if device ~= "" then
+ 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)
+ else
+ luci.http.prepare_content("text/plain")
+ luci.http.write(string.format("No gateway for interface %s found.", interface))
+ end
+ elseif task == "ping_trackips" then
+ 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])
+ end
+ else
+ luci.http.write(string.format("No tracking Hosts for interface %s defined.", interface))
+ end
+ elseif task == "check_rules" then
+ local number = getInterfaceNumber(interface)
+ local iif = 1000 + number
+ local fwmark = 2000 + number
+ local iif_rule = sys.exec(string.format("ip rule | grep %d", iif))
+ local fwmark_rule = sys.exec(string.format("ip rule | grep %d", fwmark))
+ if iif_rule ~= "" and fwmark_rule ~= "" then
+ luci.http.write(string.format("All required IP rules for interface %s found", interface))
+ luci.http.write("\n")
+ luci.http.write(fwmark_rule)
+ luci.http.write(iif_rule)
+ elseif iif_rule == "" and fwmark_rule ~= "" then
+ luci.http.write(string.format("Only one IP rules for interface %s found", interface))
+ luci.http.write("\n")
+ luci.http.write(fwmark_rule)
+ elseif iif_rule ~= "" and fwmark_rule == "" then
+ luci.http.write(string.format("Only one IP rules for interface %s found", interface))
+ luci.http.write("\n")
+ luci.http.write(iif_rule)
+ else
+ luci.http.write(string.format("Missing both IP rules for interface %s", interface))
+ end
+ elseif task == "check_routes" then
+ local number = getInterfaceNumber(interface)
+ local routeTable = sys.exec(string.format("ip route list table %s", number))
+ if routeTable ~= "" then
+ luci.http.write(string.format("Routing table %s for interface %s found", number, interface))
+ luci.http.write("\n")
+ luci.http.write(routeTable)
+ else
+ 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))
+ 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))
+ luci.http.write(string.format("Hotplug ifdown sent to interface %s", interface))