2009-11-01 11:00:00 +00:00
< html >
< head >
< title >.: Halo - Battle :: V & eacute ; rification de l ' int & eacute ; grit & eacute ; des fichiers :.</ title >
</ head >
< body >
< h2 > V & eacute ; rification de l ' int & eacute ; grit & eacute ; des fichiers </ h2 >
< ? php
2020-11-21 18:54:32 +00:00
define ( 'FILE_SAV' , " ../onyx2/cache/checksum.php " );
define ( 'dir_start' , " ../ " );
2009-11-01 11:00:00 +00:00
print 'Chargement du fichier de comparaison ...' ;
2020-11-21 18:54:32 +00:00
if ( is_file ( 'checkSum.php' )) {
print ' Touvé ...' ;
$SUM = sha1 ( file_get_contents ( 'checkSum.php' ));
print ' Données chargées avec succès<br /><br />' ;
}
2009-11-01 11:00:00 +00:00
print 'Vérification du fichier de validation ...' ;
2020-11-21 18:54:32 +00:00
if ( sha1 ( sha1_file ( __FILE__ )) != $SUM ) {
2009-11-01 11:00:00 +00:00
die ( ' INVALIDE !<br />Arrêt du processus de validation !' );
2020-11-21 18:54:32 +00:00
} else {
2009-11-01 11:00:00 +00:00
print ' Valide<br /><br />' ;
2020-11-21 18:54:32 +00:00
}
2009-11-01 11:00:00 +00:00
print 'Recherche du fichier de sauvegarde ...' ;
2020-11-21 18:54:32 +00:00
if ( is_file ( FILE_SAV ) && ! isset ( $_GET [ 'erase' ])) {
function parcourDir ( $dir , $sums )
2009-11-01 11:00:00 +00:00
{
2020-11-21 18:54:32 +00:00
if ( isset ( $_GET [ 'v' ])) {
print " <br />Parcours du dossier à la recherche de nouveaux fichiers : " . $dir ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
$new = 0 ;
$pointeur = opendir ( $dir );
while ( $fichier = readdir ( $pointeur )) {
if ( $fichier == '.' || $fichier == '..' || $fichier == '.svn' || preg_match ( " #~# " , $fichier )) {
continue ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
if ( is_dir ( $dir . $fichier ) && is_readable ( $dir . $fichier )) {
$new += parcourDir ( $dir . $fichier . '/' , $sums );
} elseif ( is_file ( $dir . $fichier )) {
if ( ! isset ( $sums [ $dir . $fichier ])) {
$new ++ ;
print " <tr style= \" background: #00FFFF; \" ><td> " . $dir . $fichier . " </td><td style= \" text-align: center; \" >Nouveau fichier !</td></tr> " ;
}
2009-11-01 11:00:00 +00:00
}
2020-11-21 18:54:32 +00:00
}
closedir ( $pointeur );
return $new ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print ' Trouvé<br /><br />' ;
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
if ( isset ( $_GET [ " check " ])) {
print 'Contrôle de la somme de la dernière validation ...' ;
if ( sha1 ( sha1_file ( FILE_SAV ) . '<^>' . sha1_file ( __FILE__ ) . sha1_file ( 'checkSum.php' )) == $_GET [ " check " ]) {
print ' <span style="color: #00FF00;">Authentique</span><br /><br />' ;
} else {
die ( ' Invalide !<br />Arrêt du processus de vérification !' );
}
} else {
print '<span style="color: #FF0000; font-weigth: bold;">Les résultats présentés ci-dessus ne peuvent pas être authentifiés sans la somme d\'un précédent contrôle, rien ne dit que les fichiers de validation n\'ont pas été modifiés !</span><br /><br />' ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
$start = unserialize ( file_get_contents ( FILE_SAV ));
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print ' Vérification des fichiers ...' ;
print '<table border="1" style=""><tr><th>Nom du fichier</th><th>Détails</th></tr>' ;
$alerte = 0 ;
foreach ( $start as $key => $sum ) {
if ( ! is_file ( $key )) {
$alerte ++ ;
if ( ! isset ( $_GET [ 'a' ])) {
print " <tr style= \" background: #FFCC00; \" ><td> " . $key . " </td><td style= \" text-align: center; \" >Fichier supprimé !</td></tr> " ;
2009-11-01 11:00:00 +00:00
}
2020-11-21 18:54:32 +00:00
} elseif ( sha1_file ( $key ) != $sum ) {
$alerte ++ ;
print " <tr style= \" background: #FF0000; \" ><td> " . $key . " </td><td style= \" text-align: center; \" >Alerte de différence de somme !</td></tr> " ;
} elseif ( isset ( $_GET [ 'v' ])) {
print " <tr style= \" background: #00FF00; \" ><td> " . $key . " </td><td style= \" text-align: center; \" >Ok</td></tr> " ;
}
}
$newFiles = parcourDir ( dir_start , $start );
print '</table>' ;
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print '<br />Fin de la vérification : ' . $alerte . ' alerte(s) sur ' . count ( $start ) . ' fichier(s). ' . $newFiles . ' nouveau(x) fichier(s).' ;
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print '<br /><br />Contôle de la prochaine validation : ' . sha1 ( sha1_file ( FILE_SAV ) . '<^>' . sha1_file ( __FILE__ ) . sha1_file ( 'checkSum.php' ));
} else {
if ( isset ( $_GET [ 'erase' ]) && $_GET [ 'erase' ] == $SUM ) {
print ' Trouvé<br />Détection d\'une demande d\'effacement<br /><br />' ;
} elseif ( ! is_file ( FILE_SAV )) {
//print ' Introuvable<br /><br />';
die ( ' Introuvable<br /><br />Arrêt de la vérification.' );
} else {
die ( ' ?<br /><br />Impossible de déterminer l\'origine de la requête !<br />Arrêt de la vérification.' );
2009-11-01 11:00:00 +00:00
}
2020-11-21 18:54:32 +00:00
function extractDir ( $dir )
{
$sums = array ();
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
if ( isset ( $_GET [ 'v' ])) {
print " <br />Génération des sommes de fichiers pour le dossier : " . $dir ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
$pointeur = opendir ( $dir );
while ( $fichier = readdir ( $pointeur )) {
if ( $fichier == '.' || $fichier == '..' || $fichier == '.svn' || preg_match ( " #~# " , $fichier )) {
continue ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
if ( is_dir ( $dir . $fichier ) && is_readable ( $dir . $fichier )) {
$sums = array_merge ( $sums , extractDir ( $dir . $fichier . '/' ));
} elseif ( is_file ( $dir . $fichier )) {
$sums [ $dir . $fichier ] = sha1_file ( $dir . $fichier );
2009-11-01 11:00:00 +00:00
}
2020-11-21 18:54:32 +00:00
}
closedir ( $pointeur );
return $sums ;
}
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print 'Génération du tableau ...' ;
$sums = array ();
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
$sums = extractDir ( dir_start );
2009-11-01 11:00:00 +00:00
2020-11-21 18:54:32 +00:00
print " Écriture du fichier.<br /> " ;
file_put_contents ( FILE_SAV , serialize ( $sums ));
print " Fin de l'opération.<br /> " ;
}
2009-11-01 11:00:00 +00:00
?>
</ body >
</ html >