mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-14 08:23:27 +00:00
Standardize sub-url display for different proxy types
This commit is contained in:
@@ -4,32 +4,18 @@ namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Article;
|
||||
use App\Models\Node;
|
||||
use App\Services\ArticleService;
|
||||
use App\Services\NodeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(NodeService $nodeService)
|
||||
{ // 帮助中心
|
||||
$data = [];
|
||||
if (Node::whereType(0)->whereStatus(1)->exists()) {
|
||||
$data[] = 'ss';
|
||||
}
|
||||
if (Node::whereIn('type', [1, 4])->whereStatus(1)->exists()) {
|
||||
$data[] = 'ssr';
|
||||
}
|
||||
if (Node::whereType(2)->whereStatus(1)->exists()) {
|
||||
$data[] = 'v2';
|
||||
}
|
||||
if (Node::whereType(3)->whereStatus(1)->exists()) {
|
||||
$data[] = 'trojan';
|
||||
}
|
||||
|
||||
$subscribe = auth()->user()->subscribe;
|
||||
|
||||
return view('user.knowledge', [
|
||||
'subType' => $data,
|
||||
'subType' => $nodeService->getActiveNodeTypes(),
|
||||
'subUrl' => route('sub', $subscribe->code),
|
||||
'subStatus' => $subscribe->status,
|
||||
'subMsg' => $subscribe->ban_desc,
|
||||
|
||||
@@ -17,9 +17,8 @@ class SubscribeController extends Controller
|
||||
|
||||
private ProxyService $proxyServer;
|
||||
|
||||
// 通过订阅码获取订阅信息
|
||||
public function getSubscribeByCode(Request $request, string $code): RedirectResponse|string
|
||||
{
|
||||
{ // 通过订阅码获取订阅信息
|
||||
preg_match('/[0-9A-Za-z]+/', $code, $matches, PREG_UNMATCHED_AS_NULL);
|
||||
|
||||
if (empty($matches) || empty($code)) {
|
||||
@@ -31,6 +30,7 @@ class SubscribeController extends Controller
|
||||
// 检查订阅码是否有效
|
||||
$subscribe = UserSubscribe::whereCode($code)->first();
|
||||
$this->proxyServer = new ProxyService;
|
||||
|
||||
if (! $subscribe) {
|
||||
$this->failed(trans('errors.subscribe.unknown'));
|
||||
}
|
||||
@@ -39,10 +39,8 @@ class SubscribeController extends Controller
|
||||
$this->failed(trans('errors.subscribe.sub_banned'));
|
||||
}
|
||||
|
||||
// 检查用户是否有效
|
||||
$user = $subscribe->user;
|
||||
$this->proxyServer->setUser($user);
|
||||
if (! $user) {
|
||||
if (! $user) { // 检查用户是否有效
|
||||
$this->failed(trans('errors.subscribe.user'));
|
||||
}
|
||||
|
||||
@@ -66,6 +64,7 @@ class SubscribeController extends Controller
|
||||
|
||||
$this->failed(trans('errors.subscribe.question'));
|
||||
}
|
||||
$this->proxyServer->setUser($user);
|
||||
|
||||
$subscribe->increment('times'); // 更新访问次数
|
||||
$this->subscribeLog($subscribe->id, IP::getClientIp(), json_encode(['Host' => $request->getHost(), 'User-Agent' => $request->userAgent()])); // 记录每次请求
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\DataChart;
|
||||
use App\Models\Article;
|
||||
use App\Services\NodeService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helpers;
|
||||
use Cache;
|
||||
@@ -23,7 +24,7 @@ class UserController extends Controller
|
||||
{
|
||||
use DataChart;
|
||||
|
||||
public function index()
|
||||
public function index(NodeService $nodeService)
|
||||
{
|
||||
// 用户转换
|
||||
if (Session::has('user')) {
|
||||
@@ -34,18 +35,6 @@ class UserController extends Controller
|
||||
$usedTransfer = $user->used_traffic;
|
||||
$unusedTraffic = max($totalTransfer - $usedTransfer, 0);
|
||||
|
||||
$nodes = $user->nodes()->get();
|
||||
$subType = [];
|
||||
if ($nodes->whereIn('type', [1, 4])->isNotEmpty()) {
|
||||
$subType[] = 'ss';
|
||||
}
|
||||
if ($nodes->where('type', 2)->isNotEmpty()) {
|
||||
$subType[] = 'v2';
|
||||
}
|
||||
if ($nodes->where('type', 3)->isNotEmpty()) {
|
||||
$subType[] = 'trojan';
|
||||
}
|
||||
|
||||
return view('user.index', array_merge([
|
||||
'remainDays' => now()->diffInDays($user->expired_at, false),
|
||||
'resetDays' => $user->reset_time ? now()->diffInDays($user->reset_time, false) : null,
|
||||
@@ -59,7 +48,7 @@ class UserController extends Controller
|
||||
'userLoginLog' => $user->loginLogs()->latest()->first(), // 近期登录日志
|
||||
'subscribe_status' => $user->subscribe->status,
|
||||
'subMsg' => $user->subscribe->ban_desc,
|
||||
'subType' => $subType,
|
||||
'subType' => $nodeService->getActiveNodeTypes($user->nodes()),
|
||||
'subUrl' => $user->subUrl(),
|
||||
], $this->dataFlowChart($user->id)));
|
||||
}
|
||||
|
||||
32
app/Services/NodeService.php
Normal file
32
app/Services/NodeService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Node;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class NodeService
|
||||
{
|
||||
public function getActiveNodeTypes(?Builder $nodes = null): array
|
||||
{
|
||||
if (! $nodes) {
|
||||
$nodes = Node::whereStatus(1);
|
||||
}
|
||||
$types = $nodes->pluck('type')->unique();
|
||||
|
||||
if ($types->contains(0)) {
|
||||
$data[] = 'ss';
|
||||
}
|
||||
if ($types->contains(1) || $types->contains(4)) {
|
||||
$data[] = 'ssr';
|
||||
}
|
||||
if ($types->contains(2)) {
|
||||
$data[] = 'v2';
|
||||
}
|
||||
if ($types->contains(3)) {
|
||||
$data[] = 'trojan';
|
||||
}
|
||||
|
||||
return $data ?? [];
|
||||
}
|
||||
}
|
||||
@@ -150,20 +150,21 @@ class ProxyService
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function failedProxyReturn(string $text, ?int $type = 1): void
|
||||
public function failedProxyReturn(string $text, ?int $type = 0): void
|
||||
{
|
||||
$url = sysConfig('website_url');
|
||||
|
||||
$data = [
|
||||
'name' => $text,
|
||||
'type' => [1 => 'shadowsocks', 2 => 'vmess', 3 => 'trojan'][$type],
|
||||
'type' => [0 => 'shadowsocks', 1 => 'shadowsocksr', 2 => 'vmess', 3 => 'trojan'][$type],
|
||||
'host' => $url,
|
||||
'port' => 0,
|
||||
'udp' => 0,
|
||||
];
|
||||
|
||||
$addition = match ($type) {
|
||||
1 => ['method' => 'none', 'passwd' => 'error'],
|
||||
0 => ['method' => 'none', 'passwd' => 'error'],
|
||||
1 => ['method' => 'none', 'passwd' => 'error', 'obfs' => 'origin', 'obfs_param' => '', 'protocol' => 'plain', 'protocol_param' => ''],
|
||||
2 => ['uuid' => '0', 'v2_alter_id' => 0, 'method' => 'auto'],
|
||||
3 => ['passwd' => 'error']
|
||||
};
|
||||
|
||||
@@ -155,7 +155,10 @@
|
||||
<select class="form-control" id="subType" name="subType" data-plugin="selectpicker"
|
||||
data-style="btn-outline btn-primary" title="{{ trans('common.all') }}">
|
||||
@if (in_array('ss', $subType, true))
|
||||
<option value="1">{{ trans('user.subscribe.ss_only') }}</option>
|
||||
<option value="0">{{ trans('user.subscribe.ss_only') }}</option>
|
||||
@endif
|
||||
@if (in_array('ssr', $subType, true))
|
||||
<option value="1">{{ trans('user.subscribe.ssr_only') }}</option>
|
||||
@endif
|
||||
@if (in_array('v2', $subType, true))
|
||||
<option value="2">{{ trans('user.subscribe.v2ray_only') }}</option>
|
||||
|
||||
Reference in New Issue
Block a user