[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH arfnet2-cstims] NNTP announce working


MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: arf20 <aruizfernandez05@xxxxxxxxx>

---
 config.php.example      |  6 ++++++
 publishannouncement.php | 17 ++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/config.php.example b/config.php.example
index e25f427..9ded280 100644
--- a/config.php.example
+++ b/config.php.example
@@ -15,6 +15,12 @@ define('MAIL_FROM', 'system@xxxxxxxxxxx');
 
 define('ANNOUNCE_MAIL', 'announce@xxxxxxxxxxx');
 define('ANNOUNCE_DISCORD', 'https://discord.com/api/webhooks/thing');
+define('ANNOUNCE_IRCSERVER', 'irc.example.com');
+define('ANNOUNCE_IRCCHANNEL', '#example');
+define('ANNOUNCE_NNTPSERVER', 'news.example.com');
+define('ANNOUNCE_NNTPUSER', 'user');
+define('ANNOUNCE_NNTPPASS', 'password');
+define('ANNOUNCE_NNTPGROUP', 'misc.test');
 
 define('DOMAIN', 'dash.example.com');
  
diff --git a/publishannouncement.php b/publishannouncement.php
index b9f3351..37bb2dc 100644
--- a/publishannouncement.php
+++ b/publishannouncement.php
@@ -115,28 +115,31 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
         do {
             $read = fread($fd, 1024);
         } while (!str_contains($read, "Message-ID"));
-        $msgidheader = substr($read, strpos($read, "Message-ID"), -1);
+        /* Assumes CRLF */
+        $msgidheader = substr($read, strpos($read, "Message-ID"), -2);
         $msgidheader = str_replace("Message-ID", "Message-ID:", $msgidheader);
 
-        echo $msgidheader;
-
-        fwrite($fd,
-            $msgidheader."\r\n".
+        $message = 
             "From: System <system@xxxxxxxxx>\r\n".
             "Reply-To: ".getuserbyid($id)["email"]."\r\n".
             "Newsgroups: ".ANNOUNCE_NNTPGROUP."\r\n".
             "Subject: ".$_POST["subject"]."\r\n".
             "Date: ".date("r")."\r\n".
+            $msgidheader."\r\n".
             "Organization: ARFNET\r\n".
             "User-Agent: ARFNET CSTIMS UAS\r\n\r\n".
             $_POST["body"]."\r\n".
-            ".\r\n");
+            ".\r\n";
 
-            echo fread($fd, 1024);
+        $response = fread($fd, 1024);
     
         fwrite($fd, "QUIT\r\n");
 
         fclose($fd);
+
+        if (str_contains($response, "240 Article received"))
+            echo "ok";
+        else echo "error $response<br>";
     }
 
     die();
-- 
2.39.2


References:
[PATCH arfnet2-cstims] NNTP announce workingarf20 <arf20@xxxxxxxxx>