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"]:'' ); $log_mail = str_replace ( "
", "\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":'' ); //$db = new db(); //$db->open(); if( !empty( $db->connect ) ) { $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 = $db->error() . "\n\n" . $log_mail; mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text ); } }else { //echo $db->error(); mail( $webmaster, "Erreur de connecxion à la base de données => " . __file__ . " ligne " . __line__ , $log_mail); } //$db->close(); if ( $level == ALERT ) { mail( $webmaster, "Alerte Site Web", $log_mail ); }elseif ( $level == ERROR ) { mail( $webmaster, "Erreur Site Web", $log_mail ); } } // $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); //echo "$log
\n"; $log_err = 'erreur dans la requête
un rapport détaillé a été envoyé au webmaster'; if ( $die ) { //echo "\n"; //die( $log_err ); }else { $_SESSION['error'] = $log_err; //header( 'Location: ' . $accueil ); } } function affich_log( $nl, $np = 1, $level=0) { global $table_prefix, $base_url, $path, $page; $db = new db(); if( !empty( $db->connect ) ) { $level_s = array( "aucun", "info", "alerte", "erreur" ); if ($level < 0 or $level >3) $level = 0; $query = 'SELECT * FROM ' . $table_prefix . 'logs'; if ( $level != 0 ) { $query .= " WHERE niveau=" . $level ; } $query .= ' ORDER BY id_log DESC'; $db->query($query); $total_lignes = $db->result->num_rows; /////////////:: Calcule le nombre de pages de logs $n_pages = round( $total_lignes / $nl ); if ( $np == 0 ) { $np = 1; }elseif ( $np > $n_pages ) { $np = $n_pages; } ////////////////////////////////////////////////////// ////////////////////////// Bouton de choix du niveau de log echo "\n" . '
'; echo "niveau de log" . ' '; echo "
\n"; ///////////////////////////////////////////////////////// // Bouton de choix du numéro de page echo "\n" . '
'; echo 'Page n° '; echo "
\n"; ////////////////////////////////////////////////////////////// //////////////// affiche page précédente et page suivante if ( $np > 1 ) { echo 'Page précédente'; } if ( $np < $n_pages ) { echo ' Page suivante'; } ////////////////////////////////////////////////////////////////// /////////////////////// affiche les logs dans un tableau if ($total_lignes != 0 ) { $query = 'SELECT * FROM ' . $table_prefix . 'logs'; if ( $level != 0 ) { $query .= " WHERE niveau='" . $level . "'"; } $query .= ' ORDER BY id_log DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl; $db->query( $query ); echo "\n"; while ( ($donnees =$db->result->fetch_array()) ) { $niveau = $donnees["niveau"]; echo "\n"; } echo "
dateauteurlogniveau
" . $donnees["date"] . "" . $donnees["auteur"] . "" . htmlentities($donnees["log"], ENT_QUOTES) . "" . $level_s[ $niveau ] . "
\n"; }else { print "aucune réponse"; } } } ?>