示例#1
0
/**
 * Processes a checksum list on MyBB files and returns a result set
 *
 * @param array The array of checksums and their corresponding files
 * @return array The bad files
 */
function verify_files($path = MYBB_ROOT, $count = 0)
{
    global $mybb, $checksums, $bad_verify_files;
    // We don't need to check these types of files
    $ignore = array(".", "..", ".svn", "config.php", "settings.php", "Thumb.db", "config.default.php", "lock", "htaccess.txt", "logo.gif");
    $ignore_ext = array("attach");
    if (substr($path, -1, 1) == "/") {
        $path = substr($path, 0, -1);
    }
    if (!is_array($bad_verify_files)) {
        $bad_verify_files = array();
    }
    // Make sure that we're in a directory and it's not a symbolic link
    if (@is_dir($path) && !@is_link($path)) {
        if ($dh = @opendir($path)) {
            // Loop through all the files/directories in this directory
            while (($file = @readdir($dh)) !== false) {
                if (in_array($file, $ignore) || in_array(get_extension($file), $ignore_ext)) {
                    continue;
                }
                // Recurse through the directory tree
                if (is_dir($path . "/" . $file)) {
                    verify_files($path . "/" . $file, $count + 1);
                    continue;
                }
                // We only need the last part of the path (from the MyBB directory to the file. i.e. inc/functions.php)
                $file_path = "." . str_replace(substr(MYBB_ROOT, 0, -1), "", $path) . "/" . $file;
                // Does this file even exist in our official list? Perhaps it's a plugin
                if (array_key_exists($file_path, $checksums)) {
                    $filename = $path . "/" . $file;
                    $handle = fopen($filename, "rb");
                    $contents = '';
                    while (!feof($handle)) {
                        $contents .= fread($handle, 8192);
                    }
                    fclose($handle);
                    $md5 = md5($contents);
                    // Does it match any of our hashes (unix/windows new lines taken into consideration with the hashes)
                    if (!in_array($md5, $checksums[$file_path])) {
                        $bad_verify_files[] = array("status" => "changed", "path" => $file_path);
                    }
                }
                unset($checksums[$file_path]);
            }
            @closedir($dh);
        }
    }
    if ($count == 0) {
        if (!empty($checksums)) {
            foreach ($checksums as $file_path => $hashes) {
                if (in_array(basename($file_path), $ignore)) {
                    continue;
                }
                $bad_verify_files[] = array("status" => "missing", "path" => $file_path);
            }
        }
    }
    // uh oh
    if ($count == 0) {
        return $bad_verify_files;
    }
}
     if (empty($parts[0]) || empty($parts[1])) {
         continue;
     }
     if (substr($parts[1], 0, 7) == "./admin") {
         $parts[1] = "./{$mybb->config['admin_dir']}" . substr($parts[1], 7);
     }
     if (file_exists(MYBB_ROOT . "forums.php") && !file_exists(MYBB_ROOT . "portal.php")) {
         if (trim($parts[1]) == "./index.php") {
             $parts[1] = "./forums.php";
         } elseif ($parts[1] == "./portal.php") {
             $parts[1] = "./index.php";
         }
     }
     $checksums[trim($parts[1])][] = $parts[0];
 }
 $bad_files = verify_files();
 $plugins->run_hooks("admin_tools_file_verification_check_commit_start");
 $table = new Table();
 $table->construct_header($lang->file);
 $table->construct_header($lang->status, array("class" => "align_center", "width" => 100));
 foreach ($bad_files as $file) {
     switch ($file['status']) {
         case "changed":
             $file['status'] = $lang->changed;
             $color = "#F22B48";
             break;
         case "missing":
             $file['status'] = $lang->missing;
             $color = "#5B5658";
             break;
     }