Fixed nat connections count..

This commit is contained in:
Martin Schröder 2015-05-25 14:19:13 +02:00 committed by Martin Schröder
parent 0e71a953ce
commit eedfec2aa6
3 changed files with 30 additions and 31 deletions

View file

@ -1,32 +1,11 @@
/*
* juci - javascript universal client interface
*
* Project Author: Martin K. Schröder <mkschreder.uk@gmail.com>
*
* Copyright (C) 2012-2013 Inteno Broadband Technology AB. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
$juci.module("core")
//! Author: Martin K. Schröder <mkschreder.uk@gmail.com>
JUCI.app
.directive("luciProgress", function(){
var plugin_root = $juci.module("core").plugin_root;
return {
// accepted parameters for this tag
scope: {
percent: "=",
value: "=",
total: "=",
units: "="
@ -34,7 +13,6 @@ $juci.module("core")
templateUrl: plugin_root+"/widgets/luci.progress.html",
replace: true,
controller: "LuciProgressControl",
controllerAs: "ctrl",
link: function(scope, element, attributes){
// make sure we interpret the units as string
scope.units = attributes.units;
@ -42,8 +20,12 @@ $juci.module("core")
};
})
.controller("LuciProgressControl", function($scope, $navigation){
if($scope.value && Number($scope.value) != 0)
$scope.width = Math.round((Number($scope.value) / Number($scope.total)) * 100);
else
$scope.width = 0;
function update(){
if($scope.value && Number($scope.value) != 0)
$scope.width = Math.round((Number($scope.value||0) / Number($scope.total||0)) * 100);
else
$scope.width = 0;
}
$scope.$watch("value", update);
$scope.$watch("total", update);
});

View file

@ -1,5 +1,13 @@
<luci-layout-with-sidebar>
<div ng-controller="StatusNATPageCtrl">
<luci-config-section>
<h2 translate>Connections</h2>
<luci-config-lines>
<luci-config-line title="{{'Active Connections'|translate}}" no-pull>
<luci-progress value="conntrack.count" total="conntrack.limit"></luci-progress>
</luci-config-line>
</luci-config-line>
</luci-config-section>
<luci-config-section>
<luci-config-heading>{{ 'Connections for each Device' | translate }}</luci-config-heading>
<luci-config-info>{{ 'status.nat.connections.info' | translate }}</luci-config-info>
@ -18,7 +26,7 @@
</tr>
</table>
</luci-config-section>
<luci-config-section>
<luci-config-section style="display: none;">
<luci-config-heading>{{ 'NAT Connection Table' | translate }}</luci-config-heading>
<luci-config-info>{{ 'status.nat.info' | translate }}</luci-config-info>
<table class="table" style="font-size: 12px">

View file

@ -1,5 +1,7 @@
JUCI.app
.controller("StatusNATPageCtrl", function($scope, $rpc){
.controller("StatusNATPageCtrl", function($scope, $rpc, $tr, gettext){
$scope.conntrack = { count: 0, limit: 0 };
$rpc.router.clients().done(function(table){
var clients = [];
Object.keys(table).map(function(x){
@ -7,8 +9,15 @@ JUCI.app
if(cl.connected) clients.push(cl);
});
$scope.clients = clients;
$scope.conntrack.count = clients.reduce(function(prev, cur){ return prev + (cur.active_cons||0); }, 0);
$scope.$apply();
});
$rpc.luci2.network.conntrack_count().done(function(res){
$scope.conntrack.limit = res.limit;
$scope.$apply();
});
$rpc.luci2.network.conntrack_table().done(function(table){
if(table && table.entries){
$scope.connections = table.entries.sort(function(a, b){ return (a.src+a.dest) < (b.src+b.dest); }).map(function(x){