Add db support to nocem.php and clean up var

This commit is contained in:
Retro_Guy 2020-12-15 02:12:06 -07:00
parent 364ae19e85
commit 45775395e1
5 changed files with 35 additions and 8 deletions

View File

@ -96,7 +96,7 @@ ob_start();
$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);
$query = $dbh->prepare('SELECT * FROM '.$table.' WHERE newsgroup=:findgroup ORDER BY date DESC LIMIT '.$maxdisplay);
$articles = array();
foreach($grouplist as $findgroup) {
$groups = preg_split("/(\ |\t)/", $findgroup, 2);

View File

@ -122,8 +122,8 @@ $results=0;
$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 = $dbh->prepare("SELECT * FROM $table WHERE ".$_POST['searchpoint']." like '%".$_POST['terms']."%' ORDER BY date DESC");
$stmt = $dbh->prepare("SELECT * FROM $table WHERE ".$_POST['searchpoint']." like :terms ORDER BY date DESC");
$stmt->bindParam(':terms', $searchterms);
$stmt->execute();
while($overviewline = $stmt->fetch()) {

View File

@ -77,8 +77,35 @@ function verify_signature($signed_text) {
}
function delete_message($messageid, $group) {
global $logfile,$spooldir, $CONFIG, $webserver_group;
global $logfile,$config_dir,$spooldir, $CONFIG, $webserver_group;
/* Find section */
$menulist = file($config_dir."menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($menulist as $menu) {
if($menu[0] == '#') {
continue;
}
$menuitem=explode(':', $menu);
$glfp=fopen($config_dir.$menuitem[0]."/groups.txt", 'r');
$section="";
while($gl=fgets($glfp)) {
$group_name = preg_split("/( |\t)/", $gl, 2);
if(stripos(trim($group_name[0]), $group) !== false) {
$config_name=$menuitem[0];
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." FOUND: ".$messageid." IN: ".$config_name.'/'.$group, FILE_APPEND);
break 2;
}
}
}
if($config_name) {
$database = $spooldir.'/'.$config_name.'-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$query = $dbh->prepare('DELETE FROM '.$table.' WHERE msgid=:messageid');
$query->execute(['messageid' => $messageid]);
$dbh = null;
}
$this_overview=$spooldir.'/'.$group.'-overview';
if(false === (is_file($this_overview))) {
return;
@ -90,7 +117,7 @@ function delete_message($messageid, $group) {
$break=explode("\t", $line);
if($break[4] == $messageid) {
echo "DELETING: ".$messageid." IN: ".$group." #".$break[0]."\r\n";
file_put_contents($logfile, "\n".format_log_date()." ".$config_name."DELETING: ".$messageid." IN: ".$group." #".$break[0], FILE_APPEND);
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." DELETING: ".$messageid." IN: ".$group." #".$break[0], FILE_APPEND);
$grouppath = preg_replace('/\./', '/', $group);
unlink($spooldir.'/articles/'.$grouppath.'/'.$break[0]);
continue;

View File

@ -991,7 +991,7 @@ $date_i,$mid_i,$references_i,$bytes_i,$lines_i,$xref_i) {
file_put_contents($logfile, "\n".format_log_date()." ".$section." Failed to connect to database: ".$database, FILE_APPEND);
} else {
file_put_contents($logfile, "\n".format_log_date()." ".$section." Connected to database: ".$database, FILE_APPEND);
$sql = "INSERT INTO overview(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)";
$sql = 'INSERT INTO '.$table.'(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)';
$stmt = $dbh->prepare($sql);
$stmt->execute([$nntp_group, $local, $mid_i, $article_date, $from_i, $subject_i]);
$dbh = null;

View File

@ -115,7 +115,7 @@ function get_articles($ns, $group) {
$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(?,?,?,?,?,?)";
$sql = 'INSERT INTO '.$table.'(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)';
$stmt = $dbh->prepare($sql);
if($ns == false) {