diff --git a/gui/EasyDEX-GUI b/gui/EasyDEX-GUI index 338e125..597a06d 160000 --- a/gui/EasyDEX-GUI +++ b/gui/EasyDEX-GUI @@ -1 +1 @@ -Subproject commit 338e125db5b92f3fb0b690d4975b330f3330f2c9 +Subproject commit 597a06dd1376289aedeaf622ba1dd571e07088c6 diff --git a/package.json b/package.json index 84a17f4..a630fc0 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "pm2": "^2.3.0", "ps-node": "^0.1.4", "request": "^2.80.0", + "rimraf": "^2.6.1", "socket.io": "^1.7.3" } } diff --git a/routes/shepherd.js b/routes/shepherd.js index caf6a1b..f982b09 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -14,7 +14,8 @@ const electron = require('electron'), md5 = require('md5'), pm2 = require('pm2'), request = require('request'), - async = require('async'); + async = require('async'), + rimraf = require('rimraf'); Promise = require('bluebird'); @@ -1197,6 +1198,142 @@ shepherd.post('/getconf', function(req, res) { res.end(JSON.stringify(obj)); }); +/* + * type: GET + * params: coin, type + */ +shepherd.get('/kick', function(req, res, next) { + var _coin = req.query.coin, + _type = req.query.type; + + if (!_coin) { + var errorObj = { + 'msg': 'error', + 'result': 'no coin name provided' + }; + + res.end(JSON.stringify(errorObj)); + } + + if (!_type) { + var errorObj = { + 'msg': 'error', + 'result': 'no type provided' + }; + + res.end(JSON.stringify(errorObj)); + } + + var kickStartDirs = { + 'soft': [ + { + 'name': 'DB/[coin]/balancecrc.', + 'type': 'pattern' + }, + { + 'name': 'DB/[coin]/utxoaddrs', + 'type': 'file' + }, + { + 'name': 'DB/[coin]/accounts', + 'type': 'folder' + }, + { + 'name': 'DB/[coin]/fastfind', + 'type': 'folder' + }, + { + 'name': 'tmp/[coin]', + 'type': 'folder' + } + ], + 'hard': [ + { + 'name': 'DB/[coin]', + 'type': 'pattern', + 'match': 'balancecrc.' + }, + { + 'name': 'DB/[coin]/utxoaddrs', + 'type': 'file' + }, + { + 'name': 'DB/[coin]', + 'type': 'pattern', + 'match': 'utxoaddrs.' + }, + { + 'name': 'DB/[coin]/accounts', + 'type': 'folder' + }, + { + 'name': 'DB/[coin]/fastfind', + 'type': 'folder' + }, + { + 'name': 'DB/[coin]/spends', + 'type': 'folder' + }, + { + 'name': 'tmp/[coin]', + 'type': 'folder' + } + ], + 'brutal': [ // delete coin related data + { + 'name': 'DB/[coin]', + 'type': 'folder' + }, + { + 'name': 'DB/purgeable/[coin]', + 'type': 'folder' + }, + { + 'name': 'DB/ro/[coin]', + 'type': 'folder' + }, + { + 'name': 'tmp/[coin]', + 'type': 'folder' + } + ] + }; + + if (_coin && _type) { + for (var i = 0; i < kickStartDirs[_type].length; i++) { + console.log('deleting ' + kickStartDirs[_type][i].type + (kickStartDirs[_type][i].match ? ' ' + kickStartDirs[_type][i].match : '') + ' ' + iguanaDir + '/' + kickStartDirs[_type][i].name.replace('[coin]', _coin)); + if (kickStartDirs[_type][i].type === 'folder' || kickStartDirs[_type][i].type === 'file') { + rimraf(iguanaDir + '/' + kickStartDirs[_type][i].name.replace('[coin]', _coin), function(err) { + if (err) { + throw err; + } + }); + } else if (kickStartDirs[_type][i].type === 'pattern') { + var dirItems = fs.readdirSync(iguanaDir + '/' + kickStartDirs[_type][i].name.replace('[coin]', _coin)); + if (dirItems && dirItems.length) { + for (var j = 0; j < dirItems.length; j++) { + if (dirItems[j].indexOf(kickStartDirs[_type][i].match) > -1) { + rimraf(iguanaDir + '/' + kickStartDirs[_type][i].name.replace('[coin]', _coin) + '/' + dirItems[j], function(err) { + if (err) { + throw err; + } + }); + console.log('deleting ' + dirItems[j]); + } + } + } + } + } + + var successObj = { + 'msg': 'success', + 'result': 'kickstart: brutal is executed' + }; + + res.end(JSON.stringify(successObj)); + } +}); + shepherd.loadLocalConfig = function() { if (fs.existsSync(iguanaDir + '/config.json')) { var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); @@ -1722,40 +1859,43 @@ function setConf(flock) { } function getConf(flock) { + const komodoDir = '', + ZcashDir = '', + DaemonConfPath = ''; + console.log(flock); if (os.platform() === 'darwin') { - var komodoDir = process.env.HOME + '/Library/Application Support/Komodo', - ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; + 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', - ZcashDir = process.env.HOME + '/.zcash'; + komodoDir = process.env.HOME + '/.komodo'; + ZcashDir = process.env.HOME + '/.zcash'; } - if (os.platform() === 'win32') { - var komodoDir = process.env.APPDATA + '/Komodo', - ZcashDir = process.env.APPDATA + '/Zcash'; + if (os.platform() === 'win32') { + komodoDir = process.env.APPDATA + '/Komodo'; + ZcashDir = process.env.APPDATA + '/Zcash'; } switch (flock) { case 'komodod': - var DaemonConfPath = komodoDir; + DaemonConfPath = komodoDir; if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); console.log('===>>> SHEPHERD API OUTPUT ===>>>'); - console.log(DaemonConfPath); } break; case 'zcashd': - var DaemonConfPath = ZcashDir; + DaemonConfPath = ZcashDir; if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); } break; default: - var DaemonConfPath = komodoDir + '/' + flock; + DaemonConfPath = komodoDir + '/' + flock; if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); } @@ -1765,27 +1905,41 @@ function getConf(flock) { return DaemonConfPath; } -function formatBytes(bytes,decimals) { - if(bytes == 0) return '0 Bytes'; - var k = 1000, - dm = decimals + 1 || 3, - sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], - i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +function formatBytes(bytes, decimals) { + if (bytes == 0) + return '0 Bytes'; + + var k = 1000, + dm = decimals + 1 || 3, + sizes = [ + 'Bytes', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ], + i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; } shepherd.SystemInfo = function() { - os_data = { - 'totalmem_bytes': os.totalmem(), - 'totalmem_readble': formatBytes(os.totalmem()), - 'arch': os.arch(), - 'cpu': os.cpus()[0].model, - 'cpu_cors': os.cpus().length, - 'platform': os.platform(), - 'os_release': os.release(), - 'os_type': os.type() - } - return os_data + const os_data = { + 'totalmem_bytes': os.totalmem(), + 'totalmem_readble': formatBytes(os.totalmem()), + 'arch': os.arch(), + 'cpu': os.cpus()[0].model, + 'cpu_cores': os.cpus().length, + 'platform': os.platform(), + 'os_release': os.release(), + 'os_type': os.type() + }; + + return os_data; }