Browse Source

fixed js code style

ca333-dev
Petr Balashov 8 years ago
parent
commit
9230caf656
  1. 2
      LICENSE
  2. 90
      gui/index.html
  3. 143
      gui/loading.js
  4. 2
      gui/main.html
  5. 179
      main.js
  6. 27
      private/mainmenu.js
  7. 19
      private/setconf.js
  8. 257
      routes/fetchparams.js
  9. 370
      routes/shepherd.js

2
LICENSE

@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

90
gui/index.html

@ -1,66 +1,30 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css"> <link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="jRoll.min.css"> <link rel="stylesheet" href="jRoll.min.css">
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script> <script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script> if (typeof module === 'object') {
<script type="text/javascript" src="bluebird.min.js"></script> window.module = module;
<script type="text/javascript" src="loading.js"></script> module = undefined;
<script type="text/javascript" src="jRoll.min.js"></script> }
<script>if (window.module) module = window.module;</script> </script>
</head> <script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<body style="overflow:hidden;"> <script type="text/javascript" src="bluebird.min.js"></script>
<div style="text-align: center;"> <script type="text/javascript" src="loading.js"></script>
<div style="/*background-image: url('loading.gif'); background-repeat: no-repeat; background-position: center;*/ height: 240px; width: 400px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto;"> <script type="text/javascript" src="jRoll.min.js"></script>
<span id="loading_status_text">Starting Wallet. Please wait...</span><br> <script>if (window.module) module = window.module;</script>
<span id="loading_sub_status_text"></span><br> </head>
<span id="loading_sub_status_output_text"></span> <body style="overflow:hidden;">
</div> <div style="text-align: center;">
<div id="pulse" style="margin: 80px 50px"></div> <div style="/*background-image: url('loading.gif'); background-repeat: no-repeat; background-position: center;*/ height: 240px; width: 400px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto;">
</div> <span id="loading_status_text">Starting Wallet. Please wait...</span><br>
<script type="text/javascript"> <span id="loading_sub_status_text"></span><br>
$(document).ready( function() { <span id="loading_sub_status_output_text"></span>
$("#pulse").jRoll({ </div>
radius: 100, <div id="pulse" style="margin: 80px 50px"></div>
animation: "pulse" </div>
}); <script type="text/javascript" src="init.js"></script>
const remote = require('electron').remote; </body>
var window = remote.getCurrentWindow();
$('#loading_status_text').text('Starting Iguana daemon...');
var appConf = GetAppConf();
if (appConf && !appConf.manualIguanaStart) {
StartIguana();
}
if (appConf && !appConf.skipBasiliskNetworkCheck) {
var portcheck;
function sartcheck() {
portcheck = setInterval(function(){
Iguana_activehandle().then(function(result){
console.log(result)
if (result !== 'error') {
stopcheck();
$('#loading_status_text').text('Connecting to Basilisk Network...');
EDEX_DEXgetinfoAll();
}
})
//var check = Iguana_activehandle();
//console.log(check[0])
},2000);
}
function stopcheck() {
clearInterval(portcheck);
}
sartcheck();
//setTimeout(function(){ window.close(); }, 15000);
} else {
window.close();
}
});
</script>
</body>
</html> </html>

143
gui/loading.js

@ -1,90 +1,87 @@
function IguanaAJAX(url,ajax_data) { function IguanaAJAX(url, ajax_data) {
return $.ajax({
return $.ajax({ data: JSON.stringify(ajax_data),
data: JSON.stringify(ajax_data), url: url,
url: url, type: 'POST',
type: 'POST', dataType: 'json',
dataType: 'json', //beforeSend: showLoadingImgFn
//beforeSend: showLoadingImgFn })
}) .fail(function(xhr, textStatus, error) {
.fail(function(xhr, textStatus, error) { // handle request failures
// handle request failures });
});
} }
function Iguana_activehandle(callback) { function Iguana_activehandle(callback) {
return new Promise((resolve) =>{ return new Promise((resolve) => {
var ajax_data = { 'agent': 'SuperNET', 'method': 'activehandle' },
var ajax_data = {"agent":"SuperNET","method":"activehandle"}; AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
var AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { //console.log(AjaxOutputData.responseText);
//console.log(AjaxOutputData.responseText); AjaxOutputData = JSON.parse(AjaxOutputData.responseText)
AjaxOutputData = JSON.parse(AjaxOutputData.responseText) //console.log(AjaxOutputData);
//console.log(AjaxOutputData); resolve(AjaxOutputData);
resolve(AjaxOutputData); }).fail(function(xhr, textStatus, error) {
}).fail(function(xhr, textStatus, error) { // handle request failures
// handle request failures console.log(xhr.statusText);
console.log(xhr.statusText); if ( xhr.readyState == 0 ) {
if ( xhr.readyState == 0 ) { }
} console.log(textStatus);
console.log(textStatus); console.log(error);
console.log(error); });
}) });
})
} }
//Iguana_activehandle().then(function(result){ //Iguana_activehandle().then(function(result){
//console.log(result) //console.log(result)
//}) //})
function StartIguana() { function StartIguana() {
var ajax_data = {"herd":"iguana"}; var ajax_data = { 'herd': 'iguana'};
console.log(ajax_data);
$.ajax({ console.log(ajax_data);
//async: false, $.ajax({
type: 'POST', type: 'POST',
data: JSON.stringify(ajax_data), data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/herd', url: 'http://127.0.0.1:17777/shepherd/herd',
dataType: "xml/html/script/json", // expected format for response dataType: 'xml/html/script/json', // expected format for response
contentType: "application/json", // send as JSON contentType: 'application/json', // send as JSON
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
var AjaxOutputData = JSON.parse(data); var AjaxOutputData = JSON.parse(data);
console.log('== ActiveHandle Data OutPut =='); console.log('== ActiveHandle Data OutPut ==');
console.log(AjaxOutputData); console.log(AjaxOutputData);
}, },
error: function(xhr, textStatus, error) { error: function(xhr, textStatus, error) {
console.log(xhr.statusText); console.log(xhr.statusText);
if ( xhr.readyState == 0 ) { if ( xhr.readyState == 0 ) {
} }
console.log(textStatus); console.log(textStatus);
console.log(error); console.log(error);
} }
}); });
} }
function GetAppConf() { // get iguana app conf function GetAppConf() { // get iguana app conf
var ajax_data = {"herd":"iguana"}; var ajax_data = { 'herd': 'iguana' };
var data = false; data = false;
console.log(ajax_data);
$.ajax({ console.log(ajax_data);
async: false, $.ajax({
type: 'GET', async: false,
url: 'http://127.0.0.1:17777/shepherd/appconf' type: 'GET',
}).done(function(_data) { url: 'http://127.0.0.1:17777/shepherd/appconf'
console.log('== App Conf Data OutPut =='); }).done(function(_data) {
console.log(_data); console.log('== App Conf Data OutPut ==');
data = _data; console.log(_data);
}).fail(function(xhr, textStatus, error) { data = _data;
// handle request failures }).fail(function(xhr, textStatus, error) {
console.log(xhr.statusText); // handle request failures
if ( xhr.readyState == 0 ) { console.log(xhr.statusText);
} if ( xhr.readyState == 0 ) {
console.log(textStatus); }
console.log(error); console.log(textStatus);
}); console.log(error);
});
return data; return data;
} }
function EDEX_DEXnotarychains() { function EDEX_DEXnotarychains() {

2
gui/main.html

@ -86,7 +86,7 @@
}); });
} }
function StartKMDNativeIGUI() { function StartKMDNativeIGUI() {
var secToLaunch = 15; var secToLaunch = 60;
$('#kmdNativeBtn').text('Starting Komodo in ' + secToLaunch + 's'); $('#kmdNativeBtn').text('Starting Komodo in ' + secToLaunch + 's');
StartCorsproxy(); StartCorsproxy();
StartKomodod(); StartKomodod();

179
main.js

@ -1,20 +1,23 @@
//main proc for EasyDEX GUI //main proc for EasyDEX GUI
//this app spawns iguana in background in nontech-mode //this app spawns iguana in background in nontech-mode
const electron = require('electron') const electron = require('electron'),
const app = electron.app app = electron.app,
const BrowserWindow = electron.BrowserWindow BrowserWindow = electron.BrowserWindow;
var express = require('express') var express = require('express'),
var bodyParser = require('body-parser') bodyParser = require('body-parser');
const path = require('path') const path = require('path'),
const url = require('url') url = require('url'),
const os = require('os') os = require('os'),
const spawn = require('child_process').spawn; spawn = require('child_process').spawn
const exec = require('child_process').exec; exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs'),
var fs = require('fs-extra') fs = require('fs-extra'),
var mkdirp = require('mkdirp'); mkdirp = require('mkdirp')
var pm2 = require('pm2'); pm2 = require('pm2');
var iguanaAppPort = 17777;
Promise = require('bluebird'); Promise = require('bluebird');
var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8')); var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
@ -22,29 +25,34 @@ var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
app.setName('Iguana'); app.setName('Iguana');
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
process.env.ELECTRON_RUN_AS_NODE = true process.env.ELECTRON_RUN_AS_NODE = true;
console.log(process.env); console.log(process.env);
} }
// preload.js // preload.js
const _setImmediate = setImmediate const _setImmediate = setImmediate,
const _clearImmediate = clearImmediate _clearImmediate = clearImmediate;
process.once('loaded', () => { process.once('loaded', () => {
global.setImmediate = _setImmediate global.setImmediate = _setImmediate
global.clearImmediate = _clearImmediate global.clearImmediate = _clearImmediate
if (os.platform() === 'darwin') { process.setFdLimit(90000); }
if (os.platform() === 'linux') { process.setFdLimit(1000000); } if (os.platform() === 'darwin') {
process.setFdLimit(90000);
}
if (os.platform() === 'linux') {
process.setFdLimit(1000000);
}
}) })
// GUI APP settings and starting gui on address http://120.0.0.1:17777 // GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'); var shepherd = require('./routes/shepherd'),
guiapp = express();
var guiapp = express()
guiapp.use(bodyParser.json()); // support json encoded bodies guiapp.use(bodyParser.json()); // support json encoded bodies
guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies
guiapp.get('/', function (req, res) { guiapp.get('/', function (req, res) {
res.send('Hello World!') res.send('Iguana app server')
}) })
var guipath = path.join(__dirname, '/gui') var guipath = path.join(__dirname, '/gui')
@ -52,8 +60,8 @@ guiapp.use('/gui', express.static(guipath))
guiapp.use('/shepherd', shepherd); guiapp.use('/shepherd', shepherd);
var rungui = guiapp.listen(17777, function () { var rungui = guiapp.listen(iguanaAppPort, function () {
console.log('guiapp listening on port 17777!') console.log('guiapp listening on port ' + iguanaAppPort + '!')
}) })
module.exports = guiapp; module.exports = guiapp;
@ -87,8 +95,12 @@ if (os.platform() === 'win32') {
} }
*/ */
if (os.platform() === 'linux') { var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png') } if (os.platform() === 'linux') {
if (os.platform() === 'win32') { var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico') } var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png')
}
if (os.platform() === 'win32') {
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico')
}
//console.log(iguanaDir); //console.log(iguanaDir);
/* /*
@ -114,12 +126,16 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) {
let mainWindow let mainWindow
let loadingWindow let loadingWindow
function createLoadingWindow() { function createLoadingWindow() {
mainWindow = null; mainWindow = null;
// initialise window // initialise window
loadingWindow = new BrowserWindow({width: 500, height: 300, frame: false, icon: iguanaIcon}) loadingWindow = new BrowserWindow({
width: 500,
height: 300,
frame: false,
icon: iguanaIcon
});
// load our index.html (i.e. easyDEX GUI) // load our index.html (i.e. easyDEX GUI)
loadingWindow.loadURL('http://127.0.0.1:17777/gui/'); loadingWindow.loadURL('http://127.0.0.1:17777/gui/');
@ -131,8 +147,8 @@ function createLoadingWindow() {
loadingWindow.on('closed', function () { loadingWindow.on('closed', function () {
// our app does not have multiwindow - so we dereference the window object instead of // our app does not have multiwindow - so we dereference the window object instead of
// putting them into an window_arr // putting them into an window_arr
loadingWindow = null loadingWindow = null;
createWindow('open') createWindow('open');
}) })
//ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms //ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms
@ -163,13 +179,17 @@ function createWindow (status) {
require(path.join(__dirname, 'private/mainmenu')); require(path.join(__dirname, 'private/mainmenu'));
// initialise window // initialise window
mainWindow = new BrowserWindow({width: 1280, height: 800, icon: iguanaIcon}) mainWindow = new BrowserWindow({
width: 1280,
height: 800,
icon: iguanaIcon
});
// load our index.html (i.e. easyDEX GUI) // load our index.html (i.e. easyDEX GUI)
if (appConfig.edexGuiOnly) { if (appConfig.edexGuiOnly) {
mainWindow.loadURL('http://127.0.0.1:17777/gui/EasyDEX-GUI/'); mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/EasyDEX-GUI/');
} else { } else {
mainWindow.loadURL('http://127.0.0.1:17777/gui/main.html'); mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/main.html');
} }
// DEVTOOLS - only for dev purposes - ca333 // DEVTOOLS - only for dev purposes - ca333
@ -178,72 +198,70 @@ function createWindow (status) {
// if window closed we kill iguana proc // if window closed we kill iguana proc
mainWindow.on('closed', function () { mainWindow.on('closed', function () {
var ConnectToPm2 = function() { var ConnectToPm2 = function() {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) { console.log('Closing Main Window...');
console.log('Closing Main Window...');
pm2.connect(true,function(err) {
pm2.connect(true,function(err) { console.log('connecting to pm2...');
console.log('connecting to pm2...');
if (err) { if (err) {
console.log(err); console.log(err);
} }
}); });
var result = 'Connecting To Pm2: done' var result = 'Connecting To Pm2: done';
console.log(result) console.log(result);
resolve(result); resolve(result);
}) })
} }
var KillPm2 = function() { var KillPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('killing to pm2...');
return new Promise(function(resolve, reject) { pm2.killDaemon(function(err) {
console.log('killing to pm2...'); pm2.disconnect();
console.log('killed to pm2...');
if (err) throw err;
});
pm2.killDaemon(function(err) { var result = 'Killing Pm2: done';
pm2.disconnect();
console.log('killed to pm2...');
if (err) throw err
});
var result = 'Killing Pm2: done' setTimeout(function() {
console.log(result);
setTimeout(function() { resolve(result);
console.log(result) }, 2000)
resolve(result); })
}, 2000)
})
} }
var HideMainWindow = function() { var HideMainWindow = function() {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) { console.log('Exiting App...');
console.log('Exiting App...'); mainWindow = null;
mainWindow = null
var result = 'Hiding Main Window: done';
var result = 'Hiding Main Window: done' console.log(result);
console.log(result) resolve(result);
resolve(result); });
})
} }
var QuitApp = function() { var QuitApp = function() {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) { app.quit();
app.quit(); var result = 'Quiting App: done';
var result = 'Quiting App: done' console.log(result);
console.log(result) resolve(result);
resolve(result); });
})
} }
ConnectToPm2() ConnectToPm2()
.then(function(result) { .then(function(result) {
return KillPm2(); return KillPm2();
}) })
.then(HideMainWindow) .then(HideMainWindow)
.then(QuitApp) .then(QuitApp);
}); });
} }
} }
@ -260,7 +278,6 @@ app.on('window-all-closed', function () {
/*if (process.platform !== 'darwin' || process.platform !== 'linux' || process.platform !== 'win32') { /*if (process.platform !== 'darwin' || process.platform !== 'linux' || process.platform !== 'win32') {
app.quit() app.quit()
}*/ }*/
}) })
app.on('activate', function () { app.on('activate', function () {

27
private/mainmenu.js

@ -1,7 +1,7 @@
const {Menu} = require('electron') const {Menu} = require('electron'),
const electron = require('electron') electron = require('electron'),
const app = electron.app app = electron.app,
const {shell} = require('electron') {shell} = require('electron');
const template = [ const template = [
{ {
@ -43,14 +43,16 @@ const template = [
label: 'Reload', label: 'Reload',
accelerator: 'CmdOrCtrl+R', accelerator: 'CmdOrCtrl+R',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) focusedWindow.reload() if (focusedWindow)
focusedWindow.reload()
} }
}, },
{ {
label: 'Toggle Developer Tools', label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.toggleDevTools() if (focusedWindow)
focusedWindow.webContents.toggleDevTools()
} }
}, },
{ {
@ -123,7 +125,8 @@ const template = [
] ]
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
const name = app.getName() const name = app.getName();
template.unshift({ template.unshift({
label: name, label: name,
submenu: [ submenu: [
@ -158,7 +161,7 @@ if (process.platform === 'darwin') {
role: 'close' role: 'close'
} }
] ]
}) });
// Edit menu. // Edit menu.
template[1].submenu.push( template[1].submenu.push(
{ {
@ -175,7 +178,7 @@ if (process.platform === 'darwin') {
} }
] ]
} }
) );
// Window menu. // Window menu.
template[3].submenu = [ template[3].submenu = [
{ {
@ -200,7 +203,7 @@ if (process.platform === 'darwin') {
role: 'front' role: 'front'
} }
] ]
} };
const menu = Menu.buildFromTemplate(template) const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu);

19
private/setconf.js

@ -21,10 +21,10 @@
* *
*/ */
const child_process = require('child_process'); const child_process = require('child_process'),
const fs = require('fs') fs = require('fs'),
const path = require('path') path = require('path'),
const os = require('os') os = require('os');
var coind_conf = module.exports = { var coind_conf = module.exports = {
exec: child_process.exec, exec: child_process.exec,
@ -89,11 +89,14 @@ function parse_status_block(block) {
*/ */
function parse_status(callback) { function parse_status(callback) {
return function(error, stdout, stderr) { return function(error, stdout, stderr) {
if (error) callback(error); if (error) {
else callback(error, callback(error);
} else {
callback(error,
stdout.trim().split('\n\n').map(parse_status_block)); stdout.trim().split('\n\n').map(parse_status_block));
//stdout.trim().split(/\s\*-usb:/g).map(parse_status_block)); //stdout.trim().split(/\s\*-usb:/g).map(parse_status_block));
//console.log(stdout.trim().split(/\s\*-usb:/g)) //console.log(stdout.trim().split(/\s\*-usb:/g))
}
}; };
} }
@ -128,8 +131,8 @@ function status(confPath, callback) {
if (os.platform() === 'darwin' || os.platform() === 'linux') { if (os.platform() === 'darwin' || os.platform() === 'linux') {
this.exec('cat "' + confPath + '"', parse_status(callback)); this.exec('cat "' + confPath + '"', parse_status(callback));
} }
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
this.exec('type "' + confPath + '"', parse_status(callback)); this.exec('type "' + confPath + '"', parse_status(callback));
} }
}
}

257
routes/fetchparams.js

@ -1,154 +1,158 @@
var app = require('http').createServer(handler) var app = require('http').createServer(handler),
var io = require('socket.io')(app); io = require('socket.io')(app),
var fs = require('fs'); fs = require('fs'),
var request = require('request'); request = require('request'),
var progress = require('request-progress'); progress = require('request-progress');
const path = require('path') const path = require('path'),
const url = require('url') url = require('url'),
const os = require('os') os = require('os'),
const sha256 = require('sha256') sha256 = require('sha256'),
const crypto = require('crypto') crypto = require('crypto');
Promise = require('bluebird'); Promise = require('bluebird');
app.listen(3000); app.listen(3000);
function handler (req, res) { function handler (req, res) {
fs.readFile(__dirname + '/index.html', fs.readFile(__dirname + '/index.html',
function (err, data) { function (err, data) {
if (err) { if (err) {
res.writeHead(500); res.writeHead(500);
return res.end('Error loading index.html'); return res.end('Error loading index.html');
} }
res.writeHead(200); res.writeHead(200);
res.end(data); res.end(data);
}); });
} }
if (os.platform() === 'darwin') { if (os.platform() === 'darwin') {
var PARAMS_DIR = process.env.HOME + '/Library/Application Support/ZcashParams' var PARAMS_DIR = process.env.HOME + '/Library/Application Support/ZcashParams';
} }
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
var PARAMS_DIR = process.env.HOME + '/.zcash-params' var PARAMS_DIR = process.env.HOME + '/.zcash-params';
} }
//PARAMS_DIR="$HOME/Library/Application Support/ZcashParams" //PARAMS_DIR="$HOME/Library/Application Support/ZcashParams"
var SPROUT_FILES_DATA = [{"file":"sprout-proving.key","hash":"8bc20a7f013b2b58970cddd2e7ea028975c88ae7ceb9259a5344a16bc2c0eef7"},{"file":"sprout-verifying.key","hash":"4bd498dae0aacfd8e98dc306338d017d9c08dd0918ead18172bd0aec2fc5df82"}] var SPROUT_FILES_DATA = [
var SPROUT_DL_URL="https://z.cash/downloads/" {
'file': 'sprout-proving.key',
'hash': '8bc20a7f013b2b58970cddd2e7ea028975c88ae7ceb9259a5344a16bc2c0eef7'
}, {
'file': 'sprout-verifying.key',
'hash': '4bd498dae0aacfd8e98dc306338d017d9c08dd0918ead18172bd0aec2fc5df82'
}
];
var SPROUT_DL_URL = 'https://z.cash/downloads/';
//console.log(SPROUT_FILES_DATA); //console.log(SPROUT_FILES_DATA);
SPROUT_FILES_DATA.forEach(function (value, index) { SPROUT_FILES_DATA.forEach(function(value, index) {
//console.log(index); //console.log(index);
//console.log(value); //console.log(value);
//console.log(value.file); //console.log(value.file);
//console.log(value.hash); //console.log(value.hash);
fs.exists(value.file, function(exists) {
if (exists) {
console.log(value.file + ' already exists at location.');
var tmphash
var fd = fs.createReadStream(value.file);
var hash = crypto.createHash('sha256')
hash.setEncoding('hex');
fd.on('end', function() {
hash.end();
console.log('hash is: ')
console.log(hash.read()); // the desired sha1sum
console.log(value.hash)
tmphash = hash.read();
if (hash.read() === value.hash) {
console.log('File SHA256 sum matches.')
} else {
console.log('File SHA256 sum does not match.')
}
});
// read all file and pipe it (write it) to the hash object
fd.pipe(hash);
} else { fs.exists(value.file, function(exists) {
var DLFile = function() { if (exists) {
console.log(value.file + ' already exists at location.');
return new Promise(function(resolve, reject) {
console.log('file not there.');
progress(request(SPROUT_DL_URL+value.file), {})
.on('progress', function (state) {
console.log('progress', state);
})
.on('error', function (err) {
console.log(err);
})
.on('end', function () {
// Do something after request finishes
console.log('download finished.')
var result = 'File ==> ' + value.file + ': DOWNLOADED'
})
.pipe(fs.createWriteStream(value.file));
console.log(result)
resolve(result);
})
}
var tmphas,
fd = fs.createReadStream(value.file),
hash = crypto.createHash('sha256');
hash.setEncoding('hex');
var CheckFileSHA = function() { fd.on('end', function() {
hash.end();
return new Promise(function(resolve, reject) {
var fd = fs.createReadStream(value.file); console.log('hash is: ');
var hash = crypto.createHash('sha256') console.log(hash.read()); // the desired sha1sum
hash.setEncoding('hex'); console.log(value.hash);
fd.on('end', function() { tmphash = hash.read();
hash.end(); if (hash.read() === value.hash) {
console.log('hash is: ') console.log('File SHA256 sum matches.');
console.log(hash.read()); // the desired sha1sum } else {
console.log(value.hash) console.log('File SHA256 sum does not match.');
if (hash.read() === value.hash) { }
console.log('File SHA256 sum matches.') });
} else { // read all file and pipe it (write it) to the hash object
console.log('File SHA256 sum does not match.') fd.pipe(hash);
} } else {
}); var DLFile = function() {
// read all file and pipe it (write it) to the hash object return new Promise(function(resolve, reject) {
fd.pipe(hash); console.log('file not there.');
var result = 'SHA256 SUM Check: DONE' progress(request(SPROUT_DL_URL + value.file), {})
.on('progress', function (state) {
console.log(result) console.log('progress', state);
resolve(result); })
}) .on('error', function (err) {
console.log(err);
})
.on('end', function () {
// Do something after request finishes
console.log('download finished.')
var result = 'File ==> ' + value.file + ': DOWNLOADED';
})
.pipe(fs.createWriteStream(value.file));
console.log(result)
resolve(result);
})
}
var CheckFileSHA = function() {
return new Promise(function(resolve, reject) {
var fd = fs.createReadStream(value.file),
hash = crypto.createHash('sha256');
hash.setEncoding('hex');
fd.on('end', function() {
hash.end();
console.log('hash is: ');
console.log(hash.read()); // the desired sha1sum
console.log(value.hash);
if (hash.read() === value.hash) {
console.log('File SHA256 sum matches.');
} else {
console.log('File SHA256 sum does not match.');
} }
});
// read all file and pipe it (write it) to the hash object
fd.pipe(hash);
var result = 'SHA256 SUM Check: DONE';
DLFile() console.log(result);
.then(function(result) { resolve(result);
return CheckFileSHA(); });
}) }
}
});
});
DLFile()
.then(function(result) {
return CheckFileSHA();
});
}
});
});
function CheckSHASum(file, hashstr) { function CheckSHASum(file, hashstr) {
console.log(hashstr) console.log(hashstr);
var shasum var shasum;
// the file you want to get the hash // the file you want to get the hash
if (shasum === hashstr ) {
return true;
if (shasum === hashstr ) { } else {
return true return false;
} else return false }
} }
/*var CheckFileExists = function() { /*var CheckFileExists = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
@ -199,11 +203,4 @@ ConnectToPm2()
}) })
.then(HideMainWindow) .then(HideMainWindow)
.then(QuitApp) .then(QuitApp)
*/ */

370
routes/shepherd.js

@ -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;
Loading…
Cancel
Save