/* GPGsend - v0.1.1 - Tony Awtrey (tony@awtrey.com) This script is licensed under the GNU Public License: (http://www.gnu.org/copyleft/gpl.html) GPGSend is a script to send a GnuPG encrypted email from a form. This script requires the following: Apache (with mod_action) PHP running as a CGI CGIwrap or SuExec GnuPG An .htaccess file needs to be created in the directory to specify the PHP script is to be wrapped: AddType application/x-httpd-wphp php Action application/x-httpd-wphp /cgi-sys/php-cgiwrap/username/php.cgi The next thing to look at is the $to variable as it needs to be pointed to the right email address. Lastly, the $commandline to run gpg needs to be modified. Change the 'username' in the homedir path to match the username specified in the .htaccess file CGIwrap action. Also specify the 'Full Username' that identifies the key to use to encrypt the message body. */ //////////////////// // Specify debug mode or not //////////////////// $debug = 0; //////////////////// // Check if we are posting //////////////////// if ($REQUEST_METHOD=='POST') { //////////////////// // Check if the form is complete //////////////////// if ($name && $email && $subject && $body) { //////////////////// // Prep the variables for the mail() function //////////////////// $to = "sendit@here.com"; $from = "From: $name <$email>"; $subject = "$subject"; //////////////////// // Clean the var we are passing to the command line //////////////////// $body = escapeshellcmd($body); //////////////////// // Encrypt it! //////////////////// $commandline = "echo $body | /usr/bin/gpg --homedir /home/username/.gnupg -a -r 'Full Username' -e -"; if ($debug==1) { system($commandline); } else { exec($commandline,$encrypted); } //////////////////// // Make the result array a string //////////////////// if (is_array($encrypted)) { $encrypted = implode($encrypted,"\n"); } //////////////////// // Either output the debug info or mail it //////////////////// if ($debug==1) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } else { if ($encrypted) { mail($to,$subject,$encrypted,$from); } else { $notenc = 1; } } } else { $notall = 1; } } ?>
Please fill out the form completely
} ?> if ($notenc==1) { ?>The encryption failed.
} ?> if ($encrypted) { ?>Your information has been sent.
} else { ?> } ?>