浏览代码

feat: move log settings to db

M1Screw 2 年之前
父节点
当前提交
70894b81ad

+ 0 - 7
config/.config.example.php

@@ -66,13 +66,6 @@ $_ENV['enable_change_email']        = true;         //是否允许用户更改
 $_ENV['notify_limit_mode']          = false;         //false为关闭,per为按照百分比提醒,mb为按照固定剩余流量提醒
 $_ENV['notify_limit_value']         = 500;           //当上一项为per时,此处填写百分比;当上一项为mb时,此处填写流量
 
-//日志设置---------------------------------------------------------------------------------------
-$_ENV['trafficLog']               = false;                       //是否记录用户每小时使用流量
-$_ENV['trafficLog_keep_days']     = 7;                           //每小时使用流量记录保留天数
-
-$_ENV['subscribeLog']             = false;                       //是否记录用户订阅日志
-$_ENV['subscribeLog_keep_days']   = 7;                           //订阅记录保留天数
-
 //订阅设置---------------------------------------------------------------------------------------
 $_ENV['Subscribe']                  = true;                         //本站是否提供订阅功能
 $_ENV['subUrl']                     = $_ENV['baseUrl'];             //订阅地址,如需和站点名称相同,请不要修改

+ 47 - 17
config/settings.json

@@ -1361,53 +1361,83 @@
     },
     {
         "id": null,
-        "item": "display_media",
+        "item": "display_detect_log",
+        "value": "1",
+        "class": "feature",
+        "is_public": 1,
+        "type": "bool",
+        "default": "1",
+        "mark": "显示用户审计记录"
+    },
+    {
+        "id": null,
+        "item": "display_docs",
+        "value": "1",
+        "class": "feature",
+        "is_public": 1,
+        "type": "bool",
+        "default": "1",
+        "mark": "显示文档"
+    },
+    {
+        "id": null,
+        "item": "display_docs_only_for_paid_user",
         "value": "0",
         "class": "feature",
         "is_public": 1,
         "type": "bool",
         "default": "0",
-        "mark": "显示节点流媒体解锁情况"
+        "mark": "文档仅付费用户可见"
     },
     {
         "id": null,
-        "item": "display_subscribe_log",
+        "item": "traffic_log",
         "value": "0",
         "class": "feature",
         "is_public": 1,
         "type": "bool",
         "default": "0",
-        "mark": "显示用户订阅记录"
+        "mark": "启用每小时使用流量日志"
     },
     {
         "id": null,
-        "item": "display_detect_log",
-        "value": "1",
+        "item": "traffic_log_retention_days",
+        "value": "7",
+        "class": "feature",
+        "is_public": 0,
+        "type": "int",
+        "default": "7",
+        "mark": "流量日志保留天数"
+    },
+    {
+        "id": null,
+        "item": "subscribe_log",
+        "value": "0",
         "class": "feature",
         "is_public": 1,
         "type": "bool",
-        "default": "1",
-        "mark": "显示用户审计记录"
+        "default": "0",
+        "mark": "启用订阅日志"
     },
     {
         "id": null,
-        "item": "display_docs",
-        "value": "1",
+        "item": "subscribe_log_retention_days",
+        "value": "7",
         "class": "feature",
         "is_public": 1,
-        "type": "bool",
-        "default": "1",
-        "mark": "显示文档"
+        "type": "int",
+        "default": "7",
+        "mark": "订阅日志保留天数"
     },
     {
         "id": null,
-        "item": "display_docs_only_for_paid_user",
-        "value": "0",
+        "item": "login_log",
+        "value": "1",
         "class": "feature",
         "is_public": 1,
         "type": "bool",
-        "default": "0",
-        "mark": "文档仅付费用户可见"
+        "default": "1",
+        "mark": "启用登录日志"
     },
     {
         "id": null,

+ 46 - 18
resources/views/tabler/admin/setting/feature.tpl

@@ -33,30 +33,15 @@
                         <li class="nav-item">
                             <a href="#display" class="nav-link active" data-bs-toggle="tab">功能显示</a>
                         </li>
+                        <li class="nav-item">
+                            <a href="#log" class="nav-link active" data-bs-toggle="tab">用户日志</a>
+                        </li>
                     </ul>
                 </div>
                 <div class="card-body">
                     <div class="tab-content">
                         <div class="tab-pane active show" id="display">
                             <div class="card-body">
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">显示节点流媒体解锁情况</label>
-                                    <div class="col">
-                                        <select id="display_media" class="col form-select" value="{$settings['display_media']}">
-                                            <option value="0" {if ! $settings['display_media']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['display_media']}selected{/if}>开启</option>
-                                        </select>
-                                    </div>
-                                </div>
-                                <div class="form-group mb-3 row">
-                                    <label class="form-label col-3 col-form-label">显示用户订阅记录</label>
-                                    <div class="col">
-                                        <select id="display_subscribe_log" class="col form-select" value="{$settings['display_subscribe_log']}">
-                                            <option value="0" {if ! $settings['display_subscribe_log']}selected{/if}>关闭</option>
-                                            <option value="1" {if $settings['display_subscribe_log']}selected{/if}>开启</option>
-                                        </select>
-                                    </div>
-                                </div>
                                 <div class="form-group mb-3 row">
                                     <label class="form-label col-3 col-form-label">显示用户审计记录</label>
                                     <div class="col">
@@ -86,6 +71,49 @@
                                 </div>
                             </div>
                         </div>
+                        <div class="tab-pane active show" id="log">
+                            <div class="card-body">
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">启用每小时使用流量日志</label>
+                                    <div class="col">
+                                        <select id="display_media" class="col form-select" value="{$settings['traffic_log']}">
+                                            <option value="0" {if ! $settings['traffic_log']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['traffic_log']}selected{/if}>开启</option>
+                                        </select>
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">流量日志保留天数</label>
+                                    <div class="col">
+                                        <input id="traffic_log_retention_days" type="text" class="form-control" value="{$settings['traffic_log_retention_days']}">
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">启用订阅日志</label>
+                                    <div class="col">
+                                        <select id="display_subscribe_log" class="col form-select" value="{$settings['subscribe_log']}">
+                                            <option value="0" {if ! $settings['subscribe_log']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['subscribe_log']}selected{/if}>开启</option>
+                                        </select>
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">订阅日志保留天数</label>
+                                    <div class="col">
+                                        <input id="subscribe_log_retention_days" type="text" class="form-control" value="{$settings['subscribe_log_retention_days']}">
+                                    </div>
+                                </div>
+                                <div class="form-group mb-3 row">
+                                    <label class="form-label col-3 col-form-label">启用登录日志</label>
+                                    <div class="col">
+                                        <select id="display_detect_log" class="col form-select" value="{$settings['login_log']}">
+                                            <option value="0" {if ! $settings['login_log']}selected{/if}>关闭</option>
+                                            <option value="1" {if $settings['login_log']}selected{/if}>开启</option>
+                                        </select>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
                     </div>
                 </div>
             </div>

+ 1 - 1
resources/views/tabler/user/header.tpl

@@ -96,7 +96,7 @@
                                                 <i class="ti ti-edit"></i>&nbsp;
                                                 资料
                                             </a>
-                                            {if $public_setting['display_subscribe_log']}
+                                            {if $public_setting['subscribe_log']}
                                             <a class="dropdown-item" href="/user/subscribe/log">
                                                 <i class="ti ti-rss"></i></i>&nbsp;
                                                 订阅

+ 1 - 1
src/Command/Cron.php

@@ -50,7 +50,7 @@ EOL;
         }
 
         // Run traffic log job
-        if ($minute === 0 && $_ENV['trafficLog']) {
+        if ($minute === 0 && Setting::obtain('traffic_log')) {
             $jobs->addTrafficLog();
         }
 

+ 7 - 5
src/Command/Tool.php

@@ -163,13 +163,15 @@ EOL;
         }
 
         if ($add_counter !== 0) {
-            echo '总计添加了 ' . $add_counter . ' 项新数据库设置' . PHP_EOL .
-                '更新了 ' . $update_counter . ' 项数据库设置' . PHP_EOL;
-        } else {
-            echo '没有任何新数据库设置项需要添加' . PHP_EOL;
+            echo '添加了 ' . $add_counter . ' 项新数据库设置' . PHP_EOL;
+        }
+
+        if ($update_counter !== 0) {
+            echo '更新了 ' . $update_counter . ' 项数据库设置' . PHP_EOL;
         }
+
         if ($del_counter !== 0) {
-            echo '总计移除了 ' . $del_counter . ' 项数据库设置' . PHP_EOL;
+            echo '移除了 ' . $del_counter . ' 项数据库设置' . PHP_EOL;
         }
     }
 

+ 0 - 1
src/Controllers/Admin/Setting/CaptchaController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class CaptchaController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/CronController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class CronController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/EmailController.php

@@ -9,7 +9,6 @@ use App\Models\Setting;
 use App\Services\Mail;
 use Exception;
 use Throwable;
-use function json_encode;
 
 final class EmailController extends BaseController
 {

+ 5 - 1
src/Controllers/Admin/Setting/FeatureController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class FeatureController extends BaseController
 {
@@ -17,6 +16,11 @@ final class FeatureController extends BaseController
         'display_detect_log',
         'display_docs',
         'display_docs_only_for_paid_user',
+        'traffic_log',
+        'traffic_log_retention_days',
+        'subscribe_log',
+        'subscribe_log_retention_days',
+        'login_log',
     ];
 
     /**

+ 0 - 1
src/Controllers/Admin/Setting/ImController.php

@@ -12,7 +12,6 @@ use App\Services\IM\Telegram;
 use Exception;
 use GuzzleHttp\Exception\GuzzleException;
 use Telegram\Bot\Exceptions\TelegramSDKException;
-use function json_encode;
 
 final class ImController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/RefController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class RefController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/RegController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class RegController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/SubscribeController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class SubscribeController extends BaseController
 {

+ 0 - 1
src/Controllers/Admin/Setting/SupportController.php

@@ -7,7 +7,6 @@ namespace App\Controllers\Admin\Setting;
 use App\Controllers\BaseController;
 use App\Models\Setting;
 use Exception;
-use function json_encode;
 
 final class SupportController extends BaseController
 {

+ 2 - 2
src/Controllers/SubController.php

@@ -65,7 +65,7 @@ final class SubController extends BaseController
         . '; total=' . $user->transfer_enable
         . '; expire=' . strtotime($user->class_expire);
 
-        if ($_ENV['subscribeLog']) {
+        if (Setting::obtain('subscribe_log')) {
             (new SubscribeLog())->add($user, $subtype, $request->getHeaderLine('User-Agent'));
         }
 
@@ -126,7 +126,7 @@ final class SubController extends BaseController
         }
 
         // 记录订阅日志
-        if ($_ENV['subscribeLog']) {
+        if (Setting::obtain('subscribe_log')) {
             (new SubscribeLog())->add($user, $sub_type, $request->getHeaderLine('User-Agent'));
         }
 

+ 1 - 1
src/Services/Bot/Telegram/Callback.php

@@ -410,7 +410,7 @@ final class Callback
                 break;
             case 'subscribe_log':
                 // 订阅记录
-                if ($_ENV['subscribeLog']) {
+                if (Setting::obtain('subscribe_log')) {
                     $logs = SubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->take(10)->get();
                     $text = '<strong>以下是你最近 10 次订阅记录:</strong>' . PHP_EOL . PHP_EOL;
 

+ 0 - 3
src/Services/Config.php

@@ -22,9 +22,6 @@ final class Config
             'enable_kill' => $_ENV['enable_kill'],
             'enable_change_email' => $_ENV['enable_change_email'],
 
-            'subscribeLog' => $_ENV['subscribeLog'],
-            'subscribeLog_keep_days' => $_ENV['subscribeLog_keep_days'],
-
             'enable_r2_client_download' => $_ENV['enable_r2_client_download'],
 
             'jsdelivr_url' => $_ENV['jsdelivr_url'],

+ 2 - 2
src/Services/Cron.php

@@ -64,9 +64,9 @@ final class Cron
         SubscribeLog::where(
             'request_time',
             '<',
-            time() - 86400 * (int) $_ENV['subscribeLog_keep_days']
+            time() - 86400 * Setting::obtain('subscribe_log_retention_days')
         )->delete();
-        UserHourlyUsage::where('datetime', '<', time() - 86400 * (int) $_ENV['trafficLog_keep_days'])->delete();
+        UserHourlyUsage::where('datetime', '<', time() - 86400 * Setting::obtain('traffic_log_retention_days'))->delete();
         DetectLog::where('datetime', '<', time() - 86400 * 3)->delete();
         EmailQueue::where('time', '<', time() - 86400)->delete();
         OnlineLog::where('last_time', '<', time() - 86400)->delete();