Index: branches/5.2.x/core/units/helpers/curl_helper.php =================================================================== diff -u -N -r14585 -r14671 --- branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 14671) @@ -1,6 +1,6 @@ responceHeaders[] = $header; + $this->responseHeaders[] = $header; return strlen($header); } @@ -323,47 +326,61 @@ * * @param string $url * @param bool $close_connection + * @param bool $log_status + * @param string $log_message * @return string * @access public */ - public function Send($url, $close_connection = true, $log_status = null) + public function Send($url, $close_connection = true, $log_status = null, $log_message = '') { - if (isset($log_status)) { + if ( isset($log_status) ) { // override debug mode setting $this->debugMode = $log_status; } - if (($this->requestMethod == self::REQUEST_METHOD_GET) && $this->requestData) { - // add query to url - $url .= (strpos($url, '?') !== false ? '&' : '?') . $this->requestData; - } - $this->connectionID = curl_init($url); - if ($this->debugMode) { - kUtil::safeDefine('DBG_CURL_LOGFILE', '/curl.log'); - $this->logFilePointer = fopen((defined('RESTRICTED') ? RESTRICTED : FULL_PATH) . DBG_CURL_LOGFILE, 'a'); + if ( $this->debugMode ) { + // collect page data + $page_data = Array (); - $user_id = $this->Application->RecallVar('user_id'); - $data = $_SERVER['REMOTE_ADDR'] . ' - ['.adodb_date('D M d H:i:s Y').'] ' . $_SERVER['REQUEST_URI'] . '; user_id: '.$user_id.'; sid: '.$this->Application->GetSID(); - fwrite($this->logFilePointer, "\n\n" . str_repeat('=', strlen($data)) . "\n"); - fwrite($this->logFilePointer, $data); - fwrite($this->logFilePointer, "\n" . str_repeat('=', strlen($data)) . "\n"); + if ( $_GET ) { + $page_data[] = '_GET:' . "\n" . print_r($_GET, true); + } - curl_setopt($this->connectionID, CURLOPT_FILE, $this->logFilePointer); - curl_setopt($this->connectionID, CURLOPT_VERBOSE, true); - curl_setopt($this->connectionID, CURLOPT_STDERR, $this->logFilePointer); - //curl_setopt($this->connectionID, CURLOPT_WRITEHEADER, $this->logFilePointer); + if ( $_POST ) { + $page_data[] = '_POST:' . "\n" . print_r($_POST, true); + } + + if ( $_COOKIE ) { + $page_data[] = '_COOKIE:' . "\n" . print_r($_COOKIE, true); + } + + // create log record + $fields_hash = Array ( + 'Message' => $log_message, + 'PageUrl' => $_SERVER['REQUEST_URI'], + 'RequestUrl' => $url, + 'PortalUserId' => $this->Application->RecallVar('user_id'), + 'SessionKey' => $this->Application->GetSID(), + 'IsAdmin' => $this->Application->isAdminUser ? 1 : 0, + 'PageData' => implode("\n", $page_data), + 'RequestData' => $this->requestData, + 'RequestDate' => adodb_mktime(), + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'CurlLog'); + $this->logId = $this->Conn->getInsertID(); } - $this->responceHeaders = Array (); + $this->responseHeaders = Array (); $this->prepareOptions(); - $this->lastRespoce = curl_exec($this->connectionID); + $this->lastResponse = curl_exec($this->connectionID); $this->Finalize($close_connection); - return $this->lastRespoce; + return $this->lastResponse; } /** @@ -383,15 +400,17 @@ /** * Finalizes curl request and saves some data from curl before closing connection * - * @param int $close_connection + * @param bool $close_connection + * @return void + * @access public */ public function Finalize($close_connection = true) { $this->lastErrorCode = curl_errno($this->connectionID); $this->lastErrorMsg = curl_error($this->connectionID); $this->lastHTTPCode = curl_getinfo($this->connectionID, CURLINFO_HTTP_CODE); - if ($close_connection) { + if ( $close_connection ) { $this->CloseConnection(); } @@ -407,20 +426,30 @@ { curl_close($this->connectionID); - if ($this->debugMode) { - // only close log after curl resource has been terminated - fwrite($this->logFilePointer, "\n" . 'LastHTTPCode: ' . $this->lastHTTPCode . '; LastError: #' . $this->lastErrorCode . ' (' . $this->lastErrorMsg . ')' . "\n"); - fwrite($this->logFilePointer, 'Respoce:' . "\n" . $this->lastRespoce); - fclose($this->logFilePointer); + if ( $this->debugMode ) { + $fields_hash = Array ( + 'ResponseData' => $this->lastResponse, + 'ResponseDate' => adodb_mktime(), + 'ResponseHttpCode' => $this->lastHTTPCode, + 'CurlError' => $this->lastErrorCode != 0 ? '#' . $this->lastErrorCode . ' (' . $this->lastErrorMsg . ')' : '', + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'CurlLog', 'LogId = ' . $this->logId); } // restore debug mode setting $this->debugMode = kUtil::constOn('DBG_CURL'); } - - function isGoodResponceCode() + + /** + * Checks, that last curl request was successful + * + * @return bool + * @access public + */ + public function isGoodResponseCode() { - if ($this->lastErrorCode != 0) { + if ( $this->lastErrorCode != 0 ) { return false; }