Initial commit
This commit is contained in:
		
							
								
								
									
										15
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| Copyright (C) 2023 Jack-Benny Persson <jack-benny@cyberinfo.se> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or modify | ||||
| it under the terms of the GNU General Public License as published by | ||||
| the Free Software Foundation; either version 2 of the License, or | ||||
| (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
							
								
								
									
										18
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| # Encrypted form | ||||
| This is a small project to send encrypted form data to a recipient. | ||||
| The data is encrypted using the form recipient's PGP key. | ||||
|  | ||||
| ## Requirements | ||||
| Apache/NGINX with PHP and the GnuGP PHP module. The module is installed with  | ||||
| `apt install php-gnupg` on Debian and Ubuntu systems. | ||||
|  | ||||
| The Apache/NGINX process also needs write permission to the GnuPG home | ||||
| directory (set the GnuPG home directory in `contact.php`). | ||||
|  | ||||
| You also need to set the following variables in `contact.php`: | ||||
|  | ||||
| * `$recipient` (email of the form recipient) | ||||
| * `$subject` (a subject line for the email) | ||||
| * `$key` (the **public** PGP key of the recipient) | ||||
| * `$fingerprint` (the fingerprint of the public PGP key) | ||||
|  | ||||
							
								
								
									
										26
									
								
								contact.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								contact.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
|   <head> | ||||
|     <meta charset="UTF-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||
|     <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||||
|     <title>Contact form</title> | ||||
|   </head> | ||||
|   <body> | ||||
|  | ||||
| 	<form action="contact.php" method="POST" name="myform" id="myform"> | ||||
| 	  <fieldset> | ||||
| 	  <legend>Contact us</legend> | ||||
| 	  <label for="name">Name: </label><input type="text" id="name" name="name" required> | ||||
| 	  <label for="email">E-mail: </label><input type="email" id="email" name="_replyto" required> | ||||
| 	  <label for="message">Message: | ||||
| 	  </label><textarea id="message" name="message" rows="8" required></textarea> | ||||
| 	   | ||||
| 	  </fieldset> | ||||
| 	  <br> | ||||
|  | ||||
| 	  <input type="submit" value="Send" name="contactform"> | ||||
| 	</form> | ||||
|  | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										84
									
								
								contact.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								contact.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| <?php | ||||
| // Where GnuPG should store keys and other stuff. | ||||
| // This directory must be writable by the Apache/NGINX process | ||||
| putenv('GNUPGHOME=/home/apache/gnupg'); | ||||
|  | ||||
| // The recipient email and a subject line | ||||
| $recipient = "me@example.com"; | ||||
| $subject = "Encrypted form"; | ||||
|  | ||||
| //The public PGP key of the recipient | ||||
| $key = "-----BEGIN PGP PUBLIC KEY BLOCK----- | ||||
| ... | ||||
| -----END PGP PUBLIC KEY BLOCK----- | ||||
| "; | ||||
|  | ||||
| // The fingerprint for the above key | ||||
| $fingerprint = "..."; | ||||
|  | ||||
|  | ||||
| // The form data from the HTML form | ||||
| $name = trim(stripslashes(htmlspecialchars($_POST['name']))); | ||||
| $message = trim(stripslashes(htmlspecialchars($_POST['message']))); | ||||
| $email = trim(stripslashes(htmlspecialchars($_POST['_replyto']))); | ||||
|  | ||||
| // Check that user has entered a name, an e-mail address and a message | ||||
| if (empty($name)) | ||||
| { | ||||
| 	echo "No name provided; the message has not been sent\n"; | ||||
| 	exit; | ||||
| } | ||||
|  | ||||
| if (empty($email)) | ||||
| { | ||||
| 	echo "No email provided; the mssage has not been sent\n"; | ||||
| 	exit; | ||||
| } | ||||
|  | ||||
| if (empty($message)) | ||||
| { | ||||
| 	echo "No message provided; the message has not been sent\n"; | ||||
| 	exit; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Initialize GnuPG | ||||
| $gpg = new gnupg(); | ||||
|  | ||||
| // Import the recipient's key | ||||
| $gpg->import($key); | ||||
|  | ||||
| // Add the key | ||||
| $gpg->addencryptkey($fingerprint); | ||||
|  | ||||
| // Encryt the message  | ||||
| $encrypted_message = $gpg->encrypt("Name: $name\nE-mail: $email\n\nMessage: $message"); | ||||
|  | ||||
| $headers = 'From: "Contact form" <info@example.com>' . "\r\n" . | ||||
|     'Reply-To: info@example.com' . "\r\n" . | ||||
|     'Content-Type: text/plain; charset=UTF-8' . "\r\n" . | ||||
|     'X-Mailer: PHP/' . phpversion(); | ||||
|  | ||||
|  | ||||
| // Send the mail (this requires a fully working SMTP-server on the host) | ||||
| mail($recipient, $subject, $encrypted_message, $headers); | ||||
|  | ||||
| ?> | ||||
|  | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
|   <head> | ||||
|       <meta charset="utf-8"> | ||||
|       <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||||
|       <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|       <title>Your message has been sent</title> | ||||
|   </head> | ||||
|   <body> | ||||
|     <h1>Your message has been sent</h1> | ||||
|     <p> | ||||
|     Thank you for your message<br> | ||||
|     <strong><i>Best regards, NNN</i></strong> | ||||
|     </p> | ||||
|   </body> | ||||
| </html> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user