#! /usr/bin/perl -wT use warnings; use strict; use Digest::SHA qw(sha256_hex); use Email::Valid; use String::Random; use CGI qw(param); #use CGI::Carp qw(fatalsToBrowser); delete @ENV{qw(IFS PATH CDPATH BASH_ENV)}; sub print_smtp_method { my $m_addr = shift; my $m_addr_pw = shift; my $m_addr_escaped = shift; my $smtp_serv = shift; my $smtp_port = shift; if ($HAS_MAILSERVER eq 0){ print 'use Net::SMTP;',"\n", 'use Net::SMTPS;',"\n", 'my $smtp = Net::SMTPS->new(\''. $smtp_serv .'\', Port => \''. $smt_port .'\', doSSL => \'ssl\', Debug_SSL => 0);', "\n", '$smtp->auth(\''. $m_addr .'\', \''. $m_addr_pw .'\') or die;', "\n", '$smtp->mail(\''. $m_addr .'\') or die "Net::SMTP module has broke: $!.";', "\n", 'if ($smtp->to(\''. $m_addr .'\')){', "\n", ' $smtp->data();', "\n", ' $smtp->datasend("To: '. $m_addr_escaped .'\n");', "\n", ' $smtp->datasend("\n");', "\n", ' $smtp->datasend("$enc_msg\n");', "\n", ' $smtp->dataend();', "\n", '}', "\n", 'else {', "\n", ' die $smtp->message();', "\n", '}', "\n"; } else { undef $m_addr_escaped; print 'use Mail::Sendmail;', '%mail = ( To => \''.$m_addr.'\',' , "\n", ' From => \''.$m_addr.'\',', "\n", ' Subject => \'Gpigeon\' ', "\n", ' Message => "$enc_msg\n" ', "\n", ');', "\n", 'sendmail(%mail) or die $Mail::Sendmail::error;', "\n" ; } } sub escape_arobase { my $mailaddress = shift; my $arobase = '@'; my $espaced_arob = q{\@}; my $escapedmailaddress = $mailaddress; $escapedmailaddress =~ s/$arobase/$espaced_arob/; return $escapedmailaddress; } sub untaint_cgi_filename { my $filename = shift; if ($filename =~ /^([-\@\w.\/]+)$/) { #data untainted $filename = $1; } else { die "$!"; } chomp $filename; return $filename; } sub notif_if_defined{ my $notif = shift; if (defined $notif){ return $notif; } } # execute 'printf "yourpassword" | sha256sum' on a terminal # and copy the long string my $PASSWD_HASH = q{password_hash_goes_here}; my $cgi_query_get = CGI->new; my $PASSWD = $cgi_query_get->param('password'); my $HAS_MAILSERVER = 0; if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ $ENV{'PATH'}='/usr/bin'; my $HTML_CONTENT_TYPE_HEADER = 'Content-type: text/html'; my $HTML_CHARSET = '',"\n",'',"\n"; my $HTML_CSS = ''; my $mymailaddr = q{your_mail_address_goes_here}; my $mymailaddr_password = q{your_mail_address_password_goes_here}; my $mymail_smtp = q{smtp_domain_goes_here}; my $mymail_smtport = q{smtp_port_goes_here}; my $mymail_gpgid = q{gpgid_goes_here}; #0xlong keyid form my $myescapedmailaddr = escape_arobase($mymailaddr); my @text_strings = ('Succesful deletion!', 'Address', 'is valid!', 'is not valid !', 'Unknown', # displays on main page table when supposed sender isn't identified 'Message length must be under 10000 chars.', 'One time GPG messaging form', # title for generated links 'Type your message below, ', 'Send me', 'Generated a link for', #displays if link gen is successful 'Link to your one time GPG messaging form', # mail subject when clicking a mailto: link in table 'Your link is ', # message body when clicking a mailto: link in table 'Delete', # text on button for deleting links 'Damn! I cannot open ', # message when file opening fails 'GPIGEON.CGI: generate one time GPG messaging links !', # main page title! 'Hi and welcome.', # a greeting at the top of the main page. 'Disconnect', # disconnect button text on main page 'Refresh', # refresh button text 'Generate link', #link generation button text "Generated links by you, $mymailaddr:", # label above links table 'Delete all links', # delete all links button text 'Link', # first table header, 'Link' 'For', # second table header, 'For' 'Deletion', # third table header, 'Delete' 'Deletion failed and here is why : ' ); my $psswd_formfield = '',"\n"; my $SRV_NAME = $ENV{'SERVER_NAME'}; my ($notif_de_creation, $notif_mail_valide, $notif_suppression) = undef; my @created_links = (); if (defined $cgi_query_get->param('supprlien')){ my $pending_deletion = $cgi_query_get->param('supprlien'); my $relpath_todelete = "./l/$pending_deletion"; if (unlink untaint_cgi_filename($relpath_todelete)){ $notif_suppression=''.$text_strings[0].''; } else { $notif_suppression=''.$text_string[24]. $relpath_todelete.':'.$!.''; } } if (defined $cgi_query_get->param('supprtout')){ opendir my $dir_handle, './l' or die "Can't open ./l: $!"; while (readdir $dir_handle) { if ($_ ne '.' and $_ ne '..'){ my $relpath_todelete = "./l/$_"; unlink untaint_cgi_filename($relpath_todelete) or die "$!"; $notif_suppression=''. $text_strings[0] .''; } } closedir $dir_handle; } if (defined $cgi_query_get->param('mail')){ my $non_gpguser = scalar $cgi_query_get->param('mail'); if ( Email::Valid->address($non_gpguser) ){ $notif_mail_valide = "$text_strings[1] $non_gpguser $text_strings[2]"; my $escaped_non_gpguser = escape_arobase($input_mail_addr); my $random_mailform_fn_str = String::Random->new; my @mailform_fn_str_buffer = (); for (1..5){ push @mailform_fn_str_buffer, $random_mailform_fn_str->randregex('\w{1,15}[0-9]{1,15}'); } my $mailform_fn_str_buffer_nospace = join('',@mailform_fn_str_buffer); my $GENERATED_FORM_FILENAME = "$mailform_fn_str_buffer_nospace.cgi"; my $MAILFORM_LINK = "http://$SRV_NAME/cgi-bin/l/$GENERATED_FORM_FILENAME"; my $MAILFORM_RELPATH = "./l/$GENERATED_FORM_FILENAME"; if (open my $mailform_fh, ">", $MAILFORM_RELPATH){ print $mailform_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";', 'use warnings;', "\n", 'use strict;',"\n", 'use GPG;',"\n", '#use CGI::Carp qw(fatalsToBrowser);', 'use CGI qw(param);', "\n", 'my $cgi_query_get = CGI->new;', "\n", 'my ($msg, $enc_msg, $error_processing_msg) = undef;', "\n", 'if (defined $cgi_query_get->param(\'msg\') and $ENV{\'REQUEST_METHOD\'} eq \'POST\'){',"\n", ' $msg = $cgi_query_get->param(\'msg\');', "\n", ' $msg =~ tr/\r//d;', "\n", ' if (length $msg gt 10000){', "\n", ' $error_processing_msg = q{La longueur du message doit être inférieure à 10000 charactères.};', "\n", ' }', "\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, \'0x'. $mymail_gpgid .'\') or die $gpg->error();', "\n"; print_smtp_method($mymailaddr,$mymailaddr_password,$mymailaddr_escaped,$mymail_smtp,$mymail_smtport); print 'unlink "../' . $MAILFORM_RELPATH . '";', "\n", 'print "Location: /gpigeon/merci/index.html\n\n";', "\n", '}', "\n", 'print "Content-type: text/html", "\n\n";', "\n", 'print qq{', "\n", '', "\n", '
', "\n", ' ', "\n", $HTML_CSS, "\n", $HTML_CHARSET, "\n", ''. $text_strings[7] . '' .$escaped_non_gpguser .' :
', "\n", ' ', "\n", ' ', "\n", '};'; close $mailform_fh; chmod(0755,$MAILFORM_RELPATH); $notif_de_creation="$text_strings[9] $non_gpguser'. $text_strings[15] .'
', "\n", '', "\n", '', "\n", ''. $text_strings[19] .'
', "\n", '', "\n", notif_if_defined($notif_suppression), ''. $text_strings[21] .' | ', "\n", ''. $text_strings[22] .' | ', "\n", ''. $text_strings[23] .' | ', "\n", '
---|