Some cleanup and mods to send.php (keep outgoing dir clean)
This commit is contained in:
parent
dbaee5338a
commit
7428ac3153
|
@ -32,18 +32,13 @@ $logfile=$logdir.'/spoolnews.log';
|
||||||
$lockfile = $lockdir . '/rslight-send.lock';
|
$lockfile = $lockdir . '/rslight-send.lock';
|
||||||
$pid = file_get_contents($lockfile);
|
$pid = file_get_contents($lockfile);
|
||||||
if (posix_getsid($pid) === false || !is_file($lockfile)) {
|
if (posix_getsid($pid) === false || !is_file($lockfile)) {
|
||||||
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Starting Send...", FILE_APPEND);
|
||||||
print "Starting Send...\n";
|
print "Starting Send...\n";
|
||||||
file_put_contents($lockfile, getmypid()); // create lockfile
|
file_put_contents($lockfile, getmypid()); // create lockfile
|
||||||
} else {
|
} else {
|
||||||
if((time() - filetime($lockfile)) > 960) {
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Send currently running...", FILE_APPEND);
|
||||||
posix_kill($pid, 9);
|
print "Send currently running\n";
|
||||||
unlink($lockfile);
|
|
||||||
print "Killing and restarting Send...\n";
|
|
||||||
file_put_contents($lockfile, getmypid()); // create lockfile
|
|
||||||
} else {
|
|
||||||
print "Send currently running\n";
|
|
||||||
exit;
|
exit;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$ns=nntp2_open($CONFIG['remote_server'], $CONFIG['remote_port']);
|
$ns=nntp2_open($CONFIG['remote_server'], $CONFIG['remote_port']);
|
||||||
if($ns == false) {
|
if($ns == false) {
|
||||||
|
@ -54,19 +49,24 @@ echo "\nPosting articles\r\n";
|
||||||
post_articles($ns, $spooldir);
|
post_articles($ns, $spooldir);
|
||||||
nntp_close($ns);
|
nntp_close($ns);
|
||||||
unlink($lockfile);
|
unlink($lockfile);
|
||||||
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Exiting Send...", FILE_APPEND);
|
||||||
echo "\nSend Done\r\n";
|
echo "\nSend Done\r\n";
|
||||||
|
|
||||||
function post_articles($ns, $spooldir) {
|
function post_articles($ns, $spooldir) {
|
||||||
global $logfile,$config_name;
|
global $logfile,$config_name;
|
||||||
if(!is_dir($spooldir."/".$config_name."/outgoing/")) {
|
if(!is_dir($spooldir."/".$config_name."/outgoing/")) {
|
||||||
return "No messages to send\r\n";
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." No messages to send", FILE_APPEND);
|
||||||
|
return "No messages to send\r\n";
|
||||||
}
|
}
|
||||||
$outgoing_dir = $spooldir."/".$config_name."/outgoing/";
|
$outgoing_dir = $spooldir."/".$config_name."/outgoing/";
|
||||||
|
$failed_dir = $outgoing_dir.'/failed';
|
||||||
|
@mkdir($failed_dir);
|
||||||
$messages = scandir($outgoing_dir);
|
$messages = scandir($outgoing_dir);
|
||||||
foreach($messages as $message) {
|
foreach($messages as $message) {
|
||||||
if(!is_file($outgoing_dir.$message)) {
|
if(!is_file($outgoing_dir.$message)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Sending: ".$outgoing_dir.$message, FILE_APPEND);
|
||||||
echo "Sending: ".$outgoing_dir.$message."\r\n";
|
echo "Sending: ".$outgoing_dir.$message."\r\n";
|
||||||
fputs($ns, "MODE READER\r\n");
|
fputs($ns, "MODE READER\r\n");
|
||||||
$response = line_read($ns);
|
$response = line_read($ns);
|
||||||
|
@ -92,6 +92,7 @@ function post_articles($ns, $spooldir) {
|
||||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Posted: ".$message.": ".$response, FILE_APPEND);
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Posted: ".$message.": ".$response, FILE_APPEND);
|
||||||
} else {
|
} else {
|
||||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Failed to POST: ".$message.": ".$response, FILE_APPEND);
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Failed to POST: ".$message.": ".$response, FILE_APPEND);
|
||||||
|
rename($outgoing_dir.$message, $failed_dir.'/'.$message);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue