#! /usr/bin/perl -wT use Digest::SHA qw(sha256_hex); use warnings; use strict; use Email::Valid; use String::Random; use CGI qw(param); #use CGI::Carp qw(fatalsToBrowser); delete @ENV{qw(IFS PATH CDPATH BASH_ENV)}; sub escape_arobase { my $mailaddress = shift; my $arobase = '@'; my $escarobase = q{\@}; my $escapedmailaddress = $mailaddress; $escapedmailaddress =~ s/$arobase/$escarobase/; 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'); 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 = ('La suppression a réussi !', 'L'adresse', 'est valide !', 'n'est pas valide !', 'sed "s/Inconnu', # displays on main page table when supposed sender isn't identified 'La longueur du message doit être inférieure à 10000 charactères.', 'Formulaire d'envoi de messages GPG', # title for generated links 'Rentrez votre message ci-dessous, ', 'M'envoyer le message', 'Lien généré pour', #displays if link gen is successful 'lien formulaire gpg', # mail subject when clicking a mailto: link in table 'Ton lien est', # message when clicking a mailto: link in table 'Supprimer', # text on button for deleting links 'Mince! Je ne peux pas ouvrir', # message when file opening fails 'GPIGEON.CGI: mails GPG pour le non-initié.', # main page title! 'Salut et bienvenue.', # a greeting at the top of the main page. 'Se déconnecter', # disconnect button text on main page 'Actualiser la page', # refresh button text 'Générer lien', #link generation button text "Liens générés pour $mymailaddr:", # label above links table 'Supprimer tous les liens', # delete all links button text 'Lien', # first table header, 'Link' 'Pour', # second table header, 'For' 'Suppression', # third table header, 'Delete' 'La suppression a échoué. Voici la cause: ' ); my $psswd_formfield = '',"\n"; my $SRV_NAME = $ENV{'SERVER_NAME'}; my ($notif_de_creation, $notif_mail_valide, $notif_suppression) = undef; my @table_des_liens_crees = (); 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 $entered_mail_addr = scalar $cgi_query_get->param('mail'); if ( Email::Valid->address($entered_mail_addr) ){ $notif_mail_valide = "$text_strings[1] $entered_mail_addr $text_strings[2]"; my $escaped_entered_mail_addr = escape_arobase($entered_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 $demandeur_du_lien = q{', $entered_mail_addr , '};', "\n", 'delete @ENV{qw(IFS PATH CDPATH BASH_ENV)};', "\n", '$ENV{\'PATH\'}="/usr/bin";', 'use warnings;', "\n", 'use strict;',"\n", 'use GPG;',"\n", 'use Net::SMTP;',"\n", 'use Net::SMTPS;',"\n", 'use CGI::Carp qw(fatalsToBrowser);', 'use CGI qw(param cookie);', "\n", 'my $cgi_query_get = CGI->new;', "\n", 'my $smtp = Net::SMTPS->new(\''. $mymail_smtp .'\', Port => \''. $mymail_smtport .'\', doSSL => \'ssl\', Debug_SSL => 0);', "\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 " . $demandeur_du_lien . ":\n". $msg, \'0x'. $mymail_gpgid .'\') or die $gpg->error();', "\n", ' $smtp->auth(\''. $mymailaddr .'\', \''. $mymailaddr_password .'\') 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: '. $myescapedmailaddr .'\n");', "\n", '$smtp->datasend("\n");', "\n", '$smtp->datasend("$enc_msg\n");', "\n", '$smtp->dataend();', "\n", 'unlink "../' . $MAILFORM_RELPATH . '";', "\n", 'print "Location: /gpigeon/merci/index.html\n\n";', "\n", '}', "\n", 'else {', "\n", 'die $smtp->message();', "\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_entered_mail_addr .' :
', "\n", ' ', "\n", ' ', "\n", '};'; close $mailform_fh; chmod(0755,$MAILFORM_RELPATH); $notif_de_creation="$text_strings[9] $entered_mail_addr'. $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", '
---|