78 lines
3.0 KiB
Plaintext
78 lines
3.0 KiB
Plaintext
<p>You may use this web form to contact us. Your message will be encrypted. A copy of your message will not be sent to you unless we reply. For an encrypted reply, paste or link your public key. </p>
|
|
|
|
<noscript><p>Uh-oh, you don't have javascript. This form won't work without it. Please send an email instead.</p></noscript>
|
|
|
|
<p><input type="text" id="name-input" placeholder="Your name"></p>
|
|
<p><input type="email" id="email-input" placeholder="Your email"></p>
|
|
<p><input type="text" id="subject-input" placeholder="Subject"></p>
|
|
<p><textarea id="message-input" placeholder="Your message"></textarea></p>
|
|
|
|
<p><button id="send-button" class="h-captcha" data-sitekey="<YOUR HCAPTCHA SITE KEY>" data-callback="sendClicked">Send</button></p>
|
|
|
|
<p id="msg"></p>
|
|
|
|
<p>This page is protected by <a href="https://www.hcaptcha.com/">hCaptcha</a> so its <a href="https://hcaptcha.com/privacy">Privacy Policy</a> and <a href="https://hcaptcha.com/terms">Terms of Service</a> apply.</p>
|
|
|
|
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
|
|
<script src="/PATH/TO/LOCAL/COPY/OF/openpgp.min.js"></script>
|
|
<script>/* global openpgp fetch */
|
|
let msg = document.getElementById('msg')
|
|
let send = document.getElementById('send-button')
|
|
let name = document.getElementById('name-input')
|
|
let email = document.getElementById('email-input')
|
|
let subj = document.getElementById('subject-input')
|
|
let text = document.getElementById('message-input')
|
|
|
|
const API_URL = "https://mailapi.mydomain.tld/"
|
|
|
|
async function sendClicked (captchaToken) {
|
|
if (captchaToken) {
|
|
send.disabled = true
|
|
msg.innerHTML = `Sending... `
|
|
let res; try {
|
|
res = await fetch(API_URL, {
|
|
method: 'POST',
|
|
// cache: 'no-cache',
|
|
headers: {'content-type': 'application/json'},
|
|
body: JSON.stringify({
|
|
token: captchaToken,
|
|
name: name.value,
|
|
subj: subj.value,
|
|
email: email.value,
|
|
msg: await openpgp.encrypt({
|
|
message: await openpgp.createMessage(
|
|
{ text: `${text.value}\n` }
|
|
),
|
|
encryptionKeys: await openpgp.readKey({
|
|
armoredKey: `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
mQGNBF/TtIoBDADvYLnftyJjfWoeK0zE3Yh3jYsuAj27aU039xh6VaX0IsXQqKLD
|
|
...
|
|
lk6lY0ktTb+vRnndyN3m+XW1mYdv3xUZMjQwMBtgdZbfY43pq8+N55tSTycF
|
|
=Wvbt
|
|
-----END PGP PUBLIC KEY BLOCK-----`,
|
|
}),
|
|
}),
|
|
}),
|
|
})
|
|
} catch (err) {
|
|
send.disabled = false
|
|
console.error(err)
|
|
msg.innerHTML = `Failed to connect to the network. Are you online?`
|
|
}
|
|
console.log(res.json())
|
|
send.disabled = false
|
|
|
|
if (res.status===200) {
|
|
text.value = ''; subj.value = ''; name.value = ''; email.value = ''
|
|
msg.innerHTML = `Sent!`
|
|
} else if (res.status===403)
|
|
msg.innerHTML = `hCaptcha failed! Please try again.`
|
|
else if (res.status===500)
|
|
msg.innerHTML = `Backend failed! Please try again. If the problem persists, please email hostmaster@[this domain].`
|
|
else msg.innerHTML = `Unknown error! Please try again. If the problem persists, please email hostmaster@[this domain].`
|
|
|
|
}
|
|
}
|
|
</script>
|