1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 19:11:51 +00:00
openmptcprouter-feeds/luci-app-iperf/luasrc/controller/iperf.lua

56 lines
1.8 KiB
Lua
Raw Normal View History

2018-07-13 14:12:57 +00:00
local uci = luci.model.uci.cursor()
local ut = require "luci.util"
module("luci.controller.iperf", package.seeall)
function index()
--entry({"admin", "openmptcprouter", "iperf"}, cbi("iperf"), _("iperf"))
2018-07-20 13:04:35 +00:00
entry({"admin", "services", "iperf"}, alias("admin", "services", "iperf", "test"), _("iPerf"),8)
2018-07-13 14:12:57 +00:00
entry({"admin", "services", "iperf", "test"}, template("iperf/test"), nil,1)
entry({"admin", "services", "iperf", "run_test"}, post("run_test")).leaf = true
end
2018-07-20 13:04:35 +00:00
function run_test(server,proto,mode,updown,omit,parallel,transmit,bitrate)
2018-07-13 14:12:57 +00:00
luci.http.prepare_content("text/plain")
local iperf
local addr = uci:get("iperf",server,"host")
local ports = uci:get("iperf",server,"ports")
2019-03-28 20:33:23 +00:00
local user = uci:get("iperf",server,"user") or ""
local password = uci:get("iperf",server,"password") or ""
local key = uci:get("iperf",server,"key") or ""
2019-03-28 21:10:29 +00:00
local options = ""
2019-03-28 20:33:23 +00:00
if user ~= "" and password ~= "" and key ~= "" then
luci.sys.call("echo " .. key .. " | base64 -d > /tmp/iperf.pem")
2019-03-28 21:10:29 +00:00
options = options .. " --username " .. user .. " --rsa-public-key-path /tmp/iperf.pem"
2019-03-28 20:33:23 +00:00
end
if mode == "udp" then
options = options .. " -u -b " .. bitrate
end
if mode ~= "upload" then
options = options .. " -R"
end
2018-07-25 13:08:16 +00:00
local ipv = "4"
if proto == "ipv6" then
local ipv = "6"
2018-07-20 13:04:35 +00:00
end
2018-07-13 14:12:57 +00:00
local t={}
for pt in ports:gmatch("([^,%s]+)") do
table.insert(t,pt)
end
local port = t[ math.random( #t ) ]
2019-03-28 20:33:23 +00:00
if password ~= "" then
2019-03-28 21:10:29 +00:00
iperf = io.popen("omr-iperf -P %s -%s -O %s -t %s -J -Z %s" % {parallel,ipv,omit,transmit,options})
2018-07-13 14:12:57 +00:00
else
2019-03-28 20:33:23 +00:00
iperf = io.popen("iperf3 -c %s -P %s -%s -p %s -O %s -t %s -J -Z %s" % {ut.shellquote(addr),parallel,ipv,port,omit,transmit,options})
2018-07-13 14:12:57 +00:00
end
if iperf then
while true do
local ln = iperf:read("*l")
if not ln then break end
luci.http.write(ln)
luci.http.write("\n")
end
end
return
end