X-Git-Url: http://git.datanom.net/qtadmin.git/blobdiff_plain/630144db19b9199b775902148309c90502d34f78..5ec97892b8d65ffdff8eef18495632e1c2c7c22e:/lib/session_handler.inc.php?ds=sidebyside diff --git a/lib/session_handler.inc.php b/lib/session_handler.inc.php index bd3a771..09f015e 100644 --- a/lib/session_handler.inc.php +++ b/lib/session_handler.inc.php @@ -1,8 +1,72 @@ root .'config.php'; + class FileSessionHandler { private $savePath; + private $log_level; + private $log_method; + + public function __construct() { + global $CFG; + + if (isset($CFG->log_level)) { + $this->log_level = $CFG->log_level; + } else { + $this->log_level = 1; + } + + if (isset($CFG->log_method)) { + $this->log_method = $CFG->log_method; + } else { + $this->log_level = 'syslog'; + } + + $this->log("Init FileSessionHandler", 4); + + } - function open($savePath, $sessionName) { + private function log($message, $level = 1) { + global $CFG; + + if ($level > $this->log_level) + return; + + $time = date('c'); + + $priority = LOG_INFO; + switch ($level) { + case 1: $priority = LOG_ERR; break; + case 2: $priority = LOG_WARNING; break; + case 3: $priority = LOG_INFO; break; + case 4: $priority = LOG_DEBUG; break; + } + + switch ($this->log_method) { + case 'file': + if (isset($CFG->log_file)) { + if ($CFG->log_file[0] == '/') { + $file = $CFG->log_file; + } else { + $file = $CFG->root.$CFG->log_file; + } + } else { + $file = $CFG->root.'qtadmin.log'; + } + file_put_contents($file, "[$time]: $message\n", FILE_APPEND | LOCK_EX); + chmod($file, 0600); + break; + case 'stderr': + file_put_contents('php://stderr', "[$time]: $message\n"); + break; + case 'syslog': + syslog($priority, $message); + break; + } + } + + public function open($savePath, $sessionName) { + $this->log("FileSessionHandler->open", 4); $this->savePath = $savePath; if (!is_dir($this->savePath)) { mkdir($this->savePath, 0777); @@ -12,6 +76,7 @@ class FileSessionHandler { } function close() { + $this->log("FileSessionHandler->close", 4); return true; } @@ -20,10 +85,15 @@ class FileSessionHandler { } function write($id, $data) { - return file_put_contents("$this->savePath/qt_sess_$id", $data) === false ? false : true; + $this->log("FileSessionHandler->write : $id->$data", 4); + $result = file_put_contents("$this->savePath/qt_sess_$id", $data); + chmod("$this->savePath/qt_sess_$id", 0600); + + return ($result === false) ? false : true; } function destroy($id) { + $this->log("FileSessionHandler->destroy : $id", 4); $file = "$this->savePath/qt_sess_$id"; if (file_exists($file)) { unlink($file); @@ -33,6 +103,7 @@ class FileSessionHandler { } function gc($maxlifetime) { + $this->log("FileSessionHandler->gc : $maxlifetime", 4); foreach (glob("$this->savePath/qt_sess_*") as $file) { if (filemtime($file) + $maxlifetime < time() && file_exists($file)) { unlink($file);