From 3e0abe93ab9706c12d1d7e652edda9e58c57c680 Mon Sep 17 00:00:00 2001 From: coldice945 Date: Sun, 13 Nov 2022 23:54:47 +0800 Subject: [PATCH] feature: add a subscription information panel to Surge and Surfboard for easy viewing --- app/Http/Controllers/Client/Protocols/Surfboard.php | 8 ++++++++ app/Http/Controllers/Client/Protocols/Surge.php | 8 ++++++++ resources/rules/default.surfboard.conf | 3 +++ resources/rules/default.surge.conf | 3 +++ 4 files changed, 22 insertions(+) diff --git a/app/Http/Controllers/Client/Protocols/Surfboard.php b/app/Http/Controllers/Client/Protocols/Surfboard.php index 1864a409..918ff7db 100644 --- a/app/Http/Controllers/Client/Protocols/Surfboard.php +++ b/app/Http/Controllers/Client/Protocols/Surfboard.php @@ -64,6 +64,14 @@ class Surfboard $config = str_replace('$subs_domain', $subsDomain, $config); $config = str_replace('$proxies', $proxies, $config); $config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config); + + $upload = round($user['u'] / (1024*1024*1024), 2); + $download = round($user['d'] / (1024*1024*1024), 2); + $totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2); + $expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']); + $subscribeInfo = "title=\"{$appName}订阅信息\", content=\"上传流量:{$upload}GB\\n下载流量:{$download}GB\\n已用总流量:{$totalTraffic}GB\\n到期时间:{$expireDate}\""; + $config = str_replace('$subscribe_info', $subscribeInfo, $config); + return $config; } diff --git a/app/Http/Controllers/Client/Protocols/Surge.php b/app/Http/Controllers/Client/Protocols/Surge.php index c41edbed..dfdeedce 100644 --- a/app/Http/Controllers/Client/Protocols/Surge.php +++ b/app/Http/Controllers/Client/Protocols/Surge.php @@ -64,6 +64,14 @@ class Surge $config = str_replace('$subs_domain', $subsDomain, $config); $config = str_replace('$proxies', $proxies, $config); $config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config); + + $upload = round($user['u'] / (1024*1024*1024), 2); + $download = round($user['d'] / (1024*1024*1024), 2); + $totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2); + $expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']); + $subscribeInfo = "title=\"{$appName}订阅信息\", content=\"上传流量:{$upload}GB\\n下载流量:{$download}GB\\n已用总流量:{$totalTraffic}GB\\n到期时间:{$expireDate}\""; + $config = str_replace('$subscribe_info', $subscribeInfo, $config); + return $config; } diff --git a/resources/rules/default.surfboard.conf b/resources/rules/default.surfboard.conf index 8d0cd515..e0d1bc17 100644 --- a/resources/rules/default.surfboard.conf +++ b/resources/rules/default.surfboard.conf @@ -12,6 +12,9 @@ test-timeout = 5 internet-test-url = http://bing.com proxy-test-url = http://bing.com +[Panel] +SubscribeInfo = $subscribe_info, style=info + # Surfboard 的服务器和策略组配置方式与 Surge 类似, 可以参考 Surge 的规则配置手册: https://manual.nssurge.com/ [Proxy] diff --git a/resources/rules/default.surge.conf b/resources/rules/default.surge.conf index 501822e7..1560bbe3 100644 --- a/resources/rules/default.surge.conf +++ b/resources/rules/default.surge.conf @@ -36,6 +36,9 @@ hide-crashlytics-request = true use-keyword-filter = false hide-udp = false +[Panel] +SubscribeInfo = $subscribe_info, style=info + # ----------------------------- # Surge 的几种策略配置规范,请参考 https://manual.nssurge.com/policy/proxy.html # 不同的代理策略有*很多*可选参数,请参考上方连接的 Parameters 一段,根据需求自行添加参数。