Esempio n. 1
0
 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";
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * リソースリクエスト送信
  *
  * @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;
 }
Esempio n. 4
0
/**
 * vpopmail Password Driver
 *
 * Driver to change passwords via vpopmaild
 *
 * @version 1.0
 * @author Johannes Hessellund
 *
 */
function password_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;
    } else {
        $result = $vpopmaild->readLine();
        if (!preg_match('/^\\+OK/', $result)) {
            $vpopmaild->disconnect();
            return PASSWORD_CONNECT_ERROR;
        } else {
            $vpopmaild->writeLine("slogin " . $_SESSION['username'] . " " . $curpass);
            $result = $vpopmaild->readLine();
            if (!preg_match('/^\\+OK/', $result)) {
                $vpopmaild->writeLine("quit");
                $vpopmaild->disconnect();
                return PASSWORD_ERROR;
            } else {
                $vpopmaild->writeLine("mod_user " . $_SESSION['username']);
                $result = $vpopmaild->readLine();
                if (!preg_match('/^\\+OK/', $result)) {
                    $vpopmaild->writeLine("quit");
                    $vpopmaild->disconnect();
                    return PASSWORD_ERROR;
                } else {
                    $vpopmaild->writeLine("clear_text_password " . $passwd);
                    $vpopmaild->writeLine(".");
                    $result = $vpopmaild->readLine();
                    $vpopmaild->writeLine("quit");
                    $vpopmaild->disconnect();
                    if (!preg_match('/^\\+OK/', $result)) {
                        return PASSWORD_ERROR;
                    } else {
                        return PASSWORD_SUCCESS;
                    }
                }
            }
        }
    }
}
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 /**
  *
  * 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());
         }
     }
 }
Esempio n. 7
0
File: Whois.php Progetto: roojs/pear
 /**
  * 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;
 }
 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;
 }
Esempio n. 10
0
 /**
  * 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);
     }
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
 /**
  * @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;
 }
Esempio n. 13
0
 /**
  * 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;
 }
Esempio n. 14
0
 /** 
  * 
  * 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;
 }
Esempio n. 15
0
/**
 * Poppassd Password Driver
 *
 * Driver to change passwords via Poppassd/Courierpassd
 *
 * @version 1.0
 * @author Philip Weir
 *
 */
function password_save($curpass, $passwd)
{
    $rcmail = rcmail::get_instance();
    //    include('Net/Socket.php');
    $poppassd = new Net_Socket();
    if (PEAR::isError($poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null))) {
        return PASSWORD_CONNECT_ERROR;
    } else {
        $result = $poppassd->readLine();
        if (!preg_match('/^2\\d\\d/', $result)) {
            $poppassd->disconnect();
            return PASSWORD_ERROR;
        } else {
            $poppassd->writeLine("user " . $_SESSION['username']);
            $result = $poppassd->readLine();
            if (!preg_match('/^[23]\\d\\d/', $result)) {
                $poppassd->disconnect();
                return PASSWORD_CONNECT_ERROR;
            } else {
                $poppassd->writeLine("pass " . $curpass);
                $result = $poppassd->readLine();
                if (!preg_match('/^[23]\\d\\d/', $result)) {
                    $poppassd->disconnect();
                    return PASSWORD_ERROR;
                } else {
                    $poppassd->writeLine("newpass " . $passwd);
                    $result = $poppassd->readLine();
                    $poppassd->disconnect();
                    if (!preg_match('/^2\\d\\d/', $result)) {
                        return PASSWORD_ERROR;
                    } else {
                        return PASSWORD_SUCCESS;
                    }
                }
            }
        }
    }
}
Esempio n. 16
0
 /**
  * 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;
 }
Esempio n. 17
0
 /**
  * Read a part of response body encoded with chunked Transfer-Encoding
  * 
  * @access private
  * @return string
  */
  function _readChunked()
  {
      // at start of the next chunk?
      if (0 == $this->_chunkLength) {
          $line = $this->_sock->readLine();
          if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
              $this->_chunkLength = hexdec($matches[1]); 
              // Chunk with zero length indicates the end
              if (0 == $this->_chunkLength) {
                  $this->_sock->readLine(); // make this an eof()
                  return '';
              }
          } else {
              return '';
          }
      }
      $data = $this->_sock->read($this->_chunkLength);
      $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
      if (0 == $this->_chunkLength) {
          $this->_sock->readLine(); // Trailing CRLF
      }
      return $data;
  }
Esempio n. 18
0
 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;
 }
Esempio n. 19
0
 /**
  * Send a command to the IMAP server and retrieve
  * the response
  *
  * @param string $command The command to send
  *
  * @param string $data    If we are issuing a command
  *                        that means the server will
  *                        consequently expect literal
  *                        data sent then this is that data.
  *
  * @return mixed          Server response string on success
  *                        or bool false on error
  */
 function sendCmd($command, $data = null, $fh = false)
 {
     if (!is_resource($this->socket->fp)) {
         $this->lastError = IC_NOT_CONNECTED;
         return false;
     }
     if (feof($this->socket->fp)) {
         $this->lastError = IC_NOT_CONNECTED;
         return false;
     }
     $cid = $this->cid;
     $this->socket->writeLine("{$this->cid} {$command}");
     $this->cid++;
     if ($this->debug) {
         $this->debugOutput("C: {$cid} {$command}\n");
     }
     $resp = '';
     $loop = 0;
     $lines = 0;
     $bytesRead = 0;
     $respSize = 0;
     $code = '';
     $fetch = substr($command, 0, 5) == 'FETCH';
     $select = substr($command, 0, 6) == 'SELECT';
     while (true) {
         // Check we are still connected
         if (!is_resource($this->socket->fp)) {
             return $resp;
         }
         if (feof($this->socket->fp)) {
             $this->lastError = IC_NOT_CONNECTED;
             return false;
         }
         $line = $this->socket->gets(8192);
         // 8192 same buffer used in Pear Net::POP3
         if ($this->debug) {
             $this->debugOutput("S: {$line}");
         }
         if (preg_match("/^{$cid} (OK|BAD|NO)/", $line, $m)) {
             $code = $m[1];
         } elseif (!$fetch && !$select && preg_match("/^\\* (BAD|NO|BYE)/", $line, $m)) {
             $code = $m[1];
         }
         // UW-IMAP been brain dead for 'status' command on a mailbox
         if ($code == 'NO' && preg_match("/NO CLIENT BUG DETECTED/", $line)) {
             $code = '';
             continue;
         } else {
             if ($code == 'BAD' || $code == 'NO' || $code == 'BYE') {
                 return false;
             } else {
                 if ($code == 'OK') {
                     return !empty($resp) ? $resp : $line;
                 }
             }
         }
         $lines++;
         // If writing to the filehandle, get msg size and skip the first line response from the IMAP server
         if (is_resource($fh) && preg_match('/^\\* /', $line) && $lines == '1') {
             preg_match('/\\{(\\d+)\\}/', $line, $m);
             $respSize = $m[1];
             continue;
         }
         // Check if we are sending literal data
         // and server is ready for literal data
         if ($data && preg_match('/^\\+/', $line)) {
             $size = $this->socket->write($data);
             if ($this->debug) {
                 $this->debugOutput("C: {$cid} {$data}\n");
             }
             sleep(1);
             $this->socket->write("\r\n");
             continue;
         }
         // Double check that we are not hung on a
         // command (ie not enough data sent)
         if ($data && $line == '') {
             // Send some new lines to try and
             // reach expected bytes
             $this->socket->writeLine('');
             if ($this->debug) {
                 $this->debugOutput("C: {$cid} \n");
             }
         }
         // Replace/fix - Under cyrus, multiple IMAP logins, mailbox locks, sockets are closed automatically
         if ($line == '' && $loop > 1000) {
             return $resp;
         } else {
             if ($line == '') {
                 $loop++;
             }
         }
         // Print to the filehandle only up to $respSize bytes so we do not append the last IMAP header on the message
         if ($stop) {
             continue;
         } elseif (is_resource($fh)) {
             $bytesRead += strlen($line);
             // Strip Control-M chars
             $line = preg_replace('/\\cM+$/', '', $line);
             fwrite($fh, $line);
             // Only read up to expected byte size
             if ($bytesRead == $respSize) {
                 $stop = true;
             }
         } else {
             $resp .= "{$line}";
         }
     }
 }
Esempio n. 20
0
 /**
  * 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;
 }