<?php // To troubleshoot what's actually on usenet. require_once dirname(__FILE__) . '/../../../www/config.php'; $cli = new ColorCLI(); if (!isset($argv[2]) || !is_numeric($argv[2])) { exit($cli->error("\nTest your nntp connection, get group information and postdate for specific article.\n\n" . "php {$argv['0']} alt.binaries.teevee 595751142 ...: To test nntp on alt.binaries.teevee with artivle 595751142.\n")); } $nntp = new NNTP(); if ($nntp->doConnect() !== true) { exit; } $first = $argv[2]; $group = $argv[1]; // Select a group. $groupArr = $nntp->selectGroup($group); print_r($groupArr); // Insert actual local part numbers here. $msg = $nntp->getXOVER($first . '-' . $first); // Print out the array of headers. print_r($msg); // get postdate for an article $binaries = new Binaries(['NNTP' => $nntp]); $newdate = $binaries->postdate($first, $groupArr); echo $cli->primary("The posted date for " . $group . ", article " . $first . " is " . date('Y-m-d H:i:s', $newdate));
/** * Returns unix time for an article number. * * @param int $post The article number to get the time from. * @param array $groupData Usenet group info from NNTP selectGroup method. * * @return bool|int */ public function postdate($post, array $groupData) { // Set table names $groupID = $this->_groups->getIDByName($groupData['group']); $group = []; if ($groupID !== '') { $group = $this->_groups->getCBPTableNames($this->_tablePerGroup, $groupID); } $currentPost = $post; $attempts = $date = 0; do { // Try to get the article date locally first. if ($groupID !== '') { // Try to get locally. $local = $this->_pdo->queryOneRow(sprintf(' SELECT b.date AS date FROM %s b, %s p WHERE b.id = p.binaryid AND b.groupid = %s AND p.number = %s LIMIT 1', $group['bname'], $group['pname'], $groupID, $currentPost)); if ($local !== false) { $date = $local['date']; break; } } // If we could not find it locally, try usenet. $header = $this->_nntp->getXOVER($currentPost); if (!$this->_nntp->isError($header)) { // Check if the date is set. if (isset($header[0]['Date']) && strlen($header[0]['Date']) > 0) { $date = $header[0]['Date']; break; } } // Try to get a different article number. if (abs($currentPost - $groupData['first']) > abs($groupData['last'] - $currentPost)) { $tempPost = round($currentPost / (mt_rand(1005, 1012) / 1000), 0, PHP_ROUND_HALF_UP); if ($tempPost < $groupData['first']) { $tempPost = $groupData['first']; } } else { $tempPost = round(mt_rand(1005, 1012) / 1000 * $currentPost, 0, PHP_ROUND_HALF_UP); if ($tempPost > $groupData['last']) { $tempPost = $groupData['last']; } } // If we got the same article number as last time, give up. if ($tempPost === $currentPost) { break; } $currentPost = $tempPost; if ($this->_debug) { $this->_colorCLI->doEcho($this->_colorCLI->debug('Postdate retried ' . $attempts . " time(s).")); } } while ($attempts++ <= 20); // If we didn't get a date, set it to now. if (!$date) { $date = time(); } else { $date = strtotime($date); } if ($this->_debug) { $this->_debugging->log('Binaries', "postdate", 'Article (' . $post . "'s) date is (" . $date . ') (' . $this->daysOld($date) . " days old)", \Logger::LOG_INFO); } return $date; }
} else { if ($groupArr['last'] - $number > $groupArr['first']) { $first = $groupArr['last'] - $number; } else { $first = $groupArr['first']; } } $last = $groupArr['last']; @unlink(nZEDb_RES . 'logs' . DS . 'not_yenc' . DS . $group . '.txt'); @unlink(nZEDb_RES . 'logs' . DS . 'not_yenc' . DS . $group . '.failed.regex.txt'); $count = $last - $first; echo "\nGrabbing " . $count . " headers from " . $argv[1] . "\n"; for ($x = $first; $x <= $last; $x += 5000) { $y = $x + 4999; echo "Grabbing " . $x . " -> " . $y . "\n"; $msgs = $nntp->getXOVER($x . "-" . $y); foreach ($msgs as $msg) { //if (isset($msg[':bytes'])) // $bytes = $msg[':bytes']; // else if (isset($msg['Bytes'])) // $bytes = $msg['Bytes']; //if (preg_match('/(.+yEnc)(\.\s*|\s*--\s*READ NFO!\s*|\s*)\((\d+)\/(\d+)\)$/', $msg['Subject'], $matches)) //{ //$clean = $cleaner->collectionsCleaner($matches[1], $group); ///if (preg_match('/yEnc/', $clean)) //{ //$header = $msg['Number']."\t\t".$msg['Subject']."\t\t".$msg['From']."\t\t".$msg['Date']."\t\t".$msg['Message-ID']."\t\t".$bytes."\t\t".$msg['Xref']."\n"; if (isset($msg['Subject'])) { $header = $msg['Subject'] . "\n"; if (preg_match('/yEnc/', $header)) { echo $header;