JUCI-core fixed buggy reconnect popup
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Fri, 24 Mar 2017 14:12:57 +0000 (15:12 +0100)
committerReidar Cederqvist <reidar.cederqvist@gmail.com>
Fri, 24 Mar 2017 14:12:57 +0000 (15:12 +0100)
and made it work after navigating off page

juci/src/js/app.js
juci/src/js/juci.js
juci/src/js/rpc.js
plugins/juci-diagnostics/Makefile [deleted file]
plugins/juci-diagnostics/access.json
plugins/juci-diagnostics/scripts/tptest-run [deleted file]
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.html
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.js
plugins/juci-diagnostics/ubus/juci.diagnostics
plugins/juci-diagnostics/ubus/juci.speedtest [deleted file]

index 0492b82..1318953 100644 (file)
@@ -64,7 +64,7 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $
                return _put.call($templateCache, name, value);
        }
 })
-.run(function($rootScope, $state, $rpc, $config, $location, $modal, $tr, gettext, $events){
+.run(function($rootScope, $state, $rpc, $config, $location, $tr, gettext){
 
        // TODO: maybe use some other way to gather errors than root scope?
        $rootScope.errors = [];
@@ -96,46 +96,6 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $
        } else {
                $juci.redirect("login");
        }
-       // setup automatic connection "pinging" and show spinner if you have lost connection
-       // if you are connected this will test if you are logged in or redirect you to login page
-       var modal;
-       var connected = true;
-       var i = 1;
-       JUCI.interval.repeat("check-connection", 2000, function(next){
-               $rpc.$isConnected().fail(function(){
-                       connected = false;
-                       modal = $modal.open({
-                               animation:false,
-                               backdrop: "static",
-                               keyboard: false,
-                               size: "md",
-                               templateUrl: "widgets/juci-disconnected.html"
-                       });
-                       var i = 1;
-                       function reconnect(){
-                               if(i < 10) i += 2;
-                               $rpc.$reconnect().done(function(){
-                                       $events.resubscribe();
-                                       modal.close();
-                                       next();
-                               }).fail(function(){
-                                       setTimeout(function(){ reconnect();}, 1000*i);
-                               });
-                       }
-                       setTimeout(function(){ reconnect(); }, 1000);
-               }).done(function(){
-                       if($rpc.$isLoggedIn() && ++i > 2){
-                               i = 0;
-                               $rpc.$authenticate().fail(function(){
-                                       //console.log("logging you out from app.js");
-                                       $rpc.$clearSession().done(function(){
-                                               setTimeout(function(){$juci.redirect("login");}, 0);
-                                       });
-                               });
-                       }
-                       next();
-               });
-       });
 
 })
 .directive('ngOnload', [function(){
index 301cc8c..e7493f1 100644 (file)
                                                }
                                        },
                                        // this function will run upon load of every page in the gui
-                                       onEnter: function($uci, $window, $rootScope, $tr){
+                                       onEnter: function($uci, $window, $rootScope, $tr, $modal, $events){
                                                
                                                $rootScope.errors.splice(0, $rootScope.errors.length);
                                                
 
                                                // scroll to top
                                                $window.scrollTo(0, 0);
+                                               // setup automatic connection "pinging" and show spinner if you have lost connection
+                                               // if you are connected this will test if you are logged in or redirect you to login page
+                                               var modal;
+                                               var connected = true;
+                                               var i = 1;
+                                               JUCI.interval.repeat("check-connection", 2000, function(next){
+                                                       $rpc.$isConnected().fail(function(){
+                                                               connected = false;
+                                                               modal = $modal.open({
+                                                                       animation:false,
+                                                                       backdrop: "static",
+                                                                       keyboard: false,
+                                                                       size: "md",
+                                                                       templateUrl: "widgets/juci-disconnected.html"
+                                                               });
+                                                               var i = 1;
+                                                               function reconnect(){
+                                                                       if(i < 10) i += 2;
+                                                                       $rpc.$reconnect().done(function(){
+                                                                               $events.resubscribe();
+                                                                               modal.close();
+                                                                               next();
+                                                                       }).fail(function(){
+                                                                               setTimeout(function(){ reconnect();}, 1000*i);
+                                                                       });
+                                                               }
+                                                               setTimeout(function(){ reconnect(); }, 1000);
+                                                       }).done(function(){
+                                                               if($rpc.$isLoggedIn() && ++i > 2){
+                                                                       i = 0;
+                                                                       $rpc.$authenticate().fail(function(){
+                                                                               //console.log("logging you out from app.js");
+                                                                               $rpc.$clearSession().done(function(){
+                                                                                       setTimeout(function(){$juci.redirect("login");}, 0);
+                                                                               });
+                                                                       });
+                                                               }
+                                                               next();
+                                                       });
+                                               });
                                        },
                                        onExit: function($uci, $tr, gettext, $events){
                                                JUCI.interval.$clearAll();
index dd22f35..394ced4 100644 (file)
                $reconnect: function(){
                        var self = this;
                        var def = $.Deferred();
-                       if(ws && ws.readyState === 1) return def.reject();
+                       if(ws && ws.readyState === 1) ws.close();
                        self.$init_websocket().done(function(res){
                                ws = res;
                                def.resolve();
diff --git a/plugins/juci-diagnostics/Makefile b/plugins/juci-diagnostics/Makefile
deleted file mode 100644 (file)
index ce9a363..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-define Plugin/juci-diagnostics/install 
-       $(Q)@$(INSTALL_DIR) $(1)/usr/bin/
-       $(Q)@chmod +x $(PLUGIN_DIR)/scripts/*
-       $(Q)@$(CP) $(PLUGIN_DIR)/scripts/* $(1)/usr/bin/
-endef
-
index 3cc3edb..7e51e57 100644 (file)
@@ -3,20 +3,18 @@
                "description": "JUCI Diagnostics module",
                "read": {
                        "ubus": {
-                               "juci.speedtest": [
-                                       "run",
-                                       "get_packet_size",
-                                       "is_running"
-                               ],
                                "juci.diagnostics": [
                                        "ping",
-                                       "traceroute"
+                                       "traceroute",
+                                       "tptest_start",
+                                       "tptest_packet_size",
+                                       "tptest_running"
                                ]
                        },
                        "uci": [
                                "speedtest"     
                        ],
-                       "owsd": [ "juci.utils.speedtest" ]
+                       "owsd": [ "diagnostics.speedtest" ]
                },
                "write": {
                        "uci": [
diff --git a/plugins/juci-diagnostics/scripts/tptest-run b/plugins/juci-diagnostics/scripts/tptest-run
deleted file mode 100755 (executable)
index d33c413..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-
-. /usr/share/libubox/jshn.sh
-
-local SUCCESS=0
-
-local args="$1"
-local sent="none"
-local received="none"
-local label="success"
-
-json_load "$args"
-json_get_var auto auto "1"
-json_get_var testmode testmode "up_down"
-json_get_var packetsize_up packetsize_up 50000
-json_get_var packetsize_down packetsize_down 50000
-json_get_var address address
-json_get_var port port
-
-case "$testmode" in
-       *up*)
-               if [ "$auto" == "1" ]; then
-                       sent=$(tptest -n 1 -m tcp-send-auto -v 1 $address $port | awk '/TCP Send/{print($3)}')
-               else
-                       sent=$(tptest -n 1 -m tcp-send 60 $packetsize_up -v 2 $address $port | awk '/Throughput/{print($2)}')
-               fi
-esac
-
-case "$testmode" in
-       *down*)
-               if [ "$auto" == "1" ]; then
-                       received=$(tptest -n 1 -m tcp-receive-auto -v 1 $address $port | awk '/TCP Recv/{print($3)}')
-               else
-                       received=$(tptest -n 1 -m tcp-receive 60 $packetsize_down -v 2 $address $port | awk '/Throughput/{print($2)}')
-               fi
-esac
-
-if [ -z "$received" -o -z "$sent" ]; then
-       SUCCESS=-1;
-       label="wrong address:port combination";
-fi
-
-ubus send juci.utils.speedtest "{\"status\":$SUCCESS, \"upstream\":\"$sent\",\"downstream\":\"$received\",\"label\":\"$label\"}"
index e7649e5..05af3e7 100644 (file)
@@ -41,9 +41,9 @@
                                {{'Run test' | translate}}</button>
                        </juci-config-line>
                </juci-config-lines>
-               <div class="alert alert-success" ng-show="data.state == 'result'">
+               <div class="alert alert-success" ng-show="data.result.length">
                        {{'Test results'|translate}}: <br/>
-                       <pre>{{data.result}}</pre>
+                       <pre ng-repeat="res in data.result track by $index">{{res}}<button class="btn btn-primary pull-right" ng-click="removeResult(res)"><i class="fa fa-close"></i></button</pre>
                </div>
                <div class="alert alert-success" ng-show="data.state == 'running'">
                        <h4>
index 028afe1..19dc135 100644 (file)
@@ -10,44 +10,58 @@ JUCI.app
        };
 })
 .controller("diagnosticsWidget90Speedtest", function($scope, $rpc, $events, $uci, utilsAddTestserverPicker, $tr, gettext){
+       var SEQ = 0
        $scope.data = {
                test_type: "up_down",
-               result: "",
+               result: [],
                state: "",
                auto: true
        }; 
 
-       $rpc.$call("juci.speedtest", "is_running").done(function(res){
-               if(res.running){
-                       $scope.data.state = "running";
-                       $scope.$apply();
-               }
-       });
-
-       function getDefaultPacketSize(){
-               $rpc.$call("juci.speedtest", "get_packet_size").done(function(data){
-                       $scope.data.downsize = parseInt(data.packetsize_down);
-                       $scope.data.upsize = parseInt(data.packetsize_up);
-                       $scope.$apply();
-               }).fail(function(e){ console.log(e); });
+       function refresh(){
+               var def = $.Deferred();
+               $rpc.$call("juci.diagnostics", "tptest_running").done(function(res){
+                       if(!res){
+                               def.reject();
+                               return;
+                       }
+                       if(res.running)
+                               $scope.data.state = "running";
+                       else if($scope.data.state === "running")
+                               $scope.data.state = "";
+                       if(res["sequence numbers"] && res["sequence numbers"].length){
+                               res["sequence numbers"].map(function(seq){
+                                       if(SEQ < seq)
+                                               SEQ = seq;
+                               });
+                       }
+                       def.resolve();
+               }).fail(function(e){def.reject(e);});
+               return def.promise();
        }
-       getDefaultPacketSize();
 
-       $scope.$watch('data.auto', function(new_value){
-               if(new_value === false){ getDefaultPacketSize(); }
-       }, false);
 
-       function getServers(){
-               $scope.allTestServers = $scope.testServers.map(function(x){
-                       return {
-                               label: x.server.value + ":" + x.port.value,
-                               value: x.server.value
-                       }
+       JUCI.interval.repeat("diagnostics-tptest-running", 10000, function(next){
+               refresh().done(function(){
+                       $scope.$apply();
+               }).always(function(){
+                       next();
+               });
+       });
+
+       $scope.removeResult = function(res){
+               if(!res) return;
+               $scope.data.result = $scope.data.result.filter(function(r){
+                       return r !== res;
                });
-               if($scope.allTestServers.length)
-                       $scope.data.server = $scope.allTestServers[0].value;
        }
 
+       $rpc.$call("juci.diagnostics", "tptest_packet_size").done(function(data){
+               $scope.data.downsize = parseInt(data.packetsize_down);
+               $scope.data.upsize = parseInt(data.packetsize_up);
+               $scope.$apply();
+       }).fail(function(e){ console.log(e); });
+
        $scope.testType = [
                {value:"down", label: $tr(gettext("Download")) },
                {value:"up", label: $tr(gettext("Upload")) },
@@ -56,21 +70,24 @@ JUCI.app
 
        $uci.$sync("speedtest").done(function(){
                $scope.testServers = $uci.speedtest["@testserver"];
-               getServers();
+               $scope.allTestServers = $scope.testServers.map(function(x){
+                       return {
+                               label: x.server.value + ":" + x.port.value,
+                               value: x.server.value
+                       }
+               });
+               if($scope.allTestServers.length)
+                       $scope.data.server = $scope.allTestServers[0].value;
                $scope.$apply();
        });
 
        $scope.runTest = function(){
-               if($scope.data.test_type.indexOf("up") !== -1 && !$scope.data.upsize){ alert("Upstream packet size missing"); return; }
-               if($scope.data.test_type.indexOf("down") !==-1 && !$scope.data.downsize){ alert("Downstream packet size missing"); return; }
+               if($scope.data.test_type.match(/up/) && !$scope.data.upsize){ alert("Upstream packet size missing"); return; }
+               if($scope.data.test_type.match(/down/) && !$scope.data.downsize){ alert("Downstream packet size missing"); return; }
                if(!$scope.testServers.length){
                        window.alert($tr(gettext("Server and port is mandatory")));
                        return;
                }
-               if($scope.data.state == "running"){
-                       window.alert($tr(gettext("Only one test can be run at a time")));
-                       return;
-               }
                var server = $scope.testServers.find(function(x){ return $scope.data.server == x.server.value;});
                var port = server.port.value;
                var address = server.server.value;
@@ -79,30 +96,29 @@ JUCI.app
                        "auto": $scope.data.auto,
                        "testmode": $scope.data.test_type,
                        "port": port,
-                       "address": address
+                       "host": address,
+                       "seq": SEQ++
                };
 
-               if($scope.data.test_type.indexOf("up") !== -1){
+               if($scope.data.test_type.match(/up/) && !$scope.data.auto){
                        speedtestArgs.packetsize_up = $scope.data.upsize * 1000000;
                }
-               if($scope.data.test_type.indexOf("down") !== -1){
+               if($scope.data.test_type.match(/down/) && !$scope.data.auto){
                        speedtestArgs.packetsize_down = $scope.data.downsize * 1000000;
                }
 
-               $rpc.$call("juci.speedtest", "run", speedtestArgs).done(function(response){
+               $rpc.$call("juci.diagnostics", "tptest_start", speedtestArgs).done(function(response){
                        if(response && response.message=="success"){
                                $scope.data.state="running";
                        }else{
                                $scope.data.state="";
                        }
                        $scope.$apply();
+               }).fail(function(e){
+                       console.log(e);
+                       $scope.data.state = "";
+                       $scope.$apply();
                });
-               setTimeout(function(){
-                       if($scope.data.state === "running"){
-                               $scope.data.state = "error";
-                               $scope.data.result = $tr(gettext("Unknown error"));
-                       }
-               }, 15000);
        };
 
        $scope.onRemoveAddress = function(){
@@ -132,10 +148,14 @@ JUCI.app
                        });
                });
        }
-       $events.subscribe("juci.utils.speedtest", function(res){
+       $events.subscribe("diagnostics.speedtest", function(res){
                if(res.data && res.data.status != undefined){
                        switch(res.data.status) {
                        case 0:
+                               if(res.data.seq && SEQ){
+                                       if(SEQ != res.data.seq)
+                                               return;
+                               }
                                var upstream = parseInt(res.data.upstream);
                                if(upstream == "NaN") {
                                        upstream = "none"
@@ -149,26 +169,24 @@ JUCI.app
                                        downstream = downstream / 1000 / 1000;
                                }
                                if(res.data.upstream != "none" && res.data.downstream != "none"){
-                                       $scope.data.result=$tr(gettext("Downstream:"))+" " + downstream.toFixed(2) + " " + $tr(gettext("Mbit/s\nUpstream:"))+" " + upstream.toFixed(2) +" "+$tr(gettext("Mbit/s"));
+                                       $scope.data.result.push($tr(gettext("Downstream:"))+" " + downstream.toFixed(2) + " " + $tr(gettext("Mbit/s\nUpstream:"))+" " + upstream.toFixed(2) +" "+$tr(gettext("Mbit/s")));
                                }else if(res.data.upstream != "none"){
-                                       $scope.data.result=$tr(gettext("Upstream:"))+" " + upstream.toFixed(2) + " "+$tr(gettext("Mbit/s"));
+                                       $scope.data.result.push($tr(gettext("Upstream:"))+" " + upstream.toFixed(2) + " "+$tr(gettext("Mbit/s")));
                                }else if(res.data.downstream != "none"){
-                                       $scope.data.result=$tr(gettext("Downstream:"))+" " + downstream.toFixed(2) + " "+$tr(gettext("Mbit/s"));
+                                       $scope.data.result.push($tr(gettext("Downstream:"))+" " + downstream.toFixed(2) + " "+$tr(gettext("Mbit/s")));
                                }else {
-                                       $scope.data.result="No speeds found";
+                                       $scope.data.result.push($tr(gettext("No speeds found")));
                                }
                                $scope.data.state="result";
                                break;
                        case -1:
-                               $scope.data.result=$tr(gettext("Wrong TP-test address and/or port"));
-                               $scope.data.state="error";
-                               break;
-                       case -2:
-                               $scope.data.result=$tr(gettext("Wrong TP-test port but correct address"));
+                               $scope.data.result.push($tr(gettext("Wrong TP-test address and/or port")));
                                $scope.data.state="error";
                                break;
                        }
-                       $scope.$apply();
+                       refresh().always(function(){
+                               $scope.$apply();
+                       });
                }
        });
 }); 
index c9c8ed2..6e6a8ff 100755 (executable)
 #!/bin/sh
 
 . /usr/share/libubox/jshn.sh
+. /lib/functions.sh
+
+is_num() {
+       [ "$1" == "" ] && return 1
+       [ "$(echo $1 | sed 's/[0-9]//g')" == "" ] && return 0 || return 1
+}
+
+validate_ping_traceroute() {
+       host="$1"
+       seq="$2"
+       count="$3"
+       timeout="$4"
+       [ "$host" == "" ] && return 1
+       is_num $seq || return 1
+       is_num $count || return 1
+       is_num $timeout || return 1
+       return 0
+}
+validate_arguments_tptest() {
+       host="$1"
+       testmode="$2"
+       packetsize_up="$3"
+       packetsize_down="$4"
+       port="$5"
+       auto="$6"
+       is_num $port || return 1
+       [ "$host" == "" ] && return 1
+       case $testmode in
+               up|down|up_down);;
+               *) return 1 ;;
+       esac
+       if [ "$auto" == "0" ]; then
+               case $testmode in
+                       *up*)
+                               is_num $packetsize_up || return 1
+                               ;;
+               esac
+               case $testmode in
+                       *down*)
+                               is_num $packetsize_down || return 1
+                               ;;
+               esac
+       elif [ "$auto" == "1" ]; then
+               return 0;
+       else
+               return 1
+       fi
+}
+
+run_cmd() {
+       CMND=$1
+       input=$2
+
+       read input;
+
+       json_load "$input"
+       json_get_var host host
+
+       json_init
+       json_add_string stdout "$($CMND $host)"
+       json_dump
+}
+
+ifaces="ethernet vdsl adsl"
+
+get_packet_sizes () {
+       local option="$1"
+       local packetsizes
+
+       packetsizes=$(uci -q get speedtest.@packetsize[0].$option)
+
+       if [ "$packetsizes" ]; then
+               packetsize_down=${packetsizes%/*}
+               packetsize_up=${packetsizes#*/}
+       else
+               case "$option" in
+                       ethernet)
+                               packetsize_up=5
+                               packetsize_down=100
+                               ;;
+                       vdsl)
+                               packetsize_up=3
+                               packetsize_down=50
+                               ;;
+                       adsl)
+                               packetsize_up=1
+                               packetsize_down=25
+                               ;;
+                       *)
+                               packetsize_up=1
+                               packetsize_down=25
+               esac
+       fi
+}
+
+get_iface () {
+       iface=$(ip route | awk '/default via/{print $5}')
+       case "$iface" in
+               eth*)
+                       iface="ethernet"
+               ;;
+               atm*)
+                       iface="adsl"
+               ;;
+               ptm*)
+                       iface="vdsl"
+               ;;
+               wwan*)
+                       iface="vdsl"
+               ;;
+               br-*)
+                       iface="ethernet"
+               ;;
+               *)
+                       iface="ethernet"
+       esac
+}
+
+local input
 
 case "$1" in
        list)
-               echo '{ "ping" : {"host":"str"}, "ping6" : {"host":"str"}, "traceroute" : {"host":"str"}, "traceroute6" : {"host":"str"} }'
+               echo '{ "ping" : {"host":"str", "seq":32, "count":32, "timeout":32},
+                       "ping6" : {"host":"str", "seq":32, "count":32, "timeout":32},
+                       "traceroute" : {"host":"str", "seq":32, "querycount":32, "timeout":32},
+                       "traceroute6" : {"host":"str", "seq":32, "querycount":32, "timeout":32},
+                       "tptest_start" : {"seq":32, "auto": true, "testmode":"str","packetsize_up":32,"packetsize_down":32,"port":32},
+                       "tptest_packet_size" : {},
+                       "tptest_running": {} }'
        ;;
        call)
                case "$2" in
-                       ping|ping6) CMND="$2 -c 5 -W 1" ;;
-                       traceroute|traceroute6) CMND="$2 -q 1 -w 1 -n" ;;
+                       ping|ping6)
+                               local cmd=$2
+                               local host seq count timeout
+                               read input
+                               json_load "$input"
+                               json_get_var host host
+                               json_get_var seq seq 0
+                               json_get_var count count 1
+                               json_get_var timeout timeout 1
+                               validate_ping_traceroute $host $seq $count $timeout && {
+                                       diagnostics -U -s $seq -C $cmd -h $host -c $count -W $timeout >/dev/null 2>&1 &
+                                       json_init
+                                       json_add_string "state" "running"
+                                       json_add_string "message" "success"
+                                       json_dump
+                               } || {
+                                       json_init
+                                       json_add_string "state" "error"
+                                       json_add_string "message" "invalid arguments"
+                                       json_dump
+                               }
+                               ;;
+                       traceroute|traceroute6)
+                               local cmd=$2
+                               local host seq count timeout
+                               read input
+                               json_load "$input"
+                               json_get_var host host
+                               json_get_var seq seq 0
+                               json_get_var count count 1
+                               json_get_var timeout timeout 1
+                               validate_ping_traceroute $host $seq $count $timeout && {
+                                       diagnostics -U -s $seq -C $cmd -h $host -q $count -w $timeout >/dev/null 2>&1 &
+                                       json_init
+                                       json_add_string "state" "running"
+                                       json_add_string "message" "success"
+                                       json_dump
+                               } || {
+                                       json_init
+                                       json_add_string "state" "error"
+                                       json_add_string "message" "invalid arguments"
+                                       json_dump
+                               }
+                               ;;
+                       tptest_start)
+                               local host seq testmode packetsize_up packetsize_down port auto
+                               read input
+                               json_load "$input"
+                               json_get_var host host ""
+                               json_get_var seq seq 1
+                               json_get_var testmode testmode "up_down"
+                               json_get_var packetsize_up packetsize_up 50000
+                               json_get_var packetsize_down packetsize_down 50000
+                               json_get_var port port 0
+                               json_get_var auto auto 1
+                               validate_arguments_tptest "$host" "$testmode" "$packetsize_up" "$packetsize_down" "$port" "$auto" && {
+                                       echo "ok arguments" >/dev/console
+                                       if [ $auto -eq 1 ]; then
+                                               diagnostics -U -s $seq -C tptest -a -t $testmode -h $host -p $port >/dev/null 2>&1 &
+                                       else
+                                               diagnostics -U -s $seq -C tptest -u $packetsize_up -d $packetsize_down -t $testmode -h $host -p $port >/dev/null 2>&1 &
+                                       fi
+                                       json_init
+                                       json_add_string "state" "running"
+                                       json_add_string "message" "success"
+                                       json_dump
+                               } || {
+                                       json_init
+                                       json_add_string "state" "error"
+                                       json_add_string "message" "invalid arguments"
+                                       json_dump
+                               }
+                       ;;
+                       tptest_running)
+                               json_init
+                               seqs="$(ps -w | awk '/diagnostic[s].*-C tptest/ { print $10 }' | sort -u)"
+                               if [ "$seqs" == "" ]; then
+                                       json_add_string "message" "Not running"
+                                       json_add_boolean "running" 0
+                                       json_dump
+                                       exit
+                               else
+                                       json_add_string "message" "Running"
+                                       json_add_boolean "running" 1
+                               fi
+                               json_add_array "sequence numbers"
+                               for s in $seqs; do
+                                       json_add_int "" $s
+                               done
+                               json_close_array
+                               json_dump
+                       ;;
+                       tptest_packet_size)
+                               get_iface
+
+                               for i in $ifaces; do
+                                       if [ $iface == "$i" ]; then
+                                               get_packet_sizes $iface
+                                               json_init
+                                               json_add_string "packetsize_up" "$packetsize_up"
+                                               json_add_string "packetsize_down" "$packetsize_down"
+                                               json_dump
+                                               return
+                                       fi
+                               done
+                       ;;
                        *) return 1 ;;
                esac
-
-               read input;
-
-               json_load "$input"
-               json_get_var host host
-       
-               json_init
-               json_add_string stdout "$($CMND $host)"
-               json_dump
        ;;
 esac
diff --git a/plugins/juci-diagnostics/ubus/juci.speedtest b/plugins/juci-diagnostics/ubus/juci.speedtest
deleted file mode 100755 (executable)
index 0d1fcd3..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/bin/sh 
-
-. /usr/share/libubox/jshn.sh 
-. /lib/functions.sh
-
-ifaces="ethernet vdsl adsl"
-
-get_packet_sizes () {
-       local option="$1"
-       local packetsizes
-
-#      config_load speedtest
-#      config_get packetsizes packetsize $option
-       packetsizes=$(uci -q get speedtest.@packetsize[0].$option)
-
-       if [ "$packetsizes" ]; then
-               packetsize_down=${packetsizes%/*}
-               packetsize_up=${packetsizes#*/}
-       else
-               case "$option" in
-                       ethernet)
-                               packetsize_up=5
-                               packetsize_down=100
-                               ;;
-                       vdsl)
-                               packetsize_up=3
-                               packetsize_down=50
-                               ;;
-                       adsl)
-                               packetsize_up=1
-                               packetsize_down=25
-                               ;;
-                       *)
-                               packetsize_up=1
-                               packetsize_down=25
-               esac
-       fi
-}
-
-get_iface () {
-       iface=$(ip route | awk '/default via/{print $5}')
-       case "$iface" in
-               eth*)
-                       iface="ethernet"
-               ;;
-               atm*)
-                       iface="adsl"
-               ;;
-               ptm*)
-                       iface="vdsl"
-               ;;
-               wwan*)
-                       iface="vdsl"
-               ;;
-               br-*)
-                       iface="ethernet"
-               ;;
-               *)
-                       iface="ethernet"
-       esac
-}
-
-case "$1" in
-       list)
-               echo '{ "run" : {"testmode":"str","packetsize_up":32,"packetsize_down":32,"address":"str","port":32}, "get_packet_size" : {}, "is_running": {} }'
-       ;;
-       call)
-               case "$2" in
-                       run)
-                               if pidof tptest-run >/dev/null; then
-                                       json_init
-                                       json_add_string "state" "error"
-                                       json_add_string "message" "there is already a speedtest going on"
-                                       json_dump
-                               else
-                                       read input
-                                       tptest-run "$input" >/dev/null 2>&1 &
-                                       json_init
-                                       json_add_string "state" "running"
-                                       json_add_string "message" "success"
-                                       json_dump
-                               fi
-                       ;;
-                       is_running)
-                               json_init
-                               if pidof tptest-run >/dev/null; then
-                                       json_add_string "message" "running"
-                                       json_add_boolean "running" 1
-                               else
-                                       json_add_string "message" "not running"
-                                       json_add_boolean "running" 0
-                               fi
-                               json_dump
-                       ;;
-                       get_packet_size)
-                               get_iface
-
-                               for i in $ifaces; do
-                                       if [ $iface == "$i" ]; then
-                                               get_packet_sizes $iface
-                                               json_init
-                                               json_add_string "packetsize_up" "$packetsize_up"
-                                               json_add_string "packetsize_down" "$packetsize_down"
-                                               json_dump
-                                               return
-                                       fi
-                               done
-                       ;;
-               esac
-       ;;
-esac