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
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
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">
<html>
<head>
<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="jRoll.min.css">
<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="bluebird.min.js"></script>
<script type="text/javascript" src="loading.js"></script>
<script type="text/javascript" src="jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body style="overflow:hidden;">
<div style="text-align: center;">
<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;">
<span id="loading_status_text">Starting Wallet. Please wait...</span><br>
<span id="loading_sub_status_text"></span><br>
<span id="loading_sub_status_output_text"></span>
</div>
<div id="pulse" style="margin: 80px 50px"></div>
</div>
<script type="text/javascript">
$(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>
<head>
<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="jRoll.min.css">
<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="bluebird.min.js"></script>
<script type="text/javascript" src="loading.js"></script>
<script type="text/javascript" src="jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body style="overflow:hidden;">
<div style="text-align: center;">
<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;">
<span id="loading_status_text">Starting Wallet. Please wait...</span><br>
<span id="loading_sub_status_text"></span><br>
<span id="loading_sub_status_output_text"></span>
</div>
<div id="pulse" style="margin: 80px 50px"></div>
</div>
<script type="text/javascript" src="init.js"></script>
</body>
</html>

143
gui/loading.js

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

2
gui/main.html

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

179
main.js

@ -1,20 +1,23 @@
//main proc for EasyDEX GUI
//this app spawns iguana in background in nontech-mode
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
var express = require('express')
var bodyParser = require('body-parser')
const path = require('path')
const url = require('url')
const os = require('os')
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
var fs = require('fs');
var fs = require('fs-extra')
var mkdirp = require('mkdirp');
var pm2 = require('pm2');
const electron = require('electron'),
app = electron.app,
BrowserWindow = electron.BrowserWindow;
var express = require('express'),
bodyParser = require('body-parser');
const path = require('path'),
url = require('url'),
os = require('os'),
spawn = require('child_process').spawn
exec = require('child_process').exec;
var fs = require('fs'),
fs = require('fs-extra'),
mkdirp = require('mkdirp')
pm2 = require('pm2');
var iguanaAppPort = 17777;
Promise = require('bluebird');
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');
if (os.platform() === 'linux') {
process.env.ELECTRON_RUN_AS_NODE = true
process.env.ELECTRON_RUN_AS_NODE = true;
console.log(process.env);
}
// preload.js
const _setImmediate = setImmediate
const _clearImmediate = clearImmediate
const _setImmediate = setImmediate,
_clearImmediate = clearImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate
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
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.urlencoded({ extended: false })); // support encoded bodies
guiapp.get('/', function (req, res) {
res.send('Hello World!')
res.send('Iguana app server')
})
var guipath = path.join(__dirname, '/gui')
@ -52,8 +60,8 @@ guiapp.use('/gui', express.static(guipath))
guiapp.use('/shepherd', shepherd);
var rungui = guiapp.listen(17777, function () {
console.log('guiapp listening on port 17777!')
var rungui = guiapp.listen(iguanaAppPort, function () {
console.log('guiapp listening on port ' + iguanaAppPort + '!')
})
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() === 'win32') { var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico') }
if (os.platform() === 'linux') {
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);
/*
@ -114,12 +126,16 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) {
let mainWindow
let loadingWindow
function createLoadingWindow() {
mainWindow = null;
// 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)
loadingWindow.loadURL('http://127.0.0.1:17777/gui/');
@ -131,8 +147,8 @@ function createLoadingWindow() {
loadingWindow.on('closed', function () {
// our app does not have multiwindow - so we dereference the window object instead of
// putting them into an window_arr
loadingWindow = null
createWindow('open')
loadingWindow = null;
createWindow('open');
})
//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'));
// 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)
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 {
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
@ -178,72 +198,70 @@ function createWindow (status) {
// if window closed we kill iguana proc
mainWindow.on('closed', function () {
var ConnectToPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('Closing Main Window...');
pm2.connect(true,function(err) {
console.log('connecting to pm2...');
if (err) {
console.log(err);
}
});
var result = 'Connecting To Pm2: done'
console.log(result)
resolve(result);
})
return new Promise(function(resolve, reject) {
console.log('Closing Main Window...');
pm2.connect(true,function(err) {
console.log('connecting to pm2...');
if (err) {
console.log(err);
}
});
var result = 'Connecting To Pm2: done';
console.log(result);
resolve(result);
})
}
var KillPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('killing to pm2...');
return new Promise(function(resolve, reject) {
console.log('killing to pm2...');
pm2.killDaemon(function(err) {
pm2.disconnect();
console.log('killed to pm2...');
if (err) throw err;
});
pm2.killDaemon(function(err) {
pm2.disconnect();
console.log('killed to pm2...');
if (err) throw err
});
var result = 'Killing Pm2: done';
var result = 'Killing Pm2: done'
setTimeout(function() {
console.log(result);
setTimeout(function() {
console.log(result)
resolve(result);
}, 2000)
})
resolve(result);
}, 2000)
})
}
var HideMainWindow = function() {
return new Promise(function(resolve, reject) {
console.log('Exiting App...');
mainWindow = null
var result = 'Hiding Main Window: done'
console.log(result)
resolve(result);
})
return new Promise(function(resolve, reject) {
console.log('Exiting App...');
mainWindow = null;
var result = 'Hiding Main Window: done';
console.log(result);
resolve(result);
});
}
var QuitApp = function() {
return new Promise(function(resolve, reject) {
app.quit();
var result = 'Quiting App: done'
console.log(result)
resolve(result);
})
return new Promise(function(resolve, reject) {
app.quit();
var result = 'Quiting App: done';
console.log(result);
resolve(result);
});
}
ConnectToPm2()
.then(function(result) {
return KillPm2();
return KillPm2();
})
.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') {
app.quit()
}*/
})
app.on('activate', function () {

27
private/mainmenu.js

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

19
private/setconf.js

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

257
routes/fetchparams.js

@ -1,154 +1,158 @@
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
var request = require('request');
var progress = require('request-progress');
const path = require('path')
const url = require('url')
const os = require('os')
const sha256 = require('sha256')
const crypto = require('crypto')
var app = require('http').createServer(handler),
io = require('socket.io')(app),
fs = require('fs'),
request = require('request'),
progress = require('request-progress');
const path = require('path'),
url = require('url'),
os = require('os'),
sha256 = require('sha256'),
crypto = require('crypto');
Promise = require('bluebird');
app.listen(3000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
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') {
var PARAMS_DIR = process.env.HOME + '/.zcash-params'
var PARAMS_DIR = process.env.HOME + '/.zcash-params';
}
//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_DL_URL="https://z.cash/downloads/"
var SPROUT_FILES_DATA = [
{
'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);
SPROUT_FILES_DATA.forEach(function (value, index) {
//console.log(index);
//console.log(value);
//console.log(value.file);
//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);
SPROUT_FILES_DATA.forEach(function(value, index) {
//console.log(index);
//console.log(value);
//console.log(value.file);
//console.log(value.hash);
} else {
var DLFile = function() {
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);
})
}
fs.exists(value.file, function(exists) {
if (exists) {
console.log(value.file + ' already exists at location.');
var tmphas,
fd = fs.createReadStream(value.file),
hash = crypto.createHash('sha256');
hash.setEncoding('hex');
var CheckFileSHA = function() {
return new Promise(function(resolve, reject) {
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)
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'
console.log(result)
resolve(result);
})
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 {
var DLFile = function() {
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 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()
.then(function(result) {
return CheckFileSHA();
})
}
});
});
console.log(result);
resolve(result);
});
}
DLFile()
.then(function(result) {
return CheckFileSHA();
});
}
});
});
function CheckSHASum(file, hashstr) {
console.log(hashstr)
var shasum
// the file you want to get the hash
if (shasum === hashstr ) {
return true
} else return false
console.log(hashstr);
var shasum;
// the file you want to get the hash
if (shasum === hashstr ) {
return true;
} else {
return false;
}
}
/*var CheckFileExists = function() {
return new Promise(function(resolve, reject) {
@ -199,11 +203,4 @@ ConnectToPm2()
})
.then(HideMainWindow)
.then(QuitApp)
*/
*/

370
routes/shepherd.js

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