mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-14 19:41:51 +00:00
Add a simple iperf LuCi interface
This commit is contained in:
parent
60c3666d6e
commit
4020e11a44
4 changed files with 255 additions and 0 deletions
15
luci-app-iperf/Makefile
Normal file
15
luci-app-iperf/Makefile
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
#
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI Support for iPerf3
|
||||
LUCI_DEPENDS:=+iperf3-ssl
|
||||
|
||||
PKG_LICENSE:=GPLv3
|
||||
|
||||
include ../luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
38
luci-app-iperf/luasrc/controller/iperf.lua
Normal file
38
luci-app-iperf/luasrc/controller/iperf.lua
Normal file
|
@ -0,0 +1,38 @@
|
|||
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"))
|
||||
entry({"admin", "services", "iperf"}, alias("admin", "services", "iperf", "test"), _("iperf"),1)
|
||||
entry({"admin", "services", "iperf", "test"}, template("iperf/test"), nil,1)
|
||||
entry({"admin", "services", "iperf", "run_test"}, post("run_test")).leaf = true
|
||||
end
|
||||
|
||||
function run_test(server,proto,mode)
|
||||
luci.http.prepare_content("text/plain")
|
||||
local iperf
|
||||
local addr = uci:get("iperf",server,"host")
|
||||
local ports = uci:get("iperf",server,"ports")
|
||||
local t={}
|
||||
for pt in ports:gmatch("([^,%s]+)") do
|
||||
table.insert(t,pt)
|
||||
end
|
||||
local port = t[ math.random( #t ) ]
|
||||
if proto == "ipv4" then
|
||||
iperf = io.popen("iperf3 -c %s -P 10 -4 -p %s -J" % {ut.shellquote(addr),port})
|
||||
--iperf = io.popen("iperf3 -c bouygues.iperf.fr -P 10 -4 -J")
|
||||
else
|
||||
iperf = io.popen("iperf3 -c %s -P 10 -6 -p %s -J" % {ut.shellquote(addr),port})
|
||||
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
|
106
luci-app-iperf/luasrc/view/iperf/test.htm
Normal file
106
luci-app-iperf/luasrc/view/iperf/test.htm
Normal file
|
@ -0,0 +1,106 @@
|
|||
<%+header%>
|
||||
|
||||
<%
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
%>
|
||||
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.193.28471-ee087a1"></script>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var stxhr = new XHR();
|
||||
|
||||
function update_status(field, proto, mode)
|
||||
{
|
||||
var tool = field.name;
|
||||
var addr = field.value;
|
||||
|
||||
var legend = document.getElementById('diag-rc-legend');
|
||||
var output = document.getElementById('diag-rc-output');
|
||||
|
||||
if (legend && output)
|
||||
{
|
||||
output.innerHTML =
|
||||
'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
|
||||
'<%:Waiting for command to complete...%>'
|
||||
;
|
||||
|
||||
legend.parentNode.style.display = 'block';
|
||||
legend.style.display = 'inline';
|
||||
|
||||
stxhr.post('<%=url('admin/services/iperf')%>/run_test' + '/' + addr + '/' + proto + '/' + mode, { token: '<%=token%>' },
|
||||
function(x)
|
||||
{
|
||||
if (x.responseText)
|
||||
{
|
||||
legend.style.display = 'none';
|
||||
var response = JSON.parse(x.responseText);
|
||||
if (response.error)
|
||||
{
|
||||
output.innerHTML = String.format('<pre>%s</pre>', response.error );
|
||||
} else {
|
||||
var sent_speed = (response.end.sum_sent.bits_per_second/1000000);
|
||||
var received_speed = (response.end.sum_received.bits_per_second/1000000);
|
||||
var server = response.start.connecting_to.host;
|
||||
output.innerHTML = String.format('<pre>Server: %s - Sent: %sMb/s - Received: %sMb/s</pre>', server, sent_speed.toFixed(2), received_speed.toFixed(2) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
|
||||
<form class="inline" method="post" action="<%=url('admin/services/iperf/run_test')%>">
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:iperf Speed tests%></h2>
|
||||
<fieldset class="cbi-section" id="networks">
|
||||
<legend><%:Settings%></legend>
|
||||
<div class="cbi-section-descr"></div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title"><%:Mode of operation%></label>
|
||||
<div class="cbi-value-field">
|
||||
<select class="cbi-input-select" name="mode">
|
||||
<option value="tcp">TCP</option>
|
||||
<!-- <option value="udp">UDP</option> -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title"><%:Internet protocol%></label>
|
||||
<div class="cbi-value-field">
|
||||
<select class="cbi-input-select" name="proto">
|
||||
<option value="ipv4">IPv4</option>
|
||||
<option value="ipv6">IPv6</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title"><%:Server%></label>
|
||||
<div class="cbi-value-field">
|
||||
<select class="cbi-input-select" name="addr">
|
||||
<%
|
||||
uci:foreach("iperf","server", function(s)
|
||||
local server = s[".name"]
|
||||
%>
|
||||
<option value="<%=server%>"><%=string.gsub(server,"_","-")%></option>
|
||||
<%
|
||||
end)
|
||||
%>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<input type="button" value="<%:Test%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.addr,this.form.proto.value,this.form.mode.value)" />
|
||||
</fieldset>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="cbi-section" style="display:none">
|
||||
<strong id="diag-rc-legend"></strong>
|
||||
<span id="diag-rc-output"></span>
|
||||
</div>
|
||||
<%+footer%>
|
96
luci-app-iperf/root/etc/config/iperf
Normal file
96
luci-app-iperf/root/etc/config/iperf
Normal file
|
@ -0,0 +1,96 @@
|
|||
config server 'bouygues'
|
||||
option host 'bouygues.iperf.fr'
|
||||
option ipv4 '1'
|
||||
option ipv6 '1'
|
||||
option speed '10000'
|
||||
option ports '5200,5201,5202,5203,5204,5205,5206,5207,5208,5209'
|
||||
option tcp '1'
|
||||
option udp '0'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'online_ipv4'
|
||||
option host 'ping.online.net'
|
||||
option ipv4 '1'
|
||||
option ipv6 '0'
|
||||
option speed '10000'
|
||||
option ports '5200,5201,5202,5203,5204,5205,5206,5207,5208,5209'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'online_ipv6'
|
||||
option host 'ping.online.net'
|
||||
option ipv4 '0'
|
||||
option ipv6 '1'
|
||||
option speed '10000'
|
||||
option ports '5200,5201,5202,5203,5204,5205,5206,5207,5208,5209'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'serverius'
|
||||
option host 'speedtest.serverius.net'
|
||||
option ipv4 '1'
|
||||
option ipv6 '1'
|
||||
option speed '10000'
|
||||
option ports '5002'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'eenet'
|
||||
option host 'iperf.eenet.ee'
|
||||
option ipv4 '1'
|
||||
option ipv6 '0'
|
||||
option ports '5201'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'volia'
|
||||
option host 'iperf.volia.net'
|
||||
option ipv4 '1'
|
||||
option ipv6 '0'
|
||||
option ports '5201'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Europe'
|
||||
|
||||
config server 'it_north'
|
||||
option host 'iperf.it-north.net'
|
||||
option ipv4 '1'
|
||||
option ipv6 '0'
|
||||
option speed '1000'
|
||||
option ports '5200,5201,5202,5203,5204,5205,5206,5207,5208,5209'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'Asia'
|
||||
|
||||
config server 'biznet'
|
||||
option host 'iperf.biznetnetworkds.com'
|
||||
option ipv4 '1'
|
||||
option ipv6 '1'
|
||||
option speed '1000'
|
||||
option ports '5201,5202,5203'
|
||||
option tcp '1'
|
||||
option udp '0'
|
||||
option location 'Asia'
|
||||
|
||||
config server 'scottlinux'
|
||||
option host 'iperf.scottlinux.com'
|
||||
option ipv4 '1'
|
||||
option ipv6 '1'
|
||||
option speed '1000'
|
||||
option ports '5201'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'America'
|
||||
|
||||
config server 'he'
|
||||
option host 'iperf.he.net'
|
||||
option ipv4 '1'
|
||||
option ipv6 '1'
|
||||
option ports '5201'
|
||||
option tcp '1'
|
||||
option udp '1'
|
||||
option location 'America'
|
Loading…
Reference in a new issue