Beispiel #1
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;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 function disconnect()
 {
     if (is_a($this->socket, 'Net_Socket')) {
         $this->socket->disconnect();
     }
     $this->socket = null;
 }
Beispiel #4
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;
 }
Beispiel #5
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";
 }
Beispiel #6
0
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;
                    }
                }
            }
        }
    }
}
Beispiel #7
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;
 }
 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;
 }
Beispiel #9
0
 /**
  * Disconnect the socket, if connected. Only useful if using Keep-Alive.
  *
  * @access public
  */
 function disconnect()
 {
     if (!empty($this->_sock) && !empty($this->_sock->fp)) {
         $this->_notify('disconnect');
         $this->_sock->disconnect();
     }
 }
Beispiel #10
0
 /**
  * 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;
 }
Beispiel #11
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;
 }
Beispiel #12
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);
     }
 }
Beispiel #13
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;
 }
Beispiel #14
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;
 }