Просмотр исходного кода

1.一键导出用户SS配置json文件
2.格式化代码

bingo 7 лет назад
Родитель
Сommit
9aedacecb8

+ 4 - 4
app/Console/Commands/AutoRegetPortJob.php

@@ -25,8 +25,8 @@ class AutoRegetPortJob extends Command
             $userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('port', 0)->get();
             if (!$userList->isEmpty()) {
                 foreach ($userList as $user) {
-                  $port = $config['is_rand_port'] ? $this->getRandPort() : $this->getOnlyPort();
-                  User::query()->where('id', $user->id)->update(['port' => $port]);
+                    $port = $config['is_rand_port'] ? $this->getRandPort() : $this->getOnlyPort();
+                    User::query()->where('id', $user->id)->update(['port' => $port]);
                 }
             }
         }
@@ -45,7 +45,7 @@ class AutoRegetPortJob extends Command
 
         return $data;
     }
-  
+
     // 获取一个随机端口
     public function getRandPort()
     {
@@ -61,7 +61,7 @@ class AutoRegetPortJob extends Command
 
         return $port;
     }
-    
+
     // 获取一个端口
     public function getOnlyPort()
     {

+ 9 - 8
app/Console/Commands/AutoReopenUserJob.php

@@ -29,20 +29,21 @@ class AutoReopenUserJob extends Command
                 $this->log($user->id, 0, '【自动解封】-封禁到期');
             }
         }
-        User::query()->where('enable', 1)->where('ban_time', -1)->update(['ban_time' => 0]);//重置ban_time
+
+        // SSR(R)被启用说明用户购买了流量
+        User::query()->where('enable', 1)->where('ban_time', -1)->update(['ban_time' => 0]); // 重置ban_time
         $userList = User::query()->where('status', '>=', 0)->where('enable', 0)->where('ban_time', -1)->whereRaw("u + d < transfer_enable")->get();
         if (!$userList->isEmpty()) {
-          foreach ($userList as $user) {
-            User::query()->where('id', $user->id)->update(['enable' => 1, 'ban_time' => 0]);
-            
-            // 写入操作日志
-            $this->log($user->id, 0, '【自动解封】-有流量解封');
-          }
+            foreach ($userList as $user) {
+                User::query()->where('id', $user->id)->update(['enable' => 1, 'ban_time' => 0]);
+
+                // 写入操作日志
+                $this->log($user->id, 0, '【自动解封】-有流量解封');
+            }
         }
 
         Log::info('定时任务:' . $this->description);
     }
-      
 
 
     private function log($user_id, $minutes, $desc)

+ 79 - 39
app/Http/Controllers/AdminController.php

@@ -344,13 +344,13 @@ class AdminController extends Controller
             if ($exists) {
                 return Response::json(['status' => 'fail', 'data' => '', 'message' => '用户名已存在,请重新输入']);
             }
-          
+
             // 校验端口是否已存在
-            $exists = User::query()->where('id', '<>', $id)->where('port','>', 0)->where('port', $port)->first();
+            $exists = User::query()->where('id', '<>', $id)->where('port', '>', 0)->where('port', $port)->first();
             if ($exists) {
                 return Response::json(['status' => 'fail', 'data' => '', 'message' => '端口已存在,请重新输入']);
             }
-          
+
             DB::beginTransaction();
             try {
                 $data = [
@@ -708,7 +708,7 @@ class AdminController extends Controller
 
         DB::beginTransaction();
         try {
-            // 删除分组关联、节点标签
+            // 删除分组关联、节点标签、节点相关日志
             SsGroupNode::query()->where('node_id', $id)->delete();
             SsNodeLabel::query()->where('node_id', $id)->delete();
             SsNode::query()->where('id', $id)->delete();
@@ -748,28 +748,27 @@ class AdminController extends Controller
         $hourlyData = [];
 
         // 节点一个月内的流量
-        $nodeTrafficDaily = SsNodeTrafficDaily::query()->with(['info'])->where('node_id', $node->id)->where('created_at', '>=', date('Y-m',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-        $dailyTotal = date('d',time())-1;//今天不算,减一
+        $nodeTrafficDaily = SsNodeTrafficDaily::query()->with(['info'])->where('node_id', $node->id)->where('created_at', '>=', date('Y-m', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+        $dailyTotal = date('d', time()) - 1;//今天不算,减一
         $dailyCount = count($nodeTrafficDaily);
-        for ($x=0; $x<($dailyTotal-$dailyCount); $x++){
+        for ($x = 0; $x < ($dailyTotal - $dailyCount); $x++) {
             $dailyData[$x] = 0;
-          }
-        for ($x=($dailyTotal-$dailyCount);$x<$dailyTotal;$x++){
-             $dailyData[$x] = round($nodeTrafficDaily[$x-($dailyTotal-$dailyCount)] / (1024 * 1024 * 1024), 3);
-          }
+        }
+        for ($x = ($dailyTotal - $dailyCount); $x < $dailyTotal; $x++) {
+            $dailyData[$x] = round($nodeTrafficDaily[$x - ($dailyTotal - $dailyCount)] / (1024 * 1024 * 1024), 3);
+        }
 
         // 节点一天内的流量
-        $nodeTrafficHourly = SsNodeTrafficHourly::query()->with(['info'])->where('node_id', $node->id)->where('created_at', '>=', date('Y-m-d',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-        $hourlyTotal = date('H',time());
+        $nodeTrafficHourly = SsNodeTrafficHourly::query()->with(['info'])->where('node_id', $node->id)->where('created_at', '>=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+        $hourlyTotal = date('H', time());
         $hourlyCount = count($nodeTrafficHourly);
-        for ($x=0; $x<($hourlyTotal-$hourlyCount); $x++){
+        for ($x = 0; $x < ($hourlyTotal - $hourlyCount); $x++) {
             $hourlyData[$x] = 0;
-          }
-        for ($x=($hourlyTotal-$hourlyCount);$x<$hourlyTotal;$x++){
-             $hourlyData[$x] = round($nodeTrafficHourly[$x-($hourlyTotal-$hourlyCount)] / (1024 * 1024 * 1024), 3);
-          }
-    
-      
+        }
+        for ($x = ($hourlyTotal - $hourlyCount); $x < $hourlyTotal; $x++) {
+            $hourlyData[$x] = round($nodeTrafficHourly[$x - ($hourlyTotal - $hourlyCount)] / (1024 * 1024 * 1024), 3);
+        }
+
         $view['trafficDaily'] = [
             'nodeName'  => $node->name,
             'dailyData' => "'" . implode("','", $dailyData) . "'"
@@ -1126,10 +1125,10 @@ class AdminController extends Controller
         }
 
         if (!file_exists($filePath)) {
-            exit('文件不存在');
+            exit('文件不存在,请检查目录权限');
         }
 
-        return Response::download(public_path('downloads/convert.json'));
+        return Response::download($filePath);
     }
 
     // 数据导入
@@ -1290,6 +1289,47 @@ class AdminController extends Controller
         return Response::view('admin/export', $view);
     }
 
+    // 导出原版SS用户配置信息
+    public function exportSSJson(Request $request)
+    {
+        $userList = User::query()->where('port', '>', 0)->get();
+        $defaultMethod = $this->getDefaultMethod();
+
+        $json = '';
+        if (!$userList->isEmpty()) {
+            $tmp = [];
+            foreach ($userList as $key => $user) {
+                $tmp[] = '"' . $user->port . '":"' . $user->passwd . '"';
+            }
+
+            $userPassword = implode(",\n\t\t", $tmp);
+            $json = <<<EOF
+{
+	"server":"0.0.0.0",
+    "local_address":"127.0.0.1",
+    "local_port":1080,
+    "port_password":{
+        {$userPassword}
+    },
+    "timeout":300,
+    "method":"{$defaultMethod}",
+    "fast_open":false
+}
+EOF;
+        }
+
+        // 生成JSON文件
+        $fileName = makeRandStr('16') . '_shadowsocks.json';
+        $filePath = public_path('downloads/' . $fileName);
+        file_put_contents($filePath, $json);
+
+        if (!file_exists($filePath)) {
+            exit('文件生成失败,请检查目录权限');
+        }
+
+        return Response::download($filePath);
+    }
+
     // 修改个人资料
     public function profile(Request $request)
     {
@@ -1349,27 +1389,27 @@ class AdminController extends Controller
             $dailyData = [];
             $hourlyData = [];
 
-          
-        // 节点一个月内的流量
-          $userTrafficDaily = UserTrafficDaily::query()->with(['info'])->where('user_id', $user->id)->where('node_id', $node->id)->where('created_at', '>=', date('Y-m',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-          $dailyTotal = date('d',time())-1;//今天不算,减一
-          $dailyCount = count($userTrafficDaily);
-          for ($x=0; $x<($dailyTotal-$dailyCount); $x++){
-              $dailyData[$x] = 0;
+
+            // 节点一个月内的流量
+            $userTrafficDaily = UserTrafficDaily::query()->with(['info'])->where('user_id', $user->id)->where('node_id', $node->id)->where('created_at', '>=', date('Y-m', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+            $dailyTotal = date('d', time()) - 1;//今天不算,减一
+            $dailyCount = count($userTrafficDaily);
+            for ($x = 0; $x < ($dailyTotal - $dailyCount); $x++) {
+                $dailyData[$x] = 0;
             }
-          for ($x=($dailyTotal-$dailyCount);$x<$dailyTotal;$x++){
-               $dailyData[$x] = round($userTrafficDaily[$x-($dailyTotal-$dailyCount)] / (1024 * 1024 * 1024), 3);
+            for ($x = ($dailyTotal - $dailyCount); $x < $dailyTotal; $x++) {
+                $dailyData[$x] = round($userTrafficDaily[$x - ($dailyTotal - $dailyCount)] / (1024 * 1024 * 1024), 3);
             }
 
-          // 节点一天内的流量
-          $userTrafficHourly = UserTrafficHourly::query()->with(['info'])->where('user_id', $user->id)->where('node_id', $node->id)->where('created_at', '>=', date('Y-m-d',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-          $hourlyTotal = date('H',time());
-          $hourlyCount = count($userTrafficHourly);
-          for ($x=0; $x<($hourlyTotal-$hourlyCount); $x++){
-              $hourlyData[$x] = 0;
+            // 节点一天内的流量
+            $userTrafficHourly = UserTrafficHourly::query()->with(['info'])->where('user_id', $user->id)->where('node_id', $node->id)->where('created_at', '>=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+            $hourlyTotal = date('H', time());
+            $hourlyCount = count($userTrafficHourly);
+            for ($x = 0; $x < ($hourlyTotal - $hourlyCount); $x++) {
+                $hourlyData[$x] = 0;
             }
-          for ($x=($hourlyTotal-$hourlyCount);$x<$hourlyTotal;$x++){
-               $hourlyData[$x] = round($userTrafficHourly[$x-($hourlyTotal-$hourlyCount)] / (1024 * 1024 * 1024), 3);
+            for ($x = ($hourlyTotal - $hourlyCount); $x < $hourlyTotal; $x++) {
+                $hourlyData[$x] = round($userTrafficHourly[$x - ($hourlyTotal - $hourlyCount)] / (1024 * 1024 * 1024), 3);
             }
 
             $trafficDaily[$node->id] = [

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

@@ -103,7 +103,7 @@ class Controller extends BaseController
 
         return $port;
     }
-    
+
     // 获取一个端口
     public function getOnlyPort()
     {

+ 20 - 20
app/Http/Controllers/UserController.php

@@ -282,38 +282,38 @@ class UserController extends Controller
     public function trafficLog(Request $request)
     {
         $user = $request->session()->get('user');
-        $trafficDaily = [];
-        $trafficHourly = [];
+
         $dailyData = [];
         $hourlyData = [];
-      
-      
+
         // 节点一个月内的流量
-        $userTrafficDaily = UserTrafficDaily::query()->where('user_id', $user['id'])->where('node_id', 0)->where('created_at', '>=', date('Y-m',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-        $dailyTotal = date('d',time())-1;//今天不算,减一
+        $userTrafficDaily = UserTrafficDaily::query()->where('user_id', $user['id'])->where('node_id', 0)->where('created_at', '>=', date('Y-m', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+
+        $dailyTotal = date('d', time()) - 1; // 今天不算,减一
         $dailyCount = count($userTrafficDaily);
-        for ($x=0; $x<($dailyTotal-$dailyCount); $x++){
+        for ($x = 0; $x < ($dailyTotal - $dailyCount); $x++) {
             $dailyData[$x] = 0;
-          }
-        for ($x=($dailyTotal-$dailyCount);$x<$dailyTotal;$x++){
-            $dailyData[$x] = round($userTrafficDaily[$x-($dailyTotal-$dailyCount)] / (1024 * 1024 * 1024), 3);
-          }
-
-         // 节点一天内的流量
-        $userTrafficHourly = UserTrafficHourly::query()->where('user_id', $user['id'])->where('node_id', 0)->where('created_at', '>=', date('Y-m-d',time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
-        $hourlyTotal = date('H',time());
+        }
+        for ($x = ($dailyTotal - $dailyCount); $x < $dailyTotal; $x++) {
+            $dailyData[$x] = round($userTrafficDaily[$x - ($dailyTotal - $dailyCount)] / (1024 * 1024 * 1024), 3);
+        }
+
+        // 节点一天内的流量
+        $userTrafficHourly = UserTrafficHourly::query()->where('user_id', $user['id'])->where('node_id', 0)->where('created_at', '>=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
+        $hourlyTotal = date('H', time());
         $hourlyCount = count($userTrafficHourly);
-        for ($x=0; $x<($hourlyTotal-$hourlyCount); $x++){
+        for ($x = 0; $x < ($hourlyTotal - $hourlyCount); $x++) {
             $hourlyData[$x] = 0;
-          }
-        for ($x=($hourlyTotal-$hourlyCount);$x<$hourlyTotal;$x++){
-             $hourlyData[$x] = round($userTrafficHourly[$x-($hourlyTotal-$hourlyCount)] / (1024 * 1024 * 1024), 3);
-          }
+        }
+        for ($x = ($hourlyTotal - $hourlyCount); $x < $hourlyTotal; $x++) {
+            $hourlyData[$x] = round($userTrafficHourly[$x - ($hourlyTotal - $hourlyCount)] / (1024 * 1024 * 1024), 3);
+        }
 
         $view['trafficDaily'] = "'" . implode("','", $dailyData) . "'";
         $view['trafficHourly'] = "'" . implode("','", $hourlyData) . "'";
         $view['website_analytics'] = self::$config['website_analytics'];
         $view['website_customer_service'] = self::$config['website_customer_service'];
+
         return Response::view('user/trafficLog', $view);
     }
 

+ 43 - 0
public/downloads/vgjDFKNihgWnVfP4_shadowsocks.json

@@ -0,0 +1,43 @@
+{
+	"server":"0.0.0.0",
+    "local_address":"127.0.0.1",
+    "local_port":1080,
+    "port_password":{
+        "10000":"uKRyuvTG",
+		"10001":"Z6b8D9",
+		"10002":"QP9cWG",
+		"10003":"Fn8tf7",
+		"10004":"psyPeV",
+		"10005":"ieqE2p",
+		"10006":"ueGeEq",
+		"10007":"gEXsUd",
+		"20996":"K89nzUuF",
+		"18392":"qXNXJHjC",
+		"29708":"x7wugGq8",
+		"28596":"PfsAGFfH",
+		"21380":"axNe7WXv",
+		"38322":"ZseHsZsG",
+		"20220":"QwxU2CNE",
+		"36263":"54jNGjZw",
+		"25199":"KgPKhujc",
+		"13140":"hF9SbcGy",
+		"22948":"mAhW7br2",
+		"35935":"GjcAHQpj",
+		"11073":"ftPKtpWV",
+		"38929":"D9zRepVc",
+		"22215":"RVZSVgxy",
+		"29545":"ZbhA7V",
+		"27234":"iHeCqa",
+		"15486":"HruN9z",
+		"27841":"JWVgZu",
+		"21009":"pPiXzu",
+		"18904":"r7raEy",
+		"37328":"ErdC5S",
+		"28109":"kCjRXC",
+		"20909":"BRvWWE",
+		"26961":"HcDacx"
+    },
+    "timeout":300,
+    "method":"aes-256-cfb",
+    "fast_open":false
+}

+ 4 - 4
resources/lang/zh-CN/home.php

@@ -90,15 +90,15 @@ return [
     'service_days'                    => '有效期',
     'service_buy_button'              => '购买',
     'day'                             => '天',
-    'coupon'                          => '充值券',
+    'coupon'                          => '优惠券',
     'redeem_coupon'                   => '使用',
     'service_type_1'                  => '流量包',
     'service_type_2'                  => '套餐',
 
     // 流量日志
-    'traffic_log_tips'                => '提示:月流量统计不会统计当天,日流量统计不会统计当前小时;如果无统计数据,请检查定时任务是否正常。(每月1日和每日0时因为没有统计流量,不显示流量)',
-    'traffic_log_30days'              => '这个月的流量使用情况',
-    'traffic_log_24hours'             => '今天的流量使用情况',
+    'traffic_log_tips'                => '提示:流量统计图更新会有延迟。按天统计图在次日更新,按小时统计图在次小时更新。(每月1日月流量不显示流量)',
+    'traffic_log_30days'              => '本月流量使用情况',
+    'traffic_log_24hours'             => '今流量使用情况',
     'traffic_log_keywords'            => '使用流量',
     'traffic_log_unit'                => '单位 / MB',
     'traffic_log_max'                 => '使用高峰',

+ 5 - 11
resources/views/admin/nodeList.blade.php

@@ -58,17 +58,11 @@
                                         @foreach($nodeList as $node)
                                             <tr class="odd gradeX">
                                                 <td> {{$node->id}} </td>
-                                                <td>
-                                                    @if(!$node->status)
-                                                        <span class="label label-warning" title="维护中">{{$node->name}}</span>
-                                                    @else
-                                                        {{$node->name}}
-                                                    @endif
-                                                </td>
-                                                <td> <span class="label label-danger">{{$node->server}}</span> </td>
-                                                <td> <span class="label label-danger">{{$node->ip}}</span> </td>
-                                                <td> <span class="label label-danger">{{$node->load}}</span> </td>
-                                                <td> <span class="label label-danger">{{$node->online_users}}</span> </td>
+                                                <td> <span class="label {{$node->status ? 'label-danger' : 'label-default'}}" title="维护中">{{$node->name}}</span> </td>
+                                                <td> <span class="label {{$node->status ? 'label-danger' : 'label-default'}}">{{$node->server}}</span> </td>
+                                                <td> <span class="label {{$node->status ? 'label-danger' : 'label-default'}}">{{$node->ip}}</span> </td>
+                                                <td> <span class="label {{$node->status ? 'label-danger' : 'label-default'}}">{{$node->load}}</span> </td>
+                                                <td> <span class="label {{$node->status ? 'label-danger' : 'label-default'}}">{{$node->online_users}}</span> </td>
                                                 <td> {{$node->transfer}} </td>
                                                 <td> <span class="label label-danger">{{$node->traffic_rate}}</span> </td>
                                                 <td>

+ 1 - 1
resources/views/admin/nodeMonitor.blade.php

@@ -93,7 +93,7 @@
 
         option = {
             title: {
-                text: '月流量',
+                text: '月流量',
                 subtext: '单位G'
             },
             tooltip: {

+ 7 - 0
resources/views/admin/userList.blade.php

@@ -19,6 +19,7 @@
                         </div>
                         <div class="actions">
                             <div class="btn-group btn-group-devided">
+                                <button class="btn sbold red" onclick="exportSSJson()"> 导出JSON </button>
                                 <button class="btn sbold blue" onclick="batchAddUsers()"> 批量生成 </button>
                                 <button class="btn sbold blue" onclick="addUser()"> 添加用户 </button>
                             </div>
@@ -169,6 +170,12 @@
     <script src="/js/layer/layer.js" type="text/javascript"></script>
 
     <script type="text/javascript">
+        // 导出原版json配置
+        function exportSSJson() {
+            layer.msg("成功导出原版SS的用户配置信息,加密方式为系统默认的加密方式");
+            window.location.href = '{{url('admin/exportSSJson')}}';
+        }
+
         // 批量生成账号
         function batchAddUsers() {
             layer.confirm('将自动生成5个账号,确定继续吗?', {icon: 3, title:'警告'}, function(index) {

+ 1 - 1
resources/views/admin/userMonitor.blade.php

@@ -95,7 +95,7 @@
 
         option = {
             title: {
-                text: '月流量',
+                text: '月流量',
                 subtext: '单位G'
             },
             tooltip: {

+ 1 - 0
routes/web.php

@@ -19,6 +19,7 @@ Route::group(['middleware' => ['forbidden', 'user', 'admin']], function () {
     Route::get('admin/userList', 'AdminController@userList'); // 账号列表
     Route::any('admin/addUser', 'AdminController@addUser'); // 添加账号
     Route::post('admin/batchAddUsers', 'AdminController@batchAddUsers'); // 批量生成账号
+    Route::get('admin/exportSSJson', 'AdminController@exportSSJson'); // 导出原版SS的json配置信息
     Route::any('admin/editUser', 'AdminController@editUser'); // 编辑账号
     Route::post('admin/delUser', 'AdminController@delUser'); // 删除账号
     Route::get('admin/nodeList', 'AdminController@nodeList'); // 节点列表