Developing lightweight computation at the DSG edge

Commit 182fa9eb authored by p4u's avatar p4u
Browse files

Added security for tools cgi-bin and some improvements on web interface

parent 43ac873b
......@@ -41,18 +41,19 @@ apply_wifi() {
wifi
}
apply_netserver() {
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
}
apply_network() {
qmp_configure
/etc/init.d/network restart
ifup -a
/etc/init.d/olsrd restart
/etc/init.d/bmx6 restart
ifup -a
/etc/init.d/dnsmasq restart
/etc/init.d/firewall restart
}
apply_netserver() {
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
apply_netserver
}
help() {
......
......@@ -843,8 +843,8 @@ qmp_configure_system() {
qmp_check_force_internet() {
[ "$(uci get qmp.interfaces.force_internet)" == "1" ] && qmp_gw_offer_default
[ "$(uci get qmp.interfaces.force_internet)" == "0" ] && qmp_gw_search_default
[ "$(uci get qmp.networks.force_internet)" == "1" ] && qmp_gw_offer_default
[ "$(uci get qmp.networks.force_internet)" == "0" ] && qmp_gw_search_default
}
qmp_configure() {
......
......@@ -36,7 +36,8 @@ function index()
-- Rest of entries
entry({"qmp","info"}, call("action_status"), "Info", 1).dependent=false
entry({"qmp","network"}, cbi("qmp/config"), "Network", 5).dependent=false
entry({"qmp","network"}, cbi("qmp/network"), "Network", 5).dependent=false
entry({"qmp","network","advanced"}, cbi("qmp/network_adv"), "Advanced networking", 1).dependent=false
entry({"qmp","wireless"}, cbi("qmp/wireless"), "Wireless", 6).dependent=false
entry({"qmp","splash"}, call("action_splash"), "Splash", 7).dependent=false
entry({"qmp","tools"}, call("action_tools"), "Tools", 8).dependent=false
......@@ -57,7 +58,8 @@ function action_tools()
package.path = package.path .. ";/etc/qmp/?.lua"
local qmp = require "qmpinfo"
local nodes = qmp.nodes()
luci.template.render("qmp/tools",{nodes=nodes})
local key = qmp.get_key()
luci.template.render("qmp/tools",{nodes=nodes,key=key})
end
function action_splash()
......
......@@ -99,7 +99,7 @@ for _,wdev in ipairs(wdevs) do
end
function m.on_commit(self,map)
luci.sys.call('/etc/qmp/qmp_control.sh apply_wifi > /tmp/qmp_control_wifi.log')
luci.sys.call('/etc/qmp/qmp_control.sh apply_wifi > /tmp/qmp_control_wifi.log &')
end
......
<%+header%>
<script type="text/javascript">
function do_bwtest(ip,index) {
function do_test(ip,index,key,tool) {
var output = document.getElementById('output_'+index);
if (output) {
......@@ -9,7 +9,7 @@ function do_bwtest(ip,index) {
output.style.display = 'inline';
var result = new XMLHttpRequest();
result.open("GET", "/cgi-bin/bwtest?"+ip, true);
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);
......@@ -29,22 +29,26 @@ function parse_result(txt) {
</script>
<h2>Bandwidth test</h2>
<p><strong>Nodes found in the network:</strong></p>
<h2>Tools</h2>
<p><strong><u>Nodes found in the network:</u></strong></p>
<form>
<% for i,n in ipairs(nodes) do %>
<div style="height:30px;width:550px;float:left">
<input type="button" value="<%=n[1]%>" onclick="do_bwtest('<%=n[2]%>',<%=i%>)" />&nbsp;&nbsp; <%=n[2]%>
<div style="clear:both;height:30px;width:550px;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>
<% end %>
<div style="clear:both;height:30px;float:left">
<strong>Specify Custom ip:</strong>
<input type="text" name="custom" />
<input type="button" value="Start" onclick='do_bwtest(this.form.custom.value,"custom")' />&nbsp;&nbsp; <%=n%>
<input type="button" value="bandwidth" onclick="do_test(this.form.custom.value,'custom','<%=key%>','bwtest')" />
<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>
</form>
<%+footer%>
#!/bin/sh
echo "content-type: text/plain"
echo ""
#TODO: Securize Query
QUERY="$QUERY_STRING"
[ ! -z "$QUERY" ] && {
/etc/qmp/qmpinfo bwtest $QUERY
}
#!/bin/sh
echo "content-type: text/plain"
echo ""
QUERY_KEY="$(echo $QUERY_STRING | cut -d'&' -f1)"
QUERY_TYPE="$(echo $QUERY_STRING | cut -d'&' -f2)"
QUERY_DATA="$(echo $QUERY_STRING | cut -d'&' -f3)"
KEY_F="$(uci get qmp.node.key)"
[ -z "$KEY_F" ] && KEY_F="/tmp/qmp_key"
KEY="$(cat $KEY_F)"
[ "$KEY" != "$QUERY_KEY" ] && { echo "Invalid key"; exit 1; }
tools_bwtest() {
[ ! -z "$QUERY_DATA" ] && /etc/qmp/qmpinfo bwtest $QUERY_DATA
}
tools_trace() {
[ ! -z "$QUERY_DATA" ] && traceroute $QUERY_DATA
}
tools_ping() {
[ ! -z "$QUERY_DATA" ] && ping -c4 $QUERY_DATA -q | grep avg
}
[ "$QUERY_TYPE" == "bwtest" ] && tools_bwtest
[ "$QUERY_TYPE" == "traceroute" ] && tools_trace
[ "$QUERY_TYPE" == "ping" ] && tools_ping
exit 0
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