2020-11-29 01:55:31 +01:00
< ? php
2023-08-20 00:33:05 +02:00
/*
* spoolnews NNTP news spool creator
* Download : https :// news . novabbs . com / getrslight
2020-11-29 01:55:31 +01:00
*
2023-08-20 00:33:05 +02:00
* E - Mail : retroguy @ novabbs . com
* Web : https :// news . novabbs . com
2020-11-29 01:55:31 +01:00
*
2023-08-20 00:33:05 +02:00
* 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 .
2020-11-29 01:55:31 +01:00
*
2023-08-20 00:33:05 +02:00
* 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 .
2020-11-29 01:55:31 +01:00
*
2023-08-20 00:33:05 +02:00
* 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
2020-11-29 01:55:31 +01:00
*/
include " config.inc.php " ;
include ( " $file_newsportal " );
2023-08-20 00:33:05 +02:00
include $config_dir . '/gpg.conf' ;
2020-11-29 01:55:31 +01:00
2023-07-23 21:36:52 +02:00
if ( $CONFIG [ 'remote_server' ] != '' ) {
2023-08-20 00:33:05 +02:00
$remote_groupfile = $spooldir . " / " . $config_name . " / " . $CONFIG [ 'remote_server' ] . " : " . $CONFIG [ 'remote_port' ] . " .txt " ;
2023-07-23 21:36:52 +02:00
}
2023-08-20 00:33:05 +02:00
$file_groups = $config_path . " groups.txt " ;
$local_groupfile = $spooldir . " / " . $config_name . " /local_groups.txt " ;
$logfile = $logdir . '/spoolnews.log' ;
2020-11-29 01:55:31 +01:00
# END MAIN CONFIGURATION
2023-08-20 00:33:05 +02:00
@ mkdir ( $spooldir . " / " . $config_name , 0755 , 'recursive' );
2020-11-29 01:55:31 +01:00
2023-08-27 16:05:53 +02:00
// Defaults
$maxarticles_per_run = 100 ;
$maxfirstrequest = 100 ;
// Overrides
if ( $OVERRIDES [ 'maxarticles_per_run' ] > 0 ) {
$maxarticles_per_run = $OVERRIDES [ 'maxarticles_per_run' ];
2020-11-29 01:55:31 +01:00
}
2023-08-27 16:05:53 +02:00
if ( $OVERRIDES [ 'maxfirstrequest' ] > 0 ) {
$maxfirstrequest = $OVERRIDES [ 'maxfirstrequest' ];
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
if ( ! isset ( $CONFIG [ 'enable_nntp' ]) || $CONFIG [ 'enable_nntp' ] != true ) {
$maxfirstrequest = $maxarticles ;
$maxarticles_per_run = $maxfetch ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$workpath = $spooldir . " / " ;
$path = $workpath . " articles/ " ;
2020-11-29 01:55:31 +01:00
2023-08-20 00:33:05 +02:00
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock' ;
2020-11-29 01:55:31 +01:00
$pid = file_get_contents ( $lockfile );
2023-08-20 00:33:05 +02:00
if ( posix_getsid ( $pid ) === false || ! is_file ( $lockfile )) {
print " Starting Spoolnews... \n " ;
file_put_contents ( $lockfile , getmypid ()); // create lockfile
2020-11-29 01:55:31 +01:00
} else {
2023-08-20 00:33:05 +02:00
print " Spoolnews currently running \n " ;
exit ();
2020-11-29 01:55:31 +01:00
}
2023-04-28 05:34:51 +02:00
2023-08-20 00:33:05 +02:00
$sem = $spooldir . " / " . $config_name . " .reload " ;
if ( is_file ( $sem )) {
unlink ( $remote_groupfile );
unlink ( $sem );
2023-08-25 13:21:06 +02:00
$maxfirstrequest = 500 ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
if ( filemtime ( $spooldir . '/' . $config_name . '-thread-timer' ) + 600 < time ()) {
$timer = true ;
touch ( $spooldir . '/' . $config_name . '-thread-timer' );
2021-01-09 02:41:29 +01:00
} else {
2023-08-20 00:33:05 +02:00
$timer = false ;
2021-01-09 02:41:29 +01:00
}
2020-11-29 01:55:31 +01:00
# Check for groups file, create if necessary
2023-07-23 21:36:52 +02:00
// only do remote server groups if necessary
if ( $CONFIG [ 'remote_server' ] != '' ) {
create_spool_groups ( $file_groups , $remote_groupfile );
}
2020-11-29 01:55:31 +01:00
create_spool_groups ( $file_groups , $local_groupfile );
2023-07-03 06:14:28 +02:00
2023-08-20 00:33:05 +02:00
# Iterate through groups
$enable_rslight = 0 ;
2020-11-29 01:55:31 +01:00
# Refresh group list
2023-08-20 00:33:05 +02:00
$menulist = file ( $config_dir . " menu.conf " , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
foreach ( $menulist as $menu ) {
if (( $menu [ 0 ] == '#' ) || ( trim ( $menu ) == " " )) {
continue ;
2020-11-29 01:55:31 +01:00
}
$menuitem = explode ( ':' , $menu );
2023-08-20 00:33:05 +02:00
if (( $menuitem [ 0 ] == $config_name ) && ( $menuitem [ 1 ] == '1' )) {
groups_read ( $server , $port , 1 , true ); // 'true' forces a refresh of the group list
$enable_rslight = 1 ;
echo " \n Loaded groups " ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
}
2023-05-17 00:40:04 +02:00
# Clean outgoing directory for LOCAL sections
2023-08-20 00:33:05 +02:00
if ( $CONFIG [ 'remote_server' ] == '' ) {
$outgoing_dir = $spooldir . " / " . $config_name . " /outgoing/ " ;
$files = scandir ( $outgoing_dir );
foreach ( $files as $file ) {
$file_name = $outgoing_dir . $file ;
if ( is_file ( $file_name ) && ( filemtime ( $file_name ) < ( time () - 3600 ))) {
2023-05-17 00:40:04 +02:00
unlink ( $file_name );
}
2023-07-03 06:14:28 +02:00
}
2023-08-20 00:33:05 +02:00
}
if ( $CONFIG [ 'remote_server' ] != '' ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " remote_server: " . $CONFIG [ 'remote_server' ], FILE_APPEND );
$ns = nntp2_open ( $CONFIG [ 'remote_server' ], $CONFIG [ 'remote_port' ]);
$ns2 = nntp_open ();
if ( ! $ns ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Failed to connect to " . $CONFIG [ 'remote_server' ] . " : " . $CONFIG [ 'remote_port' ], FILE_APPEND );
exit ();
}
$grouplist = file ( $config_dir . '/' . $config_name . '/groups.txt' , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
foreach ( $grouplist as $findgroup ) {
if ( $findgroup [ 0 ] == " : " ) {
continue ;
}
$name = preg_split ( " /( | \t )/ " , $findgroup , 2 );
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Retrieving articles for: " . $name [ 0 ] . " ... " , FILE_APPEND );
echo " \n Retrieving articles for: " . $name [ 0 ] . " ... " ;
get_articles ( $ns , $name [ 0 ]);
2020-12-26 00:24:34 +01:00
2023-08-20 00:33:05 +02:00
if ( $enable_rslight == 1 ) {
if ( $timer ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Updating threads for: " . $name [ 0 ] . " ... " , FILE_APPEND );
thread_load_newsserver ( $ns2 , $name [ 0 ], 0 );
}
}
2021-01-09 02:41:29 +01:00
}
2023-08-20 00:33:05 +02:00
nntp_close ( $ns2 );
nntp_close ( $ns );
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
# expire_overview();
2020-11-29 01:55:31 +01:00
unlink ( $lockfile );
2023-05-13 19:10:09 +02:00
echo " \n Spoolnews Done \n " ;
2020-11-29 01:55:31 +01:00
2023-08-20 00:33:05 +02:00
function get_articles ( $ns , $group )
{
global $enable_rslight , $rslight_gpg , $spooldir , $CONFIG , $user_ban_file , $maxarticles_per_run , $maxfirstrequest , $workpath , $path , $remote_groupfile , $local_groupfile , $local , $logdir , $config_name , $logfile ;
2020-11-29 01:55:31 +01:00
2023-08-20 00:33:05 +02:00
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 ();
}
2023-07-18 18:15:24 +02:00
2023-08-20 00:33:05 +02:00
$grouppath = $path . preg_replace ( '/\./' , '/' , $group );
$banned_names = file ( $user_ban_file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
2023-09-16 18:36:02 +02:00
$msgid_filter = get_config_value ( 'header_filters.conf' , 'Message-ID' );
$subject_filter = get_config_value ( 'header_filters.conf' , 'Subject' );
$from_filter = get_config_value ( 'header_filters.conf' , 'From' );
$path_filter = get_config_value ( 'header_filters.conf' , 'Path' );
2021-02-06 12:22:45 +01:00
2023-08-20 00:33:05 +02:00
$nocem_check = " @@NCM " ;
$bbsmail_check = " @@RSL " ;
2021-01-05 08:04:05 +01:00
2023-08-20 00:33:05 +02:00
# Check if group exists. Open it if it does
fputs ( $ns , " group " . $group . " \r \n " );
$response = line_read ( $ns );
if ( strcmp ( substr ( $response , 0 , 3 ), " 211 " ) != 0 ) {
echo " \n " . $response ;
return ( 1 );
}
2023-08-13 14:08:04 +02:00
2023-08-20 00:33:05 +02:00
# Get config
$grouplist = file ( $remote_groupfile , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
foreach ( $grouplist as $findgroup ) {
$name = explode ( ':' , $findgroup );
if ( strcmp ( $name [ 0 ], $group ) == 0 ) {
if ( is_numeric ( trim ( $name [ 1 ]))) {
$article = $name [ 1 ] + 1 ;
} else {
$article = 1 ;
}
break ;
}
}
if ( isset ( $CONFIG [ 'enable_nntp' ]) && $CONFIG [ 'enable_nntp' ] == true ) {
2023-08-13 14:08:04 +02:00
2023-08-20 00:33:05 +02:00
// Get list of article numbers to find what number is next
$ok_article = get_article_list ( $group );
sort ( $ok_article );
$local = $ok_article [ key ( array_slice ( $ok_article , - 1 , 1 , true ))];
if ( ! is_numeric ( $local )) {
$local = 0 ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$local = $local + 1 ;
if ( $local < 1 ) {
$local = 1 ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
while ( is_deleted_post ( $group , $local )) {
$local ++ ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
}
# Split group response line to get last article number
$detail = explode ( " " , $response );
if ( ! isset ( $article )) {
$article = $detail [ 2 ];
}
if ( $article < $detail [ 3 ] - $maxfirstrequest ) {
$article = $detail [ 3 ] - $maxfirstrequest ;
}
if ( $article < $detail [ 2 ]) {
$article = $detail [ 2 ];
}
// Articles Database
if ( $CONFIG [ 'article_database' ] == '1' ) {
$article_dbh = article_db_open ( $spooldir . '/' . $group . '-articles.db3' );
$article_sql = 'INSERT OR IGNORE INTO articles(newsgroup, number, msgid, date, name, subject, article, search_snippet) VALUES(?,?,?,?,?,?,?,?)' ;
$article_stmt = $article_dbh -> prepare ( $article_sql );
}
// Create list of message-ids
$database = $spooldir . '/articles-overview.db3' ;
$table = 'overview' ;
$dbh = overview_db_open ( $database , $table );
2023-08-25 13:21:06 +02:00
$stmt = $dbh -> prepare ( " SELECT msgid FROM $table WHERE newsgroup=:newsgroup " );
$stmt -> bindParam ( ':newsgroup' , $group );
2023-08-20 00:33:05 +02:00
$stmt -> execute ();
while ( $row = $stmt -> fetch ()) {
$msgids [ $row [ 'msgid' ]] = true ;
}
$dbh = null ;
2023-08-23 21:25:21 +02:00
// Check history database for deleted message-ids
$database = $spooldir . '/history.db3' ;
$table = 'history' ;
$dbh = history_db_open ( $database , $table );
$stmt = $dbh -> prepare ( " SELECT msgid FROM $table WHERE newsgroup=:newsgroup " );
2023-08-25 13:21:06 +02:00
$stmt -> bindParam ( ':newsgroup' , $group );
2023-08-23 21:25:21 +02:00
$stmt -> execute ();
while ( $row = $stmt -> fetch ()) {
$msgids [ $row [ 'msgid' ]] = true ;
}
$dbh = null ;
2023-08-20 00:33:05 +02:00
// Overview database
$database = $spooldir . '/articles-overview.db3' ;
$table = 'overview' ;
$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 );
// Get overview from server
$server_overview = array ();
$re = false ;
if (( $detail [ 3 ] - $article ) > $maxarticles_per_run ) {
$getlast = $article + $maxarticles_per_run ;
} else {
$getlast = $detail [ 3 ];
}
fputs ( $ns , " xover " . $article . " - " . $getlast . " \r \n " );
$response = line_read ( $ns ); // and once more
if (( substr ( $response , 0 , 3 ) != " 224 " )) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Cannot get overview from " . $CONFIG [ 'remote_server' ] . " for " . $group , FILE_APPEND );
return false ;
}
while ( trim ( $response = line_read ( $ns )) !== '.' ) {
$ov = preg_split ( " / \t / " , $response );
2023-08-25 13:21:06 +02:00
$overview_msgid [ $ov [ 0 ]] = $ov [ 4 ];
2023-08-20 00:33:05 +02:00
}
# Pull articles and save them in our spool
@ mkdir ( $grouppath , 0755 , 'recursive' );
$i = 0 ;
while ( $article <= $detail [ 3 ]) {
if ( ! is_numeric ( $article )) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " DEBUG This should show server group:article number: " . $CONFIG [ 'remote_server' ] . " " . $group . " : " . $article , FILE_APPEND );
break ;
}
if ( $CONFIG [ 'enable_nntp' ] != true ) {
$local = $article ;
2020-11-29 01:55:31 +01:00
}
2023-08-27 16:05:53 +02:00
if ( $msgids [ $overview_msgid [ $article ]] == true ) {
2023-08-20 00:33:05 +02:00
echo " \n Duplicate Message-ID for: " . $group . " : " . $article ;
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Duplicate Message-ID for: " . $group . " : " . $article , FILE_APPEND );
$article ++ ;
continue ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
fputs ( $ns , " article " . $article . " \r \n " );
$response = line_read ( $ns );
if ( strcmp ( substr ( $response , 0 , 3 ), " 220 " ) != 0 ) {
echo " \n " . $response ;
2023-08-23 21:25:21 +02:00
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " " . $response , FILE_APPEND );
2023-08-20 00:33:05 +02:00
$article ++ ;
continue ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$articleHandle = $grouppath . " / " . $local ;
$response = line_read ( $ns );
$lines = 0 ;
$bytes = 0 ;
$ref = 0 ;
2023-09-16 18:36:02 +02:00
$banned = false ;
2023-08-20 00:33:05 +02:00
$is_header = 1 ;
$body = " " ;
while ( strcmp ( $response , " . " ) != 0 ) {
$bytes = $bytes + mb_strlen ( $response , '8bit' );
if ( trim ( $response ) == " " || $lines > 0 ) {
$is_header = 0 ;
$lines ++ ;
}
if ( $is_header == 1 ) {
$response = str_replace ( " \t " , " " , $response );
// Find article date
if ( stripos ( $response , " Date: " ) === 0 ) {
$finddate = explode ( ': ' , $response , 2 );
$article_date = strtotime ( $finddate [ 1 ]);
}
// Get overview data
if ( stripos ( $response , " Message-ID: " ) === 0 ) {
$mid = explode ( ': ' , $response , 2 );
2023-09-16 18:36:02 +02:00
if ( preg_match ( $msgid_filter , $mid [ 1 ])) {
$banned = " msgid_filter " ;
}
2023-08-20 00:33:05 +02:00
$ref = 0 ;
}
if ( stripos ( $response , " From: " ) === 0 ) {
$from = explode ( ': ' , $response , 2 );
2023-09-16 18:36:02 +02:00
if ( preg_match ( $from_filter , $from [ 1 ])) {
$banned = " from_filter " ;
}
$ref = 0 ;
}
if ( stripos ( $response , " Path: " ) === 0 ) {
$msgpath = explode ( ': ' , $response , 2 );
if ( preg_match ( $path_filter , $msgpath [ 1 ])) {
$banned = " path_filter " ;
2023-08-20 00:33:05 +02:00
}
$ref = 0 ;
}
if ( stripos ( $response , " Subject: " ) === 0 ) {
$subject = explode ( 'Subject: ' , $response , 2 );
2023-09-16 18:36:02 +02:00
if ( preg_match ( $subject_filter , $subject [ 1 ])) {
$banned = " subject_filter " ;
}
2023-08-20 00:33:05 +02:00
$ref = 0 ;
}
if ( stripos ( $response , " Newsgroups: " ) === 0 ) {
$response = str_ireplace ( $group , $group , $response );
$ref = 0 ;
}
if ( stripos ( $response , " Xref: " ) === 0 ) {
if ( isset ( $CONFIG [ 'enable_nntp' ]) && $CONFIG [ 'enable_nntp' ] == true ) {
$response = " Xref: " . $CONFIG [ 'pathhost' ] . " " . $group . " : " . $local ;
}
$xref = $response ;
$ref = 0 ;
}
if ( stripos ( $response , " Content-Type: " ) === 0 ) {
preg_match ( '/.*charset=.*/' , $response , $te );
$content_type = explode ( " Content-Type: text/plain; charset= " , $te [ 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 {
$body .= $response . " \n " ;
}
file_put_contents ( $articleHandle , $response . " \n " , FILE_APPEND );
// Check here for broken $ns connection before continuing
$response = fgets ( $ns , 1200 );
if ( $response == false ) {
2023-09-16 18:36:02 +02:00
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Lost connection to " . $CONFIG [ 'remote_server' ] . " : " . $CONFIG [ 'remote_port' ] . " retrieving article " . $article , FILE_APPEND );
2023-08-20 00:33:05 +02:00
unlink ( $grouppath . " / " . $local );
break ;
// continue;
}
$response = str_replace ( " \n " , " " , str_replace ( " \r " , " " , $response ));
}
file_put_contents ( $articleHandle , $response . " \n " , FILE_APPEND );
$lines = $lines - 1 ;
$bytes = $bytes + ( $lines * 2 );
2023-09-16 18:36:02 +02:00
// Don't spool article if $banned != 0
if ( $banned != false ) {
2023-08-20 00:33:05 +02:00
unlink ( $grouppath . " / " . $local );
2023-09-16 18:36:02 +02:00
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Skipping: " . $CONFIG [ 'remote_server' ] . " " . $group . " : " . $article . " banned in " . $banned , FILE_APPEND );
// file_put_contents($logfile, "\nFrom: ".$from[1]."\nPath: ".$msgpath[1], FILE_APPEND);
2023-08-20 00:33:05 +02:00
$article ++ ;
2021-01-20 23:54:47 +01:00
} else {
2023-08-20 00:33:05 +02:00
if (( strpos ( $CONFIG [ 'nocem_groups' ], $group ) !== false ) && ( $CONFIG [ 'enable_nocem' ] == true )) {
if ( strpos ( $subject [ 1 ], $nocem_check ) !== false ) {
$nocem_file = tempnam ( $spooldir . " /nocem " , " nocem- " . $group . " - " );
copy ( $grouppath . " / " . $local , $nocem_file );
}
}
if (( strpos ( $rslight_gpg [ 'nntp_group' ], $group ) !== false ) && ( $rslight_gpg [ 'enable' ] == '1' )) {
if ( strpos ( $subject [ 1 ], $bbsmail_check ) !== false ) {
$bbsmail_file = preg_replace ( '/@@RSL /' , '' , $subject [ 1 ]);
$bbsmail_filename = $spooldir . " /bbsmail/in/bbsmail- " . $bbsmail_file ;
copy ( $grouppath . " / " . $local , $bbsmail_filename );
}
}
// Overview
$stmt -> execute ([
$group ,
$local ,
$mid [ 1 ],
$article_date ,
$finddate [ 1 ],
$from [ 1 ],
$subject [ 1 ],
$references ,
$bytes ,
$lines ,
$xref
]);
$references = " " ;
if ( $CONFIG [ 'article_database' ] == '1' ) {
$this_article = file_get_contents ( $grouppath . " / " . $local );
// CREATE SEARCH SNIPPET
$this_snippet = get_search_snippet ( $body , $content_type [ 1 ]);
$article_stmt -> execute ([
$group ,
$local ,
$mid [ 1 ],
$article_date ,
$from [ 1 ],
$subject [ 1 ],
$this_article ,
$this_snippet
]);
unlink ( $grouppath . " / " . $local );
} else {
if ( $article_date > time ())
$article_date = time ();
touch ( $grouppath . " / " . $local , $article_date );
}
echo " \n Retrieved: " . $group . " " . $article ;
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Wrote to spool: " . $CONFIG [ 'remote_server' ] . " " . $group . " : " . $article , FILE_APPEND );
2023-08-27 16:05:53 +02:00
$status = " spooled " ;
$statusdate = time ();
$statusreason = " imported " ;
add_to_history ( $group , $local , $mid [ 1 ], $status , $statusdate , $statusreason , $statusnotes );
2023-08-20 00:33:05 +02:00
$i ++ ;
$article ++ ;
$local ++ ;
if ( $i > $maxarticles_per_run ) {
break ;
}
2021-01-20 23:54:47 +01:00
}
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$article -- ;
// $local--;
// Update title
if ( ! is_file ( $workpath . $group . " -title " )) {
fputs ( $ns , " XGTITLE " . $group . " \r \n " );
2020-11-29 01:55:31 +01:00
$response = line_read ( $ns );
2023-08-20 00:33:05 +02:00
if ( strcmp ( substr ( $response , 0 , 3 ), " 282 " ) == 0 ) {
$titlefile = $workpath . $group . " -title " ;
$response = line_read ( $ns );
while ( strcmp ( $response , " . " ) != 0 ) {
file_put_contents ( $titlefile , $response );
$response = line_read ( $ns );
}
2020-11-29 01:55:31 +01:00
}
}
2023-08-20 00:33:05 +02:00
# Save config
$grouplist = file ( $remote_groupfile , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
$saveconfig = fopen ( $remote_groupfile , 'w+' );
foreach ( $grouplist as $savegroup ) {
$name = explode ( ':' , $savegroup );
if ( strcmp ( $name [ 0 ], $group ) == 0 ) {
fputs ( $saveconfig , $group . " : " . $article . " \n " );
} else {
fputs ( $saveconfig , $savegroup . " \n " );
}
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
fclose ( $saveconfig );
$grouplist = file ( $local_groupfile , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
$saveconfig = fopen ( $local_groupfile , 'w+' );
foreach ( $grouplist as $savegroup ) {
$name = explode ( ':' , $savegroup );
if ( strcmp ( $name [ 0 ], $group ) == 0 ) {
fputs ( $saveconfig , $group . " : " . $local . " \n " );
} else {
fputs ( $saveconfig , $savegroup . " \n " );
}
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
fclose ( $saveconfig );
if ( $CONFIG [ 'article_database' ] == '1' ) {
$article_dbh = null ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$dbh = null ;
}
function create_spool_groups ( $in_groups , $out_groups )
{
2023-08-25 13:21:06 +02:00
global $spooldir ;
2023-08-20 00:33:05 +02:00
$grouplist = file ( $in_groups , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
2023-08-25 13:21:06 +02:00
$temp_file = tempnam ( $spooldir . " /tmp/ " , 'groupfile-' );
2023-08-20 00:33:05 +02:00
$groupout = fopen ( $out_groups , " a+ " );
foreach ( $grouplist as $group ) {
if ( $group [ 0 ] == " : " ) {
continue ;
}
$thisgroup = preg_split ( " /( | \t )/ " , $group , 2 );
$found = 0 ;
while (( $buffer = fgets ( $groupout )) !== false ) {
2023-08-25 13:21:06 +02:00
$mod_buffer = explode ( ':' , $buffer );
if ( strcmp ( $thisgroup [ 0 ], $mod_buffer [ 0 ]) == 0 ) {
file_put_contents ( $temp_file , " $buffer " , FILE_APPEND );
2023-08-20 00:33:05 +02:00
$found = 1 ;
break ;
}
}
if ( $found == 0 ) {
2023-08-25 13:21:06 +02:00
file_put_contents ( $temp_file , " $thisgroup[0] \n " , FILE_APPEND );
2023-08-20 00:33:05 +02:00
continue ;
}
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
fclose ( $groupout );
2023-08-25 13:21:06 +02:00
rename ( $temp_file , $out_groups );
2023-08-20 00:33:05 +02:00
return ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
function get_article_list ( $thisgroup )
{
2023-07-26 21:00:14 +02:00
global $spooldir ;
2023-08-20 00:33:05 +02:00
$database = $spooldir . " /articles-overview.db3 " ;
2023-07-26 21:00:14 +02:00
$table = 'overview' ;
2023-08-13 19:00:48 +02:00
$dbh = overview_db_open ( $database , $table );
2023-07-26 21:00:14 +02:00
$stmt = $dbh -> prepare ( " SELECT * FROM $table WHERE newsgroup=:thisgroup ORDER BY number " );
2023-08-20 00:33:05 +02:00
$stmt -> execute ([
'thisgroup' => $thisgroup
]);
$ok_article = array ();
while ( $found = $stmt -> fetch ()) {
2023-07-26 21:00:14 +02:00
$ok_article [] = $found [ 'number' ];
}
$dbh = null ;
2023-08-20 00:33:05 +02:00
return ( array_unique ( $ok_article ));
2021-01-20 23:54:47 +01:00
}
2020-11-29 01:55:31 +01:00
?>