From ff0e31dacaa0f36ec03c0d6784cbe3e0c0fa736a Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Sun, 13 Aug 2023 10:00:48 -0700 Subject: [PATCH] Rename rslight_db_open to overview_db_open as it makes more sense. --- Rocksolid_Light/rocksolid/article-flat.php | 2 +- Rocksolid_Light/rocksolid/lib/thread.inc.php | 2 +- Rocksolid_Light/rocksolid/newsportal.php | 8 +- Rocksolid_Light/rocksolid/overboard.php | 2 +- Rocksolid_Light/rocksolid/search.php | 2 +- .../rslight/scripts/count_users.php | 2 +- Rocksolid_Light/rslight/scripts/expire.php | 4 +- .../rslight/scripts/import-db3.php | 4 +- .../scripts/import-tradspool-articles.php | 156 ------------------ Rocksolid_Light/rslight/scripts/nocem.php | 4 +- .../rslight/scripts/rslight-lib.php | 28 ++-- Rocksolid_Light/rslight/scripts/spoolnews.php | 6 +- Rocksolid_Light/version.txt | 2 +- 13 files changed, 34 insertions(+), 188 deletions(-) delete mode 100755 Rocksolid_Light/rslight/scripts/import-tradspool-articles.php diff --git a/Rocksolid_Light/rocksolid/article-flat.php b/Rocksolid_Light/rocksolid/article-flat.php index 70467fc..2b302b7 100644 --- a/Rocksolid_Light/rocksolid/article-flat.php +++ b/Rocksolid_Light/rocksolid/article-flat.php @@ -36,7 +36,7 @@ if(strpos($id, '@') !== false) { if($CONFIG['article_database'] == '1') { $database = $spooldir.'/articles-overview.db3'; - $articles_dbh = rslight_db_open($database); + $articles_dbh = overview_db_open($database); $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid'); $articles_query->execute(['messageid' => $id]); $found = 0; diff --git a/Rocksolid_Light/rocksolid/lib/thread.inc.php b/Rocksolid_Light/rocksolid/lib/thread.inc.php index bcb2cbf..8a4cbb2 100644 --- a/Rocksolid_Light/rocksolid/lib/thread.inc.php +++ b/Rocksolid_Light/rocksolid/lib/thread.inc.php @@ -836,7 +836,7 @@ function thread_format_lastmessage($c,$group='') { // Tradspool $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND date=:date ORDER BY date DESC"); $stmt->bindParam(':newsgroup', $group); $stmt->bindParam(':date', $c->date_thread); diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index 128b146..fd47227 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -672,7 +672,7 @@ function groups_show($gruppen) { // Look up last article info for group $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $articles_dbh = rslight_db_open($database); + $articles_dbh = overview_db_open($database); $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:group ORDER BY date DESC LIMIT 2'); $articles_query->execute(['group' => $g->name]); $found = 0; @@ -1449,7 +1449,7 @@ function mail_db_open($database, $table='messages') { return($dbh); } -function rslight_db_open($database, $table='overview') { +function overview_db_open($database, $table='overview') { try { $dbh = new PDO('sqlite:'.$database); } catch (PDOException $e) { @@ -1694,7 +1694,7 @@ function get_db_data_from_msgid($msgid, $group) { if(!is_file($database)) { return false; } - $articles_dbh = rslight_db_open($database); + $articles_dbh = article_db_open($database); $articles_query = $articles_dbh->prepare('SELECT * FROM articles WHERE msgid=:messageid'); $articles_query->execute(['messageid' => $msgid]); $found = 0; @@ -1713,7 +1713,7 @@ function get_db_data_from_msgid($msgid, $group) { function get_data_from_msgid($msgid) { global $spooldir; $database = $spooldir.'/articles-overview.db3'; - $articles_dbh = rslight_db_open($database); + $articles_dbh = overview_db_open($database); $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid'); $articles_query->execute(['messageid' => $msgid]); $found = 0; diff --git a/Rocksolid_Light/rocksolid/overboard.php b/Rocksolid_Light/rocksolid/overboard.php index 1051719..6e620c0 100755 --- a/Rocksolid_Light/rocksolid/overboard.php +++ b/Rocksolid_Light/rocksolid/overboard.php @@ -141,7 +141,7 @@ if($this_overboard['version'] !== $version) { $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; -$dbh = rslight_db_open($database, $table); +$dbh = overview_db_open($database, $table); $query = $dbh->prepare('SELECT * FROM '.$table.' WHERE newsgroup=:findgroup AND date >= '.$cachedate.' ORDER BY date DESC LIMIT '.$maxdisplay); $articles = array(); $db_articles = array(); diff --git a/Rocksolid_Light/rocksolid/search.php b/Rocksolid_Light/rocksolid/search.php index 46ab052..496591f 100644 --- a/Rocksolid_Light/rocksolid/search.php +++ b/Rocksolid_Light/rocksolid/search.php @@ -324,7 +324,7 @@ function get_header_search($group, $terms) { # Prepare search database $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $overview = array(); foreach($grouplist as $thisgroup) { diff --git a/Rocksolid_Light/rslight/scripts/count_users.php b/Rocksolid_Light/rslight/scripts/count_users.php index d73d8b5..5cd100b 100755 --- a/Rocksolid_Light/rslight/scripts/count_users.php +++ b/Rocksolid_Light/rslight/scripts/count_users.php @@ -12,7 +12,7 @@ count_users(); function count_articles() { GLOBAL $CONFIG, $spooldir; $database = $spooldir.'/articles-overview.db3'; - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $count = $dbh->query('SELECT COUNT(DISTINCT msgid) FROM overview')->fetchColumn(); $dbh = null; return $count; diff --git a/Rocksolid_Light/rslight/scripts/expire.php b/Rocksolid_Light/rslight/scripts/expire.php index 2e3d0ff..c6512e4 100755 --- a/Rocksolid_Light/rslight/scripts/expire.php +++ b/Rocksolid_Light/rslight/scripts/expire.php @@ -46,7 +46,7 @@ file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group." echo "Expiring overview database...\n"; file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group." Expiring overview database...", FILE_APPEND); $database = $spooldir.'/articles-overview.db3'; - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $query = $dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND date<:expireme'); $query->execute([':newsgroup' => $group, ':expireme' => $expireme]); $dbh = null; @@ -63,7 +63,7 @@ file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group." } } else { // Expire tradspool $database = $spooldir.'/articles-overview.db3'; - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $query = $dbh->prepare('SELECT FROM overview WHERE newsgroup=:newsgroup AND date<:expireme'); $query->execute([':newsgroup' => $group, ':expireme' => $expireme]); $grouppath = preg_replace('/\./', '/', $group); diff --git a/Rocksolid_Light/rslight/scripts/import-db3.php b/Rocksolid_Light/rslight/scripts/import-db3.php index 993a389..477ae43 100755 --- a/Rocksolid_Light/rslight/scripts/import-db3.php +++ b/Rocksolid_Light/rslight/scripts/import-db3.php @@ -189,7 +189,7 @@ function remove_articles($group) { global $spooldir, $CONFIG, $workpath, $path, $config_name, $logfile; $group = trim($group); # Prepare databases - $dbh = rslight_db_open($spooldir.'/articles-overview.db3'); + $dbh = overview_db_open($spooldir.'/articles-overview.db3'); $clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group"); $clear_stmt->bindParam(':group', $group); $clear_stmt->execute(); @@ -210,7 +210,7 @@ function import_articles($group) { $new_article_stmt = $new_article_dbh->prepare($new_article_sql); $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group"); $clear_stmt->bindParam(':group', $group); $clear_stmt->execute(); diff --git a/Rocksolid_Light/rslight/scripts/import-tradspool-articles.php b/Rocksolid_Light/rslight/scripts/import-tradspool-articles.php deleted file mode 100755 index 9d0d954..0000000 --- a/Rocksolid_Light/rslight/scripts/import-tradspool-articles.php +++ /dev/null @@ -1,156 +0,0 @@ -/
/groups.txt manually\n"; - break; - } - exit(); -} else { - exit(); -} - -function import($group) { - global $logfile, $workpath, $spooldir; - $workpath=$spooldir."/"; - $path=$workpath."articles/"; - $group = trim($group); - if($group == '') { - echo "No group selected\n"; - return; - } else { - $grouppath = preg_replace("/\./", "/", $group); - $grouparticles = scandir($spooldir.'/articles/'.$grouppath); - echo "Importing: ".$group."\n"; - import_articles($group, $grouppath, $grouparticles); - } - echo "\nImport Done\r\n"; - return; -} - -function import_articles($group, $grouppath, $grouparticles) { - global $spooldir, $CONFIG, $workpath, $path, $config_name, $logfile; - $group_overviewfile = $spooldir."/".$group."-overview"; - $gover = file($group_overviewfile); - foreach($gover as $group_overview) { - $overview_msgid = explode("\t", $group_overview); - $msgids[trim($overview_msgid[4])] = true; - } - $database = $spooldir.'/articles-overview.db3'; - $table = 'overview'; - $dbh = rslight_db_open($database, $table); - $sql = 'INSERT INTO '.$table.'(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)'; - $stmt = $dbh->prepare($sql); - foreach($grouparticles as $article) { - if($article == '.' || $article == '..') { - continue; - } - $this_article = $spooldir.'articles/'.$grouppath.'/'.$article; - $article_content = file($this_article); - - $lines=0; - $bytes=0; - $ref=0; - $is_header=1; - $body=""; - $skip=0; - unset($mid); - foreach($article_content as $response) { - $bytes = $bytes + mb_strlen($response, '8bit'); - if(trim($response) == "") { - $is_header=0; - $lines++; - } - if($is_header == 1) { - $response = str_replace("\t", " ", $response); - if(stripos($response, "Message-ID: ") === 0) { - $mid=explode(': ', $response, 2); - $ref=0; - } - if($msgids[trim($mid[1])] == true) { - echo "Duplicate Message-ID for ".$group.":".$article."\n"; - $skip=1; - break; - } - if(stripos($response, "From: ") === 0) { - $from=explode(': ', $response, 2); - } - if(stripos($response, "Date: ") === 0) { - $finddate=explode(': ', $response, 2); - $article_date = strtotime($finddate[1]); - } - if(stripos($response, "Subject: ") === 0) { - $subject=explode('Subject: ', $response, 2); - $ref=0; - } - if(stripos($response, "Xref: ") === 0) { - if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) { - $response="Xref: ".$CONFIG['pathhost']." ".$group.":".$article; - } - $xref=$response; - $ref=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 { - $lines++; - } - } - if($skip == 0) { - // Write to overview. Fix $article to proper article number. Check for duplicate. - echo "Adding ".$group.":".$article." to overview\n"; - $stmt->execute([$group, $article, trim($mid[1]), $article_date, trim($from[1]), trim($subject[1])]); - file_put_contents($group_overviewfile, $article."\t".trim($subject[1])."\t".trim($from[1])."\t".trim($finddate[1])."\t".trim($mid[1])."\t".trim($references)."\t".$bytes."\t".$lines."\t".$xref."\n", FILE_APPEND); - continue; - } - } - $dbh = null; -} -?> diff --git a/Rocksolid_Light/rslight/scripts/nocem.php b/Rocksolid_Light/rslight/scripts/nocem.php index edcfb56..b235fd3 100755 --- a/Rocksolid_Light/rslight/scripts/nocem.php +++ b/Rocksolid_Light/rslight/scripts/nocem.php @@ -92,7 +92,7 @@ function delete_message($messageid, $group) { } if($config_name) { $database = $spooldir.'/articles-overview.db3'; - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $query = $dbh->prepare('DELETE FROM overview WHERE msgid=:messageid'); $query->execute(['messageid' => $messageid]); $dbh = null; @@ -111,7 +111,7 @@ function delete_message($messageid, $group) { // Tradspool if($CONFIG['article_database'] != '1') { $database = $spooldir.'/articles-overview.db3'; - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $query = $dbh->prepare('SELECT FROM overview WHERE newsgroup=:newsgroup AND msgid<:msgid'); $query->execute([':newsgroup' => $group, ':msgid' => $messageid]); $grouppath = preg_replace('/\./', '/', $group); diff --git a/Rocksolid_Light/rslight/scripts/rslight-lib.php b/Rocksolid_Light/rslight/scripts/rslight-lib.php index 5e675c3..c67965d 100755 --- a/Rocksolid_Light/rslight/scripts/rslight-lib.php +++ b/Rocksolid_Light/rslight/scripts/rslight-lib.php @@ -455,7 +455,7 @@ function process_post($message, $group) { $duplicate=0; $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND msgid=:msgid ORDER BY number"); $stmt->execute(['thisgroup' => $group, ':msgid' => $msgid]); while($found = $stmt->fetch()) { @@ -491,7 +491,7 @@ function get_next($nntp_group) { $nntp_article++; $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND number=:number"); $stmt->bindParam(':newsgroup', $nntp_group); $stmt->bindParam(':number', $nntp_article); @@ -521,7 +521,7 @@ function get_last($nntp_group) { $nntp_article--; $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND number=:number"); $stmt->bindParam(':newsgroup', $nntp_group); $stmt->bindParam(':number', $nntp_article); @@ -682,12 +682,14 @@ function get_xover($articles, $msgsock) { $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); - $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND number BETWEEN :first AND :last ORDER BY number"); - $stmt->execute(['thisgroup' => $nntp_group, ':first' => $first, ':last' => $last]); - $msg = ''; - while($row = $stmt->fetch()) { - $msg.= $row['number']."\t".$row['subject']."\t".$row['name']."\t".$row['datestring']."\t".$row['msgid']."\t".$row['refs']."\t".$row['bytes']."\t".$row['lines']."\t".$row['xref']."\r\n"; + $dbh = overview_db_open($database, $table); + + $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND number=:number"); // Why doesn't BETWEEN work properly here? + for($i=$first; $i<=$last; $i++) { + $stmt->execute(['thisgroup' => $nntp_group, ':number' => $i]); + while($row = $stmt->fetch()) { + $msg.= $row['number']."\t".$row['subject']."\t".$row['name']."\t".$row['datestring']."\t".$row['msgid']."\t".$row['refs']."\t".$row['bytes']."\t".$row['lines']."\t".$row['xref']."\r\n"; + } } $dbh = null; $msg.=".\r\n"; @@ -713,7 +715,7 @@ function get_stat($article) { if(!is_file($database)) { return false; } - $dbh = rslight_db_open($database); + $dbh = overview_db_open($database); $query = $articles_dbh->prepare('SELECT * FROM overview WHERE number=:number AND newsgroup=:newsgroup'); $query->execute(['number' => $article, 'newsgroup' => $nntp_group]); $found = 0; @@ -1139,7 +1141,7 @@ $date_i,$mid_i,$references_i,$bytes_i,$lines_i,$xref_i,$body) { # Prepare overview database $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); if(!$dbh) { file_put_contents($logfile, "\n".format_log_date()." ".$section." Failed to connect to database: ".$database, FILE_APPEND); $return_val = "441 Posting failed (overview db error)\r\n"; @@ -1206,7 +1208,7 @@ function find_article_by_msgid($msgid) { global $spooldir; $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms"); $stmt->bindParam(':terms', $msgid); $stmt->execute(); @@ -1224,7 +1226,7 @@ function get_article_list($thisgroup) { global $spooldir; $database = $spooldir."/articles-overview.db3"; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $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(); diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index f39291a..6ed16e2 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -209,7 +209,7 @@ function get_articles($ns, $group) { // Create list of message-ids $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $dbh = overview_db_open($database, $table); $stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup"); $stmt->bindParam(':newsgroup', $nntp_group); $stmt->execute(); @@ -222,7 +222,7 @@ function get_articles($ns, $group) { // Overview database $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $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); @@ -471,7 +471,7 @@ function get_article_list($thisgroup) { global $spooldir; $database = $spooldir."/articles-overview.db3"; $table = 'overview'; - $dbh = rslight_db_open($database, $table); + $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(); diff --git a/Rocksolid_Light/version.txt b/Rocksolid_Light/version.txt index 7ada0d3..ac39a10 100644 --- a/Rocksolid_Light/version.txt +++ b/Rocksolid_Light/version.txt @@ -1 +1 @@ -0.8.5 +0.9.0