1
0
This commit is contained in:
Daniel Tartavel
2021-04-29 10:32:58 +02:00
parent 37d8c8b64f
commit 7e015a3d1b
14 changed files with 504 additions and 238 deletions

View File

@ -10,8 +10,8 @@ require_once 'envoi_courriel.inc.php';
// $level => INFO, ALERT, ERROR
function log_write($log, $level=INFO)
{
require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster;
//require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster, $db;
$user = ( !empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'' );
$log_mail = str_replace ( "<br />", "\n", $log ) . "\n";
$log_mail .= ( !empty( $_SERVER["REQUEST_METHOD"])?'$_SERVER["REQUEST_METHOD"]' . $_SERVER["REQUEST_METHOD"] . "\n":'' );
@ -25,29 +25,30 @@ 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":'' );
$db1 = new db();
$db1->open();
if( !empty( $db1->connect ) )
//$db = new db();
//$db->open();
if( !empty( $db->connect ) )
{
$query = 'INSERT INTO ' . $db1->protect($table_prefix) . 'logs SET date=NOW(), auteur="' . $db1->protect( $user ) . '", log="' . $db1->protect($log) . '", niveau="' . $db1->protect($level) . '"';
$db1->query( $query );
if ( !$db1->result )
$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 )
{
$text = $db1->error() . "\n\n" . $log_mail;
envoiMail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
$text = $db->error() . "\n\n" . $log_mail;
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
}
$db1->close();
}else
{
echo $db1->error();
envoiMail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__ , $log_mail);
echo $db->error();
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__ , $log_mail);
}
//$db->close();
if ( $level == ALERT )
{
envoiMail( $webmaster, "Alerte Site Web", $log_mail );
mail( $webmaster, "Alerte Site Web", $log_mail );
}elseif ( $level == ERROR )
{
envoiMail( $webmaster, "Erreur Site Web", $log_mail );
mail( $webmaster, "Erreur Site Web", $log_mail );
}
}
@ -57,12 +58,12 @@ 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";
//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 );
//echo "\n";
//die( $log_err );
}else
{
$_SESSION['error'] = $log_err;
@ -70,19 +71,20 @@ function log_error($log, $w_db=true, $die=false)
}
}
function affich_log( $nl, $np = 1, $level=INFO )
function affich_log( $nl, $np = 1, $level=0)
{
global $table_prefix, $base_url, $path, $page;
if( !empty( $db->open() ) )
$db = new db();
if( !empty( $db->connect ) )
{
$level_s = array( "aucun" , "info" , "alerte" , "erreur" );
$query = 'SELECT * FROM ' . $table_prefix . 'logs';
$query = 'SELECT * FROM ' . $table_prefix . 'logs ORDER BY id_log DESC';
if ( $level != 0 )
{
$query .= " WHERE niveau='" . $db->protect($level) . "'";
}
$db->query($query) OR log_error($db->error() . "<br />" . __file__ . " ligne " . __line__ );
$total_lignes = $db->result->num_rows();
$db->query($query);
$total_lignes = $db->result->num_rows;
if ($total_lignes != 0 )
{
@ -139,9 +141,9 @@ function affich_log( $nl, $np = 1, $level=INFO )
}
$query .= ' ORDER BY date DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl;
$db->query( $query ) OR log_error( $db->error( ) . "<br />" . __file__ . " ligne " . __line__ );
$db->query( $query );
echo "<table border='1' width='90%'><tr><td><b>date</b></td><td><b>auteur</b></td><td><b>log</b></td><td><b>niveau</b></td></tr>\n";
while ( $db->connect->mysqli_fetch_array( $db->result ) )
while ( ($donnees =$db->result->fetch_array()) )
{
$niveau = $donnees["niveau"];
echo "<tr><td>" . $donnees["date"] . "</td><td>" . $donnees["auteur"] . "</td><td>" . $donnees["log"] . "</td><td>" . $level_s[ $niveau ] . "</td></tr>\n";