\n~;
}
# Begin list files.
sub list_files {
chdir($data_path);
$du = `du`;
@pairs = split(/\n/,$du);
foreach (@pairs) {
@terms = split(/\s+/);
$size = $terms[0] / 2;
@parts = split(/\.\//, $terms[1]);
if ($size < 1000) {
$SIZE{$parts[1]} = $size . "k"; }
else { $SIZE{$parts[1]} = sprintf("%.2f", $size / 1000) . "m"; }}
$ls = `ls -a`;
@ls = split(/\s+/,$ls);
&header;
print qq~
Contents of:
~;
if ($dirname) { print "$dirname"; }
else { print "Root"; }
print " ";
if ($action) {
print qq~
Action:
$report ~;
}
print "
\n~; }
&footer;
# Begin check file extension.
sub Check_Ext {
$ext_file = $_[0];
@ext_parts = split(/\./, $ext_file);
return($ext_parts[-1]);
}
# Begin edit text file procedure.
sub edit {
$filename = $FORM{'filename'};
$edit_file = "$data_path/$filename";
$report = &checkname($filename);
&header;
print "";
if ($report) {
$report = $report;
&list_files;
exit; }
if (-e $edit_file) { @LINES = `cat $edit_file`; }
else { @LINES = ''; $new = 'yes'; }
if ($new) {
$Ext = &Check_Ext($filename);
if ($Ext =~ /cgi|pl/i) {
$start_document = `cat default_cgi.txt`;
print qq~
This Is A New CGI File.
The Start Of A Perl Script Is Below For Your Convenience.
~; }
elsif ($Ext =~ /html|htm|shtml|shtm/i) {
$start_document = `cat default_html.txt`;
print qq~
This Is A New HTML File.
The Start Of An HTML Document Is Below For Your Convenience.
~; }
else {
print "This Is A New File, Enter Your Text Below.
"; }}
else {
if (-T $edit_file) {
print " Modify $filename as needed below:
"; }
else {
$report = "$filename is not a text file, only text can be edited.";
&list_files; }
print "
"; }
print qq~
NOTE! Search & replace is case sensitive!
Example: word is not the same as WORD
~;
&footer;
}
# Begin get file stats.
sub get_stats {
$filename = $_[0];
$type = $_[1];
if ($type eq "perms2") {
$mode = (stat($filename))[2];
$perms = sprintf "%3o", $mode & 07777;
$stat = $perms; }
if ($type eq "modtime") {
$stat = (stat($filename))[9]; }
return $stat;
}
# Begin time format.
sub FormatTime {
$thetime = $_[0];
@dow = qw(Sun Mon Tue Wed Thu Fri Sat);
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
($sec,$min,$hour,$day,$month,$year,$wday) = (localtime($thetime))[0,1,2,3,4,5,6];
if ($day == 1 || $day == 21 || $day == 31) { $end = 'st'; }
elsif ($day == 2 || $day == 22) { $end = 'nd'; }
elsif ($day == 3 || $day == 23) { $end = 'rd'; }
else { $end = 'th'; }
if ($year < 2000) { $year = $year + 1900; }
$min = sprintf("%02d", $min);
$sec = sprintf("%02d", $sec);
$FTime = "$dow[$wday], $months[$month] $day$end, $year $hour:$min:$sec";
}
# Begin list directories.
sub DirList {
$ls = `ls -R $Root`;
@pairs = split(/\n/,$ls);
@Dirs = ();
foreach (@pairs) {
if (m/$Root/) {
s#$Root/?(.)#$1#;
chop;
push(@Dirs, $_); }}
foreach $Dir (sort @Dirs) { $selected = '';
if ($Dir eq $dirname) { $selected = "selected"; }
print qq~$Dir~; }
}
# Begin error report.
sub checkname {
$testname = $_[0]; $error = '';
@chars = split(//,$testname); $size = @chars;
if ($size == 0) { $no_name = 'y'; $error = 'y'; }
if ($testname =~ /\.\./) { $double_period = 'y'; $error = 'y'; }
if ($testname =~ /\/\//) { $double_slash = 'y'; $error = 'y'; }
$character = "";
foreach $char (@chars) {
if (!($char =~ /[A-Z,a-z,'_',\/,\-,0-9,\.]/)) { $bad_char = 'y';
if ($character) { $character = "$character, $char"; }
else { $character = $char; }
$error = 'y'; }}
if ($chars[0] eq '/') { $initial_slash = 'y'; $error = 'y'; }
if ($error) {
if ($no_name) { $err .= "No file or directory name was given."; }
if ($initial_slash) { $err .= "A / was used as the first character."; }
if ($double_period) { $err .= "Two periods were found side by side."; }
if ($double_slash) { $err .= "Double forward slashes were found."; }
if ($bad_char) { $err .= "The character(s) $character forbidden.";}
return("Name Error! $err "); }
}
# Begin make directory.
sub makedir {
$directory = $FORM{'directory'};
$new_dir = "$data_path/$directory";
$report = &checkname($directory);
if (-e $new_dir) { $report .= "$directory already exists."; }
else {
unless ($report) {
`mkdir $new_dir`;
`chmod $dir_perms $new_dir`; }
if (-e $new_dir) { $report .= "$directory has been created."; }
else { $report .= "$directory was not created."; }}
$report = $report;
}
# Begin Rename Routine
sub rename {
$old = $FORM{'old'};
$new = $FORM{'new'};
$oldfile = "$data_path/$old";
$newfile = "$data_path/$new";
$report = &checkname($new);
if (-e $oldfile) {
unless ($report) { `mv $oldfile $newfile`; }
if (!-e $oldfile && -e $newfile) {
$report .= "$old has been renamed to $new ."; }
else { $report .= "$old has not been renamed."; }}
else { $report .= "$old was not found."; }
$report = $report;
}
# Begin Chmod Routine
sub chmod {
$file = $FORM{'file'};
$perms = $FORM{'perms'};
$file_path = "$data_path/$file";
if (-e $file_path) {
if ($perms =~ /[0-7][0-7][0-7]/) {
`chmod $perms $file_path`;
$report = "Permissions for $file have been set to $perms."; }
else {
$report = "Permissions for $file were not set. Invalid number."; }}
else { $report = "$file was not found."; }
}
# Begin confirm copy.
sub confirm_copy {
$sel_files = '';
$sel_dirs = '';
if (@file_names) { $sel_files = "files"; }
if (@dir_names) { $sel_dirs = "directories"; }
if (@file_names && @dir_names) { $sel_both = " and "; }
if ($dirname eq '') { $stay_dir = "Root Directory"; }
else { $stay_dir = $dirname; }
if ($sel_files || $sel_dirs) {
&header;
print qq~
Copy these $sel_files$sel_both$sel_dirs from: $stay_dir ...
to the directory in the text box below.
*Root~;
&DirList;
print qq~
Enter new names in the text boxes or
leave them blank to keep the same name.
Stay in $stay_dir after copy?
~;
&footer;}
else {
$report = 'You must choose 1 or more files or directories to use copy.';
&list_files; }
}
# Begin copy.
sub copy {
$last_dir = $FORM{'last_dir'};
$new_dir = $FORM{'new_dir'};
$copied = &checkname($new_dir);
if ($last_dir eq $dirname) { $show_last_dir = ""; }
elsif (!$last_dir && $dirname eq $new_dir) { $show_last_dir = "Root/"; }
elsif ($dirname eq $new_dir) { $show_last_dir = "$last_dir/"; }
if (!$new_dir) { $show_new_dir = "Root/"; }
if ($last_dir) { $cp_dir = "$last_dir/"; }
if ($new_dir) { $new_dir_path = "$core_data_path/$new_dir"; }
else { $new_dir_path = $core_data_path; }
if (!-e $new_dir_path) {
`mkdir $new_dir_path`;
`chmod $dir_perms $new_dir`;
if (-e $new_dir_path) {
$copied .= "Directory: $new_dir has been created. "; }
else {
$copied .= "Directory: $new_dir was not created. "; }}
foreach $cp_file (@file_names) {
$new_file = $FORM{$cp_file};
if ($new_dir && $new_file) { $new_full_name = "$new_dir/$new_file"; }
elsif ($new_dir && !$new_file) { $new_full_name = "$new_dir/$cp_file"; }
elsif (!$new_dir && $new_file) { $new_full_name = $new_file; }
else { $new_full_name = $cp_file; }
$copied .= &checkname($new_full_name);
if ($dirname eq $last_dir) {
$cp_file_name = $cp_file;
if ($dirname eq $new_dir) {
if ($new_file) { $new_file_name = $new_file; }
else { $new_file_name = $cp_file; }}
else { $new_file_name = $show_new_dir . $new_full_name; }}
else { $cp_file_name = $show_last_dir . $cp_file;
if ($dirname eq $new_dir) {
if ($new_file) { $new_file_name = $new_file; }
else { $new_file_name = $cp_file; }}
else { $new_file_name = $new_full_name; }}
$cp_file_path = "$core_data_path/" . $cp_dir . $cp_file;
$new_file_path = "$core_data_path/$new_full_name";
if (-e $new_file_path) {
$copied .= "$new_file_name already exists. "; }
else { `cp $cp_file_path $new_file_path`;
if (-e $new_file_path) {
$copied .= "$cp_file_name has been copied to $new_file_name . "; }
else {
$copied .= "$cp_file_name was not copied. "; }}}
$report = $copied;
}
# Begin confirm move.
sub confirm_move {
$sel_files = '';
$sel_dirs = '';
if (@file_names) { $sel_files = "files"; }
if (@dir_names) { $sel_dirs = "directories"; }
if (@file_names && @dir_names) { $sel_both = " and "; }
if ($dirname eq '') { $stay_dir = "Root Directory"; }
else { $stay_dir = $dirname; }
if ($sel_files || $sel_dirs) {
&header;
print qq~
Move these $sel_files$sel_both$sel_dirs from: $stay_dir ...
to the directory in the text box below.
*Root~;
&DirList;
print qq~ ~;
foreach $mv_dir (@dir_names) {
print qq~$mv_dir ~; }
foreach $mv_file (@file_names) {
print qq~$mv_file ~; }
print qq~
Stay in $stay_dir after move?
~;
&footer; }
else {
$report = 'You must choose 1 or more files or directories to use move.';
&list_files; }
}
# Begin move.
sub move {
$last_dir = $FORM{'last_dir'};
$new_dir = $FORM{'new_dir'};
$moved = &checkname($new_dir);
if ($last_dir eq $dirname) { $show_last_dir = ""; }
elsif (!$last_dir && $dirname eq $new_dir) { $show_last_dir = "Root/"; }
elsif ($dirname eq $new_dir) { $show_last_dir = "$last_dir/"; }
if (!$new_dir) { $show_new_dir = "Root/"; }
if ($last_dir) { $mv_last_dir = "$last_dir/"; }
if ($new_dir) { $new_dir_path = "$core_data_path/$new_dir"; }
else { $new_dir_path = $core_data_path; }
if (!-e $new_dir_path) {
`mkdir $new_dir_path`;
`chmod $dir_perms $new_dir`;
if (-e $new_dir_path) {$copied .= "Directory: $new_dir has been created. ";}
else { $moved .= "Directory: $new_dir was not created. "; }}
foreach $mv_file (@file_names) {# create new file path from choices
if ($new_dir) { $new_full_name = "$new_dir/$mv_file"; }
else { $new_full_name = $mv_file; }
$moved .= &checkname($new_full_name);
if ($dirname eq $last_dir) { # stayed in the same directory
$mv_file_name = $mv_file;
if ($dirname eq $new_dir) { $new_file_name = $mv_file; }
else { $new_file_name = $show_new_dir . $new_full_name; }}
else { # changed to a different directory
$mv_file_name = $show_last_dir . $mv_file;
if ($dirname eq $new_dir) { $new_file_name = $mv_file; }
else { $new_file_name = $new_full_name; }}
$mv_file_path = "$core_data_path/" . $mv_last_dir . $mv_file;
$new_file_path = "$core_data_path/$new_full_name";
if (-e $new_file_path) { $moved .= "$new_file_name already exists. "; }
else { `mv $mv_file_path $new_file_path`;
if (-e $new_file_path) {
$moved .= "$mv_file_name has been moved to $new_file_name . "; }
else {
$moved .= "$mv_file_name has not been moved. "; }}}
$report = $moved;
}
# Begin confirm delete.
sub Confirm_Delete {
$sel_files = '';
$sel_dirs = '';
if (@file_names) { $sel_files = "files"; }
if (@dir_names) { $sel_dirs = "directories"; }
if (@file_names && @dir_names) { $sel_both = " and "; }
&header;
print qq~
Are you sure you want to delete these $sel_files$sel_both$sel_dirs?
~;
foreach $del_dir (@dir_names) {
print qq~
$del_dir
~; }
foreach $del_file (@file_names) {
print qq~
$del_file
~; }
print qq~
~;
&footer;
}
# Begin delete.
sub Delete {
foreach $del_dir (@dir_names) {
$del_dir_path = "$data_path/$del_dir";
if (-e $del_dir_path) { `rmdir $del_dir_path`;
if (-e $del_dir_path) {
$removed .= "$del_dir was not removed. "; }
else { $removed .= "$del_dir was removed. "; }}
else { $removed .= "$del_dir was not found. "; }}
foreach $del_file (@file_names) {
$del_file_path = "$data_path/$del_file";
if (-e $del_file_path) {
`rm $del_file_path`;
if (-e $del_file_path) {
$removed .= "$del_file was not removed. "; }
else { $removed .= "$del_file was removed. "; }}
else { $removed .= "$del_file was not found. "; }}
$report = $removed;
}
# Begin confirm remove directory.
sub confirm_removedir {
$remove_dir = $FORM{'directory'};
$dir_path = "$data_path/$remove_dir";
$working_path = $working_dir . $remove_dir;
if (-e $dir_path) {
chdir($dir_path);
$du = `du`;
@pairs = split(/\n/, $du);
$testls = `ls -a`;
@testls = split(/\s+/, $testls);
foreach $pair (@pairs) {
@terms = split(/\s+/,$pair);
@parts = split(/\.\//,$terms[1]);
if ($parts[1] ne "") { push (@rmDirs, $parts[1]); }}
if ($#rmDirs +1 > 0 || $#testls -1 > 0) {
&header;
print qq~
Are you sure you want to delete $working_path and everything in it?
$working_path ~;
$dirls = `ls -a $dir_path`;
@dirls = split(/\s+/, $dirls);
foreach $file (sort @dirls) {
if (!-d "$dir_path/$file") { print qq~$file ~; }}
print "";
foreach $Dir (sort @rmDirs) {
print qq~$working_path/$Dir ~;
$rmls = `ls -a $Dir`; @rmls = split(/\s+/, $rmls);
foreach $file (sort @rmls) {
if (!-d "$dir_path/$Dir/$file") {
print qq~$file ~; }}
print "
"; }
print qq~
~;
&footer; }
else {
`rmdir $dir_path`;
if (-e $dir_path) {
$report = "$remove_dir was not removed.";
&list_files; }
else {
$report = "$remove_dir was removed. It was empty.";
&list_files; }}}
else { $report = "$remove_dir was not found.";
&list_files; }
}
# Begin remove directory.
sub removedir {
$delete_dir = $FORM{'delete_dir'};
$delete_path = "$data_path/$delete_dir";
if (-e $delete_path) { `rm -r $delete_path`;
if (-e $delete_path) { $report = "$delete_dir was not removed."; }
else { $report = "$delete_dir and everything in it was removed."; }}
else { $report = "$delete_dir was not found."; }
}
# Begin preview.
sub preview {
print "Content-type: text/html\n\n";
print $FORM{'file'};
}
# Begin write text file procedure:
sub write {
$filename = $FORM{'filename'};
$report = &checkname($filename);
$Ext = &Check_Ext($filename);
$new_path = "$data_path/$filename";
$new_http = "$data_http/$filename";
if (!-e $new_path) {
$new = 'yes'; }
unless ($report) {
$FORM{'file'} =~ s/\cM\n/\n/g;
open FILE,">$new_path";
print FILE "$FORM{'file'}";
close FILE;
if ($new) {
if ($Ext =~ /cgi|pl/i) {
$perms = $cgi_perms; }
else {
$perms = $file_perms; }
`chmod $perms $new_path`; }}
if ($new) {
if (-e $new_path) {
$report .= "$filename has been created.";}
else {
$report .= "$filename has
not been created."; }}
else {
$report .= "$filename has been edited."; }
$report = $report;
}
# Begin quick delete routine.
sub deletefile {
$file = $FORM{'file'};
$file_path = "$data_path/$file";
unlink($file_path);
$report = "$file has been removed.";
}
# Begin viewzip routine.
sub viewzip {
$file = $FORM{'file'};
$file_path = "$data_path/$file";
&header;
print qq~
Unzip these files?~;
@data = `cd $data_path; unzip -l $file_path`;
foreach $i (@data) {
print qq~$i ~; }
print qq~
~;
&footer;
}
# Begin unzip routine.
sub unzip {
$file = $FORM{'file'};
$file_path = "$data_path/$file";
@data = `cd $data_path; unzip $file_path`; shift(@data);
foreach $i (@data) {
$zipdata .= "$i "; }
$report = "$zipdata$file has been unzipped.";
}
# Begin zip confirm.
sub confirm_zip {
$sel_files = '';
$sel_dirs = '';
if (@file_names) { $sel_files = "files"; }
if (@dir_names) { $sel_dirs = "directories"; }
if (@file_names && @dir_names) { $sel_both = " and "; }
if ($sel_files || $sel_dirs) {
&header;
print qq~Zip these $sel_files$sel_both$sel_dirs?
~;
foreach $zip_dir (@dir_names) {
print qq~$zip_dir ~; }
foreach $zip_file (@file_names) {
print qq~$zip_file ~; }
print qq~
Filename: