/** Select optimal server for group @access public @param string $group @return array $server */ public function GetOptimalServer($group) { foreach ($this->Servers as $server=>$score) { $score = (int)$score; if ($score > 1) { if($this->NNTP->Connect($server, $this->AuthData[$server]["port"], $this->AuthData[$server]["login"], $this->AuthData[$server]["password"], 5)) { Log::Log("Connect to {$server} on port {$this->AuthData[$server]["port"]} established ({$this->AuthData[$server]["login"]}:{$this->AuthData[$server]["password"]})", 1, "NNTPLog"); $res = $this->NNTP->SelectGroup($group); Log::Log("Found {$res["count"]} messages in group {$group}", 1, "NNTPLog"); $results[$server]["score"] = $score; $results[$server]["load"] = $this->DB->GetOne("SELECT COUNT(*) FROM newsgroups WHERE serverid='{$this->AuthData[$server]['id']}'"); if ($res) $results[$server]["count"] = $res["count"]; else $results[$server]["count"] = 0; $this->NNTP->Disconnect(); } else { Log::Log("Cannot connect to {$server} on port {$this->AuthData[$server]["port"]} ({$this->AuthData[$server]["login"]}:{$this->AuthData[$server]["password"]})", 1, "NNTPLog"); $results[$server]["count"] = 0; } } } $total = array(); foreach ((array)$results as $server=>$v) { if ($v["count"]>0) { $score = $v["count"]*$v["score"]; if ($v["load"] > 0) $score = $score/$v["load"]; $total[$server] = $score; } } if (count($total)>0) { asort($total); $total = array_reverse($total); $servers = array_keys($total); $srv = array_shift($servers); return $this->AuthData[$srv]; } return false; }
public function getArticle($msgId) { SpotDebug::msg(SpotDebug::TRACE, __CLASS__ . "->getArticle(" . $msgId . ")"); $this->connect(); $result = array('header' => array(), 'body' => array()); try { $this->registerTryCommand(); # Fetch the article $art = $this->_nntp->getArticle($msgId); } catch (Exception $x) { $this->registerError($x); echo PHP_EOL . 'getArticle(): Failed to retrieve article: ' . $msgId . PHP_EOL; /** * Try this operation again, but make sure we are not overloading * the NNTP server with useless requests */ if ($this->tooManyErrors()) { throw $x; } else { return $this->getArticle($msgId); } # else } # catch /* * Now we will split it in both a body and an array, this * way it is much easier to work with */ $i = 0; $lnCount = count($art); while ($i < $lnCount && $art[$i] != '') { $result['header'][] = $art[$i]; $i++; } # while $i++; while ($i < $lnCount) { $result['body'][] = $art[$i]; $i++; } # while return $result; }
/** * Check if we are still connected. Reconnect if not. * * @param bool $reSelectGroup Select back the group after connecting? * * @return mixed On success: (bool) True; * On failure: (object) PEAR_Error * * @access protected */ protected function _checkConnection($reSelectGroup = true) { $currentGroup = $this->_currentGroup; // Check if we are connected. if (parent::_isConnected()) { $retVal = true; } else { switch ($this->_currentServer) { case NNTP_SERVER: if (is_resource($this->_socket)) { $this->doQuit(true); } $retVal = $this->doConnect(); break; case NNTP_SERVER_A: if (is_resource($this->_socket)) { $this->doQuit(true); } $retVal = $this->doConnect(true, true); break; default: $retVal = $this->throwError('Wrong server constant used in NNTP checkConnection()!'); } if ($retVal === true && $reSelectGroup) { $group = $this->selectGroup($currentGroup); if ($this->isError($group)) { $retVal = $group; } } } return $retVal; }
$page->title = "News Server Setup"; $cfg = new Install(); if (!$cfg->isInitialized()) { header("Location: index.php"); die; } $cfg = $cfg->getSession(); if ($page->isPostBack()) { $cfg->doCheck = true; $cfg->NNTP_SERVER = trim($_POST['server']); $cfg->NNTP_USERNAME = trim($_POST['user']); $cfg->NNTP_PASSWORD = trim($_POST['pass']); $cfg->NNTP_PORT = trim($_POST['port']) == '' ? 119 : trim($_POST['port']); $cfg->NNTP_SSLENABLED = isset($_POST['ssl']) ? trim($_POST['ssl']) == '1' ? true : false : false; include $cfg->WWW_DIR . '/lib/Net_NNTP/NNTP/Client.php'; $test = new Net_NNTP_Client(); $enc = false; if ($cfg->NNTP_SSLENABLED) { $enc = "ssl"; } $cfg->nntpCheck = $test->connect($cfg->NNTP_SERVER, $enc, $cfg->NNTP_PORT); if (PEAR::isError($cfg->nntpCheck)) { $cfg->error = true; } else { $cfg->nntpCheck = $test->authenticate($cfg->NNTP_USERNAME, $cfg->NNTP_PASSWORD); if (PEAR::isError($cfg->nntpCheck)) { $cfg->error = true; } } if (!$cfg->error) { $cfg->setSession();
// +----------------------------------------------------------------------+ // | Authors: Alexander Merz <*****@*****.**> | // | Heino H. Gehlsen <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: read.php,v 1.2.2.1 2005/01/13 20:38:06 heino Exp $ ?> <html> <head> <title>NNTP news.php.net</title> </head> <body> <h1>Message</h1> <?php require_once "Net/NNTP/Client.php"; $nntp = new Net_NNTP_Client(); $ret = $nntp->connect("news.php.net"); if (PEAR::isError($ret)) { echo '<font color="red">No connection to newsserver!</font><br>'; echo $ret->getMessage(); } else { if (isset($_GET['msgid']) and isset($_GET['group'])) { $msgdata = $nntp->selectGroup($_GET['group']); if (PEAR::isError($msgdata)) { echo '<font color="red">' . $msgdata->getMessage() . '</font><br>'; } else { $header = $nntp->getHeaderRaw($_GET['msgid']); echo '<hr>'; echo '<h2>Header</h2>'; echo '<pre>'; foreach ($header as $line) {
/** * Override to intercept any Xfeature compressed responses. */ function _getTextResponse() { if ($this->XFCompression && isset($this->_currentStatusResponse[1]) && stripos($this->_currentStatusResponse[1], 'COMPRESS=GZIP') !== false) { return $this->_getXFCompressedTextResponse(); } return parent::_getTextResponse(); }
// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alexander Merz <*****@*****.**> | // | Heino H. Gehlsen <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: index.php,v 1.2.2.1 2005/01/30 15:44:44 heino Exp $ ?> <html> <head> <title>NNTP news.php.net</title> </head> <body> <?php require_once "Net/NNTP/Client.php"; $nntp = new Net_NNTP_Client(); $ret = $nntp->connect("news.php.net"); if (PEAR::isError($ret)) { echo '<font color="red">No connection to newsserver!</font><br>'; echo $ret->getMessage(); } else { echo "<h1>Avaible groups</h1>"; $groups = $nntp->getGroups(); $descriptions = $nntp->getDescriptions(); foreach ($groups as $group) { echo '<a href="group.php?group=' . urlencode($group['group']) . '&writable=' . urlencode($group['posting']) . '">' . $group['group'] . '</a>'; $msgcount = $group['last'] - $group['first']; echo ' (' . $msgcount . ' messages)<br>'; echo $descriptions[$group['group']] . '<br><br>'; } $nntp->quit();
// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alexander Merz <*****@*****.**> | // | Heino H. Gehlsen <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: group.php,v 1.2 2005/01/08 20:03:30 heino Exp $ ?> <html> <head> <title>NNTP news.php.net</title> </head> <body> <?php require_once "Net/NNTP/Client.php"; $nntp = new Net_NNTP_Client(); $ret = $nntp->connect("news.php.net"); if (PEAR::isError($ret)) { echo '<font color="red">No connection to newsserver!</font><br>'; echo $ret->getMessage(); } else { if (isset($_GET['group'])) { $msgdata = $nntp->selectGroup($_GET['group']); if (PEAR::isError($msgdata)) { echo '<font color="red">' . $msgdata->getMessage() . '</font><br>'; } else { $msgcount = $msgdata['last'] - $msgdata['first']; echo '<h1>' . $_GET['group'] . '</h1>'; echo "<b>Message count:</b> " . $msgcount; echo "<br><b>Posting allowed:</b> "; switch ($_GET['writable']) {
<?php // hai.. what this does: fetch only a header field from a // usenet group (very fast), and apply some regex to it.. // use it for testing regex stuff $hostname = 'news.usenetserver.com'; $username = '******'; $password = '******'; $group = 'alt.binaries.teevee'; $header_field = 'Subject'; $max_articles = 100000; # /usr/share/pear/Net/NNTP/Client.php include 'Net/NNTP/Client.php'; $nntp = new Net_NNTP_Client(); $nntp->connect($hostname); $nntp->authenticate($username, $password); $group = $nntp->selectGroup('alt.binaries.teevee'); print_r($group); $first = $group['last'] - $max_articles; $last = $group['last']; $articles = $nntp->getHeaderField($header_field, "{$first}-{$last}"); print count($articles) . " articles indexed..\n"; foreach ($articles as $article) { $pattern = '/(\\((\\d+)\\/(\\d+)\\))$/i'; if (!preg_match($pattern, rtrim($article), $matches)) { echo "Not matched: {$article}\n"; } else { # echo "$matches[2]\n"; } } exit;