From ad6ac494b3be85b23f22eadb86b0e98b8003be14 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Sat, 21 Nov 2020 18:15:07 +0100 Subject: Add 'if defined' checks to length_msg_form variable Now warning and strict module doesn't complain, and my web server error log is cleaner. IMO, it has a nice effect to give a clearer idea of what the conditional tries to achieve there. --- gpigeon-template.cgi | 80 +++++++++++++++++++++++++++------------------------- 1 file 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{'. $text_strings[25] .'.};', "\n", - '} elsif ( $length_msg_form eq 0 ){', "\n", + '} elsif (defined $length_msg_form and $length_msg_form eq 0 ){', "\n", ' $error_processing_msg = q{'. $text_strings[26] . '.};', "\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{', "\n", -- cgit v1.2.3-70-g09d2