From 9c82fe1f2faa40ed15d14000f2aaddd39795bff8 Mon Sep 17 00:00:00 2001 From: Michael <13236924+Mirobit@users.noreply.github.com> Date: Sun, 13 Dec 2020 18:05:14 +0100 Subject: [PATCH] Add api call icon --- src/Content.php | 56 +++++++++++++++++++++++------------------------ src/Utility.php | 42 +++++++++++++++++------------------ views/main.phtml | 9 ++++---- views/peers.phtml | 11 +++++----- 4 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/Content.php b/src/Content.php index f081c4e..be11453 100644 --- a/src/Content.php +++ b/src/Content.php @@ -3,45 +3,45 @@ namespace App; function createMainContent(){ - $peersInfo = getPeerData(); - $peerCount = count($peersInfo["peers"]); - $banListInfo = createBanListContent(); - - $content = []; - $content['bannedPeers'] = $banListInfo['totalBans']; - $content['last24h'] = $banListInfo['lastCount']; - $content['node'] = new Node(); - if(Config::PEERS_GEO){ - $content['map'] = createMapJs($peerCount, $peersInfo['countryList']); - } - $content['geo'] = Config::PEERS_GEO; - $content['nPeers'] = $peersInfo["newPeersCount"]; - $content['chartData'] = getTopClients($peersInfo["peers"]); - - // Current peers traffic - $content['cTrafficIn'] = round($peersInfo["cTrafficIn"]/1000, 2); - $content['cTrafficOut'] = round($peersInfo["cTrafficOut"]/1000, 2); - - return $content; + $peersData = getPeerData(); + $peerCount = count($peersData["peers"]); + $banListInfo = createBanListContent(); + + $content = []; + $content['bannedPeers'] = $banListInfo['totalBans']; + $content['last24h'] = $banListInfo['lastCount']; + $content['node'] = new Node(); + $content['geo'] = Config::PEERS_GEO; + if(isset($peersData['countryList'])) $content['map'] = createMapJs($peerCount, $peersData['countryList']); + if(isset($peersData['api'])) $content['api'] = $peersData['api']; + $content['nPeers'] = $peersData["newPeersCount"]; + $content['chartData'] = getTopClients($peersData["peers"]); + + // Current peers traffic + $content['cTrafficIn'] = round($peersData["cTrafficIn"]/1000, 2); + $content['cTrafficOut'] = round($peersData["cTrafficOut"]/1000, 2); + + return $content; } function createPeerContent(){ global $bitcoind; - $peersInfo = getPeerData(); + $peersData = getPeerData(); $netinfo = $bitcoind->getnettotals(); - $content = getMostPop($peersInfo["peers"]); - $content['peers'] = $peersInfo["peers"]; - $content['tPeers'] = count($peersInfo["peers"]); - $content['nPeers'] = $peersInfo["newPeersCount"]; + $content = getMostPop($peersData["peers"]); + $content['peers'] = $peersData["peers"]; + $content['tPeers'] = count($peersData["peers"]); + $content['nPeers'] = $peersData["newPeersCount"]; //$content['segWitP'] = round($content['segWitC']/($content['tPeers'] > 0 ? $content['tPeers'] : 1),2)*100; - $content['cTraffic'] = round($peersInfo["cTraffic"]/1000,2); - $content['cTrafficIn'] = round($peersInfo["cTrafficIn"]/1000, 2); - $content['cTrafficOut'] = round($peersInfo["cTrafficOut"]/1000, 2); + $content['cTraffic'] = round($peersData["cTraffic"]/1000,2); + $content['cTrafficIn'] = round($peersData["cTrafficIn"]/1000, 2); + $content['cTrafficOut'] = round($peersData["cTrafficOut"]/1000, 2); $content['tTraffic'] = round(($netinfo["totalbytesrecv"] + $netinfo["totalbytessent"])/1000000000,2); $content['tTrafficOutP'] = round(($netinfo["totalbytessent"]/($netinfo["totalbytesrecv"] + $netinfo["totalbytessent"])),2)*100; $content['cTrafficP'] = round($content['cTraffic']/($content['tTraffic'] > 0 ? $content['tTraffic'] : 1),2)*100; $content['geo'] = Config::PEERS_GEO; + if(isset($peersData['api'])) $content['api'] = $peersData['api']; return $content; } diff --git a/src/Utility.php b/src/Utility.php index febf827..c9753a0 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -479,16 +479,16 @@ function getPeerData(bool $geo = CONFIG::PEERS_GEO){ } function createPeersGeo($peerinfo){ - $peersInfo['countryList'] = []; - $peersInfo["peers"] = []; + $peerData['countryList'] = []; + $peerData["peers"] = []; // Current traffic - $peersInfo["cTraffic"] = 0; - $peersInfo["cTrafficIn"] = 0; - $peersInfo["cTrafficOut"] = 0; - $peersInfo["newPeersCount"] = 0; + $peerData["cTraffic"] = 0; + $peerData["cTrafficIn"] = 0; + $peerData["cTrafficOut"] = 0; + $peerData["newPeersCount"] = 0; // Not used yet - $peersInfo["hosterCount"] = 0; - $peersInfo["privateCount"] = 0; + $peerData["hosterCount"] = 0; + $peerData["privateCount"] = 0; $noGeoData = false; @@ -559,7 +559,7 @@ function createPeersGeo($peerinfo){ // Adds the new peer to the save list $arrayPeers[$peerObj->id] = array($peerObj->ip, $countryCode, $country, $isp, $hosted, 1); // Only counted for peers older than 5 minutes - $peersInfo["newPeersCount"]++; + $peerData["newPeersCount"]++; }elseif($peerObj->age > 5){ // If IP-Api.com call failed we set all data to Unknown and don't store the data $countryCode = "UN"; @@ -567,7 +567,7 @@ function createPeersGeo($peerinfo){ $isp = "Unknown"; $hosted = false; // Only counted for peers older than 5 minutes - $peersInfo["newPeersCount"]++; + $peerData["newPeersCount"]++; }else{ // If peer is younger than 5 minutes $countryCode = "NX"; @@ -590,11 +590,11 @@ function createPeersGeo($peerinfo){ } // Counts the countries - if(isset($peersInfo['countryList'][$country])){ - $peersInfo['countryList'][$country]['count']++; + if(isset($peerData['countryList'][$country])){ + $peerData['countryList'][$country]['count']++; }else{ - $peersInfo['countryList'][$country]['code'] = $countryCode; - $peersInfo['countryList'][$country]['count'] = 1; + $peerData['countryList'][$country]['code'] = $countryCode; + $peerData['countryList'][$country]['count'] = 1; } // Adds country data to peer object @@ -603,17 +603,17 @@ function createPeersGeo($peerinfo){ $peerObj->isp = $isp; $peerObj->hosted = $hosted; if($hosted){ - $peersInfo["hosterCount"]++; + $peerData["hosterCount"]++; }else{ - $peersInfo["privateCount"]++; + $peerData["privateCount"]++; } // Adds traffic of each peer to total traffic (in MB) - $peersInfo["cTraffic"] += $peerObj->traffic; - $peersInfo["cTrafficIn"] += $peerObj->trafficIn; - $peersInfo["cTrafficOut"] += $peerObj->trafficOut; + $peerData["cTraffic"] += $peerObj->traffic; + $peerData["cTrafficIn"] += $peerObj->trafficIn; + $peerData["cTrafficOut"] += $peerObj->trafficOut; // Adds peer to peer array - $peersInfo["peers"][] = $peerObj; + $peerData["peers"][] = $peerObj; } @@ -630,7 +630,7 @@ function createPeersGeo($peerinfo){ file_put_contents('data/geodatapeers.inc', $newSerializePeers); } - return $peersInfo; + return $peerData; } function getIpData($ips){ diff --git a/views/main.phtml b/views/main.phtml index 3c7263b..80cf1f5 100644 --- a/views/main.phtml +++ b/views/main.phtml @@ -210,11 +210,10 @@

Global Peer Distribution

diff --git a/views/peers.phtml b/views/peers.phtml index 28e3128..27b2811 100644 --- a/views/peers.phtml +++ b/views/peers.phtml @@ -55,11 +55,10 @@

Peers Connected

@@ -99,7 +98,7 @@ ping ?> hosted){ ?> isp,0,22) ?> age ?> - monitoring){ ?> client,0,13) ?> + monitoring){ ?> client,0,14) ?> traffic ?>