diff -u -r -N yasuck-0.0.8.orig/docs/ChangeLog yasuck-0.0.8/docs/ChangeLog --- yasuck-0.0.8.orig/docs/ChangeLog 2005-01-06 11:22:57.000000000 -0600 +++ yasuck-0.0.8/docs/ChangeLog 2005-01-06 23:27:48.593638320 -0600 @@ -4,7 +4,19 @@ *yasuck-0.0.8 (5 Jan 2005) + 06 Jan 2005: Mike Green docs/ChangeLog, + docs/README, includes/app.functions.php, includes/globals.php, + patch-0.0.8-01: + + Added newsd compatibility. If NNTP_USE_NEWSD is defined as true, + when spool directories are created the .config file will be + created, and when nntp messages are dumped the .info file will be + updated with the correct counts. Created nntpSpoolLock and + nntpSpoolUnlock functions to handle spool locking. Changed default + fetch timeout back to random periods between 1 and 4 seconds. + *yasuck-0.0.7 (29 Sep 2004) + 05 Jan 2005: Mike Green docs/ChangeLog, docs/README, includes/app.functions.php, includes/globals.php, yasuck, patch-0.0.7-01: @@ -136,4 +148,4 @@ 17 Sep 2004; Mike Green docs/ChangeLog: First rough cut release. - \ No newline at end of file + diff -u -r -N yasuck-0.0.8.orig/docs/README yasuck-0.0.8/docs/README --- yasuck-0.0.8.orig/docs/README 2005-01-06 11:36:28.000000000 -0600 +++ yasuck-0.0.8/docs/README 2005-01-06 23:29:20.661641856 -0600 @@ -45,4 +45,8 @@ Change ownership of the resulting messages created by yasuck in the spool directory to whatever user newsd is running as (news by default). If -a cron script is used, run it under the same user as newsd. \ No newline at end of file +a cron script is used, run it under the same user as newsd. + +If using newsd, set define(NNTP_USE_NEWSD,true) to automatically create +.config and update .info files in spool directories so that updates +will be reflected to the client. diff -u -r -N yasuck-0.0.8.orig/includes/app.functions.php yasuck-0.0.8/includes/app.functions.php --- yasuck-0.0.8.orig/includes/app.functions.php 2005-01-06 12:33:12.000000000 -0600 +++ yasuck-0.0.8/includes/app.functions.php 2005-01-06 23:21:14.000000000 -0600 @@ -1209,10 +1209,10 @@ } if (!fwrite($fd,$body)) { echo "ERROR: failed to write body of message\n"; - @fclose($fd); + fclose($fd); return false; } -@fclose($fd); +fclose($fd); echo "created: $outfile\n"; @@ -1326,18 +1326,8 @@ return true; } -// abort if a lock file exists -$LOCK = "${spool_dir}/.LCK"; -if (is_file($LOCK)) { - echo "ABORT: lock file exists: $LOCK\n"; +if (!nntpSpoolLock($board_name)) { return false; - } else { - if (!$fd = fopen($LOCK,'w')) { - echo "ABORT: could not create lock file: $LOCK\n"; - return false; - } else { - @fclose($fd); - } } $msg_ar = array(); @@ -1362,7 +1352,7 @@ $sql .= "limit 1"; if (!$qid = db_query($sql)) { echo "ABORT: query failure\n"; - @unlink($LOCK); + nntpSpoolUnlock($board_name); return false; } $row_ar = db_fetch_array($qid); @@ -1370,12 +1360,12 @@ $row_ar['ticker_id'] = $ticker_id; if (!nntpCreateMessage($row_ar)) { echo "ABORT: failed to export msgid $j\n"; - @unlink($LOCK); + nntpSpoolUnlock($board_name); return false; } } -@unlink($LOCK); +if (!nntpSpoolUnlock($board_name)) { return false; } return true; @@ -1407,6 +1397,7 @@ $max = $file; } } +closedir($dh); return $max + 1; @@ -1426,7 +1417,7 @@ foreach($tmp_ar as $dir) { $dir_str .= "/${dir}"; if (!is_dir($dir_str)) { - if (!@mkdir($dir_str,0755)) { + if (!mkdir($dir_str,0755)) { echo "ERROR: could not create dir: $dir_str\n"; return false; } @@ -1435,6 +1426,30 @@ echo "INFO: created spool directory: $spool_dir\n"; } +if (NNTP_USE_NEWSD === true) { + $config = "$spool_dir/.config"; + if (is_file($config)) { return true; } + if (!$fh = fopen($config,'w')) { + echo "ERROR: could not create $config\n"; + return true; + } + $text = "description NNTP Feed of Yahoo " . strtoupper($board_name); + $text .= " Finance Message Board\n"; + $text .= "creator -\n"; + $text .= "postok 0\n"; + $text .= "postlimit 0\n"; + $text .= "ccpost -\n"; + $text .= "replyto -\n"; + $text .= "voidemail root\n"; + if (!fwrite($fh,$text)) { + echo "ERROR: could not create $config\n"; + fclose($fh); + return false; + } + fclose($fh); + echo "INFO: created $config\n"; + } + return true; } @@ -1466,6 +1481,99 @@ /***************************************************************************** * * *****************************************************************************/ +function nntpSpoolLock($board_name='') { + +if (!$spool_dir = nntpSpoolDirName($board_name)) { + echo "ERROR: cannot locate spool dir to lock board $board_name\n"; + return false; + } + +$LOCK = "$spool_dir/.LCK"; +if (is_file($LOCK)) { + echo "ABORT: lock file exists: $LOCK\n"; + return false; + } + +if (!$fd = fopen($LOCK,'w')) { + echo "ABORT: could not create lock file: $LOCK\n"; + return false; + } else { + fclose($fd); + } + +return true; + +} + +/***************************************************************************** + * * + *****************************************************************************/ +function nntpSpoolUnlock($board_name='') { + +if (!$spool_dir = nntpSpoolDirName($board_name)) { + echo "ERROR: cannot locate spool dir to lock board $board_name\n"; + return false; + } +$LOCK = "$spool_dir/.LCK"; + +return unlink($LOCK); + +} + +/***************************************************************************** + * * + *****************************************************************************/ +function nntpUpdateSpool($board_name='') { + +if ($board_name == '') { return false; } +if (! $spool_dir = nntpSpoolDirName($board_name)) { return false; } + +if (!nntpSpoolLock($board_name)) { return false; } + +$ctr = 0; +$low = 99999999; +$high = 1; + +if (!$dh = opendir($spool_dir)) { + echo "INFO: could not update newsd spool directory: $spool_dir\n"; + nntpSpoolUnlock($board_name); + return false; + } +while ( false !== ($file = readdir($dh))) { + if (!is_numeric($file)) { continue; } + $ctr++; + if ($file < $low) { $low = $file; } + if ($file > $high) { $high = $file; } + } +closedir($dh); + +$text = "start $low +end $high +total $ctr\n"; + +$info = "$spool_dir/.info"; +if (!$fh = fopen($info,'w')) { + echo "INFO: could not update $info\n"; + nntpSpoolUnlock($board_name); + return false; + } + +if (!fwrite($fh,$text)) { + echo "ERROR: could not update $info\n"; + fclose($fh); + nntpSpoolUnlock($board_name); + return false; + } +fclose($fh); +nntpSpoolUnlock($board_name); + +return true; + +} + +/***************************************************************************** + * * + *****************************************************************************/ function parseBoardId($page='') { if ($page == '' or !is_array($page)) { return false; } @@ -2132,6 +2240,11 @@ } } + +if (NNTP_USE_NEWSD === true and DUMPNNTP === true) { + nntpUpdateSpool($board_name); + } + return true; } diff -u -r -N yasuck-0.0.8.orig/includes/globals.php yasuck-0.0.8/includes/globals.php --- yasuck-0.0.8.orig/includes/globals.php 2005-01-06 23:31:52.762519008 -0600 +++ yasuck-0.0.8/includes/globals.php 2005-01-06 23:28:08.474615952 -0600 @@ -23,8 +23,8 @@ define(YAHOO_RED_HOST,'us.rd.yahoo.com'); define(YAHOO_POST_HOST,'post.messages.yahoo.com'); define(SOCKTIMEOUT,10); -//define(FETCHSLEEP,"1,4"); -define(FETCHSLEEP,1); +define(FETCHSLEEP,"1,4"); +//define(FETCHSLEEP,1); define(RETRIES,5); // misc settings @@ -43,6 +43,7 @@ define(NNTP_SPOOL_DIR,"/var/spool/newsd"); define(NNTP_GROUP_PREFIX,"alt.yahoo"); define(NNTP_COPY_TEXT,false); +define(NNTP_USE_NEWSD,false); // debug settings define(DEBUG,false);