#!/usr/bin/perl -w print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use Net::FTP; use Cwd; $CGI::DISABLE_UPLOADS = 1; # no uploads BEGIN { $ENV{PATH} = "/usr/bin:/bin:/usr/local/bin"; use CGI::Carp qw(carpout); open(LOG, ">dmover-log.txt"); carpout(*LOG); close(LOG); } $q = CGI->new(); $tmpdir = $q->param("tmpdir"); $host = $q->param("host"); $pass = $q->param("pass"); $user = $q->param("user"); $remotedir = $q->param('remotedir'); if ( $tmpdir !~ /[0001-9999]/ ) { print "

unzipped directory to be moved is undefined


\n" and exit }; if ( $ENV{'HTTP_REFERER'} !~ "dmover1.pl" ) { print "

Sorry, but this will only move the directory that you just unzipped from WebZip


\n" and exit }; ## Disallow Specific Domains if ($host =~ 'xdoor') {print "Listen, SCUMBALL. I said porno sites are NOT ALLOWED
\n" and exit}; ## Disallow certain users if ($user =~ 'ilocate') {print "Listen, SCUMBALL. I said porno sites are NOT ALLOWED. If I catch you again, I'll report your sorry butt to Tripod.
\n" and exit}; $| = 1; $ftp = Net::FTP->new("$host", Debug => 1) or print "

ERROR: CONNECTION failed


\n" and exit; $ftp->login($user, $pass) or print "

ERROR: LOGIN failed


\n" and exit; # Go to the starting point in the remote tree $ftp->mkdir("$remotedir"); # Go to the starting point in the local tree chdir($tmpdir); # Go to the starting point in the remote tree $ftp->cwd("$remotedir"); # Crawl over the local tree my @path; finddepth(\&process_item, 1); sub process_item { my ($level, $isdir, $item, $parent) = @_; if ($isdir) { $ftp->mkdir($parent.$item); } else { my $save_remote = $ftp->pwd; $ftp->cwd($parent); $ftp->put($item); $ftp->cwd($save_remote) or print "ERROR: can't cwd to $save_remote\n" and exit; } } sub finddepth { my ($callback, $level) = @_; # Make a listing of files and/or directories my $cwd = cwd; opendir(DIR, $cwd) or print "ERROR: can't opendir $cwd: $!\n" and exit; my ($item, @list); while ( defined($item = readdir(DIR)) ) { push(@list, $item); } closedir(DIR); foreach $item (@list) { next if $item =~ /\.\.?$/; my $parent = ""; my $i; foreach $i (@path) { $parent .= $i."/"} if ( -d $item) { # It's a directory — call the callback &$callback($level, 1, $item, $parent); # Recursively crawl the subtree under this directory push(@path, $item); my $save_local = cwd; chdir($item) or print "ERROR: can't chdir to $item\n" and exit; finddepth($callback, $level+1); # Restore location in local tree chdir($save_local) or print "ERROR: can't chdir to $save_local\n" and exit; pop(@path); } elsif ( -f $item) { if ($parent eq "") {$parent = "$remotedir"}; if ($item =~ /\.(shtml|shtm|htm|html|txt|cgi|pl|php|readme|dat|doc)$/i ) { $ftp->type("A") } else { $ftp->type("I") }; # It's a file - call the callback &$callback($level, 0, $item, $parent); } } } $ftp->quit or print "Could not QUIT FTP" and exit; $log = `cat "/home/public_html/dmover-log.txt"`; # Remover everything between GLOB and /, and # Remove First 3 Lines of file $log =~ s/Net::FTP\=GLOB(.*?) /
/g; $log =~ s/^(.*\n){7}//o; print <
Your FILES and DIRECTORIES have been moved.
See the dialog below to check your results.

FTP DIALOG
$log EOL