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 , 4 );
$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 , 4 );
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 = 0 ; $i < $size ; $i++){
if ( is_core( $files[$i] , $file_to_find )){
$deleted[$j] = array( 0 => $files[$i], 1 => unlink( $files[$i] ));
$j++;
}
}
$content .= '
Deleted:<br /><ol>';
for ( $i = 0 ; $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 , 4 );
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 , 4 );
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);
}
?>
/***********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 , 4 );
$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 , 4 );
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 = 0 ; $i < $size ; $i++){
if ( is_core( $files[$i] , $file_to_find )){
$deleted[$j] = array( 0 => $files[$i], 1 => unlink( $files[$i] ));
$j++;
}
}
$content .= '
Deleted:<br /><ol>';
for ( $i = 0 ; $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 , 4 );
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 , 4 );
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);
}
?>



