commit 8985377c4bd344c76721dedeb27892e5a36d0378
parent ca1dc7eb5e03cb401576aa73b72599c6adbd1033
Author: MTRNord <mtrnord1@gmail.com>
Date: Fri, 17 Jun 2016 15:39:49 +0200
Add first Commands to backend
Diffstat:
4 files changed, 126 insertions(+), 7 deletions(-)
diff --git a/backend/commands.js b/backend/commands.js
@@ -1,13 +1,13 @@
var sshclient = require('sshclient');
export.modules[
- changeName: function (ip, newname) {
+ changeName: function (ip, key, newname) {
var opts = {
- host: 'myhost',
+ host: ip,
port: 22,
- username: 'ubuntu',
- privateKey: fs.readFileSync('./somekey.pem'),
+ username: 'root',
+ privateKey: key,
debug: true, // optional
console: console // optional, allows logger overriding
@@ -15,9 +15,111 @@ export.modules[
sshclient.session(opts, _x(cb, true, function(err, ses) {
_x(null, false, function(cb) {
- ses.exec("uci set system.@system[0].hostname='" + newname + "'", cb);
- ses.exec("uci commit system", cb);
- ses.exec("/etc/init.d/system reload", cb);
+ sshclient.exec('uci set system.@system[0].hostname="'+ newname + '"', cb);
+ sshclient.exec('uci commit system', cb);
+ sshclient.exec('/etc/init.d/system reload', cb);
+ })
+ });
+ },
+ changeContact: function (ip, key, name, email) {
+ var opts = {
+
+ host: ip,
+ port: 22,
+ username: 'root',
+ privateKey: key,
+
+ debug: true, // optional
+ console: console // optional, allows logger overriding
+ };
+
+ sshclient.session(opts, _x(cb, true, function(err, ses) {
+ _x(null, false, function(cb) {
+ sshclient.exec('uci get gluon-node-info.@owner[0] || uci add gluon-node-info owner', cb);
+ 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 opts = {
+
+ host: ip,
+ port: 22,
+ username: 'root',
+ privateKey: key,
+
+ debug: true, // optional
+ console: console // optional, allows logger overriding
+ };
+
+ sshclient.session(opts, _x(cb, true, function(err, ses) {
+ _x(null, false, function(cb) {
+ sshclient.exec('for iface in $(cat /lib/gluon/core/sysconfig/lan_ifname); do uci del_list network.client.ifname=$iface; done', cb);
+ sshclient.exec('uci set network.mesh_lan.auto=1', cb);
+ sshclient.exec('uci commit network', cb);
+ sshclient.exec('/etc/init.d/network restart', cb);
+ })
+ });
+ }.
+ deactivateMOL: function (ip, key) {
+ var opts = {
+
+ host: ip,
+ port: 22,
+ username: 'root',
+ privateKey: key,
+
+ debug: true, // optional
+ console: console // optional, allows logger overriding
+ };
+
+ sshclient.session(opts, _x(cb, true, function(err, ses) {
+ _x(null, false, function(cb) {
+ sshclient.exec('for iface in $(cat /lib/gluon/core/sysconfig/lan_ifname); do uci add_list network.client.ifname=$iface; done', cb);
+ sshclient.exec('uci set network.mesh_lan.auto=0', cb);
+ sshclient.exec('uci commit network', cb);
+ sshclient.exec('/etc/init.d/network restart', cb);
+ })
+ });
+ }.
+ activateMOW: function (ip, key) {
+ var opts = {
+
+ host: ip,
+ port: 22,
+ username: 'root',
+ privateKey: key,
+
+ debug: true, // optional
+ console: console // optional, allows logger overriding
+ };
+
+ sshclient.session(opts, _x(cb, true, function(err, ses) {
+ _x(null, false, function(cb) {
+ sshclient.exec('uci set network.mesh_wan.auto=1', cb);
+ sshclient.exec('uci commit network', cb);
+ sshclient.exec('/etc/init.d/network restart', cb);
+ })
+ });
+ }.
+ deactivateMOW: function (ip, key) {
+ var opts = {
+
+ host: ip,
+ port: 22,
+ username: 'root',
+ privateKey: key,
+
+ debug: true, // optional
+ console: console // optional, allows logger overriding
+ };
+
+ sshclient.session(opts, _x(cb, true, function(err, ses) {
+ _x(null, false, function(cb) {
+ sshclient.exec('uci set network.mesh_wan.auto=0', cb);
+ sshclient.exec('uci commit network', cb);
+ sshclient.exec('/etc/init.d/network restart', cb);
})
});
}
diff --git a/configs/config.json b/configs/config.json
@@ -0,0 +1,4 @@
+{
+ "communityName": "Freifunk Nord",
+ "nodesJson": "https://mesh.nord.freifunk.net/data/nodes.json"
+}
diff --git a/configs/schemas/config.json b/configs/schemas/config.json
@@ -0,0 +1,12 @@
+{
+ "$async": true,
+ "properties": {
+ "communityName": {
+ "type": "string"
+ },
+ "nodesJson": {
+ "type": "string",
+ "format": "uri"
+ }
+ }
+}
diff --git a/package.json b/package.json
@@ -26,6 +26,7 @@
},
"homepage": "https://github.com/MTRNord/gluon_web_remote_node#readme",
"dependencies": {
+ "ajv": "^4.1.3",
"ejs": "^2.4.2",
"express": "^4.13.4",
"helmet": "^2.1.1",