Add handling for moderated newsgroups.

This commit is contained in:
Retro_Guy 2024-04-16 07:19:03 -07:00
parent e5ff52f299
commit 2508c5e56f
3 changed files with 77 additions and 22 deletions

View File

@ -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);

View File

@ -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 '<h1 class="np_post_headline"><' . $text_post["message_posted"] . '></h1>';
// Is there a moderated group in Newsgroups: ?
if(is_moderated($newsgroups)) {
echo '<p>** <i>Moderated Newsgroup **</p>';
echo '<p>** <i>Message Queued for Moderation **</p>';
} else {
echo '<p>' . $text_post["message_posted2"] . '</p>';
}
if (isset($CONFIG['auto_return']) && ($CONFIG['auto_return'] == true)) {
echo '<meta http-equiv="refresh" content="0;url=' . $file_thread . '?group=' . urlencode($returngroup) . '"';
}
@ -278,17 +283,6 @@ if ($type == "post") {
file_put_contents($logfile, "\n" . format_log_date() . " Post in: " . $returngroup . " by " . $name, FILE_APPEND);
}
echo '<p><a href="' . $file_thread . '?group=' . $returngroup . '">Back</a></p>';
/*
* if (isset($_REQUEST['returngroup']) && $_REQUEST['returngroup'] !== '') {
* echo '<p><a href="' . $file_thread . '?group=' . $_REQUEST['returngroup'] . '">Your post will appear in ' . group_display_name($_REQUEST['returngroup']) . '</a></p>';
* }
* if (isset($_SESSION['return_page'])) {
* echo '<p><a href="' . $file_thread . '?group=' . $returngroup . '">Back</a></p>';
* //echo '<p><a href="' . $_SESSION['return_page'] . '">Back to Previous Page</a></p>';
* } else {
* echo '<p><a href="' . $file_thread . '?group=' . $returngroup . '">Back</a></p>';
* }
*/
} else {
// article not accepted by the newsserver
$type = "retry";

View File

@ -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) {