Developing lightweight computation at the DSG edge

Commit e24454e5 authored by p4u's avatar p4u
Browse files

New improved look for tools section and new traceroute tool

parent c2fe5466
<%+header%>
<script type="text/javascript">
function do_test(ip,index,key,tool) {
var output = document.getElementById('output_'+index);
if (output) {
output.innerHTML ='<%:Collecting data...%>&lt;img src="/luci-static/resources/icons/loading.gif" height="20px" alt="Loading" style="vertical-align:middle"/&gt; ';
output.style.display = 'inline';
var result = new XMLHttpRequest();
result.open("GET", "/cgi-bin/tools?" + key + "&amp;" + tool + "&amp;" + ip, true);
result.onreadystatechange = function() {
if (result.readyState == 4) {
output.innerHTML= parse_result(result.responseText);
}
}
result.send(null);
XHR.get("/cgi-bin/tools",[ key , tool , ip] ,
function(x) {
output.innerHTML= parse_result(x.responseText);
} )
}
}
function parse_result(txt) {
......@@ -25,21 +22,37 @@ function parse_result(txt) {
return("&lt;font color='#f00'&gt;<%:Cannot connecto to netserver%>&lt;/font&gt;");
else
return("&lt;font color='#0a0'&gt;"+txt+"&lt;/font&gt;");
//return("<font color='#0a0'>"+txt+"</font>");
}
</script>
<h2>Tools</h2>
<p><strong><u>Nodes found in the network:</u></strong></p>
<div class="cbi-map">
<form>
<fieldset class="cbi-section">
<legend><%:Nodes found in the network%></legend>
<table class="cbi-section-table" >
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"></th>
<th class="cbi-section-table-cell"></th>
<th class="cbi-section-table-cell"></th>
</tr>
<% for i,n in ipairs(nodes) do %>
<div style="clear:both;height:30px;width:800px;float:left">
<strong><%=n[1]%></strong> <%=n[2]%> &nbsp;&nbsp; &nbsp;&nbsp;
<input type="button" value="bandwidth" onclick="do_test('<%=n[2]%>',<%=i%>,'<%=key%>','bwtest')" />
<input type="button" value="ping" onclick="do_test('<%=n[2]%>',<%=i%>,'<%=key%>','ping')" />
<span style="display:none;margin-left:5px;border:1px solid #000;padding:0.1em 0.4em" id="output_<%=i%>"></span>
</div>
<tr>
<td title="<%=n[2]%>" style="padding-left:10px;width:15%;text-align:left;"><%=n[1]%></td>
<td style="width:18%;text-align:right;">
<input type="button" value="bandwidth" onclick="do_test('<%=n[2]%>',<%=i%>,'<%=key%>','bwtest')" />
<input type="button" value="ping" onclick="do_test('<%=n[2]%>',<%=i%>,'<%=key%>','ping')" />
<input type="button" value="trace" onclick="do_test('<%=n[2]%>',<%=i%>,'<%=key%>','traceroute')" />
</td>
<td style="text-align:left;padding-left:10px;"><span id="output_<%=i%>"></span></td>
</tr>
<% end %>
</table>
<br /><br />
<div style="clear:both;height:30px;float:left">
<strong>Specify Custom ip:</strong>
<input type="text" name="custom" />
......@@ -47,8 +60,9 @@ function parse_result(txt) {
<input type="button" value="ping" onclick="do_test(this.form.custom.value,'custom','<%=key%>','ping')" />
<span style="display:none;margin-left:5px;border:1px solid #000;padding:0.1em 0.4em" id="output_custom"></span>
</div>
</fieldset>
</form>
</div>
<%+footer%>
......@@ -2,10 +2,12 @@
echo "content-type: text/plain"
echo ""
echo "$QUERY_STRING" >> /tmp/debug
QUERY_KEY="$(echo $QUERY_STRING | cut -d'&' -f1 | cut -d'=' -f2)"
QUERY_TYPE="$(echo $QUERY_STRING | cut -d'&' -f2 | cut -d'=' -f2)"
QUERY_DATA="$(echo $QUERY_STRING | cut -d'&' -f3 | cut -d'=' -f2 | sed s/'%3A'/':'/g)"
QUERY_KEY="$(echo $QUERY_STRING | cut -d'&' -f1)"
QUERY_TYPE="$(echo $QUERY_STRING | cut -d'&' -f2)"
QUERY_DATA="$(echo $QUERY_STRING | cut -d'&' -f3)"
echo "$QUERY_TYPE $QUERY_DATA" >> /tmp/debug
KEY_F="$(uci get qmp.node.key)"
[ -z "$KEY_F" ] && KEY_F="/tmp/qmp_key"
......@@ -18,10 +20,12 @@ tools_bwtest() {
}
tools_trace() {
[ ! -z "$QUERY_DATA" ] && traceroute $QUERY_DATA
[ -z "$(which mtr)" ] && { echo "Please, install mtr"; exit 1; }
[ ! -z "$QUERY_DATA" ] && { echo "<pre>"; mtr -6 --raw --no-dns --report $QUERY_DATA; echo "</pre>"; }
}
tools_ping() {
[ -z "$(which ping)" ] && { echo "Please, install ping"; exit 1; }
[ ! -z "$QUERY_DATA" ] && ping -c4 $QUERY_DATA -q | grep avg
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment