admin 7 лет назад
Родитель
Сommit
2c8a5299b7

+ 0 - 24
app/Components/Helpers.php

@@ -134,30 +134,6 @@ class Helpers
         return $log->save();
     }
 
-    /**
-     * 添加serverChan投递日志
-     *
-     * @param string $title   标题
-     * @param string $content 内容
-     * @param int    $status  投递状态
-     * @param string $error   投递失败时记录的异常信息
-     *
-     * @return int
-     */
-    public static function addServerChanLog($title, $content, $status = 1, $error = '')
-    {
-        $log = new EmailLog();
-        $log->type = 2;
-        $log->address = 'admin';
-        $log->title = $title;
-        $log->content = $content;
-        $log->status = $status;
-        $log->error = $error;
-        $log->created_at = date('Y-m-d H:i:s');
-
-        return $log->save();
-    }
-
     /**
      * 添加优惠券操作日志
      *

+ 4 - 2
app/Components/Namesilo.php

@@ -89,13 +89,15 @@ class Namesilo
 
             // 出错
             if (empty($result['namesilo']) || $result['namesilo']['reply']['code'] != 300 || $result['namesilo']['reply']['detail'] != 'success') {
-                Helpers::addServerChanLog('[Namesilo API] - [' . $operation . ']', $content, 0, $result['namesilo']['reply']['detail']);
+                Helpers::addEmailLog(self::$systemConfig['crash_warning_email'], '[Namesilo API] - [' . $operation . ']', $content, 0, $result['namesilo']['reply']['detail']);
+            } else {
+                Helpers::addEmailLog(self::$systemConfig['crash_warning_email'], '[Namesilo API] - [' . $operation . ']', $content, 1, $result['namesilo']['reply']['detail']);
             }
 
             return $result['namesilo']['reply'];
         } catch (\Exception $e) {
             Log::error('CURL请求失败:' . $e->getMessage() . ' --- ' . $e->getLine());
-            Helpers::addServerChanLog('[Namesilo API] - [' . $operation . ']', $content, 0, $e->getMessage());
+            Helpers::addEmailLog(self::$systemConfig['crash_warning_email'], '[Namesilo API] - [' . $operation . ']', $content, 0, $e->getMessage());
 
             return false;
         }

+ 28 - 3
app/Components/ServerChan.php

@@ -2,6 +2,7 @@
 
 namespace App\Components;
 
+use App\Http\Models\EmailLog;
 use GuzzleHttp\Client;
 use GuzzleHttp\Psr7;
 use GuzzleHttp\Exception\RequestException;
@@ -25,7 +26,7 @@ class ServerChan
      * @return mixed
      * @throws \GuzzleHttp\Exception\GuzzleException
      */
-    public function send($title, $content)
+    public static function send($title, $content)
     {
         $client = new Client();
 
@@ -39,9 +40,9 @@ class ServerChan
 
             $result = json_decode($response->getBody());
             if (!$result->errno) {
-                Helpers::addServerChanLog($title, $content);
+                self::addlog($title, $content);
             } else {
-                Helpers::addServerChanLog($title, $content, 0, $result->errmsg);
+                self::addlog($title, $content, 0, $result->errmsg);
             }
         } catch (RequestException $e) {
             Log::error(Psr7\str($e->getRequest()));
@@ -50,4 +51,28 @@ class ServerChan
             }
         }
     }
+
+    /**
+     * 添加serverChan投递日志
+     *
+     * @param string $title   标题
+     * @param string $content 内容
+     * @param int    $status  投递状态
+     * @param string $error   投递失败时记录的异常信息
+     *
+     * @return int
+     */
+    private static function addlog($title, $content, $status = 1, $error = '')
+    {
+        $log = new EmailLog();
+        $log->type = 2;
+        $log->address = 'admin';
+        $log->title = $title;
+        $log->content = $content;
+        $log->status = $status;
+        $log->error = $error;
+        $log->created_at = date('Y-m-d H:i:s');
+
+        return $log->save();
+    }
 }

+ 1 - 2
app/Console/Commands/AutoCheckNodeStatus.php

@@ -193,8 +193,7 @@ class AutoCheckNodeStatus extends Command
     private function notifyMasterByServerchan($title, $content)
     {
         if (self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
-            $serverChan = new ServerChan();
-            $serverChan->send($title, $content);
+            ServerChan::send($title, $content);
         }
     }
 

+ 1 - 2
app/Console/Commands/AutoReportNode.php

@@ -60,8 +60,7 @@ class AutoReportNode extends Command
     private function notifyMasterByServerchan($title, $content)
     {
         if (self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
-            $serverChan = new ServerChan();
-            $serverChan->send($title, $content);
+            ServerChan::send($title, $content);
         }
     }
 }

+ 1 - 2
app/Console/Commands/UserTrafficAbnormalAutoWarning.php

@@ -51,8 +51,7 @@ class UserTrafficAbnormalAutoWarning extends Command
 
                     $content = "用户**{$user->username}(ID:{$user->id})**,最近1小时**上行流量:" . flowAutoShow($traffic->totalU) . ",下行流量:" . flowAutoShow($traffic->totalD) . ",共计:" . flowAutoShow($traffic->totalTraffic) . "**。";
 
-                    $serverChan = new ServerChan();
-                    $serverChan->send($title, $content);
+                    ServerChan::send($title, $content);
                 }
             }
         }

+ 1 - 1
app/Http/Controllers/AuthController.php

@@ -575,7 +575,7 @@ class AuthController extends Controller
             $content = '请求地址:' . $activeUserUrl;
 
             try {
-                Mail::to($username)->send(new activeUser(self::$systemConfig['website_name'], $activeUserUrl));
+                Mail::to($username)->send(new activeUser($activeUserUrl));
                 Helpers::addEmailLog($username, $title, $content);
             } catch (\Exception $e) {
                 Helpers::addEmailLog($username, $title, $content, 0, $e->getMessage());

+ 3 - 4
app/Http/Controllers/TicketController.php

@@ -69,9 +69,9 @@ class TicketController extends Controller
                     if (self::$systemConfig['crash_warning_email']) {
                         try {
                             Mail::to(self::$systemConfig['crash_warning_email'])->send(new replyTicket($title, $content));
-                            Helpers::addServerChanLog($title, $content);
+                            Helpers::addEmailLog(self::$systemConfig['crash_warning_email'], $title, $content);
                         } catch (\Exception $e) {
-                            Helpers::addServerChanLog($title, $content, 0, $e->getMessage());
+                            Helpers::addEmailLog(self::$systemConfig['crash_warning_email'], $title, $content, 0, $e->getMessage());
                         }
                     }
                 } else {
@@ -85,8 +85,7 @@ class TicketController extends Controller
 
                 // 通过ServerChan发微信消息提醒管理员
                 if (!Auth::user()->is_admin && self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
-                    $serverChan = new ServerChan();
-                    $serverChan->send($title, $content);
+                    ServerChan::send($title, $content);
                 }
 
                 return Response::json(['status' => 'success', 'data' => '', 'message' => '回复成功']);

+ 2 - 4
app/Http/Controllers/UserController.php

@@ -411,8 +411,7 @@ class UserController extends Controller
 
             // 通过ServerChan发微信消息提醒管理员
             if (self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
-                $serverChan = new ServerChan();
-                $serverChan->send($emailTitle, $content);
+                ServerChan::send($emailTitle, $content);
             }
 
             return Response::json(['status' => 'success', 'data' => '', 'message' => '提交成功']);
@@ -460,8 +459,7 @@ class UserController extends Controller
 
                 // 通过ServerChan发微信消息提醒管理员
                 if (self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
-                    $serverChan = new ServerChan();
-                    $serverChan->send($title, $content);
+                    ServerChan::send($title, $content);
                 }
 
                 return Response::json(['status' => 'success', 'data' => '', 'message' => '回复成功']);

+ 1 - 1
readme.md

@@ -43,4 +43,4 @@ Support ShadowsocksR、ShadowsocksRR、V2Ray
 
 ## License
 
-The project is released under the terms of the MIT License.
+SSRPanel is open-sourced software licensed under the MIT license.