Esempio n. 1
0
 /**
  * Send the given string of data to the server.
  *
  * @param string $data The string of data to send.
  *
  * @return mixed The number of bytes that were actually written,
  *               or a PEAR_Error object on failure.
  *
  * @since 1.1.0
  */
 protected function send($data)
 {
     $this->debug("Send: {$data}");
     $result = $this->socket->write($data);
     if (!$result || PEAR::isError($result)) {
         $msg = $result ? $result->getMessage() : "unknown error";
         return PEAR::raiseError("Failed to write to socket: {$msg}");
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data       The string of data to send.
  *
  * @return  mixed   True on success or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 function _send($data)
 {
     if ($this->_debug) {
         echo "DEBUG: Send: {$data}\n";
     }
     if (PEAR::isError($error = $this->_socket->write($data))) {
         return new PEAR_Error('Failed to write to socket: ' . $error->getMessage());
     }
     return true;
 }
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data    The string of data to send.
  *
  * @return  mixed   True on success or a PEAR_Error object on failure.
  *
  * @access  private
  * @since  1.0
  */
 function _send($data)
 {
     if ($this->_socket->eof()) {
         return new PEAR_Error('Failed to write to socket: (connection lost!) ');
     }
     if (PEAR::isError($error = $this->_socket->write($data))) {
         return new PEAR_Error('Failed to write to socket: ' . $error->getMessage());
     }
     if ($this->_debug) {
         // C: means this data was sent by  the client (this class)
         echo "C: " . date("H:i:s") . " " . htmlspecialchars($data) . "\n";
         $this->dbgDialog .= "C: {$data}";
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Send the given string of data to the server.
  *
  * @param string $data The string of data to send.
  *
  * @return mixed True on success or a PEAR_Error object on failure.
  *
  * @access private
  * @since 1.0
  */
 function _send($data)
 {
     if ($this->_socket->eof()) {
         return new PEAR_Error('Failed to write to socket: (connection lost!)');
     }
     if (PEAR::isError($error = $this->_socket->write($data))) {
         return new PEAR_Error('Failed to write to socket: ' . $error->getMessage());
     }
     if ($this->_debug) {
         // C: means this data was sent by  the client (this class)
         echo 'C: ' . $data;
         $this->dbgDialog .= 'C: ' . $data;
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Commmit session data
  * @param  callable $cb Callback
  * @return void
  */
 public function sessionCommit($cb = null)
 {
     if (!$this->sessionFp || $this->sessionFlushing) {
         if ($cb) {
             call_user_func($cb, false);
         }
         return;
     }
     $this->sessionFlushing = true;
     $data = $this->sessionEncode();
     $l = strlen($data);
     $cb = CallbackWrapper::wrap($cb);
     $this->sessionFp->write($data, function ($file, $result) use($l, $cb) {
         $file->truncate($l, function ($file, $result) use($cb) {
             $this->sessionFlushing = false;
             if ($cb) {
                 call_user_func($cb, true);
             }
         });
     });
 }
Esempio n. 6
0
 /**
  * Attempt to send the EHLO command and obtain a list of ESMTP
  * extensions available, and failing that just send HELO.
  *
  * @return mixed Returns a PEAR_Error with an error message on any
  *               kind of failure, or true on success.
  * @access private
  */
 function identifySender()
 {
     if (PEAR::isError($this->socket->write("EHLO {$this->localhost}\r\n"))) {
         return new PEAR_Error('write to socket failed');
     }
     $extensions = array();
     if (!$this->validateAndParseResponse('250', $extensions)) {
         if (PEAR::isError($this->socket->write("HELO {$this->localhost}\r\n"))) {
             return new PEAR_Error('write to socket failed');
         }
         if (!$this->validateResponse('250')) {
             return new PEAR_Error('HELO not accepted', $this->code);
         }
         return true;
     }
     for ($i = 0; $i < count($extensions); $i++) {
         $verb = strtok($extensions[$i], ' ');
         $arguments = substr($extensions[$i], strlen($verb) + 1, strlen($extensions[$i]) - strlen($verb) - 2);
         $this->esmtp[$verb] = $arguments;
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Sends a command to the server
  *
  * @param string $cmd The command to send.
  *
  * @return void
  */
 function _sendCmd($cmd)
 {
     $status = $this->_sock->getStatus();
     if (is_a($status, 'PEAR_Error') || $status['eof']) {
         return $this->_pear->raiseError('Failed to write to socket: connection lost');
     }
     $error = $this->_sock->write($cmd . "\r\n");
     if (is_a($error, 'PEAR_Error')) {
         return $this->_pear->raiseError('Failed to write to socket: ' . $error->getMessage());
     }
     $this->_debug("C: {$cmd}");
 }
Esempio n. 8
0
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data       The string of data to send.
  *
  * @return  mixed   The number of bytes that were actually written,
  *                  or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 function _send($data)
 {
     $this->_debug("Send: {$data}");
     $result = $this->_socket->write($data);
     if (!$result || PEAR::isError($result)) {
         $msg = $result ? $result->getMessage() : "unknown error";
         return PEAR::raiseError("Failed to write to socket: {$msg}", null, PEAR_ERROR_RETURN);
     }
     return $result;
 }
Esempio n. 9
0
 /**
  * Send the given string of data to the server.
  *
  * @param string $data  The string of data to send.
  *
  * @return integer  The number of bytes that were actually written.
  * @throws PEAR_Exception
  */
 protected function _send($data)
 {
     $this->_debug("Send: {$data}");
     $result = $this->_socket->write($data);
     if ($result === false) {
         return Net_SMTP::raiseError('Failed to write to socket: ' . $result->getMessage(), $result);
     }
     return $result;
 }
Esempio n. 10
0
 /**
  * Sends a command to the server
  *
  * @param string $cmd The command to send.
  *
  * @return void
  */
 function _sendCmd($cmd)
 {
     $status = $this->_sock->getStatus();
     if (PEAR::isError($status) || $status['eof']) {
         return PEAR::raiseError('Failed to write to socket: connection lost');
     }
     if (PEAR::isError($error = $this->_sock->write($cmd . "\r\n"))) {
         return PEAR::raiseError('Failed to write to socket: ' . $error->getMessage());
     }
     $this->_debug("C: {$cmd}");
 }
Esempio n. 11
0
File: SMTP.php Progetto: roojs/pear
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data       The string of data to send.
  *
  * @return  mixed   The number of bytes that were actually written,
  *                  or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 function _send($data)
 {
     $this->_debug("Send: {$data}");
     $result = $this->_socket->write($data);
     if (!$result || PEAR::isError($result)) {
         $msg = $result ? $result->getMessage() : "unknown error";
         $p = new PEAR();
         return $p->raiseError("Failed to write to socket: {$msg}", null, PEAR_ERROR_RETURN);
     }
     // we have to set timeout, so it works..
     //$this->setTimeout($this->_timeout);
     return $result;
 }
Esempio n. 12
0
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data       The string of data to send.
  *
  * @return  mixed   True on success or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 function _send($data)
 {
     $this->_debug("Send: {$data}");
     if (PEAR::isError($error = $this->_socket->write($data))) {
         return PEAR::raiseError('Failed to write to socket: ' . $error->getMessage());
     }
     return true;
 }
Esempio n. 13
0
 /**
  * Private method for sending data to SMTP connection
  *
  * @param string $data data to be sent to SMTP server
  * @param mixed $checkCode code to check for in server response, false to skip
  * @return bool Success
  * @access private
  */
 function __smtpSend($data, $checkCode = '250')
 {
     if (!is_null($data)) {
         $this->__smtpConnection->write($data . "\r\n");
     }
     if ($checkCode !== false) {
         $response = $this->__smtpConnection->read();
         if (!preg_match('/^' . $checkCode . '/', $response)) {
             $this->smtpError = $response;
             return false;
         }
     }
     return true;
 }
Esempio n. 14
0
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data       The string of data to send.
  *
  * @return  mixed   True on success or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 function _send($data)
 {
     $this->_debug("Send: {$data}");
     $error = $this->_socket->write($data);
     if ($error === false || PEAR::isError($error)) {
         $msg = $error ? $error->getMessage() : "unknown error";
         return PEAR::raiseError("Failed to write to socket: {$msg}");
     }
     return true;
 }
Esempio n. 15
0
 /**
  * Send the given string of data to the server.
  *
  * @param   string  $data	   The string of data to send.
  *
  * @return  mixed   True on success or a PEAR_Error object on failure.
  *
  * @access  private
  * @since   1.1.0
  */
 private function _send($data)
 {
     if ($this->_debug) {
         echo "DEBUG: Send: {$data}\n";
     }
     if (Error::is_error($error = $this->_socket->write($data))) {
         throw Error::raise('Failed to write to socket: ' . $error->getMessage());
     }
     return true;
 }
Esempio n. 16
0
 /**
  * Send the given string of data to the server.
  *
  * @param string $data  The string of data to send.
  *
  * @return integer  The number of bytes that were actually written.
  * @throws PEAR_Exception
  */
 protected function _send($data)
 {
     $this->_debug("Send: {$data}");
     $result = $this->_socket->write($data);
     if (!$result) {
         throw new PEAR_Exception('Failed to write to socket: unknown error');
     }
     return $result;
 }
Esempio n. 17
0
 /**
  * User self update method
  *
  * @access public
  * @param mixed $post //posted user details
  * @return void
  */
 public function self_update($post)
 {
     # set items to update
     $items = array("real_name" => $post['real_name'], "mailNotify" => $post['mailNotify'], "mailChangelog" => $post['mailChangelog'], "email" => $post['email'], "lang" => $post['lang'], "id" => $this->user->id, "compressOverride" => $post['compressOverride'], "hideFreeRange" => $this->verify_checkbox(@$post['hideFreeRange']), "printLimit" => @$post['printLimit'], "menuType" => $post['menuType']);
     if (strlen($post['password1']) > 0) {
         $items['password'] = $this->crypt_user_pass($post['password1']);
     }
     # prepare log file
     $log = $this->array_to_log($post);
     # update
     try {
         $this->Database->updateObject("users", $items);
     } catch (Exception $e) {
         $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
         $this->Log->write("User self update", "User self update failed!<br>" . $log, 2);
         return false;
     }
     # update language
     $this->update_session_language();
     # ok, update log table
     $this->Log->write("User self update", "User self update suceeded!", 0);
     return true;
 }
Esempio n. 18
0
 /**
  * Removes all PTR records for subnet
  *
  * @access public
  * @param mixed $domain_id
  * @param mixed $indexes (array of PTR indexes)
  * @return bool
  */
 public function remove_all_ptr_records($domain_id, $indexes = array())
 {
     // if false return ok and dont execute
     if (sizeof($indexes) == 0 || !is_array($indexes)) {
         return true;
     }
     // set parameters - default
     $params = array($domain_id);
     // set query - start
     $query = "delete from `records` where `domain_id` = ? and `type` = 'PTR'";
     // loop
     if (sizeof($indexes) > 0) {
         $q_tmp = array();
         $query .= " and (";
         foreach ($indexes as $i) {
             $q_tmp[] = " `id` = ? ";
             $params[] = $i;
         }
         // add to query
         $query .= implode(" or ", $q_tmp);
         $query .= ");";
     }
     // execute
     try {
         $this->Database_pdns->runQuery($query, $params);
     } catch (Exception $e) {
         // write log
         $this->Log->write("PowerDNS records delete", "Failed to delete all PowerDNS domain PTR records: " . $e->getMessage() . "<hr>" . $this->array_to_log((array) $domain_id), 2);
         $this->Result->show("danger", _("Error: ") . $e->getMessage());
         return false;
     }
     // write log
     $this->Log->write("PowerDNS records delete", "All PTR records for PowerDNS removed<hr>" . $this->array_to_log((array) $domain_id), 0);
     # ok
     return true;
 }
Esempio n. 19
0
 /**
  * Sends raw data over this connection's socket
  *
  * @param string $message the data to send.
  *
  * @return void
  */
 protected function send($message)
 {
     $this->socket->write($message);
 }
 /**
  * Post an article to a newsgroup.
  *
  * Among the aditional headers you might think of adding could be:
  * "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
  * of the author of the post, so the message can be traced back to him.
  * "Organization: <org>" which contain the name of the organization
  * the post originates from.
  *
  * @param string $newsgroup The newsgroup to post to.
  * @param string $subject The subject of the post.
  * @param string $body The body of the post itself.
  * @param string $from Name + email-adress of sender.
  * @param optional string $aditional Aditional headers to send.
  *
  * @return mixed (bool) true on success or (object) pear_error on failure
  * @access public
  */
 function cmdPost($newsgroup, $subject, $body, $from, $aditional = '')
 {
     // tell the newsserver we want to post an article
     $response = $this->_sendCommand('POST');
     if (PEAR::isError($response)) {
         return $response;
     }
     if ($response == 340) {
         // RFC977: 'send article to be posted. End with <CR-LF>.<CR-LF>'
         // should be presented in the format specified by RFC850
         $this->_socket->write("Newsgroups: {$newsgroup}\r\n");
         $this->_socket->write("Subject: {$subject}\r\n");
         $this->_socket->write("From: {$from}\r\n");
         $this->_socket->write("X-poster: PEAR::Net_NNTP\r\n");
         $this->_socket->write("{$aditional}\r\n");
         $this->_socket->write("\r\n");
         $this->_socket->write("{$body}\r\n");
         $this->_socket->write(".\r\n");
         // Retrive server's response.
         $response = $this->_getStatusResponse();
         if (PEAR::isError($response)) {
             return $response;
         }
     }
     switch ($response) {
         case 240:
             // RFC977: 'article posted ok'
             return true;
             break;
         case 340:
             // RFC977: 'send article to be posted. End with <CR-LF>.<CR-LF>'
             // This should not happen here!
             return PEAR::throwError('Unknown error during post', $response, $this->currentStatusResponse());
             break;
         case 440:
             // RFC977: 'posting not allowed'
             return PEAR::throwError('Posting not allowed', $response, $this->currentStatusResponse());
             break;
         case 441:
             // RFC977: 'posting failed'
             return PEAR::throwError('Posting failed', $response, $this->currentStatusResponse());
             break;
         default:
             return PEAR::throwError('Unidentified response code', $response, $this->currentStatusResponse());
     }
 }
Esempio n. 21
0
 /**
  * Protected method for sending data to SMTP connection
  *
  * @param string $data data to be sent to SMTP server
  * @param mixed $checkCode code to check for in server response, false to skip
  * @return bool Success
  * @access protected
  */
 function _smtpSend($data, $checkCode = '250')
 {
     if (!is_null($data)) {
         $this->__smtpConnection->write($data . "\r\n");
     }
     while ($checkCode !== false) {
         $response = '';
         $startTime = time();
         while (substr($response, -2) !== "\r\n" && time() - $startTime < $this->smtpOptions['timeout']) {
             $response .= $this->__smtpConnection->read();
         }
         if (substr($response, -2) !== "\r\n") {
             $this->smtpError = 'timeout';
             return false;
         }
         $response = end(explode("\r\n", rtrim($response, "\r\n")));
         if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
             if ($code[2] === '-') {
                 continue;
             }
             return $code[1];
         }
         $this->smtpError = $response;
         return false;
     }
     return true;
 }
Esempio n. 22
0
 /**
  * Private method for sending data to SMTP connection
  *
  * @param string $data data to be sent to SMTP server
  * @param mixed $checkCode code to check for in server response, false to skip
  * @return bool Success
  * @access private
  */
 function __smtpSend($data, $checkCode = '250')
 {
     if (!is_null($data)) {
         $this->__smtpConnection->write($data . "\r\n");
     }
     if ($checkCode !== false) {
         $response = '';
         while ($str = $this->__smtpConnection->read()) {
             $response .= $str;
             if ($str[3] == ' ') {
                 break;
             }
         }
         if (stristr($response, $checkCode) === false) {
             $this->smtpError = $response;
             return false;
         }
     }
     return true;
 }