Updated diagnostics page and tptest page to use new diagnostics backend
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Fri, 24 Mar 2017 14:59:59 +0000 (15:59 +0100)
committerReidar Cederqvist <reidar.cederqvist@gmail.com>
Fri, 24 Mar 2017 14:59:59 +0000 (15:59 +0100)
plugins/juci-diagnostics/access.json
plugins/juci-diagnostics/src/diagnostics.js
plugins/juci-diagnostics/src/pages/status-diagnostics-speedtest.js
plugins/juci-diagnostics/src/pages/status-diagnostics.html
plugins/juci-diagnostics/src/pages/status-diagnostics.js
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.html
plugins/juci-diagnostics/src/widgets/diagnostics-widget-speedtest.js
plugins/juci-diagnostics/src/widgets/utils-add-testserver-picker.js

index 7e51e57..e5653e4 100644 (file)
                        "uci": [
                                "speedtest"     
                        ],
-                       "owsd": [ "diagnostics.speedtest" ]
+                       "owsd": [
+                               "diagnostics.speedtest",
+                               "diagnostics.ping",
+                               "diagnostics.ping6",
+                               "diagnostics.traceroute",
+                               "diagnostics.traceroute6"
+                       ]
                },
                "write": {
                        "uci": [
index 00086c7..6dbedf7 100644 (file)
@@ -1,8 +1,8 @@
 //! Author: Reidar Cederqvst <reidar.cederqvist@gmail.com>
 
-UCI.$registerConfig("speedtest"); 
+UCI.$registerConfig("speedtest");
 UCI.speedtest.$registerSectionType("testserver", {
-       "server":               { dvalue: "", type: String }, 
+       "server":               { dvalue: "", type: String },
        "port":                 { dvalue: "", type: String }
 });
 
index bd4de6f..2f973bb 100644 (file)
@@ -2,28 +2,24 @@
        <div ng-controller="StatusDiagnostics">
                <juci-config-heading>{{ 'Diagnostic Utility' | translate }}</juci-config-heading>
                <juci-config-info>{{ 'status.diagnostics.info' | translate }}</juci-config-info>
-               
-               <!--<juci-config-section>
-                       <h3>{{'Automated Diagnostics'|translate}}</h3>
-                       <p>{{'status.diagnostics.auto.info'|translate}}</p>
-                       <juci-config-lines>
-                               <juci-config-line title="">
-                                       <button class="btn btn-lg btn-default">{{'Diagnose'|translate}}</button>
-                               </juci-config-line>
-                       </juci-config-lines>
-               </juci-config-section>-->
                <juci-config-section>
                        <juci-config-lines>
                                <juci-config-line title="{{'Ping Test'|translate}}" help="{{'status.diagnostics.ping.info'|translate}}" error="validate('pingHost')">
                                        <div class="row">
                                                <form class="form-inline form-group  pull-right">
                                                        <input type="text" class="form-control input-lg" placeholder="{{'Host to ping'|translate}}" ng-model="data.pingHost"></input>
-                                                       <button type="submit" class="btn btn-lg btn-default" ng-click="onPingTest()">{{'Ping'|translate}}</button>
+                                                       <button ng-class="{'disabled': validate('pingHost') != null}" type="submit" class="btn btn-lg btn-default" ng-click="onPingTest()">{{'Ping'|translate}}</button>
                                                </form>
                                        </div>
                                </juci-config-line>
                        </juci-config-lines>
-                       <div class="alert alert-default" ng-show="data.pingResults">{{'Ping results'|translate}}: <br/><pre>{{data.pingResults}}</pre></div>
+                       <div class="alert alert-default" ng-show="data.pingRunning">{{'Running Ping'|translate}} <i class="fa fa-spinner fa-spin"></i></div>
+                       <div class="alert alert-default" ng-show="data.pingResults.length" ng-repeat="res in data.pingResults track by $index">{{'Ping results'|translate}}: <br/>
+                               <pre>
+                                       <button class="btn btn-default pull-right" ng-click="deleteResult(res)"><i class="fa fa-close"></i></button>
+                                       {{res}}
+                               </pre>
+                       </div>
                        <div class="alert alert-danger" ng-show="data.pingError">{{'Error'|translate}}: <br/><pre>{{data.pingError}}</pre></div>
                </juci-config-section>
                <juci-config-section>
                                        <div class="row">
                                                <form class="form-inline form-group  pull-right">
                                                        <input type="text" class="form-control input-lg" placeholder="{{'Host to trace'|translate}}" ng-model="data.traceHost"></input>
-                                                       <button type="submit" class="btn btn-lg btn-default" ng-click="onTraceTest()">{{'Trace'|translate}}</button>
+                                                       <button ng-class="{'disabled': validate('traceHost') != null}" type="submit" class="btn btn-lg btn-default" ng-click="onTraceTest()">{{'Trace'|translate}}</button>
                                                </form>
                                        </div>
                                </juci-config-line>
                        </juci-config-lines>
-                       <div class="alert alert-default" ng-show="data.traceResults">{{'Trace results'|translate}}: <br/><pre>{{data.traceResults}}</pre></div>
+                       <div class="alert alert-default" ng-show="data.traceRunning">{{'Running Trace'|translate}} <i class="fa fa-spinner fa-spin"></i></div>
+                       <div class="alert alert-default" ng-show="data.traceResults.length" ng-repeat="res in data.traceResults track by $index">{{'Trace results'|translate}}: <br/>
+                               <pre>
+                                       <button class="btn btn-default pull-right" ng-click="deleteResult(res)"><i class="fa fa-close"></i></button>
+                                       {{res}}
+                               </pre>
+                       </div>
                        <div class="alert alert-danger" ng-show="data.traceError">{{'Error'|translate}}: <br/><pre>{{data.traceError}}</pre></div>
                </juci-config-section>
        <!--    <juci-config-section>
index c0031bb..e786a11 100644 (file)
  */
 
 JUCI.app
-.controller("StatusDiagnostics", function($scope, $rpc, $network, $tr, gettext){
-       $scope.data = {}; 
-       $network.getNetworks().done(function(nets){
-               $scope.data.allInterfaces = nets.map(function(x){ return { label: x[".name"], value: x[".name"] }; }); 
-               $scope.$apply(); 
-       }); 
-       $scope.onTraceTest = function(){
-               $scope.data.traceResults = "...";
-               $scope.data.error = "";
-               $rpc.$call("juci.diagnostics", "traceroute", { "host": $scope.data.traceHost }).done(function(result){
-                       if(result.stderr) $scope.data.traceError = result.stderr; 
-                       $scope.data.traceResults = result.stdout; 
-                       $scope.$apply(); 
+.controller("StatusDiagnostics", function($scope, $rpc, $tr, gettext, $events){
+       $scope.data = {
+               pingResults: [],
+               pingv6: false,
+               pingCount: 5,
+               pingWait: 1,
+               pingRunning: false,
+               pingError: "",
+               traceResults: [],
+               tracev6: false,
+               traceCount: 1,
+               traceWait: 1,
+               traceRunning: false,
+               traceError: ""
+       };
+       $scope.onPingTest = function(){
+               if($scope.validate("pingHost") !== null) return;
+               $scope.data.pingError = "";
+               var ping = $scope.data.ping6 ? "ping6" : "ping";
+               var pingArgs = {
+                       "host": $scope.data.pingHost,
+                       "count": $scope.data.pingCount,
+                       "timeout": $scope.data.pingWait
+               }
+               $rpc.$call("juci.diagnostics", ping, pingArgs).done(function(result){
+                       if(result && result.state === "running") $scope.data.pingRunning = true;
+                       $scope.data.pingHost = "";
                }).fail(function(error){
-                       $scope.data.traceResults = ""; 
-                       $scope.data.traceError = JSON.stringify(error); 
-                       $scope.$apply(); 
-               }); 
+                       $scope.data.pingError = JSON.stringify(error);
+               }).always(function(){
+                       $scope.$apply();
+               });
        }
-       $scope.onPingTest = function(){
-               $scope.data.pingResults = "..."; 
-               $scope.data.error = "";
-               $rpc.$call("juci.diagnostics", "ping", { "host": $scope.data.pingHost }).done(function(result){
-                       if(result.stderr) $scope.data.pingError = result.stderr; 
-                       $scope.data.pingResults = result.stdout; 
-                       $scope.$apply(); 
+       $scope.onTraceTest = function(){
+               if($scope.validate("traceHost") !== null) return;
+               $scope.data.traceError = "";
+               var trace = $scope.data.trace6 ? "traceroute6" : "traceroute";
+               var traceArgs = {
+                       "host": $scope.data.traceHost,
+                       "count": $scope.data.traceCount,
+                       "timeout": $scope.data.traceWait
+               }
+               $rpc.$call("juci.diagnostics", trace, traceArgs).done(function(result){
+                       if(result && result.state === "running") $scope.data.traceRunning = true;
+                       $scope.data.traceHost = "";
                }).fail(function(error){
-                       $scope.data.pingResults = ""; 
-                       $scope.data.pingError = JSON.stringify(error); 
-                       $scope.$apply(); 
-               }); 
+                       $scope.data.traceError = JSON.stringify(error);
+               }).always(function(){
+                       $scope.$apply();
+               });
        }
        $scope.validate = function(type){
                if(!$scope.data || !$scope.data[type]) return null;
                if(String($scope.data[type]).match(/[^A-z0-9}\.\-]/)) return $tr(gettext("Not a valid domain or ip address"));
                return null;
        }
-}); 
+       $scope.deleteResult = function(res){
+               $scope.data.pingResults = $scope.data.pingResults.filter(function(r){ return r !== res; });
+               $scope.data.traceResults = $scope.data.traceResults.filter(function(r){ return r !== res; });
+       }
+       $events.subscribe("diagnostics.ping", function(res){
+               if(res && res.data){
+                       if(res.data.stdout)
+                               $scope.data.pingResults.push(res.data.stdout);
+                       else if(res.data.stderr)
+                               $scope.data.pingError = res.data.stderr;
+                       $scope.data.pingRunning = false;
+                       $scope.$apply();
+               }
+       });
+       $events.subscribe("diagnostics.ping6", function(res){
+               if(res && res.data){
+                       if(res.data.stdout)
+                               $scope.data.pingResults.push(res.data.stdout);
+                       else if(res.data.stderr)
+                               $scope.data.pingError = res.data.stderr;
+                       $scope.data.pingRunning = false;
+                       $scope.$apply();
+               }
+       });
+       $events.subscribe("diagnostics.traceroute", function(res){
+               console.log(res);
+               if(res && res.data){
+                       if(res.data.stdout)
+                               $scope.data.traceResults.push(res.data.stdout);
+                       else if(res.data.stderr)
+                               $scope.data.traceError = res.data.stderr;
+                       $scope.data.traceRunning = false;
+                       $scope.$apply();
+               }
+       });
+       $events.subscribe("diagnostics.traceroute6", function(res){
+               if(res && res.data){
+                       if(res.data.stdout)
+                               $scope.data.traceResults.push(res.data.stdout);
+                       else if(res.data.stderr)
+                               $scope.data.traceError = res.data.stderr;
+                       $scope.data.traceRunning = false;
+                       $scope.$apply();
+               }
+       });
+});
index 05af3e7..7fb8545 100644 (file)
@@ -37,7 +37,7 @@
                                </div>
                        </juci-config-line>
                        <juci-config-line>
-                               <button class="btn btn-default" ng-click="runTest()">
+                               <button ng-class="{'disabled': data.state == 'running'}" class="btn btn-default" ng-click="runTest()">
                                {{'Run test' | translate}}</button>
                        </juci-config-line>
                </juci-config-lines>
index 19dc135..76ccc9d 100644 (file)
@@ -10,13 +10,12 @@ JUCI.app
        };
 })
 .controller("diagnosticsWidget90Speedtest", function($scope, $rpc, $events, $uci, utilsAddTestserverPicker, $tr, gettext){
-       var SEQ = 0
        $scope.data = {
                test_type: "up_down",
                result: [],
                state: "",
                auto: true
-       }; 
+       };
 
        function refresh(){
                var def = $.Deferred();
@@ -25,15 +24,11 @@ JUCI.app
                                def.reject();
                                return;
                        }
-                       if(res.running)
+                       if(res.running){
                                $scope.data.state = "running";
-                       else if($scope.data.state === "running")
+                       }
+                       else if($scope.data.state !== "error"){
                                $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);});
@@ -82,6 +77,7 @@ JUCI.app
        });
 
        $scope.runTest = function(){
+               if($scope.data.state === "running") 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){
@@ -97,7 +93,6 @@ JUCI.app
                        "testmode": $scope.data.test_type,
                        "port": port,
                        "host": address,
-                       "seq": SEQ++
                };
 
                if($scope.data.test_type.match(/up/) && !$scope.data.auto){
@@ -152,10 +147,6 @@ JUCI.app
                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"
@@ -189,4 +180,4 @@ JUCI.app
                        });
                }
        });
-}); 
+});
index 40daa0e..d216aac 100644 (file)
@@ -4,7 +4,7 @@ JUCI.app
 .factory("utilsAddTestserverPicker", function($modal){
        return {
                show: function(){
-                       var def = $.Deferred(); 
+                       var def = $.Deferred();
                        var modalInstance = $modal.open({
                                animation: true,
                                templateUrl: 'widgets/utils-add-testserver-picker.html',
@@ -13,21 +13,21 @@ JUCI.app
 
                        modalInstance.result.then(function (data) {
                                setTimeout(function(){ // do this because the callback is called during $apply() cycle
-                                       def.resolve(data); 
-                               }, 0); 
+                                       def.resolve(data);
+                               }, 0);
                        }, function () {
                                        
                        });
-                       return def.promise(); 
+                       return def.promise();
                }
-       }; 
+       };
 })
 .controller("utilsAddTestserverPicker", function($scope, $modalInstance, $tr, gettext){
-       $scope.data = {}; 
+       $scope.data = {};
        $scope.ok = function () {
                if((!$scope.data.address) || (!$scope.data.port)) {
-                       alert($tr(gettext("Address and port needed"))); 
-                       return; 
+                       alert($tr(gettext("Address and port needed")));
+                       return;
                }
                $modalInstance.close($scope.data);
        };