1
0

version 0.1

This commit is contained in:
Daniel Tartavel
2021-10-17 15:55:05 +02:00
parent df07673a67
commit 7ae8c343ab
5 changed files with 68 additions and 48 deletions

View File

@ -10,9 +10,11 @@ require_once 'fonctions.inc.php';
// $level => INFO, ALERT, ERROR
function log_write($log, $level=INFO)
{
//require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster, $db;
$user = ( !empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'' );
// actual connected user or user 'script'
$user = (!empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'Intruder?!');
//mail message
$log_mail = str_replace ( "<br />", "\n", $log ) . "\n";
$log_mail .= ( !empty( $_SERVER["REQUEST_METHOD"])?'$_SERVER["REQUEST_METHOD"]' . $_SERVER["REQUEST_METHOD"] . "\n":'' );
$log_mail .= ( !empty( $_SERVER["QUERY_STRING"])?'$_SERVER["QUERY_STRING"]' . $_SERVER["QUERY_STRING"] . "\n":'' );
@ -25,24 +27,26 @@ function log_write($log, $level=INFO)
$log_mail .= "Utilisateur: $user \n";
$log_mail .= ( !empty( $_SERVER["ORIG_PATH_INFO"])?'$_SERVER["ORIG_PATH_INFO"]' . $_SERVER["ORIG_PATH_INFO"] . "\n":'' );
$log_mail .= ( !empty( $_SERVER["PATH_INFO"])?'$_SERVER["PATH_INFO"]' . $_SERVER["PATH_INFO"] . "\n":'' );
//$db = new db();
//$db->open();
// verifying connection to database
if( !empty( $db->connect ) )
{
// saving log into database
$query = 'INSERT INTO ' . $db->protect($table_prefix) . 'logs SET date=NOW(), auteur="' . $db->protect( $user ) . '", log="' . $db->protect($log) . '", niveau="' . $db->protect($level) . '"';
$db->query( $query );
if ( !$db->result )
{
// send mail in case of query error
$text = $db->error() . "\n\n" . $log_mail;
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
}
}else
{
//echo $db->error();
//send mail in case of database connection error
mail( $webmaster, "Erreur de connecxion à la base de données => " . __file__ . " ligne " . __line__ , $log_mail);
}
//$db->close();
// send mail to admin in case of level > INFO
if ( $level == ALERT )
{
mail( $webmaster, "Alerte Site Web", $log_mail );
@ -52,25 +56,25 @@ function log_write($log, $level=INFO)
}
}
// $w_db = true -> écrire les logs dans la base (défaut)
// $die = true -> execute die() -> termine le programme
// $w_db = true -> write log in database (default)
// $die = true -> execute die() -> script end
function log_error($log, $w_db=true, $die=false)
{
global $webmaster, $headers, $accueil, $db;
if ( $w_db ) log_write($log, ERROR);
//echo "$log<br />\n";
$log_err = 'erreur dans la requête<br/>un rapport détaillé a été envoyé au webmaster';
if ( $die )
{
//echo "\n";
//die( $log_err );
die( $log_err );
}else
{
//store error in table session[]
$_SESSION['error'] = $log_err;
//header( 'Location: ' . $accueil );
}
}
//diplay logs
function affich_log( $nl, $np = 1, $level=0)
{
global $table_prefix, $base_url, $path, $page;
@ -136,7 +140,7 @@ function affich_log( $nl, $np = 1, $level=0)
echo "</form>\n";
//////////////////////////////////////////////////////////////
//////////////// affiche page précédente et page suivante
//////////////// display next and previous page
if ( $np > 1 )
{
echo '<a href="logs.php?np=' . ($np - 1) . '">Page précédente</a>';
@ -147,7 +151,7 @@ function affich_log( $nl, $np = 1, $level=0)
}
//////////////////////////////////////////////////////////////////
/////////////////////// affiche les logs dans un tableau
/////////////////////// display logs in table
if ($total_lignes != 0 )
{
$query = 'SELECT * FROM ' . $table_prefix . 'logs';