Browse Source

fixed js code style

ca333-dev
Petr Balashov 8 years ago
parent
commit
9230caf656
  1. 50
      gui/index.html
  2. 25
      gui/loading.js
  3. 2
      gui/main.html
  4. 119
      main.js
  5. 27
      private/mainmenu.js
  6. 17
      private/setconf.js
  7. 109
      routes/fetchparams.js
  8. 286
      routes/shepherd.js

50
gui/index.html

@ -4,7 +4,12 @@
<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>
if (typeof module === 'object') {
window.module = module;
module = undefined;
}
</script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script> <script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="bluebird.min.js"></script> <script type="text/javascript" src="bluebird.min.js"></script>
<script type="text/javascript" src="loading.js"></script> <script type="text/javascript" src="loading.js"></script>
@ -20,47 +25,6 @@
</div> </div>
<div id="pulse" style="margin: 80px 50px"></div> <div id="pulse" style="margin: 80px 50px"></div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript" src="init.js"></script>
$(document).ready( function() {
$("#pulse").jRoll({
radius: 100,
animation: "pulse"
});
const remote = require('electron').remote;
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> </body>
</html> </html>

25
gui/loading.js

@ -1,5 +1,4 @@
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,
@ -15,9 +14,8 @@ function IguanaAJAX(url,ajax_data) {
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);
@ -29,25 +27,23 @@ function Iguana_activehandle(callback) {
} }
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); console.log(ajax_data);
$.ajax({ $.ajax({
//async: false,
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 ==');
@ -64,8 +60,9 @@ function StartIguana() {
} }
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); console.log(ajax_data);
$.ajax({ $.ajax({
async: false, async: false,

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();

119
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,64 +198,62 @@ 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) { return new Promise(function(resolve, reject) {
console.log('killing to pm2...'); console.log('killing to pm2...');
pm2.killDaemon(function(err) { pm2.killDaemon(function(err) {
pm2.disconnect(); pm2.disconnect();
console.log('killed to pm2...'); console.log('killed to pm2...');
if (err) throw err if (err) throw err;
}); });
var result = 'Killing Pm2: done' var result = 'Killing Pm2: done';
setTimeout(function() { setTimeout(function() {
console.log(result) console.log(result);
resolve(result); resolve(result);
}, 2000) }, 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()
@ -243,7 +261,7 @@ function createWindow (status) {
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);

17
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));
} }
} }

109
routes/fetchparams.js

@ -1,13 +1,14 @@
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);
@ -26,17 +27,24 @@ function handler (req, res) {
} }
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);
@ -49,32 +57,32 @@ SPROUT_FILES_DATA.forEach(function (value, index) {
fs.exists(value.file, function(exists) { fs.exists(value.file, function(exists) {
if (exists) { if (exists) {
console.log(value.file + ' already exists at location.'); console.log(value.file + ' already exists at location.');
var tmphash
var fd = fs.createReadStream(value.file); var tmphas,
var hash = crypto.createHash('sha256') fd = fs.createReadStream(value.file),
hash = crypto.createHash('sha256');
hash.setEncoding('hex'); hash.setEncoding('hex');
fd.on('end', function() { fd.on('end', function() {
hash.end(); hash.end();
console.log('hash is: ')
console.log('hash is: ');
console.log(hash.read()); // the desired sha1sum console.log(hash.read()); // the desired sha1sum
console.log(value.hash) console.log(value.hash);
tmphash = hash.read(); tmphash = hash.read();
if (hash.read() === value.hash) { if (hash.read() === value.hash) {
console.log('File SHA256 sum matches.') console.log('File SHA256 sum matches.');
} else { } else {
console.log('File SHA256 sum does not match.') console.log('File SHA256 sum does not match.');
} }
}); });
// read all file and pipe it (write it) to the hash object // read all file and pipe it (write it) to the hash object
fd.pipe(hash); fd.pipe(hash);
} else { } else {
var DLFile = function() { var DLFile = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('file not there.'); console.log('file not there.');
progress(request(SPROUT_DL_URL + value.file), {}) progress(request(SPROUT_DL_URL + value.file), {})
@ -87,7 +95,7 @@ SPROUT_FILES_DATA.forEach(function (value, index) {
.on('end', function () { .on('end', function () {
// Do something after request finishes // Do something after request finishes
console.log('download finished.') console.log('download finished.')
var result = 'File ==> ' + value.file + ': DOWNLOADED' var result = 'File ==> ' + value.file + ': DOWNLOADED';
}) })
.pipe(fs.createWriteStream(value.file)); .pipe(fs.createWriteStream(value.file));
@ -95,59 +103,55 @@ SPROUT_FILES_DATA.forEach(function (value, index) {
resolve(result); resolve(result);
}) })
} }
var CheckFileSHA = function() { var CheckFileSHA = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var fd = fs.createReadStream(value.file); var fd = fs.createReadStream(value.file),
var hash = crypto.createHash('sha256') hash = crypto.createHash('sha256');
hash.setEncoding('hex'); hash.setEncoding('hex');
fd.on('end', function() { fd.on('end', function() {
hash.end(); hash.end();
console.log('hash is: ')
console.log('hash is: ');
console.log(hash.read()); // the desired sha1sum console.log(hash.read()); // the desired sha1sum
console.log(value.hash) console.log(value.hash);
if (hash.read() === value.hash) { if (hash.read() === value.hash) {
console.log('File SHA256 sum matches.') console.log('File SHA256 sum matches.');
} else { } else {
console.log('File SHA256 sum does not match.') console.log('File SHA256 sum does not match.');
} }
}); });
// read all file and pipe it (write it) to the hash object // read all file and pipe it (write it) to the hash object
fd.pipe(hash); fd.pipe(hash);
var result = 'SHA256 SUM Check: DONE' var result = 'SHA256 SUM Check: DONE';
console.log(result) console.log(result);
resolve(result); resolve(result);
}) });
} }
DLFile() DLFile()
.then(function(result) { .then(function(result) {
return CheckFileSHA(); 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 ) { if (shasum === hashstr ) {
return true return true;
} else return false } else {
return false;
}
} }
/*var CheckFileExists = function() { /*var CheckFileExists = function() {
@ -200,10 +204,3 @@ ConnectToPm2()
.then(HideMainWindow) .then(HideMainWindow)
.then(QuitApp) .then(QuitApp)
*/ */

286
routes/shepherd.js

@ -1,55 +1,55 @@
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);
} }
@ -57,12 +57,8 @@ 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) {
@ -80,7 +76,6 @@ 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
if (err) throw err // TODO: proper error handling
console.log(list[0].pm2_env.status) // print status of IGUANA proc console.log(list[0].pm2_env.status) // print status of IGUANA proc
console.log(list[0].pid) // print pid 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 + '}'); 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,17 +129,17 @@ 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...');
@ -183,7 +174,7 @@ 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) {
@ -212,7 +204,8 @@ function herder(flock, data) {
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
}); });
}); });
} }
@ -236,7 +229,8 @@ function herder(flock, data) {
//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;
}); });
}); });
} }
@ -264,7 +258,6 @@ function herder(flock, data) {
} }
} }
function slayer(flock) { function slayer(flock) {
console.log(flock); console.log(flock);
@ -279,57 +272,57 @@ 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':
var DaemonConfPath = komodoDir + '/komodo.conf';
break; break;
case 'zcashd': var DaemonConfPath = ZcashDir + '/zcash.conf'; case 'zcashd':
var DaemonConfPath = ZcashDir + '/zcash.conf';
break; break;
default: var DaemonConfPath = komodoDir + '/' + flock + '/' + flock + '.conf'; 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'
@ -337,114 +330,120 @@ function setConf(flock) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, "\n");
var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n');
fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) { fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) {
if (err) return console.log(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) throw err; if (err)
console.log('rpcuser: ADDED') throw err;
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+'\nrpcpassword='+randomstring, (err) => { fs.appendFile(DaemonConfPath, '\nrpcpass=' + randomstring +
if (err) throw err; '\nrpcpassword=' + randomstring, (err) => {
console.log('rpcpass: ADDED') if (err)
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()
@ -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