Hi
Here is a quick script I wrote a long time ago.........
It still works great on win/unix
What it does..............
uploads files............
dis-allow based on............
(TYPE,SIZE)
sends a email, like this to the admin.............
From Sunny@mail.com Sun Jan 06 20:09:20 2002
X-UID32: 1010376562
Return-path: Sunny@mail.com
Received: from 127.0.0.1 by ssl.ya-right.com (SSL SMTPD);
id s20020106200920.150; Sun, 06 Jan 2002 20:09:20
Date: Sun Jan 6 23:09:20 2002 -0500
From: "Sunny" <Sunny@mail.com>
Subject: New Music File Upload
To "Sunny" <Sunny@mail.com>
X-Mailer: <Music Mail Server>
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Hi You
New Music File Upload
File Name: bye bye bidie.mp3
Time Uploaded: Sun Jan 6 23:09:20 2002
Remote Host: 127.0.0.1
Write to a database the upload info...........
1,127.0.0.1,Sun Jan 6 23:13:56 2002,img.zip
^^ count,ip,time,file name.....
mail using basic sockets
#!/usr/local/bin/perl
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/; ## Carp debugging
$| = 1; ## Flush the open filehandle.
# CHANGE TO WHATEVER.
$title='UPLOAD MUSIC FILES!';
#This is the relative path to the upload directory.
# ./ If you leave it like this, the uploads would be
# placed where this script is (NOT GOOD CHANGE IT).....
$dir='./';
# max KB/b posts. What ever number you place here is the max file size in KB to upload.
$max = 60;
# only upload files with the file.@good in the brackets.
# ie @good = qw(txt html htm asp this that and whatever);
@good = qw(mp3 wav);
# where to log all the upload info.......
$data_file = 'data.log';
# the counter file, to keep an upload count...
$counter = 'count';
# email results info........
$fromuser = 'you@domain.com';
$fromname = 'You';
$touser = 'you@domain.com';
$toname = 'You';
$subject = 'New Music File Upload';
# mail server info....
$server = "localhost";
$LOCALHOST = 'smtp.domain.com';
$SMTP_PORT = '25';
$xmailer = '<Music Mail Server>';
# does the server require AUTH, if yes fill these in
# this is not called unless $use_AUTH = '1';
$use_AUTH = ''; # leave empty no-auth, enter 1 if using auth
# some server allow for plain sent user/pass
# others want it sent as base64
$mail_sender = "smtp_login_username";
$mail_passwd = "smtp_login_pass";
## THAT IT............
$encoding='multipart/form-data';
$match=0;
$CGI::POST_MAX=1024 * $max;
$q = new CGI;
print $q->header();
print $q->start_html(-title=>"$title\n",
-meta=>{'description'=>'Music Upload File System',
'keywords'=>'Music Upload'},
-dtd=>1,
-BGCOLOR=>'white',
-TEXT=>'navy',
-link=>'green',
-vlink=>'red',
-alink=>'blue');
print $q->h1("$title"), "Enter your music file to upload (@good ${max}Kb Max.)\n";
print $q->startform($method,$action,$encoding);
print $q->filefield(-name=>'uploaded_file', -default=>'', -size=>40, -maxlength=>120);
print $q->submit(-name=>'button_name', -value=>'UPLOAD');
print $q->endform;
$filename = $q->param('uploaded_file');
$filename2 = $filename;
$filename2 =~ /\w:[\\[\w- ]*\\]*([\w- ]*.\w{1,3})$/g;
$file=$1;
if ($filename){
foreach $good (@good){
if (grep /$good$/i,$filename){$match=1;print "$file UPLOADED!<BR>\n";
}
}
if ($match){
&upload;
}
else {
&error("File Format is not supported! $file, can not be uploaded!");
}
}
sub upload{
open(OUTFILE, ">$dir$file")||&error("Can't open $dir$file. $!");
binmode OUTFILE;
# binmode for windows. Ignored by unix
while ($bytesread=read($filename,$buffer,1024))
{print OUTFILE $buffer; }
close (OUTFILE);
}
if ($match){
&get_number;
$ip = "$ENV{'REMOTE_ADDR'}";
$timer = localtime();
$data_line = "$num,$ip,$timer,$file";
open (FILE, ">>$data_file") or die "Cannot open $data_file: $!";
flock(FILE,2) or die "cannot lock file: $!";
print FILE "$data_line\n";
close(FILE);
&add_header;
print "Thanks for the new music";
}
sub error{
@error=@_;
print "<H2>@error</H2>";
exit;
}
sub get_number {
open (COUNTER_FILE, "<$counter");
while (<COUNTER_FILE>)
{
$current_counter = $_;
}
close (COUNTER_FILE);
$current_counter++;
$num = $current_counter;
open (FILE, ">$counter");
print FILE "$num";
close (FILE);
return $num;
}
sub add_header {
$header = "Date: $timer -0500\r\n";
$header .= "From: \"$fromname\" <$fromuser>\r\n";
$header .= "Subject: $subject\r\n";
$header .= "To \"$toname\" <$touser>\r\n";
$header .= "X-Mailer: $xmailer\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\n";
$header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$header .= "Hi $toname\n\n";
$header .= "New Music File Upload\n\n";
$header .= "File Name: $file\n";
$header .= "Time Uploaded: $timer\n";
$header .= "Remote Host: $ip\n";
&send_smtp_mail($fromuser, $touser, $subject, $header);
}
sub send_smtp_mail {
use Socket;
my ($iaddr,$paddr,$proto);
my ($from, $to, $subject, $header) = @_;
no strict 'subs';
$iaddr = inet_aton($server);
$paddr = sockaddr_in($SMTP_PORT, $iaddr);
$proto = getprotobyname( 'tcp' );
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or return 0;
connect(SOCK, $paddr) or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "HELO $LOCALHOST") or return 0;
receive_from_server(\*SOCK) or return 0;
if ($use_AUTH) {
send_to_server(\*SOCK, "AUTH LOGIN") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "$mail_sender") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "$mail_passwd") or return 0;
receive_from_server(\*SOCK) or return 0;
}
send_to_server(\*SOCK, "MAIL From: <$from>") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "RCPT To: <$to>") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "DATA") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "$header\r\n.") or return 0;
receive_from_server(\*SOCK) or return 0;
send_to_server(\*SOCK, "QUIT") or return 0;
receive_from_server(\*SOCK) or return 0;
close(SOCK) or return 0;
return 1;
}
sub send_to_server {
my($socket) = shift;
my($message) = shift;
send($socket, "$message\r\n", 0) or return 0;
return 1;
}
sub receive_from_server {
my($socket) = shift;
my($reply);
while($reply = <$socket>) {
return 0 if $reply =~ /^5/;
last if $reply =~ /^\d+ /;
}
return 1;
}
print "<br><br>\n";
print $q->
hr({-width=>'90%',-size=>3,-style=>'raised'}),
p({-align=>CENTER},'Upload music services by ',
a({-href=>'http://music-world.com/'},'Music World')
);
print "</body></html>\n";
exit;
F!