mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-22 04:54:06 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1efecc2633 | |||
| a91347ca46 | |||
| 3547695245 | |||
| 0aeaada922 | |||
| 5e33adbbaf | |||
| 42583d198e | |||
| cb20328a6a | |||
| f1b58a03f3 | |||
| 8b86e38361 |
16
README.md
16
README.md
@@ -43,9 +43,21 @@ a backup of your sqlite.db3 database.
|
||||
|
||||
## Changelog
|
||||
|
||||
### (WIP) Version 0.9.2
|
||||
### (WIP) Version 0.9.3
|
||||
|
||||
-TODO: More info in admin page
|
||||
-TODO: Cleaner code
|
||||
|
||||
### Version 0.9.2 (Beta)
|
||||
|
||||
-A bit more info in admin page (Checks->Errors/History info)
|
||||
|
||||
-Fix duplicate entries for failed checks (Less false failed tests)
|
||||
|
||||
-More optimizations when lot of pages/tests
|
||||
|
||||
-Fix dates and some texts in index
|
||||
|
||||
-Updater fixed, 0.9.1 not working right
|
||||
|
||||
### Version 0.9.1 (Beta)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<p>JKA Network © 2017-actualidad. Versión 0.1 Alpha</p>
|
||||
<p>JKA Network © 2018. Versión {{version}}</p>
|
||||
</div>
|
||||
<div class="col-sm-6 text-right">
|
||||
<p>Design by <a href="https://bootstrapious.com" class="external">Bootstrapious</a></p>
|
||||
|
||||
@@ -31,44 +31,30 @@
|
||||
|
||||
{# "Switch" type #}
|
||||
{% if check.ID_TC == 1 or check.ID_TC == 2 or check.ID_TC == 4 %} {# Ping, HttpCode, SQL DB #}
|
||||
|
||||
{% if check.uptime != -1 %}{#Only if records exists#}
|
||||
<td>
|
||||
{#IF/SWITCH uptime to text#}
|
||||
{%if check.uptime <= 100 and check.uptime > 90 %}
|
||||
<span class='green' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_right}}</span>
|
||||
{%elseif check.uptime <= 95 and check.uptime > 60 %}
|
||||
<span class='blue' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_lproblems}}</span>
|
||||
{%elseif check.uptime <= 60 and check.uptime > 15 %}
|
||||
<span class='orange' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_problems}}</span>
|
||||
{%elseif check.uptime <= 15 and check.uptime >= 0 %}
|
||||
<span class='red' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_outofserv}}</span>
|
||||
{%elseif check.uptime == 255 %}
|
||||
<span class='blue' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_maintenance}}</span>
|
||||
{%else%}
|
||||
<span class='grey' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_empty}}</span>
|
||||
{%endif%}
|
||||
{#END IF/SWITCH#}
|
||||
<span class='{{check.statusColor}}' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{check.statusText}}</span>
|
||||
({{ check.uptime}}%)
|
||||
</td>
|
||||
{% if check.uptime != -1 %}{#Only if records exists#}
|
||||
<td>
|
||||
{{check.dateLastChk}} -
|
||||
{% if check.failedLastChk == 0 %}
|
||||
<span style="color:green">{{T_.status_right}}</span>
|
||||
{% else %}
|
||||
<span style="color:red">{{T_.failed}}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{%else%}
|
||||
<td>Dame tiempo para recopilar estadísticas</td>
|
||||
{%endif%}
|
||||
<td>
|
||||
{%if check.dateLastErr is not null%}
|
||||
{{check.dateLastErr}}
|
||||
{%else%}
|
||||
{{T_.no_errs}}
|
||||
{%endif%}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{{check.dateLastChk}} -
|
||||
{% if check.failedLastChk == 0 %}
|
||||
<span style="color:green">{{T_.status_right}}</span>
|
||||
{% else %}
|
||||
<span style="color:red">{{T_.failed}}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{%else%} {#If not records yet#}
|
||||
<td colspan="2">Dame tiempo para recopilar estadísticas</td>
|
||||
{%endif%}
|
||||
<td>
|
||||
{%if check.dateLastErr is not null%}
|
||||
{{check.dateLastErr}}
|
||||
{%else%}
|
||||
{{T_.no_errs}}
|
||||
{%endif%}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if check.ID_TC == 3 %}
|
||||
<td colspan="3">
|
||||
|
||||
@@ -29,4 +29,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
{% include 'footer.twig' %}
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
<div class="wrapper recent-updated">
|
||||
<div id="new-updates" class="card-header d-flex justify-content-between align-items-center">
|
||||
<h2 class="h5 display"><a data-toggle="collapse" data-parent="#accordion" href="#upadtes-box" aria-expanded="true" aria-controls="upadtes-box">Ultimos fallos</a></h2>
|
||||
<h2 class="h5 display"><a data-toggle="collapse" data-parent="#accordion" href="#upadtes-box" aria-expanded="true" aria-controls="upadtes-box">{{T_.lastest_fails}}</a></h2>
|
||||
</div>
|
||||
<div id="upadtes-box" role="tabpanel" class="collapse show">
|
||||
<ul class="news list-unstyled">
|
||||
@@ -48,9 +48,9 @@
|
||||
<li class="d-flex justify-content-between">
|
||||
<div class="left-col d-flex">
|
||||
<div class="icon"><i class="icon-times"></i></div>
|
||||
<div class="title">{{fail.name}} - <strong>{{fail.groupName}}</strong>
|
||||
<div class="title"><a href="?page=viewhist&ID_C={{fail.ID_C}}">{{fail.name}} - <strong>{{fail.groupName}}</strong>
|
||||
<p>{{fail.typeCheck}}</p>
|
||||
</div>
|
||||
</a></div>
|
||||
</div>
|
||||
<div class="right-col text-right">
|
||||
<div class="update-date">{{fail.date}}<span class="month">{{fail.hour}}</span></div>
|
||||
|
||||
84
assets/html/panel/p_viewhist.twig
Executable file
84
assets/html/panel/p_viewhist.twig
Executable file
@@ -0,0 +1,84 @@
|
||||
{% include 'panel/p_header.twig' %}
|
||||
<script src="assets/js/Chart.min.js"></script>
|
||||
<!-- Checks -->
|
||||
<section>
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h2 class="h5 display">Historial de los últimos {{pagedata.cant}} checks de {{pagedata.name}} - {{pagedata.group}}</h2>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-block">
|
||||
<div style="width:75%;">
|
||||
<canvas id="canvas"></canvas>
|
||||
</div>
|
||||
<!-- Lastest fails -->
|
||||
<h2>{{T_.lastest_fails}}</h2>
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for err in pagedata.fails %}
|
||||
<tr>
|
||||
<td>{{err}}</td>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Script Chartjs -->
|
||||
<script>
|
||||
var barChartData = {
|
||||
//labels: ["Correctos", "Errores"],
|
||||
datasets: [{
|
||||
label: "Correctos",
|
||||
backgroundColor: "#2B86FF",
|
||||
borderColor: "#2B86FF",
|
||||
data: [ {{ pagedata.cgood }} ]
|
||||
},{
|
||||
label: "Errores",
|
||||
backgroundColor: "#ff2a2a",
|
||||
borderColor: "#ff2a2a",
|
||||
data: [ {{ pagedata.cbad }} ]
|
||||
}]
|
||||
};
|
||||
var config = {
|
||||
type: 'bar',
|
||||
data: barChartData,
|
||||
|
||||
options: {
|
||||
responsive: true,
|
||||
legend: {
|
||||
position: 'top',
|
||||
},
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Checks correctos y erroneos'
|
||||
},
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
var ctx = document.getElementById("canvas").getContext("2d");
|
||||
window.myBar = new Chart(ctx, config);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% include 'footer.twig' %}
|
||||
@@ -38,4 +38,5 @@ $T_['VISIT_COUNT'] = 'Visit counter';
|
||||
$T_['DATABASE'] = 'Database check';
|
||||
$T_['add_grp_to_add_chk'] = 'Add a group for start adding checks';
|
||||
$T_['view_hist'] = 'View history';
|
||||
$T_['lastest_fails'] = 'Lastest fails';
|
||||
?>
|
||||
@@ -38,4 +38,5 @@ $T_['VISIT_COUNT'] = 'Contador de visitas';
|
||||
$T_['DATABASE'] = 'Conexión a base de datos';
|
||||
$T_['add_grp_to_add_chk'] = 'Añade un grupo para empezar a añadir checks';
|
||||
$T_['view_hist'] = 'Ver histórico';
|
||||
$T_['lastest_fails'] = 'Ultimos errores';
|
||||
?>
|
||||
37
connect.php
37
connect.php
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
define('VERSION','0.9.1');
|
||||
session_start(); //Session in all page
|
||||
require_once "lib/dbwrapper.php";
|
||||
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (!is_file($db_file)){ //Go to install if not.
|
||||
header("Location: install.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$db_conn = dbw_connect("sqlite",$db_file); //Database
|
||||
|
||||
/** In connect.php check if user SessionID exists, if not, delete Cookie */
|
||||
if (isset($_SESSION['UserID'])){
|
||||
$data = dbw_query_fetch_array($db_conn, "SELECT * FROM USERS WHERE ID_U='$_SESSION[UserID]'");
|
||||
if ($data['ID_U'] != $_SESSION['UserID']){
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
}
|
||||
|
||||
$you['ID_U'] = $data['ID_U'];
|
||||
$you['nick'] = $data['nick'];
|
||||
$you['fullRights'] = $data['fullRights'];
|
||||
$you['webRoot'] = webRoot();
|
||||
}
|
||||
|
||||
$lang=getSystemOpt($db_conn,'lang');
|
||||
//Translations
|
||||
require_once __DIR__."/assets/translations/en.php"; //Ever first English, and then your lang (Database)
|
||||
require_once __DIR__."/assets/translations/$lang.php";
|
||||
|
||||
$ver=getSystemOpt($db_conn,'version');
|
||||
if (getSystemOpt($db_conn,'version') != VERSION){
|
||||
die("<p>Please run updater.php to update before using page");
|
||||
}
|
||||
?>
|
||||
37
cronchk.php
37
cronchk.php
@@ -1,33 +1,29 @@
|
||||
<?php
|
||||
require_once "functions.php";
|
||||
|
||||
function PING_IP($db_conn,$ID_C,$URL,$timestamp){
|
||||
function PING_IP($db_conn,$ID_C,$URL){
|
||||
if (strpos($URL, ":")){ //Si usa un puerto, dividir
|
||||
$host = explode(":", $URL)[0];
|
||||
$port = explode(":", $URL)[1];
|
||||
}else{$host=$URL;}
|
||||
$result = isset($port) ? ping($host,$port) : ping($host); //Ping IP with or without port
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','$result','$timestamp')");
|
||||
return $result; //Returns result
|
||||
}
|
||||
|
||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param,$timestamp){
|
||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param){
|
||||
$httpCode = httpCode($URL); //Code
|
||||
|
||||
$code = (int)$Param != 0 ? $Param : 200; //Establish the code test want to see
|
||||
|
||||
if ($httpCode == $code){ //Si es igual
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
$ret = 0; //All right
|
||||
}else{ //Si no es igual (Incluye false)
|
||||
$httpCode = (int)$httpCode; //Force int
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`codeText`,`timestamp`) VALUES ('$ID_C','1','$httpCode','$timestamp')");
|
||||
$ret = 1;
|
||||
$ret = (int)$httpCode; //Code not 0 (And it's received code)
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
||||
function DATABASE_CONN($db_conn,$ID_C,$URL){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $URL);
|
||||
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||
@@ -37,13 +33,10 @@ function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
||||
curl_close($ch);
|
||||
$result = htmlentities($body);
|
||||
if($result == 'OK'){
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
$ret = 0;
|
||||
}else{ //Fail if it's not ok.
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
||||
$ret = 1;
|
||||
return 0;
|
||||
}else{ //Fail if it returns other than "OK".
|
||||
return 1;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,18 +50,28 @@ while ($site = dbw_fetch_array($db_conn,$sites)){
|
||||
|
||||
switch ($site['ID_TC']) {
|
||||
case '1': //Ping to IP:Port
|
||||
$exitC = PING_IP($db_conn,$ID_C,$site['URL'],time());
|
||||
$exitC = PING_IP($db_conn,$ID_C,$site['URL']);
|
||||
break;
|
||||
|
||||
case '2': //HttpCode
|
||||
$exitC = HTTP_CODE($db_conn,$ID_C,$site['URL'],$site['TCParam'],time());
|
||||
$exitC = HTTP_CODE($db_conn,$ID_C,$site['URL'],$site['TCParam']);
|
||||
break;
|
||||
|
||||
case '4': //MySQL|Database connect
|
||||
$exitC = DATABASE_CONN($db_conn,$ID_C,$site['URL'],time());
|
||||
$exitC = DATABASE_CONN($db_conn,$ID_C,$site['URL']);
|
||||
break;
|
||||
}
|
||||
}while($try <= 2 && $exitC == 1);
|
||||
$timestamp = time();
|
||||
if ($exitC == 0){ //Check successful
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
}else if ($exitC == 1){ //Normal check failed
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
||||
}else{ //Other code of check failed
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`errorText`,`timestamp`) VALUES ('$ID_C','1','$exitC','$timestamp')");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
/* First, db connection */
|
||||
require_once "connect.php";
|
||||
require_once 'lib/loadTwig.php';
|
||||
//Functions
|
||||
|
||||
function checkUptime($db_conn,$ID_C,$precision = 0){
|
||||
function getUptime($ID_C,$precision = 0){
|
||||
$db_conn = getconn();
|
||||
if ($precision == 0){
|
||||
$time = time()-30*7*3600; //Last week
|
||||
}else{
|
||||
@@ -16,7 +15,6 @@ function checkUptime($db_conn,$ID_C,$precision = 0){
|
||||
$count++;
|
||||
$err += $fila['code'];
|
||||
}
|
||||
echo $count."-";
|
||||
if ($count == 0){
|
||||
return '-1'; //No registers
|
||||
}else{
|
||||
@@ -27,7 +25,34 @@ function checkUptime($db_conn,$ID_C,$precision = 0){
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getStatus($ID_C){
|
||||
$T_ = loadLang();
|
||||
$db_conn = getconn();
|
||||
$resql = dbw_query($db_conn,"SELECT code FROM CHKHIST WHERE ID_C='$ID_C' ORDER BY `timestamp` DESC LIMIT 5");
|
||||
$err = 0;
|
||||
while ($x = dbw_fetch_array($db_conn,$resql)){
|
||||
if ($x['code'] != 0){
|
||||
$err++;
|
||||
}
|
||||
}
|
||||
switch ($err){
|
||||
case 0:
|
||||
case 1:
|
||||
return array($T_['status_right'],'green');
|
||||
break;
|
||||
case 2:
|
||||
return array($T_['status_lproblems'],'blue');
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
return array($T_['status_problems'],'orange');
|
||||
break;
|
||||
default: // > 4
|
||||
return array($T_['status_outofserv'],'red');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +70,8 @@ function webRoot(){
|
||||
}
|
||||
|
||||
/** Returns a system option */
|
||||
function getSystemOpt($db_conn,$sysopt){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
||||
function getSystemOpt($sysopt){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
||||
}
|
||||
|
||||
/** Return HttpCode of page. Returns false if page is not found */
|
||||
@@ -97,16 +122,16 @@ function requireLogin(){
|
||||
}
|
||||
}
|
||||
|
||||
function nameFromIDC($db_conn,$ID_C){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
||||
function nameFromIDC($ID_C){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
||||
}
|
||||
|
||||
function nameGroupFromIDG($db_conn,$ID_G){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
function nameGroupFromIDG($ID_G){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
}
|
||||
|
||||
function IDGFromIDC($db_conn,$ID_C){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G'];
|
||||
function IDGFromIDC($ID_C){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G'];
|
||||
}
|
||||
|
||||
/* This funtion returns the array with type of checks */
|
||||
@@ -118,11 +143,35 @@ function arrayTypeChk(){
|
||||
'4' => 'DATABASE');
|
||||
}
|
||||
/* This funtion returns the translated text of a type check */
|
||||
function textTypeChk($T_,$typeChk){
|
||||
function textTypeChk($typeChk){
|
||||
$T_ = loadLang();
|
||||
$arr = array(
|
||||
'1' => $T_['PING_IP'],
|
||||
'2' => $T_['HTTP_CODE'],
|
||||
'3' => $T_['VISIT_COUNT'],
|
||||
'4' => $T_['DATABASE']);
|
||||
return $arr[$typeChk];
|
||||
}
|
||||
}
|
||||
|
||||
//This function is an alias to Twig render, with "standard args" added
|
||||
function renderPage($page,$array = array()){
|
||||
$T_ = loadLang(); //Load transactions
|
||||
//Default params to send
|
||||
$allarray = array(
|
||||
'version' => VERSION,
|
||||
'T_' => $T_,
|
||||
);
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$allarray[$key] = $value;
|
||||
}
|
||||
require 'lib/loadTwig.php';
|
||||
echo $twig->render($page, $allarray);
|
||||
}
|
||||
|
||||
function loadLang(){
|
||||
//Translations
|
||||
require __DIR__."/assets/translations/en.php"; //Ever first English, and then your lang (Database)
|
||||
require __DIR__."/assets/translations/".LANG.".php";
|
||||
return $T_;
|
||||
}
|
||||
|
||||
29
index.php
29
index.php
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
require_once "functions.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
|
||||
|
||||
@@ -14,41 +14,43 @@ 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 ($chks[$idchk]['ID_TC']){
|
||||
switch ($ID_TC){
|
||||
// Case 1 and 2 are normal status, case 3 (Visits) is numeric, not status
|
||||
case 1: //Ping
|
||||
case 2: //HttpCode
|
||||
case 4: //MySQL
|
||||
|
||||
if (dbw_query_fetch_array($db_conn, "SELECT COUNT(`ID_CHist`) FROM CHKHIST WHERE ID_C = '$idchk'")[0] != 0){
|
||||
//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' AND (select min(`timestamp`) FROM CHKHIST)");
|
||||
$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 MIN(`timestamp`) FROM CHKHIST WHERE ID_C = '$idchk' AND code != 0")[0]; //Record last error, for showing if there are any.
|
||||
$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);
|
||||
}
|
||||
|
||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
||||
$chks[$idchk]['nameCheck'] = textTypeChk($T_,$ID_TC);
|
||||
$chks[$idchk]['nameCheck'] = textTypeChk($ID_TC);
|
||||
|
||||
if ($onechk['manStatus'] != ''){
|
||||
$chks[$idchk]['uptime'] = 255;//255 = Maintenance I suppose, not implemented
|
||||
}else{
|
||||
$chks[$idchk]['uptime'] = checkUptime($db_conn,$idchk);
|
||||
$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");
|
||||
$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'];
|
||||
@@ -81,6 +83,5 @@ while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
||||
->text($incident['text']);
|
||||
$incs[$ID_N]['ID_N'] = $incident['ID_N'];
|
||||
}
|
||||
|
||||
echo $twig->render('indexpage.twig', array('T_' => $T_, 'you' => $you, 'checks' => $chks, 'news' => $incs)); //Render
|
||||
renderPage('indexpage.twig',array('you' => $you,'checks' => $chks, 'news' => $incs)); //Render
|
||||
?>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
define('VERSION','0.9.1');
|
||||
define('VERSION','0.9.2');
|
||||
//define('INSTALLER_MODE','1');
|
||||
require_once 'lib/loadTwig.php';
|
||||
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
|
||||
38
load.php
Normal file
38
load.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
require_once 'functions.php'; //Preloads functions
|
||||
require_once 'lib/dbwrapper.php';
|
||||
define('VERSION','0.9.2');
|
||||
session_start(); //Session in all page
|
||||
//Preload file
|
||||
//This function loads all things needed, with optional db things if needed
|
||||
|
||||
function getconn(){
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (!is_file($db_file)){ //Go to install if not.
|
||||
header("Location: install.php");
|
||||
die();
|
||||
}
|
||||
return dbw_connect("sqlite",$db_file); //Database
|
||||
}
|
||||
|
||||
$db_conn = getconn();
|
||||
|
||||
/** Check if user SessionID exists, if not, delete Cookie */
|
||||
if (isset($_SESSION['UserID'])){
|
||||
$data = dbw_query_fetch_array($db_conn, "SELECT * FROM USERS WHERE ID_U='$_SESSION[UserID]'");
|
||||
if ($data['ID_U'] != $_SESSION['UserID']){
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
}
|
||||
|
||||
$you['ID_U'] = $data['ID_U'];
|
||||
$you['nick'] = $data['nick'];
|
||||
$you['fullRights'] = $data['fullRights'];
|
||||
$you['webRoot'] = webRoot();
|
||||
}
|
||||
define('LANG', getSystemOpt('lang'));
|
||||
|
||||
if (getSystemOpt('version') != VERSION){
|
||||
die("<p>Please run updater.php to update before using page");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
require "functions.php";
|
||||
require "load.php";
|
||||
|
||||
if (isset($_GET['do'])){
|
||||
if ($_GET['do'] == 'logout'){
|
||||
require_once "connect.php";
|
||||
//dbw_query($db_conn, "UPDATE USERS SET SessionID = NULL WHERE SessionID='$_COOKIE[SessionID]'");
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
}
|
||||
@@ -15,7 +13,7 @@ if (isset($_SESSION['UserID'])){ //Ya está logueado
|
||||
}
|
||||
|
||||
if (!isset($_POST['nick'])){
|
||||
echo $twig->render('login.twig');
|
||||
renderPage('login.twig');
|
||||
}
|
||||
if (isset($_POST['nick'])){
|
||||
$nick=$_POST['nick'];
|
||||
@@ -27,7 +25,7 @@ if (isset($_POST['nick'])){
|
||||
$_SESSION['UserID'] = $resql['ID_U'];
|
||||
header('Location: panel.php');
|
||||
}else{
|
||||
echo $twig->render('login.twig', array('status' => 'error'));
|
||||
renderPage('login.twig', array('status' => 'error'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
58
panel.php
58
panel.php
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once 'functions.php';
|
||||
require_once 'load.php';
|
||||
requirelogin();
|
||||
|
||||
//Calculo día 1 del mes en curso
|
||||
@@ -38,7 +38,7 @@ switch($page){
|
||||
$ID_G = $chks[$idchk]['ID_G']; //For nameGroup
|
||||
$chks[$idchk]['nameGroup'] = dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
||||
$chks[$idchk]['nameTCheck'] = textTypeChk($T_,$ID_TC);
|
||||
$chks[$idchk]['nameTCheck'] = textTypeChk($ID_TC);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ switch($page){
|
||||
$emptyG[] = array('name' =>$emptygrp['name']);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_checks.twig', array('T_' => $T_, 'mpage' => 'checks','you' => $you, 'checks' => $chks,'groups' => $groups,'emptygrp' => $emptyG));
|
||||
renderPage('panel/p_checks.twig',array('mpage' => 'checks','you' => $you, 'checks' => $chks,'groups' => $groups,'emptygrp' => $emptyG));
|
||||
break;
|
||||
|
||||
//Forms to add or edit a check (Not saving, only forms)
|
||||
@@ -65,17 +65,18 @@ switch($page){
|
||||
foreach(arrayTypeChk() as $key => $value){
|
||||
$tchecks[] = array(
|
||||
'ID_TC' =>$key,
|
||||
'name' => textTypeChk($T_,$key)
|
||||
'name' => textTypeChk($key)
|
||||
);
|
||||
}
|
||||
|
||||
//En este if hago las diferencias entre add y edit, para no repetir código.
|
||||
if ($page == 'addcheck'){
|
||||
echo $twig->render('panel/p_addedit.twig', array('T_' => $T_, 'mpage' => 'checks', 'type' => 'new','groups' => $groups,'tchecks' => $tchecks));
|
||||
renderPage('panel/p_addedit.twig', array('mpage' => 'checks', 'type' => 'new','groups' => $groups,'tchecks' => $tchecks));
|
||||
}elseif ($page == 'editcheck'){
|
||||
$ID_C = (int)$_GET['ID_C']; //Check to edit
|
||||
$checkdata = dbw_query_fetch_array($db_conn,"SELECT * FROM CHECKS WHERE ID_C='$ID_C'"); //Checkdata
|
||||
echo $twig->render('panel/p_addedit.twig', array('T_' => $T_, 'mpage' => 'checks', 'you' => $you, 'type' => 'edit','groups' => $groups,'tchecks' => $tchecks,'check' => $checkdata));
|
||||
|
||||
renderPage('panel/p_addedit.twig', array('mpage' => 'checks', 'you' => $you, 'type' => 'edit','groups' => $groups,'tchecks' => $tchecks,'check' => $checkdata));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -144,8 +145,7 @@ switch($page){
|
||||
'checks' => $countchk
|
||||
);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_groups.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
||||
renderPage('panel/p_groups.twig', array('you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
||||
break;
|
||||
|
||||
case 'addgroup':
|
||||
@@ -186,8 +186,7 @@ switch($page){
|
||||
->text($result['text']);
|
||||
$news[$ID_N]['mdtext'] = $result['text']; //Raw text
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_news.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
||||
renderPage('panel/p_news.twig', array('you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
||||
break;
|
||||
|
||||
case 'newnews':
|
||||
@@ -218,8 +217,7 @@ switch($page){
|
||||
while ($syso = dbw_fetch_array($db_conn,$results)){
|
||||
$sys[$syso['option']] = $syso['value'];
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_settings.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
||||
renderPage('panel/p_settings.twig', array('you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
||||
break;
|
||||
|
||||
case 'users':
|
||||
@@ -233,8 +231,7 @@ switch($page){
|
||||
'fullrights' => $us['fullRights']
|
||||
);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_users.twig', array('T_' => $T_, 'mpage' => 'users', 'you' => $you, 'users' => $user));
|
||||
renderPage('panel/p_users.twig', array('mpage' => 'users', 'you' => $you, 'users' => $user));
|
||||
break;
|
||||
|
||||
case 'adduser':
|
||||
@@ -271,6 +268,32 @@ switch($page){
|
||||
header('Location: panel.php?page=users');
|
||||
break;
|
||||
|
||||
|
||||
//History of checks for a ID_C
|
||||
case 'viewhist':
|
||||
//All page data
|
||||
$ID_C = (int)$_GET['ID_C'];
|
||||
$page = dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'");
|
||||
$cant = 100;
|
||||
$results = dbw_query($db_conn,"SELECT * FROM CHKHIST WHERE ID_C='$ID_C' ORDER BY `timestamp` DESC LIMIT $cant");
|
||||
|
||||
//TODO TIMESTAMPS FAILS
|
||||
$cgood = 0;$cbad = 0; $fails = array();
|
||||
while ($us = dbw_fetch_array($db_conn,$results)){
|
||||
if ($us['code'] == 0){
|
||||
$cgood++;
|
||||
}else{
|
||||
$cbad++;
|
||||
$fails[] = date('d/m/Y H:i',$us['timestamp']); //Record timestamps
|
||||
}
|
||||
}
|
||||
|
||||
$group = nameGroupFromIDG(IDGFromIDC($ID_C));
|
||||
$pagedata = array('cgood' => $cgood,'cbad' => $cbad,'name' => nameFromIDC($db_conn,$ID_C), 'group' => $group,'cant' => $cant,'fails' => $fails);
|
||||
|
||||
renderPage('panel/p_viewhist.twig', array('mpage' => 'viewhist', 'you' => $you,'pagedata' => $pagedata));
|
||||
break;
|
||||
|
||||
// Página principal
|
||||
case 'status':
|
||||
default:
|
||||
@@ -283,8 +306,9 @@ switch($page){
|
||||
if ($failssql != false){
|
||||
while ($fail = dbw_fetch_array($db_conn,$failssql)){ //Create array
|
||||
$fails[] = array (
|
||||
'name' => nameFromIDC($db_conn,$fail['ID_C']),
|
||||
'groupName' => nameGroupFromIDG($db_conn,IDGFromIDC($db_conn,$fail['ID_C'])),
|
||||
'ID_C' => $fail['ID_C'],
|
||||
'name' => nameFromIDC($fail['ID_C']),
|
||||
'groupName' => nameGroupFromIDG(IDGFromIDC($fail['ID_C'])),
|
||||
'typeCheck' => textTypeChk($T_,$fail['ID_TC']),
|
||||
'errorText' => $fail['errorText'],
|
||||
'date' => date('j/n/Y',$fail['timestamp']),
|
||||
@@ -295,7 +319,7 @@ switch($page){
|
||||
$fails = array(); //Empty
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_index.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render
|
||||
renderPage('panel/p_index.twig', array('you' => $you, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
24
updater.php
24
updater.php
@@ -1,7 +1,14 @@
|
||||
<?php
|
||||
echo "<h2>Updater of CheckServer</h2>";
|
||||
echo "<p>Connecting to database</p>";
|
||||
require_once 'connect.php';
|
||||
require_once 'lib/dbwrapper.php';
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (!is_file($db_file)){ //Go to install if not.
|
||||
header("Location: install.php");
|
||||
die();
|
||||
}
|
||||
$db_conn = dbw_connect("sqlite",$db_file); //Database
|
||||
|
||||
$version = dbw_query_fetch_array($db_conn,"SELECT value FROM SYS WHERE option = 'version'")[0];
|
||||
echo "<p>Your version: ".$version;
|
||||
echo "<p>Updating to lastest</p>";
|
||||
@@ -11,11 +18,12 @@ switch ($version){
|
||||
dbw_query($db_conn,"DELETE FROM SYS WHERE option='maxChecksSave'");
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES('maxTimeSave',14)");
|
||||
//Can not delete USERS.SessionID because sqlite3 not supports it, but doesn't do any harm.
|
||||
|
||||
case '0.9.1':
|
||||
echo "0.9.1-Lastest";
|
||||
dbw_query($db_conn,"UPDATE SYS SET value='0.9.1' WHERE option='version'");
|
||||
case '0.9.1': //No db updates
|
||||
echo "<p>0.9.1->0.9.2<p>";
|
||||
dbw_query($db_conn,"UPDATE SYS SET value='0.9.2' WHERE option='version'");
|
||||
case '0.9.2':
|
||||
echo "0.9.2-Lastest";
|
||||
echo "<p>Updated to lastest. Close this and go to index</p>";
|
||||
//Remove files on a good update
|
||||
unlink('updater.php');
|
||||
unlink('installer.php');
|
||||
}
|
||||
echo "<p>Remember to delete updater.php and install.php for security!</p>"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user