From 3f9fd64e82c954799609329653645062ad0b318e Mon Sep 17 00:00:00 2001 From: Gab <24553253+gabrix73@users.noreply.github.com> Date: Thu, 17 Apr 2025 11:21:07 +0200 Subject: Create send.php --- send.php | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 send.php diff --git a/send.php b/send.php new file mode 100644 index 0000000..b31d3e1 --- /dev/null +++ b/send.php @@ -0,0 +1,113 @@ + 3) { + $groups = array_slice($groups, 0, 3); +} +$newsgroups = implode(', ', $groups); + +// Build raw email with dummy To for sendmail -t +$headers = []; +$headers[] = "From: $from"; +$headers[] = "To: mail2news@localhost"; +$headers[] = "Newsgroups: $newsgroups"; +$headers[] = "Subject: $subject"; +if ($references) { + $headers[] = "References: $references"; +} +// PoW header +$headers[] = "X-Hashcash: $hashcash"; +// Enforce signature immediately after PoW +$headers[] = "X-Ed25519-Sig: $sig"; +// Optionally include public key header +if ($pubkey) { + $headers[] = "X-Ed25519-Pub: $pubkey"; +} +$headers[] = "X-No-Archive: Yes"; +$headers[] = "Mime-Version: 1.0"; +$headers[] = "Content-Type: text/plain; charset=UTF-8"; +$headers[] = "Content-Transfer-Encoding: 7bit"; +$headers[] = ""; // end of headers + +$rawEmail = implode("\r\n", $headers) . "\r\n" . $message . "\r\n"; + +// Send via sendmail using mail2news transport +$sendmail = '/usr/sbin/sendmail'; +$cmd = escapeshellcmd($sendmail) . ' -i -oTransport=mail2news -t'; + +$descriptors = [ + 0 => ['pipe', 'r'], // stdin + 1 => ['pipe', 'w'], // stdout + 2 => ['pipe', 'w'], // stderr +]; + +$process = proc_open($cmd, $descriptors, $pipes); +if (!is_resource($process)) { + http_response_code(500); + echo "Failed to invoke sendmail."; + exit; +} + +// Write the raw email +fwrite($pipes[0], $rawEmail); +fclose($pipes[0]); + +// Capture and close outputs +$stderr = stream_get_contents($pipes[2]); +fclose($pipes[1]); +fclose($pipes[2]); + +$returnCode = proc_close($process); +if ($returnCode !== 0) { + http_response_code(500); + echo "Sendmail error (code {$returnCode}):\n" . nl2br(htmlspecialchars($stderr)); + exit; +} + +// Success page +?> + + +
+ +Your post has been handed off to the mail2news transport.
+ Return to Home + + -- cgit v1.2.3