From aa5a8bdd33fe857a1ebf53cd8630a4a73a36fdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Mon, 30 Aug 2021 10:56:52 +0800 Subject: [PATCH] * adjust for add tid for session. --- config/filter.php | 1 + framework/base/helper.class.php | 21 +++- framework/base/router.class.php | 122 ++++++++++++++++++++++++ lib/base/front/front.class.php | 2 + module/common/view/header.lite.html.php | 1 - module/user/control.php | 8 +- 6 files changed, 147 insertions(+), 8 deletions(-) diff --git a/config/filter.php b/config/filter.php index 46681c79d7..919313f523 100644 --- a/config/filter.php +++ b/config/filter.php @@ -20,6 +20,7 @@ $filter->default->paramName = 'reg::paramName'; $filter->default->paramValue = 'reg::paramValue'; $filter->default->get['onlybody'] = 'equal::yes'; +$filter->default->get['tid'] = 'reg::word'; $filter->default->get['HTTP_X_REQUESTED_WITH'] = 'equal::XMLHttpRequest'; $filter->default->cookie['lang'] = 'reg::lang'; diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index 1f39f5ec90..33141d1ab7 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -160,9 +160,12 @@ class baseHelper public static function processOnlyBodyParam($link, $onlyBody = false) { global $config; - if(!$onlyBody and !self::inOnlyBodyMode()) return $link; - $onlybodyString = strpos($link, '?') === false ? "?onlybody=yes" : "&onlybody=yes"; - return $link . $onlybodyString; + + $sign = strpos($link, '?') === false ? "?" : "&"; + $appendString = ''; + if($onlyBody or self::inOnlyBodyMode()) $appendString = $sign . "onlybody=yes"; + if(self::isWithTID()) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}"; + return $link . $appendString; } /** @@ -177,6 +180,18 @@ class baseHelper return (isset($_GET['onlybody']) and $_GET['onlybody'] == 'yes'); } + /** + * Is with tid. + * + * @static + * @access public + * @return bool + */ + public static function isWithTID() + { + return (!empty($config->tabSession) and isset($_GET['tid'])); + } + /** * 使用helper::import()来引入文件,不要直接使用include或者require. * Using helper::import() to import a file, instead of include or require. diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 9049bb980b..5b5ff3c496 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -855,6 +855,16 @@ class baseRouter { if(defined('SESSION_STARTED')) return; + $ztSessionHandler = new ztSessionHandler(zget($_GET, 'tid', '')); + session_set_save_handler( + array($ztSessionHandler, "open"), + array($ztSessionHandler, "close"), + array($ztSessionHandler, "read"), + array($ztSessionHandler, "write"), + array($ztSessionHandler, "destroy"), + array($ztSessionHandler, "gc") + ); + /* If request header has token, use it as session for authentication. */ if(isset($_SERVER['HTTP_TOKEN'])) session_id($_SERVER['HTTP_TOKEN']); @@ -2616,3 +2626,115 @@ class super if($this->scope == 'global') a($GLOBALS); } } + +/** + * ZenTao session handler. + * + * @package framework + */ +class ztSessionHandler +{ + public $sessSavePath; + public $tagID; + + /** + * Construct. + * + * @param string $tagID + * @access public + * @return void + */ + public function __construct($tagID = '') + { + $this->tagID = $tagID; + } + + /** + * Open + * + * @param string $savePath + * @param string $sessionName + * @access public + * @return bool + */ + public function open($savePath, $sessionName) + { + $this->sessSavePath = $savePath; + return true; + } + + /** + * Close + * + * @access public + * @return bool + */ + public function close() + { + return true; + } + + /** + * Read + * + * @param string $id + * @access public + * @return bool + */ + public function read($id) + { + $sessFile = "$this->sessSavePath/sess_$id" . $this->tagID; + if(!file_exists($sessFile)) + { + ($this->tagID and file_exists("$this->sessSavePath/sess_$id")) ? copy("$this->sessSavePath/sess_$id", $sessFile) : touch($sessFile); + } + return (string) file_get_contents($sessFile); + } + + /** + * Write + * + * @param string $id + * @param string $sessData + * @access public + * @return bool + */ + public function write($id, $sessData) + { + $sessFile = "$this->sessSavePath/sess_$id" . $this->tagID; + if(file_put_contents($sessFile, $sessData)) return true; + return false; + } + + /** + * Destroy + * + * @param string $id + * @access public + * @return bool + */ + public function destroy($id) + { + $sessFile = "$this->sessSavePath/sess_$id" . $this->tagID; + @unlink($sessFile); + touch($sessFile); + return true; + } + + /** + * GC + * + * @param int $maxlifeTime + * @access public + * @return bool + */ + public function gc($maxlifeTime) + { + $time = time(); + foreach(glob("$this->sessSavePath/sess_*") as $fileName) + { + if(filemtime($fileName) + $maxlifeTime < $time) @unlink($fileName); + } + return true; + } +} diff --git a/lib/base/front/front.class.php b/lib/base/front/front.class.php index c45f30725d..a25afa7015 100644 --- a/lib/base/front/front.class.php +++ b/lib/base/front/front.class.php @@ -1166,7 +1166,9 @@ EOT; $jsConfig->runMode = $runMode; $jsConfig->timeout = isset($config->timeout) ? $config->timeout : ''; $jsConfig->pingInterval = isset($config->pingInterval) ? $config->pingInterval : ''; + $jsConfig->onlybody = zget($_GET, 'onlybody', 'no'); $jsConfig->tabSession = $config->tabSession; + if($config->tabSession and helper::inTabIDMode()) $jsConfig->tid = zget($_GET, 'tid', ''); $jsLang = new stdclass(); $jsLang->submitting = isset($lang->loading) ? $lang->loading : ''; diff --git a/module/common/view/header.lite.html.php b/module/common/view/header.lite.html.php index 120292dc77..6020e669c3 100755 --- a/module/common/view/header.lite.html.php +++ b/module/common/view/header.lite.html.php @@ -19,7 +19,6 @@ $onlybody = zget($_GET, 'onlybody', 'no'); zentaoPMS); js::exportConfigVars(); - echo ''; if($config->debug) { $timestamp = time(); diff --git a/module/user/control.php b/module/user/control.php index e16397c027..848d057ac1 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -777,7 +777,7 @@ class user extends control $canModifyDIR = false; $floderPath = $this->app->tmpRoot; } - elseif(!is_dir($this->app->dataRoot) or substr(base_convert(@fileperms($this->app->dataRoot),10,8),-4) != '0777') + elseif(!is_dir($this->app->dataRoot) or substr(base_convert(@fileperms($this->app->dataRoot), 10, 8), -4) != '0777') { $canModifyDIR = false; $floderPath = $this->app->dataRoot; @@ -827,7 +827,7 @@ class user extends control } else { - $response['locate'] = $this->config->webRoot; + $response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : ''); return $this->send($response); } } @@ -902,7 +902,7 @@ class user extends control } else { - $response['locate'] = $this->config->webRoot; + $response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : ''); return $this->send($response); } } @@ -914,7 +914,7 @@ class user extends control die(helper::removeUTF8Bom(json_encode(array('status' => 'success') + $data))); } - $response['locate'] = $this->config->webRoot; + $response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : ''); $response['result'] = 'success'; return $this->send($response); }