mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-24 14:03:48 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97ac06b224 | |||
| 9e4982c838 | |||
| 1efecc2633 | |||
| a91347ca46 | |||
| 3547695245 | |||
| 0aeaada922 | |||
| 5e33adbbaf | |||
| 42583d198e | |||
| cb20328a6a | |||
| f1b58a03f3 | |||
| 8b86e38361 | |||
| 374bd97a91 | |||
| 3ded2a052c | |||
| 0e13bfc91a | |||
| 446102796f | |||
| a44f87cea4 | |||
|
|
344f837c30 | ||
|
|
1be1751a3d |
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#Database file
|
||||||
|
sqlite.db3
|
||||||
|
|
||||||
|
#Well known (Other)
|
||||||
|
**/.well-known/
|
||||||
51
README.md
51
README.md
@@ -5,27 +5,26 @@ without dependencies and installable only coping repository and ajusting some pa
|
|||||||
|
|
||||||
Also can show stadistics for all sites
|
Also can show stadistics for all sites
|
||||||
|
|
||||||
Demo can be viewed in https://status.jkanetwork.com/
|
Real using index 'demo' can be viewed in https://status.jkanetwork.com/
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
This is an beta, opensource, and human made program. **There may be bugs and problems**, and
|
This is an beta, opensource, and a human made program. **There may be bugs and problems**, and
|
||||||
although we can help or fix things, JKANetwork is **not** responsable for derivated problems.
|
although we can update and fix things, JKANetwork is **not** responsable for derivated problems.
|
||||||
|
|
||||||
You can see the master code and tell us any improvment or bug. Plase see indications for installing if you want
|
You can see the master code and tell us any improvment or bug. Plase see indications for installing if you want
|
||||||
to install instead of downloading master and install, that it will not work right. Master is like beta, and tags its like releases.
|
to install without problems. Master is bleeding edge, use tags for versions and not having problems.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
-Modern PHP (5.6+) with SQLite enabled
|
-Modern PHP (5.6+) with SQLite3 enabled
|
||||||
|
|
||||||
-Cron support
|
-Cron support
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
For installing, only download last version from https://gitlab.com/JKANetwork/CheckServer/tags (not git master, reason
|
For installing, only download last version from https://gitlab.com/JKANetwork/CheckServer/tags (not git master, reason
|
||||||
below. **Think of tags as releases**)
|
below. **Think of tags as releases**), decompress it and copy all to the folder in your hosting.
|
||||||
, decompress it and copy all to the folder in your hosting.
|
|
||||||
|
|
||||||
Please **do not download and use master git**,it is not recommended, because is for devel and things like installer sql can not work right. Use the tags. **Think of tags as releases**
|
Please **do not download and use master git**,it is not recommended, because is for devel and things like installer sql can not work right. Use the tags. **Think of tags as releases**
|
||||||
|
|
||||||
@@ -36,16 +35,46 @@ For finishing it, you have to add a cron in your system for running checks. The
|
|||||||
*/5 * * * * root cd /srv/http/checkserver/ && /usr/bin/php -f cronchk.php >/dev/null 2>&1
|
*/5 * * * * root cd /srv/http/checkserver/ && /usr/bin/php -f cronchk.php >/dev/null 2>&1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Update
|
||||||
|
|
||||||
|
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
|
||||||
|
a backup of your sqlite.db3 database before updating or data may lost.
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
### (NEXT) Version 0.9.1 (Beta)
|
### (WIP) Version 0.9.4
|
||||||
|
|
||||||
-TODO: See uptime percent
|
-TODO: Fix JSON GET/POST Check (Only add part works)
|
||||||
|
|
||||||
-TODO: Better index admin page (More data)
|
### Version 0.9.3 (Beta)
|
||||||
|
|
||||||
|
-New JSON GET/POST Check
|
||||||
|
|
||||||
|
-Bugfix in cronchk!
|
||||||
|
|
||||||
|
-A bit 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)
|
||||||
|
|
||||||
|
-See uptime percent
|
||||||
|
|
||||||
|
-Optimized index webpage, times went down to half when have a lot of pages
|
||||||
|
|
||||||
### Version 0.9 (Beta)
|
### Version 0.9 (Beta)
|
||||||
|
|
||||||
-First public version
|
-First public version
|
||||||
|
|
||||||
-Supports ping at different ports, httpcode returns (default or custom), and MySQL/sqlite/PgSQL status. Also you can post news to index, and have a (invisible) visit counter of visits in your webpages.
|
-Supports ping at different ports, httpcode returns (default or custom), and MySQL/sqlite/PgSQL status. Also you can post news to index, and have a (invisible) visit counter of visits in your webpages.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<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>
|
||||||
<div class="col-sm-6 text-right">
|
<div class="col-sm-6 text-right">
|
||||||
<p>Design by <a href="https://bootstrapious.com" class="external">Bootstrapious</a></p>
|
<p>Design by <a href="https://bootstrapious.com" class="external">Bootstrapious</a></p>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<!--<th>#</th>-->
|
<!--<th>#</th>-->
|
||||||
<th>{{T_.name}}</th>
|
<th>{{T_.name}}</th>
|
||||||
<th>{{T_.status}}</th>
|
<th>{{T_.status_uptime}}</th>
|
||||||
<th>{{T_.last_check}}</th>
|
<th>{{T_.last_check}}</th>
|
||||||
<th>{{T_.last_err}}</th>
|
<th>{{T_.last_err}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -30,45 +30,31 @@
|
|||||||
|
|
||||||
|
|
||||||
{# "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#}
|
||||||
<td>
|
<td>
|
||||||
{#IF/SWITCH status text#}
|
<span class='{{check.statusColor}}' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{check.statusText}}</span>
|
||||||
{%if check.status == 0%}
|
({{ check.uptime}}%)
|
||||||
<span class='green' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_right}}</span>
|
</td>
|
||||||
{%elseif check.status == 1%}
|
<td>
|
||||||
<span class='blue' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_lproblems}}</span>
|
{{check.dateLastChk}} -
|
||||||
{%elseif check.status == 2%}
|
{% if check.failedLastChk == 0 %}
|
||||||
<span class='orange' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_problems}}</span>
|
<span style="color:green">{{T_.status_right}}</span>
|
||||||
{%elseif check.status == 3%}
|
{% else %}
|
||||||
<span class='red' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_outofserv}}</span>
|
<span style="color:red">{{T_.failed}}</span>
|
||||||
{%elseif check.status == 4%}
|
{% endif %}
|
||||||
<span class='blue' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_maintenance}}</span>
|
</td>
|
||||||
{%else%}
|
{%else%} {#If not records yet#}
|
||||||
<span class='grey' data-tooltip='Type of check: {{check.nameCheck}}' data-tooltip-position='top'>{{T_.status_empty}}</span>
|
<td colspan="2">Dame tiempo para recopilar estadísticas</td>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
{#END IF/SWITCH#}
|
<td>
|
||||||
|
{%if check.dateLastErr is not null%}
|
||||||
|
{{check.dateLastErr}}
|
||||||
|
{%else%}
|
||||||
|
{{T_.no_errs}}
|
||||||
|
{%endif%}
|
||||||
</td>
|
</td>
|
||||||
{% if check.status is defined %}{#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>
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if check.ID_TC == 3 %}
|
{% if check.ID_TC == 3 %}
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
|
|||||||
@@ -29,4 +29,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
{% include 'footer.twig' %}
|
||||||
@@ -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,12 +36,13 @@
|
|||||||
{% 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>
|
||||||
{% if you.fullRights == 1 %}
|
{% if you.fullRights == 1 %}
|
||||||
<a href="?page=editcheck&ID_C={{check.ID_C}}" class="btn btn-primary">{{T_.edit}}</a>
|
<a href="?page=editcheck&ID_C={{check.ID_C}}" class="btn btn-primary">{{T_.edit}}</a>
|
||||||
{% if check.ID_TC == 3 %}{#Visitas#}
|
{% if check.ID_TC == 3 %}{#Visitas#}
|
||||||
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#countercode_{{check.ID_C}}">Código del contador</button>
|
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#countercode_{{check.ID_C}}">Código del contador</button>
|
||||||
|
|
||||||
{% elseif check.ID_TC == 4 %}{#Database#}
|
{% elseif check.ID_TC == 4 %}{#Database#}
|
||||||
<a href="#" data-toggle="modal" data-target="#dbcode_{{check.ID_C}}" class="btn btn-info">Codigo para check database</a>
|
<a href="#" data-toggle="modal" data-target="#dbcode_{{check.ID_C}}" class="btn btn-info">Codigo para check database</a>
|
||||||
@@ -187,18 +188,38 @@ var SiteID={{check.ID_C}};
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<h3>Datos de la conexión (Para generar el fichero)</h3>
|
<h3>Datos de la conexión (Para generar el fichero)</h3>
|
||||||
<p>Tipo de base de datos:
|
<p>Tipo de base de datos:
|
||||||
<select name="dbcode_type">
|
<select id="dbcode_type" name="dbcode_type" onchange="showOptD(this);">
|
||||||
<option value="sqlite3">SQLite3</option>
|
<option value="sqlite3">SQLite3</option>
|
||||||
<option value="mysqli">MySql</option>
|
<option value="mysqli">MySql</option>
|
||||||
<option value="pgsql">PostgreSQL</option>
|
<option value="pgsql">PostgreSQL</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<p><small>En Sqlite3 solo hay que rellenar en host la ubicación de la base de datos, nada más</small></p>
|
<p><small>En sqlite, el host es la ubicación relativa al fichero</small></p>
|
||||||
<p>Host (Usualmente localhost): <input type="text" name="dbcode_host" placeholder="Host" /></p>
|
<p>Host (Usualmente localhost): <input type="text" name="dbcode_host" placeholder="Host" /></p>
|
||||||
<p>Usuario bd<input type="text" name="dbcode_user" placeholder="Usuario" /></p>
|
<p id="userBD">Usuario bd<input type="text" name="dbcode_user" placeholder="Usuario" /></p>
|
||||||
<p>Contraseña bd<input type="pass" name="dbcode_pass" placeholder="Contraseña" /></p>
|
<p id="passBD">Contraseña bd<input type="password" name="dbcode_pass" placeholder="Contraseña" /></p>
|
||||||
<p>Base de datos<input type="text" name="dbcode_db" placeholder="Base de datos" /></p>
|
<p id="baseBD">Base de datos<input type="text" name="dbcode_db" placeholder="Base de datos" /></p>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Script for showing options -->
|
||||||
|
<script>
|
||||||
|
function showOptD(valSel){
|
||||||
|
optVal = valSel.value;
|
||||||
|
if(optVal == 'sqlite3'){
|
||||||
|
document.getElementById("userBD").style.display = "none";
|
||||||
|
document.getElementById("passBD").style.display = "none";
|
||||||
|
document.getElementById("baseBD").style.display = "none";
|
||||||
|
}else if(optVal == 'mysqli'){
|
||||||
|
document.getElementById("userBD").style.display = "block";
|
||||||
|
document.getElementById("passBD").style.display = "block";
|
||||||
|
document.getElementById("baseBD").style.display = "none";
|
||||||
|
}else if(optVal == 'pgsql'){
|
||||||
|
document.getElementById("userBD").style.display = "block";
|
||||||
|
document.getElementById("passBD").style.display = "block";
|
||||||
|
document.getElementById("baseBD").style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showOptD(document.getElementById("dbcode_type"))
|
||||||
|
</script>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="submit" class="btn btn-primary">Enviar y descargar php</button>
|
<button type="submit" class="btn btn-primary">Enviar y descargar php</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -227,4 +248,4 @@ var SiteID={{check.ID_C}};
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{% include 'footer.twig' %}
|
{% include 'footer.twig' %}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<div class="wrapper recent-updated">
|
<div class="wrapper recent-updated">
|
||||||
<div id="new-updates" class="card-header d-flex justify-content-between align-items-center">
|
<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>
|
||||||
<div id="upadtes-box" role="tabpanel" class="collapse show">
|
<div id="upadtes-box" role="tabpanel" class="collapse show">
|
||||||
<ul class="news list-unstyled">
|
<ul class="news list-unstyled">
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
<li class="d-flex justify-content-between">
|
<li class="d-flex justify-content-between">
|
||||||
<div class="left-col d-flex">
|
<div class="left-col d-flex">
|
||||||
<div class="icon"><i class="icon-times"></i></div>
|
<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>
|
<p>{{fail.typeCheck}}</p>
|
||||||
</div>
|
</a></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="right-col text-right">
|
<div class="right-col text-right">
|
||||||
<div class="update-date">{{fail.date}}<span class="month">{{fail.hour}}</span></div>
|
<div class="update-date">{{fail.date}}<span class="month">{{fail.hour}}</span></div>
|
||||||
|
|||||||
@@ -10,18 +10,18 @@
|
|||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
<form class="form-horizontal" method="POST" action="?page=saveopts">
|
<form class="form-horizontal" method="POST" action="?page=savesettings">
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-2">Nombre de la web</label>
|
<label class="col-sm-2">Nombre de la web</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<input name="name" type="text" placeholder="Nombre del check" value="{{sys.name}}" class="form-control form-control-success"><small class="form-text">Nombre para sacar en titulos.</small>
|
<input name="name" type="text" placeholder="Nombre de la web" value="{{sys.name}}" class="form-control form-control-success"><small class="form-text">Nombre para sacar en titulos.</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-2">Cantidad de resultados (Individuales) a guardar en historial por cada check</label>
|
<label class="col-sm-2">Cantidad de tiempo a guardar historial de resultados en días.</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<input name="maxChecksSave" type="numeric" placeholder="Nombre del check" value="{{sys.maxChecksSave}}" class="form-control form-control-success"><small class="form-text">300 es un buen numero</small>
|
<input name="maxTimeSave" type="numeric" placeholder="Nombre del check" value="{{sys.maxTimeSave}}" class="form-control form-control-success"><small class="form-text">Por defecto, dos semanas</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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' %}
|
||||||
@@ -5,7 +5,9 @@ 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_['failed'] = 'Failed';
|
$T_['failed'] = 'Failed';
|
||||||
$T_['last_check'] = 'Last check';
|
$T_['last_check'] = 'Last check';
|
||||||
$T_['last_err'] = 'Last error';
|
$T_['last_err'] = 'Last error';
|
||||||
@@ -30,10 +32,13 @@ $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_['lastest_fails'] = 'Lastest fails';
|
||||||
?>
|
?>
|
||||||
@@ -5,7 +5,9 @@ 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_['failed'] = 'Erróneo';
|
$T_['failed'] = 'Erróneo';
|
||||||
$T_['last_check'] = 'Última comprobación';
|
$T_['last_check'] = 'Última comprobación';
|
||||||
$T_['last_err'] = 'Último error';
|
$T_['last_err'] = 'Último error';
|
||||||
@@ -30,10 +32,13 @@ $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_['lastest_fails'] = 'Ultimos errores';
|
||||||
?>
|
?>
|
||||||
33
connect.php
33
connect.php
@@ -1,33 +0,0 @@
|
|||||||
<?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
|
|
||||||
|
|
||||||
/** In connect.php check if user SessionID exists, if not, delete Cookie */
|
|
||||||
if (isset($_COOKIE['SessionID'])){
|
|
||||||
$data = dbw_query_fetch_array($db_conn, "SELECT * FROM USERS WHERE SessionID='$_COOKIE[SessionID]'");
|
|
||||||
if (!isset($data['SessionID'])){
|
|
||||||
setcookie("SessionID", "", time()-3600,"/");
|
|
||||||
header("Location: index.php");
|
|
||||||
}
|
|
||||||
|
|
||||||
$you['ID_U'] = $data['ID_U'];
|
|
||||||
$you['nick'] = $data['nick'];
|
|
||||||
$you['fullRights'] = $data['fullRights'];
|
|
||||||
$you['SessionID'] = $data['SessionID'];
|
|
||||||
$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";
|
|
||||||
|
|
||||||
?>
|
|
||||||
89
cronchk.php
89
cronchk.php
@@ -1,33 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "functions.php";
|
require_once "load.php";
|
||||||
|
|
||||||
function PING_IP($db_conn,$ID_C,$URL,$timestamp){
|
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];
|
||||||
}else{$host=$URL;}
|
}else{$host=$URL;}
|
||||||
$result = isset($port) ? ping($host,$port) : ping($host); //Ping IP with or without port
|
$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
|
return $result; //Returns result
|
||||||
}
|
}
|
||||||
|
|
||||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param,$timestamp){
|
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
|
||||||
|
|
||||||
if ($httpCode == $code){ //Si es igual
|
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
|
$ret = 0; //All right
|
||||||
}else{ //Si no es igual (Incluye false)
|
}else{ //Si no es igual (Incluye false)
|
||||||
$httpCode = (int)$httpCode; //Force int
|
$ret = (int)$httpCode; //Code not 0 (And it's received code)
|
||||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`codeText`,`timestamp`) VALUES ('$ID_C','1','$httpCode','$timestamp')");
|
|
||||||
$ret = 1;
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
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);
|
||||||
@@ -37,19 +33,47 @@ function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
$result = htmlentities($body);
|
$result = htmlentities($body);
|
||||||
if($result == 'OK'){
|
if($result == 'OK'){
|
||||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
return 0;
|
||||||
$ret = 0;
|
}else{ //Fail if it returns other than "OK".
|
||||||
}else{ //Fail if it's not ok.
|
return 1;
|
||||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
|
||||||
$ret = 1;
|
|
||||||
}
|
}
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
@@ -57,31 +81,38 @@ 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'],time());
|
$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'],time());
|
$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'],time());
|
$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);
|
||||||
}
|
$timestamp = time();
|
||||||
|
if ($exitC == 0){ //Check successful
|
||||||
|
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||||
//Delete old Checks (Based on user input)
|
}else if ($exitC == 1){ //Normal check failed
|
||||||
$sites = dbw_query($db_conn,"SELECT * FROM CHECKS");
|
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
||||||
while ($site = dbw_fetch_array($db_conn,$sites)){
|
}else{ //Other code of check failed
|
||||||
$count = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C='$site[ID_C]'")[0]; //Count how much checks has a site
|
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`errorText`,`timestamp`) VALUES ('$ID_C','1','$exitC','$timestamp')");
|
||||||
|
|
||||||
if ($count > getSystemOpt($db_conn,"maxChecksSave")){
|
|
||||||
$todelete = $count - getSystemOpt($db_conn,"maxChecksSave"); //How much to delete
|
|
||||||
dbw_query($db_conn, "DELETE FROM CHKHIST WHERE ID_C='$site[ID_C]' ORDER BY `timestamp` ASC LIMIT $todelete");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Delete old Checks (Based on time to save, put in secs)
|
||||||
|
$mintime = time()-(getSystemOpt("maxTimeSave")*24*3600);
|
||||||
|
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
|
||||||
dbw_query($db_conn, "DELETE FROM CHKHIST WHERE ID_C NOT IN (SELECT ID_C FROM CHECKS)");
|
dbw_query($db_conn, "DELETE FROM CHKHIST WHERE ID_C NOT IN (SELECT ID_C FROM CHECKS)");
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ switch($type){
|
|||||||
case 'mysqli':
|
case 'mysqli':
|
||||||
$dbUser = $_POST['dbcode_user'];
|
$dbUser = $_POST['dbcode_user'];
|
||||||
$dbPass = $_POST['dbcode_pass'];
|
$dbPass = $_POST['dbcode_pass'];
|
||||||
$dbDb = $_POST['dbcode_db'];
|
|
||||||
$file = '<?php
|
$file = '<?php
|
||||||
mysqli_connect("'.$dbHost.'","'.$dbUser.'","'.$dbPass.'","'.$dbDb.'") or die("FAIL");
|
mysqli_connect("'.$dbHost.'","'.$dbUser.'","'.$dbPass.'",) or die("FAIL");
|
||||||
die("OK");
|
die("OK");
|
||||||
?>';
|
?>';
|
||||||
break;
|
break;
|
||||||
|
|||||||
155
functions.php
155
functions.php
@@ -1,46 +1,57 @@
|
|||||||
<?php
|
<?php
|
||||||
/* First, db connection */
|
//Functions
|
||||||
require_once "connect.php";
|
|
||||||
require_once 'lib/loadTwig.php';
|
|
||||||
|
|
||||||
/** Function checkStatus checks last "Checks" and their return
|
function getUptime($ID_C,$precision = 0){
|
||||||
Return can be:
|
$db_conn = getconn();
|
||||||
A value from 0-1-2 for status. 3 for Out Of Service. 3 and 4 can be turned up manually (
|
if ($precision == 0){
|
||||||
0-Perfect
|
$time = time()-30*7*3600; //Last week
|
||||||
1-Little problems
|
}else{
|
||||||
2-Problems
|
$time = $precision;
|
||||||
3-Out of service
|
}
|
||||||
4-In maintenance
|
$res = dbw_query($db_conn,"SELECT code FROM CHKHIST WHERE ID_C='$ID_C' AND `timestamp` > $time");
|
||||||
255-Not results recolected (grey)
|
$count = 0;
|
||||||
*/
|
$err = 0;
|
||||||
function checkStatus($db_conn,$ID_C){
|
while ($fila = dbw_fetch_array($db_conn,$res)){
|
||||||
//First, check if the status is marked to any manual value
|
$count++;
|
||||||
$manualPage = dbw_query_fetch_array($db_conn,"SELECT ID_C,manStatus FROM CHECKS WHERE ID_C='$ID_C'")['manStatus'];
|
$err += $fila['code'];
|
||||||
if ($manualPage != NULL){return $manualPage;}
|
}
|
||||||
//If it's not manual-setted, see real status
|
if ($count == 0){
|
||||||
$result = checkUptime($db_conn,$ID_C);
|
return '-1'; //No registers
|
||||||
//Return status
|
}else{
|
||||||
if ($result == 255){return 255;}
|
if ($err != 0){
|
||||||
if ($result > 95 && $result <= 100){return 0;}
|
$uptime = (100 - round(($err/$count)*100,2));
|
||||||
if ($result > 60 && $result <= 95){return 1;}
|
return $uptime;
|
||||||
if ($result > 10 && $result <= 60){return 2;}
|
}else{
|
||||||
if ($result >= 0 && $result <= 10){return 3;} //If test fail much (90% fail)
|
return 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUptime($db_conn,$ID_C,$precision = 0){
|
function getStatus($ID_C){
|
||||||
$time = $precision;
|
$T_ = loadLang();
|
||||||
if ($precision != 0){
|
$db_conn = getconn();
|
||||||
$good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0 AND `timestamp` > $time")[0];
|
$resql = dbw_query($db_conn,"SELECT code FROM CHKHIST WHERE ID_C='$ID_C' ORDER BY `timestamp` DESC LIMIT 5");
|
||||||
$all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND `timestamp` > $time")[0];
|
$err = 0;
|
||||||
}else{ //Uptime of all time
|
while ($x = dbw_fetch_array($db_conn,$resql)){
|
||||||
$good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0")[0];
|
if ($x['code'] != 0){
|
||||||
$all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C'")[0];
|
$err++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($all != 0){
|
switch ($err){
|
||||||
$uptime = ($good/$all)*100;
|
case 0:
|
||||||
return $uptime;
|
case 1:
|
||||||
}else{
|
return array($T_['status_right'],'green');
|
||||||
return 100;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +70,11 @@ function webRoot(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a system option */
|
/** Returns a system option */
|
||||||
function getSystemOpt($db_conn,$sysopt){
|
function getSystemOpt($sysopt){
|
||||||
return dbw_query_fetch_array($db_conn,"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();
|
||||||
@@ -99,45 +110,71 @@ function RandomString($length)
|
|||||||
|
|
||||||
/** 1 if its logued, 0 if not */
|
/** 1 if its logued, 0 if not */
|
||||||
function isLogued(){
|
function isLogued(){
|
||||||
if (isset($_COOKIE['SessionID'])){
|
if (isset($_SESSION['UserID'])){
|
||||||
return 1;
|
return 1;
|
||||||
}else{
|
}else{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function requireLogin(){
|
function requireLogin(){
|
||||||
if (isLogued() == 0){
|
if (isLogued() == 0){
|
||||||
die('You dont have admin rights'); //This blocks edit or create nothing if its not logued
|
die('You dont have admin rights'); //This blocks edit or create nothing if its not logued
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nameFromIDC($db_conn,$ID_C){
|
function nameFromIDC($ID_C){
|
||||||
return dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
return dbw_query_fetch_array(getconn(),"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function nameGroupFromIDG($db_conn,$ID_G){
|
function nameGroupFromIDG($ID_G){
|
||||||
return dbw_query_fetch_array($db_conn,"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($db_conn,$ID_C){
|
function IDGFromIDC($ID_C){
|
||||||
return dbw_query_fetch_array($db_conn,"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G'];
|
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 */
|
/* 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($T_,$typeChk){
|
function textTypeChk($typeChk){
|
||||||
|
$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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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_;
|
||||||
|
}
|
||||||
|
|||||||
46
index.php
46
index.php
@@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "functions.php";
|
require_once "load.php";
|
||||||
|
|
||||||
$results = dbw_query($db_conn,"SELECT * FROM GROUPS"); //All groups
|
$results = dbw_query($db_conn,"SELECT * FROM GROUPS"); //All groups
|
||||||
|
|
||||||
while ($group = dbw_fetch_array($db_conn,$results)){ //Know name of all groups
|
while ($group = dbw_fetch_array($db_conn,$results)){ //Know name of all groups
|
||||||
$groups[$group['ID_G']] = $group['name'];
|
$groups[$group['ID_G']] = $group['name'];
|
||||||
}
|
}
|
||||||
|
unset($results); //Free mem
|
||||||
|
|
||||||
$results = dbw_query($db_conn,"SELECT * FROM CHECKS ORDER BY ID_G"); //All checks
|
$results = dbw_query($db_conn,"SELECT * FROM CHECKS ORDER BY ID_G"); //All checks
|
||||||
|
|
||||||
@@ -14,32 +14,44 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){
|
|||||||
$idchk = $onechk['ID_C'];
|
$idchk = $onechk['ID_C'];
|
||||||
$chks[$idchk] = $onechk; //First array data
|
$chks[$idchk] = $onechk; //First array data
|
||||||
$chks[$idchk]['nameGroup'] = $groups[$onechk['ID_G']]; //Know group of this check
|
$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 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
|
||||||
|
|
||||||
if (dbw_query_fetch_array($db_conn, "SELECT COUNT(*) 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)
|
||||||
$chks[$idchk]['status'] = checkStatus($db_conn,$idchk); //Check status of a site
|
if (dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' LIMIT 1")[0] != 0){
|
||||||
$chks[$idchk]['dateLastChk'] = date('d/m H:i',dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' ORDER BY `timestamp` DESC")['timestamp']);
|
|
||||||
|
$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'] = dbw_query_fetch_array($db_conn, "SELECT `code` FROM CHKHIST WHERE ID_C = '$idchk' ORDER BY `timestamp` DESC LIMIT 0,1")['code'];
|
$chks[$idchk]['failedLastChk'] = $consul['code'];
|
||||||
|
|
||||||
$lastErr = dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' AND code != 0 ORDER BY `timestamp` DESC LIMIT 0,1")['timestamp']; //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){
|
if ($lastErr != false){
|
||||||
$chks[$idchk]['dateLastErr'] = date('d/m H:i',$lastErr);
|
$chks[$idchk]['dateLastErr'] = date('d/m H:i',$lastErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
$chks[$idchk]['nameCheck'] = textTypeChk($ID_TC);
|
||||||
$chks[$idchk]['nameCheck'] = textTypeChk($T_,$ID_TC);
|
|
||||||
|
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;
|
break;
|
||||||
|
|
||||||
case 3: //Visits
|
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
|
//Create array from last 5 days
|
||||||
while ($visitsDay = dbw_fetch_array($db_conn, $visitsSite)){
|
while ($visitsDay = dbw_fetch_array($db_conn, $visitsSite)){
|
||||||
$dateArray[] = $visitsDay['date'];
|
$dateArray[] = $visitsDay['date'];
|
||||||
@@ -53,7 +65,7 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Here load "News"
|
//Here load "News"
|
||||||
|
|
||||||
$incidents = dbw_query($db_conn,"SELECT * FROM NEWS ORDER BY ID_N DESC LIMIT 20");
|
$incidents = dbw_query($db_conn,"SELECT * FROM NEWS ORDER BY ID_N DESC LIMIT 20");
|
||||||
while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
||||||
@@ -72,7 +84,5 @@ while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
|||||||
->text($incident['text']);
|
->text($incident['text']);
|
||||||
$incs[$ID_N]['ID_N'] = $incident['ID_N'];
|
$incs[$ID_N]['ID_N'] = $incident['ID_N'];
|
||||||
}
|
}
|
||||||
|
renderPage('indexpage.twig',array('you' => $you,'checks' => $chks, 'news' => $incs)); //Render
|
||||||
echo $twig->render('indexpage.twig', array('T_' => $T_, 'you' => $you, 'checks' => $chks, 'news' => $incs)); //Render
|
?>
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
19
install.php
19
install.php
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$ver = '0.9';
|
define('VERSION','0.9.3');
|
||||||
//require "functions.php"; //THIS FILE CAN'T BE USED THERE, BECAUSE IT HAS connect.php dependence
|
//define('INSTALLER_MODE','1');
|
||||||
require_once 'lib/loadTwig.php';
|
require_once 'lib/loadTwig.php';
|
||||||
|
|
||||||
$db_file = __DIR__."/sqlite.db3";
|
$db_file = __DIR__."/sqlite.db3";
|
||||||
@@ -12,7 +12,7 @@ if (!isset($_POST['websiteName']) && !isset($_POST['username']) && !isset($_POST
|
|||||||
echo $twig->render('install.twig');
|
echo $twig->render('install.twig');
|
||||||
}else{
|
}else{
|
||||||
if ($_POST['passw1'] !== $_POST['passw2']){
|
if ($_POST['passw1'] !== $_POST['passw2']){
|
||||||
die("NONO");
|
die("Passwords didn't match");
|
||||||
}else{
|
}else{
|
||||||
//Creamos toda la base de datos
|
//Creamos toda la base de datos
|
||||||
require_once "lib/dbwrapper.php"; //For using database
|
require_once "lib/dbwrapper.php"; //For using database
|
||||||
@@ -30,7 +30,6 @@ CREATE TABLE "USERS" (
|
|||||||
`ID_U` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`ID_U` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`nick` TEXT NOT NULL UNIQUE,
|
`nick` TEXT NOT NULL UNIQUE,
|
||||||
`passw` TEXT,
|
`passw` TEXT,
|
||||||
`SessionID` INTEGER UNIQUE,
|
|
||||||
`fullRights` INTEGER NOT NULL
|
`fullRights` INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE TABLE "TOKENS" (
|
CREATE TABLE "TOKENS" (
|
||||||
@@ -64,24 +63,26 @@ 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
|
||||||
|
|
||||||
//System opts
|
//System opts
|
||||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maxChecksSave',300)");
|
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maxTimeSave',14)");
|
||||||
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','$ver')");
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
|
* 2.4.4 (2017-09-27)
|
||||||
|
|
||||||
|
* added Twig_Profiler_Profile::reset()
|
||||||
|
* fixed use TokenParser to return an empty Node
|
||||||
|
* added RuntimeExtensionInterface
|
||||||
|
* added circular reference detection when loading templates
|
||||||
|
* added support for runtime loaders in IntegrationTestCase
|
||||||
|
* fixed deprecation when using Twig_Profiler_Dumper_Html
|
||||||
|
* removed @final from Twig_Profiler_Dumper_Text
|
||||||
|
|
||||||
* 2.4.3 (2017-06-07)
|
* 2.4.3 (2017-06-07)
|
||||||
|
|
||||||
* fixed namespaces introduction
|
* fixed namespaces introduction
|
||||||
@@ -69,9 +79,17 @@
|
|||||||
* improved the performance of the filesystem loader
|
* improved the performance of the filesystem loader
|
||||||
* removed features that were deprecated in 1.x
|
* removed features that were deprecated in 1.x
|
||||||
|
|
||||||
* 1.34.4 (2017-XX-XX)
|
* 1.35.0 (2017-XX-XX)
|
||||||
|
|
||||||
* n/a
|
* added Twig_Profiler_Profile::reset()
|
||||||
|
* fixed use TokenParser to return an empty Node
|
||||||
|
* added RuntimeExtensionInterface
|
||||||
|
* added circular reference detection when loading templates
|
||||||
|
|
||||||
|
* 1.34.4 (2017-07-04)
|
||||||
|
|
||||||
|
* added support for runtime loaders in IntegrationTestCase
|
||||||
|
* fixed deprecation when using Twig_Profiler_Dumper_Html
|
||||||
|
|
||||||
* 1.34.3 (2017-06-07)
|
* 1.34.3 (2017-06-07)
|
||||||
|
|
||||||
@@ -212,7 +230,7 @@
|
|||||||
|
|
||||||
* fixed reserved keywords (forbids true, false, null and none keywords for variables names)
|
* fixed reserved keywords (forbids true, false, null and none keywords for variables names)
|
||||||
* fixed support for PHP7 (Throwable support)
|
* fixed support for PHP7 (Throwable support)
|
||||||
* marked the following methods as being internals on Twig_Environment:
|
* marked the following methods as being internals on Twig_Environment:
|
||||||
getFunctions(), getFilters(), getTests(), getFunction(), getFilter(), getTest(),
|
getFunctions(), getFilters(), getTests(), getFunction(), getFilter(), getTest(),
|
||||||
getTokenParsers(), getTags(), getNodeVisitors(), getUnaryOperators(), getBinaryOperators(),
|
getTokenParsers(), getTags(), getNodeVisitors(), getUnaryOperators(), getBinaryOperators(),
|
||||||
getFunctions(), getFilters(), getGlobals(), initGlobals(), initExtensions(), and initExtension()
|
getFunctions(), getFilters(), getGlobals(), initGlobals(), initExtensions(), and initExtension()
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
class Twig_Environment
|
class Twig_Environment
|
||||||
{
|
{
|
||||||
const VERSION = '2.4.3';
|
const VERSION = '2.4.4';
|
||||||
const VERSION_ID = 20403;
|
const VERSION_ID = 20404;
|
||||||
const MAJOR_VERSION = 2;
|
const MAJOR_VERSION = 2;
|
||||||
const MINOR_VERSION = 4;
|
const MINOR_VERSION = 4;
|
||||||
const RELEASE_VERSION = 3;
|
const RELEASE_VERSION = 4;
|
||||||
const EXTRA_VERSION = '';
|
const EXTRA_VERSION = '';
|
||||||
|
|
||||||
private $charset;
|
private $charset;
|
||||||
@@ -42,6 +42,7 @@ class Twig_Environment
|
|||||||
private $runtimeLoaders = array();
|
private $runtimeLoaders = array();
|
||||||
private $runtimes = array();
|
private $runtimes = array();
|
||||||
private $optionsHash;
|
private $optionsHash;
|
||||||
|
private $loading = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -308,6 +309,10 @@ class Twig_Environment
|
|||||||
*
|
*
|
||||||
* @param string|Twig_TemplateWrapper|Twig_Template $name The template name
|
* @param string|Twig_TemplateWrapper|Twig_Template $name The template name
|
||||||
*
|
*
|
||||||
|
* @throws Twig_Error_Loader When the template cannot be found
|
||||||
|
* @throws Twig_Error_Runtime When a previously generated cache is corrupted
|
||||||
|
* @throws Twig_Error_Syntax When an error occurred during compilation
|
||||||
|
*
|
||||||
* @return Twig_TemplateWrapper
|
* @return Twig_TemplateWrapper
|
||||||
*/
|
*/
|
||||||
public function load($name)
|
public function load($name)
|
||||||
@@ -382,7 +387,19 @@ class Twig_Environment
|
|||||||
// to be removed in 3.0
|
// to be removed in 3.0
|
||||||
$this->extensionSet->initRuntime($this);
|
$this->extensionSet->initRuntime($this);
|
||||||
|
|
||||||
return $this->loadedTemplates[$cls] = new $cls($this);
|
if (isset($this->loading[$cls])) {
|
||||||
|
throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, array($name)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->loading[$cls] = $name;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->loadedTemplates[$cls] = new $cls($this);
|
||||||
|
} finally {
|
||||||
|
unset($this->loading[$cls]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->loadedTemplates[$cls];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1430,8 +1430,6 @@ function twig_array_batch($items, $size, $fill = null)
|
|||||||
*/
|
*/
|
||||||
function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
||||||
{
|
{
|
||||||
static $cache = array();
|
|
||||||
|
|
||||||
// array
|
// array
|
||||||
if (Twig_Template::METHOD_CALL !== $type) {
|
if (Twig_Template::METHOD_CALL !== $type) {
|
||||||
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
||||||
@@ -1518,6 +1516,8 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static $cache = array();
|
||||||
|
|
||||||
$class = get_class($object);
|
$class = get_class($object);
|
||||||
|
|
||||||
// object method
|
// object method
|
||||||
|
|||||||
62
lib/Twig/lib/Twig/Profiler/Dumper/Base.php
Normal file
62
lib/Twig/lib/Twig/Profiler/Dumper/Base.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Twig.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
abstract class Twig_Profiler_Dumper_Base
|
||||||
|
{
|
||||||
|
private $root;
|
||||||
|
|
||||||
|
public function dump(Twig_Profiler_Profile $profile)
|
||||||
|
{
|
||||||
|
return $this->dumpProfile($profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix);
|
||||||
|
|
||||||
|
abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix);
|
||||||
|
|
||||||
|
abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent);
|
||||||
|
|
||||||
|
private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
|
||||||
|
{
|
||||||
|
if ($profile->isRoot()) {
|
||||||
|
$this->root = $profile->getDuration();
|
||||||
|
$start = $profile->getName();
|
||||||
|
} else {
|
||||||
|
if ($profile->isTemplate()) {
|
||||||
|
$start = $this->formatTemplate($profile, $prefix);
|
||||||
|
} else {
|
||||||
|
$start = $this->formatNonTemplate($profile, $prefix);
|
||||||
|
}
|
||||||
|
$prefix .= $sibling ? '│ ' : ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
|
||||||
|
|
||||||
|
if ($profile->getDuration() * 1000 < 1) {
|
||||||
|
$str = $start."\n";
|
||||||
|
} else {
|
||||||
|
$str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
|
||||||
|
}
|
||||||
|
|
||||||
|
$nCount = count($profile->getProfiles());
|
||||||
|
foreach ($profile as $i => $p) {
|
||||||
|
$str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig_Profiler_Dumper_Base', 'Twig\Profiler\Dumper\BaseDumper', false);
|
||||||
|
class_exists('Twig_Profiler_Profile');
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
final class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Text
|
final class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base
|
||||||
{
|
{
|
||||||
private static $colors = array(
|
private static $colors = array(
|
||||||
'block' => '#dfd',
|
'block' => '#dfd',
|
||||||
|
|||||||
@@ -11,18 +11,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*
|
|
||||||
* @final
|
|
||||||
*/
|
*/
|
||||||
class Twig_Profiler_Dumper_Text
|
final class Twig_Profiler_Dumper_Text extends Twig_Profiler_Dumper_Base
|
||||||
{
|
{
|
||||||
private $root;
|
|
||||||
|
|
||||||
public function dump(Twig_Profiler_Profile $profile)
|
|
||||||
{
|
|
||||||
return $this->dumpProfile($profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
|
protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
|
||||||
{
|
{
|
||||||
return sprintf('%s└ %s', $prefix, $profile->getTemplate());
|
return sprintf('%s└ %s', $prefix, $profile->getTemplate());
|
||||||
@@ -37,36 +28,6 @@ class Twig_Profiler_Dumper_Text
|
|||||||
{
|
{
|
||||||
return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent);
|
return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
|
|
||||||
{
|
|
||||||
if ($profile->isRoot()) {
|
|
||||||
$this->root = $profile->getDuration();
|
|
||||||
$start = $profile->getName();
|
|
||||||
} else {
|
|
||||||
if ($profile->isTemplate()) {
|
|
||||||
$start = $this->formatTemplate($profile, $prefix);
|
|
||||||
} else {
|
|
||||||
$start = $this->formatNonTemplate($profile, $prefix);
|
|
||||||
}
|
|
||||||
$prefix .= $sibling ? '│ ' : ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
|
|
||||||
|
|
||||||
if ($profile->getDuration() * 1000 < 1) {
|
|
||||||
$str = $start."\n";
|
|
||||||
} else {
|
|
||||||
$str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
|
|
||||||
}
|
|
||||||
|
|
||||||
$nCount = count($profile->getProfiles());
|
|
||||||
foreach ($profile as $i => $p) {
|
|
||||||
$str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Profiler_Dumper_Text', 'Twig\Profiler\Dumper\TextDumper', false);
|
class_alias('Twig_Profiler_Dumper_Text', 'Twig\Profiler\Dumper\TextDumper', false);
|
||||||
|
|||||||
@@ -149,6 +149,12 @@ class Twig_Profiler_Profile implements IteratorAggregate, Serializable
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
$this->starts = $this->ends = $this->profiles = array();
|
||||||
|
$this->enter();
|
||||||
|
}
|
||||||
|
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
return new ArrayIterator($this->profiles);
|
return new ArrayIterator($this->profiles);
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
|
|||||||
*/
|
*/
|
||||||
abstract protected function getFixturesDir();
|
abstract protected function getFixturesDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Twig_RuntimeLoaderInterface[]
|
||||||
|
*/
|
||||||
|
protected function getRuntimeLoaders()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Twig_ExtensionInterface[]
|
* @return Twig_ExtensionInterface[]
|
||||||
*/
|
*/
|
||||||
@@ -143,6 +151,10 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
|
|||||||
), $match[2] ? eval($match[2].';') : array());
|
), $match[2] ? eval($match[2].';') : array());
|
||||||
$twig = new Twig_Environment($loader, $config);
|
$twig = new Twig_Environment($loader, $config);
|
||||||
$twig->addGlobal('global', 'global');
|
$twig->addGlobal('global', 'global');
|
||||||
|
foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
|
||||||
|
$twig->addRuntimeLoader($runtimeLoader);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->getExtensions() as $extension) {
|
foreach ($this->getExtensions() as $extension) {
|
||||||
$twig->addExtension($extension);
|
$twig->addExtension($extension);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ final class Twig_TokenParser_Use extends Twig_TokenParser
|
|||||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
$this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
|
$this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
|
||||||
|
|
||||||
|
return new Twig_Node();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTag()
|
public function getTag()
|
||||||
|
|||||||
@@ -49,14 +49,20 @@ function dbw_escape_string($conn,$string){
|
|||||||
|
|
||||||
/** Make query */
|
/** Make query */
|
||||||
function dbw_query($conn,$query){
|
function dbw_query($conn,$query){
|
||||||
|
$time = microtime(true);
|
||||||
switch ($conn[1]){
|
switch ($conn[1]){
|
||||||
case "mysqli":
|
case "mysqli":
|
||||||
return mysqli_query($conn[0],$query);
|
$ret = mysqli_query($conn[0],$query);
|
||||||
|
break;
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
return $conn[0]->query($query);
|
$ret = $conn[0]->query($query);
|
||||||
|
break;
|
||||||
case "PgSQL":
|
case "PgSQL":
|
||||||
return pg_query($query); //Last error (pg_last_error()) not implemented
|
$ret = pg_query($query);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
//echo "<p>".$query."->".(microtime(true)-$time)." milisegundos</p>";
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fetch array from query */
|
/** Fetch array from query */
|
||||||
@@ -83,23 +89,27 @@ function dbw_fetch_array($conn,$result,$typearray = NULL){
|
|||||||
|
|
||||||
/** Make query and fetch array */
|
/** Make query and fetch array */
|
||||||
function dbw_query_fetch_array($conn,$query){
|
function dbw_query_fetch_array($conn,$query){
|
||||||
|
$time = microtime(true);
|
||||||
|
|
||||||
switch ($conn[1]){
|
switch ($conn[1]){
|
||||||
case "mysqli":
|
case "mysqli":
|
||||||
$query = mysqli_query($conn[0],$query);
|
$result = mysqli_query($conn[0],$query);
|
||||||
if ($query == false || $query == NULL){return false;}
|
if (!$result){return false;}
|
||||||
return mysqli_fetch_array($query);
|
$ret = mysqli_fetch_array($result);
|
||||||
break;
|
break;
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
$query = $conn[0]->query($query);
|
$result = $conn[0]->query($query);
|
||||||
if ($query == false || $query == NULL){return false;}
|
if (!$result){return false;}
|
||||||
return $query->fetchArray();
|
$ret = $result->fetchArray();
|
||||||
break;
|
break;
|
||||||
case "PgSQL":
|
case "PgSQL":
|
||||||
$query = pg_query($query);
|
$result = pg_query($query);
|
||||||
if ($query == false || $query == NULL){return false;}
|
if (!$result){return false;}
|
||||||
return pg_fetch_array($query); //Last error (pg_last_error()) not implemented
|
$ret = pg_fetch_array($result); //Last error (pg_last_error()) not implemented
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//echo "<p>".$query."->".(microtime(true)-$time)." milisegundos</p>";
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Goes a query to $row. $row starts in 0 as first row as if not specified */
|
/** Goes a query to $row. $row starts in 0 as first row as if not specified */
|
||||||
@@ -155,7 +165,8 @@ function dbw_num_rows($conn,$result){
|
|||||||
case "mysqli":
|
case "mysqli":
|
||||||
return mysqli_num_rows($result);
|
return mysqli_num_rows($result);
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
return $result->numRows();
|
die("Sqlite3 not supports numRows, use query with COUNT(*)");
|
||||||
|
return $result->numRows(); //ERROR
|
||||||
case "PgSQL":
|
case "PgSQL":
|
||||||
return pg_num_rows ($result);
|
return pg_num_rows ($result);
|
||||||
}
|
}
|
||||||
|
|||||||
41
load.php
Normal file
41
load.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'functions.php'; //Preloads functions
|
||||||
|
require_once 'lib/dbwrapper.php';
|
||||||
|
define('VERSION','0.9.3');
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
if (getSystemOpt('maintenance') == '1'){
|
||||||
|
die("<p>CheckStatus is in maintenance mode, wait for admin to disable maintenance mode</p>");
|
||||||
|
}
|
||||||
|
|
||||||
22
login.php
22
login.php
@@ -1,35 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
require "functions.php";
|
require "load.php";
|
||||||
|
|
||||||
if (isset($_GET['do'])){
|
if (isset($_GET['do'])){
|
||||||
if ($_GET['do'] == 'logout'){
|
if ($_GET['do'] == 'logout'){
|
||||||
require_once "connect.php";
|
session_destroy();
|
||||||
dbw_query($db_conn, "UPDATE USERS SET SessionID = NULL WHERE SessionID='$_COOKIE[SessionID]'");
|
|
||||||
setcookie("SessionID", "", time()-3600,"/");
|
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_COOKIE['SessionID'])){ //Ya está logueado
|
if (isset($_SESSION['UserID'])){ //Ya está logueado
|
||||||
header('Location: panel.php');
|
header('Location: panel.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($_POST['nick'])){
|
if (!isset($_POST['nick'])){
|
||||||
echo $twig->render('login.twig');
|
renderPage('login.twig');
|
||||||
}
|
}
|
||||||
if (isset($_POST['nick'])){
|
if (isset($_POST['nick'])){
|
||||||
$nick=$_POST['nick'];
|
$nick=$_POST['nick'];
|
||||||
$pass= hash("sha256",$_POST['pass']);
|
$pass= hash("sha256",$_POST['pass']);
|
||||||
$finalpass = dbw_query_fetch_array($db_conn,"SELECT `Passw` FROM `USERS` WHERE nick ='$nick'");
|
$resql = dbw_query_fetch_array($db_conn,"SELECT ID_U,`passw` FROM `USERS` WHERE nick ='$nick'");
|
||||||
$passcomprobar = $finalpass[0];
|
$passcomprobar = $resql['passw'];
|
||||||
if ($pass == $passcomprobar)
|
if ($pass == $passcomprobar)
|
||||||
{
|
{
|
||||||
$sesid = RandomString(12);
|
$_SESSION['UserID'] = $resql['ID_U'];
|
||||||
dbw_query($db_conn, "UPDATE USERS SET SessionID = '$sesid' WHERE nick = '$nick'");
|
header('Location: panel.php');
|
||||||
setcookie("SessionID",$sesid,"0","/");
|
|
||||||
header('Location: panel.php');
|
|
||||||
}else{
|
}else{
|
||||||
echo $twig->render('login.twig', array('status' => 'error'));
|
renderPage('login.twig', array('status' => 'error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
96
panel.php
96
panel.php
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'functions.php';
|
require_once 'load.php';
|
||||||
requirelogin();
|
requirelogin();
|
||||||
|
|
||||||
//Calculo día 1 del mes en curso
|
//Calculo día 1 del mes en curso
|
||||||
@@ -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")
|
||||||
@@ -38,7 +38,7 @@ switch($page){
|
|||||||
$ID_G = $chks[$idchk]['ID_G']; //For nameGroup
|
$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'];
|
$chks[$idchk]['nameGroup'] = dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
$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']);
|
$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;
|
break;
|
||||||
|
|
||||||
//Forms to add or edit a check (Not saving, only forms)
|
//Forms to add or edit a check (Not saving, only forms)
|
||||||
@@ -65,17 +65,18 @@ switch($page){
|
|||||||
foreach(arrayTypeChk() as $key => $value){
|
foreach(arrayTypeChk() as $key => $value){
|
||||||
$tchecks[] = array(
|
$tchecks[] = array(
|
||||||
'ID_TC' =>$key,
|
'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.
|
//En este if hago las diferencias entre add y edit, para no repetir código.
|
||||||
if ($page == 'addcheck'){
|
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'){
|
}elseif ($page == 'editcheck'){
|
||||||
$ID_C = (int)$_GET['ID_C']; //Check to edit
|
$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
|
$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;
|
break;
|
||||||
|
|
||||||
@@ -89,17 +90,28 @@ 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'");
|
||||||
@@ -144,8 +156,7 @@ switch($page){
|
|||||||
'checks' => $countchk
|
'checks' => $countchk
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
renderPage('panel/p_groups.twig', array('you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
||||||
echo $twig->render('panel/p_groups.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'addgroup':
|
case 'addgroup':
|
||||||
@@ -186,8 +197,7 @@ switch($page){
|
|||||||
->text($result['text']);
|
->text($result['text']);
|
||||||
$news[$ID_N]['mdtext'] = $result['text']; //Raw text
|
$news[$ID_N]['mdtext'] = $result['text']; //Raw text
|
||||||
}
|
}
|
||||||
|
renderPage('panel/p_news.twig', array('you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
||||||
echo $twig->render('panel/p_news.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'newnews':
|
case 'newnews':
|
||||||
@@ -208,15 +218,17 @@ switch($page){
|
|||||||
header('Location: panel.php?page=news');
|
header('Location: panel.php?page=news');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'savesettings':
|
||||||
|
//All group names and IDs
|
||||||
|
dbw_query($db_conn,"UPDATE SYS SET `value`='$_POST[name]' WHERE `option`='name'");
|
||||||
|
dbw_query($db_conn,"UPDATE SYS SET `value`='$_POST[maxTimeSave]' WHERE `option`='maxTimeSave'");
|
||||||
case 'settings':
|
case 'settings':
|
||||||
//All group names and IDs
|
//All group names and IDs
|
||||||
$results = dbw_query($db_conn,"SELECT * FROM SYS"); //All groups
|
$results = dbw_query($db_conn,"SELECT * FROM SYS"); //All groups
|
||||||
while ($syso = dbw_fetch_array($db_conn,$results)){
|
while ($syso = dbw_fetch_array($db_conn,$results)){
|
||||||
$sys[$syso['option']] = $syso['value'];
|
$sys[$syso['option']] = $syso['value'];
|
||||||
}
|
}
|
||||||
|
renderPage('panel/p_settings.twig', array('you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
||||||
echo $twig->render('panel/p_settings.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'users':
|
case 'users':
|
||||||
@@ -230,8 +242,7 @@ switch($page){
|
|||||||
'fullrights' => $us['fullRights']
|
'fullrights' => $us['fullRights']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
renderPage('panel/p_users.twig', array('mpage' => 'users', 'you' => $you, 'users' => $user));
|
||||||
echo $twig->render('panel/p_users.twig', array('T_' => $T_, 'mpage' => 'users', 'you' => $you, 'users' => $user));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'adduser':
|
case 'adduser':
|
||||||
@@ -268,6 +279,32 @@ switch($page){
|
|||||||
header('Location: panel.php?page=users');
|
header('Location: panel.php?page=users');
|
||||||
break;
|
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
|
// Página principal
|
||||||
case 'status':
|
case 'status':
|
||||||
default:
|
default:
|
||||||
@@ -280,8 +317,9 @@ switch($page){
|
|||||||
if ($failssql != false){
|
if ($failssql != false){
|
||||||
while ($fail = dbw_fetch_array($db_conn,$failssql)){ //Create array
|
while ($fail = dbw_fetch_array($db_conn,$failssql)){ //Create array
|
||||||
$fails[] = array (
|
$fails[] = array (
|
||||||
'name' => nameFromIDC($db_conn,$fail['ID_C']),
|
'ID_C' => $fail['ID_C'],
|
||||||
'groupName' => nameGroupFromIDG($db_conn,IDGFromIDC($db_conn,$fail['ID_C'])),
|
'name' => nameFromIDC($fail['ID_C']),
|
||||||
|
'groupName' => nameGroupFromIDG(IDGFromIDC($fail['ID_C'])),
|
||||||
'typeCheck' => textTypeChk($T_,$fail['ID_TC']),
|
'typeCheck' => textTypeChk($T_,$fail['ID_TC']),
|
||||||
'errorText' => $fail['errorText'],
|
'errorText' => $fail['errorText'],
|
||||||
'date' => date('j/n/Y',$fail['timestamp']),
|
'date' => date('j/n/Y',$fail['timestamp']),
|
||||||
@@ -292,7 +330,7 @@ switch($page){
|
|||||||
$fails = array(); //Empty
|
$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;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
51
updater.php
Normal file
51
updater.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
echo "<h2>Updater of CheckServer</h2>";
|
||||||
|
echo "<p>Connecting to database</p>";
|
||||||
|
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
|
||||||
|
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];
|
||||||
|
echo "<p>Your version: ".$version;
|
||||||
|
echo "<p>Updating to lastest</p>";
|
||||||
|
switch ($version){
|
||||||
|
case '0.9':
|
||||||
|
echo "<p>0.9->0.9.1<p>";
|
||||||
|
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 "<p>0.9.1->0.9.2</p>";
|
||||||
|
case '0.9.2':
|
||||||
|
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>Remember to delete updater.php and install.php for security!</p>";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user