mainWindow = new BrowserWindow({
resizable: true,
width: 1200,
height: 55,
icon: __dirname + '/img/logo.png',
autoHideMenuBar: true,
frame: false,
show: false
});
backupRun.prototype.checkSSHConnection = async function (serverName) {
var self = this;
var exec = self.bConfig.clientserver[self.eServer]
var client = self.bConfig.clientserver[serverName]
return new Promise((resolve, reject) => {
self.runUnderSSH("hostname", self.sshkey, exec, client)
.then((sshOutput) => {
return resolve(sshOutput);
}, (sshOutputErr) => {
return reject(sshOutputErr)
})
})
};
backupJob.checkSSHConnection(program.exec) //check ssh to exec server
.then((response) => {
logger.debug("SSH test connection to exec " + program.exec + " successfull");
backupJob.checkSSHConnection(program.server) //check ssh connection to backup server
.then((response) => {
logger.debug("SSH test connection to backup server " + program.exec + " successfull");
backupJob.createBackupPrePostCommands('prerun') //create backup server prerun commands
.then((backupPreRun) => {
logger.debug("Create backup prerun commands");
}, (err) => {
logger.error("Error: config array was not generated " + err);
})
})
})
}, (error) => {
logger.error("SSH test connection to backup server " + program.exec + " failed: " + error);
})
}, (error) => {
logger.error("SSH test connection to exec " + program.exec + " failed: " + error);
});
var path = require('path');
...
var scriptdir = path.dirname(process.argv[1]); //get dir of scripts
var getFilename = function (partFilename) {
return new Promise((resolve, reject) => {
var files = fs.readdirSync(uploadPath);
files.forEach(file => {
var comparedPart = file.split('.')[0];
if (comparedPart == partFilename) {
resolve(file);
}
});
reject(new Error('404'));
});
}
var getFilename = function (partFilename) {
return new Promise((resolve, reject) => {
var files = fs.readdir(uploadPath, (err, files) => {
if (err) {
reject(new Error('404'));
} else {
files.forEach(file => {
var comparedPart = file.split('.')[0];
if (comparedPart == partFilename) {
resolve(file);
}
});
}
})
});
}
require('./file.json')
fs.readFile('./file.json', function read(err, data) {
//...
});
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
var output;
var genNum = async function () {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(Math.random())
}, 1000)
})
}
output = await gennum();
console.log(output);
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);
}
});
});
};