From 2508c5e56f8dc3b21266dde5e6113fcb14c7de6b Mon Sep 17 00:00:00 2001
From: Retro_Guy
Date: Tue, 16 Apr 2024 07:19:03 -0700
Subject: [PATCH] Add handling for moderated newsgroups.
---
Rocksolid_Light/rocksolid/newsportal.php | 62 ++++++++++++++++++-
Rocksolid_Light/rocksolid/post.php | 20 +++---
.../rslight/scripts/rslight-lib.php | 17 +++--
3 files changed, 77 insertions(+), 22 deletions(-)
diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php
index 5cc9e0c..fe2d66c 100644
--- a/Rocksolid_Light/rocksolid/newsportal.php
+++ b/Rocksolid_Light/rocksolid/newsportal.php
@@ -1200,7 +1200,7 @@ function check_bbs_auth($username, $password)
$keyFilename = $config_dir . "/userconfig/" . $username;
foreach ($banned_list as $banned) {
- if($banned[0] == '#')
+ if ($banned[0] == '#')
continue;
if (strtolower(trim($username)) == strtolower(trim($banned))) {
file_put_contents($logfile, "\n" . format_log_date() . " AUTH Failed for: " . $username . ' (user is banned)', FILE_APPEND);
@@ -1551,10 +1551,10 @@ function create_xref_from_msgid($msgid, $thisgroup = null, $thisnumber = null)
function get_search_snippet($body, $content_type = '', $content_transfer_encoding = null)
{
- if($content_transfer_encoding == 'base64') {
+ if ($content_transfer_encoding == 'base64') {
$body = base64_decode($body);
}
- if($content_transfer_encoding == 'quoted-printable') {
+ if ($content_transfer_encoding == 'quoted-printable') {
$body = quoted_printable_decode($body);
}
if ($content_type !== '') {
@@ -2026,6 +2026,62 @@ function verify_gpg_signature($res, $signed_text)
}
}
+function is_moderated($newsgroups)
+{
+ global $CONFIG, $OVERRIDES, $spooldir;
+ $moderated_groups_file = $spooldir . '/moderated_groups.dat';
+ $unmoderated_groups_file = $spooldir . '/unmoderated_groups.dat';
+ $moderated_groups = array();
+ $unmoderated_groups = array();
+
+ $ngroups = preg_split("/[\s,]+/", $newsgroups);
+ foreach ($ngroups as $group) {
+ if (file_exists($moderated_groups_file)) {
+ $moderated_groups = file($moderated_groups_file, FILE_IGNORE_NEW_LINES);
+ if (in_array($group, $moderated_groups)) {
+ return true;
+ }
+ }
+ if (file_exists($unmoderated_groups_file)) {
+ $unmoderated_groups = file($unmoderated_groups_file, FILE_IGNORE_NEW_LINES);
+ if (in_array($group, $unmoderated_groups)) {
+ return false;
+ }
+ }
+ }
+ $ns = nntp2_open();
+ if (! $ns) {
+ return false;
+ }
+
+ foreach ($ngroups as $group) {
+ fputs($ns, "list active $group\r\n");
+ while ($weg = line_read($ns)) {
+ if (strcmp($weg, ".") == 0) {
+ nntp_close($ns);
+ return false;
+ }
+ if (strpos($weg, $group . ' ') !== false) {
+ if (str_ends_with($weg, 'm')) {
+ nntp_close($ns);
+ if (! in_array($newsgroups, $moderated_groups)) {
+ file_put_contents($moderated_groups_file, $group . "\n", FILE_APPEND);
+ }
+ return true;
+ } else {
+ nntp_close($ns);
+ if (! in_array($newsgroups, $unmoderated_groups)) {
+ file_put_contents($unmoderated_groups_file, $group . "\n", FILE_APPEND);
+ }
+ return false;
+ }
+ }
+ }
+ }
+ nntp_close($ns);
+ return false;
+}
+
function get_next_article_number($group)
{
$ok_article = get_article_list($group);
diff --git a/Rocksolid_Light/rocksolid/post.php b/Rocksolid_Light/rocksolid/post.php
index f1a1e03..09935ba 100644
--- a/Rocksolid_Light/rocksolid/post.php
+++ b/Rocksolid_Light/rocksolid/post.php
@@ -260,8 +260,13 @@ if ($type == "post") {
}
// Article sent without errors, or duplicate?
if ((substr($message, 0, 3) == "240") || (substr($message, 0, 7) == "441 435")) {
- echo '<' . $text_post["message_posted"] . '>
';
- echo '' . $text_post["message_posted2"] . '
';
+ // Is there a moderated group in Newsgroups: ?
+ if(is_moderated($newsgroups)) {
+ echo '** Moderated Newsgroup **
';
+ echo '** Message Queued for Moderation **
';
+ } else {
+ echo '' . $text_post["message_posted2"] . '
';
+ }
if (isset($CONFIG['auto_return']) && ($CONFIG['auto_return'] == true)) {
echo 'Back
';
- /*
- * if (isset($_REQUEST['returngroup']) && $_REQUEST['returngroup'] !== '') {
- * echo 'Your post will appear in ' . group_display_name($_REQUEST['returngroup']) . '
';
- * }
- * if (isset($_SESSION['return_page'])) {
- * echo 'Back
';
- * //echo 'Back to Previous Page
';
- * } else {
- * echo 'Back
';
- * }
- */
} else {
// article not accepted by the newsserver
$type = "retry";
diff --git a/Rocksolid_Light/rslight/scripts/rslight-lib.php b/Rocksolid_Light/rslight/scripts/rslight-lib.php
index 7049a36..d33442d 100644
--- a/Rocksolid_Light/rslight/scripts/rslight-lib.php
+++ b/Rocksolid_Light/rslight/scripts/rslight-lib.php
@@ -7,12 +7,12 @@ function interact($msgsock, $use_crypto = false)
$path = $workpath . "articles/";
$groupconfig = $spooldir . "/spoolnews/groups.txt";
- if(isset($OVERRIDES['nntp_full_auth_required']) && $OVERRIDES['nntp_full_auth_required'] == true) {
+ if (isset($OVERRIDES['nntp_full_auth_required']) && $OVERRIDES['nntp_full_auth_required'] == true) {
$nntp_full_auth_required = true;
} else {
$nntp_full_auth_required = false;
}
-
+
$logfile = $logdir . '/nntp.log';
$nntp_group = "";
$nntp_article = "";
@@ -56,8 +56,8 @@ function interact($msgsock, $use_crypto = false)
$command = explode(' ', $buf);
$command[0] = strtolower($command[0]);
// Check if auth required for everything or only posting
- if($nntp_full_auth_required == true && $auth_ok == 0) {
- if($command[0] == 'authinfo' || $command[0] == 'quit' || $command[0] == 'mode') {
+ if ($nntp_full_auth_required == true && $auth_ok == 0) {
+ if ($command[0] == 'authinfo' || $command[0] == 'quit' || $command[0] == 'mode') {
// Ok to continue
} else {
// Auth is required. Try again
@@ -66,7 +66,7 @@ function interact($msgsock, $use_crypto = false)
continue;
}
}
-
+
if (isset($command[1])) {}
if ($command[0] == 'date') {
$msg = '111 ' . date('YmdHis') . "\r\n";
@@ -339,7 +339,7 @@ function prepare_post($filename)
$nocem_file = tempnam($spooldir . "/nocem", "nocem-" . $group . "-");
copy($filename, $nocem_file);
}
- $response = "240 Article received OK\r\n";
+ $response = "240 Article received OK (posted)\r\n";
} else {
// $response = "441 Posting failed (group not found)\r\n";
}
@@ -1125,6 +1125,11 @@ function insert_article($section, $nntp_group, $filename, $subject_i, $from_i, $
{
global $enable_rslight, $spooldir, $CONFIG, $OVERRIDES, $logdir, $lockdir, $logfile;
+ if(is_moderated($nntp_group)) {
+ file_put_contents($logfile, "\n" . format_log_date() . " " . $section . " Moderated group... Queuing local post: " . $nntp_group, FILE_APPEND);
+ $return_val = "240 Article received OK (queued for moderation)\r\n";
+ return ($return_val);
+ }
if (isset($OVERRIDES['insert_disable']) && $OVERRIDES['insert_disable'] != '') {
$insert_disable = explode(',', $OVERRIDES['insert_disable']);
foreach ($insert_disable as $disable) {