From d01ebdd1150c4cf40ccaa60a98919f9a40fed52e Mon Sep 17 00:00:00 2001 From: joeuhren <46763106+joeuhren@users.noreply.github.com> Date: Sat, 2 Jan 2021 01:30:47 -0700 Subject: [PATCH] Restore missing/deleted /ext/getnetworkpeers api -Added new public api setting for enabling disabling public use of /ext/getnetworkpeers api -Added new entry to the /info api page for the /ext/getnetworkpeers api -Integrated /ext/getnetworkpeers api into the network page + network includes and removed the deleted /ext/connections api references --- app.js | 30 ++++++++++++++++++++++++++++++ lib/settings.js | 1 + settings.json.template | 1 + views/includes/net_addnodes.pug | 4 ++-- views/includes/net_list.pug | 2 +- views/info.pug | 9 ++++++++- 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index f049867..57584b4 100644 --- a/app.js +++ b/app.js @@ -455,6 +455,36 @@ app.use('/ext/getsummary', function(req, res) { res.end('This method is disabled'); }); +app.use('/ext/getnetworkpeers', function(req, res) { + // check if the getnetworkpeers api is enabled or else check the headers to see if it matches an internal ajax request from the explorer itself (TODO: come up with a more secure method of whitelisting ajax calls from the explorer) + if ((settings.display.api == true && settings.public_api.ext['getnetworkpeers']) || (req.headers['x-requested-with'] != null && req.headers['x-requested-with'].toLowerCase() == 'xmlhttprequest' && req.headers.referer != null && req.headers.accept.indexOf('text/javascript') > -1 && req.headers.accept.indexOf('application/json') > -1)) { + var internal = false; + // split url suffix by forward slash and remove blank entries + var split = req.url.split('/').filter(function(v) { return v; }); + // check if this is an internal request + if (split.length > 0 && split[0].indexOf('internal') > -1) + internal = true; + + // get list of peers + db.get_peers(function(peers) { + // loop through peers list and remove the mongo _id and __v keys + for (i = 0; i < peers.length; i++) { + delete peers[i]['_doc']['_id']; + delete peers[i]['_doc']['__v']; + } + // check if this is an internal request + if (internal) { + // display data formatted for internal datatable + res.json({"data": peers}); + } else { + // display data in more readable format for public api + res.json(peers); + } + }); + } else + res.end('This method is disabled'); +}); + // get the list of masternodes from local collection app.use('/ext/getmasternodelist', function(req, res) { // check if the getmasternodelist api is enabled or else check the headers to see if it matches an internal ajax request from the explorer itself (TODO: come up with a more secure method of whitelisting ajax calls from the explorer) diff --git a/lib/settings.js b/lib/settings.js index 4e7ca40..d3ff603 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -260,6 +260,7 @@ exports.public_api = { "getcurrentprice": true, "getbasicstats": true, "getsummary": true, + "getnetworkpeers": true, "getmasternodelist": true, "getmasternoderewards": true, "getmasternoderewardstotal": true diff --git a/settings.json.template b/settings.json.template index 6f5a0ae..a030f17 100644 --- a/settings.json.template +++ b/settings.json.template @@ -345,6 +345,7 @@ "getcurrentprice": true, "getbasicstats": true, "getsummary": true, + "getnetworkpeers": true, "getmasternodelist": true, "getmasternoderewards": true, "getmasternoderewardstotal": true diff --git a/views/includes/net_addnodes.pug b/views/includes/net_addnodes.pug index fc573d5..340eb47 100644 --- a/views/includes/net_addnodes.pug +++ b/views/includes/net_addnodes.pug @@ -15,7 +15,7 @@ script. } }, ajax: { - url: '/ext/connections', + url: '/ext/getnetworkpeers/internal', dataSrc: function (json) { var rows = []; for (var i=0; i