* newsportal.php now allows a force reload of groups.txt, by suppling (force_reload=true) as the third parameter to groups_read();

* spoolnews.php now forces a reload of groups.txt whenever it runs (regardless of caching) and also checks to see if a remote server has been defined before it tries to contact one.
This commit is contained in:
vga256 2023-07-02 22:14:28 -06:00 committed by Retro_Guy
parent 09a1eb340d
commit 1d229d5ad1
2 changed files with 38 additions and 26 deletions

View File

@ -454,17 +454,22 @@ function address_decode($adrstring,$defaulthost) {
/* /*
* Read the groupnames from groups.txt, and get additional informations * Read the groupnames from groups.txt, and get additional informations
* of the groups from the newsserver * of the groups from the newsserver
*/ *
function groups_read($server,$port,$load=0) { * when load=0, returns cached group list
* when load=1, checks if the cache should be used, and returns nothing
* when force_reload=true, rebuilds group list cache
*/
function groups_read($server,$port,$load=0,$force_reload=false) {
global $gl_age,$file_groups,$spooldir,$config_name,$cache_index; global $gl_age,$file_groups,$spooldir,$config_name,$cache_index;
// is there a cached version, and is it actual enough? // is there a cached version, and is it actual enough?
$cachefile=$spooldir.'/'.$config_name.'-groups.dat'; $cachefile=$spooldir.'/'.$config_name.'-groups.dat';
// if cache is new enough, don't recreate it // if cache is new enough, don't recreate it
clearstatcache(TRUE, $cachefile); clearstatcache(TRUE, $cachefile);
if($load == 1 && file_exists($cachefile) && (filemtime($cachefile)+$cache_index>time())) { if(!$force_reload && $load == 1 && file_exists($cachefile) && (filemtime($cachefile)+$cache_index>time())) {
return; return;
} }
if(file_exists($cachefile) && $load == 0) { if(!$force_reload && file_exists($cachefile) && $load == 0) {
echo 'using cached version of groups';
// cached file exists and is new enough, so lets read it out. // cached file exists and is new enough, so lets read it out.
$file=fopen($cachefile,"r"); $file=fopen($cachefile,"r");
$data=""; $data="";
@ -473,7 +478,10 @@ function groups_read($server,$port,$load=0) {
} }
fclose($file); fclose($file);
$newsgroups=unserialize($data); $newsgroups=unserialize($data);
} else { }
else
{
// force a refresh of the group list
$ns=nntp_open($server,$port); $ns=nntp_open($server,$port);
if ($ns == false) return false; if ($ns == false) return false;
// $gf=fopen($file_groups,"r"); // $gf=fopen($file_groups,"r");

View File

@ -71,6 +71,7 @@ if(filemtime($spooldir.'/'.$config_name.'-thread-timer')+600 < time()) {
# Check for groups file, create if necessary # Check for groups file, create if necessary
create_spool_groups($file_groups, $remote_groupfile); create_spool_groups($file_groups, $remote_groupfile);
create_spool_groups($file_groups, $local_groupfile); create_spool_groups($file_groups, $local_groupfile);
# Iterate through groups # Iterate through groups
$enable_rslight=0; $enable_rslight=0;
# Refresh group list # Refresh group list
@ -81,7 +82,7 @@ $enable_rslight=0;
} }
$menuitem = explode(':', $menu); $menuitem = explode(':', $menu);
if(($menuitem[0] == $config_name) && ($menuitem[1] == '1')) { if(($menuitem[0] == $config_name) && ($menuitem[1] == '1')) {
groups_read($server,$port,1); groups_read($server,$port,1,true); // 'true' forces a refresh of the group list
$enable_rslight = 1; $enable_rslight = 1;
echo "\nLoaded groups"; echo "\nLoaded groups";
} }
@ -97,31 +98,34 @@ $enable_rslight=0;
} }
} }
} }
$ns=nntp2_open($CONFIG['remote_server'], $CONFIG['remote_port']); if ($CONFIG['remote_server'] != '')
$ns2=nntp_open(); {
if(!$ns) { $ns=nntp2_open($CONFIG['remote_server'], $CONFIG['remote_port']);
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Failed to connect to ".$CONFIG['remote_server'].":".$CONFIG['remote_port'], FILE_APPEND); $ns2=nntp_open();
exit(); if(!$ns) {
} file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Failed to connect to ".$CONFIG['remote_server'].":".$CONFIG['remote_port'], FILE_APPEND);
$grouplist = file($config_dir.'/'.$config_name.'/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); exit();
foreach($grouplist as $findgroup) {
if($findgroup[0] == ":") {
continue;
} }
$name = preg_split("/( |\t)/", $findgroup, 2); $grouplist = file($config_dir.'/'.$config_name.'/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Retrieving articles for: ".$name[0]."...", FILE_APPEND); foreach($grouplist as $findgroup) {
echo "\nRetrieving articles for: ".$name[0]."..."; if($findgroup[0] == ":") {
get_articles($ns, $name[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 "\nRetrieving articles for: ".$name[0]."...";
get_articles($ns, $name[0]);
if($enable_rslight == 1) { if($enable_rslight == 1) {
if($timer) { if($timer) {
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Updating threads for: ".$name[0]."...", FILE_APPEND); file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Updating threads for: ".$name[0]."...", FILE_APPEND);
thread_load_newsserver($ns2,$name[0],0); thread_load_newsserver($ns2,$name[0],0);
}
} }
} }
nntp_close($ns2);
nntp_close($ns);
} }
nntp_close($ns2);
nntp_close($ns);
#expire_overview(); #expire_overview();
unlink($lockfile); unlink($lockfile);
echo "\nSpoolnews Done\n"; echo "\nSpoolnews Done\n";