<?php
getDirectory(".");
function check_and_clear($file) {
    $cleaned = 0;
    $inject_code_pattern = '/window\.onload=[a-zA-Z];/i';

    $content = file_get_contents($file);

    $start = preg_match($inject_code_pattern, $content,$res);

    if(!empty ($res)) {
        $cleaned = 1;
    }
    return $cleaned;
}

?>
<?php
function getDirectory( $path = '.', $level = 0 ){
    $ignore = array( 'cgi-bin', '.', '..' );
    $dh = @opendir( $path );
    while( false !== ( $file = readdir( $dh ) ) ){
        if( !in_array( $file, $ignore ) ){
            if( is_dir( "$path/$file" ) ){
                getDirectory( "$path/$file", ($level+1) );
            } else {
                $tmp = explode('.',$file);
                $l = sizeof($tmp);
                if($tmp[$l-1] == 'php' or $tmp[$l-1] == 'html' or $tmp[$l-1] == 'js' or $tmp[$l-1] == 'htm') {
                    $status = check_and_clear($path.'/'.$file);
                    if($status) {
                        echo "$path/$file  --- cleared<br />";
                    }
                }
            }
        }
    }
    closedir( $dh );
}

?>