mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-15 01:31:37 +01:00
89 lines
3.4 KiB
PHP
Executable File
89 lines
3.4 KiB
PHP
Executable File
<?php
|
|
require_once "load.php";
|
|
|
|
$results = dbw_query($db_conn,"SELECT * FROM GROUPS"); //All groups
|
|
|
|
while ($group = dbw_fetch_array($db_conn,$results)){ //Know name of all groups
|
|
$groups[$group['ID_G']] = $group['name'];
|
|
}
|
|
unset($results); //Free mem
|
|
|
|
$results = dbw_query($db_conn,"SELECT * FROM CHECKS ORDER BY ID_G"); //All checks
|
|
|
|
while ($onechk = dbw_fetch_array($db_conn,$results)){
|
|
$idchk = $onechk['ID_C'];
|
|
$chks[$idchk] = $onechk; //First array data
|
|
$chks[$idchk]['nameGroup'] = $groups[$onechk['ID_G']]; //Know group of this check
|
|
$ID_TC = $chks[$idchk]['ID_TC']; //Type of Check
|
|
|
|
switch ($ID_TC){
|
|
// Case 3 (Visits) is numeric, not status
|
|
case 1: //Ping
|
|
case 2: //HttpCode
|
|
case 4: //MySQL
|
|
case 5: //JSON GET|POST
|
|
|
|
//To enter or not, check if has history (Instead of count > 0, only see if there is any timestamp, is faster)
|
|
if (dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' LIMIT 1")[0] != 0){
|
|
|
|
$consul = dbw_query_fetch_array($db_conn, "SELECT `code`,`timestamp` FROM CHKHIST WHERE ID_C = '$idchk' ORDER BY `timestamp` DESC LIMIT 1");
|
|
$chks[$idchk]['dateLastChk'] = date('d/m H:i',$consul['timestamp']);
|
|
|
|
$chks[$idchk]['failedLastChk'] = $consul['code'];
|
|
|
|
$lastErr = dbw_query_fetch_array($db_conn, "SELECT MAX(`timestamp`) FROM CHKHIST WHERE ID_C = '$idchk' AND code != 0")[0]; //Record last error, for showing if there are any.
|
|
if ($lastErr != false){
|
|
$chks[$idchk]['dateLastErr'] = date('d/m H:i',$lastErr);
|
|
}
|
|
|
|
$chks[$idchk]['nameCheck'] = arrayTypeChk()[$ID_TC]; //To send array name and not the word
|
|
|
|
if ($onechk['manStatus'] != ''){
|
|
$chks[$idchk]['uptime'] = 255;//255 = Maintenance I suppose, not implemented
|
|
}else{
|
|
$chks[$idchk]['uptime'] = getUptime($idchk);
|
|
}
|
|
list($chks[$idchk]['statusText'],$chks[$idchk]['statusColor']) = getStatus($idchk);
|
|
}else{ //If nothing collected yet
|
|
$chks[$idchk]['uptime'] = -1; // -1 is nothing in twig page
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: //Visits
|
|
$visitsSite = dbw_query($db_conn, "SELECT * FROM (SELECT * FROM VISITS WHERE ID_C = '$idchk' ORDER BY `date` DESC LIMIT 0,5) sub ORDER BY `date` ASC"); //Subquery for reorder lastest days in reverse
|
|
//Create array from last 5 days
|
|
while ($visitsDay = dbw_fetch_array($db_conn, $visitsSite)){
|
|
$dateArray[] = $visitsDay['date'];
|
|
$visitsArray[] = $visitsDay['visits'];
|
|
$uniqueVisitsArray[] = $visitsDay['uniqueVisits'];
|
|
}
|
|
$chks[$idchk]['dateArray'] = implode(',',$dateArray);
|
|
$chks[$idchk]['visitsArray'] = implode(',',$visitsArray);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
//Here load "News"
|
|
|
|
$incidents = dbw_query($db_conn,"SELECT * FROM NEWS ORDER BY ID_N DESC LIMIT 20");
|
|
while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
|
$ID_N = $incident['ID_N'];
|
|
$incs[$ID_N]['day'] = date('j/n/Y', $incident['timestamp']);
|
|
require_once "lib/parsedown.php"; //Import parsedown (once)
|
|
|
|
$incs[$ID_N]['sentBy'] = $incident['sentBy'];
|
|
if ($incident['sentBy'] != NULL && substr($incident['sentBy'],0,1) == "S"){ // Sent by a page
|
|
$pageinc = substr($incident['sentBy'],1);
|
|
$pageinc = dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C = '$pageinc'")[0];
|
|
$incs[$ID_N]['sentBy'] = $pageinc;
|
|
}
|
|
$incs[$ID_N]['text'] = Parsedown::instance()
|
|
->setMarkupEscaped(true) # escapes markup (HTML)
|
|
->text($incident['text']);
|
|
$incs[$ID_N]['ID_N'] = $incident['ID_N'];
|
|
}
|
|
renderPage('indexpage.twig',array('checks' => $chks, 'news' => $incs)); //Render
|
|
?>
|