home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / checksum.php < prev    next >
Encoding:
PHP Script  |  2008-02-02  |  2.0 KB  |  71 lines

  1. <?php
  2. /**
  3. * XOOPS installation md5 checksumminig script
  4. *
  5. * This script allows you to check that the XOOPS system files have been correctly uploaded.
  6. * It reads all the XOOPS files and reports missing or invalid ones.
  7. * Instructions:
  8. * - Upload this script and xoops.md5 to your XOOPS documents root
  9. * - Access it using a browser
  10. * - Re-upload missing/invalid files
  11. *
  12. * @copyright    The XOOPS Project http://xoops.sf.net/
  13. * @license      http://www.fsf.org/copyleft/gpl.html GNU public license
  14. * @author       Skalpa Keo <skalpa@xoops.org>
  15. * @author       phppp <phppp@users.sourceforge.net>
  16. * @since        2.0.14
  17. * @version        $Id $
  18. * @package         xoops
  19. */
  20.  
  21. error_reporting( 0 );
  22.  
  23. header( "Content-type: text/plain" );
  24.  
  25. $md5_file = "./checksum.md5";
  26. $root = ( is_dir("./htdocs") ? "./htdocs" : "." );
  27. if ( isset($_GET["root"]) && false === strpos($_GET["root"], "..") ) {
  28.     $root .= "/" . $_GET["root"];
  29.     $md5_file = "./checksum.".str_replace("/", "-", $_GET["root"]).".md5";
  30. }
  31. $num_files = check_folder($root);
  32.  
  33. echo "There are {$num_files} files checked.\n";
  34. echo "Please remove the file $md5_file and ".basename(__FILE__)." as soon as possible.\n";
  35.  
  36. function check_file ($line, $path = ".") 
  37. {
  38.     list( $file, $sum ) = explode( ":", $line, 2 );
  39.     if ( substr( $file, 0, 7 ) == 'htdocs/' ) {
  40.         $file = substr( $file, 7 );
  41.     } else {
  42.         $file = $path."/".$file;
  43.     }
  44.     if ( !file_exists( $file ) ) {
  45.         echo "$file missing !\n";
  46.     } else {
  47.         $txt = file_get_contents( "$file" );
  48.         $txt = str_replace( array( "\r\n", "\r" ), "\n", $txt );
  49.         if ( md5($txt) != $sum ) {
  50.             echo "$file content invalid\n";
  51.         }
  52.     }
  53. }
  54.  
  55. function check_folder( $path = '.', $recursive = false ) {
  56.     global $md5_file;
  57.     $num_files = 0;
  58.     if ( !is_file( $md5_file ) || !is_readable( $md5_file ) ) {
  59.         echo "$md5_file file not found.\n";
  60.         return false;
  61.     }
  62.     $sums = explode( "\n", rtrim( file_get_contents( $md5_file ) ) );
  63.     foreach ( $sums as $line ) {
  64.         check_file ($line, $path);
  65.         $num_files ++;
  66.     }
  67.     
  68.     return $num_files;
  69. }
  70.