mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-16 02:01:34 +01:00
Change connect to load and fix code
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<p>JKA Network © 2017-actualidad. Versión 0.1 Alpha</p>
|
||||
<p>JKA Network © 2018. Versión {{version}}</p>
|
||||
</div>
|
||||
<div class="col-sm-6 text-right">
|
||||
<p>Design by <a href="https://bootstrapious.com" class="external">Bootstrapious</a></p>
|
||||
|
||||
@@ -30,3 +30,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% include 'footer.twig' %}
|
||||
38
connect.php
38
connect.php
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
define('VERSION','0.9.2');
|
||||
session_start(); //Session in all page
|
||||
require_once "lib/dbwrapper.php";
|
||||
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (!is_file($db_file)){ //Go to install if not.
|
||||
header("Location: install.php");
|
||||
die();
|
||||
}
|
||||
|
||||
$db_conn = dbw_connect("sqlite",$db_file); //Database
|
||||
|
||||
/** In connect.php check if user SessionID exists, if not, delete Cookie */
|
||||
if (isset($_SESSION['UserID'])){
|
||||
$data = dbw_query_fetch_array($db_conn, "SELECT * FROM USERS WHERE ID_U='$_SESSION[UserID]'");
|
||||
if ($data['ID_U'] != $_SESSION['UserID']){
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
}
|
||||
|
||||
$you['ID_U'] = $data['ID_U'];
|
||||
$you['nick'] = $data['nick'];
|
||||
$you['fullRights'] = $data['fullRights'];
|
||||
$you['webRoot'] = webRoot();
|
||||
}
|
||||
|
||||
|
||||
$lang=getSystemOpt($db_conn,'lang');
|
||||
//Translations
|
||||
require_once __DIR__."/assets/translations/en.php"; //Ever first English, and then your lang (Database)
|
||||
require_once __DIR__."/assets/translations/$lang.php";
|
||||
|
||||
$ver=getSystemOpt($db_conn,'version');
|
||||
if (getSystemOpt($db_conn,'version') != VERSION){
|
||||
die("<p>Please run updater.php to update before using page");
|
||||
}
|
||||
?>
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
/* First, db connection */
|
||||
require_once "connect.php";
|
||||
require_once 'lib/loadTwig.php';
|
||||
//Functions
|
||||
|
||||
function getUptime($db_conn,$ID_C,$precision = 0){
|
||||
function getUptime($ID_C,$precision = 0){
|
||||
$db_conn = getconn();
|
||||
if ($precision == 0){
|
||||
$time = time()-30*7*3600; //Last week
|
||||
}else{
|
||||
@@ -28,7 +27,9 @@ function getUptime($db_conn,$ID_C,$precision = 0){
|
||||
}
|
||||
}
|
||||
|
||||
function getStatus($db_conn,$T_,$ID_C){
|
||||
function getStatus($ID_C){
|
||||
$T_ = loadLang();
|
||||
$db_conn = getconn();
|
||||
$resql = dbw_query($db_conn,"SELECT code FROM CHKHIST WHERE ID_C='$ID_C' ORDER BY `timestamp` DESC LIMIT 5");
|
||||
$err = 0;
|
||||
while ($x = dbw_fetch_array($db_conn,$resql)){
|
||||
@@ -69,8 +70,8 @@ function webRoot(){
|
||||
}
|
||||
|
||||
/** Returns a system option */
|
||||
function getSystemOpt($db_conn,$sysopt){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
||||
function getSystemOpt($sysopt){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM SYS WHERE option = '$sysopt'")['value'];
|
||||
}
|
||||
|
||||
/** Return HttpCode of page. Returns false if page is not found */
|
||||
@@ -121,16 +122,16 @@ function requireLogin(){
|
||||
}
|
||||
}
|
||||
|
||||
function nameFromIDC($db_conn,$ID_C){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
||||
function nameFromIDC($ID_C){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0];
|
||||
}
|
||||
|
||||
function nameGroupFromIDG($db_conn,$ID_G){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
function nameGroupFromIDG($ID_G){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
}
|
||||
|
||||
function IDGFromIDC($db_conn,$ID_C){
|
||||
return dbw_query_fetch_array($db_conn,"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G'];
|
||||
function IDGFromIDC($ID_C){
|
||||
return dbw_query_fetch_array(getconn(),"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G'];
|
||||
}
|
||||
|
||||
/* This funtion returns the array with type of checks */
|
||||
@@ -142,7 +143,8 @@ function arrayTypeChk(){
|
||||
'4' => 'DATABASE');
|
||||
}
|
||||
/* This funtion returns the translated text of a type check */
|
||||
function textTypeChk($T_,$typeChk){
|
||||
function textTypeChk($typeChk){
|
||||
$T_ = loadLang();
|
||||
$arr = array(
|
||||
'1' => $T_['PING_IP'],
|
||||
'2' => $T_['HTTP_CODE'],
|
||||
@@ -150,3 +152,26 @@ function textTypeChk($T_,$typeChk){
|
||||
'4' => $T_['DATABASE']);
|
||||
return $arr[$typeChk];
|
||||
}
|
||||
|
||||
//This function is an alias to Twig render, with "standard args" added
|
||||
function renderPage($page,$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_;
|
||||
}
|
||||
11
index.php
11
index.php
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once "functions.php";
|
||||
require_once "load.php";
|
||||
|
||||
$results = dbw_query($db_conn,"SELECT * FROM GROUPS"); //All groups
|
||||
|
||||
@@ -35,14 +35,14 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){
|
||||
}
|
||||
|
||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
||||
$chks[$idchk]['nameCheck'] = textTypeChk($T_,$ID_TC);
|
||||
$chks[$idchk]['nameCheck'] = textTypeChk($ID_TC);
|
||||
|
||||
if ($onechk['manStatus'] != ''){
|
||||
$chks[$idchk]['uptime'] = 255;//255 = Maintenance I suppose, not implemented
|
||||
}else{
|
||||
$chks[$idchk]['uptime'] = getUptime($db_conn,$idchk);
|
||||
$chks[$idchk]['uptime'] = getUptime($idchk);
|
||||
}
|
||||
list($chks[$idchk]['statusText'],$chks[$idchk]['statusColor']) = getStatus($db_conn,$T_,$idchk);
|
||||
list($chks[$idchk]['statusText'],$chks[$idchk]['statusColor']) = getStatus($idchk);
|
||||
|
||||
}
|
||||
|
||||
@@ -82,6 +82,5 @@ while ($incident = dbw_fetch_array($db_conn,$incidents)){
|
||||
->text($incident['text']);
|
||||
$incs[$ID_N]['ID_N'] = $incident['ID_N'];
|
||||
}
|
||||
|
||||
echo $twig->render('indexpage.twig', array('T_' => $T_, 'you' => $you, 'checks' => $chks, 'news' => $incs)); //Render
|
||||
renderPage('indexpage.twig',array('you' => $you,'checks' => $chks, 'news' => $incs)); //Render
|
||||
?>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
define('VERSION','0.9.2');
|
||||
//define('INSTALLER_MODE','1');
|
||||
require_once 'lib/loadTwig.php';
|
||||
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
|
||||
38
load.php
Normal file
38
load.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
require_once 'functions.php'; //Preloads functions
|
||||
require_once 'lib/dbwrapper.php';
|
||||
define('VERSION','0.9.2');
|
||||
session_start(); //Session in all page
|
||||
//Preload file
|
||||
//This function loads all things needed, with optional db things if needed
|
||||
|
||||
function getconn(){
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (!is_file($db_file)){ //Go to install if not.
|
||||
header("Location: install.php");
|
||||
die();
|
||||
}
|
||||
return dbw_connect("sqlite",$db_file); //Database
|
||||
}
|
||||
|
||||
$db_conn = getconn();
|
||||
|
||||
/** Check if user SessionID exists, if not, delete Cookie */
|
||||
if (isset($_SESSION['UserID'])){
|
||||
$data = dbw_query_fetch_array($db_conn, "SELECT * FROM USERS WHERE ID_U='$_SESSION[UserID]'");
|
||||
if ($data['ID_U'] != $_SESSION['UserID']){
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
}
|
||||
|
||||
$you['ID_U'] = $data['ID_U'];
|
||||
$you['nick'] = $data['nick'];
|
||||
$you['fullRights'] = $data['fullRights'];
|
||||
$you['webRoot'] = webRoot();
|
||||
}
|
||||
define('LANG', getSystemOpt('lang'));
|
||||
|
||||
if (getSystemOpt('version') != VERSION){
|
||||
die("<p>Please run updater.php to update before using page");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
require "functions.php";
|
||||
require "load.php";
|
||||
|
||||
if (isset($_GET['do'])){
|
||||
if ($_GET['do'] == 'logout'){
|
||||
require_once "connect.php";
|
||||
//dbw_query($db_conn, "UPDATE USERS SET SessionID = NULL WHERE SessionID='$_COOKIE[SessionID]'");
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
}
|
||||
@@ -15,7 +13,7 @@ if (isset($_SESSION['UserID'])){ //Ya está logueado
|
||||
}
|
||||
|
||||
if (!isset($_POST['nick'])){
|
||||
echo $twig->render('login.twig');
|
||||
renderPage('login.twig');
|
||||
}
|
||||
if (isset($_POST['nick'])){
|
||||
$nick=$_POST['nick'];
|
||||
@@ -27,7 +25,7 @@ if (isset($_POST['nick'])){
|
||||
$_SESSION['UserID'] = $resql['ID_U'];
|
||||
header('Location: panel.php');
|
||||
}else{
|
||||
echo $twig->render('login.twig', array('status' => 'error'));
|
||||
renderPage('login.twig', array('status' => 'error'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
panel.php
35
panel.php
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once 'functions.php';
|
||||
require_once 'load.php';
|
||||
requirelogin();
|
||||
|
||||
//Calculo día 1 del mes en curso
|
||||
@@ -38,7 +38,7 @@ switch($page){
|
||||
$ID_G = $chks[$idchk]['ID_G']; //For nameGroup
|
||||
$chks[$idchk]['nameGroup'] = dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name'];
|
||||
$ID_TC = $chks[$idchk]['ID_TC'];
|
||||
$chks[$idchk]['nameTCheck'] = textTypeChk($T_,$ID_TC);
|
||||
$chks[$idchk]['nameTCheck'] = textTypeChk($ID_TC);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ switch($page){
|
||||
$emptyG[] = array('name' =>$emptygrp['name']);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_checks.twig', array('T_' => $T_, 'mpage' => 'checks','you' => $you, 'checks' => $chks,'groups' => $groups,'emptygrp' => $emptyG));
|
||||
renderPage('panel/p_checks.twig',array('mpage' => 'checks','you' => $you, 'checks' => $chks,'groups' => $groups,'emptygrp' => $emptyG));
|
||||
break;
|
||||
|
||||
//Forms to add or edit a check (Not saving, only forms)
|
||||
@@ -65,17 +65,18 @@ switch($page){
|
||||
foreach(arrayTypeChk() as $key => $value){
|
||||
$tchecks[] = array(
|
||||
'ID_TC' =>$key,
|
||||
'name' => textTypeChk($T_,$key)
|
||||
'name' => textTypeChk($key)
|
||||
);
|
||||
}
|
||||
|
||||
//En este if hago las diferencias entre add y edit, para no repetir código.
|
||||
if ($page == 'addcheck'){
|
||||
echo $twig->render('panel/p_addedit.twig', array('T_' => $T_, 'mpage' => 'checks', 'type' => 'new','groups' => $groups,'tchecks' => $tchecks));
|
||||
renderPage('panel/p_addedit.twig', array('mpage' => 'checks', 'type' => 'new','groups' => $groups,'tchecks' => $tchecks));
|
||||
}elseif ($page == 'editcheck'){
|
||||
$ID_C = (int)$_GET['ID_C']; //Check to edit
|
||||
$checkdata = dbw_query_fetch_array($db_conn,"SELECT * FROM CHECKS WHERE ID_C='$ID_C'"); //Checkdata
|
||||
echo $twig->render('panel/p_addedit.twig', array('T_' => $T_, 'mpage' => 'checks', 'you' => $you, 'type' => 'edit','groups' => $groups,'tchecks' => $tchecks,'check' => $checkdata));
|
||||
|
||||
renderPage('panel/p_addedit.twig', array('mpage' => 'checks', 'you' => $you, 'type' => 'edit','groups' => $groups,'tchecks' => $tchecks,'check' => $checkdata));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -144,8 +145,7 @@ switch($page){
|
||||
'checks' => $countchk
|
||||
);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_groups.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
||||
renderPage('panel/p_groups.twig', array('you' => $you, 'mpage' => 'groups', 'groups' => $groups));
|
||||
break;
|
||||
|
||||
case 'addgroup':
|
||||
@@ -186,8 +186,7 @@ switch($page){
|
||||
->text($result['text']);
|
||||
$news[$ID_N]['mdtext'] = $result['text']; //Raw text
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_news.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
||||
renderPage('panel/p_news.twig', array('you' => $you, 'mpage' => 'news', 'allnews' => $news));
|
||||
break;
|
||||
|
||||
case 'newnews':
|
||||
@@ -218,8 +217,7 @@ switch($page){
|
||||
while ($syso = dbw_fetch_array($db_conn,$results)){
|
||||
$sys[$syso['option']] = $syso['value'];
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_settings.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
||||
renderPage('panel/p_settings.twig', array('you' => $you, 'mpage' => 'settings', 'sys' => $sys));
|
||||
break;
|
||||
|
||||
case 'users':
|
||||
@@ -233,8 +231,7 @@ switch($page){
|
||||
'fullrights' => $us['fullRights']
|
||||
);
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_users.twig', array('T_' => $T_, 'mpage' => 'users', 'you' => $you, 'users' => $user));
|
||||
renderPage('panel/p_users.twig', array('mpage' => 'users', 'you' => $you, 'users' => $user));
|
||||
break;
|
||||
|
||||
case 'adduser':
|
||||
@@ -291,10 +288,10 @@ switch($page){
|
||||
}
|
||||
}
|
||||
|
||||
$group = nameGroupFromIDG($db_conn,IDGFromIDC($db_conn,$ID_C));
|
||||
$group = nameGroupFromIDG(IDGFromIDC($ID_C));
|
||||
$pagedata = array('cgood' => $cgood,'cbad' => $cbad,'name' => nameFromIDC($db_conn,$ID_C), 'group' => $group,'cant' => $cant,'fails' => $fails);
|
||||
|
||||
echo $twig->render('panel/p_viewhist.twig', array('T_' => $T_, 'mpage' => 'viewhist', 'you' => $you,'pagedata' => $pagedata));
|
||||
renderPage('panel/p_viewhist.twig', array('mpage' => 'viewhist', 'you' => $you,'pagedata' => $pagedata));
|
||||
break;
|
||||
|
||||
// Página principal
|
||||
@@ -310,8 +307,8 @@ switch($page){
|
||||
while ($fail = dbw_fetch_array($db_conn,$failssql)){ //Create array
|
||||
$fails[] = array (
|
||||
'ID_C' => $fail['ID_C'],
|
||||
'name' => nameFromIDC($db_conn,$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']),
|
||||
'errorText' => $fail['errorText'],
|
||||
'date' => date('j/n/Y',$fail['timestamp']),
|
||||
@@ -322,7 +319,7 @@ switch($page){
|
||||
$fails = array(); //Empty
|
||||
}
|
||||
|
||||
echo $twig->render('panel/p_index.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render
|
||||
renderPage('panel/p_index.twig', array('you' => $you, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
31
updater.php
31
updater.php
@@ -1,31 +0,0 @@
|
||||
<?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
|
||||
|
||||
$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.
|
||||
dbw_query($db_conn,"UPDATE SYS SET value='0.9.1' WHERE option='version'");
|
||||
case '0.9.1': //No db updates
|
||||
echo "<p>0.9.1->0.9.2<p>";
|
||||
dbw_query($db_conn,"UPDATE SYS SET value='0.9.2' WHERE option='version'");
|
||||
case '0.9.2':
|
||||
echo "0.9.2-Lastest";
|
||||
echo "<p>Updated to lastest. Close this and go to index</p>";
|
||||
//Remove files on a good update
|
||||
unlink('updater.php');
|
||||
unlink('installer.php');
|
||||
}
|
||||
Reference in New Issue
Block a user