示例#1
0
 public function connect()
 {
     SpotDebug::msg(SpotDebug::TRACE, __CLASS__ . "->connect()");
     /*
      * Store the username and password in it, we will not put it in member variables
      * because they might show up in a stack trace.
      *
      * We keep an array of tmpUser and tmpPass because when different servers are
      * used for diffferent types of retrieval we need to be able to store seperate passwords
      */
     static $tmpUser;
     static $tmpPass;
     # dummy operation
     if ($this->_connected) {
         return;
     }
     # if
     # if an empty hostname is provided, abort
     if (empty($this->_server)) {
         throw new NntpException('Servername is empty', -1);
     }
     # if
     # if a portnumber is empty, abort
     if (!is_numeric($this->_serverport) || $this->_serverport < 1) {
         throw new NntpException('A server portnumber has to be entered', -1);
     }
     # if
     # if the type of SSL is invalid, abort
     if ($this->_serverenc !== false && strtolower($this->_serverenc) !== 'ssl' && strtolower($this->_serverenc) !== 'tls') {
         throw new NntpException('Invalid encryption method specified (' . $this->_serverenc . ')', -1);
     }
     # if
     $this->_connected = true;
     /*
      * Erase username/password so it won't show up in any stacktrace
      *
      * Because this class can be reused (e - reconnected) without
      * reconstructing it, we cannot simple
      */
     if ($this->_user !== '*FILTERED*' && $this->_pass !== '*FILTERED*') {
         $tmpUser[$this->_server] = $this->_user;
         $tmpPass[$this->_server] = $this->_pass;
         $this->_user = '******';
         $this->_pass = '******';
     }
     # if
     try {
         $ret = $this->_nntp->connect($this->_server, $this->_serverenc, $this->_serverport, 10);
         if ($ret === false) {
             throw new NntpException('Error while connecting to server (server did not respond)', -1);
         }
         # if
         SpotDebug::msg(SpotDebug::TRACE, __CLASS__ . "->connect called, trying to authenticate?: " . $tmpUser[$this->_server] . ", " . $tmpPass[$this->_server] . ".");
         if (!empty($tmpUser[$this->_server])) {
             $authed = $this->_nntp->authenticate($tmpUser[$this->_server], $tmpPass[$this->_server]);
         }
         # if
     } catch (Exception $x) {
         throw new NntpException($x->getMessage(), $x->getCode());
     }
 }
示例#2
0
文件: step3.php 项目: nubzzz/newznab
    $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();
        header("Location: ?success");
        die;
    }
}
$page->smarty->assign('cfg', $cfg);
$page->smarty->assign('page', $page);
$page->content = $page->smarty->fetch('step3.tpl');
$page->render();
示例#3
0
<?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;