diff options
| author | Gab <24553253+gabrix73@users.noreply.github.com> | 2025-04-21 15:11:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-21 15:11:43 +0200 |
| commit | 46777cd7016b63225ada5ef74d55798c85d0171b (patch) | |
| tree | 85e94197ecee3e409ac9da88f0821c0a36db507a | |
| parent | 9aa9a6246857903b7a58ed8a5ef260bd1f92536e (diff) | |
| download | m2usenet-and-mail2news-46777cd7016b63225ada5ef74d55798c85d0171b.tar.gz m2usenet-and-mail2news-46777cd7016b63225ada5ef74d55798c85d0171b.tar.xz m2usenet-and-mail2news-46777cd7016b63225ada5ef74d55798c85d0171b.zip | |
Update index.php
| -rw-r--r-- | index.php | 732 |
1 files changed, 541 insertions, 191 deletions
@@ -1,219 +1,569 @@ <?php -// /var/www/mail2usenet/index.php -// Production‑ready Mail2Usenet Gateway frontend in English, -// with UTC Hashcash, parallel PoW via Web Workers, -// Ed25519 signature (mandatory), and form reset on return. +// /var/www/m2usenet/index.php ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> - <title>Mail2Usenet Gateway – Production</title> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Mail2Usenet Gateway</title> <style> - body.day { background: #f9f9f9; color: #333; } - body.night { background: #333; color: #ddd; } - .container { max-width:960px; margin:auto; padding:20px; box-shadow:0 0 10px rgba(0,0,0,0.1); } - h1,h2 { text-align:center; } - .tabs { text-align:center; margin:20px 0; } - .tabs button { padding:10px 20px; margin:0 5px; cursor:pointer; background:#eee; border:none; } - .tabs button.active { background:#ccc; } - .tab-content { display:none; padding:20px; } - .tab-content.active { display:block; } - label { display:block; margin-top:10px; font-weight:bold; } - input, select, textarea, button { width:100%; padding:8px; margin-top:5px; box-sizing:border-box; } - .progress-bar { width:100%; background:#ddd; border-radius:5px; overflow:hidden; height:20px; margin-top:10px; } - .progress-bar-inner { height:100%; width:0; background:#4caf50; text-align:center; color:#fff; line-height:20px; } - #themeToggle { position:fixed; top:20px; right:20px; padding:8px 12px; background:#888; color:#fff; border:none; border-radius:5px; cursor:pointer; } - .info { font-style:italic; margin-bottom:15px; } + :root { + --background: #f9f9f9; + --card-bg: #fff; + --text: #333; + --border: #ccc; + --primary: #4caf50; + --primary-hover: #45a049; + --tab-bg: #eee; + --input-bg: #fff; + --input-readonly: #eee; + --progress-bg: #ddd; + } + + .dark-theme { + --background: #1a1a1a; + --card-bg: #2c2c2c; + --text: #e0e0e0; + --border: #444; + --primary: #5cbb60; + --primary-hover: #4caf50; + --tab-bg: #333; + --input-bg: #3c3c3c; + --input-readonly: #2a2a2a; + --progress-bg: #444; + } + + body { + background: var(--background); + color: var(--text); + font-family: sans-serif; + margin: 0; + padding: 0; + transition: background 0.3s ease; + } + + .container { + max-width: 800px; + margin: auto; + padding: 20px; + } + + header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 20px; + } + + .theme-toggle { + display: flex; + align-items: center; + } + + .toggle { + position: relative; + width: 60px; + height: 30px; + background: #ccc; + border-radius: 30px; + padding: 4px; + cursor: pointer; + transition: 0.3s; + } + + .toggle:before { + content: ''; + position: absolute; + width: 26px; + height: 26px; + border-radius: 50%; + background: white; + top: 2px; + left: 2px; + transition: 0.3s; + } + + input[type="checkbox"]:checked + .toggle { + background: #4caf50; + } + + input[type="checkbox"]:checked + .toggle:before { + transform: translateX(30px); + } + + input[type="checkbox"] { + display: none; + } + + .section-info { + background: var(--card-bg); + border-left: 4px solid var(--primary); + padding: 10px 15px; + margin-bottom: 15px; + border-radius: 0 4px 4px 0; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); + } + + .tabs { + display: flex; + flex-direction: column; + gap: 8px; + margin-bottom: 15px; + } + + .tabs button { + display: block; + width: 100%; + padding: 12px; + border: none; + background: var(--tab-bg); + color: var(--text); + cursor: pointer; + border-radius: 4px; + font-weight: bold; + transition: background 0.2s, transform 0.1s; + } + + .tabs button:hover { + background: var(--primary); + color: white; + } + + .tabs button:active { + transform: scale(0.98); + } + + .tab-content { + display: none; + padding: 20px; + background: var(--card-bg); + border: 1px solid var(--border); + border-radius: 4px; + box-shadow: 0 2px 8px rgba(0,0,0,0.1); + margin-bottom: 20px; + } + + .tab-content.active { + display: block; + } + + label { + display: block; + margin-top: 15px; + font-weight: bold; + margin-bottom: 5px; + } + + input, textarea, select { + width: 100%; + padding: 10px; + margin-top: 5px; + box-sizing: border-box; + border: 1px solid var(--border); + border-radius: 4px; + background: var(--input-bg); + color: var(--text); + } + + input[readonly] { + background: var(--input-readonly); + cursor: not-allowed; + } + + button { + margin-top: 15px; + padding: 12px 20px; + background: var(--primary); + color: white; + border: none; + border-radius: 4px; + cursor: pointer; + font-weight: bold; + transition: background 0.2s; + } + + button:hover { + background: var(--primary-hover); + } + + .progress-bar { + width: 100%; + background: var(--progress-bg); + border-radius: 5px; + overflow: hidden; + height: 20px; + margin-top: 10px; + } + + .progress-bar-inner { + height: 100%; + width: 0; + background: var(--primary); + text-align: center; + color: white; + line-height: 20px; + transition: width 0.3s; + } + + .output-field { + margin-top: 15px; + padding: 10px; + background: var(--input-readonly); + border: 1px solid var(--border); + border-radius: 4px; + word-break: break-all; + min-height: 20px; + } + + footer { + text-align: center; + margin-top: 40px; + padding-top: 20px; + border-top: 1px solid var(--border); + font-size: 0.9em; + color: #888; + } + + .footer-links { + display: flex; + justify-content: center; + gap: 20px; + margin-top: 10px; + } + + .footer-links a { + color: var(--primary); + text-decoration: none; + transition: color 0.2s; + } + + .footer-links a:hover { + color: var(--primary-hover); + text-decoration: underline; + } + + @media (max-width: 600px) { + .container { + padding: 10px; + } + .tab-content { + padding: 15px 10px; + } + .footer-links { + flex-direction: column; + gap: 10px; + } + } </style> - <!-- Crypto & Web Worker support --> - <script src="https://cdnjs.cloudflare.com/ajax/libs/tweetnacl/1.0.3/nacl.min.js"></script> - <script src="https://unpkg.com/tweetnacl-util@1.0.2/nacl-util.min.js"></script> - <script> - // Fallback if nacl.util is missing - if (typeof nacl.util === 'undefined') { - nacl.util = { - decodeUTF8: str => new TextEncoder().encode(str), - encodeUTF8: arr => new TextDecoder().decode(arr), - encodeBase64: arr => { let s=''; arr.forEach(b=>s+=String.fromCharCode(b)); return btoa(s); }, - decodeBase64: b64 => { const bin=atob(b64), a=new Uint8Array(bin.length); for(let i=0;i<bin.length;i++) a[i]=bin.charCodeAt(i); return a; } - }; - } - </script> + <!-- Include both TweetNaCl libraries --> +<script src="https://cdn.jsdelivr.net/npm/tweetnacl@1.0.3/nacl.min.js"></script> +<script src="https://cdn.jsdelivr.net/npm/tweetnacl-util@0.15.1/nacl-util.min.js"></script> </head> -<body class="day"> - <button id="themeToggle">Night</button> - <div class="container"> - <h1>Mail2Usenet Gateway – Production</h1> - <div class="tabs"> - <button class="tab-button active" data-tab="token">Generate Hashcash Token</button> - <button class="tab-button" data-tab="signature">Digital Signature</button> - <button class="tab-button" data-tab="send">Send Message</button> +<body> +<div class="container"> + <header> + <h1>Mail2Usenet Gateway</h1> + <div class="theme-toggle"> + <span>🌞</span> + <input type="checkbox" id="themeToggle"> + <label for="themeToggle" class="toggle"></label> + <span>🌙</span> </div> + </header> + + <div class="tabs"> + <button onclick="showTab('pow')">1. Generate Hashcash Token</button> + <button onclick="showTab('sign')">2. Sign Message</button> + <button onclick="showTab('send')">3. Send Message</button> + </div> - <!-- 1) Generate Hashcash Token --> - <div id="token" class="tab-content active"> - <h2>Generate Hashcash Token</h2> - <p class="info">Client‑side PoW: SHA‑1 with leading hex zeros (6/7/8) to mitigate spam.</p> - <label>Email (resource): - <input type="email" id="hcEmail" placeholder="user@example.com" required> - </label> - <label>Difficulty: - <select id="hcBits"> - <option value="24">Fast (24 bits)</option> - <option value="28">Medium (28 bits)</option> - <option value="32">Slow (32 bits)</option> - </select> - </label> - <button id="genTokenBtn">Generate Token</button> - <p>Generated Token: <span id="tokenOutput"></span></p> - <div class="progress-bar"><div id="tokenProgress" class="progress-bar-inner">0</div></div> - <p class="info">Using UTC timestamp (YYMMDDhhmmss) from <code>toISOString()</code>.</p> + <div id="pow" class="tab-content active"> + <h2>Proof-of-Work Token</h2> + + <div class="section-info"> + <p><strong>What is this?</strong> This step generates a "proof-of-work" token (hashcash) that prevents spam by requiring your computer to perform some calculations. This is similar to how cryptocurrencies work - you need to "mine" a valid token before sending a message.</p> + <p><strong>How to use:</strong> Enter your email address, select the difficulty level (higher bits = longer processing time), and click "Generate Token". Your browser will mine a valid token that will be required in the next steps.</p> </div> + + <label>Email (resource): <input type="email" id="hcEmail" placeholder="your@email.com"></label> + <label>Difficulty (bits): + <select id="hcBits"> + <option value="24">24 bits (faster, suitable for most devices)</option> + <option value="28">28 bits (medium difficulty)</option> + <option value="32">32 bits (slower, more secure)</option> + </select> + </label> + <button id="genTokenBtn">Generate Token</button> + <div class="progress-bar"><div id="tokenProgress" class="progress-bar-inner">0</div></div> + <label>Generated Token:</label> + <div id="tokenOutput" class="output-field"></div> + </div> - <!-- 2) Digital Signature (Ed25519) --> - <div id="signature" class="tab-content"> - <h2>Digital Signature (Ed25519)</h2> - <p class="info">Ephemeral key pair; signature is mandatory and discarded on send.</p> - <label>Message to Sign: - <textarea id="messageToSign" rows="6" placeholder="Enter message"></textarea> - </label> - <button id="genKeyBtn">Generate Key Pair</button> - <button id="signMsgBtn">Sign Message</button> - <p>Public Key: <span id="pubKeyOutput"></span></p> - <p>Signature: <span id="signatureOutput"></span></p> + <div id="sign" class="tab-content"> + <h2>Ed25519 Digital Signature</h2> + + <div class="section-info"> + <p><strong>What is this?</strong> This step creates a digital signature for your message using the Ed25519 cryptographic algorithm. This signature helps verify that the message was sent by you and hasn't been tampered with.</p> + <p><strong>How to use:</strong> First, generate a key pair (this creates a public and private key). Then, write your message and click "Sign Message". This will create a digital signature that will be attached to your post.</p> </div> + + <label>Email used for PoW:</label> + <input type="text" id="readonlyEmailSign" readonly> + <label>Message to Sign:</label> + <textarea id="messageToSign" rows="6" placeholder="Write your message here..."></textarea> + <button id="genKeyBtn">Generate Key Pair</button> + <button id="signMsgBtn">Sign Message</button> + + <label>Generated Public Key:</label> + <div id="pubKeyOutput" class="output-field"></div> + <label>Generated Signature:</label> + <div id="signatureOutput" class="output-field"></div> + </div> - <!-- 3) Send Message --> - <div id="send" class="tab-content"> - <h2>Send Message to Usenet</h2> - <p class="info">Includes X-Hashcash and X-Ed25519-Sig headers; max 3 newsgroups.</p> - <form id="sendForm" action="send.php" method="POST"> - <label>User Name: - <input type="text" id="fromName" placeholder="Your Name" required> - </label> - <label>Email: - <input type="email" id="fromEmail" placeholder="user@example.com" required> - </label> - <input type="hidden" id="fromCombined" name="from"> - <label>Newsgroups (max 3): - <input type="text" id="newsgroups" name="newsgroups" placeholder="comp.lang.go, ..." required> - </label> - <label>Subject: - <input type="text" id="subject" name="subject" required> - </label> - <label>References (optional): - <input type="text" id="references" name="references" placeholder="<msgid@domain>"> - </label> - <label>Token X-Hashcash: - <input type="text" id="hcToken" name="xhashcash" required> - </label> - <label>Message: - <textarea id="messageContent" name="message" rows="8" required></textarea> - </label> - <input type="hidden" name="x-ed25519-pub" id="x-ed25519-pub"> - <input type="hidden" name="x-ed25519-sig" id="x-ed25519-sig"> - <button type="submit">Send</button> - </form> + <div id="send" class="tab-content"> + <h2>Send Message</h2> + + <div class="section-info"> + <p><strong>What is this?</strong> This final step sends your signed message to the Usenet network through our NNTP server running on the Tor network at <code>peannyjkqwqfynd24p6dszvtchkq7hfkwymi5by5y332wmosy5dwfaqd.onion</code>.</p> + <p><strong>How to use:</strong> Complete the form below with your name, the newsgroups you want to post to (max 3), subject, and verify that your message and authentication details are correct. Then click "Send" to post your message.</p> </div> + + <label>Email used for PoW:</label> + <input type="text" id="readonlyEmailSend" readonly> + <form id="sendForm" method="POST" action="send.php"> + <label>From (Name): <input type="text" id="fromName" required placeholder="Your Name"></label> + <input type="hidden" name="from" id="fromFull"> + <label>Newsgroups (max 3, comma separated): <input type="text" name="newsgroups" required placeholder="e.g. alt.privacy, comp.security"></label> + <label>Subject: <input type="text" name="subject" required placeholder="Message Subject"></label> + <label>References (optional): <input type="text" name="references" placeholder="Message-ID of post you're replying to"></label> + <label>X-Hashcash Token: <input type="text" name="xhashcash" id="hcToken" required readonly></label> + <label>Message:</label> + <textarea name="message" id="messageContent" rows="8" required placeholder="Your message content will appear here after signing..."></textarea> + <input type="hidden" name="x-ed25519-pub" id="x-ed25519-pub"> + <input type="hidden" name="x-ed25519-sig" id="x-ed25519-sig"> + <button type="submit">Send Message</button> + </form> </div> + + <footer> + <div>Mail2Usenet Gateway © 2025 - Privacy-focused communication tool</div> + <div class="footer-links"> + <a href="https://yamn.virebent.art">Home</a> + <a href="mailto:%69%6E%66%6F%40%76%69%72%65%62%65%6E%74%2E%61%72%74">Contact</a> + <a href="https://github.com/gabrix73/m2usenet-go">Code</a> + </div> + </footer> +</div> + +<script> +// Theme toggle functionality +document.getElementById('themeToggle').addEventListener('change', function() { + document.body.classList.toggle('dark-theme', this.checked); + localStorage.setItem('darkTheme', this.checked); +}); - <script> - // Theme toggle - document.getElementById('themeToggle').onclick = () => { - const b = document.body, btn = document.getElementById('themeToggle'); - b.classList.toggle('night'); b.classList.toggle('day'); - btn.innerText = b.classList.contains('night') ? 'Day' : 'Night'; +// Check for saved theme preference +document.addEventListener('DOMContentLoaded', function() { + const darkTheme = localStorage.getItem('darkTheme') === 'true'; + document.getElementById('themeToggle').checked = darkTheme; + document.body.classList.toggle('dark-theme', darkTheme); + + // Check if nacl is properly loaded + if (typeof nacl === 'undefined') { + console.error("TweetNaCl library not loaded properly!"); + } + + // Initialize nacl.util if it doesn't exist + if (typeof nacl.util === 'undefined') { + nacl.util = { + decodeUTF8: function(str) { + return new TextEncoder().encode(str); + }, + encodeUTF8: function(arr) { + return new TextDecoder().decode(arr); + }, + encodeBase64: function(arr) { + return btoa(Array.from(new Uint8Array(arr)) + .map(byte => String.fromCharCode(byte)) + .join('')); + }, + decodeBase64: function(b64) { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; i++) { + arr[i] = bin.charCodeAt(i); + } + return arr; + } }; + } +}); + +function showTab(id) { + document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active')); + document.getElementById(id).classList.add('active'); +} + +let keyPair = null; +document.getElementById('genKeyBtn').onclick = function() { + try { + // Make sure nacl is loaded and the sign function exists + if (typeof nacl === 'undefined') { + throw new Error("TweetNaCl library is not loaded"); + } + + if (typeof nacl.sign === 'undefined' || typeof nacl.sign.keyPair !== 'function') { + throw new Error("TweetNaCl's sign functionality is not available"); + } + + keyPair = nacl.sign.keyPair(); + const pubKey = keyPair.publicKey; + + // Use our nacl.util implementation to encode the public key + const pubB64 = typeof nacl.util.encodeBase64 === 'function' + ? nacl.util.encodeBase64(pubKey) + : btoa(Array.from(new Uint8Array(pubKey)).map(byte => String.fromCharCode(byte)).join('')); + + document.getElementById('pubKeyOutput').innerText = pubB64; + document.getElementById('x-ed25519-pub').value = pubB64; + alert("Key pair generated successfully! You can now sign your message."); + } catch (error) { + console.error("Error generating key pair:", error); + alert("Error generating key pair: " + error.message); + } +}; + +document.getElementById('signMsgBtn').onclick = function() { + try { + if (!keyPair) { + return alert("Please generate a key pair first."); + } + + const msg = document.getElementById('messageToSign').value; + if (!msg) { + return alert("Please enter a message to sign."); + } + + const msgBytes = typeof nacl.util.decodeUTF8 === 'function' + ? nacl.util.decodeUTF8(msg) + : new TextEncoder().encode(msg); + + const sig = nacl.sign.detached(msgBytes, keyPair.secretKey); + + const sigB64 = typeof nacl.util.encodeBase64 === 'function' + ? nacl.util.encodeBase64(sig) + : btoa(Array.from(new Uint8Array(sig)).map(byte => String.fromCharCode(byte)).join('')); + + document.getElementById('signatureOutput').innerText = sigB64; + document.getElementById('x-ed25519-sig').value = sigB64; + document.getElementById('messageContent').value = msg + "\n\n--- Digital Signature ---\n" + sigB64; + alert("Message signed successfully! You can now proceed to the Send Message tab."); + } catch (error) { + console.error("Error signing message:", error); + alert("Error signing message: " + error.message); + } +}; - // Tab navigation - document.querySelectorAll('.tab-button').forEach(btn => { - btn.onclick = () => { - document.querySelectorAll('.tab-button').forEach(b=>b.classList.remove('active')); - document.querySelectorAll('.tab-content').forEach(c=>c.classList.remove('active')); - btn.classList.add('active'); - document.getElementById(btn.dataset.tab).classList.add('active'); - }; - }); +document.getElementById('genTokenBtn').onclick = () => { + const email = document.getElementById('hcEmail').value; + const bits = parseInt(document.getElementById('hcBits').value); + if (!email) return alert("Please enter an email address."); + + // Update UI to show processing + document.getElementById('genTokenBtn').disabled = true; + document.getElementById('genTokenBtn').textContent = 'Processing...'; + + const now = new Date(); + const timestamp = now.getUTCFullYear().toString().slice(2) + + ("0"+(now.getUTCMonth()+1)).slice(-2) + + ("0"+now.getUTCDate()).slice(-2) + + ("0"+now.getUTCHours()).slice(-2) + + ("0"+now.getUTCMinutes()).slice(-2) + + ("0"+now.getUTCSeconds()).slice(-2); + const ext = ""; + const rand = Math.floor(Math.random()*1e6); + const prefix = `1:${bits}:${timestamp}:${email}:${ext}:${rand}:`; + const zeros = bits/4; + const cores = navigator.hardwareConcurrency || 2; + let found = false; + let totalChecked = Array(cores).fill(0); + const progBar = document.getElementById('tokenProgress'); + progBar.style.width = '0%'; progBar.innerText = '0'; + const workers = []; - // Clear form on back-button - window.addEventListener('pageshow', () => document.getElementById('sendForm').reset()); + function updateProgress() { + const sum = totalChecked.reduce((a,b)=>a+b,0); + const pct = Math.min(100,(sum%(cores*1000))/(cores*10)); + progBar.style.width = pct + '%'; + progBar.innerText = sum; + } - // Parallel PoW via Web Workers, UTC timestamp - document.getElementById('genTokenBtn').onclick = () => { - const email = document.getElementById('hcEmail').value.trim(); - const bits = +document.getElementById('hcBits').value; - if (!email) return alert('Enter a valid email.'); - const now = new Date(), iso = now.toISOString(); - const dateStr = - iso.substr(2,2)+iso.substr(5,2)+iso.substr(8,2)+ - iso.substr(11,2)+iso.substr(14,2)+iso.substr(17,2); - const ext='', rand=Math.floor(Math.random()*1e6).toString(); - const prefix = `1:${bits}:${dateStr}:${email}:${ext}:${rand}:`; - const zeros = bits/4, cores = navigator.hardwareConcurrency||2; - let found=false, totalChecked=Array(cores).fill(0); - const prog = document.getElementById('tokenProgress'); - prog.style.width='0%'; prog.innerText='0'; - const workers=[]; - function upd() { - const sum = totalChecked.reduce((a,b)=>a+b,0), - pct = Math.min(100,(sum%(cores*1000))/(cores*10)); - prog.style.width=pct+'%'; prog.innerText=sum; + for (let i = 0; i < cores; i++) { + const w = new Worker('powWorker.js'); + w.postMessage({ prefix, targetZeros: zeros, startNonce: i, step: cores }); + w.onmessage = e => { + if (found) return; + if (e.data.type === 'found') { + found = true; + const token = prefix + e.data.nonce; + document.getElementById('tokenOutput').innerText = token; + document.getElementById('hcToken').value = token; + const fromName = document.getElementById('fromName').value; + document.getElementById('fromFull').value = `${fromName} <${email}>`; + document.getElementById('readonlyEmailSign').value = email; + document.getElementById('readonlyEmailSend').value = email; + workers.forEach(x => x.terminate()); + + // Restore button + document.getElementById('genTokenBtn').disabled = false; + document.getElementById('genTokenBtn').textContent = 'Generate Token'; + + // Show completion message + alert("Token generation complete! You can now proceed to the Sign Message tab."); } - for(let i=0;i<cores;i++){ - const w=new Worker('powWorker.js'); - w.postMessage({ prefix, targetZeros:zeros, startNonce:i, step:cores }); - w.onmessage=e=>{ - if(found) return; - if(e.data.type==='found'){ - found=true; - const token=prefix+e.data.nonce; - document.getElementById('tokenOutput').innerText=token; - document.getElementById('hcToken').value=token; - document.getElementById('fromEmail').value=email; - workers.forEach(x=>x.terminate()); - } - if(e.data.type==='progress'){ - totalChecked[i]=e.data.checked; upd(); - } - }; - workers.push(w); + if (e.data.type === 'progress') { + totalChecked[i] = e.data.checked; + updateProgress(); } }; + workers.push(w); + } +}; - // Ed25519 signature - let keyPair=null; - document.getElementById('genKeyBtn').onclick = () => { - try { - keyPair = nacl.sign.keyPair(); - document.getElementById('pubKeyOutput').innerText = nacl.util.encodeBase64(keyPair.publicKey); - alert('Key pair generated. Secret key will be discarded.'); - } catch(e){ alert('Key generation error: '+e); } - }; - document.getElementById('signMsgBtn').onclick = () => { - if(!keyPair) return alert('Generate key pair first.'); - const msg=document.getElementById('messageToSign').value; - if(!msg) return alert('Enter a message.'); - try { - const sig=nacl.sign.detached(nacl.util.decodeUTF8(msg),keyPair.secretKey), - sigB64=nacl.util.encodeBase64(sig), - pubB64=nacl.util.encodeBase64(keyPair.publicKey); - document.getElementById('signatureOutput').innerText=sigB64; - document.getElementById('x-ed25519-sig').value=sigB64; - document.getElementById('x-ed25519-pub').value=pubB64; - document.getElementById('messageContent').value=msg+"\n\n--- Digital Signature ---\n"+sigB64; - } catch(e){ alert('Signing error: '+e); } - }; +document.getElementById('sendForm').addEventListener('submit', function(e) { + // Form validation + const requiredFields = ['fromName', 'hcToken', 'messageContent', 'x-ed25519-pub', 'x-ed25519-sig']; + const missing = requiredFields.filter(id => !document.getElementById(id).value.trim()); + + if (missing.length > 0) { + e.preventDefault(); + alert("Please complete all previous steps before sending your message."); + return false; + } + + // Log for debugging + console.log('[DEBUG] x-ed25519-pub:', document.getElementById('x-ed25519-pub').value); + console.log('[DEBUG] x-ed25519-sig:', document.getElementById('x-ed25519-sig').value); + console.log('[DEBUG] From (full):', document.getElementById('fromFull').value); + console.log('[DEBUG] Token:', document.getElementById('hcToken').value); + console.log('[DEBUG] Message:', document.getElementById('messageContent').value); + + if (confirm("Are you sure you want to send this message to the Usenet network?")) { + return true; + } else { + e.preventDefault(); + return false; + } +}); - // Combine From - function updateFrom(){ - const n=document.getElementById('fromName').value.trim(), - e=document.getElementById('fromEmail').value.trim(); - if(n&&e) document.getElementById('fromCombined').value=`${n} <${e}>`; - } - document.getElementById('fromName').oninput=updateFrom; - document.getElementById('fromEmail').oninput=updateFrom; - updateFrom(); - </script> +// Handle form field updates for "from" field +document.getElementById('fromName').addEventListener('input', function() { + const email = document.getElementById('hcEmail').value; + if (email) { + document.getElementById('fromFull').value = `${this.value} <${email}>`; + } +}); +</script> </body> -</html> +</html> |
