1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Copyright 2013 Manuel Munz <freifunk@somakoma.de>
4 -- Licensed to the public under the Apache License 2.0.
6 module("luci.controller.freifunk.diag", package.seeall)
9 local uci = require("luci.model.uci").cursor()
11 page = node("freifunk", "status", "diagnostics")
12 page.target = template("freifunk/diagnostics")
13 page.title = _("Diagnostics")
16 page = entry({"freifunk", "status", "diag_ping"}, call("diag_ping"), nil)
19 page = entry({"freifunk", "status", "diag_nslookup"}, call("diag_nslookup"), nil)
22 page = entry({"freifunk", "status", "diag_traceroute"}, call("diag_traceroute"), nil)
25 page = entry({"freifunk", "status", "diag_ping6"}, call("diag_ping6"), nil)
28 page = entry({"freifunk", "status", "diag_traceroute6"}, call("diag_traceroute6"), nil)
32 function diag_command(cmd, addr)
33 if addr and addr:match("^[a-zA-Z0-9%-%.:_]+$") then
34 luci.http.prepare_content("text/plain")
36 local util = io.popen(cmd % luci.util.shellquote(addr))
39 local ln = util:read("*l")
40 if not ln then break end
51 luci.http.status(500, "Bad address")
54 function diag_ping(addr)
55 diag_command("ping -c 5 -W 1 %s 2>&1", addr)
58 function diag_traceroute(addr)
59 diag_command("traceroute -q 1 -w 1 -n %s 2>&1", addr)
62 function diag_nslookup(addr)
63 diag_command("nslookup %s 2>&1", addr)
66 function diag_ping6(addr)
67 diag_command("ping6 -c 5 %s 2>&1", addr)
70 function diag_traceroute6(addr)
71 diag_command("traceroute6 -q 1 -w 2 -n %s 2>&1", addr)