Index: install/install_schema.sql =================================================================== --- install/install_schema.sql (revision 14656) +++ install/install_schema.sql (working copy) @@ -1197,4 +1197,32 @@ KEY ExternalUrl (ExternalUrl), KEY RedirectOnIPMatch (RedirectOnIPMatch), KEY Priority (Priority) +); + +CREATE TABLE CurlLog ( + LogId int(11) NOT NULL AUTO_INCREMENT, + Message varchar(255) NOT NULL, + PageUrl varchar(255) NOT NULL, + RequestUrl varchar(255) NOT NULL, + PortalUserId int(11) NOT NULL, + SessionKey int(11) NOT NULL, + IsAdmin tinyint(4) NOT NULL, + PageData text, + RequestData text, + ResponseData text, + RequestDate int(11) DEFAULT NULL, + ResponseDate int(11) DEFAULT NULL, + ResponseHttpCode int(11) NOT NULL, + CurlError varchar(255) NOT NULL, + PRIMARY KEY (LogId), + KEY Message (Message), + KEY PageUrl (PageUrl), + KEY RequestUrl (RequestUrl), + KEY PortalUserId (PortalUserId), + KEY SessionKey (SessionKey), + KEY IsAdmin (IsAdmin), + KEY RequestDate (RequestDate), + KEY ResponseDate (ResponseDate), + KEY ResponseHttpCode (ResponseHttpCode), + KEY CurlError (CurlError) ); \ No newline at end of file Index: install/upgrades.sql =================================================================== --- install/upgrades.sql (revision 14656) +++ install/upgrades.sql (working copy) @@ -2146,3 +2146,31 @@ ALTER TABLE ItemReview ADD HelpfulCount INT NOT NULL , ADD NotHelpfulCount INT NOT NULL; + +CREATE TABLE CurlLog ( + LogId int(11) NOT NULL AUTO_INCREMENT, + Message varchar(255) NOT NULL, + PageUrl varchar(255) NOT NULL, + RequestUrl varchar(255) NOT NULL, + PortalUserId int(11) NOT NULL, + SessionKey int(11) NOT NULL, + IsAdmin tinyint(4) NOT NULL, + PageData text, + RequestData text, + ResponseData text, + RequestDate int(11) DEFAULT NULL, + ResponseDate int(11) DEFAULT NULL, + ResponseHttpCode int(11) NOT NULL, + CurlError varchar(255) NOT NULL, + PRIMARY KEY (LogId), + KEY Message (Message), + KEY PageUrl (PageUrl), + KEY RequestUrl (RequestUrl), + KEY PortalUserId (PortalUserId), + KEY SessionKey (SessionKey), + KEY IsAdmin (IsAdmin), + KEY RequestDate (RequestDate), + KEY ResponseDate (ResponseDate), + KEY ResponseHttpCode (ResponseHttpCode), + KEY CurlError (CurlError) +); \ No newline at end of file Index: units/helpers/curl_helper.php =================================================================== --- units/helpers/curl_helper.php (revision 14656) +++ units/helpers/curl_helper.php (working copy) @@ -16,6 +16,8 @@ class kCurlHelper extends kHelper { + var $logId = 0; + const REQUEST_METHOD_GET = 1; const REQUEST_METHOD_POST = 2; @@ -29,14 +31,6 @@ protected $connectionID = null; /** - * Pointer to opened log file - * - * @var resource - * @access protected - */ - protected $logFilePointer = null; - - /** * Responce waiting timeout in seconds * * @var int @@ -326,34 +320,47 @@ * @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)) { // 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'); + // 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->postData, + 'RequestDate' => adodb_mktime(), + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'CurlLog'); + $this->logId = $this->Conn->getInsertID(); } $this->responceHeaders = Array (); @@ -403,21 +410,26 @@ * * @access public */ + public function CloseConnection() { 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); + $fields_hash = Array ( + 'ResponseData' => $this->lastRespoce, + '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() { if ($this->lastErrorCode != 0) {