Added check if server is "up"

Clicking the OS icon on the card will ping either the ipv4 or hostname if ipv4 empy/null. If reached then the icon will return green else it will turn red.
This commit is contained in:
cp6 2021-01-27 13:49:32 +11:00
parent 07ea6ac27d
commit ec9a931ff6
4 changed files with 48 additions and 3 deletions

View File

@ -1290,6 +1290,18 @@ button.close {
color: #537cf7;
}
.os-icon {
color: #6f6b6b;
}
.green-fa {
color: #51bf51;
}
.red-fa {
color: #bf5151;
}
.tab-pane {
margin-top: .8rem
}

View File

@ -294,6 +294,25 @@ $(document).on("click", "#fillIpv4", function () {
}
});
$(document).on("click", "#checkUpStatus", function () {
var host_name = $(this).attr('value');
var icon = $(this).children().first();
if (host_name) {
$.ajax({
type: "GET",
url: "check_up.php",
data: {"type": "check_up", "host": host_name},
success: function (result) {
if (result == 1) {
icon.addClass("green-fa");
} else {
icon.addClass("red-fa");
}
}
});
}
});
$('#virt').change(function(){
if($(this).val() == 'DEDI'){
$('#dedi_cpu').prop("checked", true);

View File

@ -38,6 +38,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
} elseif ($_GET['type'] == 'dns_search') {
$idle->getIpForDomain($_GET['hostname'], $_GET['type']);
} elseif ($_GET['type'] == 'check_up') {
echo $idle->checkIsUp($_GET['host']);
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {

View File

@ -859,7 +859,7 @@ class idlers extends helperFunctions
protected function vpsCard(string $id)
{
$select = $this->dbConnect()->prepare("
SELECT servers.id,servers.hostname,servers.`cpu`,servers.cpu_freq,servers.ram,servers.ram_type,servers.`disk`,
SELECT servers.id,servers.hostname,servers.ipv4,servers.`cpu`,servers.cpu_freq,servers.ram,servers.ram_type,servers.`disk`,
servers.disk_type,servers.os,servers.virt,servers.was_special,locations.name as location,providers.name as provider,pricing.price,pricing.currency,pricing.term,pricing.next_dd
FROM servers INNER JOIN locations on servers.location = locations.id INNER JOIN providers on servers.provider = providers.id
INNER JOIN pricing on servers.id = pricing.server_id WHERE servers.id = ? LIMIT 1;");
@ -874,7 +874,8 @@ class idlers extends helperFunctions
$this->HTMLphrase('h4', 'hostname-header', $data['hostname']);
$this->tagClose('div');
$this->colOpen('col-12 col-xl-2 os-col');
$this->outputString($this->osIntToIcon($data['os']));
(empty($data['ipv4']) || is_null($data['ipv4'])) ? $host = $data['hostname'] : $host = $data['ipv4'];
$this->outputString('<a id="checkUpStatus" href="#" value="' . $host . '">' . $this->osIntToIcon($data['os']) . '</a>');
$this->tagClose('div', 3);
$this->tagOpen('div', 'card-body');
$this->HTMLphrase('h6', 'price', '$' . $data['price'] . ' ' . $data['currency'] . ' ' . $this->paymentTerm($data['term']));
@ -2799,6 +2800,17 @@ class idlers extends helperFunctions
return "";//Doesnt exist/null/empty/invalid
}
public function checkIsUp(string $host, int $port = 80, int $wait_time = 1): int
{//Check if host/ip is "up"
if ($fp = @fsockopen($host, $port, $errCode, $errStr, $wait_time)) {
$result = 1;
} else {
$result = 0;
}
@fclose($fp);
return $result;
}
}
class itemInsert extends idlers