From cf274bb96f2e1d20b2ba298c58ff2151eaf451bd Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 18 Sep 2024 22:20:40 +0800 Subject: [PATCH] add ip check for clean cache function --- themes/beauty/controller/SiteController.php | 15 ++++++++++----- themes/beauty/views/site/index.php | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index c18bf07..601f245 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -231,12 +231,17 @@ Class SiteController extends Controller { $msg = 'OK'; try { - $cacheDir = __DIR__ . '/../../../runtime/cache/'; - $files = scandir($cacheDir); - foreach($files as $file) { - if (!preg_match('/\.json$/i', $file)) {continue;} + if (Common::isAdminIp($this->getUserIp()) == false) { + $code = 0; + $msg = '403 Forbidden,禁止访问'; + }else { + $cacheDir = __DIR__ . '/../../../runtime/cache/'; + $files = scandir($cacheDir); + foreach($files as $file) { + if (!preg_match('/\.json$/i', $file)) {continue;} - unlink("{$cacheDir}{$file}"); + unlink("{$cacheDir}{$file}"); + } } }catch(Exception $e) { $code = 0; diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index af28312..0fed848 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -21,7 +21,9 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full';