Testing to clean up spamassassin integration.

This commit is contained in:
Retro_Guy 2023-12-23 06:44:03 -07:00
parent 5c66baf348
commit 8dfa22d64d
4 changed files with 65 additions and 52 deletions

View File

@ -443,13 +443,12 @@ function message_post($subject, $from, $newsgroups, $ref, $body, $encryptthis =
/* /*
* SPAM CHECK * SPAM CHECK
*/ */
if ((isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true))) { if (isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true)) {
$spam_result_array = check_spam($subject, $from, $newsgroups, $ref, $body, $msgid); $spam_result_array = check_spam($subject, $from, $newsgroups, $ref, $body, $msgid);
$res = $spam_result_array['res']; $res = $spam_result_array['res'];
$spamresult = $spam_result_array['spamresult']; $spamresult = $spam_result_array['spamresult'];
$spamcheckerversion = $spam_result_array['spamcheckerversion']; $spamcheckerversion = $spam_result_array['spamcheckerversion'];
$spamlevel = $spam_result_array['spamlevel']; $spamlevel = $spam_result_array['spamlevel'];
$spam_fail = $spam_result_array['spam_fail'];
} }
if ($do_attach) { if ($do_attach) {
move_uploaded_file($_FILES["photo"]["tmp_name"], $attachment_temp_dir . $_FILES["photo"]["name"]); move_uploaded_file($_FILES["photo"]["tmp_name"], $attachment_temp_dir . $_FILES["photo"]["name"]);
@ -461,9 +460,8 @@ function message_post($subject, $from, $newsgroups, $ref, $body, $encryptthis =
if (! is_dir($spooldir . '/upload/' . $uploadname)) { if (! is_dir($spooldir . '/upload/' . $uploadname)) {
mkdir($spooldir . '/upload/' . $uploadname); mkdir($spooldir . '/upload/' . $uploadname);
} }
if (! file_exists($spooldir . '/upload/' . $uploadname . '/' . $_FILES["photo"]["name"])) { // Copy attachment to user's upload directory
copy($attachment_temp_dir . $_FILES["photo"]["name"], $spooldir . '/upload/' . $uploadname . '/' . $_FILES["photo"]["name"]); copy($attachment_temp_dir . $_FILES["photo"]["name"], $spooldir . '/upload/' . $uploadname . '/' . $_FILES["photo"]["name"]);
}
} }
$ns = nntp_open($server, $port); $ns = nntp_open($server, $port);
if ($ns != false) { if ($ns != false) {
@ -484,8 +482,9 @@ function message_post($subject, $from, $newsgroups, $ref, $body, $encryptthis =
} }
// X-Rslight headers // X-Rslight headers
if ((isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true))) { if ((isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true))) {
if (isset($res) && $spam_fail == 0) { if ($res === 1) {
fputs($ns, $spamcheckerversion . "\r\n"); fputs($ns, $spamcheckerversion . "\r\n");
if (strpos($spamlevel, '*') !== false) if (strpos($spamlevel, '*') !== false)
fputs($ns, $spamlevel . "\r\n"); fputs($ns, $spamlevel . "\r\n");
@ -495,6 +494,7 @@ function message_post($subject, $from, $newsgroups, $ref, $body, $encryptthis =
} }
} }
} }
fputs($ns, 'From: ' . $from . "\r\n"); fputs($ns, 'From: ' . $from . "\r\n");
if ($followupto !== null) { if ($followupto !== null) {
fputs($ns, 'Followup-To: ' . $followupto . "\r\n"); fputs($ns, 'Followup-To: ' . $followupto . "\r\n");

View File

@ -1311,38 +1311,30 @@ function check_spam($subject, $from, $newsgroups, $ref, $body, $msgid)
global $CONFIG; global $CONFIG;
$logfile = $logdir . '/spam.log'; $logfile = $logdir . '/spam.log';
$spamfile = tempnam($spooldir, 'spam-'); $spamfile = tempnam($spooldir, 'spam-');
file_put_contents($spamfile, $body);
$tmpheader = 'From: ' . $from . "\r\n"; $spamcommand = $CONFIG['spamc'] . ' -E < ' . $spamfile;
if (strpos($from, $CONFIG['anonusername'])) { ob_start();
$tmpheader .= "Anonymous: TRUE\r\n"; passthru($spamcommand, $res);
} $spamresult = ob_get_contents();
$tmpheader .= 'Message-ID: ' . $msgid . "\r\n"; ob_end_clean();
$tmpheader .= 'Subject: ' . encode_subject($subject) . "\r\n\r\n"; $spam_fail = 1;
if ($spamFileHandle = fopen($spamfile, 'w')) { foreach (explode(PHP_EOL, $spamresult) as $line) {
fwrite($spamFileHandle, $tmpheader); $line = str_replace(array(
fwrite($spamFileHandle, $body); "\n\r",
$spamcommand = $CONFIG['spamc'] . ' -E < ' . $spamfile; "\n",
ob_start(); "\r"
$spamresult = passthru($spamcommand, $res); ), '', $line);
$spamresult = ob_get_contents(); if (strpos($line, 'X-Spam-Checker-Version:') !== FALSE) {
ob_end_clean(); $spamcheckerversion = $line;
$spam_fail = 1; $spam_fail = 0;
foreach (explode(PHP_EOL, $spamresult) as $line) { }
$line = str_replace(array( if (strpos($line, 'X-Spam-Level:') !== FALSE) {
"\n\r", $spamlevel = $line;
"\n", }
"\r" if ((strpos($line, "X-Spam-Flag: YES") === 0) && ($res !== 1)) {
), '', $line); $res = 1;
if (strpos($line, 'X-Spam-Checker-Version:') !== FALSE) {
$spamcheckerversion = $line;
$spam_fail = 0;
}
if (strpos($line, 'X-Spam-Level:') !== FALSE) {
$spamlevel = $line;
}
} }
} }
fclose($spamFileHandle);
unlink($spamfile); unlink($spamfile);
if ($res === 1) { if ($res === 1) {
file_put_contents($logfile, "\n" . format_log_date() . " " . $spamresult . "\n------------\n", FILE_APPEND); file_put_contents($logfile, "\n" . format_log_date() . " " . $spamresult . "\n------------\n", FILE_APPEND);
@ -1475,7 +1467,7 @@ function create_xref_from_msgid($msgid, $thisgroup = null, $thisnumber = null)
} }
$xref .= ' ' . $row['newsgroup'] . ':' . $row['number']; $xref .= ' ' . $row['newsgroup'] . ':' . $row['number'];
} }
if (!$found) { if (! $found) {
$xref .= ' ' . $thisgroup . ':' . $thisnumber; $xref .= ' ' . $thisgroup . ':' . $thisnumber;
} }
$overview_dbh = null; $overview_dbh = null;

View File

@ -300,7 +300,8 @@ function prepare_post($filename)
$allgroups = preg_split("/\ |\,/", $ngroups[1]); $allgroups = preg_split("/\ |\,/", $ngroups[1]);
foreach ($allgroups as $agroup) { foreach ($allgroups as $agroup) {
$agroup = trim($agroup); $agroup = trim($agroup);
if ((testGroup($agroup)) || $agroup == '') { if (testGroup($agroup)) {
// if ((testGroup($agroup)) || $agroup == '') {
$response = process_post($message, $agroup); $response = process_post($message, $agroup);
if (substr($response, 0, 3) == "240") { if (substr($response, 0, 3) == "240") {
$ok = 1; $ok = 1;
@ -322,7 +323,7 @@ function prepare_post($filename)
} }
$response = "240 Article received OK\r\n"; $response = "240 Article received OK\r\n";
} else { } else {
$response = "441 Posting failed (group not found)\r\n"; // $response = "441 Posting failed (group not found)\r\n";
} }
return $response; return $response;
} }
@ -404,6 +405,8 @@ function process_post($message, $group)
$orig_newsgroups = $newsgroups; $orig_newsgroups = $newsgroups;
$newsgroups = $CONFIG['spamgroup']; $newsgroups = $CONFIG['spamgroup'];
$group = $newsgroups; $group = $newsgroups;
$response = "441 Posting failed (Exceeds Spam Score)\r\n";
return $response;
} }
/* Find section for posting */ /* Find section for posting */
$section = get_section_by_group($group); $section = get_section_by_group($group);
@ -450,7 +453,7 @@ function process_post($message, $group)
chmod($postfilename, 0600); chmod($postfilename, 0600);
unlink($filename); unlink($filename);
if ($section == "") { if ($section == "") {
$response = "441 Posting failed (group not found)\r\n"; $response = "441 Posting failed (section not found)\r\n";
} else { } else {
$response = insert_article($section, $group, $postfilename, $subject[1], $from[1], $article_date, $date_rep, $msgid, $references, $bytes, $lines, $xref, $body); $response = insert_article($section, $group, $postfilename, $subject[1], $from[1], $article_date, $date_rep, $msgid, $references, $bytes, $lines, $xref, $body);
} }

View File

@ -451,18 +451,36 @@ function get_articles($ns, $group)
$current_article['article'] = $this_article; $current_article['article'] = $this_article;
$current_article['snippet'] = $this_snippet; $current_article['snippet'] = $this_snippet;
foreach ($allgroups as $agroup) { // Check Spam
$agroup = trim($agroup); if (isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true)) {
if ((! testGroup($agroup)) || $agroup == '') { $spam_result_array = check_spam($subject[1], $from[1], $groupnames[1], $references, $body, $mid[1]);
continue; $res = $spam_result_array['res'];
} $spamresult = $spam_result_array['spamresult'];
$current_article['group'] = $agroup; $spamcheckerversion = $spam_result_array['spamcheckerversion'];
if ($group == $agroup) { $spamlevel = $spam_result_array['spamlevel'];
$current_article['local'] = $local; }
insert_article_from_array($current_article); if ($res === 1) {
} else { unlink($grouppath . "/" . $local);
$current_article['local'] = get_next_article_number($agroup); file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Skipping: " . $CONFIG['remote_server'] . " " . $group . ":" . $article . " Exceeds Spam Score", FILE_APPEND);
insert_article_from_array($current_article); // $orig_newsgroups = $newsgroups;
// $newsgroups = $CONFIG['spamgroup'];
// $group = $newsgroups;
$i --;
$local --;
} else {
foreach ($allgroups as $agroup) {
$agroup = trim($agroup);
if ((! testGroup($agroup)) || $agroup == '') {
continue;
}
$current_article['group'] = $agroup;
if ($group == $agroup) {
$current_article['local'] = $local;
insert_article_from_array($current_article);
} else {
$current_article['local'] = get_next_article_number($agroup);
insert_article_from_array($current_article);
}
} }
} }