Skip to content

Commit 5929f1e

Browse files
committed
1.下载二维码
2.每日节点使用情况报告
1 parent 22d3207 commit 5929f1e

9 files changed

Lines changed: 242 additions & 83 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Components\Helpers;
6+
use App\Components\ServerChan;
7+
use App\Http\Models\SsNode;
8+
use App\Http\Models\SsNodeTrafficDaily;
9+
use Illuminate\Console\Command;
10+
use Log;
11+
12+
class AutoReportNode extends Command
13+
{
14+
protected $signature = 'autoReportNode';
15+
protected $description = '自动报告节点使用情况';
16+
protected static $systemConfig;
17+
18+
public function __construct()
19+
{
20+
parent::__construct();
21+
self::$systemConfig = Helpers::systemConfig();
22+
}
23+
24+
public function handle()
25+
{
26+
$jobStartTime = microtime(true);
27+
28+
if (self::$systemConfig['node_daily_report']) {
29+
$nodeList = SsNode::query()->where('status', 1)->get();
30+
if (!empty($nodeList)) {
31+
foreach ($nodeList as $node) {
32+
$log = SsNodeTrafficDaily::query()
33+
->where('node_id', $node->id)
34+
->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime("-1 day")))
35+
->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime("-1 day")))
36+
->first();
37+
38+
if ($log) {
39+
$this->notifyMasterByServerchan('节点使用情况日报', '节点**' . $node->name . ',上行流量:' . flowAutoShow($node->u) . ',下行流量:' . flowAutoShow($node->d) . ',共计:' . $node->traffic . '**');
40+
}
41+
}
42+
}
43+
}
44+
45+
$jobEndTime = microtime(true);
46+
$jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
47+
48+
Log::info('执行定时任务【' . $this->description . '】,耗时' . $jobUsedTime . '');
49+
}
50+
51+
/**
52+
* 通过ServerChan发微信消息提醒管理员
53+
*
54+
* @param string $title 消息标题
55+
* @param string $content 消息内容
56+
*
57+
* @throws \GuzzleHttp\Exception\GuzzleException
58+
*/
59+
private function notifyMasterByServerchan($title, $content)
60+
{
61+
if (self::$systemConfig['is_server_chan'] && self::$systemConfig['server_chan_key']) {
62+
$serverChan = new ServerChan();
63+
$serverChan->send($title, $content);
64+
}
65+
}
66+
}

app/Console/Commands/upgradeUserVmess.php renamed to app/Console/Commands/upgradeUserVmessId.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use App\Http\Models\User;
66
use Illuminate\Console\Command;
77

8-
class upgradeUserVmess extends Command
8+
class upgradeUserVmessId extends Command
99
{
10-
protected $signature = 'upgradeUserVmess';
11-
protected $description = '更新用户的Vmess';
10+
protected $signature = 'upgradeUserVmessId';
11+
protected $description = '重新生成用户的vmess_id字段';
1212

1313
public function __construct()
1414
{

app/Console/Kernel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class Kernel extends ConsoleKernel
2626
\App\Console\Commands\UserExpireAutoWarning::class,
2727
\App\Console\Commands\UserTrafficAutoWarning::class,
2828
\App\Console\Commands\upgradeUserPassword::class,
29-
\App\Console\Commands\upgradeUserVmess::class,
29+
\App\Console\Commands\upgradeUserVmessId::class,
30+
\App\Console\Commands\AutoReportNode::class,
3031
];
3132

3233
/**
@@ -50,6 +51,7 @@ protected function schedule(Schedule $schedule)
5051
$schedule->command('userTrafficAbnormalAutoWarning')->hourly();
5152
$schedule->command('userExpireAutoWarning')->dailyAt('20:00');
5253
$schedule->command('userTrafficAutoWarning')->dailyAt('10:30');
54+
$schedule->command('autoReportNode')->dailyAt('09:00');
5355
}
5456

5557
/**

app/Http/Controllers/AdminController.php

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,46 +1328,81 @@ public function export(Request $request)
13281328
// 获取分组名称
13291329
$group = SsGroup::query()->where('id', $node->group_id)->first();
13301330

1331-
// 生成ssr scheme
1332-
$obfs_param = $user->obfs_param ? $user->obfs_param : $node->obfs_param;
1333-
$protocol_param = $node->single ? $user->port . ':' . $user->passwd : $user->protocol_param;
1334-
1335-
$ssr_str = ($node->server ? $node->server : $node->ip) . ':' . ($node->single ? $node->single_port : $user->port);
1336-
$ssr_str .= ':' . ($node->single ? $node->single_protocol : $user->protocol) . ':' . ($node->single ? $node->single_method : $user->method);
1337-
$ssr_str .= ':' . ($node->single ? $node->single_obfs : $user->obfs) . ':' . ($node->single ? base64url_encode($node->single_passwd) : base64url_encode($user->passwd));
1338-
$ssr_str .= '/?obfsparam=' . base64url_encode($obfs_param);
1339-
$ssr_str .= '&protoparam=' . ($node->single ? base64url_encode($user->port . ':' . $user->passwd) : base64url_encode($protocol_param));
1340-
$ssr_str .= '&remarks=' . base64url_encode($node->name);
1341-
$ssr_str .= '&group=' . base64url_encode(empty($group) ? '' : $group->name);
1342-
$ssr_str .= '&udpport=0';
1343-
$ssr_str .= '&uot=0';
1344-
$ssr_str = base64url_encode($ssr_str);
1345-
$ssr_scheme = 'ssr://' . $ssr_str;
1346-
1347-
// 生成ss scheme
1348-
$ss_str = $user->method . ':' . $user->passwd . '@';
1349-
$ss_str .= ($node->server ? $node->server : $node->ip) . ':' . $user->port;
1350-
$ss_str = base64url_encode($ss_str) . '#' . 'VPN';
1351-
$ss_scheme = 'ss://' . $ss_str;
1352-
1353-
// 生成配置信息
1354-
$txt = "服务器:" . ($node->server ? $node->server : $node->ip) . "\r\n";
1355-
if ($node->ipv6) {
1356-
$txt .= "IPv6:" . $node->ipv6 . "\r\n";
1331+
if ($node->type == 1) {
1332+
// 生成ssr scheme
1333+
$obfs_param = $user->obfs_param ? $user->obfs_param : $node->obfs_param;
1334+
$protocol_param = $node->single ? $user->port . ':' . $user->passwd : $user->protocol_param;
1335+
1336+
$ssr_str = ($node->server ? $node->server : $node->ip) . ':' . ($node->single ? $node->single_port : $user->port);
1337+
$ssr_str .= ':' . ($node->single ? $node->single_protocol : $user->protocol) . ':' . ($node->single ? $node->single_method : $user->method);
1338+
$ssr_str .= ':' . ($node->single ? $node->single_obfs : $user->obfs) . ':' . ($node->single ? base64url_encode($node->single_passwd) : base64url_encode($user->passwd));
1339+
$ssr_str .= '/?obfsparam=' . base64url_encode($obfs_param);
1340+
$ssr_str .= '&protoparam=' . ($node->single ? base64url_encode($user->port . ':' . $user->passwd) : base64url_encode($protocol_param));
1341+
$ssr_str .= '&remarks=' . base64url_encode($node->name);
1342+
$ssr_str .= '&group=' . base64url_encode(empty($group) ? '' : $group->name);
1343+
$ssr_str .= '&udpport=0';
1344+
$ssr_str .= '&uot=0';
1345+
$ssr_str = base64url_encode($ssr_str);
1346+
$ssr_scheme = 'ssr://' . $ssr_str;
1347+
1348+
// 生成ss scheme
1349+
$ss_str = $user->method . ':' . $user->passwd . '@';
1350+
$ss_str .= ($node->server ? $node->server : $node->ip) . ':' . $user->port;
1351+
$ss_str = base64url_encode($ss_str) . '#' . 'VPN';
1352+
$ss_scheme = 'ss://' . $ss_str;
1353+
1354+
// 生成配置信息
1355+
$txt = "服务器:" . ($node->server ? $node->server : $node->ip) . "\r\n";
1356+
if ($node->ipv6) {
1357+
$txt .= "IPv6:" . $node->ipv6 . "\r\n";
1358+
}
1359+
$txt .= "远程端口:" . ($node->single ? $node->single_port : $user->port) . "\r\n";
1360+
$txt .= "密码:" . ($node->single ? $node->single_passwd : $user->passwd) . "\r\n";
1361+
$txt .= "加密方法:" . ($node->single ? $node->single_method : $user->method) . "\r\n";
1362+
$txt .= "路由:绕过局域网及中国大陆地址\r\n\r\n";
1363+
$txt .= "协议:" . ($node->single ? $node->single_protocol : $user->protocol) . "\r\n";
1364+
$txt .= "协议参数:" . ($node->single ? $user->port . ':' . $user->passwd : $user->protocol_param) . "\r\n";
1365+
$txt .= "混淆方式:" . ($node->single ? $node->single_obfs : $user->obfs) . "\r\n";
1366+
$txt .= "混淆参数:" . ($user->obfs_param ? $user->obfs_param : $node->obfs_param) . "\r\n";
1367+
$txt .= "本地端口:1080\r\n";
1368+
1369+
$node->txt = $txt;
1370+
$node->ssr_scheme = $ssr_scheme;
1371+
$node->ss_scheme = $node->compatible ? $ss_scheme : ''; // 节点兼容原版才显示
1372+
} else {
1373+
// 生成v2ray scheme
1374+
$v2_json = [
1375+
"v" => "2",
1376+
"ps" => $node->name,
1377+
"add" => $node->server ? $node->server : $node->ip,
1378+
"port" => $node->v2_port,
1379+
"id" => $user->vmess_id,
1380+
"aid" => $node->v2_alter_id,
1381+
"net" => $node->v2_net,
1382+
"type" => $node->v2_type,
1383+
"host" => $node->v2_host,
1384+
"path" => $node->v2_path,
1385+
"tls" => $node->v2_tls == 1 ? "tls" : ""
1386+
];
1387+
$v2_scheme = 'vmess://' . base64url_encode(json_encode($v2_json));
1388+
1389+
// 生成文本配置信息
1390+
$txt = "服务器:" . ($node->server ? $node->server : $node->ip) . "\r\n";
1391+
if ($node->ipv6) {
1392+
$txt .= "IPv6:" . $node->ipv6 . "\r\n";
1393+
}
1394+
$txt .= "端口:" . $node->v2_port . "\r\n";
1395+
$txt .= "用户ID:" . $user->vmess_id . "\r\n";
1396+
$txt .= "额外ID:" . $node->v2_alter_id . "\r\n";
1397+
$txt .= "传输协议:" . $node->v2_net . "\r\n";
1398+
$txt .= "伪装类型:" . $node->v2_type . "\r\n";
1399+
$txt .= $node->v2_host ? "伪装域名:" . $node->v2_host . "\r\n" : "";
1400+
$txt .= $node->v2_path ? "路径:" . $node->v2_path . "\r\n" : "";
1401+
$txt .= $node->v2_tls == 1 ? "TLS:tls\r\n" : "";
1402+
1403+
$node->txt = $txt;
1404+
$node->v2_scheme = $v2_scheme;
13571405
}
1358-
$txt .= "远程端口:" . ($node->single ? $node->single_port : $user->port) . "\r\n";
1359-
$txt .= "密码:" . ($node->single ? $node->single_passwd : $user->passwd) . "\r\n";
1360-
$txt .= "加密方法:" . ($node->single ? $node->single_method : $user->method) . "\r\n";
1361-
$txt .= "路由:绕过局域网及中国大陆地址\r\n\r\n";
1362-
$txt .= "协议:" . ($node->single ? $node->single_protocol : $user->protocol) . "\r\n";
1363-
$txt .= "协议参数:" . ($node->single ? $user->port . ':' . $user->passwd : $user->protocol_param) . "\r\n";
1364-
$txt .= "混淆方式:" . ($node->single ? $node->single_obfs : $user->obfs) . "\r\n";
1365-
$txt .= "混淆参数:" . ($user->obfs_param ? $user->obfs_param : $node->obfs_param) . "\r\n";
1366-
$txt .= "本地端口:1080\r\n";
1367-
1368-
$node->txt = $txt;
1369-
$node->ssr_scheme = $ssr_scheme;
1370-
$node->ss_scheme = $node->compatible ? $ss_scheme : ''; // 节点兼容原版才显示
13711406
}
13721407

13731408
$view['nodeList'] = $nodeList;

resources/views/admin/export.blade.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,17 @@
9191
<h4 class="modal-title">Scheme Links - {{$node->name}}</h4>
9292
</div>
9393
<div class="modal-body">
94-
<textarea class="form-control" rows="5" readonly="readonly">{{$node->ssr_scheme}}</textarea>
95-
<a href="{{$node->ssr_scheme}}" class="btn purple uppercase" style="display: block; width: 100%;margin-top: 10px;">打开SSR</a>
96-
@if($node->ss_scheme)
97-
<p></p>
98-
<textarea class="form-control" rows="3" readonly="readonly">{{$node->ss_scheme}}</textarea>
99-
<a href="{{$node->ss_scheme}}" class="btn blue uppercase" style="display: block; width: 100%;margin-top: 10px;">打开SS</a>
94+
@if($node->type ==1)
95+
<textarea class="form-control" rows="5" readonly="readonly">{{$node->ssr_scheme}}</textarea>
96+
<a href="{{$node->ssr_scheme}}" class="btn purple uppercase" style="display: block; width: 100%;margin-top: 10px;">打开SSR</a>
97+
@if($node->ss_scheme)
98+
<p></p>
99+
<textarea class="form-control" rows="3" readonly="readonly">{{$node->ss_scheme}}</textarea>
100+
<a href="{{$node->ss_scheme}}" class="btn blue uppercase" style="display: block; width: 100%;margin-top: 10px;">打开SS</a>
101+
@endif
102+
@else
103+
<textarea class="form-control" rows="5" readonly="readonly">{{$node->v2_scheme}}</textarea>
104+
<a href="{{$node->v2_scheme}}" class="btn purple uppercase" style="display: block; width: 100%;margin-top: 10px;">打开V2Ray</a>
100105
@endif
101106
</div>
102107
</div>
@@ -111,16 +116,26 @@
111116
</div>
112117
<div class="modal-body">
113118
<div class="row">
114-
@if ($node->compatible)
115-
<div class="col-md-6">
116-
<div id="qrcode_ssr_img_{{$node->id}}" style="text-align: center;"></div>
117-
</div>
118-
<div class="col-md-6">
119-
<div id="qrcode_ss_img_{{$node->id}}" style="text-align: center;"></div>
120-
</div>
119+
@if($node->type == 1)
120+
@if($node->compatible)
121+
<div class="col-md-6">
122+
<div id="qrcode_ssr_img_{{$node->id}}" style="text-align: center;"></div>
123+
<div style="text-align: center;"><a id="download_qrcode_ssr_img_{{$node->id}}">下载二维码</a></div>
124+
</div>
125+
<div class="col-md-6">
126+
<div id="qrcode_ss_img_{{$node->id}}" style="text-align: center;"></div>
127+
<div style="text-align: center;"><a id="download_qrcode_ss_img_{{$node->id}}">下载二维码</a></div>
128+
</div>
129+
@else
130+
<div class="col-md-12">
131+
<div id="qrcode_ssr_img_{{$node->id}}" style="text-align: center;"></div>
132+
<div style="text-align: center;"><a id="download_qrcode_ssr_img_{{$node->id}}">下载二维码</a></div>
133+
</div>
134+
@endif
121135
@else
122136
<div class="col-md-12">
123-
<div id="qrcode_ssr_img_{{$node->id}}" style="text-align: center;"></div>
137+
<div id="qrcode_v2_img_{{$node->id}}" style="text-align: center;"></div>
138+
<div style="text-align: center;"><a id="download_qrcode_v2_img_{{$node->id}}">下载二维码</a></div>
124139
</div>
125140
@endif
126141
</div>
@@ -165,8 +180,15 @@
165180
166181
// 循环输出节点scheme用于生成二维码
167182
@foreach ($nodeList as $node)
168-
$('#qrcode_ssr_img_{{$node->id}}').qrcode("{{$node->ssr_scheme}}");
169-
$('#qrcode_ss_img_{{$node->id}}').qrcode("{{$node->ss_scheme}}");
183+
@if($node->type == 1)
184+
$('#qrcode_ssr_img_{{$node->id}}').qrcode("{{$node->ssr_scheme}}");
185+
$('#download_qrcode_ssr_img_{{$node->id}}').attr({'download':'code','href':$('#qrcode_ssr_img_{{$node->id}} canvas')[0].toDataURL("image/png")})
186+
$('#qrcode_ss_img_{{$node->id}}').qrcode("{{$node->ss_scheme}}");
187+
$('#download_qrcode_ss_img_{{$node->id}}').attr({'download':'code','href':$('#qrcode_ss_img_{{$node->id}} canvas')[0].toDataURL("image/png")})
188+
@else
189+
$('#qrcode_v2_img_{{$node->id}}').qrcode("{{$node->v2_scheme}}");
190+
$('#download_qrcode_v2_img_{{$node->id}}').attr({'download':'code','href':$('#qrcode_v2_img_{{$node->id}} canvas')[0].toDataURL("image/png")})
191+
@endif
170192
@endforeach
171193
</script>
172194
@endsection

0 commit comments

Comments
 (0)