Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from nanotools/develop
Browse files Browse the repository at this point in the history
v1.3.8
  • Loading branch information
BitDesert authored Mar 29, 2018
2 parents f5b7543 + 5f0b62f commit 41fe1f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
3 changes: 1 addition & 2 deletions modules/constants.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

// the project version
define('PROJECT_VERSION', '1.3.7');
define('PROJECT_VERSION', '1.3.8');

// project URL
define('PROJECT_URL', 'https://github.com/nanotools/nanoNodeMonitor');

// URL to get version of latest release from github

define('GITHUB_LATEST_API_URL', 'https://api.github.com/repos/nanotools/nanoNodeMonitor/releases/latest');

// donation account for Nano Node Monitor development
Expand Down
47 changes: 28 additions & 19 deletions modules/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function getSystemMemInfo()
// get system total memory in MB
function getSystemTotalMem()
{
return intval(getSystemMemInfo()["MemTotal"] / 1024);
return intval((int)getSystemMemInfo()["MemTotal"] / 1024);
}

// get system used memory in MB
function getSystemUsedMem()
{
$meminfo = getSystemMemInfo();
return intval(($meminfo["MemTotal"] - $meminfo["MemAvailable"]) / 1024);
return intval(((int)$meminfo["MemTotal"] - (int)$meminfo["MemAvailable"]) / 1024);
}

// get system uptime array with secs, mins, hours and days
Expand Down Expand Up @@ -83,30 +83,39 @@ function bool2string($boolean)
// get version of latest release from github
function getLatestReleaseVersion()
{

// get release tag of "latest" from github
$ch = curl_init();
curl_setopt_array($ch, [
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => GITHUB_LATEST_API_URL,
CURLOPT_HTTPHEADER => [
"Accept: application/vnd.github.v3+json",
"Content-Type: text/plain",
"User-Agent: Chrome/47.0.2526.111"
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_GET => true
]);
$output = curl_exec($ch);
curl_close($ch);
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"User-Agent: NanoNodeMonitor"
),
));

// decode json
$decoded = json_decode($output);
$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
return "API error";
}

// decode JSON response
$response = json_decode($response);

// tag string
if (array_key_exists("tag_name", $decoded))
if (property_exists($response, "tag_name"))
{
$tagString = $decoded->tag_name;
$tagString = $response->tag_name;

// search for version name x.x.x
if (0 != preg_match('/(\d+\.?)+$/', $tagString, $versionString))
Expand Down

0 comments on commit 41fe1f1

Please sign in to comment.