2021-03-22 12:20:39 +01:00
< ? php
if ( ! isset ( $site ) )
{
require_once ( " config.inc.php " );
header ( 'Location: ' . $accueil );
}
2021-03-23 20:26:52 +01:00
require_once 'db.class.php' ;
require_once 'envoi_courriel.inc.php' ;
2021-03-22 12:20:39 +01:00
// $level => INFO, ALERT, ERROR
function log_write ( $log , $level = INFO )
{
2021-04-29 10:32:58 +02:00
//require_once( "envoi_courriel.inc.php" );
global $table_prefix , $webmaster , $db ;
2021-03-22 12:20:39 +01:00
$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 " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " QUERY_STRING " ]) ? '$_SERVER["QUERY_STRING"]' . $_SERVER [ " QUERY_STRING " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ]) ? '$_SERVER["HTTP_ACCEPT_LANGUAGE"]' . $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " HTTP_USER_AGENT " ]) ? '$_SERVER["HTTP_USER_AGENT"]' . $_SERVER [ " HTTP_USER_AGENT " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " REMOTE_ADDR " ]) ? '$_SERVER["REMOTE_ADDR"]' . $_SERVER [ " REMOTE_ADDR " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " REMOTE_HOST " ]) ? '$_SERVER["REMOTE_HOST"]' . $_SERVER [ " REMOTE_HOST " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " REMOTE_USER " ]) ? '$_SERVER["REMOTE_USER"]' . $_SERVER [ " REMOTE_USER " ] . " \n " : '' );
$log_mail .= ( ! empty ( $_SERVER [ " REQUEST_URI " ]) ? '$_SERVER["REQUEST_URI"]' . $_SERVER [ " REQUEST_URI " ] . " \n " : '' );
$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 " : '' );
2021-04-29 10:32:58 +02:00
//$db = new db();
//$db->open();
if ( ! empty ( $db -> connect ) )
2021-03-22 12:20:39 +01:00
{
2021-04-29 10:32:58 +02:00
$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 )
2021-03-22 12:20:39 +01:00
{
2021-04-29 10:32:58 +02:00
$text = $db -> error () . " \n \n " . $log_mail ;
mail ( $webmaster , " Erreur écriture logs => " . __file__ . " ligne " . __line__ , $text );
2021-03-22 12:20:39 +01:00
}
2021-04-29 10:32:58 +02:00
2021-03-22 12:20:39 +01:00
} else
{
2021-07-24 10:18:09 +02:00
//echo $db->error();
mail ( $webmaster , " Erreur de connecxion à la base de données => " . __file__ . " ligne " . __line__ , $log_mail );
2021-03-22 12:20:39 +01:00
}
2021-04-29 10:32:58 +02:00
//$db->close();
2021-03-22 12:20:39 +01:00
if ( $level == ALERT )
{
2021-04-29 10:32:58 +02:00
mail ( $webmaster , " Alerte Site Web " , $log_mail );
2021-03-22 12:20:39 +01:00
} elseif ( $level == ERROR )
{
2021-04-29 10:32:58 +02:00
mail ( $webmaster , " Erreur Site Web " , $log_mail );
2021-03-22 12:20:39 +01:00
}
}
// $w_db = true -> écrire les logs dans la base (défaut)
// $die = true -> execute die() -> termine le programme
function log_error ( $log , $w_db = true , $die = false )
{
global $webmaster , $headers , $accueil , $db ;
if ( $w_db ) log_write ( $log , ERROR );
2021-04-29 10:32:58 +02:00
//echo "$log<br />\n";
2021-03-22 12:20:39 +01:00
$log_err = 'erreur dans la requête<br/>un rapport détaillé a été envoyé au webmaster' ;
if ( $die )
{
2021-04-29 10:32:58 +02:00
//echo "\n";
//die( $log_err );
2021-03-22 12:20:39 +01:00
} else
{
$_SESSION [ 'error' ] = $log_err ;
//header( 'Location: ' . $accueil );
}
}
2021-04-29 10:32:58 +02:00
function affich_log ( $nl , $np = 1 , $level = 0 )
2021-03-22 12:20:39 +01:00
{
global $table_prefix , $base_url , $path , $page ;
2021-04-29 10:32:58 +02:00
$db = new db ();
if ( ! empty ( $db -> connect ) )
2021-03-22 12:20:39 +01:00
{
2021-07-24 10:18:09 +02:00
$level_s = array ( " aucun " , " info " , " alerte " , " erreur " );
if ( $level < 0 or $level > 3 ) $level = 0 ;
$query = 'SELECT * FROM ' . $table_prefix . 'logs' ;
2021-03-22 12:20:39 +01:00
if ( $level != 0 )
{
2021-07-24 10:18:09 +02:00
$query .= " WHERE niveau= " . $level ;
2021-03-22 12:20:39 +01:00
}
2021-07-24 10:18:09 +02:00
$query .= ' ORDER BY id_log DESC' ;
2021-04-29 10:32:58 +02:00
$db -> query ( $query );
$total_lignes = $db -> result -> num_rows ;
2021-07-24 10:18:09 +02:00
/////////////:: Calcule le nombre de pages de logs
$n_pages = round ( $total_lignes / $nl );
if ( $np == 0 )
{
$np = 1 ;
} elseif ( $np > $n_pages )
2021-03-22 12:20:39 +01:00
{
2021-07-24 10:18:09 +02:00
$np = $n_pages ;
}
//////////////////////////////////////////////////////
2021-03-22 12:20:39 +01:00
2021-07-24 10:18:09 +02:00
////////////////////////// Bouton de choix du niveau de log
echo " \n " . '<form action="none" method="post" enctype="multipart/form-data">' ;
echo " niveau de log " . ' <select id="level" size="0" onchange="window.location.href = \'logs.php?np=\' + document.getElementById(\'np\').value + \'&level=\' + document.getElementById(\'level\').value ;">' ;
2021-03-22 12:20:39 +01:00
2021-07-24 10:18:09 +02:00
for ( $n = 0 ; $n <= count ( $level_s ) - 1 ; $n ++ )
{
echo '<option value="' . $n . '"' ;
if ( $n == $level )
2021-03-22 12:20:39 +01:00
{
2021-07-24 10:18:09 +02:00
echo ' selected="selected"' ;
2021-03-22 12:20:39 +01:00
}
2021-07-24 10:18:09 +02:00
echo '>' . $level_s [ $n ] . '</option>' ;
}
echo '</select><noscript><input type="submit" name="submit" Value="none" /></noscript>' ;
echo " </form> \n " ;
2021-03-22 12:20:39 +01:00
2021-07-24 10:18:09 +02:00
/////////////////////////////////////////////////////////
// Bouton de choix du numéro de page
echo " \n " . '<form action="none" method="post" enctype="multipart/form-data">' ;
echo 'Page n° <select id="np" name="np" size="0" onchange="window.location.href = \'logs.php?np=\' + document.getElementById(\'np\').value + \'&level=\' + document.getElementById(\'level\').value ;">' ;
for ( $n = 1 ; $n <= $n_pages ; $n ++ )
{
echo '<option value="' . $n . '"' ;
if ( $n == $np )
2021-03-22 12:20:39 +01:00
{
2021-07-24 10:18:09 +02:00
echo ' selected="selected"' ;
2021-03-22 12:20:39 +01:00
}
2021-07-24 10:18:09 +02:00
echo '>' . $n . '</option>' ;
}
echo '</select><noscript><input type="submit" name="submit" Value="Envoyer" /></noscript>' ;
echo " </form> \n " ;
//////////////////////////////////////////////////////////////
2021-03-22 12:20:39 +01:00
2021-07-24 10:18:09 +02:00
//////////////// affiche page précédente et page suivante
if ( $np > 1 )
{
echo '<a href="logs.php?np=' . ( $np - 1 ) . '">Page précédente</a>' ;
}
if ( $np < $n_pages )
{
echo ' <a href="logs.php?np=' . ( $np + 1 ) . '">Page suivante</a>' ;
}
//////////////////////////////////////////////////////////////////
/////////////////////// affiche les logs dans un tableau
if ( $total_lignes != 0 )
{
2021-03-22 12:20:39 +01:00
$query = 'SELECT * FROM ' . $table_prefix . 'logs' ;
if ( $level != 0 )
{
$query .= " WHERE niveau=' " . $level . " ' " ;
}
2021-05-31 12:27:51 +02:00
$query .= ' ORDER BY id_log DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl ;
2021-04-29 10:32:58 +02:00
$db -> query ( $query );
2021-03-22 12:20:39 +01:00
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 " ;
2021-04-29 10:32:58 +02:00
while ( ( $donnees = $db -> result -> fetch_array ()) )
2021-03-22 12:20:39 +01:00
{
$niveau = $donnees [ " niveau " ];
2021-07-24 10:18:09 +02:00
echo " <tr><td> " . $donnees [ " date " ] . " </td><td> " . $donnees [ " auteur " ] . " </td><td> " . htmlentities ( $donnees [ " log " ], ENT_QUOTES ) . " </td><td> " . $level_s [ $niveau ] . " </td></tr> \n " ;
2021-03-22 12:20:39 +01:00
}
echo " </table> \n " ;
} else
{
2021-07-24 10:18:09 +02:00
print " aucune réponse " ;
2021-03-22 12:20:39 +01:00
}
}
}
?>