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
This commit is contained in:
joeuhren
2021-01-02 01:30:47 -07:00
parent 55449956ea
commit d01ebdd115
6 changed files with 43 additions and 4 deletions
+30
View File
@@ -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)
+1
View File
@@ -260,6 +260,7 @@ exports.public_api = {
"getcurrentprice": true,
"getbasicstats": true,
"getsummary": true,
"getnetworkpeers": true,
"getmasternodelist": true,
"getmasternoderewards": true,
"getmasternoderewardstotal": true
+1
View File
@@ -345,6 +345,7 @@
"getcurrentprice": true,
"getbasicstats": true,
"getsummary": true,
"getnetworkpeers": true,
"getmasternodelist": true,
"getmasternoderewards": true,
"getmasternoderewardstotal": true
+2 -2
View File
@@ -15,7 +15,7 @@ script.
}
},
ajax: {
url: '/ext/connections',
url: '/ext/getnetworkpeers/internal',
dataSrc: function (json) {
var rows = [];
for (var i=0; i<json.data.length; i++) {
@@ -50,7 +50,7 @@ script.
}
},
ajax: {
url: '/ext/connections',
url: '/ext/getnetworkpeers/internal',
dataSrc: function (json) {
var rows = [];
for (var i=0; i<json.data.length; i++) {
+1 -1
View File
@@ -15,7 +15,7 @@ script.
}
},
ajax: {
url: '/ext/connections',
url: '/ext/getnetworkpeers/internal',
dataSrc: function (json) {
return json.data;
}
+8 -1
View File
@@ -11,7 +11,7 @@ block content
em #{settings.locale.api_message}
hr
- var hide_rpc_api_section = !(settings.public_api.rpc['getdifficulty'] == true && settings.api_cmds['getdifficulty'] != null && settings.api_cmds['getdifficulty'] != '') && !(settings.public_api.rpc['getconnectioncount'] == true && settings.api_cmds['getconnectioncount'] != null && settings.api_cmds['getconnectioncount'] != '') && !(settings.public_api.rpc['getblockcount'] == true && settings.api_cmds['getblockcount'] != null && settings.api_cmds['getblockcount'] != '') && !(settings.public_api.rpc['getblockhash'] == true && settings.api_cmds['getblockhash'] != null && settings.api_cmds['getblockhash'] != '') && !(settings.public_api.rpc['getblock'] == true && settings.api_cmds['getblock'] != null && settings.api_cmds['getblock'] != '') && !(settings.public_api.rpc['getrawtransaction'] == true && settings.api_cmds['getrawtransaction'] != null && settings.api_cmds['getrawtransaction'] != '') && !(settings.public_api.rpc['getnetworkhashps'] == true && settings.index.show_hashrate == true && settings.api_cmds['getnetworkhashps'] != null && settings.api_cmds['getnetworkhashps'] != '') && !(settings.public_api.rpc['getvotelist'] == true && settings.api_cmds['getvotelist'] != null && settings.api_cmds['getvotelist'] != '') && !(settings.public_api.rpc['getmasternodecount'] == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '') && (!settings.heavy || (!(settings.public_api.rpc['getmaxmoney'] == true && settings.api_cmds.heavies['getmaxmoney'] != null && settings.api_cmds.heavies['getmaxmoney'] != '') && !(settings.public_api.rpc['getmaxvote'] == true && settings.api_cmds.heavies['getmaxvote'] != null && settings.api_cmds.heavies['getmaxvote'] != '') && !(settings.public_api.rpc['getvote'] == true && settings.api_cmds.heavies['getvote'] != null && settings.api_cmds.heavies['getvote'] != '') && !(settings.public_api.rpc['getphase'] == true && settings.api_cmds.heavies['getphase'] != null && settings.api_cmds.heavies['getphase'] != '') && !(settings.public_api.rpc['getreward'] == true && settings.api_cmds.heavies['getreward'] != null && settings.api_cmds.heavies['getreward'] != '') && !(settings.public_api.rpc['getsupply'] == true && settings.api_cmds.heavies['getsupply'] != null && settings.api_cmds.heavies['getsupply'] != '') && !(settings.public_api.rpc['getnextrewardestimate'] == true && settings.api_cmds.heavies['getnextrewardestimate'] != null && settings.api_cmds.heavies['getnextrewardestimate'] != '') && !(settings.public_api.rpc['getnextrewardwhenstr'] == true && settings.api_cmds.heavies['getnextrewardwhenstr'] != null && settings.api_cmds.heavies['getnextrewardwhenstr'] != '')));
- var hide_ext_api_section = !settings.public_api.ext['getmoneysupply'] && !settings.public_api.ext['getdistribution'] && !settings.public_api.ext['getaddress'] && !settings.public_api.ext['getaddresstxs'] && !settings.public_api.ext['gettx'] && !settings.public_api.ext['getbalance'] && !settings.public_api.ext['getlasttxs'] && !settings.public_api.ext['getcurrentprice'] && !settings.public_api.ext['getbasicstats'] && !settings.public_api.ext['getsummary'] && !(settings.public_api.ext['getmasternodelist'] == true && settings.api_cmds['getmasternodelist'] != null && settings.api_cmds['getmasternodelist'] != '') && !settings.public_api.ext['getmasternoderewards'] && !settings.public_api.ext['getmasternoderewardstotal'];
- var hide_ext_api_section = !settings.public_api.ext['getmoneysupply'] && !settings.public_api.ext['getdistribution'] && !settings.public_api.ext['getaddress'] && !settings.public_api.ext['getaddresstxs'] && !settings.public_api.ext['gettx'] && !settings.public_api.ext['getbalance'] && !settings.public_api.ext['getlasttxs'] && !settings.public_api.ext['getcurrentprice'] && !settings.public_api.ext['getnetworkpeers'] && !settings.public_api.ext['getbasicstats'] && !settings.public_api.ext['getsummary'] && !(settings.public_api.ext['getmasternodelist'] == true && settings.api_cmds['getmasternodelist'] != null && settings.api_cmds['getmasternodelist'] != '') && !settings.public_api.ext['getmasternoderewards'] && !settings.public_api.ext['getmasternoderewardstotal'];
if !hide_rpc_api_section
h3 #{settings.locale.api_calls}
p
@@ -203,6 +203,13 @@ block content
div
em Returns last known exchange price
a(href='/ext/getcurrentprice') #{address}/ext/getcurrentprice
if settings.public_api.ext['getnetworkpeers'] == true
li
p
div.font-weight-bold getnetworkpeers
div
em Returns the list of network peers that have connected to the explorer node in the last 24 hours
a(href='/ext/getnetworkpeers') #{address}/ext/getnetworkpeers
if settings.public_api.ext['getbasicstats'] == true
li
p