Skip to content

Commit

Permalink
Merge pull request #133 from zelcash/development
Browse files Browse the repository at this point in the history
v0.70.0
  • Loading branch information
TheTrunk authored Aug 3, 2020
2 parents 4498bbc + 0a13aeb commit c0e3a8f
Show file tree
Hide file tree
Showing 23 changed files with 3,582 additions and 379 deletions.
44 changes: 34 additions & 10 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ module.exports = (app, expressWs) => {
app.get('/zelapps/hashes', (req, res) => {
zelappsService.getZelAppHashes(req, res);
});
app.get('/zelapps/location/:zelapp?', (req, res) => {
zelappsService.getZelAppsLocation(req, res);
});
app.get('/zelapps/locations', (req, res) => {
zelappsService.getZelAppsLocations(req, res);
});
Expand Down Expand Up @@ -314,7 +317,7 @@ module.exports = (app, expressWs) => {
app.get('/zelbench/getstatus', (req, res) => {
zelbenchService.getStatus(req, res);
});
app.get('/zelbench/help', (req, res) => {
app.get('/zelbench/help/:command?', (req, res) => {
zelbenchService.help(req, res);
});
app.get('/zelbench/getbenchmarks', (req, res) => {
Expand Down Expand Up @@ -528,12 +531,6 @@ module.exports = (app, expressWs) => {
zelidService.logoutAllUsers(req, res);
});

app.get('/zelnode/startzelcash', (req, res) => {
zelnodeService.startZelCash(req, res);
});
app.get('/zelnode/restartzelcash', (req, res) => {
zelnodeService.restartZelCash(req, res);
});
app.get('/zelnode/reindexzelcash', (req, res) => {
zelnodeService.reindexZelCash(req, res);
});
Expand Down Expand Up @@ -565,6 +562,18 @@ module.exports = (app, expressWs) => {
zelcashService.stopZelBenchD(req, res);
});

app.get('/zelnode/startzelbench', (req, res) => {
zelnodeService.startZelBench(req, res);
});
app.get('/zelnode/restartzelbench', (req, res) => {
zelnodeService.restartZelBench(req, res);
});
app.get('/zelnode/startzelcash', (req, res) => {
zelnodeService.startZelCash(req, res);
});
app.get('/zelnode/restartzelcash', (req, res) => {
zelnodeService.restartZelCash(req, res);
});
app.get('/zelnode/updatezelflux', (req, res) => { // method shall be called only if zelflux version is obsolete.
zelnodeService.updateZelFlux(req, res);
});
Expand All @@ -586,9 +595,18 @@ module.exports = (app, expressWs) => {
app.get('/zelnode/zelbenchdebug', (req, res) => {
zelnodeService.zelbenchDebug(req, res);
});
app.get('/zelnode/tailzelcashdebug', (req, res) => {
zelnodeService.tailZelCashDebug(req, res);
});
app.get('/zelnode/tailzelbenchdebug', (req, res) => {
zelnodeService.tailZelBenchDebug(req, res);
});
app.get('/zelnode/zelfluxerrorlog', (req, res) => {
zelnodeService.zelfluxErrorLog(req, res);
});
app.get('/zelnode/tailzelfluxerrorlog', (req, res) => {
zelnodeService.tailFluxErrorLog(req, res);
});

app.get('/zelflux/broadcastmessage/:data?', (req, res) => {
zelfluxCommunication.broadcastMessageFromUser(req, res);
Expand All @@ -615,6 +633,12 @@ module.exports = (app, expressWs) => {
zelfluxCommunication.isCommunicationEstablished(req, res);
});

app.get('/zelbench/start', (req, res) => {
zelnodeService.startZelBench(req, res);
});
app.get('/zelbench/restart', (req, res) => {
zelnodeService.restartZelBench(req, res);
});
app.get('/zelbench/restartnodebenchmarks', (req, res) => {
zelbenchService.restartNodeBenchmarks(req, res);
});
Expand Down Expand Up @@ -692,13 +716,13 @@ module.exports = (app, expressWs) => {
app.get('/zelapps/createzelfluxnetwork', (req, res) => {
zelappsService.createZelFluxNetwork(req, res);
});
app.get('/zelapps/rescanglobalappsinformation/:blockheight?/:removelastinformation?', (req, res) => { // todo post, privileges
app.get('/zelapps/rescanglobalappsinformation/:blockheight?/:removelastinformation?', (req, res) => {
zelappsService.rescanGlobalAppsInformationAPI(req, res);
});
app.get('/zelapps/reindexglobalappsinformation', (req, res) => { // todo post, privileges
app.get('/zelapps/reindexglobalappsinformation', (req, res) => {
zelappsService.reindexGlobalAppsInformationAPI(req, res);
});
app.get('/zelapps/reindexglobalappslocation', (req, res) => { // todo post, privileges
app.get('/zelapps/reindexglobalappslocation', (req, res) => {
zelappsService.reindexGlobalAppsLocationAPI(req, res);
});

Expand Down
35 changes: 35 additions & 0 deletions ZelBack/src/services/zelappsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3382,6 +3382,40 @@ async function getZelAppsLocations(req, res) {
res.json(resultsResponse);
}

async function getZelAppsLocation(req, res) {
try {
let { zelapp } = req.params;
zelapp = zelapp || req.query.zelapp;
if (!zelapp) {
throw new Error('No ZelApp name specified');
}
const dbopen = serviceHelper.databaseConnection();
const database = dbopen.db(config.database.zelappsglobal.database);
const query = { name: new RegExp(`^${zelapp}$`, 'i') }; // case insensitive
const projection = {
projection: {
_id: 0,
name: 1,
hash: 1,
ip: 1,
broadcastedAt: 1,
expireAt: 1,
},
};
const results = await serviceHelper.findInDatabase(database, globalZelAppsLocations, query, projection);
const resultsResponse = serviceHelper.createDataMessage(results);
res.json(resultsResponse);
} catch (error) {
log.error(error);
const errorResponse = serviceHelper.createErrorMessage(
error.message || error,
error.name,
error.code,
);
res.json(errorResponse);
}
}

async function checkSynced() {
try {
// check if flux database is synced with zelcash database (equal or -1 inheight)
Expand Down Expand Up @@ -3797,6 +3831,7 @@ module.exports = {
rescanGlobalAppsInformation,
continuousZelAppHashesCheck,
getZelAppHashes,
getZelAppsLocation,
getZelAppsLocations,
storeZelAppRunningMessage,
reindexGlobalAppsLocation,
Expand Down
13 changes: 12 additions & 1 deletion ZelBack/src/services/zelcashService.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ async function getInfo(req, res) {

response = await executeCall(rpccall);

const authorized = await serviceHelper.verifyPrivilege('admin', req);
if (authorized !== true) {
delete response.data.balance;
}

return res ? res.json(response) : response;
}

Expand Down Expand Up @@ -192,7 +197,7 @@ async function getZelNodeCount(req, res) {
}

async function getDOSList(req, res) {
const rpccall = 'getdostlist';
const rpccall = 'getdoslist';

response = await executeCall(rpccall);

Expand Down Expand Up @@ -1284,6 +1289,12 @@ async function validateAddress(req, res) {
}
response = await executeCall(rpccall, rpcparameters);

const authorized = await serviceHelper.verifyPrivilege('admin', req);
if (authorized !== true) {
delete response.data.ismine;
delete response.data.iswatchonly;
}

return res ? res.json(response) : response;
}

Expand Down
112 changes: 112 additions & 0 deletions ZelBack/src/services/zelnodeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,47 @@ async function updateZelBench(req, res) {
}
}

// eslint-disable-next-line consistent-return
async function startZelBench(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
if (authorized === true) {
const exec = 'zelbenchd -daemon';
cmd.get(exec, (err, data) => {
if (err) {
const errMessage = serviceHelper.createErrorMessage(`Error starting ZelBench: ${err.message}`, err.name, err.code);
return res.json(errMessage);
}
console.log(data);
const message = serviceHelper.createSuccessMessage('ZelBench successfully started');
return res.json(message);
});
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
return res.json(errMessage);
}
}

// eslint-disable-next-line consistent-return
async function restartZelBench(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
if (authorized === true) {
const zelnodedpath = path.join(__dirname, '../../../helpers');
const exec = `cd ${zelnodedpath} && sh restartZelBench.sh`;
cmd.get(exec, (err) => {
if (err) {
const errMessage = serviceHelper.createErrorMessage(`Error restarting ZelBench: ${err.message}`, err.name, err.code);
return res.json(errMessage);
}
const message = serviceHelper.createSuccessMessage('ZelBench successfully restarted');
return res.json(message);
});
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
console.log(errMessage);
return res.json(errMessage);
}
}

// eslint-disable-next-line consistent-return
async function startZelCash(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
Expand Down Expand Up @@ -223,6 +264,50 @@ async function zelbenchDebug(req, res) {
return res.sendFile(filepath);
}

async function tailZelCashDebug(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
if (authorized === true) {
const homeDirPath = path.join(__dirname, '../../../../');
const datadir = zelcashService.getConfigValue('datadir') || `${homeDirPath}.zelcash`;
const filepath = `${datadir}/debug.log`;
const exec = `tail -n 100 ${filepath}`;
cmd.get(exec, (err, data) => {
if (err) {
const errMessage = serviceHelper.createErrorMessage(`Error obtaining ZelBench debug file: ${err.message}`, err.name, err.code);
res.json(errMessage);
return;
}
const message = serviceHelper.createSuccessMessage(data);
res.json(message);
});
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
}

async function tailZelBenchDebug(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
if (authorized === true) {
const homeDirPath = path.join(__dirname, '../../../../');
const datadir = `${homeDirPath}.zelbenchmark`;
const filepath = `${datadir}/debug.log`;
const exec = `tail -n 100 ${filepath}`;
cmd.get(exec, (err, data) => {
if (err) {
const errMessage = serviceHelper.createErrorMessage(`Error obtaining ZelBench debug file: ${err.message}`, err.name, err.code);
res.json(errMessage);
return;
}
const message = serviceHelper.createSuccessMessage(data);
res.json(message);
});
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
}

async function zelfluxErrorLog(req, res) {
const authorized = await serviceHelper.verifyPrivilege('zelteam', req);
if (!authorized) {
Expand All @@ -236,6 +321,28 @@ async function zelfluxErrorLog(req, res) {
return res.sendFile(filepath);
}

async function tailFluxErrorLog(req, res) {
const authorized = await serviceHelper.verifyZelTeamSession(req.headers);
if (authorized === true) {
const homeDirPath = path.join(__dirname, '../../../../');
const datadir = `${homeDirPath}zelflux`;
const filepath = `${datadir}/error.log`;
const exec = `tail -n 100 ${filepath}`;
cmd.get(exec, (err, data) => {
if (err) {
const errMessage = serviceHelper.createErrorMessage(`Error obtaining Flux error file: ${err.message}`, err.name, err.code);
res.json(errMessage);
return;
}
const message = serviceHelper.createSuccessMessage(data);
res.json(message);
});
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
}

function getZelFluxTimezone(req, res) {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
Expand Down Expand Up @@ -357,4 +464,9 @@ module.exports = {
zelfluxErrorLog,
getZelFluxTimezone,
getZelFluxInfo,
startZelBench,
restartZelBench,
tailZelCashDebug,
tailZelBenchDebug,
tailFluxErrorLog,
};
25 changes: 25 additions & 0 deletions ZelFront/src/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ a:hover {
hr {
height: 1px;
background-color: rgba(255, 255, 255, 0.6);
margin: 30px;
}

::-webkit-scrollbar {
Expand Down Expand Up @@ -307,3 +308,27 @@ h4 {
overflow: hidden;
border: 1px solid #333;
}

/* */

.zelnodesection .el-button,
.zelcashsection .el-button,
.zelbenchsection .el-button,
.zeladminsection .el-button {
margin: 10px;
}

.zelnodesection .el-switch,
.zelcashsection .el-switch,
.zelbenchsection .el-switch,
.zeladminsection .el-switch {
margin-left: 10px;
}

.helpSectionData {
text-align: left;
}

.helpSpecific {
margin-left: 30px;
}
Loading

0 comments on commit c0e3a8f

Please sign in to comment.