commit 35bb15c369ced1952e1ff75f793cbce98a641248
parent 2fb4154280dbf383370cbec8e704b1e47ff54600
Author: MTRNord <mtrnord1@gmail.com>
Date: Fri, 17 Jun 2016 23:10:53 +0200
Add commandline options
Diffstat:
9 files changed, 206 insertions(+), 53 deletions(-)
diff --git a/backend/commands.js b/backend/commands.js
@@ -1,7 +1,7 @@
var sshclient = require('sshclient');
-
-export.modules[
- changeName: function (ip, key, newname) {
+var laeh = require('laeh2').leanStacks(true);
+var _x = laeh._x;
+var changeName = function (ip, key, newname, token, cb) {
var opts = {
host: ip,
@@ -19,9 +19,9 @@ export.modules[
sshclient.exec('uci commit system', cb);
sshclient.exec('/etc/init.d/system reload', cb);
})
- });
- },
- changeContact: function (ip, key, name, email) {
+ }));
+ }
+var changeContact = function (ip, key, name, email, token, cb) {
var opts = {
host: ip,
@@ -39,9 +39,9 @@ export.modules[
sshclient.exec('uci set gluon-node-info.@owner[0].contact="' + name + ' <' + email + '>', cb);
sshclient.exec('uci commit gluon-node-info', cb);
})
- });
- },
- activateMOL: function (ip, key) {
+ }));
+ }
+var activateMOL = function (ip, key, cb) {
var opts = {
host: ip,
@@ -60,9 +60,9 @@ export.modules[
sshclient.exec('uci commit network', cb);
sshclient.exec('/etc/init.d/network restart', cb);
})
- });
- },
- deactivateMOL: function (ip, key) {
+ }));
+ }
+var deactivateMOL = function (ip, key, cb) {
var opts = {
host: ip,
@@ -81,9 +81,9 @@ export.modules[
sshclient.exec('uci commit network', cb);
sshclient.exec('/etc/init.d/network restart', cb);
})
- });
- },
- activateMOW: function (ip, key) {
+ }));
+ }
+var activateMOW = function (ip, key, cb) {
var opts = {
host: ip,
@@ -101,9 +101,9 @@ export.modules[
sshclient.exec('uci commit network', cb);
sshclient.exec('/etc/init.d/network restart', cb);
})
- });
- },
- deactivateMOW: function (ip, key) {
+ }));
+ }
+var deactivateMOW = function (ip, key, cb) {
var opts = {
host: ip,
@@ -121,10 +121,10 @@ export.modules[
sshclient.exec('uci commit network', cb);
sshclient.exec('/etc/init.d/network restart', cb);
})
- });
- },
- changeGeo: function (ip, key, lat, long, alt, token) {
- if (ccode === "ffnord" || ccode === "ffhh" || ccode === "ffhl" ||) {
+ }));
+ }
+var changeGeo = function (ip, key, lat, long, alt, token, cb) {
+ if (ccode === "ffnord" || ccode === "ffhh" || ccode === "ffhl") {
//TODÃ’ Add formAPI
} else {
var opts = {
@@ -146,8 +146,15 @@ export.modules[
sshclient.exec('uci set gluon-node-info.@location[0].share_location=1', cb);
sshclient.exec('uci commit gluon-node-info', cb);
})
- });
+ }));
}
}
-]
+
+exports.changeName = changeName;
+exports.changeContact = changeContact;
+exports.activateMOL = activateMOL;
+exports.deactivateMOL = deactivateMOL;
+exports.activateMOW = activateMOW;
+exports.deactivateMOW = deactivateMOW;
+exports.changeGeo = changeGeo;
diff --git a/gluon_web_remote-MOL.js b/gluon_web_remote-MOL.js
@@ -0,0 +1,26 @@
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .parse(process.argv);
+
+console.log();
+
+var args = program.args;
+
+if (args.length < 3) {
+ console.error('Please set all required Arguments');
+ process.exit(1);
+}
+if (args.length === 3) {
+ var ip = args[1]
+ var key = args[2]
+ var switchPosition = args[3]
+ if (switchPosition === "on") {
+ backend.activateMOL(ip, key)
+ }else if (switchPosition === "off") {
+ backend.deactivateMOL(ip, key)
+ }
+}
+
+console.log();
diff --git a/gluon_web_remote-MOW.js b/gluon_web_remote-MOW.js
@@ -0,0 +1,26 @@
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .parse(process.argv);
+
+var args = program.args;
+
+console.log();
+
+if (args.length < 3) {
+ console.error('Please set all required Arguments');
+ process.exit(1);
+}
+if (args.length === 3) {
+ var ip = args[1]
+ var key = args[2]
+ var switchPosition = args[3]
+ if (switchPosition === "on") {
+ backend.activateMOW(ip, key)
+ }else if (switchPosition === "off") {
+ backend.deactivateMOW(ip, key)
+ }
+}
+
+console.log();
diff --git a/gluon_web_remote-changeContact.js b/gluon_web_remote-changeContact.js
@@ -0,0 +1,30 @@
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .parse(process.argv);
+
+var args = program.args;
+
+console.log();
+
+if (args.length < 4) {
+ console.error('Please set all required Arguments');
+ process.exit(1);
+}
+if (args.length === 4) {
+ var ip = args[1]
+ var key = args[2]
+ var name = args[3]
+ var email = args[4]
+ backend.changeContact(ip, key, name, email, "")
+}
+if (args.length === 5) {
+ var ip = args[1]
+ var key = args[2]
+ var token = args[3]
+ var name = args[4]
+ var email = args[5]
+ backend.changeContact(ip, key, name, email, token)
+}
+console.log();
diff --git a/gluon_web_remote-changeGeo.js b/gluon_web_remote-changeGeo.js
@@ -0,0 +1,33 @@
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .parse(process.argv);
+
+var args = program.args;
+
+console.log();
+
+if (args.length < 5) {
+ console.error('Please set all required Arguments');
+ process.exit(1);
+}
+if (args.length === 5) {
+ var ip = args[1]
+ var key = args[2]
+ var lat = args[3]
+ var long = args[4]
+ var alt = args[5]
+ backend.changeGeo(ip, key, lat, long, alt, "")
+}
+if (args.length === 6) {
+ var ip = args[1]
+ var key = args[2]
+ var token = args[3]
+ var lat = args[4]
+ var long = args[5]
+ var alt = args[6]
+ backend.changeGeo(ip, key, lat, long, alt, token)
+}
+
+console.log();
diff --git a/gluon_web_remote-changeName.js b/gluon_web_remote-changeName.js
@@ -0,0 +1,29 @@
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .parse(process.argv);
+
+var args = program.args;
+
+console.log();
+
+if (args.length < 3) {
+ console.error('Please set all required Arguments');
+ process.exit(1);
+}
+if (args.length === 3) {
+ var ip = args[1]
+ var key = args[2]
+ var newname = args[3]
+ backend.changeName(ip, key, newname, "")
+}
+if (args.length === 4) {
+ var ip = args[1]
+ var key = args[2]
+ var token = args[3]
+ var newname = args[4]
+ backend.changeName(ip, key, newname, token)
+}
+
+console.log();
diff --git a/gluon_web_remote.js b/gluon_web_remote.js
@@ -0,0 +1,28 @@
+var express = require('express');
+var app = express();
+app.set('view engine', 'ejs');
+var helmet = require('helmet')
+var program = require('commander');
+var backend = require("./backend/commands.js");
+
+program
+ .command('changeName <ip> <ssh> [token] <newname>', 'Change the Hostname of the router (no Formular support yet!)')
+ .command('changeContact <ip> <ssh> [token] <name> <email>', 'Change the Contact of the router (no Formular support yet!)')
+ .command('MOL <ip> <ssh> <on/off>', 'Activate or deactivate Mesh on Lan')
+ .command('MOW <ip> <ssh> <on/off>', 'Activate or deactivate Mesh on Wan')
+ .command('changeGeo <ip> <ssh> [token] <lat> <long> <altitude>', 'Change the Router Position (no Formular support yet!)')
+ .parse(process.argv);
+
+
+// app.use(helmet())
+//
+// // index page
+// app.get('/', function(req, res) {
+// res.render('pages/index');
+// });
+//
+// app.use('/static', express.static('static'));
+//
+// app.listen(process.env.PORT || 3000, function () {
+// console.log('Example app listening on port 3000!');
+// });
diff --git a/package.json b/package.json
@@ -2,10 +2,10 @@
"name": "gluon-web-remote",
"version": "1.0.0",
"description": "A Web Config mode for running mode of Gluon Router",
- "main": "server.js",
+ "main": "gluon_web_remote.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
- "start": "node server.js"
+ "start": "node gluon_web_remote.js"
},
"repository": {
"type": "git",
@@ -31,6 +31,7 @@
"ejs": "^2.4.2",
"express": "^4.13.4",
"helmet": "^2.1.1",
+ "laeh2": "^0.3.3",
"ssh-keygen": "^0.2.1",
"sshclient": "0.0.4"
},
diff --git a/server.js b/server.js
@@ -1,27 +0,0 @@
-var express = require('express');
-var app = express();
-app.set('view engine', 'ejs');
-var helmet = require('helmet')
-var program = require('commander');
-
-program
- .option('<ip> <ssh-key> [token]', 'SSH key and IP to login (currently no filepaths supported)*')
- .option('changeName <newname>', 'Change the Hostname of the router (no Formular support yet!)')
- .option('changeContact <name> <email>', 'Change the Contact of the router (no Formular support yet!)')
- .option('MOL <on/off>', 'Activate or deactivate Mesh on Lan')
- .option('MOW <on/off>', 'Activate or deactivate Mesh on Wan')
- .option('changeGeo <lat> <long> <altitude>', 'Change the Router Position (no Formular support yet!)')
- .parse(process.argv);
-
-app.use(helmet())
-
-// index page
-app.get('/', function(req, res) {
- res.render('pages/index');
-});
-
-app.use('/static', express.static('static'));
-
-app.listen(process.env.PORT || 3000, function () {
- console.log('Example app listening on port 3000!');
-});