From ae4136777b82e7801d7ff3600191b74eef7e3e16 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Sun, 27 Aug 2023 07:05:53 -0700 Subject: [PATCH] Add 'overrides' for some vars and try to read/write history as necessary. --- Rocksolid_Light/rocksolid/config.inc.php | 268 +++++++++--------- Rocksolid_Light/rocksolid/newsportal.php | 10 + Rocksolid_Light/rslight/overrides.inc.php | 10 + Rocksolid_Light/rslight/scripts/expire.php | 56 +++- .../rslight/scripts/import-db3.php | 5 + Rocksolid_Light/rslight/scripts/spoolnews.php | 19 +- 6 files changed, 221 insertions(+), 147 deletions(-) create mode 100644 Rocksolid_Light/rslight/overrides.inc.php diff --git a/Rocksolid_Light/rocksolid/config.inc.php b/Rocksolid_Light/rocksolid/config.inc.php index 926a826..8966b68 100644 --- a/Rocksolid_Light/rocksolid/config.inc.php +++ b/Rocksolid_Light/rocksolid/config.inc.php @@ -1,53 +1,55 @@ "aldi.inc", -// '^de\.' => "german.inc" -//); +// $group_config=array( +// '^de\.alt\.fan\.aldi$' => "aldi.inc", +// '^de\.' => "german.inc" +// ); /* * Do not edit anything below this line */ // Load group specifig config files -if((isset($group)) && (isset($group_config))) { - foreach ($group_config as $key => $value) { - if (ereg($key,$group)) { - include $value; - break; +if ((isset($group)) && (isset($group_config))) { + foreach ($group_config as $key => $value) { + if (ereg($key, $group)) { + include $value; + break; + } } - } } // load the english language definitions first because some of the other // definitions are incomplete -include("lang/english.lang"); -include($file_language); +include ("lang/english.lang"); +include ($file_language); ?> diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index e24eda5..3cf3e6e 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -1823,6 +1823,16 @@ function add_to_history($group, $number, $msgid, $status, $statusdate, $statusre $history_dbh = null; } +function clear_history_by_group($group) { + global $spooldir; + $history = $spooldir . '/history.db3'; + $history_dbh = history_db_open($history); + $clear_stmt = $history_dbh->prepare("DELETE FROM history WHERE newsgroup=:group"); + $clear_stmt->bindParam(':group', $group); + $clear_stmt->execute(); + $history_dbh = null; +} + function get_db_data_from_msgid($msgid, $group) { global $spooldir; diff --git a/Rocksolid_Light/rslight/overrides.inc.php b/Rocksolid_Light/rslight/overrides.inc.php new file mode 100644 index 0000000..edcbd6f --- /dev/null +++ b/Rocksolid_Light/rslight/overrides.inc.php @@ -0,0 +1,10 @@ + 10000, + + // spoolnews.php + 'maxarticles_per_run' => 100, + 'maxfirstrequest' => 100 +]; +?> diff --git a/Rocksolid_Light/rslight/scripts/expire.php b/Rocksolid_Light/rslight/scripts/expire.php index 5cb55eb..0e337d3 100755 --- a/Rocksolid_Light/rslight/scripts/expire.php +++ b/Rocksolid_Light/rslight/scripts/expire.php @@ -15,8 +15,6 @@ if (posix_getsid($pid) === false || ! is_file($lockfile)) { exit(); } -// pcntl_setpriority(0); - $webserver_group = $CONFIG['webserver_user']; $logfile = $logdir . '/expire.log'; @@ -27,22 +25,32 @@ foreach ($grouplist as $groupline) { if ($group[0] == ':') { continue; } + // Delete over $max_articles_per_group if so configured in $OVERRIDES $expire_conf = $CONFIG['expire_days']; + $override_days = convert_max_articles_to_days($group); $expire_user = get_config_value('expire.conf', $group); - + /* + * Order of preference is: + * 1. value in $config_dir/expire.conf + * 2. value in section config file OR $config_dir/overrides.inc.php + * whichever is lower + */ + $expire = $expire_conf; + if ($override_days) { + $expire = $override_days; + } if ($expire_user !== false) { $expire = $expire_user; - } else { - $expire = $expire_conf; } + $expire = trim($expire); if ($expire < 1) { continue; } $expireme = time() - ($expire * 86400); $showme = date('d M, Y', $expireme); - echo "Expire $group articles before $showme\n"; - file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme, FILE_APPEND); + echo "Expire $group articles before " . $showme . " (" . $expire . ") days\n"; + file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme . " (" . $expire . ") days", FILE_APPEND); if ($CONFIG['article_database'] == '1') { $database = $spooldir . '/' . $group . '-articles.db3'; if (is_file($database)) { @@ -71,7 +79,7 @@ foreach ($grouplist as $groupline) { $statusdate = time(); $statusreason = "expired"; $i = 0; - foreach($get_row as $row) { + foreach ($get_row as $row) { if (is_file($spooldir . '/articles/' . $grouppath . '/' . $row['number'])) { unlink($spooldir . '/articles/' . $grouppath . '/' . $row['number']); } @@ -110,4 +118,34 @@ foreach ($grouplist as $groupline) { echo "Expired " . $i . " articles for " . $group . "\n"; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expired " . $i . " articles", FILE_APPEND); } -?> + +function convert_max_articles_to_days($group) +{ + global $spooldir, $OVERRIDES, $CONFIG; + if ($OVERRIDES['max_articles_per_group'] > 0) { + $count = $OVERRIDES['max_articles_per_group']; + } else { + return false; + } + $database = $spooldir . '/articles-overview.db3'; + $overview_dbh = overview_db_open($database); + $overview_query = $overview_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:newsgroup ORDER BY date DESC LIMIT :count'); + $overview_query->execute([ + ':newsgroup' => $group, + ':count' => $count + ]); + $i = 0; + while ($row = $overview_query->fetch()) { + $i ++; + if ($i == $count) { + $found = $row; + } + } + $overview_dbh = null; + if ($found) { + $days = ((time() - $found['date']) / 86400); + return (round($days)); + } else { + return false; + } +} \ No newline at end of file diff --git a/Rocksolid_Light/rslight/scripts/import-db3.php b/Rocksolid_Light/rslight/scripts/import-db3.php index e804e76..d11de1e 100755 --- a/Rocksolid_Light/rslight/scripts/import-db3.php +++ b/Rocksolid_Light/rslight/scripts/import-db3.php @@ -214,6 +214,7 @@ function import_articles($group) { $clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group"); $clear_stmt->bindParam(':group', $group); $clear_stmt->execute(); + clear_history_by_group($group); $sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)'; $stmt = $dbh->prepare($sql); @@ -282,6 +283,10 @@ function import_articles($group) { $this_snippet = get_search_snippet($body, $content_type[1]); $new_article_stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1], $row['article'], $this_snippet]); $stmt->execute([$group, $local, $mid[1], $article_date, $finddate[1], $from[1], $subject[1], $references, $bytes, $lines, $xref]); + $status = "respooled"; + $statusdate = time(); + $statusreason = "repair"; + add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes); echo "\nImported: ".$group." ".$local; file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Imported: ".$group.":".$local, FILE_APPEND); $i++; diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index f059f72..241132b 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -34,11 +34,16 @@ $logfile = $logdir . '/spoolnews.log'; # END MAIN CONFIGURATION @mkdir($spooldir . "/" . $config_name, 0755, 'recursive'); -if (! isset($maxarticles_per_run)) { - $maxarticles_per_run = 100; +// Defaults +$maxarticles_per_run = 100; +$maxfirstrequest = 100; + +// Overrides +if ($OVERRIDES['maxarticles_per_run'] > 0) { + $maxarticles_per_run = $OVERRIDES['maxarticles_per_run']; } -if (! isset($maxfirstrequest)) { - $maxfirstrequest = 100; +if ($OVERRIDES['maxfirstrequest'] > 0) { + $maxfirstrequest = $OVERRIDES['maxfirstrequest']; } if (! isset($CONFIG['enable_nntp']) || $CONFIG['enable_nntp'] != true) { @@ -267,7 +272,7 @@ function get_articles($ns, $group) if ($CONFIG['enable_nntp'] != true) { $local = $article; } - if($msgids[$overview_msgid[$article]] == true) { + 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 ++; @@ -420,6 +425,10 @@ function get_articles($ns, $group) } echo "\nRetrieved: " . $group . " " . $article; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Wrote to spool: " . $CONFIG['remote_server'] . " " . $group . ":" . $article, FILE_APPEND); + $status = "spooled"; + $statusdate = time(); + $statusreason = "imported"; + add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes); $i ++; $article ++; $local ++;