|
@ -1,68 +1,64 @@ |
|
|
const electron = require('electron') |
|
|
const electron = require('electron'), |
|
|
const app = electron.app |
|
|
app = electron.app, |
|
|
const BrowserWindow = electron.BrowserWindow |
|
|
BrowserWindow = electron.BrowserWindow, |
|
|
const path = require('path') |
|
|
path = require('path'), |
|
|
const url = require('url') |
|
|
url = require('url'), |
|
|
const os = require('os') |
|
|
os = require('os'), |
|
|
const fsnode = require('fs'); |
|
|
fsnode = require('fs'), |
|
|
const fs = require('fs-extra'); |
|
|
fs = require('fs-extra'), |
|
|
const mkdirp = require('mkdirp'); |
|
|
mkdirp = require('mkdirp'), |
|
|
const express = require('express'); |
|
|
express = require('express'), |
|
|
const exec = require('child_process').exec; |
|
|
exec = require('child_process').exec, |
|
|
const md5 = require('md5'); |
|
|
md5 = require('md5'), |
|
|
const pm2 = require('pm2'); |
|
|
pm2 = require('pm2'); |
|
|
Promise = require('bluebird'); |
|
|
|
|
|
const fixPath = require('fix-path'); |
|
|
|
|
|
var ps = require('ps-node'); |
|
|
|
|
|
|
|
|
|
|
|
var setconf = require("../private/setconf.js"); |
|
|
|
|
|
|
|
|
|
|
|
var shepherd = express.Router(); |
|
|
Promise = require('bluebird'); |
|
|
|
|
|
|
|
|
|
|
|
const fixPath = require('fix-path'); |
|
|
|
|
|
var ps = require('ps-node'), |
|
|
|
|
|
setconf = require('../private/setconf.js'), |
|
|
|
|
|
shepherd = express.Router(); |
|
|
|
|
|
|
|
|
// IGUANA FILES AND CONFIG SETTINGS
|
|
|
// IGUANA FILES AND CONFIG SETTINGS
|
|
|
|
|
|
var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'), |
|
|
var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'); |
|
|
CorsProxyBin = path.join(__dirname, '../node_modules/corsproxy/bin/corsproxy'); |
|
|
var CorsProxyBin = path.join(__dirname, '../node_modules/corsproxy/bin/corsproxy'); |
|
|
|
|
|
|
|
|
|
|
|
// SETTING OS DIR TO RUN IGUANA FROM
|
|
|
// SETTING OS DIR TO RUN IGUANA FROM
|
|
|
// SETTING APP ICON FOR LINUX AND WINDOWS
|
|
|
// SETTING APP ICON FOR LINUX AND WINDOWS
|
|
|
if (os.platform() === 'darwin') { |
|
|
if (os.platform() === 'darwin') { |
|
|
fixPath(); |
|
|
fixPath(); |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/osx/iguana'); |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/osx/iguana'), |
|
|
var iguanaDir = process.env.HOME + '/Library/Application Support/iguana'; |
|
|
iguanaDir = process.env.HOME + '/Library/Application Support/iguana', |
|
|
var iguanaConfsDir = iguanaDir + '/confs'; |
|
|
iguanaConfsDir = iguanaDir + '/confs', |
|
|
var komododBin = path.join(__dirname, '../assets/bin/osx/komodod'); |
|
|
komododBin = path.join(__dirname, '../assets/bin/osx/komodod'), |
|
|
var komodocliBin = path.join(__dirname, '../assets/bin/osx/komodo-cli'); |
|
|
komodocliBin = path.join(__dirname, '../assets/bin/osx/komodo-cli'), |
|
|
var komodoDir = process.env.HOME + '/Library/Application Support/Komodo'; |
|
|
komodoDir = process.env.HOME + '/Library/Application Support/Komodo'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (os.platform() === 'linux') { |
|
|
if (os.platform() === 'linux') { |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/linux64/iguana'); |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/linux64/iguana'), |
|
|
var iguanaDir = process.env.HOME + '/.iguana' |
|
|
iguanaDir = process.env.HOME + '/.iguana', |
|
|
var iguanaConfsDir = iguanaDir + '/confs'; |
|
|
iguanaConfsDir = iguanaDir + '/confs', |
|
|
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png') |
|
|
iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png'), |
|
|
var komododBin = path.join(__dirname, '../assets/bin/linux64/komodod'); |
|
|
komododBin = path.join(__dirname, '../assets/bin/linux64/komodod'), |
|
|
var komodocliBin = path.join(__dirname, '../assets/bin/linux64/komodo-cli'); |
|
|
komodocliBin = path.join(__dirname, '../assets/bin/linux64/komodo-cli'), |
|
|
var komodoDir = process.env.HOME + '/.komodo' |
|
|
komodoDir = process.env.HOME + '/.komodo'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (os.platform() === 'win32') { |
|
|
if (os.platform() === 'win32') { |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); iguanaBin = path.normalize(iguanaBin); |
|
|
var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); iguanaBin = path.normalize(iguanaBin), |
|
|
var iguanaDir = process.env.APPDATA + '/iguana'; iguanaDir = path.normalize(iguanaDir) |
|
|
iguanaDir = process.env.APPDATA + '/iguana'; iguanaDir = path.normalize(iguanaDir), |
|
|
var iguanaConfsDir = process.env.APPDATA + '/iguana/confs'; iguanaConfsDir = path.normalize(iguanaConfsDir) |
|
|
iguanaConfsDir = process.env.APPDATA + '/iguana/confs'; iguanaConfsDir = path.normalize(iguanaConfsDir), |
|
|
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico') |
|
|
iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico'), |
|
|
iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc); |
|
|
iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(iguanaDir); |
|
|
console.log(iguanaDir); |
|
|
console.log(iguanaBin); |
|
|
console.log(iguanaBin); |
|
|
|
|
|
|
|
|
// END IGUANA FILES AND CONFIG SETTINGS
|
|
|
// END IGUANA FILES AND CONFIG SETTINGS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shepherd.get('/', function(req, res, next) { |
|
|
shepherd.get('/', function(req, res, next) { |
|
|
res.send('Hello World!') |
|
|
res.send('Iguana app server') |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
shepherd.get('/appconf', function(req, res, next) { |
|
|
shepherd.get('/appconf', function(req, res, next) { |
|
@ -79,8 +75,7 @@ shepherd.post('/herd', function(req, res) { |
|
|
|
|
|
|
|
|
herder(req.body.herd, req.body.options); |
|
|
herder(req.body.herd, req.body.options); |
|
|
|
|
|
|
|
|
res.end('{"msg": "success","result": "result"}'); |
|
|
res.end('{ "msg": "success", "result": "result" }'); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
shepherd.post('/herdlist', function(req, res) { |
|
|
shepherd.post('/herdlist', function(req, res) { |
|
@ -91,19 +86,20 @@ shepherd.post('/herdlist', function(req, res) { |
|
|
//console.log(req.body.options);
|
|
|
//console.log(req.body.options);
|
|
|
|
|
|
|
|
|
pm2.connect(true, function(err) { |
|
|
pm2.connect(true, function(err) { |
|
|
if (err) throw err; //todo: proper error handling
|
|
|
if (err) throw err; // TODO: proper error handling
|
|
|
pm2.describe(req.body.herdname, function(err, list) { |
|
|
pm2.describe(req.body.herdname, function(err, list) { |
|
|
pm2.disconnect(); //disconnect after getting proc info list
|
|
|
pm2.disconnect(); // disconnect after getting proc info list
|
|
|
if (err) throw err //todo: proper error handling
|
|
|
|
|
|
console.log(list[0].pm2_env.status) //print status of IGUANA proc
|
|
|
if (err) throw err // TODO: proper error handling
|
|
|
console.log(list[0].pid) //print pid of IGUANA proc
|
|
|
|
|
|
res.end('{"herdname": '+req.body.herdname+',"status": '+list[0].pm2_env.status+',"pid":'+list[0].pid+'}'); |
|
|
console.log(list[0].pm2_env.status) // print status of IGUANA proc
|
|
|
}); |
|
|
console.log(list[0].pid) // print pid of IGUANA proc
|
|
|
|
|
|
|
|
|
|
|
|
res.end('{ "herdname": ' + req.body.herdname + ', "status": ' + list[0].pm2_env.status + ', "pid": ' + list[0].pid + '}'); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shepherd.post('/slay', function(req, res) { |
|
|
shepherd.post('/slay', function(req, res) { |
|
|
console.log('======= req.body ======='); |
|
|
console.log('======= req.body ======='); |
|
|
//console.log(req);
|
|
|
//console.log(req);
|
|
@ -111,12 +107,9 @@ shepherd.post('/slay', function(req, res) { |
|
|
//console.log(req.body.slay);
|
|
|
//console.log(req.body.slay);
|
|
|
|
|
|
|
|
|
slayer(req.body.slay); |
|
|
slayer(req.body.slay); |
|
|
|
|
|
res.end('{ "msg": "success", "result": "result" }'); |
|
|
res.end('{"msg": "success","result": "result"}'); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shepherd.post('/setconf', function(req, res) { |
|
|
shepherd.post('/setconf', function(req, res) { |
|
|
console.log('======= req.body ======='); |
|
|
console.log('======= req.body ======='); |
|
|
//console.log(req);
|
|
|
//console.log(req);
|
|
@ -124,9 +117,7 @@ shepherd.post('/setconf', function(req, res) { |
|
|
//console.log(req.body.chain);
|
|
|
//console.log(req.body.chain);
|
|
|
|
|
|
|
|
|
setConf(req.body.chain); |
|
|
setConf(req.body.chain); |
|
|
|
|
|
res.end('{ "msg": "success", "result": "result" }'); |
|
|
res.end('{"msg": "success","result": "result"}'); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
shepherd.post('/getconf', function(req, res) { |
|
|
shepherd.post('/getconf', function(req, res) { |
|
@ -138,21 +129,21 @@ shepherd.post('/getconf', function(req, res) { |
|
|
var confpath = getConf(req.body.chain); |
|
|
var confpath = getConf(req.body.chain); |
|
|
console.log('got conf path is:') |
|
|
console.log('got conf path is:') |
|
|
console.log(confpath); |
|
|
console.log(confpath); |
|
|
|
|
|
res.end('{ "msg": "success", "result": "' + confpath + '" }'); |
|
|
res.end('{"msg": "success","result": "' + confpath + '"}'); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function herder(flock, data) { |
|
|
function herder(flock, data) { |
|
|
//console.log(flock);
|
|
|
//console.log(flock);
|
|
|
//console.log(data);
|
|
|
//console.log(data);
|
|
|
|
|
|
|
|
|
if (data == undefined) { data = 'none'; console.log('it is undefined'); } |
|
|
if (data == undefined) { |
|
|
|
|
|
data = 'none'; |
|
|
|
|
|
console.log('it is undefined'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (flock === 'iguana') { |
|
|
if (flock === 'iguana') { |
|
|
console.log('iguana flock selected...'); |
|
|
console.log('iguana flock selected...'); |
|
|
console.log('selected data: '+data); |
|
|
console.log('selected data: ' + data); |
|
|
|
|
|
|
|
|
//Make sure iguana isn't running before starting new process, kill it dammit!
|
|
|
//Make sure iguana isn't running before starting new process, kill it dammit!
|
|
|
// A simple pid lookup
|
|
|
// A simple pid lookup
|
|
@ -181,9 +172,9 @@ function herder(flock, data) { |
|
|
});*/ |
|
|
});*/ |
|
|
|
|
|
|
|
|
// MAKE SURE IGUANA DIR IS THERE FOR USER
|
|
|
// MAKE SURE IGUANA DIR IS THERE FOR USER
|
|
|
mkdirp(iguanaDir, function (err) { |
|
|
mkdirp(iguanaDir, function(err) { |
|
|
if (err) |
|
|
if (err) |
|
|
console.error(err) |
|
|
console.error(err); |
|
|
else |
|
|
else |
|
|
fs.readdir(iguanaDir, (err, files) => { |
|
|
fs.readdir(iguanaDir, (err, files) => { |
|
|
files.forEach(file => { |
|
|
files.forEach(file => { |
|
@ -194,10 +185,11 @@ function herder(flock, data) { |
|
|
|
|
|
|
|
|
// COPY CONFS DIR WITH PEERS FILE TO IGUANA DIR, AND KEEP IT IN SYNC
|
|
|
// COPY CONFS DIR WITH PEERS FILE TO IGUANA DIR, AND KEEP IT IN SYNC
|
|
|
fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) { |
|
|
fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) { |
|
|
if (err) return console.error(err) |
|
|
if (err) |
|
|
console.log('confs files copied successfully at: '+ iguanaConfsDir ) |
|
|
return console.error(err); |
|
|
}) |
|
|
|
|
|
|
|
|
console.log('confs files copied successfully at: ' + iguanaConfsDir); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
pm2.connect(true,function(err) { //start up pm2 god
|
|
|
pm2.connect(true,function(err) { //start up pm2 god
|
|
|
if (err) { |
|
|
if (err) { |
|
@ -206,44 +198,46 @@ function herder(flock, data) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pm2.start({ |
|
|
pm2.start({ |
|
|
script : iguanaBin, // path to binary
|
|
|
script: iguanaBin, // path to binary
|
|
|
name: 'IGUANA', |
|
|
name: 'IGUANA', |
|
|
exec_mode : 'fork', |
|
|
exec_mode : 'fork', |
|
|
cwd: iguanaDir, //set correct iguana directory
|
|
|
cwd: iguanaDir, //set correct iguana directory
|
|
|
}, function(err, apps) { |
|
|
}, function(err, apps) { |
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
if (err) throw err |
|
|
if (err) |
|
|
|
|
|
throw err |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (flock === 'komodod') { |
|
|
if (flock === 'komodod') { |
|
|
console.log('komodod flock selected...'); |
|
|
console.log('komodod flock selected...'); |
|
|
console.log('selected data: '+data); |
|
|
console.log('selected data: ' + data); |
|
|
|
|
|
|
|
|
pm2.connect(true,function(err) { //start up pm2 god
|
|
|
pm2.connect(true, function(err) { // start up pm2 god
|
|
|
if (err) { |
|
|
if (err) { |
|
|
console.error(err); |
|
|
console.error(err); |
|
|
process.exit(2); |
|
|
process.exit(2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pm2.start({ |
|
|
pm2.start({ |
|
|
script: komododBin, // path to binary
|
|
|
script: komododBin, // path to binary
|
|
|
name: data.ac_name, //REVS, USD, EUR etc.
|
|
|
name: data.ac_name, // REVS, USD, EUR etc.
|
|
|
exec_mode : 'fork', |
|
|
exec_mode : 'fork', |
|
|
cwd: komodoDir, |
|
|
cwd: komodoDir, |
|
|
args: data.ac_options, |
|
|
args: data.ac_options, |
|
|
//args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
|
|
|
//args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
|
|
|
}, function(err, apps) { |
|
|
}, function(err, apps) { |
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
if (err) throw err |
|
|
if (err) |
|
|
|
|
|
throw err; |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (flock === 'corsproxy') { |
|
|
if (flock === 'corsproxy') { |
|
|
console.log('corsproxy flock selected...'); |
|
|
console.log('corsproxy flock selected...'); |
|
|
console.log('selected data: '+data); |
|
|
console.log('selected data: ' + data); |
|
|
|
|
|
|
|
|
pm2.connect(true,function(err) { //start up pm2 god
|
|
|
pm2.connect(true,function(err) { //start up pm2 god
|
|
|
if (err) { |
|
|
if (err) { |
|
@ -252,19 +246,18 @@ function herder(flock, data) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pm2.start({ |
|
|
pm2.start({ |
|
|
script: CorsProxyBin, // path to binary
|
|
|
script: CorsProxyBin, // path to binary
|
|
|
name: 'CORSPROXY', //REVS, USD, EUR etc.
|
|
|
name: 'CORSPROXY', // REVS, USD, EUR etc.
|
|
|
exec_mode : 'fork', |
|
|
exec_mode : 'fork', |
|
|
cwd: iguanaDir, |
|
|
cwd: iguanaDir, |
|
|
}, function(err, apps) { |
|
|
}, function(err, apps) { |
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
if (err) throw err |
|
|
if (err) throw err |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function slayer(flock) { |
|
|
function slayer(flock) { |
|
|
console.log(flock); |
|
|
console.log(flock); |
|
|
|
|
|
|
|
@ -279,173 +272,179 @@ function setConf(flock) { |
|
|
console.log(flock); |
|
|
console.log(flock); |
|
|
|
|
|
|
|
|
if (os.platform() === 'darwin') { |
|
|
if (os.platform() === 'darwin') { |
|
|
var komodoDir = process.env.HOME + '/Library/Application Support/Komodo'; |
|
|
var komodoDir = process.env.HOME + '/Library/Application Support/Komodo', |
|
|
var ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; |
|
|
ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (os.platform() === 'linux') { |
|
|
if (os.platform() === 'linux') { |
|
|
var komodoDir = process.env.HOME + '/.komodo' |
|
|
var komodoDir = process.env.HOME + '/.komodo', |
|
|
var ZcashDir = process.env.HOME + '/.zcash' |
|
|
ZcashDir = process.env.HOME + '/.zcash'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (flock) { |
|
|
switch (flock) { |
|
|
case 'komodod': var DaemonConfPath = komodoDir + '/komodo.conf'; |
|
|
case 'komodod': |
|
|
break; |
|
|
var DaemonConfPath = komodoDir + '/komodo.conf'; |
|
|
case 'zcashd': var DaemonConfPath = ZcashDir + '/zcash.conf'; |
|
|
break; |
|
|
break; |
|
|
case 'zcashd': |
|
|
default: var DaemonConfPath = komodoDir + '/' + flock + '/' + flock + '.conf'; |
|
|
var DaemonConfPath = ZcashDir + '/zcash.conf'; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
var DaemonConfPath = komodoDir + '/' + flock + '/' + flock + '.conf'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(DaemonConfPath); |
|
|
console.log(DaemonConfPath); |
|
|
|
|
|
|
|
|
var CheckFileExists = function() { |
|
|
var CheckFileExists = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'Check Conf file exists is done' |
|
|
var result = 'Check Conf file exists is done' |
|
|
|
|
|
|
|
|
fs.ensureFile(DaemonConfPath, function (err) { |
|
|
fs.ensureFile(DaemonConfPath, function(err) { |
|
|
console.log(err) // => null
|
|
|
console.log(err); // => null
|
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log(result) |
|
|
console.log(result); |
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}, 2000) |
|
|
}, 2000); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var FixFilePermissions = function() { |
|
|
var FixFilePermissions = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'Conf file permissions updated to Read/Write' |
|
|
var result = 'Conf file permissions updated to Read/Write'; |
|
|
|
|
|
|
|
|
fsnode.chmodSync(DaemonConfPath, '0666'); |
|
|
fsnode.chmodSync(DaemonConfPath, '0666'); |
|
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log(result) |
|
|
console.log(result); |
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}, 1000) |
|
|
}, 1000); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var RemoveLines = function() { |
|
|
var RemoveLines = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'RemoveLines is done' |
|
|
var result = 'RemoveLines is done' |
|
|
|
|
|
|
|
|
fs.readFile(DaemonConfPath, 'utf8', function (err,data) { |
|
|
fs.readFile(DaemonConfPath, 'utf8', function(err, data) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
return console.log(err); |
|
|
return console.log(err); |
|
|
} |
|
|
} |
|
|
var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, "\n"); |
|
|
|
|
|
fs.writeFile(DaemonConfPath, rmlines, 'utf8', function (err) { |
|
|
var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n'); |
|
|
if (err) return console.log(err); |
|
|
|
|
|
|
|
|
fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) { |
|
|
|
|
|
if (err) |
|
|
|
|
|
return console.log(err); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
fsnode.chmodSync(DaemonConfPath, '0666'); |
|
|
fsnode.chmodSync(DaemonConfPath, '0666'); |
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log(result) |
|
|
console.log(result); |
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}, 2000) |
|
|
}, 2000); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var CheckConf = function() { |
|
|
var CheckConf = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'CheckConf is done' |
|
|
var result = 'CheckConf is done'; |
|
|
|
|
|
|
|
|
setconf.status(DaemonConfPath, function(err, status) { |
|
|
setconf.status(DaemonConfPath, function(err, status) { |
|
|
//console.log(status[0]);
|
|
|
//console.log(status[0]);
|
|
|
//console.log(status[0].rpcuser);
|
|
|
//console.log(status[0].rpcuser);
|
|
|
var rpcuser = function() { |
|
|
var rpcuser = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'checking rpcuser...' |
|
|
var result = 'checking rpcuser...'; |
|
|
|
|
|
|
|
|
if(status[0].hasOwnProperty('rpcuser')){ |
|
|
if (status[0].hasOwnProperty('rpcuser')) { |
|
|
console.log('rpcuser: OK'); |
|
|
console.log('rpcuser: OK'); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
console.log('rpcuser: NOT FOUND'); |
|
|
console.log('rpcuser: NOT FOUND') |
|
|
var randomstring = md5(Math.random() * Math.random() * 999); |
|
|
var randomstring = md5(Math.random()*Math.random()*999); |
|
|
|
|
|
|
|
|
fs.appendFile(DaemonConfPath, '\nrpcuser=user' + randomstring.substring(0, 16), (err) => { |
|
|
fs.appendFile(DaemonConfPath, '\nrpcuser=user'+randomstring.substring(0,16), (err) => { |
|
|
if (err) |
|
|
if (err) throw err; |
|
|
throw err; |
|
|
console.log('rpcuser: ADDED') |
|
|
console.log('rpcuser: ADDED'); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//console.log(result)
|
|
|
//console.log(result)
|
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var rpcpass = function() { |
|
|
var rpcpass = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'checking rpcpass...' |
|
|
var result = 'checking rpcpass...'; |
|
|
|
|
|
|
|
|
if(status[0].hasOwnProperty('rpcpass')){ |
|
|
if (status[0].hasOwnProperty('rpcpass')) { |
|
|
console.log('rpcpass: OK'); |
|
|
console.log('rpcpass: OK'); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
console.log('rpcpass: NOT FOUND'); |
|
|
console.log('rpcpass: NOT FOUND') |
|
|
var randomstring = md5(Math.random() * Math.random() * 999); |
|
|
var randomstring = md5(Math.random()*Math.random()*999); |
|
|
|
|
|
|
|
|
fs.appendFile(DaemonConfPath, '\nrpcpass=' + randomstring + |
|
|
fs.appendFile(DaemonConfPath, '\nrpcpass='+randomstring+'\nrpcpassword='+randomstring, (err) => { |
|
|
'\nrpcpassword=' + randomstring, (err) => { |
|
|
if (err) throw err; |
|
|
if (err) |
|
|
console.log('rpcpass: ADDED') |
|
|
throw err; |
|
|
|
|
|
console.log('rpcpass: ADDED'); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//console.log(result)
|
|
|
//console.log(result)
|
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var server = function() { |
|
|
var server = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'checking server...' |
|
|
var result = 'checking server...'; |
|
|
|
|
|
|
|
|
if(status[0].hasOwnProperty('server')){ |
|
|
if (status[0].hasOwnProperty('server')) { |
|
|
console.log('server: OK'); |
|
|
console.log('server: OK'); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
console.log('server: NOT FOUND'); |
|
|
console.log('server: NOT FOUND') |
|
|
|
|
|
fs.appendFile(DaemonConfPath, '\nserver=1', (err) => { |
|
|
fs.appendFile(DaemonConfPath, '\nserver=1', (err) => { |
|
|
if (err) throw err; |
|
|
if (err) |
|
|
console.log('server: ADDED') |
|
|
throw err; |
|
|
|
|
|
console.log('server: ADDED'); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//console.log(result)
|
|
|
//console.log(result)
|
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var addnode = function() { |
|
|
var addnode = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'checking addnode...' |
|
|
var result = 'checking addnode...'; |
|
|
|
|
|
|
|
|
if(status[0].hasOwnProperty('addnode')){ |
|
|
if(status[0].hasOwnProperty('addnode')) { |
|
|
console.log('addnode: OK'); |
|
|
console.log('addnode: OK'); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
|
|
|
console.log('addnode: NOT FOUND') |
|
|
console.log('addnode: NOT FOUND') |
|
|
fs.appendFile(DaemonConfPath, '\naddnode=78.47.196.146\naddnode=5.9.102.210\naddnode=178.63.69.164\naddnode=88.198.65.74\naddnode=5.9.122.241\naddnode=144.76.94.3', (err) => { |
|
|
fs.appendFile(DaemonConfPath, |
|
|
if (err) throw err; |
|
|
'\naddnode=78.47.196.146' + |
|
|
console.log('addnode: ADDED') |
|
|
'\naddnode=5.9.102.210' + |
|
|
|
|
|
'\naddnode=178.63.69.164' + |
|
|
|
|
|
'\naddnode=88.198.65.74' + |
|
|
|
|
|
'\naddnode=5.9.122.241' + |
|
|
|
|
|
'\naddnode=144.76.94.3', |
|
|
|
|
|
(err) => { |
|
|
|
|
|
if (err) |
|
|
|
|
|
throw err; |
|
|
|
|
|
console.log('addnode: ADDED'); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//console.log(result)
|
|
|
//console.log(result)
|
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rpcuser() |
|
|
rpcuser() |
|
|
.then(function(result) { |
|
|
.then(function(result) { |
|
@ -454,25 +453,25 @@ function setConf(flock) { |
|
|
.then(server) |
|
|
.then(server) |
|
|
.then(addnode) |
|
|
.then(addnode) |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log(result) |
|
|
console.log(result); |
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}, 2000) |
|
|
}, 2000); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var MakeConfReadOnly = function() { |
|
|
var MakeConfReadOnly = function() { |
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
var result = 'Conf file permissions updated to Read Only' |
|
|
var result = 'Conf file permissions updated to Read Only'; |
|
|
|
|
|
|
|
|
fsnode.chmodSync(DaemonConfPath, '0400'); |
|
|
fsnode.chmodSync(DaemonConfPath, '0400'); |
|
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log(result) |
|
|
console.log(result); |
|
|
resolve(result); |
|
|
resolve(result); |
|
|
}, 1000) |
|
|
}, 1000); |
|
|
}) |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
CheckFileExists() |
|
|
CheckFileExists() |
|
@ -481,7 +480,7 @@ function setConf(flock) { |
|
|
}) |
|
|
}) |
|
|
.then(RemoveLines) |
|
|
.then(RemoveLines) |
|
|
.then(CheckConf) |
|
|
.then(CheckConf) |
|
|
.then(MakeConfReadOnly) |
|
|
.then(MakeConfReadOnly); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -489,25 +488,28 @@ function getConf(flock) { |
|
|
console.log(flock); |
|
|
console.log(flock); |
|
|
|
|
|
|
|
|
if (os.platform() === 'darwin') { |
|
|
if (os.platform() === 'darwin') { |
|
|
var komodoDir = process.env.HOME + '/Library/Application Support/Komodo'; |
|
|
var komodoDir = process.env.HOME + '/Library/Application Support/Komodo', |
|
|
var ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; |
|
|
ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (os.platform() === 'linux') { |
|
|
if (os.platform() === 'linux') { |
|
|
var komodoDir = process.env.HOME + '/.komodo' |
|
|
var komodoDir = process.env.HOME + '/.komodo', |
|
|
var ZcashDir = process.env.HOME + '/.zcash' |
|
|
ZcashDir = process.env.HOME + '/.zcash'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (flock) { |
|
|
switch (flock) { |
|
|
case 'komodod': var DaemonConfPath = komodoDir; |
|
|
case 'komodod': |
|
|
|
|
|
var DaemonConfPath = komodoDir; |
|
|
break; |
|
|
break; |
|
|
case 'zcashd': var DaemonConfPath = ZcashDir; |
|
|
case 'zcashd': |
|
|
|
|
|
var DaemonConfPath = ZcashDir; |
|
|
break; |
|
|
break; |
|
|
default: var DaemonConfPath = komodoDir + '/' + flock; |
|
|
default: |
|
|
|
|
|
var DaemonConfPath = komodoDir + '/' + flock; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(DaemonConfPath); |
|
|
console.log(DaemonConfPath); |
|
|
return DaemonConfPath |
|
|
return DaemonConfPath; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = shepherd; |
|
|
module.exports = shepherd; |