# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub PB {print @_,"
\n"} # Message with break and newline.
sub PL {print @_,"\n"} # Message with newline.
sub PC {print "\n"} # Comment.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$| = 1;
$dir = 'new'; # Where to put new files.
($me = $1) =~ s".*/"";
$V = $ENV{"V_$me"} || $ENV{"D_$me"} || 1;
$ENV{PATH} = ".:sh:abc:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin";
use CGI_Lite;
use CGI::Carp 'fatalsToBrowser';
use Socket;
if (!$HTTPhdr) {print "Content-type: text/html\n\n"; ++$HTTPhdr}
$cgi = new CGI_Lite ();
$cgi->set_platform('UNIX');
%data = $cgi->parse_form_data();
if ($V>1) {for $a (@ARGV) {PB("ARG \"$a\"")}}
if ($V>1) {for $var (sort keys %ENV ) {PB("ENV $var = \"$ENV{$var}\"")}}
if ($V>1) {for $var (sort keys %data) {PB("VAR $var = \"$data{$var}\"")}}
chomp($cwd = `pwd`);
PB("CWD \"$cwd\"") if $V>1;
PB("
JC's file uploader
");
PB("dir: \"$ENV{DOCUMENT_ROOT}/$dir\"") if $V>1;
if ($file = $data{file}) {
$path = "$ENV{DOCUMENT_ROOT}/$dir/$file";
PB("path: \"$path\"") if $V>1;
if (!open(F,">$path")) {
PB("Can't write \"$path\" ($!)");
}
}
if ($msg = $data{msg}) {
$mcmd = "sendmail -t webmaster";
if (open(MSG,"| $mcmd")) {
$raddr = $ENV{REMOTE_ADDR};
$rhost = gethostbyaddr(inet_aton($raddr), AF_INET);
print MSG "To: webmaster\n";
print MSG "Subject: Messge from $raddr ($rhost)\n\n";
print MSG "\n";
print MSG "Someone at $raddr ($rhost) wrote:\n";
print MSG "\n";
print MSG $msg;
close MSG;
$msg = '';
} else {
VM("Can't run \"$mcmd\" ($!)") if $V>0;
}
}
if ($data{GetURL}) {
PB("Download from URL ...") if $V>1;
if ($URL = $data{URL}) {
PB("Loading URL \"$URL\"") if $V>1;
$cmd = "w3cat +TH -T20 $URL |";
PB("Command \"$cmd\"") if $V>1;
if (open(P,$cmd)) {
PB("Running \"$cmd\"") if $V>1;
$l = $n = 0;
$inhdr = 1;
for $line () {
chomp $line;
++$l;
PB("$l: \"$line\"") if $V>1;
if ($inhdr) {
if (!$line) {
PB("### End of header ###") if $V>1;
$inhdr = 0;
}
} else {
++$n;
print F "$line\n";
}
}
close P;
} else {
PB("Can't exec \"$cmd\" ($!)");
}
PB("Copied $n lines from $URL to \"$ENV{DOCUMENT_ROOT}/$dir/$file\".
") if $V>0;
}
}
if ($data{GetTXT}) {
PB("Download text ...") if $V>1;
if ($text = $data{text}) {
PB("Writing text to $path ...") if $V>1;
$l = 0;
for $line (split("\n",$text)) {
++$l;
PB("$l: \"$line\"") if $V>1;
print F "$line\n";
}
$NEW = "http://$ENV{HTTP_HOST}/$dir/$file";
PB("Wrote $l lines of text to \"/$dir/$file\".
") if $V>0;
}
}
PL("This will copy a URL or download some text into a file in the");
PL("$dir directory on the $ENV{HTTP_HOST} server.");
PL("Enter a file name, and either a URL or some text,");
PL("and press the appropriate button.");
PB("");
exit 0;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #