Add 'overrides' for some vars and try to read/write history as necessary.

This commit is contained in:
Retro_Guy 2023-08-27 07:05:53 -07:00
parent 65b8d86e25
commit ae4136777b
6 changed files with 221 additions and 147 deletions

View File

@ -1,53 +1,55 @@
<?php
include "../common/config.inc.php";
ini_set('memory_limit','1536M');
ini_set('memory_limit', '1536M');
/* Config file name should be the basename
/*
* Config file name should be the basename
* of your path where you installed rslight
* plus .inc.php.
* So if installed in /var/www/html/rocksolid
* it's rocksolid.inc.php in $config_dir
*/
$config_name = basename(getcwd());
if(file_exists($config_dir.$config_name.'.inc.php')) {
$config_file = $config_dir.$config_name.'.inc.php';
if (file_exists($config_dir . $config_name . '.inc.php')) {
$config_file = $config_dir . $config_name . '.inc.php';
} else {
$config_file = $config_dir.'rslight.inc.php';
$config_file = $config_dir . 'rslight.inc.php';
}
$installed_path = getcwd();
/* $config_path is a directory off the $config_dir
/*
* $config_path is a directory off the $config_dir
* where specific files such as groups.txt
* are located
*/
$config_path = $config_dir.$config_name."/";
$script_path = $config_dir."/scripts/";
$CONFIG = include($config_file);
$config_path = $config_dir . $config_name . "/";
$script_path = $config_dir . "/scripts/";
$CONFIG = include ($config_file);
$OVERRIDES = include ($config_dir . '/overrides.inc.php');
$logdir=$spooldir.'/log';
$lockdir=$spooldir.'/lock';
$ssldir=$spooldir.'/ssl/';
$user_ban_file=$config_dir.'/banned_names.conf';
$logdir = $spooldir . '/log';
$lockdir = $spooldir . '/lock';
$ssldir = $spooldir . '/ssl/';
$user_ban_file = $config_dir . '/banned_names.conf';
/* Permanent configuration changes */
@mkdir($logdir,0755,'recursive');
@mkdir($spooldir.'/upload',0755,'recursive');
chown($logdir,$CONFIG['webserver_user']);
chown($spooldir.'/upload',$CONFIG['webserver_user']);
@mkdir($logdir, 0755, 'recursive');
@mkdir($spooldir . '/upload', 0755, 'recursive');
chown($logdir, $CONFIG['webserver_user']);
chown($spooldir . '/upload', $CONFIG['webserver_user']);
date_default_timezone_set('UTC');
$overboard=true;
$spoolnews=true;
if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
$server=$CONFIG['local_server'];
$port=$CONFIG['local_port'];
$overboard = true;
$spoolnews = true;
if (isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
$server = $CONFIG['local_server'];
$port = $CONFIG['local_port'];
} else {
$server=$CONFIG['remote_server'];
$port=$CONFIG['remote_port'];
$CONFIG['server_auth_user']=$CONFIG['remote_auth_user'];
$CONFIG['server_auth_pass']=$CONFIG['remote_auth_pass'];
$server = $CONFIG['remote_server'];
$port = $CONFIG['remote_port'];
$CONFIG['server_auth_user'] = $CONFIG['remote_auth_user'];
$CONFIG['server_auth_pass'] = $CONFIG['remote_auth_pass'];
}
/*
@ -55,47 +57,47 @@ if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
*/
// Set to true to use framed version of rslight
$frames_on=false;
$frames_on = false;
// The default content for the left side 'menu' frame
$default_menu="/rocksolid/index.php";
$default_menu = "/rocksolid/index.php";
if (isset($frames_on) && $frames_on === true) {
$style_css="style-frames.css";
$frame['content']="content";
$frame['menu']="menu";
$frame['header']="header";
$style_css = "style-frames.css";
$frame['content'] = "content";
$frame['menu'] = "menu";
$frame['header'] = "header";
} else {
$style_css="style.css";
$frame['content']="_self";
$frame['menu']="_self";
$frame['header']="_self";
$style_css = "style.css";
$frame['content'] = "_self";
$frame['menu'] = "_self";
$frame['header'] = "_self";
}
$frame_externallink="_blank";
$frame_externallink = "_blank";
/*
* directories and files
*/
$imgdir="img";
$imgdir = "img";
$file_newsportal="newsportal.php";
$file_index="index.php";
$file_thread="thread.php";
$file_article="article-flat.php";
$file_article_full="article.php";
$file_attachment="attachment.php";
$file_post="post.php";
$file_cancel="cancel.php";
$file_language="lang/english.lang";
$file_footer="footer.inc";
$file_groups=$config_path."groups.txt";
$file_newsportal = "newsportal.php";
$file_index = "index.php";
$file_thread = "thread.php";
$file_article = "article-flat.php";
$file_article_full = "article.php";
$file_attachment = "attachment.php";
$file_post = "post.php";
$file_cancel = "cancel.php";
$file_language = "lang/english.lang";
$file_footer = "footer.inc";
$file_groups = $config_path . "groups.txt";
$title = $CONFIG['title_full'];
/*
* Grouplist Layout
*/
$gl_age=true;
$gl_age = true;
/*
* Thread layout
@ -104,81 +106,81 @@ $gl_age=true;
# simply by date, oldest to newest?
# Set to false to sort by date, true to sort into subthreads.
# Generally, false makes it easier to find the latest posts at the bottom.
$thread_articles=false;
$thread_articles = false;
$thread_treestyle=7;
$thread_show["date"]=false;
$thread_show["subject"]=true;
$thread_show["author"]=true;
$thread_show["authorlink"]=false;
$thread_show["replies"]=false;
$thread_show["lastdate"]=true; // makes only sense with $thread_show["replies"]=false
$thread_show["threadsize"]=true;
$thread_show["latest"]=true;
$thread_maxSubject=70;
$maxfetch=1000;
$maxarticles=0;
$maxarticles_extra=0;
$age_count=3;
$age_time[1]=86400; //24 hours
$age_color[1]="red";
$age_time[2]=259200; //3 days
$age_color[2]="darkgoldenrod";
$age_time[3]=604800; //7 days
$age_color[3]="darkgreen";
$thread_sort_order=-1;
$thread_sort_type="thread";
$articles_per_page=200;
$startpage="first";
$thread_treestyle = 7;
$thread_show["date"] = false;
$thread_show["subject"] = true;
$thread_show["author"] = true;
$thread_show["authorlink"] = false;
$thread_show["replies"] = false;
$thread_show["lastdate"] = true; // makes only sense with $thread_show["replies"]=false
$thread_show["threadsize"] = true;
$thread_show["latest"] = true;
$thread_maxSubject = 70;
$maxfetch = 1000;
$maxarticles = 0;
$maxarticles_extra = 0;
$age_count = 3;
$age_time[1] = 86400; // 24 hours
$age_color[1] = "red";
$age_time[2] = 259200; // 3 days
$age_color[2] = "darkgoldenrod";
$age_time[3] = 604800; // 7 days
$age_color[3] = "darkgreen";
$thread_sort_order = - 1;
$thread_sort_type = "thread";
$articles_per_page = 200;
$startpage = "first";
/*
* article layout
/*
* article layout
*/
$article_show["Subject"]=true;
$article_show["From"]=true;
$article_show["Newsgroups"]=true;
$article_show["Followup"]=true;
$article_show["Organization"]=true;
$article_show["Date"]=true;
$article_show["Message-ID"]=false;
$article_show["User-Agent"]=false;
$article_show["References"]=true;
$article_show["From_link"]=false;
$article_show["trigger_headers"]=true;
//$article_show["From_rewrite"]=array('@',' (at) ');
$article_showthread=true;
$article_graphicquotes=true;
$article_show["Subject"] = true;
$article_show["From"] = true;
$article_show["Newsgroups"] = true;
$article_show["Followup"] = true;
$article_show["Organization"] = true;
$article_show["Date"] = true;
$article_show["Message-ID"] = false;
$article_show["User-Agent"] = false;
$article_show["References"] = true;
$article_show["From_link"] = false;
$article_show["trigger_headers"] = true;
// $article_show["From_rewrite"]=array('@',' (at) ');
$article_showthread = true;
$article_graphicquotes = true;
/*
* settings for the article flat view, if used
*/
$articleflat_articles_per_page=25;
$articleflat_chars_per_articles=10000;
$articleflat_articles_per_page = 25;
$articleflat_chars_per_articles = 10000;
/*
* Message posting
*/
$send_poster_host=false;
$testgroup=true; // don't disable unless you really know what you are doing!
$validate_email=1;
$setcookies=true;
$anonym_address="AnonUser@retrobbs.rocksolidbbs.com";
$msgid_generate="md5";
$msgid_fqdn=$_SERVER["HTTP_HOST"];
$post_autoquote=false;
$post_captcha=false;
$send_poster_host = false;
$testgroup = true; // don't disable unless you really know what you are doing!
$validate_email = 1;
$setcookies = true;
$anonym_address = "AnonUser@retrobbs.rocksolidbbs.com";
$msgid_generate = "md5";
$msgid_fqdn = $_SERVER["HTTP_HOST"];
$post_autoquote = false;
$post_captcha = false;
/*
/*
* Attachments
*/
$attachment_show=true;
$attachment_delete_alternative=true; // delete non-text mutipart/alternative
$attachment_uudecode=true; // experimental!
$attachment_show = true;
$attachment_delete_alternative = true; // delete non-text mutipart/alternative
$attachment_uudecode = true; // experimental!
/*
* Security settings
*/
$block_xnoarchive=false;
$block_xnoarchive = false;
/*
* User registration and database
@ -188,52 +190,52 @@ $block_xnoarchive=false;
/*
* Cache
*/
$cache_articles=false; // article cache, experimental!
$cache_index=600; // cache the group index for ten minutes before reloading
$cache_thread=60; // cache the thread for one minute reloading
$cache_articles = false; // article cache, experimental!
$cache_index = 600; // cache the group index for ten minutes before reloading
$cache_thread = 60; // cache the thread for one minute reloading
/*
* Misc
* Misc
*/
$cutsignature=true;
$compress_spoolfiles=false;
$cutsignature = true;
$compress_spoolfiles = false;
if(isset($spoolnews) && ($spoolnews === true)) {
$spoolpath = $spooldir."/articles/";
$localeol=PHP_EOL.PHP_EOL;
if (isset($spoolnews) && ($spoolnews === true)) {
$spoolpath = $spooldir . "/articles/";
$localeol = PHP_EOL . PHP_EOL;
} else {
$spoolpath = "/var/spool/news/articles/";
$localeol="\r\n\r\n";
$localeol = "\r\n\r\n";
}
// website charset, "koi8-r" for example
//$www_charset = "iso-8859-15";
// $www_charset = "iso-8859-15";
$www_charset = "utf-8";
// Use the iconv extension for improved charset conversions
$iconv_enable=true;
$iconv_enable = true;
/*
* Group specific config
* Group specific config
*/
//$group_config=array(
// '^de\.alt\.fan\.aldi$' => "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);
?>

View File

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

View File

@ -0,0 +1,10 @@
<?php
return [
// expire.php
'max_articles_per_group' => 10000,
// spoolnews.php
'maxarticles_per_run' => 100,
'maxfirstrequest' => 100
];
?>

View File

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

View File

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

View File

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