From eb769fec176f5325cae05387b36e8d96e225be78 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Fri, 11 Dec 2020 21:16:13 -0700 Subject: [PATCH] Introduce modified files using database support and remove result.php --- Rocksolid_Light/rocksolid/newsportal.php | 26 ++- Rocksolid_Light/rocksolid/overboard.php | 27 ++- Rocksolid_Light/rocksolid/result.php | 213 ------------------ Rocksolid_Light/rocksolid/search.php | 160 ++++++++++++- Rocksolid_Light/rslight/scripts/spoolnews.php | 12 +- 5 files changed, 203 insertions(+), 235 deletions(-) delete mode 100755 Rocksolid_Light/rocksolid/result.php diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index 8c7bf3b..67af4e5 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -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 "
NNTP OPEN
"; 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 "

".$text_error["connection_failed"]."

"; - 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); +} ?> diff --git a/Rocksolid_Light/rocksolid/overboard.php b/Rocksolid_Light/rocksolid/overboard.php index bbce4df..760612b 100755 --- a/Rocksolid_Light/rocksolid/overboard.php +++ b/Rocksolid_Light/rocksolid/overboard.php @@ -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 '

'; @@ -266,7 +275,7 @@ foreach($files as $article) { $poster_name = $fromoutput[0]; } $poster_name = trim($poster_name, "\""); - echo '

Posted: '.$date_interval.' by: '.create_name_link($poster_name).'

'; + echo '

Posted: '.$date_interval.' by: '.create_name_link(mb_decode_mimeheader($poster_name)).'

'; // echo '

Posted: '.$date_interval.' by: '.mb_decode_mimeheader($fromoutput[0]).'

'; # Try to display useful snippet if($stop=strpos($body, "begin 644 ")) diff --git a/Rocksolid_Light/rocksolid/result.php b/Rocksolid_Light/rocksolid/result.php deleted file mode 100755 index 68dc436..0000000 --- a/Rocksolid_Light/rocksolid/result.php +++ /dev/null @@ -1,213 +0,0 @@ - - - - - -'.$grouplist[0].' (latest)

'; - echo ''; -// Article List button - echo ''; -// Newsgroups button (hidden) - echo ''; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo ''; - echo '
'; - echo '
'; -} else { - echo '

'; - echo ''.basename(getcwd()).' / '; - echo 'search results for: '.$_GET['terms'].'

'; - echo ''; -// Newsgroups button (hidden) - echo ''; - echo '
'; - echo '
'; - echo ''; - echo '
'; - echo '
'; -} -echo ''; - -# 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 ''; - if($results++ > ($maxdisplay - 2)) - break; - } - fclose($overviewfp); - } -} - -echo '
'; - } else { - echo '
'; - } - echo '

'; - echo ''.mb_decode_mimeheader($article[1])."\r\n"; - echo '

'; - echo ''.$findgroup.''; - echo '

'; - echo '

Posted: '.$article[3].' by: '.mb_decode_mimeheader($fromoutput[0]).'

'; - echo '
'; -echo "

".$results." matching articles found.

\r\n"; -#echo "
Rocksolid Overboard 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, ''.$match.'', $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; -} - -?> - - diff --git a/Rocksolid_Light/rocksolid/search.php b/Rocksolid_Light/rocksolid/search.php index e3465aa..58d5318 100644 --- a/Rocksolid_Light/rocksolid/search.php +++ b/Rocksolid_Light/rocksolid/search.php @@ -1,10 +1,16 @@ + - +
@@ -18,12 +24,13 @@ include "head.inc"; - - - + + + +';?> @@ -40,3 +47,146 @@ include "head.inc";
SubjectPosterMessage-IDSubjectPosterMessage-ID
 
+ + + + +'.$grouplist[0].' (latest)'; + echo ''; +// Article List button + echo ''; +// Newsgroups button (hidden) + echo ''; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + echo ''; + echo '
'; + echo '
'; +} else { + echo '

'; + echo ''.basename(getcwd()).' / '; + echo 'search results for: '.$_POST['terms'].'

'; + echo ''; +// Newsgroups button (hidden) + echo ''; + echo '
'; + echo '
'; + echo ''; + echo '
'; + echo '
'; +} +echo ''; + +# 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 ''; + if($results++ > ($maxdisplay - 2)) + break; + } + $dbh = null; +} + +echo '
'; + } else { + echo '
'; + } + echo '

'; + echo ''.mb_decode_mimeheader($overviewline['subject'])."\r\n"; + echo '

'; + echo ''.$overviewline['newsgroup'].''; + echo '

'; + + echo '

Posted: '.$newdate.' by: '.mb_decode_mimeheader($lastname).'

'; + echo '
'; +echo "

".$results." matching articles found.

\r\n"; +#echo "
Rocksolid Overboard 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, ''.$match.'', $haystack); + } + } + return $haystack; +} +?> + + diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index 87bc017..d7da489 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -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) {