Introduce modified files using database support and remove result.php

This commit is contained in:
Retro_Guy 2020-12-11 21:16:13 -07:00
parent 9efa924ede
commit eb769fec17
5 changed files with 203 additions and 235 deletions

View File

@ -42,16 +42,12 @@ $CONFIG = include($config_file);
*/
function nntp_open($nserver=0,$nport=0) {
global $text_error,$CONFIG;
global $server,$port,$synchro_user,$synchro_pass;
global $server,$port;
// echo "<br>NNTP OPEN<br>";
if(!isset($CONFIG['enable_nntp']) || $CONFIG['enable_nntp'] != true) {
$CONFIG['server_auth_user'] = $CONFIG['remote_auth_user'];
$CONFIG['server_auth_pass'] = $CONFIG['remote_auth_pass'];
}
if(isset($synchro_user)) {
$CONFIG['server_auth_user'] = $synchro_user;
$CONFIG['server_auth_pass'] = $synchro_pass;
}
$authorize=((isset($CONFIG['server_auth_user'])) && (isset($CONFIG['server_auth_pass'])) &&
($CONFIG['server_auth_user'] != ""));
if ($nserver==0) $nserver=$server;
@ -87,8 +83,6 @@ function nntp_open($nserver=0,$nport=0) {
}
}
if ($ns==false) echo "<p>".$text_error["connection_failed"]."</p>";
unset($synchro_user);
unset($synchro_pass);
return $ns;
}
@ -1203,4 +1197,22 @@ function get_date_interval($value) {
}
return $variance;
}
function rslight_db_open($database, $table) {
try {
$dbh = new PDO('sqlite:'.$database);
} catch (PDOExeption $e) {
echo 'Connection failed: '.$e->getMessage();
exit;
}
$dbh->exec("CREATE TABLE IF NOT EXISTS $table(
id INTEGER PRIMARY KEY,
newsgroup TEXT,
number TEXT,
msgid TEXT,
date TEXT,
name TEXT,
subject TEXT)");
return($dbh);
}
?>

View File

@ -93,9 +93,13 @@ if(is_file($cachefile)) {
ob_start();
# Iterate through groups
$database = $spooldir.'/'.$config_name.'-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$query = $dbh->prepare('SELECT * FROM overview WHERE newsgroup=:findgroup ORDER BY date DESC LIMIT '.$maxdisplay);
$articles = array();
foreach($grouplist as $findgroup) {
$groups = explode(" ", $findgroup);
$groups = preg_split("/(\ |\t)/", $findgroup, 2);
$findgroup = $groups[0];
$none=0;
@ -115,16 +119,21 @@ foreach($grouplist as $findgroup) {
}
$stats = stat($spoolpath.$thisgroup);
if($stats[9] > $oldest) {
$newarticles = scandir($spoolpath.$thisgroup);
foreach($newarticles as $newarticle) {
$newarticle = $spoolpath.$thisgroup."/".$newarticle;
$stats = stat($newarticle);
if($stats[9] > $oldest && $stats[7] > 0) {
$articles[] = $newarticle;
}
if($dbh) {
$query->execute(['findgroup' => $findgroup]);
while (($overviewline = $query->fetch()) !== false) {
if($overviewline['date'] < $oldest) {
continue 2;
}
if(stripos($overviewline['newsgroup'], $findgroup) !== false) {
$articles[] = $spoolpath.$thisgroup.'/'.$overviewline['number'];
}
}
}
}
}
$dbh = null;
if (isset($_GET['thisgroup'])) {
echo '<h1 class="np_thread_headline">';
@ -266,7 +275,7 @@ foreach($files as $article) {
$poster_name = $fromoutput[0];
}
$poster_name = trim($poster_name, "\"");
echo '<p class=np_ob_posted_date>Posted: '.$date_interval.' by: '.create_name_link($poster_name).'</p>';
echo '<p class=np_ob_posted_date>Posted: '.$date_interval.' by: '.create_name_link(mb_decode_mimeheader($poster_name)).'</p>';
// echo '<p class=np_ob_posted_date>Posted: '.$date_interval.' by: '.mb_decode_mimeheader($fromoutput[0]).'</p>';
# Try to display useful snippet
if($stop=strpos($body, "begin 644 "))

View File

@ -1,213 +0,0 @@
<?php
/* rocksolid overboard - overboard for rslight
* Download: https://news.novabbs.com/getrslight
*
* E-Mail: retroguy@novabbs.com
* Web: https://news.novabbs.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
?>
<?php
include "config.inc.php";
if(isset($frames_on) && $frames_on === true) {
?>
<script>
var contentURL=window.location.pathname+window.location.search+window.location.hash;
if ( window.self !== window.top ) {
/* Great! now we move along */
} else {
window.location.href = '../index.php?content='+encodeURIComponent(contentURL);
}
top.history.replaceState({}, 'Title', 'index.php?content='+encodeURIComponent(contentURL));
</script>
<?php
}
# Maximum number of articles to show
$maxdisplay = 1000;
$thissite = '.';
$groupconfig=$config_path."/groups.txt";
if (isset($_GET['thisgroup'])) {
$grouplist = array();
$grouplist[0] = _rawurldecode(_rawurldecode($_GET['thisgroup']));
} else {
$grouplist = file($groupconfig, FILE_IGNORE_NEW_LINES);
}
$title.=' - search results for: '.$_GET[terms];
include "head.inc";
ob_start();
if (isset($_GET['thisgroup'])) {
echo '<h1 class="np_thread_headline">'.$grouplist[0].' (latest)</h1>';
echo '<table cellpadding="0" cellspacing="0" width="100%" class="np_buttonbar"><tr>';
// Article List button
echo '<td>';
echo '<form action="'.$file_thread.'">';
echo '<input type="hidden" name="group" value="'.$grouplist[0].'"/>';
echo '<button class="np_button_link" type="submit">'.$text_article["back_to_group"].'</button>';
echo '</form>';
echo '</td>';
// Newsgroups button (hidden)
echo '<td>';
echo '<form action="'.$file_index.'">';
echo '<button class="np_button_hidden" type="submit">'.$text_thread["button_grouplist"].'</button>';
echo '</form>';
echo '</td>';
echo '</tr></table>';
} else {
echo '<h1 class="np_thread_headline">';
echo '<a href="'.$file_index.'" target='.$frame['menu'].'>'.basename(getcwd()).'</a> / ';
echo 'search results for: '.$_GET['terms'].'</h1>';
echo '<table cellpadding="0" cellspacing="0" width="100%" class="np_buttonbar"><tr>';
// Newsgroups button (hidden)
echo '<td>';
echo '<form action="'.$file_index.'">';
echo '<button class="np_button_hidden" type="submit">'.$text_thread["button_grouplist"].'</button>';
echo '</form>';
echo '</td>';
echo '</tr></table>';
}
echo '<table cellspacing="0" width="100%" class="np_results_table">';
# Iterate through groups
$local_groupfile=$spooldir."/".$config_name."/local_groups.txt";
$results=0;
foreach($grouplist as $findgroup) {
$groups = preg_split("/( |\t)/", $findgroup, 2);
$findgroup = $groups[0];
// Find starting article number (last - $maxdisplay)
$local_grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES);
foreach($local_grouplist as $local_findgroup) {
$name = explode(':', $local_findgroup);
if (strcmp($name[0], $findgroup) == 0) {
if (is_numeric($name[1]))
$local = $name[1];
else {
$thisgroup = $path."/".preg_replace('/\./', '/', $findgroup);
$articles = scandir($thisgroup);
$ok_article=array();
foreach($articles as $this_article) {
if(!is_numeric($this_article)) {
continue;
}
$ok_article[]=$this_article;
}
sort($ok_article);
$local = $ok_article[key(array_slice($ok_article, -1, 1, true))];
if(!is_numeric($local))
$local = 0;
}
break;
}
}
if($local < 1)
$local = 1;
// $overviewfp=fopen($spooldir."/".$findgroup."-overview", "r");
$overviewfp=popen($CONFIG['tac'].' '.$spooldir.'/'.$findgroup.'-overview', 'r');
if($overviewfp) {
while (($overviewline = fgets($overviewfp)) !== false) {
$article = explode("\t", $overviewline);
if(intval($article[0]) < ($local - $maxdisplay)) {
continue;
}
if(!strcmp($_GET['searchpoint'], "Subject")) {
$searchme = quoted_printable_decode(mb_decode_mimeheader($article[1]));
}
if(!strcmp($_GET['searchpoint'], "Poster")) {
$searchme = quoted_printable_decode(mb_decode_mimeheader($article[2]));
}
if(!strcmp($_GET['searchpoint'], "Message-ID")) {
$searchme = $article[4];
}
if(stripos($searchme, $_GET['terms']) === false) {
continue;
}
# Generate link
$url = $thissite."/article-flat.php?id=".$article[0]."&group="._rawurlencode($findgroup)."#".$article[0];
$groupurl = $thissite."/thread.php?group="._rawurlencode($findgroup);
$fromoutput = explode("<", html_entity_decode($article[2]));
// Just an email address?
if(strlen($fromoutput[0]) < 2) {
preg_match("/\<([^\)]*)\@/", html_entity_decode($article[2]), $fromaddress);
$fromoutput[0] = $fromaddress[1];
}
if(strpos($fromoutput[0], "(")) {
preg_match("/\(([^\)]*)\)/", html_entity_decode($article[2]), $fromaddress);
$fromoutput[0] = $fromaddress[1];
}
if(($results % 2) != 0){
echo '<tr class="np_result_line1"><td style="word-wrap:break-word";>';
} else {
echo '<tr class="np_result_line2"><td style="word-wrap:break-word";>';
}
echo '<p class=np_ob_subject>';
echo '<b><a href="'.$url.'">'.mb_decode_mimeheader($article[1])."</a></b>\r\n";
echo '</p><p class=np_ob_group>';
echo '<a href="'.$groupurl.'">'.$findgroup.'</a>';
echo '</p>';
echo '<p class=np_ob_posted_date>Posted: '.$article[3].' by: '.mb_decode_mimeheader($fromoutput[0]).'</p>';
echo '</td></tr>';
if($results++ > ($maxdisplay - 2))
break;
}
fclose($overviewfp);
}
}
echo '</table>';
echo "<p class=np_ob_tail><b>".$results."</b> matching articles found.</p>\r\n";
#echo "<center><i>Rocksolid Overboard</i> version ".$version;
include "tail.inc";
$thispage = ob_get_contents();
ob_end_clean();
echo $thispage;
function highlightStr($haystack, $needle) {
preg_match_all("/$needle+/i", $haystack, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
$haystack = str_replace($match, '<b>'.$match.'</b>', $haystack);
}
}
return $haystack;
}
function _rawurlencode($string) {
$string = rawurlencode(str_replace('+','%2B',$string));
return $string;
}
function _rawurldecode($string) {
$string = rawurldecode(str_replace('%2B','+',$string));
return $string;
}
?>
</body>
</html>

View File

@ -1,10 +1,16 @@
<?php
include "head.inc";
include "config.inc.php";
include "newsportal.php";
include $config_dir.'/admin.inc.php';
if(!isset($_POST['key']) || $_POST['key'] !== hash('md5', $admin['key'])) {
include "head.inc";
?>
<body>
<table width=100% border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<form name="form1" method="get" action="result.php">
<form name="form1" method="post" action="search.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
@ -18,12 +24,13 @@ include "head.inc";
</tr>
<tr></tr>
<tr>
<td><input type="radio" name="searchpoint" value="Subject" checked="checked"/>Subject</td>
<td><input type="radio" name="searchpoint" value="Poster"/>Poster</td>
<td><input type="radio" name="searchpoint" value="Message-ID"/>Message-ID</td>
<td><input type="radio" name="searchpoint" value="subject" checked="checked"/>Subject</td>
<td><input type="radio" name="searchpoint" value="name"/>Poster</td>
<td><input type="radio" name="searchpoint" value="msgid"/>Message-ID</td>
</tr>
<tr>
<td><input name="command" type="hidden" id="command" value="Search" readonly="readonly"></td>
<?php echo '<input type="hidden" name="key" value="'.hash('md5', $admin['key']).'">';?>
</tr>
<tr>
<td>&nbsp;</td>
@ -40,3 +47,146 @@ include "head.inc";
</table>
</body>
</html>
<?php exit(0); }
if(isset($frames_on) && $frames_on === true) {
?>
<script>
var contentURL=window.location.pathname+window.location.search+window.location.hash;
if ( window.self !== window.top ) {
/* Great! now we move along */
} else {
window.location.href = '../index.php?content='+encodeURIComponent(contentURL);
}
top.history.replaceState({}, 'Title', 'index.php?content='+encodeURIComponent(contentURL));
</script>
<?php
}
# Maximum number of articles to show
$maxdisplay = 1000;
$thissite = '.';
$groupconfig=$config_path."/groups.txt";
$title.=' - search results for: '.$_POST[terms];
include "head.inc";
ob_start();
if (isset($_POST['thisgroup'])) {
echo '<h1 class="np_thread_headline">'.$grouplist[0].' (latest)</h1>';
echo '<table cellpadding="0" cellspacing="0" width="100%" class="np_buttonbar"><tr>';
// Article List button
echo '<td>';
echo '<form action="'.$file_thread.'">';
echo '<input type="hidden" name="group" value="'.$grouplist[0].'"/>';
echo '<button class="np_button_link" type="submit">'.$text_article["back_to_group"].'</button>';
echo '</form>';
echo '</td>';
// Newsgroups button (hidden)
echo '<td>';
echo '<form action="'.$file_index.'">';
echo '<button class="np_button_hidden" type="submit">'.$text_thread["button_grouplist"].'</button>';
echo '</form>';
echo '</td>';
echo '</tr></table>';
} else {
echo '<h1 class="np_thread_headline">';
echo '<a href="'.$file_index.'" target='.$frame['menu'].'>'.basename(getcwd()).'</a> / ';
echo 'search results for: '.$_POST['terms'].'</h1>';
echo '<table cellpadding="0" cellspacing="0" width="100%" class="np_buttonbar"><tr>';
// Newsgroups button (hidden)
echo '<td>';
echo '<form action="'.$file_index.'">';
echo '<button class="np_button_hidden" type="submit">'.$text_thread["button_grouplist"].'</button>';
echo '</form>';
echo '</td>';
echo '</tr></table>';
}
echo '<table cellspacing="0" width="100%" class="np_results_table">';
# Iterate through groups
$results=0;
if(isset($_COOKIE['tzo'])) {
$offset=$_COOKIE['tzo'];
} else {
$offset=$CONFIG['timezone'];
}
$searchterms = "%".$_POST['terms']."%";
# Prepare search database
$database = $spooldir.'/'.$config_name.'-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
if($dbh) {
// $stmt = $dbh->prepare("SELECT * FROM overview WHERE ".$_POST['searchpoint']." like '%".$_POST['terms']."%' ORDER BY date DESC");
$stmt = $dbh->prepare("SELECT * FROM overview WHERE ".$_POST['searchpoint']." like :terms ORDER BY date DESC");
$stmt->bindParam(':terms', $searchterms);
$stmt->execute();
while($overviewline = $stmt->fetch()) {
# Generate link
$url = $thissite."/article-flat.php?id=".$overviewline['number']."&group="._rawurlencode($overviewline['newsgroup'])."#".$overviewline['number'];
$groupurl = $thissite."/thread.php?group="._rawurlencode($overviewline['newsgroup']);
$fromoutput = explode("<", html_entity_decode($overviewline['name']));
// Use local timezone if possible
$ts = new DateTime(date($text_header["date_format"], $overviewline['date']), new DateTimeZone('UTC'));
$ts->add(DateInterval::createFromDateString($offset.' minutes'));
if($offset != 0) {
$newdate = $ts->format('D, j M Y H:i');
} else {
$newdate = $ts->format($text_header["date_format"]);
}
unset($ts);
$fromline=address_decode(headerDecode($overviewline['name']),"nirgendwo");
if (!isset($fromline[0]["personal"])) {
$lastname=$fromline[0]["mailbox"];;
} else {
$lastname=$fromline[0]["personal"];
}
if(($results % 2) != 0){
echo '<tr class="np_result_line1"><td style="word-wrap:break-word";>';
} else {
echo '<tr class="np_result_line2"><td style="word-wrap:break-word";>';
}
echo '<p class=np_ob_subject>';
echo '<b><a href="'.$url.'">'.mb_decode_mimeheader($overviewline['subject'])."</a></b>\r\n";
echo '</p><p class=np_ob_group>';
echo '<a href="'.$groupurl.'">'.$overviewline['newsgroup'].'</a>';
echo '</p>';
echo '<p class=np_ob_posted_date>Posted: '.$newdate.' by: '.mb_decode_mimeheader($lastname).'</p>';
echo '</td></tr>';
if($results++ > ($maxdisplay - 2))
break;
}
$dbh = null;
}
echo '</table>';
echo "<p class=np_ob_tail><b>".$results."</b> matching articles found.</p>\r\n";
#echo "<center><i>Rocksolid Overboard</i> version ".$version;
include "tail.inc";
$thispage = ob_get_contents();
ob_end_clean();
echo $thispage;
function highlightStr($haystack, $needle) {
preg_match_all("/$needle+/i", $haystack, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
$haystack = str_replace($match, '<b>'.$match.'</b>', $haystack);
}
}
return $haystack;
}
?>
</body>
</html>

View File

@ -111,6 +111,13 @@ 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, $overview_file, $local, $logdir, $config_name, $logfile;
# Prepare search database (this is only for testing atm)
$database = $spooldir.'/'.$config_name.'-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$sql = "INSERT INTO overview(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)";
$stmt = $dbh->prepare($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();
@ -120,7 +127,7 @@ function get_articles($ns, $group) {
$banned_names = file("/etc/rslight/banned_names.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$nocem_check="@@NCM";
# Check if group exists. Open it if it does
fputs($ns, "group ".$group."\r\n");
$response = line_read($ns);
@ -323,6 +330,8 @@ function get_articles($ns, $group) {
$references="";
// overview for entire section
file_put_contents($overview_file, $group."\t".$local."\t".$mid[1]."\t".$article_date."\t".$from[1]."\t".$subject[1]."\n", FILE_APPEND);
// add to search database
$stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1]]);
// End Overview
if($article_date > time())
@ -377,6 +386,7 @@ function get_articles($ns, $group) {
}
}
fclose($saveconfig);
$dbh = null;
}
function create_spool_groups($in_groups, $out_groups) {