Показать сообщение отдельно

  #8  
Старый 23.03.2008, 21:31
neprovad
Постоянный
Регистрация: 19.10.2007
Сообщений: 794
Провел на форуме:
1013791

Репутация: 711


По умолчанию

Может кому пригодится или поможет..
/cdbs/web/contact/sendmail.cgi~
Код:
#!/usr/bin/perl
##############################################################################
# By BumbleBeeWare.com 2006
# Simple CAPTCHA using static premade images
# check-captcha.cgi
##############################################################################

use Mail::Sender;
use CGI;
use CGI::Carp qw ( fatalsToBrowser ); 
use File::Basename;
use Encode;

$CGI::POST_MAX = 1024 * 2000;
$upload_dir = "/tmp/upload";

print "Content-type: text/html\n\n";
open IN1, "sendmail1.html.txt" || die "Error !";
while (<IN1>)
{
 print;
}

##########################
# configuration
$tempdir = "/srv/www/lighttpd/captcha/temp";

##########################
# parse the input data
&form_parse;

# lets block direct access that is not via the form post
if ($ENV{"REQUEST_METHOD"} ne "POST"){&nopost;}

# use this program to remove all old temp files
# this keeps the director clean without setting up a cron job
opendir TMPDIR, "$tempdir"; 
@alltmpfiles = readdir TMPDIR;

foreach $oldtemp (@alltmpfiles) {

	$age = 0;
	$age = (stat("$tempdir/$oldtemp"))[9];
	# if age is more than 300 seconds or 5 minutes	
	if ((time - $age) > 300){unlink "$tempdir/$oldtemp";}
	
	}


# open the temp datafile for current user based on ip
$tempfile = "$tempdir/$ENV{'REMOTE_ADDR'}";
open (TMPFILE, "<$tempfile")|| ($nofile = 1);
(@tmpfile) = <TMPFILE>;
close TMPFILE;

# if no matching ip file check for a cookie match
# this will compensate for AOL proxy servers accessing images
if ($nofile == 1){
	
$cookieip = $ENV{HTTP_COOKIE};
$cookieip =~ /checkme=([^;]*)/;
$cookieip = $1;

if ($cookieip ne ""){
	
	$tempfile = "$tempdir/$cookieip";
	open (TMPFILE, "<$tempdir/$cookieip")|| &nofile;
	(@tmpfile) = <TMPFILE>;
	close TMPFILE;
}

}

$imagetext = $tmpfile[0];
chomp $imagetext;

# set the form input to lower case
#$FORM{'captcha'} = lc($FORM{'captcha'});
$query = new CGI;
$captcha=$query->param("captcha");
$captcha=lc($captcha);

#print "CAPTCHA=$captcha waiting for $imagetext";

# compare the form input with the file text
#if ($FORM{'captcha'} ne "$imagetext"){&error;}
if ($captcha ne "$imagetext"){&error;}

# now delete the temp file so it cannot be used again by the same user
unlink "$tempfile";

# if no error continue with the program
#print "Content-type: text/html\n\n";
#print "sucessful verification";
#print "$FORM{'name'} $FORM{'email'} $FORM{'message_subject'} $FORM{'message_body'}";
$sender = new Mail::Sender
{smtp => '10.10.10.104', from => 'webmail@radarix.org'};
#$sender->MailFile({to => 'peter@radarix.org',
#subject => $FORM{'message_subject'},
#msg => FORM{'message_body'}});
$filename=$query->param("filename");
$subject=$query->param("message_subject");
Encode::from_to($subject, 'utf-8', 'windows-1251');
$name=$query->param("name");
$email=$query->param("email");
$IP=$ENV{REMOTE_ADDR};

$msg="Name: $name\nFrom: $email\nIP=$IP\n\n\n";
$msg.=$query->param("message_body");
Encode::from_to($msg, 'utf-8', 'windows-1251');

if ($filename)
   {
#    print "Filename = $filename<br>";
    $upload_filehandle = $query->upload("filename");
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; 
    binmode UPLOADFILE; 
    while ( <$upload_filehandle> ) 
       {
        print UPLOADFILE;
       }
    close UPLOADFILE;
    if (ref ($sender->MailFile({to =>'support@radarix.org', subject => $subject, msg => $msg, file => "$upload_dir/$filename"})))
       {
       $str1="Письмо отправлено.";
       Encode::from_to($str1, 'windows-1251', 'utf-8');
       print $str1;
       } else {
              die "$Mail::Sender::Error\n";
              }
    unlink("$upload_dir/$filename");
   }
else
{   
if (ref ($sender->MailMsg({to =>'support@radarix.org', subject => $subject, msg => $msg}))) 
   {
    $str1="Письмо отправлено.";
    Encode::from_to($str1, 'windows-1251', 'utf-8');
    print $str1;
   } else {
           die "$Mail::Sender::Error\n";
          }
}
&myexit;
exit;



sub error {
	
#print "Content-type: text/html\n\n";
$str1="Кодовая фраза введена неверно.";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;
# now delete the temp file so it cannot be used again by the same user
unlink "$tempdir/$ENV{'REMOTE_ADDR'}";
&myexit;
exit;	
}

sub nofile {
	
#print "Content-type: text/html\n\n";
$str1="Ошибка при проверке кодового слова. Пожалуйчта повторите";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;
&myexit;
exit;	
}


sub nopost {
	
#print "Content-type: text/html\n\n";
$str1="Ошибка вызова. Требуется POST запрос!";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;	
&myexit;
exit;	
}



sub form_parse  {
return;
	read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);

	foreach $pair (@pairs)
	{
    	($name, $value) = split(/=/, $pair);
    	$value =~ tr/+/ /;
    	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    	$FORM{$name} = $value;
}}

sub myexit
   {
    open IN2, "sendmail2.html.txt" || die "Error !";
    while (<IN2>)
       {
        print;
       }
   }
/cdbs/web/signup/registration.cgi~

Код:
#!/usr/bin/perl
##############################################################################
# By BumbleBeeWare.com 2006
# Simple CAPTCHA using static premade images
# check-captcha.cgi
##############################################################################

use Mail::Sender;
use CGI;
use CGI::Carp qw ( fatalsToBrowser ); 
use File::Basename;
use Encode;

$CGI::POST_MAX = 1024 * 2000;
$upload_dir = "/tmp/upload";


print "Content-type: text/html\n\n";
open IN1, "sendmail1.html.txt" || die "Error !";
while (<IN1>)
{
 print;
}


##########################
# configuration
$tempdir = "/srv/www/lighttpd/captcha/temp";

##########################

# parse the input data
&form_parse;

# lets block direct access that is not via the form post
if ($ENV{"REQUEST_METHOD"} ne "POST"){&nopost;}

# use this program to remove all old temp files
# this keeps the director clean without setting up a cron job
opendir TMPDIR, "$tempdir"; 
@alltmpfiles = readdir TMPDIR;

foreach $oldtemp (@alltmpfiles) {

	$age = 0;
	$age = (stat("$tempdir/$oldtemp"))[9];
	# if age is more than 300 seconds or 5 minutes	
	if ((time - $age) > 300){unlink "$tempdir/$oldtemp";}
	
	}


# open the temp datafile for current user based on ip
$tempfile = "$tempdir/$ENV{'REMOTE_ADDR'}";
open (TMPFILE, "<$tempfile")|| ($nofile = 1);
(@tmpfile) = <TMPFILE>;
close TMPFILE;

# if no matching ip file check for a cookie match
# this will compensate for AOL proxy servers accessing images
if ($nofile == 1){
	
$cookieip = $ENV{HTTP_COOKIE};
$cookieip =~ /checkme=([^;]*)/;
$cookieip = $1;

if ($cookieip ne ""){
	
	$tempfile = "$tempdir/$cookieip";
	open (TMPFILE, "<$tempdir/$cookieip")|| &nofile;
	(@tmpfile) = <TMPFILE>;
	close TMPFILE;
}

}

$imagetext = $tmpfile[0];
chomp $imagetext;

# set the form input to lower case
#$FORM{'captcha'} = lc($FORM{'captcha'});
$query = new CGI;
$captcha=$query->param("captcha");
$captcha=lc($captcha);

#print "CAPTCHA=$captcha waiting for $imagetext";

# compare the form input with the file text
#if ($FORM{'captcha'} ne "$imagetext"){&error;}
if ($captcha ne "$imagetext"){&error;}

# now delete the temp file so it cannot be used again by the same user
unlink "$tempfile";

# if no error continue with the program
#print "Content-type: text/html\n\n";
#print "sucessful verification";
#print "$FORM{'name'} $FORM{'email'} $FORM{'message_subject'} $FORM{'message_body'}";
$sender = new Mail::Sender
{smtp => '10.10.10.104', from => 'webmail@radarix.org'};
#$sender->MailFile({to => 'peter@radarix.org',
#subject => $FORM{'message_subject'},
#msg => FORM{'message_body'}});
$filename=$query->param("filename");
$subject=$query->param("message_subject");
Encode::from_to($subject, 'utf-8', 'windows-1251');
$name=$query->param("name");
$email=$query->param("email");
$IP=$ENV{REMOTE_ADDR};
$adv_type=$query->param("adv_type");

$msg="Name: $name\nFrom: $email\n$adv_type\nIP: $IP\n\n\n";
$msg2="$name|\\|$email|\\|$adv_type|\\|$IP\n";
#$msg.=$query->param("message_body");
Encode::from_to($msg, 'utf-8', 'windows-1251');
Encode::from_to($msg2, 'utf-8', 'windows-1251');

open MYFILE, ">>./e/em.file";
flock(MYFILE,2);
print MYFILE $msg2;
close (MYFILE);

if ($filename)
   {
#    print "Filename = $filename<br>";
    $upload_filehandle = $query->upload("filename");
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; 
    binmode UPLOADFILE; 
    while ( <$upload_filehandle> ) 
       {
        print UPLOADFILE;
       }
    close UPLOADFILE;
    if (ref ($sender->MailFile({to =>'support@radarix.org', subject => $subject, msg => $msg, file => "$upload_dir/$filename"})))
       {
       $str1="Письмо отправлено.";
       Encode::from_to($str1, 'windows-1251', 'utf-8');
       print $str1;
       } else {
              die "$Mail::Sender::Error\n";
              }
    unlink("$upload_dir/$filename");
   }
else
{   
if (ref ($sender->MailMsg({to =>'support@radarix.org', subject => "registration", msg => $msg}))) 
   {
    $str1="Спасибо за регистрацию. <br>Логин и пароль будут Вам высланы через несколько дней<br> по мере снижения нагрузки на систему.";
    Encode::from_to($str1, 'windows-1251', 'utf-8');
    print $str1;
   } else {
           die "$Mail::Sender::Error\n";
          }
}
&myexit;
exit;



sub error {
	
#print "Content-type: text/html\n\n";
$str1="Кодовая фраза введена неверно.";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;
# now delete the temp file so it cannot be used again by the same user
unlink "$tempdir/$ENV{'REMOTE_ADDR'}";
&myexit;
exit;	
}

sub nofile {
	
#print "Content-type: text/html\n\n";
$str1="Ошибка при проверке кодового слова. Пожалуйчта повторите";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;
&myexit;
exit;	
}


sub nopost {
	
#print "Content-type: text/html\n\n";
$str1="Ошибка вызова. Требуется POST запрос!";
Encode::from_to($str1, 'windows-1251', 'utf-8');
print $str1;	
&myexit;
exit;	
}



sub form_parse  {
return;
	read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);

	foreach $pair (@pairs)
	{
    	($name, $value) = split(/=/, $pair);
    	$value =~ tr/+/ /;
    	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    	$FORM{$name} = $value;
}}

sub myexit
   {
    open IN2, "sendmail2.html.txt" || die "Error !";
    while (<IN2>)
       {
        print;
       }
   }