diagnostics: add tptest_stop functionality
authorSukru Senli <sukru.senli@iopsys.eu>
Fri, 31 Aug 2018 15:12:26 +0000 (17:12 +0200)
committerSukru Senli <sukru.senli@iopsys.eu>
Sat, 8 Sep 2018 11:40:39 +0000 (13:40 +0200)
plugins/juci-diagnostics/access.json
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.html
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.js
plugins/juci-diagnostics/ubus/juci.diagnostics

index e5653e4..372f320 100644 (file)
@@ -7,6 +7,7 @@
                                        "ping",
                                        "traceroute",
                                        "tptest_start",
                                        "ping",
                                        "traceroute",
                                        "tptest_start",
+                                       "tptest_stop",
                                        "tptest_packet_size",
                                        "tptest_running"
                                ]
                                        "tptest_packet_size",
                                        "tptest_running"
                                ]
index 7fb8545..555ebde 100644 (file)
                                </div>
                        </juci-config-line>
                        <juci-config-line>
                                </div>
                        </juci-config-line>
                        <juci-config-line>
-                               <button ng-class="{'disabled': data.state == 'running'}" class="btn btn-default" ng-click="runTest()">
-                               {{'Run test' | translate}}</button>
+                               <button class="btn btn-default">
+                                       <span ng-click="runTest()" ng-show="(data.state != 'running')">{{'Run test' | translate}}</span>
+                                       <span ng-click="abortTest()"ng-show="(data.state == 'running')">{{'Abort' | translate}}</span></span>
+                               </button>
                        </juci-config-line>
                </juci-config-lines>
                <div class="alert alert-success" ng-show="data.result.length">
                        </juci-config-line>
                </juci-config-lines>
                <div class="alert alert-success" ng-show="data.result.length">
index 0b9cf83..36b326c 100644 (file)
@@ -121,6 +121,21 @@ JUCI.app
                });
        };
 
                });
        };
 
+       $scope.abortTest = function(){
+               $rpc.$call("juci.diagnostics", "tptest_stop").done(function(response){
+                       if(response && response.message=="success"){
+                               $scope.data.state="aborted";
+                       }else{
+                               $scope.data.state="";
+                       }
+                       $scope.$apply();
+               }).fail(function(e){
+                       console.log(e);
+                       $scope.data.state = "";
+                       $scope.$apply();
+               });
+       };
+
        $scope.onRemoveAddress = function(){
                var server = $scope.testServers.find(function(x){
                        return $scope.data.server == x.server.value
        $scope.onRemoveAddress = function(){
                var server = $scope.testServers.find(function(x){
                        return $scope.data.server == x.server.value
index 5befdce..9aae9e2 100755 (executable)
@@ -126,6 +126,7 @@ case "$1" in
                        "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},
                        "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_stop" : {},
                        "tptest_packet_size" : {},
                        "tptest_running": {} }'
        ;;
                        "tptest_packet_size" : {},
                        "tptest_running": {} }'
        ;;
@@ -215,6 +216,14 @@ case "$1" in
                                        json_dump
                                }
                        ;;
                                        json_dump
                                }
                        ;;
+                       tptest_stop)
+                               killall -9 diagnostics >/dev/null 2>&1
+                               killall -9 tptest >/dev/null 2>&1
+                                json_init                                                                                                                      
+                                json_add_string "state" "aborted"                                                                                              
+                                json_add_string "message" "success"                                                                                            
+                                json_dump 
+                       ;;
                        tptest_running)
                                json_init
                                seqs="$(ps -w | awk '/diagnostic[s].*-C tptest/ { print $10 }' | sort -u)"
                        tptest_running)
                                json_init
                                seqs="$(ps -w | awk '/diagnostic[s].*-C tptest/ { print $10 }' | sort -u)"