Skip to content

Commit

Permalink
update demo app with authentication and starttls
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/Net_NNTP/trunk@289175 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
heino committed Oct 4, 2009
1 parent d7a994e commit 7a35215
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 12 deletions.
17 changes: 17 additions & 0 deletions docs/examples/demo/article.php
Expand Up @@ -122,6 +122,23 @@
error('Unable to connect to NNTP server: ' . $posting->getMessage());
}


// Start TLS encryption
if ($starttls) {
$R = $nntp->_cmdStartTLS();
if (PEAR::isError($R)) {
error('Unable to connect to NNTP server: ' . $R->getMessage());
}
}

// Authenticate
if (!is_null($user) && !is_null($pass)) {
$authenticated = $nntp->authenticate($user, $pass);
if (PEAR::isError($authenticated)) {
error('Unable to authenticate: ' . $authenticated->getMessage());
}
}

// If asked for a article in a group, select group then article
if ($messageID === null) {

Expand Down
21 changes: 19 additions & 2 deletions docs/examples/demo/common.inc.php
Expand Up @@ -79,12 +79,17 @@

// Register connection input parameters
if ($allowoverwrite) {
$encryption = isset($_GET['encryption']) && !empty($_GET['encryption']) ? $_GET['encryption'] : $encryption;
$loglevel = isset($_GET['loglevel']) && !empty($_GET['loglevel']) ? $_GET['loglevel'] : $loglevel;

$host = isset($_GET['host']) && !empty($_GET['host']) ? $_GET['host'] : $host;
$port = isset($_GET['port']) && !empty($_GET['port']) ? $_GET['port'] : $port;

$encryption = isset($_GET['encryption']) && !empty($_GET['encryption']) ? $_GET['encryption'] : $encryption;

$user = isset($_GET['user']) && !empty($_GET['user']) ? $_GET['user'] : $user;
$pass = isset($_GET['pass']) && !empty($_GET['pass']) ? $_GET['pass'] : $pass;

$wildmat = isset($_GET['wildmat']) && !empty($_GET['wildmat']) ? $_GET['wildmat'] : $wildmat;
$loglevel = isset($_GET['loglevel']) && !empty($_GET['loglevel']) ? $_GET['loglevel'] : $loglevel;
}


Expand All @@ -96,6 +101,16 @@
$format = isset($_GET['format']) && !empty($_GET['format'])? $_GET['format'] : 'html';


/********************/
/* */
/********************/

$starttls = ($encryption == 'starttls');
if ($starttls) {
$encryption = null;
}


/********************/
/* Init NNTP client */
/********************/
Expand Down Expand Up @@ -272,6 +287,8 @@ function query($query = null)
$full = 'host=' . urlencode($host) .
'&encryption=' . urlencode($encryption) .
'&port=' . urlencode($port) .
'&user=' . urlencode($user) .
'&pass=' . urlencode($pass) .
'&wildmat=' . urlencode($wildmat) .
'&loglevel=' . urlencode($loglevel);

Expand Down
19 changes: 11 additions & 8 deletions docs/examples/demo/config.inc.php
Expand Up @@ -68,19 +68,22 @@
* @since File available since release 1.3.0
*/

$frontpage = true;

$loglevel = 5; // PEAR_LOG_NOTICE = 5 ; PEAR_LOG_INFO = 6 ; PEAR_LOG_DEBUG = 7
$allowoverwrite = true;

$host = 'news.php.net';
$encryption = null;
$port = null;
$wildmat = 'php.pear*';
$loglevel = 5; // PEAR_LOG_NOTICE = 5 ; PEAR_LOG_INFO = 6 ; PEAR_LOG_DEBUG = 7
$timeout = null;

$frontpage = true;
$allowoverwrite = true;
$encryption = null;

$user = null;
$pass = null;

$wildmat = 'php.pear*';
$useRange = false;
$max = 10;

$timeout = null;


?>
18 changes: 18 additions & 0 deletions docs/examples/demo/group.php
Expand Up @@ -101,6 +101,24 @@
error('Unable to connect to NNTP server: ' . $posting->getMessage());
}


// Start TLS encryption
if ($starttls) {
$R = $nntp->_cmdStartTLS();
if (PEAR::isError($R)) {
error('Unable to connect to NNTP server: ' . $R->getMessage());
}
}

// Authenticate
if (!is_null($user) && !is_null($pass)) {
$authenticated = $nntp->authenticate($user, $pass);
if (PEAR::isError($authenticated)) {
error('Unable to authenticate: ' . $authenticated->getMessage());
}
}


// Select group
$summary = $nntp->selectGroup($group);
if (PEAR::isError($summary)) {
Expand Down
17 changes: 16 additions & 1 deletion docs/examples/demo/groups.php
Expand Up @@ -85,13 +85,28 @@
$breadcrumbs['Frontpage'] = './index.php?' . query();
$breadcrumbs['Groups @ ' . ($host == null ? 'localhost' : $host)] = null;


// Connect
$posting = $nntp->connect($host, $encryption, $port);
if (PEAR::isError($posting)) {
error('Unable to connect to NNTP server: ' . $posting->getMessage());
}

// Start TLS encryption
if ($starttls) {
$R = $nntp->_cmdStartTLS();
if (PEAR::isError($R)) {
error('Unable to connect to NNTP server: ' . $R->getMessage());
}
}

// Authenticate
if (!is_null($user) && !is_null($pass)) {
$authenticated = $nntp->authenticate($user, $pass);
if (PEAR::isError($authenticated)) {
error('Unable to authenticate: ' . $authenticated->getMessage());
}
}

// Fetch list of groups
$groups = $nntp->getGroups($wildmat);
if (PEAR::isError($groups)) {
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/demo/index.php
Expand Up @@ -96,7 +96,12 @@
<tr><td valign="top"><b>Host:</b></td><td><input type="text" name="host" value="<?php echo $host==null ? 'news.php.net' : $host; ?>"></td><td>(Defaults to 'localhost' when empty)</td></tr>
<tr><td valign="top"><b>Port:</b></td><td><input type="text" name="port" value="<?php echo $port; ?>"></td><td>(Defaults to '119' on non-encrypted connections, and '563' on encrypted connections when empty)</td></tr>
<tr><td valign="top"><b>Windmat:</b></td><td><input type="text" name="wildmat" value="<?php echo $wildmat; ?>"></td><td>(Group wildmat)</td></tr>
<tr><td valign="top"><b>Encryption:</b></td><td><input type="radio" name="encryption" value="" checked="checked">none<br><input type="radio" name="encryption" value="tls">TLS<br><input type="radio" name="encryption" value="ssl">SSL</td><td valign="top">(Requires a NNTPS server)</td></tr>
<tr><td valign="top"><b>Username:</b></td><td><input type="text" name="user" value="<?php echo $user; ?>"></td><td>(Only used if both username and password is entered)</td></tr>
<tr><td valign="top"><b>Password:</b></td><td><input type="password" name="pass" value="<?php echo $pass; ?>"></td><td>(Only used if both username and password is entered)</td></tr>
<tr><td valign="top" rowspan="4"><b>Encryption:</b></td><td colspan="2"><input type="radio" name="encryption" value="" checked="checked">none</td></tr>
<tr><td style="border-top: 0px"><input type="radio" name="encryption" value="starttls">startTLS</td><td valign="top" style="border-top: 0px">(Starts encryption on an initially unencrypted connection)</td></tr>
<tr><td style="border-top: 0px"><input type="radio" name="encryption" value="tls">TLS</td><td valign="top" style="border-top: 0px">(Requires a NNTPS server)</td></tr>
<tr><td style="border-top: 0px"><input type="radio" name="encryption" value="ssl">SSL</td><td valign="top" style="border-top: 0px">(Requires a NNTPS server)</td></tr>
<tr><td valign="top"><b>Loglevel:</b></td><td><input type="radio" name="loglevel" value="4" checked="checked">warning<br><input type="radio" name="loglevel" value="5" checked="checked">notice<br><input type="radio" name="loglevel" value="6">info<br><input type="radio" name="loglevel" value="7">debug</td><td valign="top">(Application logging level)</td></tr>
<tr><td></td><td colspan="2"><input type="submit" value="View newsgroups"></td></tr>
</table>
Expand Down

0 comments on commit 7a35215

Please sign in to comment.