mirror of https://github.com/aredn/aredn.git
Add cross origin access to remove remote access limitation. (#347)
This commit is contained in:
parent
e3558c02de
commit
3660b26fbb
|
@ -35,28 +35,29 @@
|
|||
--]]
|
||||
|
||||
require("uci")
|
||||
require("aredn.http")
|
||||
require("luci.sys")
|
||||
require("aredn.html")
|
||||
|
||||
local q = os.getenv("QUERY_STRING") or ""
|
||||
local server = q:match("server=([^&]*)")
|
||||
local protocol = q:match("protocol=([^&]*)") or "tcp"
|
||||
http_header(true)
|
||||
|
||||
print "Content-type: text/html\r"
|
||||
print "Cache-Control: no-store\r"
|
||||
print("Access-Control-Allow-Origin: *\r")
|
||||
print("\r")
|
||||
if uci.cursor():get("aredn", "@iperf[0]", "enable") == "0" then
|
||||
aredn.html.print("<html><head></head><body><pre>iperf is disabled</pre></body></html>")
|
||||
print("<html><head></head><body><pre>iperf is disabled</pre></body></html>")
|
||||
elseif not server then
|
||||
aredn.html.print("<html><head></head><body><pre>Provide a server name to run a test between this client and a server [/cgi-bin/iperf?server=<ServerName>&protocol=<udp|tcp>]</pre></body></html>")
|
||||
print("<html><head></head><body><pre>Provide a server name to run a test between this client and a server [/cgi-bin/iperf?server=<ServerName>&protocol=<udp|tcp>]</pre></body></html>")
|
||||
elseif server == "" then
|
||||
os.execute("killall iperf3; iperf3 -s -D -1")
|
||||
aredn.html.print("<html><head></head><body><pre>iperf server running (one time)</pre></body></html>")
|
||||
print("<html><head></head><body><pre>iperf server running (one time)</pre></body></html>")
|
||||
elseif server:match("[^%w-%.]") then
|
||||
aredn.html.print("<html><head></head><body><pre>Illegal server name</pre></body></html>")
|
||||
print("<html><head></head><body><pre>Illegal server name</pre></body></html>")
|
||||
else
|
||||
if not server:match("%.") then
|
||||
server = server .. ".local.mesh"
|
||||
end
|
||||
luci.sys.httpget("http://" .. server .. ":8080/cgi-bin/iperf?server=")
|
||||
aredn.html.print("<html><head><title>iperf</title></head><body><body><pre>" .. io.popen("/usr/bin/iperf3 -b 0 -c " .. server .. (protocol == "udp" and " -u" or "") .. " 2>&1"):read("*a") .. "</pre></body></html>")
|
||||
print("<html><head><title>iperf</title></head><body><body><pre>" .. io.popen("/usr/bin/iperf3 -b 0 -c " .. server .. (protocol == "udp" and " -u" or "") .. " 2>&1"):read("*a") .. "</pre></body></html>")
|
||||
end
|
||||
http_footer()
|
||||
|
|
Loading…
Reference in New Issue