var output;
var genNum = async function () {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(Math.random())
}, 1000)
})
}
output = await gennum();
console.log(output);
volumes:
- /nodejs/nodebackup/config.yml:/nodebackup/config.yml
- /nodejs/nodebackup/id_rsa:/nodebackup/id_rsa
- /nodejs/nodebackup/crontab.tmp:/crontab.tmp
var req = https.request(options, function(res){
res.on('data', function(chunk){
resData += chunk;
})
res.on('end', function(){
if (res.statusCode == "200") {
var output = JSON.parse(resData);
return callback(null, output.results);
} else {
return callback({
"Statuscode": res.statusCode,
"StatusMessage": res.statusMessage
}, null);
}
})
});
req.end(JSON.stringify(filter));
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var fs = require('fs');
var https = require('https');
app.set('views', __dirname + '/views')
app.set('view engine', 'pug')
app.use(express.static(__dirname + '/public'))
server.listen(5000, function () {
console.log('Server listening at port %d', 5000);
});
const opts = {
key: fs.readFileSync('privateKey.key'),
cert: fs.readFileSync('certificate.crt')
}
var httpsServer = https.createServer(opts, app);
httpsServer.listen(5001, function(){
console.log("HTTPS on port " + 5001);
})
app.get('/', function (req, res) {
res.render('index');
})
io.attach(httpsServer);
io.attach(server);
io.on('connection', function(client) {
console.log('Client connected...');
client.on('click', function(data){
console.log(JSON.parse(data));
setTimeout(function() {
client.emit("ok", "data");
}, 3000);
})
});
if (window.location.protocol != "https:"){
var socket = io.connect('https://localhost:5001');
} else {
var socket = io.connect('http://localhost:5000');
}
self.startVerifyBackup(listOfServer).then(function (outArr) {
return callback(null, outArr);
}).catch(function (err) {
return callback(err, null);
});
verifyBackup.prototype.startVerifyBackup = function (folderList) {
var self = this;
return Promise.all(folderList.map(function (folder) {
return self.checkFolder(folder);
}));
};
verifyBackup.prototype.checkFolder = function (folder) {
var self = this;
return new Promise(function (resolve, reject) {
if (self.config.backupserver[self.bserver].passphrase !== undefined && self.config.backupserver[self.bserver].passphrase !== null) {
var passphrase = "PASSPHRASE=" + self.config.backupserver[self.bserver].passphrase;
} else {
var passphrase = "";
}
if (self.config.backupserver[self.bserver].tmpdir !== undefined && self.config.backupserver[self.bserver].tmpdir !== null) {
var btemp = self.config.backupserver[self.bserver].tmpdir;
} else {
var btemp = "";
}
var command = "sudo " + passphrase + " duplicity verify file://" + folder + " " + btemp;
self.runSSH(command, self.sshkeypath, self.eserver, self.bserver, function (err, data) {
if (err) {
return reject(err);
} else {
var output = data.toString().split("\n");
output.splice(0, 2);
var objReturn = {
name: folder,
output: output
};
return resolve(objReturn);
}
});
});
};
var exec = require('ssh-exec')
exec('ls -lh', {
"user": "de1m",
"host": "localhost",
"password": "pass"
}, function (err, stdout, stderr) {
console.log(err, stdout, stderr)
})