diff --git a/app/common/command/Timer.php b/app/common/command/Timer.php index 2284e75..994d6a8 100644 --- a/app/common/command/Timer.php +++ b/app/common/command/Timer.php @@ -28,11 +28,19 @@ class Timer extends Command // 指令输出 $output->writeln('start timer'); + + $site_domain = sysconfig('site', 'site_domain'); + + if (empty($site_domain)) { + $output->writeln('请前往后台设置站点域名(site_domain)配置项'); + return; + } + $client = new Client([ - 'base_uri' => sysconfig('site', 'site_domain'), + 'base_uri' => $site_domain, 'verify' => false, ]); - + while (true) { try { @@ -48,6 +56,10 @@ class Timer extends Command $name = $config_item['name']; + if ($name == 'http_demo' && !env('adminsystem.is_demo', false)) { + continue; + } + $cache_key = 'timer_' . $name; $cache_tag = 'system_timer'; @@ -74,10 +86,10 @@ class Timer extends Command } } - if (empty($list_promises)){ - + if (empty($list_promises)) { + $output->writeln(date('Y-m-d H:i:s') . ' no request'); - }else{ + } else { $results = Utils::unwrap($list_promises); $output->writeln(date('Y-m-d H:i:s') . ': request all finished'); } @@ -106,8 +118,8 @@ class Timer extends Command $data = array_merge($default, $config); - if ($data['frequency'] < 1) { - $data['frequency'] = 1; + if ($data['frequency'] < 0) { + $data['frequency'] = 0; } return $data; diff --git a/app/common/controller/TimerController.php b/app/common/controller/TimerController.php new file mode 100644 index 0000000..40bed2f --- /dev/null +++ b/app/common/controller/TimerController.php @@ -0,0 +1,35 @@ +frequency)) { + $this->protectVisit($this->frequency); + } + } + + protected function protectVisit(int $frequency) + { + + $cache_tag = 'timer_protect'; + + $cache_key = 'timer_protect_' . $this->request->url(); + + $last_exec_time = Cache::get($cache_key, 0); + + if ($last_exec_time >= time() - $frequency) { + + return $this->error('请不要频繁请求'); + } + + Cache::tag($cache_tag)->set($cache_key, time()); + } +} diff --git a/app/tools/controller/timer/ResetPassword.php b/app/tools/controller/timer/ResetPassword.php index 5269d89..cc3a0dc 100644 --- a/app/tools/controller/timer/ResetPassword.php +++ b/app/tools/controller/timer/ResetPassword.php @@ -4,13 +4,21 @@ declare(strict_types=1); namespace app\tools\controller\timer; -use app\common\controller\ToolsController; +use app\common\controller\TimerController; use think\facade\Console; -class ResetPassword extends ToolsController +class ResetPassword extends TimerController { + + protected $frequency = 600; + public function do() { + + if (!env('adminsystem.is_demo', false)) { + return $this->error('本功能只有在演示环境下在能使用', '', '/'); + } + $output = Console::call('admin:resetPassword', [ '--password=123456' ]);