function save($curpass, $passwd) { $rcmail = rcmail::get_instance(); $vpopmaild = new Net_Socket(); $host = $rcmail->config->get('password_vpopmaild_host'); $port = $rcmail->config->get('password_vpopmaild_port'); $result = $vpopmaild->connect($host, $port, null); if (is_a($result, 'PEAR_Error')) { return PASSWORD_CONNECT_ERROR; } $vpopmaild->setTimeout($rcmail->config->get('password_vpopmaild_timeout'), 0); $result = $vpopmaild->readLine(); if (!preg_match('/^\\+OK/', $result)) { $vpopmaild->disconnect(); return PASSWORD_CONNECT_ERROR; } $vpopmaild->writeLine("slogin " . $_SESSION['username'] . " " . $curpass); $result = $vpopmaild->readLine(); if (!preg_match('/^\\+OK/', $result)) { $vpopmaild->writeLine("quit"); $vpopmaild->disconnect(); return PASSWORD_ERROR; } $vpopmaild->writeLine("mod_user " . $_SESSION['username']); $vpopmaild->writeLine("clear_text_password " . $passwd); $vpopmaild->writeLine("."); $result = $vpopmaild->readLine(); $vpopmaild->writeLine("quit"); $vpopmaild->disconnect(); if (!preg_match('/^\\+OK/', $result)) { return PASSWORD_ERROR; } return PASSWORD_SUCCESS; }
/** * Connect to an IMAP server * * @param string $host * @param int $port * @param int $timeout */ function connect($host = 'localhost', $port = 143, $timeout = 30, $ssl = false) { $this->host = $host; if ($ssl) { $host = "ssl://{$host}"; $this->SSL = true; } $con = $this->socket->connect($host, $port, null, $timeout); if (PEAR::isError($con)) { return false; } $resp = $this->socket->readLine(); if (substr($resp, 0, 4) != '* OK') { return false; } if (preg_match('/\\[CAPABILITY (.+?)\\]/i', $resp, $m)) { $this->capabilities = explode(' ', $m[1]); } else { $resp = $this->capability(); if (is_array($resp)) { $this->capabilities = $resp; } } //$this->startTLS(); return true; }
function save($curpass, $passwd) { $rcmail = rcmail::get_instance(); // include('Net/Socket.php'); $vpopmaild = new Net_Socket(); if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'), $rcmail->config->get('password_vpopmaild_port'), null))) { return PASSWORD_CONNECT_ERROR; } $result = $vpopmaild->readLine(); if (!preg_match('/^\\+OK/', $result)) { $vpopmaild->disconnect(); return PASSWORD_CONNECT_ERROR; } $vpopmaild->writeLine("slogin " . $_SESSION['username'] . " " . $curpass); $result = $vpopmaild->readLine(); if (!preg_match('/^\\+OK/', $result)) { $vpopmaild->writeLine("quit"); $vpopmaild->disconnect(); return PASSWORD_ERROR; } $vpopmaild->writeLine("mod_user " . $_SESSION['username']); $vpopmaild->writeLine("clear_text_password " . $passwd); $vpopmaild->writeLine("."); $result = $vpopmaild->readLine(); $vpopmaild->writeLine("quit"); $vpopmaild->disconnect(); if (!preg_match('/^\\+OK/', $result)) { return PASSWORD_ERROR; } return PASSWORD_SUCCESS; }
/** * リソースリクエスト送信 * * @param string $method リクエストメソッド(CRUD) * @param string $uri URI(クエリー付き) * @param array $values 引数 * * @return mixed BEAR_Ro | array */ public function send($method, $uri, array $values = array()) { $socket = new Net_Socket(); // 接続を確立する $socket->connect($this->_ip, $this->_port, true, 30); $uriWithVal = self::_mergeQueryAndArray($uri, $values); // 改行を含むデータを送信する $request = "{$method} {$uriWithVal}"; $socket->writeLine($request); // 改行が現れるまでデータを受信する $code = $socket->readLine(); // アトリビュート $header = $socket->readLine(); while ($header) { $headers[] = $header; $header = $socket->readLine(); } $body = $socket->readLine(); if ($this->_returnVo && class_exists('BEAR_Ro', false)) { $ro = BEAR::factory('BEAR_Ro'); /* @var $ro BEAR_Ro */ $ro->setBody($body); $ro->setHeaders($headers); $ro->setCode($code); $result = $ro; } else { $result = array('code' => $code, 'headers' => $headers, 'body' => $body); } return $result; }
/** * Implements Net_Finger::query() function using PEAR's socket functions * * @param string $server The finger-server to query * @param string $query The finger database object to lookup * @return mixed The data returned from the finger-server as string * or a PEAR_Error ( see Net_Socket for error codes) */ function query($server, $query) { $socket = new Net_Socket(); if (PEAR::isError($sockerror = $socket->connect($server, 79))) { $data = new PEAR_Error("Error connecting to {$server} ( Net_Socket says: " . $sockerror->getMessage() . ")", $sockerror->getCode()); } else { $query .= "\n"; $socket->write($query); $data = $socket->read(16384); $socket->disconnect(); } return $data; }
function sendCommand($address, $command) { $socket = new Net_Socket(); // open connection $socket->connect("{$address}", 23, true, 3); $socket->writeLine($command); echo "\naddress:: {$address} command {$comando}"; sleep(1); $respuesta = trim($socket->read(200)); echo "\n respuesta: {$respuesta}\n"; $socket->disconnect(); echo "\ndisconnect..\n"; }
function password_save($curpass, $passwd) { $rcmail = rcmail::get_instance(); // include('Net/Socket.php'); $poppassd = new Net_Socket(); $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); if (PEAR::isError($result)) { return format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); } else { $result = $poppassd->readLine(); if (!preg_match('/^2\\d\\d/', $result)) { $poppassd->disconnect(); return format_error_result(PASSWORD_ERROR, $result); } else { $poppassd->writeLine("user " . $_SESSION['username']); $result = $poppassd->readLine(); if (!preg_match('/^[23]\\d\\d/', $result)) { $poppassd->disconnect(); return format_error_result(PASSWORD_CONNECT_ERROR, $result); } else { $poppassd->writeLine("pass " . $curpass); $result = $poppassd->readLine(); if (!preg_match('/^[23]\\d\\d/', $result)) { $poppassd->disconnect(); return format_error_result(PASSWORD_ERROR, $result); } else { $poppassd->writeLine("newpass " . $passwd); $result = $poppassd->readLine(); $poppassd->disconnect(); if (!preg_match('/^2\\d\\d/', $result)) { return format_error_result(PASSWORD_ERROR, $result); } else { return PASSWORD_SUCCESS; } } } } } }
function save($curpass, $passwd) { $rcmail = rcmail::get_instance(); $poppassd = new Net_Socket(); $port = $rcmail->config->get('password_pop_port', 106); $host = $rcmail->config->get('password_pop_host', 'localhost'); $host = rcube_utils::parse_host($host); $result = $poppassd->connect($host, $port, null); if (is_a($result, 'PEAR_Error')) { return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); } $result = $poppassd->readLine(); if (!preg_match('/^2\\d\\d/', $result)) { $poppassd->disconnect(); return $this->format_error_result(PASSWORD_ERROR, $result); } $poppassd->writeLine("user " . $_SESSION['username']); $result = $poppassd->readLine(); if (!preg_match('/^[23]\\d\\d/', $result)) { $poppassd->disconnect(); return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result); } $poppassd->writeLine("pass " . $curpass); $result = $poppassd->readLine(); if (!preg_match('/^[23]\\d\\d/', $result)) { $poppassd->disconnect(); return $this->format_error_result(PASSWORD_ERROR, $result); } $poppassd->writeLine("newpass " . $passwd); $result = $poppassd->readLine(); $poppassd->disconnect(); if (!preg_match('/^2\\d\\d/', $result)) { return $this->format_error_result(PASSWORD_ERROR, $result); } return PASSWORD_SUCCESS; }
/** * @brief * @param string $data_file Saveするファイルのパス * @param string $url データのURL * @retval bool */ function fetchTgzFile($data_file, $url) { /* exec('which wget || which curl', $which, $status); $command = strpos($which[0], 'wget')!==false ? sprintf('%s -O %s %s', $which[0], $data_file, $_url) : sprintf('%s -o %s %s', $which[0], $data_file, $_url); exec($command, $result, $status); return $status === 0; */ if ($fp = fopen($data_file, 'w')) { $url = parse_url($url); if (isset($url['port']) && $url['port']) { $port = $url['port']; } else { $port = $url['scheme'] == 'https' ? '443' : '80'; } $path = isset($url['path']) && $url['path'] ? $url['path'] : '/'; $path .= isset($url['query']) && $url['query'] ? $url['query'] : ''; require_once 'Net/Socket.php'; $sock = new Net_Socket(); $connect = $sock->connect($url['host'], $port); if ($connect) { $sock->writeLine("GET {$path} HTTP/1.1"); $sock->writeLine("Host: " . $url['host']); $sock->writeLine("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)"); $sock->writeLine("Keep-Alive: 1000"); $sock->writeLine("Connection: keep-alive"); $sock->writeLine(""); $null_line = false; while (!$sock->eof()) { if ($null_line === false) { $_sock_d = $sock->readLine(); if ($_sock_d == "") { $null_line = true; } } if ($null_line === true) { $_sock_d = $sock->read(1024); fputs($fp, $_sock_d); } } $sock->disconnect(); } fclose($fp); return true; } return false; }
/** * * Print proxy settings * * @access private * */ public function printProxyStatus($client) { require_once './Services/Http/exceptions/class.ilProxyException.php'; $settings = $client->getAllSettings(); if ((bool) $settings['proxy_status'] == true) { try { /** * * Verifies the proxy server connection */ require_once 'Services/PEAR/lib/Net/Socket.php'; $socket = new Net_Socket(); $socket->setErrorHandling(PEAR_ERROR_RETURN); $response = $socket->connect($settings['proxy_host'], $settings['proxy_port']); if (!is_bool($response)) { global $lng; throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable')); } ilUtil::sendSuccess($this->lng->txt('proxy_connectable')); } catch (ilProxyException $e) { ilUtil::sendFailure($this->lng->txt('proxy_pear_net_socket_error') . ': ' . $e->getMessage()); } } }
/** * Connects to the whois server and retrieves domain information * * @param string $nicServer FQDN of whois server to query * @param string $domain Domain name to query * * @access private * @return mixed returns a PEAR_Error on failure, string of whois data on success */ function _connect($nicServer, $domain) { include_once 'Net/Socket.php'; if (is_null($nicServer) || empty($nicServer)) { return new PEAR_Error($this->_errorCodes[014], 14); } if (PEAR::isError($socket = new Net_Socket())) { return new PEAR_Error($this->_errorCodes[010], 10); } $result = $socket->connect($nicServer, $this->getPort(), null, $this->getTimeout(), $this->getOptions()); if (PEAR::isError($result)) { return new PEAR_Error($this->_errorCodes[011], 11); } $socket->setBlocking(false); // Querying denic.de requires some special coaxing for a domain query. // http://www.denic.de/en/faq-single/2978/1115.html if (substr($domain, -3) == '.de') { if (PEAR::isError($socket->writeLine("-T dn,ace " . $domain))) { return new PEAR_Error($this->_errorCodes[012], 12); } } else { if (PEAR::isError($socket->writeLine($domain))) { return new PEAR_Error($this->_errorCodes[012], 12); } } $nHost = null; $whoisData = $socket->readAll(); if (PEAR::isError($whoisData)) { return new PEAR_Error($this->_errorCodes[013], 13); } $data = explode("\n", $whoisData); foreach ($data as $line) { $line = rtrim($line); // check for whois server redirection if (!isset($nHost)) { $pattern = '/' . $this->_whoisServerID . '([a-z0-9.]+)\\n/i'; if (preg_match($pattern, $line, $matches)) { $nHost = $matches[1]; } elseif ($nicServer == $this->_nicServers['ANICHOST']) { foreach ($this->_ipNicServers as $ipNicServer) { $server = trim($this->_nicServers[$ipNicServer], '.'); if (strstr($line, $server)) { $nHost = $this->_nicServers[$ipNicServer]; } } } } } // this should fail, but we'll call it anyway and ignore the error $socket->disconnect(); if ($nHost && $nHost != $nicServer) { $tmpBuffer = $this->_connect($nHost, $domain); if (PEAR::isError($tmpBuffer)) { return $tmpBuffer; } $whoisData .= $tmpBuffer; } return $whoisData; }
/** * Connects to the whois server and retrieves domain information * * @param $nicServer string FQDN of whois server to query * @param $domain string domain name to query * @access private * @return mixed returns a PEAR_Error on failure, string of whois data on success */ function _connect($nicServer, $domain) { include_once 'Net/Socket.php'; if (PEAR::isError($socket = new Net_Socket())) { return new PEAR_Error($this->_errorCodes[010]); } if (PEAR::isError($socket->connect($nicServer, getservbyname('whois', 'tcp')))) { return new PEAR_Error($this->_errorCodes[011]); } $socket->setBlocking(false); if (PEAR::isError($socket->writeLine($domain))) { return new PEAR_Error($this->_errorCodes[012]); } $nHost = null; $whoisData = $socket->readAll(); if (PEAR::isError($whoisData)) { return new PEAR_Error($this->_errorCodes[013]); } $data = explode("\n", $whoisData); foreach ($data as $line) { $line = rtrim($line); // check for whois server redirection if (!isset($nHost)) { if (preg_match("/" . $this->_whoisServerID . "(.*)/", $line, $matches)) { $nHost = $matches[1]; } elseif ($nicServer == $this->_nicServers["ANICHOST"]) { foreach ($this->_ipNicServers as $ipNicServer) { if (strstr($line, $ipNicServer)) { $nHost = $ipNicServer; } } } } } // this should fail, but we'll call it anyway and ignore the error $socket->disconnect(); if ($nHost) { $tmpBuffer = $this->_connect($nHost, $domain); if (PEAR::isError($tmpBuffer)) { return $tmpBuffer; } $whoisData .= $tmpBuffer; } return $whoisData; }
function checkout() { //$repo_url, $repo_sub_path, $current_rev) { $repo_url = $this->state->get_repository_root(); $repo_sub_path = $this->state->get_repository_path(); $current_rev = $this->state->get_revision(); $src_path = $repo_url . $repo_sub_path; // figure out where to send our http REPORT request $bits = parse_url($repo_url . "/!svn/vcc/default"); $repo_host = $bits['host']; $repo_port = @$bits['port']; if (!$repo_port) { $repo_port = 80; } $repo_path = $bits['path']; $this->out("Connecting to host {$repo_host}:{$repo_port},<br>sending HTTP REPORT {$repo_path} for src-path {$src_path}.\n"); $xml = '<S:update-report send-all="true" xmlns:S="svn:"><S:src-path>' . $src_path . '</S:src-path><S:entry rev="' . $current_rev . '"></S:entry></S:update-report>'; $xml_len = strlen($xml); $query = "REPORT {$repo_path} HTTP/1.0\nHost: {$repo_host}\nContent-Type: text/xml\nContent-Length: {$xml_len}\nDepth: 0\n\n{$xml}"; $this->out($query); $sock = new Net_Socket(); $this->check_err($sock->connect($repo_host, $repo_port, null, 60, null)); // 60 sec timeout $this->check_err($sock->write($query)); // read response $this->out("Downloading patch ...\n"); $this->fp = fopen($this->diff_fn, "wt"); if (!$this->fp) { throw new Subversion_Failure("can't open {$this->diff_fn} file"); } $listeners = array($this); $this->received_bytes = 0; $resp = new HTTP_Response($sock, $listeners); $this->check_err($resp->process(false)); fclose($this->fp); $this->out("\nFinished downloading update ({$this->received_bytes} bytes).\n"); }
function get_gg_status($numer_gg, $haslo_gg, $szukany_numer, &$error, &$gg_status_widocznosc) { define("GG_WELCOME", 0x1); define("GG_LOGIN", 0xc); define("GG_LOGIN60", 0x15); define("GG_LOGIN_OK", 0x3); define("GG_LOGIN_FAILED", 0x9); define("GG_NEW_STATUS", 0x2); define("GG_STATUS", 0x2); define("GG_STATUS_NOT_AVAIL", 0x1); define("GG_STATUS_NOT_AVAIL_DESCR", 0x15); define("GG_STATUS_AVAIL", 0x2); define("GG_STATUS_AVAIL_DESCR", 0x4); define("GG_STATUS_BUSY", 0x3); define("GG_STATUS_BUSY_DESCR", 0x5); define("GG_STATUS_INVISIBLE", 0x14); define("GG_NOTIFY", 0x10); define("GG_NOTIFY_REPLY", 0xc); define("GG_NOTIFY_REPLY60", 0x11); define("GG_USER_NORMAL", 0x3); define("GG_USER_BLOCKED", 0x4); define("GG_SEND_MSG", 0xb); define("GG_CLASS_MSG", 0x4); define("GG_CLASS_CHAT", 0x8); define("GG_CLASS_ACK", 0x20); define("GG_SEND_MSG_ACK", 0x5); define("GG_ACK_DELIVERED", 0x2); define("GG_ACK_QUEUED", 0x3); define("GG_RECV_MSG", 0xa); define("GG_LOGIN_FAILED2", 0xb); define("GG_ACK_MBOXFULL", 0x4); define("DISCONNECTED", 0x100); define("GG_PUBDIR50_REQUEST", 0x14); define("GG_PUBDIR50_REPLY", 0xe); define("GG_PUBDIR50_SEARCH", 0x3); // // Getting a logon server // require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; serendipity_request_start(); $req = new HTTP_Request('http://appmsg.gadu-gadu.pl:80/appsvc/appmsg.asp?fmnumber=<' . $numer_gg . '>'); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { $error = PLUGIN_GGOPIS_MSG_NOCONNTOAPPMSG . $errno . " - " . $errstr . "\n"; serendipity_request_end(); return false; } else { $buf = $req->getResponseBody(); preg_match("/\\s([\\d\\.]{8,16})\\:([\\d]{1,5})\\s/", $buf, $adres); $host = $adres[1]; $port = $adres[2]; serendipity_request_end(); } // // Connecting to a server // require_once S9Y_PEAR_PATH . 'Net/Socket.php'; $conn = new Net_Socket(); if (!$conn->connect($host, $port, null, 10)) { $error = PLUGIN_GGOPIS_MSG_CONNERROR . ": {$errno} - {$errstr}\n\n"; return false; } // // Getting data from a server - // receiving a key needed to calculate // a hash from your password // if (!($data = $conn->read(12))) { $error = PLUGIN_GGOPIS_MSG_CONNUNEXPCLOSED . "\n\n"; $conn->disconnect(); return false; } $tab = unpack("Vtyp/Vrozmiar/Vklucz", $data); // Calculating a password hash $hash = $this->calculate_hash($haslo_gg, $tab['klucz']); $data = pack("VVVVVVvVvVvCCa" . strlen(""), GG_LOGIN60, 0x20 + strlen(""), $numer_gg, $hash, GG_STATUS_AVAIL, 0x20, 0, 0, 0, 0, 0, 0x14, 0xbe, ""); // Sending a password hash - logging to a GG server $conn->write($data); if (!($data1 = $conn->read(8))) { $error = PLUGIN_GGOPIS_MSG_UNKNOWNERROR . "\n"; $conn->disconnect(); return false; } // Checking a login status $tab = unpack("Vlogin_status/Vrozmiar", $data1); if ($tab['login_status'] != GG_LOGIN_OK) { $error = PLUGIN_GGOPIS_MSG_INCORRPASSWD . "\n\n"; $conn->disconnect(); return false; } // Sending a contact list with one contact $data = pack("VVVC", GG_NOTIFY, 5, $szukany_numer, GG_USER_NORMAL); if (!$conn->write($data)) { $error = PLUGIN_GGOPIS_MSG_SENDCONTACTSERROR . "\n\n"; $conn->disconnect(); return false; } // Receiving a packet with the next packet specification $gg_opis = ''; $data = $conn->read(8); if (strlen($data) > 0) { $tab = unpack("Vtyp/Vrozmiar", $data); // Pobranie pakietu opisu // DEBUG: echo $tab['rozmiar']; $data = $conn->read($tab['rozmiar']); if ($tab['rozmiar'] > 14) { $tablica = unpack("Iuin/Cstatus/Iremoteip/Sremoteport/Cversion/Cimagesize/Cunknown/Cdescription_size/a*description", $data); // Getting a status description, and converting it from CP1250 (that's how it's encoded) to UTF8 $gg_opis = $this->cp1250_to_utf8($tablica['description']); // Getting a status itself $gg_status_flaga = $tablica['status']; } else { $tablica = unpack("Iuin/Cstatus", $data); // Getting a status $gg_status_flaga = $tablica['status']; } if (empty($gg_opis)) { $gg_opis = PLUGIN_GGOPIS_MSG_NOSTATUSDESC; } // Choosing a status icon to display switch ($gg_status_flaga) { case GG_STATUS_NOT_AVAIL: case GG_STATUS_NOT_AVAIL_DESCR: $gg_status_widocznosc = 'gg11'; break; case GG_STATUS_AVAIL: case GG_STATUS_AVAIL_DESCR: $gg_status_widocznosc = 'gg12'; break; case GG_STATUS_BUSY: case GG_STATUS_BUSY_DESCR: $gg_status_widocznosc = 'gg13'; break; default: $gg_status_widocznosc = 'gg11'; } } else { $gg_opis = PLUGIN_GGOPIS_MSG_NOSTATUSDESC; } // Closing a connection to the server $conn->disconnect(); return $gg_opis; }
/** * Connects to a dict server and sets up a socket * * @param string $server * @param integer $port * * @return mixed true on success, else PEAR_Error */ function connect($server = '', $port = 0) { $s = new Net_Socket(); if (empty($server)) { $server = $this->server; } if (0 == $port) { $port = $this->port; } $err = $s->connect($server, $port); if (PEAR::isError($err)) { return $err; } $banner = $s->readLine(); preg_match("/\\d{3} (.*) <(.*)> <(.*)>/", $banner, &$reg); $this->servinfo["signature"] = $reg[1]; $this->servinfo["capabilities"] = explode(".", $reg[2]); $this->servinfo["msg-id"] = $reg[3]; $this->_socket = $s; return true; }
/** * * Verifies the proxy server connection * * @access public * @return ilProxySettings * @throws ilProxyException * */ public function checkConnection() { require_once 'Services/PEAR/lib/Net/Socket.php'; $socket = new Net_Socket(); $socket->setErrorHandling(PEAR_ERROR_RETURN); $response = $socket->connect($this->getHost(), $this->getPort()); if (!is_bool($response)) { global $lng; throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable')); } return $this; }
/** * Sends the request * * @access public * @param bool Whether to store response body in Response object property, * set this to false if downloading a LARGE file and using a Listener * @return mixed PEAR error on error, true otherwise */ function sendRequest($saveBody = true) { if (!is_a($this->_url, 'Net_URL')) { return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL); } $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; if (strcasecmp($this->_url->protocol, 'https') == 0) { // Bug #14127, don't try connecting to HTTPS sites without OpenSSL if (version_compare(PHP_VERSION, '4.3.0', '<') || !extension_loaded('openssl')) { return PEAR::raiseError('Need PHP 4.3.0 or later with OpenSSL support for https:// requests', HTTP_REQUEST_ERROR_URL); } elseif (isset($this->_proxy_host)) { return PEAR::raiseError('HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY); } $host = 'ssl://' . $host; } // magic quotes may f**k up file uploads and chunked response processing $magicQuotes = ini_get('magic_quotes_runtime'); ini_set('magic_quotes_runtime', false); // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive // connection token to a proxy server... if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']) { $this->removeHeader('connection'); } $keepAlive = HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection']) || !empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']; $sockets =& PEAR::getStaticProperty('HTTP_Request', 'sockets'); $sockKey = $host . ':' . $port; unset($this->_sock); // There is a connected socket in the "static" property? if ($keepAlive && !empty($sockets[$sockKey]) && !empty($sockets[$sockKey]->fp)) { $this->_sock =& $sockets[$sockKey]; $err = null; } else { $this->_notify('connect'); $this->_sock = new Net_Socket(); $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); } PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); if (!PEAR::isError($err)) { if (!empty($this->_readTimeout)) { $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]); } $this->_notify('sentRequest'); // Read the response $this->_response = new HTTP_Response($this->_sock, $this->_listeners); $err = $this->_response->process($this->_saveBody && $saveBody, HTTP_REQUEST_METHOD_HEAD != $this->_method); if ($keepAlive) { $keepAlive = isset($this->_response->_headers['content-length']) || isset($this->_response->_headers['transfer-encoding']) && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked'; if ($keepAlive) { if (isset($this->_response->_headers['connection'])) { $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive'; } else { $keepAlive = 'HTTP/' . HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol; } } } } ini_set('magic_quotes_runtime', $magicQuotes); if (PEAR::isError($err)) { return $err; } if (!$keepAlive) { $this->disconnect(); // Store the connected socket in "static" property } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { $sockets[$sockKey] =& $this->_sock; } // Check for redirection if ($this->_allowRedirects and $this->_redirects <= $this->_maxRedirects and $this->getResponseCode() > 300 and $this->getResponseCode() < 399 and !empty($this->_response->_headers['location'])) { $redirect = $this->_response->_headers['location']; // Absolute URL if (preg_match('/^https?:\\/\\//i', $redirect)) { $this->_url = new Net_URL($redirect); $this->addHeader('Host', $this->_generateHostHeader()); // Absolute path } elseif ($redirect[0] == '/') { $this->_url->path = $redirect; // Relative path } elseif (substr($redirect, 0, 3) == '../' or substr($redirect, 0, 2) == './') { if (substr($this->_url->path, -1) == '/') { $redirect = $this->_url->path . $redirect; } else { $redirect = dirname($this->_url->path) . '/' . $redirect; } $redirect = Net_URL::resolvePath($redirect); $this->_url->path = $redirect; // Filename, no path } else { if (substr($this->_url->path, -1) == '/') { $redirect = $this->_url->path . $redirect; } else { $redirect = dirname($this->_url->path) . '/' . $redirect; } $this->_url->path = $redirect; } // handle cookes on redirect... if (!empty($this->_response->_cookies)) { foreach ($this->_response->_cookies as $c) { $this->_cookies[] = $c; } } if (isset($this->_requestHeaders['cookie'])) { unset($this->_requestHeaders['cookie']); } //print_r($this->_cookies); $cookies = array(); foreach ($this->_cookies as $c) { if (substr($this->_url->host, -1 * strlen($c['domain']) == $c['domain'])) { $cookies[$c['name']] = $c['value']; } } foreach ($cookies as $k => $v) { $this->addCookie($k, $v); } $this->_redirects++; return $this->sendRequest($saveBody); // Too many redirects } elseif ($this->_allowRedirects and $this->_redirects > $this->_maxRedirects) { return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS); } return true; }
/** * Sends the request * * @access public * @param bool Whether to store response body in Response object property, * set this to false if downloading a LARGE file and using a Listener * @return mixed PEAR error on error, true otherwise */ function sendRequest($saveBody = true) { if (!is_a($this->_url, 'Net_URL')) { return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL); } $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; // 4.3.0 supports SSL connections using OpenSSL. The function test determines // we running on at least 4.3.0 if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { if (isset($this->_proxy_host)) { return PEAR::raiseError('HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY); } $host = 'ssl://' . $host; } // magic quotes may f**k up file uploads and chunked response processing $magicQuotes = ini_get('magic_quotes_runtime'); ini_set('magic_quotes_runtime', false); // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive // connection token to a proxy server... if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']) { $this->removeHeader('connection'); } $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) || (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']); $sockets = &PEAR::getStaticProperty('HTTP_Request', 'sockets'); $sockKey = $host . ':' . $port; unset($this->_sock); // There is a connected socket in the "static" property? if ($keepAlive && !empty($sockets[$sockKey]) && !empty($sockets[$sockKey]->fp)) { $this->_sock =& $sockets[$sockKey]; $err = null; } else { $this->_notify('connect'); $this->_sock = new Net_Socket(); $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); } PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); if (!PEAR::isError($err)) { if (!empty($this->_readTimeout)) { $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]); } $this->_notify('sentRequest'); // Read the response $this->_response = new HTTP_Response($this->_sock, $this->_listeners); $err = $this->_response->process( $this->_saveBody && $saveBody, HTTP_REQUEST_METHOD_HEAD != $this->_method ); if ($keepAlive) { $keepAlive = (isset($this->_response->_headers['content-length']) || (isset($this->_response->_headers['transfer-encoding']) && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked')); if ($keepAlive) { if (isset($this->_response->_headers['connection'])) { $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive'; } else { $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol; } } } } ini_set('magic_quotes_runtime', $magicQuotes); if (PEAR::isError($err)) { return $err; } if (!$keepAlive) { $this->disconnect(); // Store the connected socket in "static" property } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { $sockets[$sockKey] =& $this->_sock; } // Check for redirection if ( $this->_allowRedirects AND $this->_redirects <= $this->_maxRedirects AND $this->getResponseCode() > 300 AND $this->getResponseCode() < 399 AND !empty($this->_response->_headers['location'])) { $redirect = $this->_response->_headers['location']; // Absolute URL if (preg_match('/^https?:\/\//i', $redirect)) { $this->_url = new Net_URL($redirect); $this->addHeader('Host', $this->_generateHostHeader()); // Absolute path } elseif ($redirect{0} == '/') { $this->_url->path = $redirect; // Relative path } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { if (substr($this->_url->path, -1) == '/') { $redirect = $this->_url->path . $redirect; } else { $redirect = dirname($this->_url->path) . '/' . $redirect; } $redirect = Net_URL::resolvePath($redirect); $this->_url->path = $redirect; // Filename, no path } else { if (substr($this->_url->path, -1) == '/') { $redirect = $this->_url->path . $redirect; } else { $redirect = dirname($this->_url->path) . '/' . $redirect; } $this->_url->path = $redirect; } $this->_redirects++; return $this->sendRequest($saveBody); // Too many redirects } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS); } return true; }
function sendCommand($address, $command, $port = 23) { if (empty($address)) { return; } $socket = new Net_Socket(); // open connection $respuesta = ''; if ($socket->connect("{$address}", $port, true, 1)) { $socket->writeLine($command); //usleep(1000000); sleep(1); $respuesta = trim($socket->read(200)); $socket->disconnect(); } return $respuesta; }
/** * Used to figure out which Sieve server the script will be run * on, and then open a GSSAPI authenticated socket to said server. * * @param string $username The username. * @param string $password The password. * @param string $hostspec The hostspec. * * @return TODO * @throws Ingo_Exception */ public function sivtestSocket($username, $password, $hostspec) { $command = ''; $error_return = ''; if (strtolower($this->_params['logintype']) == 'gssapi' && isset($_SERVER['KRB5CCNAME'])) { $command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME']; } $domain_socket = 'unix://' . $this->_params['socket']; $command .= ' ' . $this->_params['command'] . ' -m ' . $this->_params['logintype'] . ' -u ' . $username . ' -a ' . $username . ' -w ' . $password . ' -p ' . $this->_params['port'] . ' -X ' . $this->_params['socket'] . ' ' . $hostspec; $conn_attempts = 0; while ($conn_attempts++ < 4) { $attempts = 0; if (!file_exists($this->_params['socket'])) { exec($command . ' > /dev/null 2>&1'); sleep(1); while (!file_exists($this->_params['socket'])) { usleep(200000); if ($attempts++ > 5) { $error_return = ': No socket after 10 seconds of trying!'; continue 2; } } } $socket = new Net_Socket(); $error = $socket->connect($domain_socket, 0, true, 30); if (!$error instanceof PEAR_Error) { break; } // We failed, break this connection. unlink($this->_params['socket']); } if (!empty($error_return)) { throw new Ingo_Exception($error_return); } $status = $socket->getStatus(); if ($status instanceof PEAR_Error || $status['eof']) { throw new Ingo_Exception(_("Failed to write to socket: (connection lost!)")); } $error = $socket->writeLine("CAPABILITY"); if ($error instanceof PEAR_Error) { throw new Ingo_Exception(_("Failed to write to socket: " . $error->getMessage())); } $result = $socket->readLine(); if ($result instanceof PEAR_Error) { throw new Ingo_Exception(_("Failed to read from socket: " . $error->getMessage())); } if (preg_match('|^bye \\(referral "(sieve://)?([^"]+)|i', $result, $matches)) { $socket->disconnect(); $this->sivtestSocket($username, $password, $matches[2]); } else { $socket->disconnect(); exec($command . ' > /dev/null 2>&1'); sleep(1); } }
/** * Connects to a dict server and sets up a socket * * @param string $server * @param integer $port * @return mixed true on success, else PEAR_Error */ function connect($server = '', $port = 0) { $s = new Net_Socket(); if (empty($server)) { $server = $this->server; } if (0 == $port) { $port = $this->port; } $err = $s->connect($server, $port); if (PEAR::isError($err)) { return $err; } $banner = $s->readLine(); $resp['code'] = substr($banner, 0, 3); $resp['text'] = ltrim(substr($banner, 3)); if (!Net_Dict::isOK($resp)) { return new PEAR_Error($resp['text'], $resp['code']); } $reg = array(); preg_match("/\\d{3} (.*) <(.*)> <(.*)>/", $banner, $reg); $this->servinfo["signature"] = $reg[1]; $this->servinfo["capabilities"] = explode(".", $reg[2]); $this->servinfo["msg-id"] = $reg[3]; $this->_socket =& $s; return true; }