Browse Source

feat: remove function calls in frontend tpl

Cat 2 years ago
parent
commit
624e5948c8

+ 12 - 20
resources/views/tabler/user/detect/log.tpl

@@ -24,7 +24,7 @@
                             <table class="table table-vcenter card-table">
                             <table class="table table-vcenter card-table">
                                 <thead>
                                 <thead>
                                     <tr>
                                     <tr>
-                                        <th>ID</th>
+                                        <th>事件ID</th>
                                         <th>节点ID</th>
                                         <th>节点ID</th>
                                         <th>节点名称</th>
                                         <th>节点名称</th>
                                         <th>规则ID</th>
                                         <th>规则ID</th>
@@ -37,25 +37,17 @@
                                 </thead>
                                 </thead>
                                 <tbody>
                                 <tbody>
                                 {foreach $logs as $log}
                                 {foreach $logs as $log}
-                                    {assign var="rule" value=$log->rule()}
-                                    {if $rule != null}
-                                        <tr>
-                                            <td>#{$log->id}</td>
-                                            <td>{$log->node_id}</td>
-                                            <td>{$log->Node()->name}</td>
-                                            <td>{$log->list_id}</td>
-                                            <td>{$rule->name}</td>
-                                            <td>{$rule->text}</td>
-                                            <td>{$rule->regex}</td>
-                                            {if $rule->type == 1}
-                                                <td>数据包明文匹配</td>
-                                            {/if}
-                                            {if $rule->type == 2}
-                                                <td>数据包 hex 匹配</td>
-                                            {/if}
-                                            <td>{date('Y-m-d H:i:s',$log->datetime)}</td>
-                                        </tr>
-                                    {/if}
+                                <tr>
+                                    <td>#{$log->id}</td>
+                                    <td>{$log->node_id}</td>
+                                    <td>{$log->node_name}</td>
+                                    <td>{$log->list_id}</td>
+                                    <td>{$log->rule->name}</td>
+                                    <td>{$log->rule->text}</td>
+                                    <td>{$log->rule->regex}</td>
+                                    <td>{$log->rule->type}</td>
+                                    <td>{$log->datetime}</td>
+                                </tr>
                                 {/foreach}
                                 {/foreach}
                                 </tbody>
                                 </tbody>
                             </table>
                             </table>

+ 6 - 6
resources/views/tabler/user/profile.tpl

@@ -75,12 +75,12 @@
                                     </tr>
                                     </tr>
                                 </thead>
                                 </thead>
                                 <tbody>
                                 <tbody>
-                                    {foreach $loginips as $login}
-                                        <tr>
-                                            <td>{$login->ip}</td>
-                                            <td>{date('Y-m-d H:i:s', $login->datetime)}</td>
-                                            <td>{Tools::getIpInfo($login->ip)}</td>
-                                        </tr>
+                                    {foreach $logins as $login}
+                                    <tr>
+                                        <td>{$login->ip}</td>
+                                        <td>{$login->datetime}</td>
+                                        <td>{$login->location}</td>
+                                    </tr>
                                     {/foreach}
                                     {/foreach}
                                 </tbody>
                                 </tbody>
                             </table>
                             </table>

+ 2 - 2
resources/views/tabler/user/subscribe/log.tpl → resources/views/tabler/user/subscribe_log.tpl

@@ -24,7 +24,7 @@
                             <table class="table table-vcenter card-table">
                             <table class="table table-vcenter card-table">
                                 <thead>
                                 <thead>
                                     <tr>
                                     <tr>
-                                        <th>ID</th>
+                                        <th>事件ID</th>
                                         <th>类型</th>
                                         <th>类型</th>
                                         <th>IP</th>
                                         <th>IP</th>
                                         <th>归属</th>
                                         <th>归属</th>
@@ -38,7 +38,7 @@
                                         <td>#{$log->id}</td>
                                         <td>#{$log->id}</td>
                                         <td>{$log->subscribe_type}</td>
                                         <td>{$log->subscribe_type}</td>
                                         <td>{$log->request_ip}</td>
                                         <td>{$log->request_ip}</td>
-                                        <td>{Tools::getIpInfo($log->request_ip)}</td>
+                                        <td>{$log->location}</td>
                                         <td>{$log->request_time}</td>
                                         <td>{$log->request_time}</td>
                                         <td>{$log->request_user_agent}</td>
                                         <td>{$log->request_user_agent}</td>
                                     </tr>
                                     </tr>

+ 0 - 2
src/Controllers/SubController.php

@@ -59,8 +59,6 @@ final class SubController extends BaseController
             ]);
             ]);
         }
         }
 
 
-        $sub_info = [];
-
         match ($subtype) {
         match ($subtype) {
             'json' => $sub_info = self::getJson($user),
             'json' => $sub_info = self::getJson($user),
             'clash' => $sub_info = self::getClash($user),
             'clash' => $sub_info = self::getClash($user),

+ 20 - 3
src/Controllers/User/LogController.php

@@ -24,22 +24,39 @@ final class LogController extends BaseController
     {
     {
         $logs = UserSubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
         $logs = UserSubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
 
 
+        foreach ($logs as $log) {
+            $log->location = Tools::getIpLocation($log->request_ip);
+        }
+
         return $response->write($this->view()
         return $response->write($this->view()
             ->assign('logs', $logs)
             ->assign('logs', $logs)
-            ->registerClass('Tools', Tools::class)
-            ->fetch('user/subscribe/log.tpl'));
+            ->fetch('user/subscribe_log.tpl'));
     }
     }
 
 
     /**
     /**
+     * 审计碰撞记录
+     *
      * @throws Exception
      * @throws Exception
      */
      */
     public function detect(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     public function detect(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
     {
         $logs = DetectLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
         $logs = DetectLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
 
 
+        foreach ($logs as $log) {
+            $log->node_name = $log->nodeName();
+            $log->rule = $log->rule();
+
+            if ($log->rule->type === 1) {
+                $log->rule->type = '数据包明文匹配';
+            } elseif ($log->type === 2) {
+                $log->rule->type = '数据包 hex 匹配';
+            }
+
+            $log->datetime = Tools::toDateTime($log->datetime);
+        }
+
         return $response->write($this->view()
         return $response->write($this->view()
             ->assign('logs', $logs)
             ->assign('logs', $logs)
-            ->registerClass('Tools', Tools::class)
             ->fetch('user/detect/log.tpl'));
             ->fetch('user/detect/log.tpl'));
     }
     }
 }
 }

+ 8 - 22
src/Controllers/UserController.php

@@ -68,36 +68,22 @@ final class UserController extends BaseController
         );
         );
     }
     }
 
 
-    public function resetPort(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
-    {
-        $temp = $this->user->resetPort();
-        return $response->withJson([
-            'ret' => ($temp['ok'] === true ? 1 : 0),
-            'msg' => $temp['msg'],
-        ]);
-    }
-
-    public function specifyPort(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
-    {
-        $temp = $this->user->specifyPort((int) $request->getParam('port'));
-        return $response->withJson([
-            'ret' => ($temp['ok'] === true ? 1 : 0),
-            'msg' => $temp['msg'],
-        ]);
-    }
-
     /**
     /**
      * @throws Exception
      * @throws Exception
      */
      */
     public function profile(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     public function profile(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
     {
         // 登录IP
         // 登录IP
-        $loginips = LoginIp::where('userid', '=', $this->user->id)->where('type', '=', 0)->orderBy('datetime', 'desc')->take(10)->get();
+        $logins = LoginIp::where('userid', '=', $this->user->id)->where('type', '=', 0)->orderBy('datetime', 'desc')->take(10)->get();
+
+        foreach ($logins as $login) {
+            $login->datetime = Tools::toDateTime((int) $login->datetime);
+            $login->location = Tools::getIpLocation($login->ip);
+        }
 
 
         return $response->write(
         return $response->write(
             $this->view()
             $this->view()
-                ->assign('loginips', $loginips)
-                ->registerClass('Tools', Tools::class)
+                ->assign('logins', $logins)
                 ->fetch('user/profile.tpl')
                 ->fetch('user/profile.tpl')
         );
         );
     }
     }
@@ -302,7 +288,7 @@ final class UserController extends BaseController
         $oldemail = $user->email;
         $oldemail = $user->email;
         $otheruser = User::where('email', $newemail)->first();
         $otheruser = User::where('email', $newemail)->first();
 
 
-        if ($_ENV['enable_change_email'] !== true) {
+        if (! $_ENV['enable_change_email']) {
             return ResponseHelper::error($response, '此项不允许自行修改,请联系管理员操作');
             return ResponseHelper::error($response, '此项不允许自行修改,请联系管理员操作');
         }
         }