Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo 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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
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;
                    }
                }
            }
        }
    }
}
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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;
 }