<?php
+/* vim: set ts=4 tw=0 sw=4 noet: */
+require_once $CFG->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);
}
function close() {
+ $this->log("FileSessionHandler->close", 4);
return true;
}
}
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);
}
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);