diff options
-rwxr-xr-x | gpigeon-template.cgi | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/gpigeon-template.cgi b/gpigeon-template.cgi index 077ae45..59d676b 100755 --- a/gpigeon-template.cgi +++ b/gpigeon-template.cgi @@ -137,56 +137,60 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ print $gpg_form_fh '#! /usr/bin/perl -wT',"\n\n", ' my $non_gpguser = q{'. $non_gpguser .'};', "\n", 'delete @ENV{qw(IFS PATH CDPATH BASH_ENV)};', "\n", - '$ENV{\'PATH\'}="/usr/bin";', + '$ENV{\'PATH\'}="/usr/bin";', "\n", 'use warnings;', "\n", 'use strict;',"\n", 'use GPG;',"\n", - '#use CGI::Carp qw(fatalsToBrowser);', + '#use CGI::Carp qw(fatalsToBrowser);', "\n", 'use CGI qw(param);', "\n", 'my $cgi_query_get = CGI->new;', "\n", 'my ($msg_form, $enc_msg, $error_processing_msg,$msg_form_char_limit) = undef;', "\n", '$msg_form_char_limit = '. $msg_form_char_limit . ' ;', "\n", '$msg_form = $cgi_query_get->param(\'msg\');', "\n", 'my $length_msg_form = length $msg_form;', "\n", - 'if ($length_msg_form > $msg_form_char_limit){', "\n", + + 'if (defined $length_msg_form and $length_msg_form > $msg_form_char_limit){', "\n", ' $error_processing_msg = q{<span style="color:red"><b>'. $text_strings[25] .'.</b></span>};', "\n", - '} elsif ( $length_msg_form eq 0 ){', "\n", + '} elsif (defined $length_msg_form and $length_msg_form eq 0 ){', "\n", ' $error_processing_msg = q{<span style="color:red"><b>'. $text_strings[26] . '.</b></span>};', "\n", '} else {', "\n", - 'if (defined $cgi_query_get->param(\'msg\') and $ENV{\'REQUEST_METHOD\'} eq \'POST\'){',"\n", - ' $msg_form =~ tr/\r//d;', "\n", - ' my $gpg = new GPG(gnupg_path => "/usr/bin", homedir => "/usr/share/www-data/.gnupg/");', "\n", - ' $enc_msg = $gpg->encrypt("De la part de " . $non_gpguser . ":\n". $msg_form, \''. $mymail_gpgid .'\') or die $gpg->error();', "\n"; - if ($HAS_MAILSERVER){ - undef $mymailaddr_escaped; - print $gpg_form_fh 'use Mail::Sendmail;', - '%mail = ( To => \''.$mymailaddr.'\',' , "\n", - ' From => \''.$mymailaddr.'\',', "\n", - ' Subject => \'Gpigeon\' ', "\n", - ' Message => "$enc_msg\n" ', "\n", - ');', "\n", - 'sendmail(%mail) or die $Mail::Sendmail::error;', "\n"; - } - else { - print $gpg_form_fh 'use Net::SMTP;',"\n", - 'use Net::SMTPS;',"\n", - 'my $smtp = Net::SMTPS->new(\''. $mymail_smtp .'\', Port => \''. $mymail_smtport .'\', doSSL => \'ssl\', Debug_SSL => 0);', "\n", - '$smtp->auth(\''. $mymailaddr .'\', \''. $mymailaddr_pw .'\') or die;', "\n", - '$smtp->mail(\''. $mymailaddr .'\') or die "Net::SMTP module has broke: $!.";', "\n", - 'if ($smtp->to(\''. $mymailaddr .'\')){', "\n", - ' $smtp->data();', "\n", - ' $smtp->datasend("To: '. $mymailaddr_escaped .'\n");', "\n", - ' $smtp->datasend("\n");', "\n", - ' $smtp->datasend("$enc_msg\n");', "\n", - ' $smtp->dataend();', "\n", - '}', "\n", - 'else {', "\n", - ' die $smtp->message();', "\n", - '}', "\n"; - } - print $gpg_form_fh 'unlink "../' . $MAILFORM_RELPATH . '";', "\n", - 'print "Location: /merci/index.html\n\n";', "\n", - '}', "\n", + ' if (defined $length_msg_form and $ENV{\'REQUEST_METHOD\'} eq \'POST\'){',"\n", + ' $msg_form =~ tr/\r//d;', "\n", + ' my $gpg = new GPG(gnupg_path => "/usr/bin", homedir => "/usr/share/www-data/.gnupg/");', "\n", + ' $enc_msg = $gpg->encrypt("De la part de " . $non_gpguser . ":\n". $msg_form, \''. $mymail_gpgid .'\') or die $gpg->error();', "\n"; + if ($HAS_MAILSERVER){ + undef $mymailaddr_escaped; + print $gpg_form_fh "\n", + ' use Mail::Sendmail;', + ' %mail = ( To => \''.$mymailaddr.'\',' , "\n", + ' From => \''.$mymailaddr.'\',', "\n", + ' Subject => \'Gpigeon\' ', "\n", + ' Message => "$enc_msg\n" ', "\n", + ' );', "\n", + ' sendmail(%mail) or die $Mail::Sendmail::error;', "\n"; + } + else { + print $gpg_form_fh "\n", + ' use Net::SMTP;',"\n", + ' use Net::SMTPS;',"\n", + ' my $smtp = Net::SMTPS->new(\''. $mymail_smtp .'\', Port => \''. $mymail_smtport .'\', doSSL => \'ssl\', Debug_SSL => 0);', "\n", + ' $smtp->auth(\''. $mymailaddr .'\', \''. $mymailaddr_pw .'\') or die;', "\n", + ' $smtp->mail(\''. $mymailaddr .'\') or die "Net::SMTP module has broke: $!.";', "\n", + ' if ($smtp->to(\''. $mymailaddr .'\')){', "\n", + ' $smtp->data();', "\n", + ' $smtp->datasend("To: '. $mymailaddr_escaped .'\n");', "\n", + ' $smtp->datasend("\n");', "\n", + ' $smtp->datasend("$enc_msg\n");', "\n", + ' $smtp->dataend();', "\n", + ' }', "\n", + ' else {', "\n", + ' die $smtp->message();', "\n", + ' }', "\n"; + } + print $gpg_form_fh "\n", + ' unlink "../' . $MAILFORM_RELPATH . '";', "\n", + ' print "Location: /merci/index.html\n\n";', "\n", + ' }', "\n", '}', "\n", 'print "Content-type: text/html", "\n\n";', "\n", 'print q{<!DOCTYPE html>', "\n", |