diff --git a/CHANGELOG.md b/CHANGELOG.md index acc8976..d6d3b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Feat - **Auth:** Use JWT to set cookies content (bf897c6) - **Auth/Login:** Add full Advanced Options support (6009dc8) +- **Secret:** Protect jwt key for env('APP_SECRET_KEY') (dfa67da) - **ban_ips:** Store banned ip in components/Site (01084c9) ### Fix diff --git a/apps/models/form/Auth/UserLoginForm.php b/apps/models/form/Auth/UserLoginForm.php index 1536174..f82c593 100644 --- a/apps/models/form/Auth/UserLoginForm.php +++ b/apps/models/form/Auth/UserLoginForm.php @@ -124,7 +124,7 @@ protected function loadUserFromPdo() /** @noinspection PhpUnused */ protected function isMaxUserSessionsReached() { - $exist_session_count = app()->pdo->createCommand('SELECT COUNT(`id`) FROM `user_session_log` WHERE uid = :uid AND expired = -1')->bindParams([ + $exist_session_count = app()->pdo->createCommand('SELECT COUNT(`id`) FROM `user_session_log` WHERE uid = :uid AND expired != 1')->bindParams([ 'uid' => $this->self['id'] ])->queryScalar(); diff --git a/apps/process/TrackerAnnounceProcess.php b/apps/process/TrackerAnnounceProcess.php index e0734e1..751d19e 100644 --- a/apps/process/TrackerAnnounceProcess.php +++ b/apps/process/TrackerAnnounceProcess.php @@ -15,12 +15,12 @@ class TrackerAnnounceProcess extends Process { public function run() { - do { + while (true) { $data = app()->redis->brpoplpush(Constant::trackerToDealQueue, Constant::trackerBackupQueue, 5); if ($data !== false) { app()->pdo->beginTransaction(); try { - /* We got data from Http Server Like + /** We got data from Http Server Like * [ * 'timestamp' => timestamp when controller receive the announce, * 'queries' => $queries, 'role' => $role, @@ -37,8 +37,7 @@ public function run() // TODO deal with the items in backup_queue } } - \Rid::app()->cleanComponents(); - } while ($data !== false); + } } /** diff --git a/framework/Base/Process.php b/framework/Base/Process.php index 60c3a6a..4ef6c04 100644 --- a/framework/Base/Process.php +++ b/framework/Base/Process.php @@ -46,14 +46,20 @@ protected function resetSleepTime() final public function start($config) { $this->_config = $config; + $this->disablePdoAndRedisRecord(); $this->resetSleepTime(); println('New Custom process `' . static::class . '` added.'); while (true) { $this->run(); - \Rid::app()->cleanComponents(); sleep($this->getSleepTime()); } } + + private function disablePdoAndRedisRecord() + { + if (in_array('pdo', $this->_config['components'])) app()->pdo->setRecordData(false); + if (in_array('redis', $this->_config['components'])) app()->redis->setRecordData(false); + } } diff --git a/framework/Database/BasePDOConnection.php b/framework/Database/BasePDOConnection.php index fc1793e..29aba16 100644 --- a/framework/Database/BasePDOConnection.php +++ b/framework/Database/BasePDOConnection.php @@ -45,6 +45,7 @@ class BasePDOConnection extends Component // sql原始数据 protected $_sqlPrepareData = []; + protected $_recordData = true; protected $_sqlExecuteData = []; // 默认驱动连接选项 @@ -66,7 +67,7 @@ public function onInitialize() public function onRequestAfter() { - $this->cleanSqlExecuteData(); + $this->_recordData && $this->cleanSqlExecuteData(); } // 创建连接 @@ -202,7 +203,7 @@ protected function prepare() // 清扫预处理数据 protected function clearPrepare() { - $this->_sqlExecuteData[] = $this->getRawSql(); + if ($this->_recordData) $this->_sqlExecuteData[] = $this->getRawSql(); $this->_sql = ''; $this->_params = []; $this->_values = []; @@ -433,4 +434,12 @@ public function cleanSqlExecuteData() public function getExecuteData() { return $this->_sqlExecuteData; } + + /** + * @param bool $recordData + */ + public function setRecordData(bool $recordData): void + { + $this->_recordData = $recordData; + } } diff --git a/framework/Redis/BaseRedisConnection.php b/framework/Redis/BaseRedisConnection.php index defa684..dc1b2e3 100644 --- a/framework/Redis/BaseRedisConnection.php +++ b/framework/Redis/BaseRedisConnection.php @@ -201,7 +201,7 @@ class BaseRedisConnection extends Component // 默认驱动连接选项 protected $_defaultDriverOptions = [ \Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP, // 默认做序列化 - \Redis::OPT_PREFIX => "", + \Redis::OPT_PREFIX => '', ]; // 驱动连接选项 @@ -211,6 +211,7 @@ class BaseRedisConnection extends Component /** @var \Redis */ protected $_redis; + protected $_recordData = true; protected $_calledData = []; // 初始化事件 @@ -269,17 +270,19 @@ public function __call($name, $arguments) $this->autoConnect(); // 自动连接 - $arg_text = ''; - foreach ($arguments as $arg) { - if (!is_string($arg)) $arg = '[Array]'; - $arg_text .= ' ' . $arg; - } + if ($this->_recordData) { + $arg_text = ''; + foreach ($arguments as $arg) { + if (!is_string($arg)) $arg = '[Array]'; + $arg_text .= ' ' . $arg; + } - $calling = $name . ($arguments ? ' ' . $arg_text : ''); - if (isset($this->_calledData[$calling])) { - $this->_calledData[$calling] += 1; - } else { - $this->_calledData[$calling] = 1; + $calling = $name . ($arguments ? ' ' . $arg_text : ''); + if (isset($this->_calledData[$calling])) { + $this->_calledData[$calling] += 1; + } else { + $this->_calledData[$calling] = 1; + } } return call_user_func_array([$this->_redis, $name], $arguments); // 执行命令 @@ -316,7 +319,15 @@ public function getCalledData() public function cleanCalledData() { - $this->_calledData = []; + $this->_recordData && $this->_calledData = []; + } + + /** + * @param bool $recordData + */ + public function setRecordData(bool $recordData): void + { + $this->_recordData = $recordData; } /**