prepare($article_sql); } // Create list of message-ids $database = $spooldir . '/articles-overview.db3'; $table = 'overview'; $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT msgid FROM $table WHERE newsgroup=:newsgroup"); $stmt->bindParam(':newsgroup', $group); $stmt->execute(); while ($row = $stmt->fetch()) { $msgids[$row['msgid']] = true; } $dbh = null; // Check history database for deleted message-ids $database = $spooldir . '/history.db3'; $table = 'history'; $dbh = history_db_open($database, $table); $stmt = $dbh->prepare("SELECT msgid FROM $table WHERE newsgroup=:newsgroup"); $stmt->bindParam(':newsgroup', $group); $stmt->execute(); while ($row = $stmt->fetch()) { $msgids[$row['msgid']] = true; } $dbh = null; // Overview database $database = $spooldir . '/articles-overview.db3'; $table = 'overview'; $dbh = overview_db_open($database, $table); $sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)'; $stmt = $dbh->prepare($sql); // Get overview from server $server_overview = array(); $re = false; if (($detail[3] - $article) > $maxarticles_per_run) { $getlast = $article + $maxarticles_per_run; } else { $getlast = $detail[3]; } fputs($ns, "xover " . $article . "-" . $getlast . "\r\n"); $response = line_read($ns); // and once more if ((substr($response, 0, 3) != "224")) { file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Cannot get overview from " . $CONFIG['remote_server'] . " for " . $group, FILE_APPEND); return false; } while (trim($response = line_read($ns)) !== '.') { $ov = preg_split("/\t/", $response); $overview_msgid[$ov[0]] = $ov[4]; } # Pull articles and save them in our spool @mkdir($grouppath, 0755, 'recursive'); $i = 0; while ($article <= $detail[3]) { if (! is_numeric($article)) { file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " DEBUG This should show server group:article number: " . $CONFIG['remote_server'] . " " . $group . ":" . $article, FILE_APPEND); break; } if ($CONFIG['enable_nntp'] != true) { $local = $article; } if($msgids[$overview_msgid[$article]] == true) { echo "\nDuplicate Message-ID for: " . $group . ":" . $article; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Duplicate Message-ID for: " . $group . ":" . $article, FILE_APPEND); $article ++; continue; } fputs($ns, "article " . $article . "\r\n"); $response = line_read($ns); if (strcmp(substr($response, 0, 3), "220") != 0) { echo "\n" . $response; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $response, FILE_APPEND); $article ++; continue; } $articleHandle = $grouppath . "/" . $local; $response = line_read($ns); $lines = 0; $bytes = 0; $ref = 0; $banned = 0; $is_header = 1; $body = ""; while (strcmp($response, ".") != 0) { $bytes = $bytes + mb_strlen($response, '8bit'); if (trim($response) == "" || $lines > 0) { $is_header = 0; $lines ++; } if ($is_header == 1) { $response = str_replace("\t", " ", $response); // Find article date if (stripos($response, "Date: ") === 0) { $finddate = explode(': ', $response, 2); $article_date = strtotime($finddate[1]); } // Get overview data if (stripos($response, "Message-ID: ") === 0) { $mid = explode(': ', $response, 2); $ref = 0; } if (stripos($response, "From: ") === 0) { $from = explode(': ', $response, 2); if (isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) { foreach ($banned_names as $banned_name) { if (stripos($from[1], $banned_name) !== false) { $banned = 1; } } } $ref = 0; } if (stripos($response, "Subject: ") === 0) { $subject = explode('Subject: ', $response, 2); $ref = 0; } if (stripos($response, "Newsgroups: ") === 0) { $response = str_ireplace($group, $group, $response); $ref = 0; } if (stripos($response, "Xref: ") === 0) { if (isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) { $response = "Xref: " . $CONFIG['pathhost'] . " " . $group . ":" . $local; } $xref = $response; $ref = 0; } if (stripos($response, "Content-Type: ") === 0) { preg_match('/.*charset=.*/', $response, $te); $content_type = explode("Content-Type: text/plain; charset=", $te[0]); } if (stripos($response, "References: ") === 0) { $this_references = explode('References: ', $response); $references = $this_references[1]; $ref = 1; } if ((stripos($response, ':') === false) && (strpos($response, '>'))) { if ($ref == 1) { $references = $references . $response; } } } else { $body .= $response . "\n"; } file_put_contents($articleHandle, $response . "\n", FILE_APPEND); // Check here for broken $ns connection before continuing $response = fgets($ns, 1200); if ($response == false) { file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Lost connection to " . $CONFIG['remote_server'] . ":" . $CONFIG['remote_port'] . " retrieving article " . $article, FILE_APPEND); unlink($grouppath . "/" . $local); break; // continue; } $response = str_replace("\n", "", str_replace("\r", "", $response)); } file_put_contents($articleHandle, $response . "\n", FILE_APPEND); $lines = $lines - 1; $bytes = $bytes + ($lines * 2); // Don't spool article if $banned=1 if ($banned == 1) { unlink($grouppath . "/" . $local); file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Skipping: " . $CONFIG['remote_server'] . " " . $group . ":" . $article . " user: " . $from[1] . " is banned", FILE_APPEND); $article ++; } else { if ((strpos($CONFIG['nocem_groups'], $group) !== false) && ($CONFIG['enable_nocem'] == true)) { if (strpos($subject[1], $nocem_check) !== false) { $nocem_file = tempnam($spooldir . "/nocem", "nocem-" . $group . "-"); copy($grouppath . "/" . $local, $nocem_file); } } if ((strpos($rslight_gpg['nntp_group'], $group) !== false) && ($rslight_gpg['enable'] == '1')) { if (strpos($subject[1], $bbsmail_check) !== false) { $bbsmail_file = preg_replace('/@@RSL /', '', $subject[1]); $bbsmail_filename = $spooldir . "/bbsmail/in/bbsmail-" . $bbsmail_file; copy($grouppath . "/" . $local, $bbsmail_filename); } } // Overview $stmt->execute([ $group, $local, $mid[1], $article_date, $finddate[1], $from[1], $subject[1], $references, $bytes, $lines, $xref ]); $references = ""; if ($CONFIG['article_database'] == '1') { $this_article = file_get_contents($grouppath . "/" . $local); // CREATE SEARCH SNIPPET $this_snippet = get_search_snippet($body, $content_type[1]); $article_stmt->execute([ $group, $local, $mid[1], $article_date, $from[1], $subject[1], $this_article, $this_snippet ]); unlink($grouppath . "/" . $local); } else { if ($article_date > time()) $article_date = time(); touch($grouppath . "/" . $local, $article_date); } echo "\nRetrieved: " . $group . " " . $article; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Wrote to spool: " . $CONFIG['remote_server'] . " " . $group . ":" . $article, FILE_APPEND); $i ++; $article ++; $local ++; if ($i > $maxarticles_per_run) { break; } } } $article --; // $local--; // Update title if (! is_file($workpath . $group . "-title")) { fputs($ns, "XGTITLE " . $group . "\r\n"); $response = line_read($ns); if (strcmp(substr($response, 0, 3), "282") == 0) { $titlefile = $workpath . $group . "-title"; $response = line_read($ns); while (strcmp($response, ".") != 0) { file_put_contents($titlefile, $response); $response = line_read($ns); } } } # Save config $grouplist = file($remote_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $saveconfig = fopen($remote_groupfile, 'w+'); foreach ($grouplist as $savegroup) { $name = explode(':', $savegroup); if (strcmp($name[0], $group) == 0) { fputs($saveconfig, $group . ":" . $article . "\n"); } else { fputs($saveconfig, $savegroup . "\n"); } } fclose($saveconfig); $grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $saveconfig = fopen($local_groupfile, 'w+'); foreach ($grouplist as $savegroup) { $name = explode(':', $savegroup); if (strcmp($name[0], $group) == 0) { fputs($saveconfig, $group . ":" . $local . "\n"); } else { fputs($saveconfig, $savegroup . "\n"); } } fclose($saveconfig); if ($CONFIG['article_database'] == '1') { $article_dbh = null; } $dbh = null; } function create_spool_groups($in_groups, $out_groups) { global $spooldir; $grouplist = file($in_groups, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $temp_file = tempnam($spooldir . "/tmp/", 'groupfile-'); $groupout = fopen($out_groups, "a+"); foreach ($grouplist as $group) { if ($group[0] == ":") { continue; } $thisgroup = preg_split("/( |\t)/", $group, 2); $found = 0; while (($buffer = fgets($groupout)) !== false) { $mod_buffer = explode(':', $buffer); if (strcmp($thisgroup[0], $mod_buffer[0]) == 0) { file_put_contents($temp_file, "$buffer", FILE_APPEND); $found = 1; break; } } if ($found == 0) { file_put_contents($temp_file, "$thisgroup[0]\n", FILE_APPEND); continue; } } fclose($groupout); rename($temp_file, $out_groups); return; } function get_article_list($thisgroup) { global $spooldir; $database = $spooldir . "/articles-overview.db3"; $table = 'overview'; $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup ORDER BY number"); $stmt->execute([ 'thisgroup' => $thisgroup ]); $ok_article = array(); while ($found = $stmt->fetch()) { $ok_article[] = $found['number']; } $dbh = null; return (array_unique($ok_article)); } ?>