Add sqlite support for articles spool
This commit is contained in:
parent
12c7293708
commit
34ed3f90ce
|
@ -467,10 +467,35 @@ function show_header($head,$group,$local_poster=false) {
|
|||
|
||||
function display_full_headers($id,$group,$name,$from) {
|
||||
global $spoolpath, $CONFIG;
|
||||
$thisgroup = preg_replace('/\./', '/', $group);
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$message = np_get_db_article($id, $group, 1);
|
||||
foreach($message as $line) {
|
||||
if(trim($line) == '') {
|
||||
break;
|
||||
}
|
||||
if(stripos($line, 'Xref: ') === 0) {
|
||||
continue;
|
||||
}
|
||||
if(stripos($line, 'From: ') === 0) {
|
||||
$return.='From: ';
|
||||
if(isset($CONFIG['hide_email']) && $CONFIG['hide_email'] == true) {
|
||||
$return.=truncate_email($from);
|
||||
} else {
|
||||
$return.=htmlspecialchars($from);
|
||||
}
|
||||
if ($name != "") {
|
||||
$return.=' ('.htmlspecialchars($name).')';
|
||||
}
|
||||
$return.='<br />';
|
||||
continue;
|
||||
}
|
||||
$return.=mb_decode_mimeheader(htmlspecialchars($line)).'<br />';
|
||||
}
|
||||
} else {
|
||||
$thisgroup = preg_replace('/\./', '/', $group);
|
||||
$message=fopen($spoolpath.$thisgroup.'/'.$id, 'r');
|
||||
|
||||
$message=fopen($spoolpath.$thisgroup.'/'.$id, 'r');
|
||||
while($line=fgets($message)) {
|
||||
while($line=fgets($message)) {
|
||||
if(trim($line) == '') {
|
||||
break;
|
||||
}
|
||||
|
@ -489,13 +514,11 @@ function display_full_headers($id,$group,$name,$from) {
|
|||
}
|
||||
$return.='<br />';
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$return.=mb_decode_mimeheader(htmlspecialchars($line)).'<br />';
|
||||
}
|
||||
$return.=mb_decode_mimeheader(htmlspecialchars($line)).'<br />';
|
||||
}
|
||||
fclose($message);
|
||||
}
|
||||
fclose($message);
|
||||
|
||||
return($return);
|
||||
}
|
||||
|
||||
|
|
|
@ -261,6 +261,7 @@ function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis,$encryp
|
|||
}
|
||||
if (isset($CONFIG['organization']))
|
||||
fputs($ns,'Organization: '.quoted_printable_encode($CONFIG['organization'])."\r\n");
|
||||
$body=trim($body);
|
||||
if ((isset($CONFIG['postfooter'])) && ($CONFIG['postfooter']!="")) {
|
||||
$body.="\n-- \n".$CONFIG['postfooter']."\n".$_SERVER['HTTP_HOST'];
|
||||
}
|
||||
|
|
|
@ -1198,14 +1198,14 @@ function get_date_interval($value) {
|
|||
return $variance;
|
||||
}
|
||||
|
||||
function rslight_db_open($database, $table) {
|
||||
function rslight_db_open($database, $table='overview') {
|
||||
try {
|
||||
$dbh = new PDO('sqlite:'.$database);
|
||||
} catch (PDOExeption $e) {
|
||||
echo 'Connection failed: '.$e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$dbh->exec("CREATE TABLE IF NOT EXISTS $table(
|
||||
$dbh->exec("CREATE TABLE IF NOT EXISTS overview(
|
||||
id INTEGER PRIMARY KEY,
|
||||
newsgroup TEXT,
|
||||
number TEXT,
|
||||
|
@ -1213,8 +1213,76 @@ function rslight_db_open($database, $table) {
|
|||
date TEXT,
|
||||
name TEXT,
|
||||
subject TEXT)");
|
||||
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_date on overview(date)');
|
||||
$stmt->execute();
|
||||
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_newsgroup on overview(newsgroup)');
|
||||
$stmt->execute();
|
||||
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_newsgroup_number on overview(newsgroup,number)');
|
||||
$stmt->execute();
|
||||
return($dbh);
|
||||
}
|
||||
|
||||
function article_db_open($database) {
|
||||
try {
|
||||
$dbh = new PDO('sqlite:'.$database);
|
||||
} catch (PDOExeption $e) {
|
||||
echo 'Connection failed: '.$e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$dbh->exec("CREATE TABLE IF NOT EXISTS articles(
|
||||
id INTEGER PRIMARY KEY,
|
||||
newsgroup TEXT,
|
||||
number TEXT,
|
||||
msgid TEXT,
|
||||
date TEXT,
|
||||
name TEXT,
|
||||
subject TEXT,
|
||||
article TEXT)");
|
||||
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS db_number on articles(number)');
|
||||
$stmt->execute();
|
||||
return($dbh);
|
||||
}
|
||||
|
||||
function np_get_db_article($article, $group, $makearray=1, $dbh=null) {
|
||||
global $config_dir,$path,$groupconfig,$config_name,$logdir,$spooldir;
|
||||
$logfile=$logdir.'/newsportal.log';
|
||||
$msg2="";
|
||||
$closeme = 0;
|
||||
$database = $spooldir.'/'.$group.'-articles.db3';
|
||||
if(!$dbh) {
|
||||
$dbh = article_db_open($database);
|
||||
$closeme = 1;
|
||||
}
|
||||
// By Message-ID
|
||||
if(!is_numeric($article)) {
|
||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE msgid like :terms");
|
||||
$stmt->bindParam(':terms', $article);
|
||||
$stmt->execute();
|
||||
while($found = $stmt->fetch()) {
|
||||
$msg2 = $found['article'];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE number = :terms");
|
||||
$stmt->bindParam(':terms', $article);
|
||||
$stmt->execute();
|
||||
while($found = $stmt->fetch()) {
|
||||
$msg2 = $found['article'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($closeme == 1) {
|
||||
$dbh = null;
|
||||
}
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." DEBUG: fetched: ".$article." from ".$group, FILE_APPEND);
|
||||
if($makearray == 1) {
|
||||
$thisarticle = preg_split("/\r\n|\n|\r/", trim($msg2));
|
||||
return $thisarticle;
|
||||
} else {
|
||||
return trim($msg2);
|
||||
}
|
||||
}
|
||||
|
||||
function get_config_value($configfile,$request) {
|
||||
global $config_dir;
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ $table = 'overview';
|
|||
$dbh = rslight_db_open($database, $table);
|
||||
$query = $dbh->prepare('SELECT * FROM '.$table.' WHERE newsgroup=:findgroup AND date >= '.$oldest.' ORDER BY date DESC LIMIT '.$maxdisplay);
|
||||
$articles = array();
|
||||
$db_articles = array();
|
||||
foreach($grouplist as $findgroup) {
|
||||
$groups = preg_split("/(\ |\t)/", $findgroup, 2);
|
||||
$findgroup = $groups[0];
|
||||
|
@ -108,16 +109,20 @@ foreach($grouplist as $findgroup) {
|
|||
continue 2;
|
||||
}
|
||||
}
|
||||
/*
|
||||
$thisgroup = preg_replace('/\./', '/', $findgroup);
|
||||
if (!is_dir($spoolpath.$thisgroup)) {
|
||||
continue;
|
||||
}
|
||||
$stats = stat($spoolpath.$thisgroup);
|
||||
if($stats[9] > $oldest) {
|
||||
*/
|
||||
if(1) {
|
||||
if($dbh) {
|
||||
$query->execute(['findgroup' => $findgroup]);
|
||||
while (($overviewline = $query->fetch()) !== false) {
|
||||
$articles[] = $spoolpath.$thisgroup.'/'.$overviewline['number'];
|
||||
$db_articles[] = $findgroup.':'.$overviewline['number'].':'.$overviewline['date'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,17 +182,29 @@ if (isset($_GET['thisgroup'])) {
|
|||
|
||||
$results=0;
|
||||
$files = array();
|
||||
foreach($articles as $article) {
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
foreach($db_articles as $article) {
|
||||
$order=explode(':', $article);
|
||||
$files[$order[2]] = $article;
|
||||
}
|
||||
} else {
|
||||
foreach($articles as $article) {
|
||||
if(is_dir($article)) {
|
||||
continue;
|
||||
}
|
||||
$files[filemtime($article)] = $article;
|
||||
}
|
||||
}
|
||||
krsort($files);
|
||||
echo '<table cellspacing="0" width="100%" class="np_results_table">';
|
||||
//date_default_timezone_set(timezone_name_from_abbr("", $CONFIG['timezone'] * 3600, 0));
|
||||
foreach($files as $article) {
|
||||
$articledata = file_get_contents($article);
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$data = explode(':', $article);
|
||||
$articledata = np_get_db_article($data[1], $data[0], 0);
|
||||
} else {
|
||||
$articledata = file_get_contents($article);
|
||||
}
|
||||
$bodystart = strpos($articledata, $localeol);
|
||||
|
||||
$header = substr($articledata, 0, $bodystart);
|
||||
|
@ -201,12 +218,17 @@ foreach($files as $article) {
|
|||
}
|
||||
|
||||
# Find group name and article number
|
||||
$group = preg_replace($spoolpath_regexp, '', $article);
|
||||
$group = preg_replace('/\//', '.', $group);
|
||||
$findme = strrpos($group, '.');
|
||||
$groupname = substr($group, 0, $findme);
|
||||
$articlenumber = substr($group, $findme+1);
|
||||
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$group = $data[0];
|
||||
$articlenumber = $data[1];
|
||||
$groupname = $group;
|
||||
} else {
|
||||
$group = preg_replace($spoolpath_regexp, '', $article);
|
||||
$group = preg_replace('/\//', '.', $group);
|
||||
$findme = strrpos($group, '.');
|
||||
$groupname = substr($group, 0, $findme);
|
||||
$articlenumber = substr($group, $findme+1);
|
||||
}
|
||||
# Generate link
|
||||
$url = $thissite."/article-flat.php?id=".$articlenumber."&group="._rawurlencode($groupname)."#".$articlenumber;
|
||||
$groupurl = $thissite."/thread.php?group="._rawurlencode($groupname);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<center>
|
||||
<font size="1em">
|
||||
<i>rocksolid light</i> 0.6.7
|
||||
<i>rocksolid light</i> 0.6.8
|
||||
<br />
|
||||
<a href="https://github.com/novabbs/rocksolid-light" target=_blank>clearnet</a>
|
||||
<a href="http://rslight.i2p/getrslight" target=_blank>i2p</a>
|
||||
|
|
|
@ -19,11 +19,6 @@
|
|||
$webserver_group=$CONFIG['webserver_user'];
|
||||
$logfile=$logdir.'/expire.log';
|
||||
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$table = 'overview';
|
||||
$dbh = rslight_db_open($database, $table);
|
||||
$query = $dbh->prepare('DELETE FROM '.$table.' WHERE newsgroup=:newsgroup AND number=:number');
|
||||
|
||||
$grouplist = file($config_dir.'/'.$config_name.'/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach($grouplist as $groupline) {
|
||||
$expireme = 0;
|
||||
|
@ -40,6 +35,18 @@
|
|||
if($expireme < 1) {
|
||||
continue;
|
||||
}
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$dbh = rslight_db_open($database);
|
||||
$query = $dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND date<:expireme');
|
||||
$query->execute([':newsgroup' => $group, ':expireme' => $expireme]);
|
||||
$dbh = null;
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$database = $spooldir.'/'.$group.'-articles.db3';
|
||||
$articles_dbh = article_db_open($database);
|
||||
$articles_query = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND date<:expireme');
|
||||
$articles_query->execute([':newsgroup' => $group, ':expireme' => $expireme]);
|
||||
$articles_dbh = null;
|
||||
}
|
||||
$grouppath = preg_replace('/\./', '/', $group);
|
||||
|
||||
$this_overview=$spooldir.'/'.$group.'-overview';
|
||||
|
@ -54,7 +61,6 @@
|
|||
echo "Expiring: ".$break[4]." IN: ".$group." #".$break[0]."\r\n";
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Expiring: ".$break[4]." IN: ".$group." #".$break[0], FILE_APPEND);
|
||||
unlink($spooldir.'/articles/'.$grouppath.'/'.$break[0]);
|
||||
$query->execute([':newsgroup' => $group, ':number' => $break[0]]);
|
||||
continue;
|
||||
} else {
|
||||
fputs($out_overviewfp, $line);
|
||||
|
@ -66,7 +72,6 @@
|
|||
chown($this_overview, $CONFIG['webserver_user']);
|
||||
chgrp($this_overview, $webserver_group);
|
||||
}
|
||||
$dbh = null;
|
||||
unlink($lockfile);
|
||||
touch($spooldir.'/'.$config_name.'-expire-timer');
|
||||
?>
|
||||
|
|
|
@ -99,13 +99,18 @@ function delete_message($messageid, $group) {
|
|||
}
|
||||
if($config_name) {
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$table = 'overview';
|
||||
$dbh = rslight_db_open($database, $table);
|
||||
$query = $dbh->prepare('DELETE FROM '.$table.' WHERE msgid=:messageid');
|
||||
$dbh = rslight_db_open($database);
|
||||
$query = $dbh->prepare('DELETE FROM overview WHERE msgid=:messageid');
|
||||
$query->execute(['messageid' => $messageid]);
|
||||
$dbh = null;
|
||||
}
|
||||
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$database = $spooldir.'/'.$group.'-articles.db3';
|
||||
$articles_dbh = article_db_open($database);
|
||||
$articles_query = $articles_dbh->prepare('DELETE FROM articles WHERE msgid=:messageid');
|
||||
$articles_query->execute(['messageid' => $messageid]);
|
||||
$articles_dbh = null;
|
||||
}
|
||||
$this_overview=$spooldir.'/'.$group.'-overview';
|
||||
if(false === (is_file($this_overview))) {
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
function interact($msgsock, $use_crypto=false)
|
||||
{
|
||||
global $logdir,$logfile,$installed_path,$config_path,$groupconfig,$workpath,$path, $spooldir,$nntp_group,$nntp_article,$auth_ok,$user,$pass;
|
||||
global $CONFIG,$logdir,$logfile,$installed_path,$config_path,$groupconfig,$workpath,$path, $spooldir,$nntp_group,$nntp_article,$auth_ok,$user,$pass;
|
||||
|
||||
$workpath=$spooldir."/";
|
||||
$path=$workpath."articles/";
|
||||
|
@ -474,10 +474,7 @@ function get_xhdr($header, $articles) {
|
|||
$msg="221 Header information for ".$header." follows (from articles)\r\n";
|
||||
for($i=$first; $i<=$last; $i++) {
|
||||
$article_full_path=$thisgroup.'/'.strval($i);
|
||||
if(!is_file($article_full_path)) {
|
||||
continue;
|
||||
}
|
||||
$data=extract_header_line($article_full_path, $header);
|
||||
$data=extract_header_line($article_full_path, $header, $thisgroup, $i);
|
||||
if($data !== false) {
|
||||
if($mid !== false) {
|
||||
$msg.=$mid." ".$data;
|
||||
|
@ -490,8 +487,13 @@ function get_xhdr($header, $articles) {
|
|||
return $msg;
|
||||
}
|
||||
|
||||
function extract_header_line($article_full_path, $header) {
|
||||
$thisarticle=file($article_full_path, FILE_IGNORE_NEW_LINES);
|
||||
function extract_header_line($article_full_path, $header, $thisgroup, $article) {
|
||||
global $CONFIG;
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$thisarticle=get_db_article($article, $thisgroup);
|
||||
} else {
|
||||
$thisarticle=file($article_full_path, FILE_IGNORE_NEW_LINES);
|
||||
}
|
||||
foreach($thisarticle as $thisline) {
|
||||
if($thisline == "") {
|
||||
$msg2.=".\r\n";
|
||||
|
@ -585,11 +587,6 @@ function get_stat($article) {
|
|||
return $msg;
|
||||
}
|
||||
$overviewfile=$workpath.$nntp_group."-overview";
|
||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||
if(!file_exists($thisgroup."/".$article)) {
|
||||
$msg="423 No such article number ".$article."\r\n";
|
||||
return $msg;
|
||||
}
|
||||
$overviewfp=fopen($overviewfile, 'r');
|
||||
while($overviewline=fgets($overviewfp)) {
|
||||
$over=explode("\t", $overviewline);
|
||||
|
@ -605,13 +602,13 @@ function get_stat($article) {
|
|||
}
|
||||
|
||||
function get_article($article, $nntp_group) {
|
||||
global $config_dir,$path,$groupconfig,$config_name,$spooldir,$nntp_article;
|
||||
global $CONFIG,$config_dir,$path,$groupconfig,$config_name,$spooldir,$nntp_article;
|
||||
$msg2="";
|
||||
// By Message-ID
|
||||
// Use article pointer
|
||||
if(!isset($article) && is_numeric($nntp_article)) {
|
||||
$article = $nntp_article;
|
||||
}
|
||||
// By Message-ID
|
||||
if(!is_numeric($article)) {
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$table = 'overview';
|
||||
|
@ -622,6 +619,7 @@ function get_article($article, $nntp_group) {
|
|||
while($found = $stmt->fetch()) {
|
||||
$nntp_group = $found['newsgroup'];
|
||||
$article = $found['number'];
|
||||
$this_id = $found['msgid'];
|
||||
break;
|
||||
}
|
||||
$dbh = null;
|
||||
|
@ -636,13 +634,17 @@ function get_article($article, $nntp_group) {
|
|||
return $msg;
|
||||
}
|
||||
}
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$thisarticle=get_db_article($article, $nntp_group);
|
||||
} else {
|
||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||
if(!file_exists($thisgroup."/".$article)) {
|
||||
$msg.="430 no such article found\r\n";
|
||||
return $msg;
|
||||
}
|
||||
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
||||
foreach($thisarticle as $thisline) {
|
||||
}
|
||||
foreach($thisarticle as $thisline) {
|
||||
if((strpos($thisline, "Message-ID: ") === 0) && !isset($mid[1])) {
|
||||
$mid=explode(': ', $thisline);
|
||||
}
|
||||
|
@ -653,45 +655,82 @@ function get_article($article, $nntp_group) {
|
|||
return $msg.$msg2;
|
||||
}
|
||||
|
||||
function get_header($article, $nntp_group) {
|
||||
global $nntp_article,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||
function get_db_article($article, $group) {
|
||||
global $nntp_article,$nntp_group,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||
$msg2="";
|
||||
$database = $spooldir.'/'.$nntp_group.'-articles.db3';
|
||||
$dbh = article_db_open($database);
|
||||
// Use article pointer
|
||||
if(!isset($article) && is_numeric($nntp_article)) {
|
||||
$article = $nntp_article;
|
||||
}
|
||||
// By Message-ID
|
||||
if(!is_numeric($article)) {
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$table = 'overview';
|
||||
$dbh = rslight_db_open($database, $table);
|
||||
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE msgid like :terms");
|
||||
$stmt->bindParam(':terms', $article);
|
||||
$stmt->execute();
|
||||
while($found = $stmt->fetch()) {
|
||||
$nntp_group = $found['newsgroup'];
|
||||
$article = $found['number'];
|
||||
$msg2 = $found['article'];
|
||||
break;
|
||||
}
|
||||
$dbh = null;
|
||||
} else {
|
||||
// By article number
|
||||
if($nntp_group === "") {
|
||||
$msg.="412 no newsgroup has been selected\r\n";
|
||||
return $msg;
|
||||
}
|
||||
if(!is_numeric($article)) {
|
||||
$msg.="420 no article has been selected\r\n";
|
||||
return $msg;
|
||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE number = :terms");
|
||||
$stmt->bindParam(':terms', $article);
|
||||
$stmt->execute();
|
||||
while($found = $stmt->fetch()) {
|
||||
$msg2 = $found['article'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||
if(!file_exists($thisgroup."/".$article)) {
|
||||
$dbh = null;
|
||||
|
||||
$thisarticle = preg_split("/\r\n|\n|\r/", trim($msg2));
|
||||
return $thisarticle;
|
||||
}
|
||||
|
||||
function get_header($article, $nntp_group) {
|
||||
global $CONFIG,$nntp_article,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||
$msg2="";
|
||||
// Use article pointer
|
||||
if(!isset($article) && is_numeric($nntp_article)) {
|
||||
$article = $nntp_article;
|
||||
}
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$thisarticle=get_db_article($article, $nntp_group);
|
||||
} else {
|
||||
// By Message-ID
|
||||
if(!is_numeric($article)) {
|
||||
$database = $spooldir.'/articles-overview.db3';
|
||||
$table = 'overview';
|
||||
$dbh = rslight_db_open($database, $table);
|
||||
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
||||
$stmt->bindParam(':terms', $article);
|
||||
$stmt->execute();
|
||||
while($found = $stmt->fetch()) {
|
||||
$nntp_group = $found['newsgroup'];
|
||||
$article = $found['number'];
|
||||
break;
|
||||
}
|
||||
$dbh = null;
|
||||
} else {
|
||||
// By article number
|
||||
if($nntp_group === "") {
|
||||
$msg.="412 no newsgroup has been selected\r\n";
|
||||
return $msg;
|
||||
}
|
||||
if(!is_numeric($article)) {
|
||||
$msg.="420 no article has been selected\r\n";
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||
if(!file_exists($thisgroup."/".$article)) {
|
||||
$msg.="430 no such article found\r\n";
|
||||
return $msg;
|
||||
}
|
||||
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
||||
}
|
||||
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
||||
foreach($thisarticle as $thisline) {
|
||||
foreach($thisarticle as $thisline) {
|
||||
if($thisline == "") {
|
||||
$msg2.=".\r\n";
|
||||
break;
|
||||
|
@ -706,8 +745,15 @@ function get_header($article, $nntp_group) {
|
|||
}
|
||||
|
||||
function get_body($article, $nntp_group) {
|
||||
global $config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||
global $CONFIG,$nntp_article,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||
$msg2="";
|
||||
// Use article pointer
|
||||
if(!isset($article) && is_numeric($nntp_article)) {
|
||||
$article = $nntp_article;
|
||||
}
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$thisarticle=get_db_article($article, $nntp_group);
|
||||
} else {
|
||||
// By Message-ID
|
||||
if(!is_numeric($article)) {
|
||||
$menulist = file($config_dir."menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
@ -744,6 +790,7 @@ function get_body($article, $nntp_group) {
|
|||
return $msg;
|
||||
}
|
||||
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
||||
}
|
||||
$body=0;
|
||||
foreach($thisarticle as $thisline) {
|
||||
if(($thisline == "") && ($body == 0)) {
|
||||
|
@ -1015,6 +1062,15 @@ $date_i,$mid_i,$references_i,$bytes_i,$lines_i,$xref_i) {
|
|||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->execute([$nntp_group, $local, $mid_i, $article_date, $from_i, $subject_i]);
|
||||
$dbh = null;
|
||||
}
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$article_dbh = article_db_open($spooldir.'/'.$nntp_group.'-articles.db3');
|
||||
$article_sql = 'INSERT INTO articles(newsgroup, number, msgid, date, name, subject, article) VALUES(?,?,?,?,?,?,?)';
|
||||
$article_stmt = $article_dbh->prepare($article_sql);
|
||||
$this_article = file_get_contents($grouppath."/".$local);
|
||||
$article_stmt->execute([$nntp_group, $local, $mid_i, $article_date, $from_i, $subject_i, trim($this_article)]);
|
||||
unlink($grouppath."/".$local);
|
||||
$article_dbh = null;
|
||||
}
|
||||
fputs($overviewHandle, $local."\t".$subject_i."\t".$from_i."\t".$date_i."\t".$mid_i."\t".$references_i."\t".$bytes_i."\t".$lines_i."\t".$xref_i."\n");
|
||||
fclose($overviewHandle);
|
||||
|
|
|
@ -36,7 +36,7 @@ if(!isset($maxarticles_per_run)) {
|
|||
$maxarticles_per_run = 100;
|
||||
}
|
||||
if(!isset($maxfirstrequest)) {
|
||||
$maxfirstrequest = 1000;
|
||||
$maxfirstrequest = 50000;
|
||||
}
|
||||
|
||||
if(!isset($CONFIG['enable_nntp']) || $CONFIG['enable_nntp'] != true) {
|
||||
|
@ -118,13 +118,17 @@ echo "\nSpoolnews Done\r\n";
|
|||
function get_articles($ns, $group) {
|
||||
global $enable_rslight, $spooldir, $CONFIG, $maxarticles_per_run, $maxfirstrequest, $workpath, $path, $remote_groupfile, $local_groupfile, $local, $logdir, $config_name, $logfile;
|
||||
|
||||
# Prepare search database (this is only for testing atm)
|
||||
# Prepare databases
|
||||
$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);
|
||||
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$article_dbh = article_db_open($spooldir.'/'.$group.'-articles.db3');
|
||||
$article_sql = 'INSERT INTO articles(newsgroup, number, msgid, date, name, subject, article) VALUES(?,?,?,?,?,?,?)';
|
||||
$article_stmt = $article_dbh->prepare($article_sql);
|
||||
}
|
||||
if($ns == false) {
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Lost connection to ".$CONFIG['remote_server'].":".$CONFIG['remote_port'], FILE_APPEND);
|
||||
exit();
|
||||
|
@ -158,15 +162,7 @@ function get_articles($ns, $group) {
|
|||
// Try to find last article number in local_groupfile
|
||||
$local = get_high_watermark($group);
|
||||
if(!is_numeric($local)) {
|
||||
$thisgroup = $path."/".preg_replace('/\./', '/', $group);
|
||||
$articles = scandir($thisgroup);
|
||||
$ok_article=array();
|
||||
foreach($articles as $this_article) {
|
||||
if(!is_numeric($this_article)) {
|
||||
continue;
|
||||
}
|
||||
$ok_article[]=$this_article;
|
||||
}
|
||||
$ok_article = get_article_list($group);
|
||||
sort($ok_article);
|
||||
$local = $ok_article[key(array_slice($ok_article, -1, 1, true))];
|
||||
if(!is_numeric($local)) {
|
||||
|
@ -330,13 +326,17 @@ function get_articles($ns, $group) {
|
|||
fputs($overviewHandle, $local."\t".$subject[1]."\t".$from[1]."\t".$finddate[1]."\t".$mid[1]."\t".$references."\t".$bytes."\t".$lines."\t".$xref."\n");
|
||||
fclose($overviewHandle);
|
||||
$references="";
|
||||
// add to search database
|
||||
// add to database
|
||||
$stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1]]);
|
||||
// End Overview
|
||||
|
||||
if($article_date > time())
|
||||
$article_date = time();
|
||||
touch($grouppath."/".$local, $article_date);
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$this_article = file_get_contents($grouppath."/".$local);
|
||||
$article_stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1], $this_article]);
|
||||
unlink($grouppath."/".$local);
|
||||
} else {
|
||||
if($article_date > time())
|
||||
$article_date = time();
|
||||
touch($grouppath."/".$local, $article_date);
|
||||
}
|
||||
echo "\nRetrieved: ".$group." ".$article."\n";
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Wrote to spool: ".$CONFIG['remote_server']." ".$group.":".$article, FILE_APPEND);
|
||||
$i++;
|
||||
|
@ -386,6 +386,9 @@ function get_articles($ns, $group) {
|
|||
}
|
||||
}
|
||||
fclose($saveconfig);
|
||||
if($CONFIG['article_database'] == '1') {
|
||||
$article_dbh = null;
|
||||
}
|
||||
$dbh = null;
|
||||
}
|
||||
|
||||
|
@ -482,4 +485,18 @@ function get_high_watermark($group) {
|
|||
}
|
||||
}
|
||||
|
||||
function get_article_list($thisgroup) {
|
||||
global $spooldir;
|
||||
$group_overviewfp=fopen($spooldir."/".$thisgroup."-overview", 'r');
|
||||
$ok_article=array();
|
||||
while($line = fgets($group_overviewfp)) {
|
||||
$art=explode("\t", $line);
|
||||
if(is_numeric($art[0])) {
|
||||
$ok_article[] = $art[0];
|
||||
}
|
||||
}
|
||||
fclose($group_overviewfp);
|
||||
return($ok_article);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue