2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6 Copyright 2013 Manuel Munz <freifunk@somakoma.de>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.controller.freifunk.diag", package.seeall)
19 local uci = require("luci.model.uci").cursor()
21 page = node("freifunk", "status", "diagnostics")
22 page.target = template("freifunk/diagnostics")
23 page.title = _("Diagnostics")
26 page = entry({"freifunk", "status", "diag_ping"}, call("diag_ping"), nil)
29 page = entry({"freifunk", "status", "diag_nslookup"}, call("diag_nslookup"), nil)
32 page = entry({"freifunk", "status", "diag_traceroute"}, call("diag_traceroute"), nil)
35 page = entry({"freifunk", "status", "diag_ping6"}, call("diag_ping6"), nil)
38 page = entry({"freifunk", "status", "diag_traceroute6"}, call("diag_traceroute6"), nil)
42 function diag_command(cmd, addr)
43 if addr and addr:match("^[a-zA-Z0-9%-%.:_]+$") then
44 luci.http.prepare_content("text/plain")
46 local util = io.popen(cmd % addr)
49 local ln = util:read("*l")
50 if not ln then break end
61 luci.http.status(500, "Bad address")
64 function diag_ping(addr)
65 diag_command("ping -c 5 -W 1 %q 2>&1", addr)
68 function diag_traceroute(addr)
69 diag_command("traceroute -q 1 -w 1 -n %q 2>&1", addr)
72 function diag_nslookup(addr)
73 diag_command("nslookup %q 2>&1", addr)
76 function diag_ping6(addr)
77 diag_command("ping6 -c 5 %q 2>&1", addr)
80 function diag_traceroute6(addr)
81 diag_command("traceroute6 -q 1 -w 2 -n %q 2>&1", addr)