xx Find core dump files easily.
June 10, 2008, 05:13:38 pm by grant
I had the problem of trying to track down core dump files on my hosting account that were taking up space.  I came up with this script.  Just set your username.  You can also specify the directory.  I'm on shared hosting so username is appended to /home/ to get to my account.  Then you can view all the files and delete the ones you select using the password you put in the configuration.  Simple.

Code: (php)
<?php
/***********Configuration**************/
$username 'username';
$password 'password';  //any random password.  don't store your account password in a file like this, make a new one up!
/***********End of Config**************/
$file_to_find 'core';
$script_start microtime_float();
$directory '/home/'$username;
$self $_SERVER['PHP_SELF'];
if ( !isset( 
$_POST['submit'] )){
    
$core_files listdir$directory $file_to_find );
    
$script_end microtime_float();
    
$execution_time bcsub$script_end $script_start );
    
$form = <<<EOT
    <form action="{$self}" method="post"><p>
$core_files
    Password: <input type="password" name="password" /><br />
    <input type="submit" value="Delete Selected" name="submit" /></p>
    </form>
EOT;
    echo 
page"Core files in $directory"$form $execution_time );
}
else if ( isset( 
$_POST['password'] )){
    if ( 
$password == $_POST['password'] ){
        
$auth true;
    }
    else{
        
$auth false;
        
$script_end microtime_float();
        
$execution_time bcsub$script_end $script_start );
        echo 
page'Wrong Password!' "You entered the wrong password.<br />\r\n <a href=\"$self\">Home</a>\r\n"$execution_time );
    }
}
if ( isset( 
$_POST['file']) && $auth){
    
$files $_POST['file'];
    
$size sizeof$files );
    
$j 0;
    for( 
$i $i $size $i++){
        if ( 
is_core$files[$i] , $file_to_find )){
            
$deleted[$j] = array( => $files[$i], => unlink$files[$i] ));
            
$j++;
        }
    }
    
$content .= '
    Deleted:<br /><ol>'
;
    for ( 
$i $i sizeof$deleted ); $i++ ){
        
$content .= '<li>' $deleted[$i][0] .' was ';
        if ( 
$deleted[$i][1] ){
            
$content .= 'successfully deleted.</li>' "\r\n";
        }
        else{
            
$content .= 'not deleted.</li>' "\r\n";
        }
    }
    
$content .= '</ol>'"\r\n" .'<a href="'$self .'">Home</a>';
    
$script_end microtime_float();
    
$execution_time bcsub$script_end $script_start );
    echo 
page"Files deleted from $directory" $content $execution_time );
}
else if( !isset( 
$_POST['file'] ) && $auth ){
    
$script_end microtime_float();
    
$execution_time bcsub$script_end $script_start );
    echo 
page'Nothing to do!' 'No core files found!' "<br />\r\n<a href=\"$self\">Home</a>" $execution_time );
}
function 
page$title $content $execution ){
    
$page = <<<EOT
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$title</title>
</head>
<body>
  <div>
$content
    <br />
    Script executed in $execution seconds.
  </div>
</body>
</html>
EOT;
    return $page;
}
function listdir( $dir , $find ){
    $handle = opendir($dir);
    while(false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".."){
            $fname = $dir .'/'. $file;
        if( is_link( $fname )){
            //do nothing
            }       
            else{
                if( is_dir( $fname )) {
            $output .= listdir( $fname , $find );
                }
                if( is_core( $fname , $find )){
                    $output .= '    <input type="checkbox" name="file[]" value="'. $dir .'/'. $file .'" />' . $dir .'/'. $file . "<br />\r\n";
                }
            }
        }
    }
    closedir($handle);
    return $output;
}
function is_core( $filename , $find ){
    $pieces = explode('/', $filename);
    $length = sizeof( $pieces );
    $c_pieces = explode('.' , $pieces[$length - 1] );
    if ( in_array( $find , $c_pieces ) && file_exists( $filename )){
        if ( is_numeric( $c_pieces[1] )){
            return true;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
}
function microtime_float(){
    list($utime, $time) = explode(" ", microtime());
    return ((float)$utime + (float)$time);
}
?>
0 comments | Write Comment

lamp Email
February 13, 2008, 08:52:54 pm by grant
http://www.grantgarvey.com/email/

This is a simple script which will make an image of your email address to make it less readable by robots that will spam you.


0 comments | Write Comment

grin 101Deaths.com
February 13, 2008, 08:48:13 pm by grant
http://www.101Deaths.com

Comics!
Dilbert

Get Fuzzy
0 comments | Write Comment