mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-16 02:01:34 +01:00
Fixing cronchk and adding JSON API check (WIP)
This commit is contained in:
@@ -39,13 +39,17 @@ For finishing it, you have to add a cron in your system for running checks. The
|
|||||||
|
|
||||||
Decompress folder over your installation folder, and run "updater.php",
|
Decompress folder over your installation folder, and run "updater.php",
|
||||||
it will update and say if something goes wrong. Its a good idea to make
|
it will update and say if something goes wrong. Its a good idea to make
|
||||||
a backup of your sqlite.db3 database.
|
a backup of your sqlite.db3 database before updating or data may lost.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
### (WIP) Version 0.9.3
|
### (WIP) Version 0.9.3
|
||||||
|
|
||||||
-TODO: Cleaner code
|
-TODO: New JSON GET/POST check
|
||||||
|
|
||||||
|
-Bugfix in cronchk!
|
||||||
|
|
||||||
|
-A bit cleaner code
|
||||||
|
|
||||||
### Version 0.9.2 (Beta)
|
### Version 0.9.2 (Beta)
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
{# "Switch" type #}
|
{# "Switch" type #}
|
||||||
{% if check.ID_TC == 1 or check.ID_TC == 2 or check.ID_TC == 4 %} {# Ping, HttpCode, SQL DB #}
|
{% if check.ID_TC != 3 %} {# Every except Visits that is different #}
|
||||||
|
|
||||||
{% if check.uptime != -1 %}{#Only if records exists#}
|
{% if check.uptime != -1 %}{#Only if records exists#}
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -21,14 +21,14 @@
|
|||||||
action="?page=savenewcheck"
|
action="?page=savenewcheck"
|
||||||
{%endif%}>
|
{%endif%}>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-2">Nombre</label>
|
<label class="col-sm-2">{{T_.name}}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<input name="name" type="text" placeholder="Nombre del check" value="{{check.name}}" class="form-control form-control-success"><small class="form-text">Nombre del checkeo.</small>
|
<input name="name" type="text" placeholder="Nombre del check" value="{{check.name}}" class="form-control form-control-success"><small class="form-text">Nombre del checkeo.</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-2 form-control-label">Grupo</label>
|
<label class="col-sm-2 form-control-label">{{T_.group}}</label>
|
||||||
<div class="col-sm-10 select">
|
<div class="col-sm-10 select">
|
||||||
<select name="group" id="group" class="form-control">
|
<select name="group" id="group" class="form-control">
|
||||||
{% for group in groups %}
|
{% for group in groups %}
|
||||||
@@ -54,15 +54,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# Aquí empiezan los campos "opcionales" dependiendo del tipo de check #}
|
{# Aquí empiezan los campos "opcionales" dependiendo del tipo de check (Estos vienen de la tabla, al campo) #}
|
||||||
{# Sacar variables #}
|
{# Sacar variables #}
|
||||||
{% if check.ID_TC == 1%}
|
{% if check.ID_TC == 1%}
|
||||||
{% set t1 = check.URL|split(':') %}
|
{% set t1 = check.url|split(':') %}
|
||||||
{% elseif check.ID_TC == 2%}
|
{% elseif check.ID_TC == 2%}
|
||||||
{% set t2_url = check.URL %}
|
{% set t2_url = check.url %}
|
||||||
{% set t2_code = check.TCParam %}
|
{% set t2_code = check.urlParam %}
|
||||||
{% elseif check.ID_TC == 4%}
|
{% elseif check.ID_TC == 4%}
|
||||||
{% set t4_url = check.URL %}
|
{% set t4_url = check.url %}
|
||||||
|
{% elseif check.ID_TC == 5 %}
|
||||||
|
{% set t5_url = check.url %}
|
||||||
|
{% set t5_params = check.urlParam|split('|') %}
|
||||||
|
{% set t5_exceptedRes = check.exceptedRes %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# Trozos de formulario #}
|
{# Trozos de formulario #}
|
||||||
@@ -119,7 +123,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{# Tipo 5 - Json API #}
|
||||||
|
<div id="t5" style="display:none;">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2">JSON</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input name="t5url" type="text" placeholder="URL" value="{{t5_url}}" class="form-control form-control-success"><small class="form-text">URL de la API</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2">Tipo de request</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<select name="t5type" class="form-control">
|
||||||
|
<option value="GET" {%if t5_params[0] == 'GET' %} selected="selected" {%endif%}>GET</option>
|
||||||
|
<option value="POST" {%if t5_params[0] == 'POST' %} selected="selected" {%endif%}>POST</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2">Parametros enviados</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input name="t5params" type="text" placeholder="?params" value="{{t5_params[1]}}" class="form-control form-control-success"><small class="form-text">Parametros de la API (Si es GET, empezar con ? o /)</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-2">Respuesta esperada</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<textarea name="t5exceptedRes" placeholder="Respuesta en formato JSON" class="form-control form-control-success">{{t5_exceptedRes}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-10 offset-sm-2">
|
<div class="col-sm-10 offset-sm-2">
|
||||||
<button type="submit" class="btn btn-primary">Guardar cambios</button>
|
<button type="submit" class="btn btn-primary">Guardar cambios</button>
|
||||||
@@ -135,28 +168,23 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function showOptData(valSel){
|
function showOptData(valSel){
|
||||||
|
document.getElementById("t1").style.display = "none";
|
||||||
|
document.getElementById("t2").style.display = "none";
|
||||||
|
document.getElementById("t3").style.display = "none";
|
||||||
|
document.getElementById("t4").style.display = "none";
|
||||||
|
document.getElementById("t5").style.display = "none";
|
||||||
optVal = valSel.value;
|
optVal = valSel.value;
|
||||||
|
|
||||||
if(optVal == '1'){
|
if(optVal == '1'){
|
||||||
document.getElementById("t1").style.display = "block";
|
document.getElementById("t1").style.display = "block";
|
||||||
document.getElementById("t2").style.display = "none";
|
|
||||||
document.getElementById("t3").style.display = "none";
|
|
||||||
document.getElementById("t4").style.display = "none";
|
|
||||||
}else if(optVal == '2'){
|
}else if(optVal == '2'){
|
||||||
document.getElementById("t1").style.display = "none";
|
|
||||||
document.getElementById("t2").style.display = "block";
|
document.getElementById("t2").style.display = "block";
|
||||||
document.getElementById("t3").style.display = "none";
|
|
||||||
document.getElementById("t4").style.display = "none";
|
|
||||||
}else if(optVal == '3'){
|
}else if(optVal == '3'){
|
||||||
document.getElementById("t1").style.display = "none";
|
|
||||||
document.getElementById("t2").style.display = "none";
|
|
||||||
document.getElementById("t3").style.display = "block";
|
document.getElementById("t3").style.display = "block";
|
||||||
document.getElementById("t4").style.display = "none";
|
}else if(optVal == '4'){
|
||||||
}else {
|
|
||||||
document.getElementById("t1").style.display = "none";
|
|
||||||
document.getElementById("t2").style.display = "none";
|
|
||||||
document.getElementById("t3").style.display = "none";
|
|
||||||
document.getElementById("t4").style.display = "block";
|
document.getElementById("t4").style.display = "block";
|
||||||
|
}else {
|
||||||
|
document.getElementById("t5").style.display = "block";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showOptData(document.getElementById("tcheck"))
|
showOptData(document.getElementById("tcheck"))
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
{% set beforegroup = check.ID_G %}
|
{% set beforegroup = check.ID_G %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{check.name}}</td>
|
<td>{{check.name}}</td>
|
||||||
<td>{{check.nameTCheck}} - {{check.URL}}</td>
|
<td>{{check.nameTCheck}} - {{check.url}}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="?page=viewhist&ID_C={{check.ID_C}}" class="btn btn-info">{{T_.view_hist}}</a>
|
<a href="?page=viewhist&ID_C={{check.ID_C}}" class="btn btn-info">{{T_.view_hist}}</a>
|
||||||
{% if you.fullRights == 1 %}
|
{% if you.fullRights == 1 %}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ define('T_ENGVERSION',1);
|
|||||||
//(indexpage.twig) In index, title
|
//(indexpage.twig) In index, title
|
||||||
$T_['statdif1'] = 'Status of different checks';
|
$T_['statdif1'] = 'Status of different checks';
|
||||||
$T_['name'] = 'Name';
|
$T_['name'] = 'Name';
|
||||||
|
$T_['group'] = 'Group';
|
||||||
$T_['status'] = 'Status';
|
$T_['status'] = 'Status';
|
||||||
$T_['status_uptime'] = 'Status (Uptime)';
|
$T_['status_uptime'] = 'Status (Uptime)';
|
||||||
$T_['failed'] = 'Failed';
|
$T_['failed'] = 'Failed';
|
||||||
@@ -31,11 +32,12 @@ $T_['groups'] = 'Groups';
|
|||||||
$T_['news'] = 'News';
|
$T_['news'] = 'News';
|
||||||
$T_['settings'] = 'Settings';
|
$T_['settings'] = 'Settings';
|
||||||
$T_['users'] = 'Users';
|
$T_['users'] = 'Users';
|
||||||
//[NEXT 4]Check texts
|
//[NEXT 5]Check texts
|
||||||
$T_['PING_IP'] = 'Ping to IP:Port';
|
$T_['PING_IP'] = 'Ping to IP:Port';
|
||||||
$T_['HTTP_CODE'] = 'Http code';
|
$T_['HTTP_CODE'] = 'Http code';
|
||||||
$T_['VISIT_COUNT'] = 'Visit counter';
|
$T_['VISIT_COUNT'] = 'Visit counter';
|
||||||
$T_['DATABASE'] = 'Database check';
|
$T_['DATABASE'] = 'Database check';
|
||||||
|
$T_['JSON_API'] = 'JSON API';
|
||||||
$T_['add_grp_to_add_chk'] = 'Add a group for start adding checks';
|
$T_['add_grp_to_add_chk'] = 'Add a group for start adding checks';
|
||||||
$T_['view_hist'] = 'View history';
|
$T_['view_hist'] = 'View history';
|
||||||
$T_['lastest_fails'] = 'Lastest fails';
|
$T_['lastest_fails'] = 'Lastest fails';
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ define('T_VERSION',1);
|
|||||||
//(indexpage.twig) In index, title
|
//(indexpage.twig) In index, title
|
||||||
$T_['statdif1'] = 'Estado de los diferentes servicios';
|
$T_['statdif1'] = 'Estado de los diferentes servicios';
|
||||||
$T_['name'] = 'Nombre';
|
$T_['name'] = 'Nombre';
|
||||||
|
$T_['group'] = 'Grupo';
|
||||||
$T_['status'] = 'Estado';
|
$T_['status'] = 'Estado';
|
||||||
$T_['status_uptime'] = 'Estado (Uptime)';
|
$T_['status_uptime'] = 'Estado (Uptime)';
|
||||||
$T_['failed'] = 'Erróneo';
|
$T_['failed'] = 'Erróneo';
|
||||||
@@ -31,11 +32,12 @@ $T_['groups'] = 'Grupos';
|
|||||||
$T_['news'] = 'Noticias';
|
$T_['news'] = 'Noticias';
|
||||||
$T_['settings'] = 'Opciones';
|
$T_['settings'] = 'Opciones';
|
||||||
$T_['users'] = 'Usuarios';
|
$T_['users'] = 'Usuarios';
|
||||||
//[NEXT 4]Check texts
|
//[NEXT 5]Check texts
|
||||||
$T_['PING_IP'] = 'Ping a IP:Puerto';
|
$T_['PING_IP'] = 'Ping a IP:Puerto';
|
||||||
$T_['HTTP_CODE'] = 'Código HTTP';
|
$T_['HTTP_CODE'] = 'Código HTTP';
|
||||||
$T_['VISIT_COUNT'] = 'Contador de visitas';
|
$T_['VISIT_COUNT'] = 'Contador de visitas';
|
||||||
$T_['DATABASE'] = 'Conexión a base de datos';
|
$T_['DATABASE'] = 'Conexión a base de datos';
|
||||||
|
$T_['JSON_API'] = 'JSON API';
|
||||||
$T_['add_grp_to_add_chk'] = 'Añade un grupo para empezar a añadir checks';
|
$T_['add_grp_to_add_chk'] = 'Añade un grupo para empezar a añadir checks';
|
||||||
$T_['view_hist'] = 'Ver histórico';
|
$T_['view_hist'] = 'Ver histórico';
|
||||||
$T_['lastest_fails'] = 'Ultimos errores';
|
$T_['lastest_fails'] = 'Ultimos errores';
|
||||||
|
|||||||
52
cronchk.php
52
cronchk.php
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "functions.php";
|
require_once "load.php";
|
||||||
|
|
||||||
function PING_IP($db_conn,$ID_C,$URL){
|
function PING_IP($ID_C,$URL){
|
||||||
if (strpos($URL, ":")){ //Si usa un puerto, dividir
|
if (strpos($URL, ":")){ //Si usa un puerto, dividir
|
||||||
$host = explode(":", $URL)[0];
|
$host = explode(":", $URL)[0];
|
||||||
$port = explode(":", $URL)[1];
|
$port = explode(":", $URL)[1];
|
||||||
@@ -10,7 +10,7 @@ function PING_IP($db_conn,$ID_C,$URL){
|
|||||||
return $result; //Returns result
|
return $result; //Returns result
|
||||||
}
|
}
|
||||||
|
|
||||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param){
|
function HTTP_CODE($ID_C,$URL,$Param){
|
||||||
$httpCode = httpCode($URL); //Code
|
$httpCode = httpCode($URL); //Code
|
||||||
|
|
||||||
$code = (int)$Param != 0 ? $Param : 200; //Establish the code test want to see
|
$code = (int)$Param != 0 ? $Param : 200; //Establish the code test want to see
|
||||||
@@ -23,7 +23,7 @@ function HTTP_CODE($db_conn,$ID_C,$URL,$Param){
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DATABASE_CONN($db_conn,$ID_C,$URL){
|
function DATABASE_CONN($ID_C,$URL){
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $URL);
|
curl_setopt($ch, CURLOPT_URL, $URL);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||||
@@ -39,10 +39,41 @@ function DATABASE_CONN($db_conn,$ID_C,$URL){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WIP, doesnt compare right!
|
||||||
|
function JSON_API($ID_C,$URL,$params,$exceptedRes){
|
||||||
|
$type = explode('|',$params)[0];
|
||||||
|
$JSONParams = explode('|',$params)[1];
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
if ($type == 'GET'){
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $URL . $JSONParams);
|
||||||
|
}else if ($type == 'POST'){
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONParams);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $URL);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 4); //timeout in seconds
|
||||||
|
$body = curl_exec($ch); //All file
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$json_ret = json_decode($body,true);
|
||||||
|
$json_param = json_decode($exceptedRes,true);
|
||||||
|
$comp_ret =serialize($json_ret);
|
||||||
|
$comp_param =serialize($json_param);
|
||||||
|
if ($comp_ret == $comp_param){
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$db_conn = getconn();
|
||||||
$sites = dbw_query($db_conn,"SELECT * FROM CHECKS");
|
$sites = dbw_query($db_conn,"SELECT * FROM CHECKS");
|
||||||
while ($site = dbw_fetch_array($db_conn,$sites)){
|
while ($site = dbw_fetch_array($db_conn,$sites)){
|
||||||
$try = 0;
|
$try = 0;
|
||||||
|
$extitC = 0;
|
||||||
$ID_C= $site['ID_C'];
|
$ID_C= $site['ID_C'];
|
||||||
do {
|
do {
|
||||||
$try++; //This is for avoiding posible "second" problems in some checks that are working but doesn't answer to first time
|
$try++; //This is for avoiding posible "second" problems in some checks that are working but doesn't answer to first time
|
||||||
@@ -50,15 +81,19 @@ while ($site = dbw_fetch_array($db_conn,$sites)){
|
|||||||
|
|
||||||
switch ($site['ID_TC']) {
|
switch ($site['ID_TC']) {
|
||||||
case '1': //Ping to IP:Port
|
case '1': //Ping to IP:Port
|
||||||
$exitC = PING_IP($db_conn,$ID_C,$site['URL']);
|
$exitC = PING_IP($ID_C,$site['url']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2': //HttpCode
|
case '2': //HttpCode
|
||||||
$exitC = HTTP_CODE($db_conn,$ID_C,$site['URL'],$site['TCParam']);
|
$exitC = HTTP_CODE($ID_C,$site['url'],$site['urlParam']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '4': //MySQL|Database connect
|
case '4': //MySQL|Database connect
|
||||||
$exitC = DATABASE_CONN($db_conn,$ID_C,$site['URL']);
|
$exitC = DATABASE_CONN($ID_C,$site['url']);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '5': //JSON GET | POST
|
||||||
|
$exitC = JSON_API($ID_C,$site['url'],$site['urlParam'],$site['exceptedRes']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while($try <= 2 && $exitC == 1);
|
}while($try <= 2 && $exitC == 1);
|
||||||
@@ -71,12 +106,11 @@ while ($site = dbw_fetch_array($db_conn,$sites)){
|
|||||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`errorText`,`timestamp`) VALUES ('$ID_C','1','$exitC','$timestamp')");
|
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`errorText`,`timestamp`) VALUES ('$ID_C','1','$exitC','$timestamp')");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Delete old Checks (Based on time to save, put in secs)
|
//Delete old Checks (Based on time to save, put in secs)
|
||||||
$mintime = time()-(getSystemOpt($db_conn,"maxTimeSave")*24*3600);
|
$mintime = time()-(getSystemOpt("maxTimeSave")*24*3600);
|
||||||
dbw_query($db_conn,"DELETE FROM CHKHIST WHERE `timestamp` < $mintime");
|
dbw_query($db_conn,"DELETE FROM CHKHIST WHERE `timestamp` < $mintime");
|
||||||
|
|
||||||
//Delete Checks stored for pages that not exist
|
//Delete Checks stored for pages that not exist
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ function getSystemOpt($sysopt){
|
|||||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
return dbw_query_fetch_array(getconn(),"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return HttpCode of page. Returns false if page is not found */
|
/** Return HttpCode of page. Returns false if page is not found (Used in cron) */
|
||||||
function httpCode($url, $wait = 5)
|
function httpCode($url, $wait = 5)
|
||||||
{
|
{
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
@@ -127,7 +127,7 @@ function nameFromIDC($ID_C){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nameGroupFromIDG($ID_G){
|
function nameGroupFromIDG($ID_G){
|
||||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
return dbw_query_fetch_array(getconn(),"SELECT ID_G,name FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function IDGFromIDC($ID_C){
|
function IDGFromIDC($ID_C){
|
||||||
@@ -137,19 +137,22 @@ function IDGFromIDC($ID_C){
|
|||||||
/* This funtion returns the array with type of checks */
|
/* This funtion returns the array with type of checks */
|
||||||
function arrayTypeChk(){
|
function arrayTypeChk(){
|
||||||
return array(
|
return array(
|
||||||
'1' => 'PING_IP',
|
1 => 'PING_IP',
|
||||||
'2' => 'HTTP_CODE',
|
2 => 'HTTP_CODE',
|
||||||
'3' => 'VISIT_COUNT',
|
3 => 'VISIT_COUNT',
|
||||||
'4' => 'DATABASE');
|
4 => 'DATABASE',
|
||||||
|
5 => 'JSON_API');
|
||||||
}
|
}
|
||||||
/* This funtion returns the translated text of a type check */
|
/* This funtion returns the translated text of a type check */
|
||||||
function textTypeChk($typeChk){
|
function textTypeChk($typeChk){
|
||||||
$T_ = loadLang();
|
$T_ = loadLang();
|
||||||
$arr = array(
|
$arr = array(
|
||||||
'1' => $T_['PING_IP'],
|
1 => $T_['PING_IP'],
|
||||||
'2' => $T_['HTTP_CODE'],
|
2 => $T_['HTTP_CODE'],
|
||||||
'3' => $T_['VISIT_COUNT'],
|
3 => $T_['VISIT_COUNT'],
|
||||||
'4' => $T_['DATABASE']);
|
4 => $T_['DATABASE'],
|
||||||
|
5 => $T_['JSON_API']
|
||||||
|
);
|
||||||
return $arr[$typeChk];
|
return $arr[$typeChk];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){
|
|||||||
$ID_TC = $chks[$idchk]['ID_TC']; //Type of Check
|
$ID_TC = $chks[$idchk]['ID_TC']; //Type of Check
|
||||||
|
|
||||||
switch ($ID_TC){
|
switch ($ID_TC){
|
||||||
// Case 1 and 2 are normal status, case 3 (Visits) is numeric, not status
|
// Case 3 (Visits) is numeric, not status
|
||||||
case 1: //Ping
|
case 1: //Ping
|
||||||
case 2: //HttpCode
|
case 2: //HttpCode
|
||||||
case 4: //MySQL
|
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)
|
//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){
|
if (dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' LIMIT 1")[0] != 0){
|
||||||
|
|||||||
10
install.php
10
install.php
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
define('VERSION','0.9.2');
|
define('VERSION','0.9.3');
|
||||||
//define('INSTALLER_MODE','1');
|
//define('INSTALLER_MODE','1');
|
||||||
require_once 'lib/loadTwig.php';
|
require_once 'lib/loadTwig.php';
|
||||||
|
|
||||||
@@ -63,16 +63,17 @@ CREATE TABLE "CHECKS" (
|
|||||||
`ID_C` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`ID_C` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`ID_G` INTEGER,
|
`ID_G` INTEGER,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
`URL` TEXT,
|
`url` TEXT,
|
||||||
`manStatus` INTEGER,
|
`manStatus` INTEGER,
|
||||||
`ID_TC` INTEGER,
|
`ID_TC` INTEGER,
|
||||||
`TCParam` TEXT,
|
`urlParam` TEXT,
|
||||||
|
`exceptedRes` TEXT,
|
||||||
FOREIGN KEY(`ID_G`) REFERENCES `GROUPS`(`ID_G`),
|
FOREIGN KEY(`ID_G`) REFERENCES `GROUPS`(`ID_G`),
|
||||||
FOREIGN KEY(`ID_TC`) REFERENCES `TYPECHK`(`ID_TC`)
|
FOREIGN KEY(`ID_TC`) REFERENCES `TYPECHK`(`ID_TC`)
|
||||||
);
|
);
|
||||||
COMMIT;';
|
COMMIT;';
|
||||||
dbw_multi_query($db_conn,$sqlcreate); //Create scheme
|
dbw_multi_query($db_conn,$sqlcreate); //Create scheme
|
||||||
$user = $_POST[username];
|
$user = $_POST['username'];
|
||||||
$pass = hash("sha256",$_POST['passw1']);
|
$pass = hash("sha256",$_POST['passw1']);
|
||||||
dbw_query($db_conn,"INSERT INTO USERS (nick,passw,fullRights) VALUES('$user','$pass',1)"); //Create user
|
dbw_query($db_conn,"INSERT INTO USERS (nick,passw,fullRights) VALUES('$user','$pass',1)"); //Create user
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ COMMIT;';
|
|||||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('lang','$_POST[lang]')");
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('lang','$_POST[lang]')");
|
||||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('websiteTitle','Status')");
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('websiteTitle','Status')");
|
||||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('version','".VERSION."')");
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('version','".VERSION."')");
|
||||||
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maintenance','0')");
|
||||||
|
|
||||||
echo $twig->render('install.twig', array('part' => 2));
|
echo $twig->render('install.twig', array('part' => 2));
|
||||||
}
|
}
|
||||||
|
|||||||
5
load.php
5
load.php
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'functions.php'; //Preloads functions
|
require_once 'functions.php'; //Preloads functions
|
||||||
require_once 'lib/dbwrapper.php';
|
require_once 'lib/dbwrapper.php';
|
||||||
define('VERSION','0.9.2');
|
define('VERSION','0.9.3');
|
||||||
session_start(); //Session in all page
|
session_start(); //Session in all page
|
||||||
//Preload file
|
//Preload file
|
||||||
//This function loads all things needed, with optional db things if needed
|
//This function loads all things needed, with optional db things if needed
|
||||||
@@ -35,4 +35,7 @@ define('LANG', getSystemOpt('lang'));
|
|||||||
if (getSystemOpt('version') != VERSION){
|
if (getSystemOpt('version') != VERSION){
|
||||||
die("<p>Please run updater.php to update before using page");
|
die("<p>Please run updater.php to update before using page");
|
||||||
}
|
}
|
||||||
|
if (getSystemOpt('maintenance') == '1'){
|
||||||
|
die("<p>CheckStatus is in maintenance mode, wait for admin to disable maintenance mode</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
33
panel.php
33
panel.php
@@ -18,7 +18,7 @@ if (in_array($page,$arrPagesFullRigths) && $you['fullRights'] != 1){
|
|||||||
|
|
||||||
switch($page){
|
switch($page){
|
||||||
case 'notperm':
|
case 'notperm':
|
||||||
echo $twig->render('panel/p_notperm.twig', array('T_' => $T_, 'you' => $you));
|
renderPage('panel/p_notperm.twig', array('you' => $you));
|
||||||
break;
|
break;
|
||||||
case 'checks':
|
case 'checks':
|
||||||
//Groups (For "fast-change-group option in html")
|
//Groups (For "fast-change-group option in html")
|
||||||
@@ -90,18 +90,29 @@ switch($page){
|
|||||||
$ID_G = $_POST['group'];
|
$ID_G = $_POST['group'];
|
||||||
$ID_TC = $_POST['tcheck'];
|
$ID_TC = $_POST['tcheck'];
|
||||||
//Datos que dependen del tipo de check
|
//Datos que dependen del tipo de check
|
||||||
if ($ID_TC == 1){
|
switch ($ID_TC){
|
||||||
$URL = $_POST['t1url'] . ':' . $_POST['t1port'];
|
case 1:
|
||||||
dbw_query($db_conn,"UPDATE CHECKS SET URL='$URL' WHERE ID_C='$ID_C'");
|
$url = $_POST['t1url'] . ':' . $_POST['t1port'];
|
||||||
}elseif ($ID_TC == 2){
|
dbw_query($db_conn,"UPDATE CHECKS SET url='$url' WHERE ID_C='$ID_C'");
|
||||||
$URL = $_POST['t2url'];
|
break;
|
||||||
$TCParam = isset($_POST['t2code']) ? $_POST['t2code'] : '';
|
case 2:
|
||||||
dbw_query($db_conn,"UPDATE CHECKS SET URL='$URL',TCParam = '$TCParam' WHERE ID_C='$ID_C'");
|
$url = $_POST['t2url'];
|
||||||
}elseif ($ID_TC == 4){
|
$urlParam = isset($_POST['t2code']) ? $_POST['t2code'] : '';
|
||||||
$URL = $_POST['t4url'];
|
dbw_queryurl($db_conn,"UPDATE CHECKS SET url='$url',urlParam = '$urlParam' WHERE ID_C='$ID_C'");
|
||||||
dbw_query($db_conn,"UPDATE CHECKS SET URL='$URL' WHERE ID_C='$ID_C'");
|
break;
|
||||||
|
case 4:
|
||||||
|
$url = $_POST['t4url'];
|
||||||
|
dbw_query($db_conn,"UPDATE CHECKS SET url='$url' WHERE ID_C='$ID_C'");
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$url = $_POST['t5url'];
|
||||||
|
$urlParam = dbw_escape_string($db_conn,$_POST['t5type'].'|'.$_POST['t5params']);
|
||||||
|
$exceptedRes = dbw_escape_string($db_conn,$_POST['t5exceptedRes']);
|
||||||
|
dbw_query($db_conn,"UPDATE CHECKS SET url='$url', urlParam='$urlParam',exceptedRes='$exceptedRes' WHERE ID_C='$ID_C'");
|
||||||
|
break;
|
||||||
}//Si es 3 no hay datos que guardar (de momento)
|
}//Si es 3 no hay datos que guardar (de momento)
|
||||||
|
|
||||||
|
|
||||||
//Guardamos el resto de datos
|
//Guardamos el resto de datos
|
||||||
dbw_query($db_conn,"UPDATE CHECKS SET name='$name', ID_G='$ID_G', ID_TC='$ID_TC' WHERE ID_C='$ID_C'");
|
dbw_query($db_conn,"UPDATE CHECKS SET name='$name', ID_G='$ID_G', ID_TC='$ID_TC' WHERE ID_C='$ID_C'");
|
||||||
|
|
||||||
|
|||||||
36
updater.php
36
updater.php
@@ -8,7 +8,7 @@ if (!is_file($db_file)){ //Go to install if not.
|
|||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
$db_conn = dbw_connect("sqlite",$db_file); //Database
|
$db_conn = dbw_connect("sqlite",$db_file); //Database
|
||||||
|
dbw_query($db_conn,"UPDATE SYS SET value='1' WHERE option='maintenance'");
|
||||||
$version = dbw_query_fetch_array($db_conn,"SELECT value FROM SYS WHERE option = 'version'")[0];
|
$version = dbw_query_fetch_array($db_conn,"SELECT value FROM SYS WHERE option = 'version'")[0];
|
||||||
echo "<p>Your version: ".$version;
|
echo "<p>Your version: ".$version;
|
||||||
echo "<p>Updating to lastest</p>";
|
echo "<p>Updating to lastest</p>";
|
||||||
@@ -18,12 +18,34 @@ switch ($version){
|
|||||||
dbw_query($db_conn,"DELETE FROM SYS WHERE option='maxChecksSave'");
|
dbw_query($db_conn,"DELETE FROM SYS WHERE option='maxChecksSave'");
|
||||||
dbw_query($db_conn,"INSERT INTO SYS VALUES('maxTimeSave',14)");
|
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.
|
//Can not delete USERS.SessionID because sqlite3 not supports it, but doesn't do any harm.
|
||||||
dbw_query($db_conn,"UPDATE SYS SET value='0.9.1' WHERE option='version'");
|
case '0.9.1':
|
||||||
case '0.9.1': //No db updates
|
echo "<p>0.9.1->0.9.2</p>";
|
||||||
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':
|
case '0.9.2':
|
||||||
echo "0.9.2-Lastest";
|
echo "<p>0.9.2->0.9.3</p>";
|
||||||
|
dbw_query($db_conn,'ALTER TABLE CHECKS RENAME TO CHECKS_orig;');
|
||||||
|
dbw_query($db_conn,'
|
||||||
|
CREATE TABLE "CHECKS" (
|
||||||
|
`ID_C` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`ID_G` INTEGER,
|
||||||
|
`ID_TC` INTEGER,
|
||||||
|
`name` TEXT NOT NULL,
|
||||||
|
`url` TEXT,
|
||||||
|
`manStatus` INTEGER,
|
||||||
|
`urlParam` TEXT,
|
||||||
|
`exceptedRes` TEXT,
|
||||||
|
FOREIGN KEY(`ID_G`) REFERENCES `GROUPS`(`ID_G`),
|
||||||
|
FOREIGN KEY(`ID_TC`) REFERENCES `TYPECHK`(`ID_TC`)
|
||||||
|
);
|
||||||
|
');
|
||||||
|
dbw_query($db_conn,"INSERT INTO CHECKS(ID_C, ID_G,ID_TC,name,url,manStatus,urlParam) SELECT ID_C,ID_G,ID_TC,name,URL,manStatus,TCParam FROM CHECKS_orig;");
|
||||||
|
dbw_query($db_conn,"DROP TABLE CHECKS_orig");
|
||||||
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maintenance','1')"); //New system opt
|
||||||
|
|
||||||
|
case '0.9.3':
|
||||||
|
dbw_query($db_conn,"UPDATE SYS SET value='0.9.3' WHERE option='version'");
|
||||||
|
dbw_query($db_conn,"UPDATE SYS SET value='0' WHERE option='maintenance'");
|
||||||
|
|
||||||
|
echo "0.9.3-Lastest";
|
||||||
echo "<p>Updated to lastest. Close this and go to index</p>";
|
echo "<p>Updated to lastest. Close this and go to index</p>";
|
||||||
echo "<p>Remember to delete updater.php and install.php for security!</p>"
|
echo "<p>Remember to delete updater.php and install.php for security!</p>";
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user