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
*/
2022-11-21 21:07:16 +01:00
set_time_limit ( 900 );
2020-11-29 01:55:31 +01:00
include " config.inc.php " ;
include ( " $file_newsportal " );
2023-07-29 19:00:27 +02:00
if ( $CONFIG [ 'remote_server' ] == '' ) {
exit ();
}
2023-08-20 00:33:05 +02:00
$logfile = $logdir . '/spoolnews.log' ;
2020-11-29 01:55:31 +01:00
2023-08-20 00:33:05 +02:00
@ mkdir ( $spooldir . " / " . $config_name , 0755 , 'recursive' );
2020-11-29 01:55:31 +01:00
2021-07-03 04:08:34 +02:00
$lockfile = $lockdir . '/rslight-send.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 Send... \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 " Send currently running \n " ;
exit ();
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$ns = nntp2_open ( $CONFIG [ 'remote_server' ], $CONFIG [ 'remote_port' ]);
if ( $ns == false ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Failed to connect to " . $CONFIG [ 'remote_server' ] . " : " . $CONFIG [ 'remote_port' ], FILE_APPEND );
exit ();
2020-11-29 01:55:31 +01:00
}
echo " \n Posting articles \r \n " ;
post_articles ( $ns , $spooldir );
nntp_close ( $ns );
unlink ( $lockfile );
echo " \n Send Done \r \n " ;
2023-08-20 00:33:05 +02:00
function post_articles ( $ns , $spooldir )
{
global $logfile , $config_name ;
if ( ! is_dir ( $spooldir . " / " . $config_name . " /outgoing/ " )) {
return " No messages to send \r \n " ;
2020-11-29 01:55:31 +01:00
}
2023-08-20 00:33:05 +02:00
$outgoing_dir = $spooldir . " / " . $config_name . " /outgoing/ " ;
$messages = scandir ( $outgoing_dir );
foreach ( $messages as $message ) {
if ( ! is_file ( $outgoing_dir . $message )) {
continue ;
}
echo " Sending: " . $outgoing_dir . $message . " \r \n " ;
fputs ( $ns , " MODE READER \r \n " );
$response = line_read ( $ns );
if ( strcmp ( substr ( $response , 0 , 3 ), " 200 " ) != 0 ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Unexpected response to MODE command: " . $response , FILE_APPEND );
return $response ;
}
fputs ( $ns , " POST \r \n " );
$response = line_read ( $ns );
if ( strcmp ( substr ( $response , 0 , 3 ), " 340 " ) != 0 ) {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Unexpected response to POST command: " . $response , FILE_APPEND );
return $response ;
}
$message_fp = fopen ( $outgoing_dir . $message , " rb " );
while (( $msgline = fgets ( $message_fp , 4096 )) !== false ) {
fputs ( $ns , $msgline );
}
fputs ( $ns , " . \r \n " );
fclose ( $message_fp );
$response = line_read ( $ns );
if ( strcmp ( substr ( $response , 0 , 3 ), " 240 " ) == 0 ) {
2023-11-05 14:10:02 +01:00
$removed = unlink ( $outgoing_dir . $message );
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Posted: " . $message . " : " . $response . " Removed: " . $removed , FILE_APPEND );
2023-08-20 00:33:05 +02:00
} else {
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Failed to POST: " . $message . " : " . $response , FILE_APPEND );
continue ;
}
2020-11-29 01:55:31 +01:00
}
2023-08-22 22:45:01 +02:00
prune_dir_by_days ( $outgoing_dir , 7 );
2023-08-20 00:33:05 +02:00
return " Messages sent \r \n " ;
2020-11-29 01:55:31 +01:00
}
?>