From 7fd6119da8bd71209cbd2e6e07db8dd63fca5c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Wed, 20 May 2015 15:21:48 +0200 Subject: [PATCH] Added nat table status --- luciexpress/htdocs/js/config.js | 32 +++++++++++---- luciexpress/htdocs/js/juci.js | 12 +++--- .../plugins/juci-mod-dropbear/dropbear.js | 17 ++++++++ .../pages/services.dropbear.html | 40 ++++++++++++++++++- .../pages/services.dropbear.js | 13 +++++- .../plugins/juci-mod-dropbear/plugin.json | 1 + .../juci-mod-dropbear/tests/test-dropbear.js | 9 +++++ .../plugins/status/pages/status.nat.html | 33 ++++++++++++++- .../htdocs/plugins/status/pages/status.nat.js | 11 +++-- .../plugins/status/pages/status.restart.html | 3 +- luciexpress/share/acl.d/luci2.json | 1 + 11 files changed, 151 insertions(+), 21 deletions(-) create mode 100644 luciexpress/htdocs/plugins/juci-mod-dropbear/dropbear.js create mode 100644 luciexpress/htdocs/plugins/juci-mod-dropbear/tests/test-dropbear.js diff --git a/luciexpress/htdocs/js/config.js b/luciexpress/htdocs/js/config.js index cebd38ce2..c7a747912 100644 --- a/luciexpress/htdocs/js/config.js +++ b/luciexpress/htdocs/js/config.js @@ -8,15 +8,33 @@ var deferred = $.Deferred(); var self = this; console.log("Init CONFIG"); - $.get("/config.json", { - format: "json" - }).done(function(data){ - if(!data || data == undefined) throw new Error("Could not get config.json!"); - Object.keys(data).map(function(k) { self[k] = data[k]; }); - deferred.resolve(); + UCI.sync("juci").done(function(){ + if(UCI.juci && UCI.juci.settings){ + console.log("Using settings from config/juci on router"); + Object.keys(UCI.juci.settings).map(function(k){ + var i = UCI.juci.settings[k]; + if(i instanceof Object && "value" in i) self[k] = i.value; + }); + deferred.resolve(); + } else { + loadJSON(); + } }).fail(function(){ - deferred.reject(); + loadJSON(); }); + function loadJSON(){ + console.log("Using settings from config.json on router"); + $.get("/config.json", { + format: "json" + }).done(function(data){ + if(!data || data == undefined) throw new Error("Could not get config.json!"); + Object.keys(data).map(function(k) { self[k] = data[k]; }); + deferred.resolve(); + }).fail(function(){ + deferred.reject(); + }); + } + return deferred.promise(); } $juci.config = new JUCIConfig(); diff --git a/luciexpress/htdocs/js/juci.js b/luciexpress/htdocs/js/juci.js index 3a5f64d68..c8625d216 100644 --- a/luciexpress/htdocs/js/juci.js +++ b/luciexpress/htdocs/js/juci.js @@ -44,6 +44,11 @@ scope.UBUS.$init().fail(function(){ console.error("UBUS failed to initialize!"); }).always(function(){ next(); }); + }, + function(next){ + $uci.$init().fail(function(){ + console.error("UCI failed to initialize!"); + }).always(function(){ next(); }); }, function(next){ $juci.config.$init().fail(function(){ @@ -139,12 +144,7 @@ console.log("Failed to verify session."); next(); }); - }, - function(next){ - $uci.$init().fail(function(){ - console.error("UCI failed to initialize!"); - }).always(function(){ next(); }); - }, + }, function(next){ // TODO: this will be moved somewhere else. What we want to do is // pick both a theme and plugins based on the router model. diff --git a/luciexpress/htdocs/plugins/juci-mod-dropbear/dropbear.js b/luciexpress/htdocs/plugins/juci-mod-dropbear/dropbear.js new file mode 100644 index 000000000..3e7104d05 --- /dev/null +++ b/luciexpress/htdocs/plugins/juci-mod-dropbear/dropbear.js @@ -0,0 +1,17 @@ + +UCI.$registerConfig("dropbear"); +UCI.dropbear.$registerSectionType("settings", { + "enable": { dvalue: true, type: Boolean }, //Set to 0 to disable starting dropbear at system boot. + "verbose": { dvalue: false, type: Boolean }, //Set to 1 to enable verbose output by the start script. + "BannerFile": { dvalue: "", type: String} , //Name of a file to be printed before the user has authenticated successfully. + "PasswordAuth": { dvalue: true, type: Boolean }, //Set to 0 to disable authenticating with passwords. + "Port": { dvalue: 22, type: Number }, //Port number to listen on. + "RootPasswordAuth": { dvalue: true, type: Boolean }, //Set to 0 to disable authenticating as root with passwords. + "RootLogin": { dvalue: true, type: Boolean }, //Set to 0 to disable SSH logins as root. + "GatewayPorts": { dvalue: false, type: Boolean }, //Set to 1 to allow remote hosts to connect to forwarded ports. + "Interface": { dvalue: "", type: String }, //Tells dropbear to listen only on the specified interface.1) + "rsakeyfile": { dvalue: "", type: String }, //Path to RSA file + "dsskeyfile": { dvalue: "", type: String }, //Path to DSS/DSA file + "SSHKeepAlive": { dvalue: 300, type: Number }, //Keep Alive + "IdleTimeout": { dvalue: 0, type: Number } //Idle Timeout +}); diff --git a/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.html b/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.html index 6f17e5b4e..f075ef0a4 100644 --- a/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.html +++ b/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.html @@ -3,7 +3,45 @@ {{ 'Dropbear' | translate }} {{ 'settings.dropbear.info' | translate }} - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.js b/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.js index 43f93ffe6..217abcf7b 100644 --- a/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.js +++ b/luciexpress/htdocs/plugins/juci-mod-dropbear/pages/services.dropbear.js @@ -1,5 +1,14 @@ //! Author: Martin K. Schröder -$juci.app.controller("DropbearSettings", function($scope){ - +JUCI.app +.controller("DropbearSettings", function($scope, $uci){ + $uci.sync("dropbear").done(function(){ + if($uci.dropbear && $uci.dropbear.settings){ + $scope.dropbear = $uci.dropbear.settings; + $scope.$apply(); + } + }); + $scope.onSave = function(){ + $uci.save(); + } }); diff --git a/luciexpress/htdocs/plugins/juci-mod-dropbear/plugin.json b/luciexpress/htdocs/plugins/juci-mod-dropbear/plugin.json index 75ef4b86c..8d04623cc 100644 --- a/luciexpress/htdocs/plugins/juci-mod-dropbear/plugin.json +++ b/luciexpress/htdocs/plugins/juci-mod-dropbear/plugin.json @@ -1,5 +1,6 @@ { "scripts": [ + "dropbear" ], "pages": { "settings/dropbear": { diff --git a/luciexpress/htdocs/plugins/juci-mod-dropbear/tests/test-dropbear.js b/luciexpress/htdocs/plugins/juci-mod-dropbear/tests/test-dropbear.js new file mode 100644 index 000000000..c92c14c6d --- /dev/null +++ b/luciexpress/htdocs/plugins/juci-mod-dropbear/tests/test-dropbear.js @@ -0,0 +1,9 @@ +global.JUCI = require("../../../../tests/lib-juci"); +require("../dropbear"); + +describe("Dropbear", function(){ + it("should have config dropbear and should have settings section named 'settings'", function(){ + expect($uci.dropbear).to.be.ok(); + expect($uci.dropbear.settings).to.be.ok(); + }); +}); diff --git a/luciexpress/htdocs/plugins/status/pages/status.nat.html b/luciexpress/htdocs/plugins/status/pages/status.nat.html index 5b537615b..6619a58f3 100644 --- a/luciexpress/htdocs/plugins/status/pages/status.nat.html +++ b/luciexpress/htdocs/plugins/status/pages/status.nat.html @@ -1,5 +1,36 @@
- Nat + + {{ 'Nat table' | translate }} + {{ 'status.nat.info' | translate }} + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProtocolSourceDest.Source PortDest. PortRX PacketsTX PacketsRX BytesTX Bytes
{{con.protocol}}{{con.src}}{{con.dest}}{{con.sport}}{{con.dport}}{{con.rx_packets}}{{con.rx_bytes}}{{con.tx_packets}}{{con.tx_bytes}}
+
diff --git a/luciexpress/htdocs/plugins/status/pages/status.nat.js b/luciexpress/htdocs/plugins/status/pages/status.nat.js index c8fc32e94..52daf4ba9 100644 --- a/luciexpress/htdocs/plugins/status/pages/status.nat.js +++ b/luciexpress/htdocs/plugins/status/pages/status.nat.js @@ -1,4 +1,9 @@ -$juci.module("status") -.controller("StatusNATPageCtrl", function($scope){ - +JUCI.app +.controller("StatusNATPageCtrl", function($scope, $rpc){ + $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); }); + $scope.$apply(); + } + }); }); diff --git a/luciexpress/htdocs/plugins/status/pages/status.restart.html b/luciexpress/htdocs/plugins/status/pages/status.restart.html index 7df9ca3b2..8c8f24716 100644 --- a/luciexpress/htdocs/plugins/status/pages/status.restart.html +++ b/luciexpress/htdocs/plugins/status/pages/status.restart.html @@ -1,7 +1,8 @@
- {{ 'EasyBox' | translate }} + {{ 'Restart' | translate }} + {{ 'status.restart.info' | translate }}
diff --git a/luciexpress/share/acl.d/luci2.json b/luciexpress/share/acl.d/luci2.json index 528d75807..32f6ac9b0 100644 --- a/luciexpress/share/acl.d/luci2.json +++ b/luciexpress/share/acl.d/luci2.json @@ -376,6 +376,7 @@ "switch_info", "switch_status", "device_list", + "conntrack_table", "dslstats" ], "luci2.network.bwmon": [