This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
contact.html
97 lines (88 loc) · 2.62 KB
/
contact.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<title>Contact</title>
<script src="openpgp.min.js" type="text/javascript"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<script>
document.addEventListener('DOMContentLoaded', function() {
if (window.crypto && window.crypto.getRandomValues) {
// form ready
var message = document.getElementById("message");
// encrypt on submit
console.log(document.forms);
document.forms[0].addEventListener("submit", function(evt) {
evt.preventDefault();
if (form.elements['message'].value == '') {
alert('Please enter a message!');
} else {
encrypt(message.value).then(function(encrypted_msg) {
form.elements['message'].value = encrypted_msg;
form.submit();
});
return true;
}
});
} else {
// not ready
document.getElementById("button").disabled = true;
window.alert("Error: Browser not supported\nReason: We need a cryptographically secure PRNG to be implemented (i.e. the window.crypto method)\nSolution: Use Chrome >= 11, Safari >= 3.1, Firefox >= 21, Opera >= 15 or IE >= 11.");
return false;
}
});
function encrypt(msg) {
if (msg.indexOf("-----BEGIN PGP MESSAGE-----") !== -1 && msg.indexOf("-----END PGP MESSAGE-----") !== -1) {
return msg;
} else {
var key = document.getElementById("pubkey").innerHTML;
var publicKey = openpgp.key.readArmored(key).keys[0];
return openpgp.encryptMessage(publicKey, msg).then(function(pgpMessage) {
return pgpMessage;
});
}
}
</script>
<h3><a href="https://github.com/encrypt-to/secure.contactform.php">secure.contactform.php</a></h3>
<p>Secure contact form made with PHP based on OpenPGP.js a JavaScript implementation of the OpenPGP standard.</p>
<form id="form" method="post" action="send_form.php">
<table width="450px">
<tr>
<td valign="top">
<label for="email">Your Email</label>
</td>
<td valign="top">
<input type="text" name="email" style="height:18px;width:300px;">
</td>
</tr>
<tr>
<td valign="top">
<label for="subject">Subject</label>
</td>
<td valign="top">
<input type="text" name="subject" style="height:18px;width:300px;">
</td>
</tr>
<tr>
<td valign="top">
<label for="message">Message</label>
</td>
<td valign="top">
<textarea id="message" name="message" style="height:150px;width:300px;"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit">
</td>
</tr>
</table>
</form>
<!-- your pgp public key -->
<div id="pubkey" hidden="true">
-----BEGIN PGP PUBLIC KEY BLOCK-----
-----END PGP PUBLIC KEY BLOCK-----
</div>
</body>
</html>