1. Import
This commit is contained in:
391
html/service/LN_374893028394/Net/Curl.php
Normal file
391
html/service/LN_374893028394/Net/Curl.php
Normal file
@@ -0,0 +1,391 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Sterling Hughes <sterling@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Curl.php,v 1.9 2002/02/28 08:27:14 sebastian Exp $
|
||||
//
|
||||
// A nice friendly OO interface for CURL
|
||||
//
|
||||
require_once('PEAR.php');
|
||||
|
||||
class Net_Curl extends PEAR
|
||||
{
|
||||
// {{{ Public Properties
|
||||
|
||||
/**
|
||||
* The URL for cURL to work with
|
||||
*
|
||||
* @var string $url
|
||||
* @access public
|
||||
*/
|
||||
var $url;
|
||||
|
||||
/**
|
||||
* The SSL version for the transfer
|
||||
*
|
||||
* @var integer $sslVersion
|
||||
* @access public
|
||||
*/
|
||||
var $sslVersion;
|
||||
|
||||
/**
|
||||
* The filename of the SSL certificate
|
||||
*
|
||||
* @var string $sslCert
|
||||
* @access public
|
||||
*/
|
||||
var $sslCert;
|
||||
|
||||
/**
|
||||
* The password corresponding to the certificate
|
||||
* in the $sslCert property
|
||||
*
|
||||
* @var string $sslCertPasswd
|
||||
* @access public
|
||||
*/
|
||||
var $sslCertPasswd;
|
||||
|
||||
/**
|
||||
* User Agent string when making an HTTP request
|
||||
*
|
||||
* @var string $userAgent
|
||||
* @access public
|
||||
*/
|
||||
var $userAgent;
|
||||
|
||||
/**
|
||||
* Whether or not to include the header in the results
|
||||
* of the CURL transfer
|
||||
*
|
||||
* @var boolean $header
|
||||
*/
|
||||
var $header = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to output debug information while executing a
|
||||
* curl transfer
|
||||
*
|
||||
* @var boolean $verbose
|
||||
* @access public
|
||||
*/
|
||||
var $verbose = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to display a progress meter for the current transfer
|
||||
*
|
||||
* @var boolean $progress
|
||||
* @access public
|
||||
*/
|
||||
var $progress = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to suppress error messages
|
||||
*
|
||||
* @var boolean $mute
|
||||
* @access public
|
||||
*/
|
||||
var $mute = 1;
|
||||
|
||||
/**
|
||||
* Whether or not to follow HTTP Location headers.
|
||||
*
|
||||
* @var boolean $follow_location
|
||||
* @access public
|
||||
*/
|
||||
var $follow_location = 1;
|
||||
|
||||
/**
|
||||
* Time allowed for current transfer, in seconds. 0 means no limit
|
||||
*
|
||||
* @var int $timeout
|
||||
* @access public
|
||||
*/
|
||||
var $timeout = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to return the results of the
|
||||
* current transfer
|
||||
*
|
||||
* @var boolean $return_transfer
|
||||
* @access public
|
||||
*/
|
||||
var $return_transfer = 1;
|
||||
|
||||
/**
|
||||
* The type of transfer to perform
|
||||
*
|
||||
* @var string $type
|
||||
* @access public
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* The file to upload
|
||||
*
|
||||
* @var string $file
|
||||
* @access public
|
||||
*/
|
||||
var $file;
|
||||
|
||||
/**
|
||||
* The file size of the file pointed to by the $file
|
||||
* property
|
||||
*
|
||||
* @var integer $file_size
|
||||
* @access public
|
||||
*/
|
||||
var $file_size;
|
||||
|
||||
/**
|
||||
* The cookies to send to the remote site
|
||||
*
|
||||
* @var array $cookies
|
||||
* @access public
|
||||
*/
|
||||
var $cookies;
|
||||
|
||||
/**
|
||||
* The fields to send in a 'POST' request
|
||||
*
|
||||
* @var array $fields
|
||||
* @access public
|
||||
*/
|
||||
var $fields;
|
||||
|
||||
/**
|
||||
* The proxy server to go through
|
||||
*
|
||||
* @var string $proxy
|
||||
* @access public
|
||||
*/
|
||||
var $proxy;
|
||||
|
||||
/**
|
||||
* The username for the Proxy server
|
||||
*
|
||||
* @var string $proxyUser
|
||||
* @access public
|
||||
*/
|
||||
var $proxyUser;
|
||||
|
||||
/**
|
||||
* The password for the Proxy server
|
||||
*
|
||||
* @var string $proxyPassword
|
||||
* @access public
|
||||
*/
|
||||
var $proxyPassword;
|
||||
|
||||
// }}}
|
||||
// {{{ Private Properties
|
||||
|
||||
/**
|
||||
* The current curl handle
|
||||
*
|
||||
* @var resource $_ch
|
||||
* @access public
|
||||
*/
|
||||
var $_ch;
|
||||
|
||||
// }}}
|
||||
// {{{ Net_Curl()
|
||||
|
||||
/**
|
||||
* The Net_Curl constructor, called when a new Net_Curl object
|
||||
* is initialized
|
||||
*
|
||||
* @param string [$url] The URL to fetch (can be set
|
||||
* using the $url property as well)
|
||||
*
|
||||
* @return object Net_Curl $obj A new Net_Curl object
|
||||
*
|
||||
* @access public
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function Net_Curl($url = "")
|
||||
{
|
||||
if ($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
if (!$ch) {
|
||||
$this = new PEAR_Error("Couldn't initialize a new curl handle");
|
||||
}
|
||||
|
||||
$this->_ch = $ch;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ execute()
|
||||
|
||||
/**
|
||||
* Executes a prepared CURL transfer
|
||||
*
|
||||
* @access public
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function execute()
|
||||
{
|
||||
$ch = &$this->_ch;
|
||||
$ret = true;
|
||||
|
||||
// Basic stuff
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_URL, $this->url);
|
||||
$ret = curl_setopt($ch, CURLOPT_HEADER, $this->header);
|
||||
|
||||
// Whether or not to return the transfer contents
|
||||
if ($this->return_transfer && !isset($this->file)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
}
|
||||
|
||||
// SSL Checks
|
||||
|
||||
if (isset($this->sslVersion)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_SSLVERSION, $this->sslVersion);
|
||||
}
|
||||
|
||||
if (isset($this->sslCert)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_SSLCERT, $this->sslCert);
|
||||
}
|
||||
|
||||
if (isset($this->sslCertPasswd)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $this->sslCertPasswd);
|
||||
}
|
||||
|
||||
// Proxy Related checks
|
||||
|
||||
if (isset($this->proxy)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
|
||||
}
|
||||
|
||||
if (isset($this->proxyUser) || isset($this->proxyPassword)) {
|
||||
$proxyString = $this->proxyUser . ":" . $this->proxyPassword;
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyString);
|
||||
}
|
||||
|
||||
|
||||
// Transfer type
|
||||
|
||||
if (isset($this->type)) {
|
||||
switch (strtolower($this->type)) {
|
||||
case 'post':
|
||||
$ret = curl_setopt($ch, CURLOPT_POST, 1);
|
||||
break;
|
||||
case 'put':
|
||||
$ret = curl_setopt($ch, CURLOPT_PUT, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Transfer upload, etc. related
|
||||
|
||||
if (isset($this->file)) {
|
||||
if (!isset($this->file_size)) {
|
||||
$this->file_size = filesize($this->file);
|
||||
}
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_INFILE, $this->file);
|
||||
$ret = curl_setopt($ch, CURLOPT_INFILESIZE, $this->file_size);
|
||||
}
|
||||
|
||||
if (isset($this->fields)) {
|
||||
if (!isset($this->type)) {
|
||||
$this->type = 'post';
|
||||
$ret = curl_setopt($ch, CURLOPT_POST, 1);
|
||||
}
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_POSTFIELDS, $this->fields);
|
||||
}
|
||||
|
||||
|
||||
// Error related
|
||||
|
||||
if ($this->progress) {
|
||||
$ret = curl_setopt($ch, CURLOPT_PROGRESS, 1);
|
||||
}
|
||||
|
||||
if ($this->verbose) {
|
||||
$ret = curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
||||
}
|
||||
|
||||
if (!$this->mute) {
|
||||
$ret = curl_setopt($ch, CURLOPT_MUTE, 0);
|
||||
}
|
||||
|
||||
// Other stuff
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location);
|
||||
|
||||
if ($this->timeout) {
|
||||
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||
}
|
||||
|
||||
if (isset($this->userAgent)) {
|
||||
$ret = curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Cookies and the such
|
||||
|
||||
if (isset($this->cookies)) {
|
||||
foreach ($this->cookies as $name => $value) {
|
||||
$cookie_data .= urlencode($name) . ": " . urlencode($value) . ";";
|
||||
}
|
||||
|
||||
$ret = curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
|
||||
}
|
||||
|
||||
$ret = curl_exec($ch);
|
||||
if (!$ret) {
|
||||
$errObj = new PEAR_Error(curl_error($ch), curl_errno($ch));
|
||||
return($errObj);
|
||||
}
|
||||
|
||||
return($ret);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ close()
|
||||
|
||||
/**
|
||||
* Closes the curl transfer and finishes the object (kinda ;)
|
||||
*
|
||||
* @access public
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if ($this->_ch) {
|
||||
curl_close($this->_ch);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
?>
|
||||
448
html/service/LN_374893028394/Net/Dig.php
Normal file
448
html/service/LN_374893028394/Net/Dig.php
Normal file
@@ -0,0 +1,448 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Colin Viebrock <colin@easyDNS.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Dig.php,v 1.4 2002/02/28 08:27:15 sebastian Exp $
|
||||
//
|
||||
// A nice friendly OO interface to dig
|
||||
//
|
||||
require_once('PEAR.php');
|
||||
|
||||
class Net_Dig extends PEAR
|
||||
{
|
||||
// {{{ Public Properties
|
||||
|
||||
/**
|
||||
* The address to dig
|
||||
*
|
||||
* @var string $address
|
||||
* @access public
|
||||
*/
|
||||
var $address;
|
||||
|
||||
/**
|
||||
* The server to use for digging
|
||||
*
|
||||
* @var string $server
|
||||
* @access public
|
||||
*/
|
||||
var $server;
|
||||
|
||||
/**
|
||||
* The type of DNS records to dig for
|
||||
*
|
||||
* @var string $query_type
|
||||
* @access public
|
||||
*/
|
||||
var $query_type;
|
||||
|
||||
/**
|
||||
* The last system command executed (for debugging)
|
||||
*
|
||||
* @var string $cmd
|
||||
* @access public
|
||||
*/
|
||||
var $cmd;
|
||||
|
||||
/**
|
||||
* The raw output of the system command (for debugging)
|
||||
*
|
||||
* @var string $raw_data
|
||||
* @access public
|
||||
*/
|
||||
var $raw_data;
|
||||
|
||||
/**
|
||||
* The location of the system dig program
|
||||
*
|
||||
* @var string $dig_prg
|
||||
* @access public
|
||||
*/
|
||||
var $dig_prog;
|
||||
|
||||
/**
|
||||
* The parsed result of the last dig
|
||||
*
|
||||
* @var string $result
|
||||
* @access public
|
||||
*/
|
||||
var $result;
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ Net_Dig()
|
||||
|
||||
/**
|
||||
* The Net_Dig constructor
|
||||
* Called when a new Net_Dig object is initialized
|
||||
*
|
||||
* @param string [$address] The address to dig (can be set
|
||||
* using the $address property as well)
|
||||
*
|
||||
* @param string [$server] The server to dig at (can be set
|
||||
* using the $server property as well)
|
||||
*
|
||||
* @return object Net_Dig $obj A new Net_Dig object
|
||||
*
|
||||
* @access public
|
||||
* @author Colin Viebrock <colin@easyDNS.com>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function Net_Dig($address = false, $server = false )
|
||||
{
|
||||
|
||||
$this->address = $address;
|
||||
$this->server = $server;
|
||||
$this->query_type = false;
|
||||
|
||||
$this->cmd = '';
|
||||
$this->raw_data = '';
|
||||
|
||||
$this->result = false;
|
||||
|
||||
$this->dig_prog = trim(`which dig`);
|
||||
if (!$this->dig_prog) {
|
||||
$this = new PEAR_Error("Couldn't find system dig program");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
|
||||
// {{{ dig()
|
||||
|
||||
/**
|
||||
* Does a dig of the given address (or $this->address)
|
||||
*
|
||||
* @param string [$address] The address to dig (can be set
|
||||
* using the $address property as well)
|
||||
*
|
||||
* @return object Net_Dig_result $obj A new Net_Dig_result object
|
||||
*
|
||||
* @access public
|
||||
* @author Colin Viebrock <colin@easyDNS.com>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function dig($address=false)
|
||||
{
|
||||
|
||||
if ($address) {
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
if (!$this->address) {
|
||||
return new PEAR_Error("No address specified");
|
||||
}
|
||||
|
||||
if (!$this->_validate_type()) {
|
||||
return new PEAR_Error($this->query_type." is an invalid query type");
|
||||
}
|
||||
|
||||
$cmd = escapeshellcmd(
|
||||
sprintf("%s %s %s %s",
|
||||
$this->dig_prog,
|
||||
($this->server ? '@'.$this->server : ''),
|
||||
$this->address,
|
||||
($this->query_type ? $this->query_type : '' )
|
||||
)
|
||||
);
|
||||
|
||||
$this->cmd = $cmd;
|
||||
|
||||
|
||||
$this->raw_data = `$cmd`;
|
||||
$this->raw_data = trim( $this->raw_data );
|
||||
|
||||
return $this->_parse_data();
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ _validate_type()
|
||||
|
||||
/**
|
||||
* Validates the value of $this->query_type
|
||||
*
|
||||
* @return boolean $return True if $this->query_type is a
|
||||
* valid dig query, otherwise false
|
||||
*
|
||||
* @access private
|
||||
* @author Colin Viebrock <colin@easyDNS.com>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function _validate_type()
|
||||
{
|
||||
$return = true;
|
||||
if ($this->query_type) {
|
||||
$this->query_type = strtolower($this->query_type);
|
||||
switch ($this->query_type) {
|
||||
case 'a':
|
||||
case 'any':
|
||||
case 'mx':
|
||||
case 'ns':
|
||||
case 'soa':
|
||||
case 'hinfo':
|
||||
case 'axfr':
|
||||
case 'txt':
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
|
||||
// {{{ _parse_data()
|
||||
|
||||
/**
|
||||
* Parses the raw data in $this->raw_data
|
||||
*
|
||||
* @return obj Net_Dig_result $return A Net_Dig_result object
|
||||
*
|
||||
* @access private
|
||||
* @author Colin Viebrock <colin@easyDNS.com>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function _parse_data()
|
||||
{
|
||||
|
||||
if (!$this->raw_data) {
|
||||
return new PEAR_Error("No raw data to parse");
|
||||
}
|
||||
|
||||
$regex = '/' .
|
||||
'^;(.*?)' .
|
||||
';; QUESTION SECTION\:(.*?)' .
|
||||
'(;; ANSWER SECTION\:(.*?))?' .
|
||||
'(;; AUTHORITY SECTION\:(.*?))?' .
|
||||
'(;; ADDITIONAL SECTION\:(.*?))?' .
|
||||
'(;;.*)' .
|
||||
'/ims';
|
||||
|
||||
if (preg_match($regex, $this->raw_data, $matches)) {
|
||||
|
||||
$result = new Net_Dig_result;
|
||||
|
||||
/* Start parsing the data */
|
||||
|
||||
|
||||
/* the header ... */
|
||||
|
||||
|
||||
$temp = explode("\n", trim($matches[1]));
|
||||
if (preg_match('/DiG (.*?) /i', $temp[0], $m)) {
|
||||
$result->dig_version = trim($m[1]);
|
||||
}
|
||||
if (preg_match('/status: (.*?), id: (.*?)$/i', $temp[3], $m)) {
|
||||
$result->status = trim($m[1]);
|
||||
$result->id = trim($m[2]);
|
||||
}
|
||||
|
||||
if (preg_match('/flags: (.*?); query: (.*?), answer: (.*?), authority: (.*?), additional: (.*?)$/i', $temp[4], $m)) {
|
||||
$result->flags = trim($m[1]);
|
||||
$result->query_count = (int)trim($m[2]);
|
||||
$result->answer_count = (int)trim($m[3]);
|
||||
$result->authority_count = (int)trim($m[4]);
|
||||
$result->additional_count = (int)trim($m[5]);
|
||||
}
|
||||
|
||||
|
||||
/* query section */
|
||||
|
||||
$line = trim(preg_replace('/^(;*)/', '', trim($matches[2])));
|
||||
list($host, $class, $type) = preg_split('/[\s]+/', $line, 3);
|
||||
$result->query[] = new Net_Dig_resource($host, false, $class, $type, false);
|
||||
|
||||
|
||||
/* answer section */
|
||||
|
||||
$temp = trim($matches[4]);
|
||||
if ($temp) {
|
||||
$temp = explode("\n", $temp);
|
||||
if (count($temp)) {
|
||||
foreach($temp as $line) {
|
||||
$result->answer[] = $this->_parse_resource($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* authority section */
|
||||
|
||||
$temp = trim($matches[6]);
|
||||
if ($temp) {
|
||||
$temp = explode("\n", $temp);
|
||||
if (count($temp)) {
|
||||
foreach($temp as $line) {
|
||||
$result->authority[] = $this->_parse_resource($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* additional section */
|
||||
|
||||
$temp = trim($matches[8]);
|
||||
if ($temp) {
|
||||
$temp = explode("\n", $temp);
|
||||
if (count($temp)) {
|
||||
foreach($temp as $line) {
|
||||
$result->additional[] = $this->_parse_resource($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* footer */
|
||||
|
||||
$temp = explode("\n", trim($matches[9]));
|
||||
if (preg_match('/query time: (.*?)$/i', $temp[0], $m)) {
|
||||
$result->query_time = trim($m[1]);
|
||||
}
|
||||
if (preg_match('/server: (.*?)#(.*?)\(/i', $temp[1], $m)) {
|
||||
$result->dig_server = trim($m[1]);
|
||||
$result->dig_port = trim($m[2]);
|
||||
}
|
||||
|
||||
/* done */
|
||||
|
||||
$result->consistency_check = (
|
||||
(count($result->query) == $result->query_count) &&
|
||||
(count($result->answer) == $result->answer_count) &&
|
||||
(count($result->authority) == $result->authority_count) &&
|
||||
(count($result->additional) == $result->additional_count)
|
||||
);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
return new PEAR_Error("Can't parse raw data");
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ _parse_resource()
|
||||
|
||||
/**
|
||||
* Parses a resource record line
|
||||
*
|
||||
* @param string $line The line to parse
|
||||
*
|
||||
* @return obj Net_Dig_resource $return A Net_Dig_resource object
|
||||
*
|
||||
* @access private
|
||||
* @author Colin Viebrock <colin@easyDNS.com>
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function _parse_resource($line)
|
||||
{
|
||||
|
||||
/* trim and remove leading ;, if present */
|
||||
|
||||
$line = trim(preg_replace('/^(;*)/', '', trim($line)));
|
||||
|
||||
if ($line) {
|
||||
list($host, $ttl, $class, $type, $data) = preg_split('/[\s]+/', $line, 5);
|
||||
return new Net_Dig_resource($host, $ttl, $class, $type, $data);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Net_Dig_result {
|
||||
|
||||
// {{{ Public Properties
|
||||
|
||||
var $status;
|
||||
var $id;
|
||||
var $flags;
|
||||
var $query_count;
|
||||
var $answer_count;
|
||||
var $authority_count;
|
||||
var $additional_count;
|
||||
|
||||
var $dig_version;
|
||||
var $dig_server;
|
||||
var $dig_port;
|
||||
|
||||
var $query;
|
||||
var $answer;
|
||||
var $authority;
|
||||
var $additional;
|
||||
|
||||
var $consistency_check;
|
||||
|
||||
function Net_Dig_result() {
|
||||
$this->status = false;
|
||||
$this->id = false;
|
||||
$this->flags = false;
|
||||
$this->query_count = false;
|
||||
$this->answer_count = false;
|
||||
$this->authority_count = false;
|
||||
$this->additional_count = false;
|
||||
|
||||
$this->dig_version = false;
|
||||
$this->dig_server = false;
|
||||
$this->dig_port = false;
|
||||
|
||||
$this->query = array();
|
||||
$this->answer = array();
|
||||
$this->authority = array();
|
||||
$this->additional = array();
|
||||
|
||||
$this->consistency_check = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Net_Dig_resource {
|
||||
|
||||
var $host;
|
||||
var $ttl;
|
||||
var $class;
|
||||
var $type;
|
||||
var $data;
|
||||
|
||||
function Net_Dig_resource($host=false, $ttl=false, $class=false, $type=false, $data=false) {
|
||||
$this->host = $host;
|
||||
$this->ttl = $ttl;
|
||||
$this->class = $class;
|
||||
$this->type = $type;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
400
html/service/LN_374893028394/Net/SMTP.php
Normal file
400
html/service/LN_374893028394/Net/SMTP.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Chuck Hagenbuch <chuck@horde.org> |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Provides an implementation of the SMTP protocol using PEAR's
|
||||
* Net_Socket:: class.
|
||||
*/
|
||||
class Net_SMTP extends PEAR {
|
||||
|
||||
/**
|
||||
* The server to connect to.
|
||||
* @var string
|
||||
*/
|
||||
var $host = 'localhost';
|
||||
|
||||
/**
|
||||
* The port to connect to.
|
||||
* @var int
|
||||
*/
|
||||
var $port = 25;
|
||||
|
||||
/**
|
||||
* The value to give when sending EHLO or HELO.
|
||||
* @var string
|
||||
*/
|
||||
var $localhost = 'localhost';
|
||||
|
||||
/**
|
||||
* The socket resource being used to connect to the SMTP server.
|
||||
* @var resource
|
||||
*/
|
||||
var $socket;
|
||||
|
||||
/**
|
||||
* The most recent reply code
|
||||
* @var int
|
||||
*/
|
||||
var $code;
|
||||
|
||||
/**
|
||||
* Stores detected features of the SMTP server.
|
||||
* @var array
|
||||
*/
|
||||
var $esmtp;
|
||||
|
||||
/**
|
||||
* The last line read from the server.
|
||||
* @var string
|
||||
*/
|
||||
var $lastline;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Instantiates a new Net_SMTP object, overriding any defaults
|
||||
* with parameters that are passed in.
|
||||
*
|
||||
* @param string The server to connect to.
|
||||
* @param int The port to connect to.
|
||||
* @param string The value to give when sending EHLO or HELO.
|
||||
*/
|
||||
function Net_SMTP($host = null, $port = null, $localhost = null) {
|
||||
if (isset($host)) $this->host = $host;
|
||||
if (isset($port)) $this->port = $port;
|
||||
if (isset($localhost)) $this->localhost = $localhost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to connect to the SMTP server.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function connect() {
|
||||
include_once 'Net/Socket.php';
|
||||
|
||||
if (PEAR::isError($this->socket = new Net_Socket())) { return new PEAR_Error('unable to create a socket object'); }
|
||||
if (PEAR::isError($this->socket->connect($this->host, $this->port))) { return new PEAR_Error('unable to open socket'); }
|
||||
|
||||
if (PEAR::isError($this->validateResponse('220'))) { return new PEAR_Error('smtp server not 220 ready'); }
|
||||
if (!$this->identifySender()) { return new PEAR_Error('unable to identify smtp server'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to disconnect from the SMTP server.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function disconnect() {
|
||||
if (PEAR::isError($this->socket->write("QUIT\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!$this->validateResponse('221')) { return new PEAR_Error('221 Bye not received'); }
|
||||
if (PEAR::isError($this->socket->disconnect())) { return new PEAR_Error('socket disconnect failed'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to do SMTP authentication.
|
||||
*
|
||||
* @param string The userid to authenticate as.
|
||||
* @param string The password to authenticate with.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function auth($uid, $pwd) {
|
||||
/* Note: not currently checking if AUTH LOGIN is allowed */
|
||||
/* Note: only allows one authentication mechanism */
|
||||
|
||||
if (!isset($this->esmtp['AUTH'])) { return new PEAR_Error('auth not supported'); }
|
||||
|
||||
if (PEAR::isError($this->socket->write("AUTH LOGIN\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!$this->validateResponse('334')) { return new PEAR_Error('AUTH LOGIN not recognized'); }
|
||||
|
||||
if (PEAR::isError($this->socket->write(base64_encode($uid) . "\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!$this->validateResponse('334')) { return new PEAR_Error('354 not received'); }
|
||||
|
||||
if (PEAR::isError($this->socket->write(base64_encode($pwd) . "\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!$this->validateResponse('235')) { return new PEAR_Error('235 not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the HELO command.
|
||||
*
|
||||
* @param string The domain name to say we are.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function helo($domain) {
|
||||
if (PEAR::isError($this->socket->write("HELO $domain\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the MAIL FROM: command.
|
||||
*
|
||||
* @param string The sender (reverse path) to set.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function mailFrom($reverse_path) {
|
||||
if (PEAR::isError($this->socket->write("MAIL FROM:<$reverse_path>\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the RCPT TO: command.
|
||||
*
|
||||
* @param string The recipient (forward path) to add.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function rcptTo($forward_path) {
|
||||
/* Note: 251 is also a valid response code */
|
||||
|
||||
if (PEAR::isError($this->socket->write("RCPT TO: <$forward_path>\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error($this->lastline); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the DATA command.
|
||||
*
|
||||
* @param string The message body to send.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function data($data) {
|
||||
$data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data);
|
||||
$data = preg_replace("/\n\n/", "\n\r\n", $data);
|
||||
$data = preg_replace("/\n\./", "\n..", $data);
|
||||
|
||||
if (PEAR::isError($this->socket->write("DATA\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('354'))) { return new PEAR_Error('354 not received'); }
|
||||
if (PEAR::isError($this->socket->write($data . "\r\n.\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the SEND FROM: command.
|
||||
*
|
||||
* @param string The reverse path to send.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function send_from($reverse_path) {
|
||||
if (PEAR::isError($this->socket->write("SEND FROM:<$reverse_path>\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the SOML FROM: command.
|
||||
*
|
||||
* @param string The reverse path to send.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function soml_from($reverse_path) {
|
||||
if (PEAR::isError($this->socket->write("SOML FROM:<$reverse_path>\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the SAML FROM: command.
|
||||
*
|
||||
* @param string The reverse path to send.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function saml_from($reverse_path) {
|
||||
if (PEAR::isError($this->socket->write("SAML FROM:<$reverse_path>\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the RSET command.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function rset() {
|
||||
if (PEAR::isError($this->socket->write("RSET\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the VRFY command.
|
||||
*
|
||||
* @param string The string to verify
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function vrfy($string) {
|
||||
/* Note: 251 is also a valid response code */
|
||||
if (PEAR::isError($this->socket->write("VRFY $string\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the NOOP command.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access public
|
||||
*/
|
||||
function noop() {
|
||||
if (PEAR::isError($this->socket->write("NOOP\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('250 OK not received'); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to send the EHLO command and obtain a list of ESMTP
|
||||
* extensions available, and failing that just send HELO.
|
||||
*
|
||||
* @return mixed Returns a PEAR_Error with an error message on any
|
||||
* kind of failure, or true on success.
|
||||
* @access private
|
||||
*/
|
||||
function identifySender() {
|
||||
if (PEAR::isError($this->socket->write("EHLO $this->localhost\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
|
||||
$extensions = array();
|
||||
if (!($this->validateAndParseResponse('250', $extensions))) {
|
||||
if (PEAR::isError($this->socket->write("HELO $this->localhost\r\n"))) { return new PEAR_Error('write to socket failed'); }
|
||||
if (!($this->validateResponse('250'))) { return new PEAR_Error('HELO not accepted', $this->code); }
|
||||
return true;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($extensions); $i++) {
|
||||
$verb = strtok($extensions[$i], ' ');
|
||||
$arguments = substr($extensions[$i], strlen($verb) + 1, strlen($extensions[$i]) - strlen($verb) - 2);
|
||||
$this->esmtp[$verb] = $arguments;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a response from the server and see if the response code
|
||||
* matches what we are expecting.
|
||||
*
|
||||
* @param int The response code we are expecting.
|
||||
*
|
||||
* @return boolean True if we get what we expect, false otherwise.
|
||||
* @access private
|
||||
*/
|
||||
function validateResponse($code) {
|
||||
while ($this->lastline = $this->socket->readLine()) {
|
||||
$reply_code = strtok($this->lastline, ' ');
|
||||
if (!(strcmp($code, $reply_code))) {
|
||||
$this->code = $reply_code;
|
||||
return true;
|
||||
} else {
|
||||
$reply_code = strtok($this->lastline, '-');
|
||||
if (strcmp($code, $reply_code)) {
|
||||
$this->code = $reply_code;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a response from the server and see if the response code
|
||||
* matches what we are expecting. Also save the rest of the
|
||||
* response in the array passed by reference as the second
|
||||
* argument.
|
||||
*
|
||||
* @param int The response code we are expecting.
|
||||
* @param array An array to dump the rest of the response into.
|
||||
*
|
||||
* @return boolean True if we get what we expect, false otherwise.
|
||||
* @access private
|
||||
*/
|
||||
function validateAndParseResponse($code, &$arguments) {
|
||||
$arguments = array();
|
||||
|
||||
while ($this->lastline = $this->socket->readLine()) {
|
||||
$reply_code = strtok($this->lastline, ' ');
|
||||
if (!(strcmp($code, $reply_code))) {
|
||||
$arguments[] = substr($this->lastline, strlen($code) + 1, strlen($this->lastline) - strlen($code) - 1);
|
||||
$this->code = $reply_code;
|
||||
return true;
|
||||
} else {
|
||||
$reply_code = strtok($this->lastline, '-');
|
||||
if (strcmp($code, $reply_code)) {
|
||||
$this->code = $reply_code;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$arguments[] = substr($this->lastline, strlen($code) + 1, strlen($this->lastline) - strlen($code) - 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
456
html/service/LN_374893028394/Net/Socket.php
Normal file
456
html/service/LN_374893028394/Net/Socket.php
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@php.net> |
|
||||
// | Chuck Hagenbuch <chuck@horde.org> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Socket.php,v 1.9 2004/04/26 23:02:41 chagenbu Exp $
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Generalized Socket class. More docs to be written.
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
*/
|
||||
class Net_Socket extends PEAR {
|
||||
// {{{ properties
|
||||
|
||||
/** Socket file pointer. */
|
||||
var $fp = null;
|
||||
|
||||
/** Whether the socket is blocking. */
|
||||
var $blocking = true;
|
||||
|
||||
/** Whether the socket is persistent. */
|
||||
var $persistent = false;
|
||||
|
||||
/** The IP address to connect to. */
|
||||
var $addr = '';
|
||||
|
||||
/** The port number to connect to. */
|
||||
var $port = 0;
|
||||
|
||||
/** Number of seconds to wait on socket connections before
|
||||
assuming there's no more data. */
|
||||
var $timeout = false;
|
||||
|
||||
/** Number of bytes to read at a time in readLine() and
|
||||
readAll(). */
|
||||
var $lineLength = 2048;
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
/**
|
||||
* Constructs a new Net_Socket object.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Net_Socket()
|
||||
{
|
||||
$this->PEAR();
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ connect()
|
||||
/**
|
||||
* Connect to the specified port. If called when the socket is
|
||||
* already connected, it disconnects and connects again.
|
||||
*
|
||||
* @param $addr string IP address or host name
|
||||
* @param $port int TCP port number
|
||||
* @param $persistent bool (optional) whether the connection is
|
||||
* persistent (kept open between requests by the web server)
|
||||
* @param $timeout int (optional) how long to wait for data
|
||||
* @param $options array see options for stream_context_create
|
||||
* @access public
|
||||
* @return mixed true on success or error object
|
||||
*/
|
||||
function connect($addr, $port, $persistent = null, $timeout = null, $options = null)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
@fclose($this->fp);
|
||||
$this->fp = null;
|
||||
}
|
||||
|
||||
if (strspn($addr, '.0123456789') == strlen($addr)) {
|
||||
$this->addr = $addr;
|
||||
} else {
|
||||
$this->addr = gethostbyname($addr);
|
||||
}
|
||||
$this->port = $port % 65536;
|
||||
if ($persistent !== null) {
|
||||
$this->persistent = $persistent;
|
||||
}
|
||||
if ($timeout !== null) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
if ($options && function_exists('stream_context_create')) {
|
||||
if ($this->timeout) {
|
||||
$timeout = $this->timeout;
|
||||
} else {
|
||||
$timeout = 0;
|
||||
}
|
||||
$context = stream_context_create($options);
|
||||
$fp = $openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
|
||||
} else {
|
||||
if ($this->timeout) {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
|
||||
} else {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fp) {
|
||||
return $this->raiseError($errstr, $errno);
|
||||
}
|
||||
|
||||
$this->fp = $fp;
|
||||
|
||||
return $this->setBlocking($this->blocking);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ disconnect()
|
||||
/**
|
||||
* Disconnects from the peer, closes the socket.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
fclose($this->fp);
|
||||
$this->fp = null;
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ isBlocking()
|
||||
/**
|
||||
* Find out if the socket is in blocking mode.
|
||||
*
|
||||
* @access public
|
||||
* @return bool the current blocking mode.
|
||||
*/
|
||||
function isBlocking()
|
||||
{
|
||||
return $this->blocking;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ setBlocking()
|
||||
/**
|
||||
* Sets whether the socket connection should be blocking or
|
||||
* not. A read call to a non-blocking socket will return immediately
|
||||
* if there is no data available, whereas it will block until there
|
||||
* is data for blocking sockets.
|
||||
*
|
||||
* @param $mode bool true for blocking sockets, false for nonblocking
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setBlocking($mode)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$this->blocking = $mode;
|
||||
socket_set_blocking($this->fp, $this->blocking);
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ setTimeout()
|
||||
/**
|
||||
* Sets the timeout value on socket descriptor,
|
||||
* expressed in the sum of seconds and microseconds
|
||||
*
|
||||
* @param $seconds int seconds
|
||||
* @param $microseconds int microseconds
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setTimeout($seconds, $microseconds)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
socket_set_timeout($this->fp, $seconds, $microseconds);
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ getStatus()
|
||||
/**
|
||||
* Returns information about an existing socket resource.
|
||||
* Currently returns four entries in the result array:
|
||||
*
|
||||
* <p>
|
||||
* timed_out (bool) - The socket timed out waiting for data<br>
|
||||
* blocked (bool) - The socket was blocked<br>
|
||||
* eof (bool) - Indicates EOF event<br>
|
||||
* unread_bytes (int) - Number of bytes left in the socket buffer<br>
|
||||
* </p>
|
||||
*
|
||||
* @access public
|
||||
* @return mixed Array containing information about existing socket resource or an error object otherwise
|
||||
*/
|
||||
function getStatus()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return socket_get_status($this->fp);
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ gets()
|
||||
/**
|
||||
* Get a specified line of data
|
||||
*
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function gets($size)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return fgets($this->fp, $size);
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ read()
|
||||
/**
|
||||
* Read a specified amount of data. This is guaranteed to return,
|
||||
* and has the added benefit of getting everything in one fread()
|
||||
* chunk; if you know the size of the data you're getting
|
||||
* beforehand, this is definitely the way to go.
|
||||
*
|
||||
* @param $size The number of bytes to read from the socket.
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function read($size)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return fread($this->fp, $size);
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ write()
|
||||
/**
|
||||
* Write a specified amount of data.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function write($data)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return fwrite($this->fp, $data);
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ writeLine()
|
||||
/**
|
||||
* Write a line of data to the socket, followed by a trailing "\r\n".
|
||||
*
|
||||
* @access public
|
||||
* @return mixed fputs result, or an error
|
||||
*/
|
||||
function writeLine ($data)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return $this->write($data . "\r\n");
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ eof()
|
||||
/**
|
||||
* Tests for end-of-file on a socket descriptor
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function eof()
|
||||
{
|
||||
return (is_resource($this->fp) && feof($this->fp));
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readByte()
|
||||
/**
|
||||
* Reads a byte of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 byte of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readByte()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
return ord($this->read(1));
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readWord()
|
||||
/**
|
||||
* Reads a word of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 word of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readWord()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$buf = $this->read(2);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8));
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readInt()
|
||||
/**
|
||||
* Reads an int of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 int of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readInt()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$buf = $this->read(4);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8) +
|
||||
(ord($buf[2]) << 16) + (ord($buf[3]) << 24));
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readString()
|
||||
/**
|
||||
* Reads a zeroterminated string of data
|
||||
*
|
||||
* @access public
|
||||
* @return string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readString()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$string = '';
|
||||
while (($char = $this->read(1)) != "\x00") {
|
||||
$string .= $char;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readIPAddress()
|
||||
/**
|
||||
* Reads an IP Address and returns it in a dot formated string
|
||||
*
|
||||
* @access public
|
||||
* @return Dot formated string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readIPAddress()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$buf = $this->read(4);
|
||||
return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]),
|
||||
ord($buf[2]), ord($buf[3]));
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readLine()
|
||||
/**
|
||||
* Read until either the end of the socket or a newline, whichever
|
||||
* comes first. Strips the trailing newline from the returned data.
|
||||
*
|
||||
* @access public
|
||||
* @return All available data up to a newline, without that
|
||||
* newline, or until the end of the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readLine()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$line = '';
|
||||
$timeout = time() + $this->timeout;
|
||||
while (!$this->eof() && (!$this->timeout || time() < $timeout)) {
|
||||
$line .= $this->gets($this->lineLength);
|
||||
if (substr($line, -2) == "\r\n" ||
|
||||
substr($line, -1) == "\n") {
|
||||
return rtrim($line, "\r\n");
|
||||
}
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ readAll()
|
||||
/**
|
||||
* Read until the socket closes. THIS FUNCTION WILL NOT EXIT if the
|
||||
* socket is in blocking mode until the socket closes.
|
||||
*
|
||||
* @access public
|
||||
* @return All data until the socket closes, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readAll()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
$data = '';
|
||||
while (!$this->eof())
|
||||
$data .= $this->read($this->lineLength);
|
||||
return $data;
|
||||
}
|
||||
return $this->raiseError("not connected");
|
||||
}
|
||||
// }}}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user