diff --git a/e107_handlers/admin_log_class.php b/e107_handlers/admin_log_class.php index 82aeef610..4b89bbe91 100644 --- a/e107_handlers/admin_log_class.php +++ b/e107_handlers/admin_log_class.php @@ -640,7 +640,7 @@ class e_admin_log /** * Save Message stack to File. */ - private function saveToFile($logTitle='') + private function saveToFile($logTitle='', $append=false) { if($this->logFile == null) { @@ -664,10 +664,20 @@ class e_admin_log $text .= date('Y-m-d H:i:s',$m['time'])." \t".str_pad($m['dislevel'],10," ",STR_PAD_RIGHT)."\t".strip_tags($m['message'])."\n"; } - $date = date('Y-m-d_H-i-s'); + $date = ($append == true) ? date('Y-m-d') : date('Y-m-d_H-i-s').'_'.crc32($text); + $fileName = e_LOG.$date."_".$this->logFile.".log"; - if(file_put_contents($fileName,$text)) + if($append == true) + { + $app = FILE_APPEND; + } + else + { + $app = null; + } + + if(file_put_contents($fileName, $text, $app)) { $this->_allMessages = array(); return $this->logFile; @@ -680,17 +690,17 @@ class e_admin_log /** - * Set and enable logging to a file. - * Must be set PRIOR to flushMessages(). (which saves the results) - * @param name without the extension. (ie. data prefix and .log suffix will be added automatically) + * Set and save accumulated log to a file. + * Use addDebug(), addError() or addSuccess() prior to executing. + * @param string name without the extension. (ie. date prefix and .log suffix will be added automatically) + * @param string Title for use inside the Log file + * @param boolean true = append to file, false = new file each save. */ - public function toFile($name,$logTitle='') + public function toFile($name,$logTitle='',$append=false) { - - - + $this->logFile = $name; - $this->saveToFile($logTitle); + $this->saveToFile($logTitle,$append); $this->logFile = null; } diff --git a/e107_handlers/session_handler.php b/e107_handlers/session_handler.php index 7604a9413..a490587c6 100644 --- a/e107_handlers/session_handler.php +++ b/e107_handlers/session_handler.php @@ -839,7 +839,8 @@ class e_core_session extends e_session || (isset($_GET['e-token']) && !$this->checkFormToken($_GET['e-token']))) { if(defsettrue('e_DEBUG')) - { + { + $details = "USER: ".USERNAME."\n"; $details = "HOST: ".$_SERVER['HTTP_HOST']."\n"; $details .= "REQUEST_URI: ".$_SERVER['REQUEST_URI']."\n"; $details .= "e-token (POST): ".$_POST['e-token']."\n"; @@ -852,8 +853,12 @@ class e_core_session extends e_session // $details .= print_r($_GET,true); $details .= "\nPlugins:\n"; $details .= print_r($pref['plug_installed'],true); - - e107::getAdminLog()->log_event('Unauthorized access!', $details, E_LOG_FATAL); + + $log = e107::getAdminLog(); + $log->addDebug($details); + $log->toFile('Unauthorized_access','Unauthorized access Log', true); + $log->add('Unauthorized access!', $details, E_LOG_FATAL); + // e107::getAdminLog()->log_event('Unauthorized access!', $details, E_LOG_FATAL); } // do not redirect, prevent dead loop, save server resources if($die) die('Unauthorized access!');