update: add vless

This commit is contained in:
v2board
2023-07-17 15:40:08 +08:00
parent 1a30aa30ad
commit 4c865d0262
9 changed files with 247 additions and 16 deletions

View File

@ -6,6 +6,7 @@ use App\Models\ServerHysteria;
use App\Models\ServerLog;
use App\Models\ServerRoute;
use App\Models\ServerShadowsocks;
use App\Models\ServerVless;
use App\Models\User;
use App\Models\ServerVmess;
use App\Models\ServerTrojan;
@ -15,6 +16,29 @@ use Illuminate\Support\Facades\Cache;
class ServerService
{
public function getAvailableVless(User $user):array
{
$servers = [];
$model = ServerVless::orderBy('sort', 'ASC');
$server = $model->get();
foreach ($server as $key => $v) {
if (!$v['show']) continue;
$server[$key]['type'] = 'vless';
if (!in_array($user->group_id, $server[$key]['group_id'])) continue;
if (strpos($server[$key]['port'], '-') !== false) {
$server[$key]['port'] = Helper::randomPort($server[$key]['port']);
}
if ($server[$key]['parent_id']) {
$server[$key]['last_check_at'] = Cache::get(CacheKey::get('SERVER_VLESS_LAST_CHECK_AT', $server[$key]['parent_id']));
} else {
$server[$key]['last_check_at'] = Cache::get(CacheKey::get('SERVER_VLESS_LAST_CHECK_AT', $server[$key]['id']));
}
$servers[] = $server[$key]->toArray();
}
return $servers;
}
public function getAvailableVmess(User $user):array
{
@ -113,7 +137,8 @@ class ServerService
$this->getAvailableShadowsocks($user),
$this->getAvailableVmess($user),
$this->getAvailableTrojan($user),
$this->getAvailableHysteria($user)
$this->getAvailableHysteria($user),
$this->getAvailableVless($user)
);
$tmp = array_column($servers, 'sort');
array_multisort($tmp, SORT_ASC, $servers);
@ -196,6 +221,17 @@ class ServerService
return $servers;
}
public function getAllVLess()
{
$servers = ServerVless::orderBy('sort', 'ASC')
->get()
->toArray();
foreach ($servers as $k => $v) {
$servers[$k]['type'] = 'vless';
}
return $servers;
}
public function getAllTrojan()
{
$servers = ServerTrojan::orderBy('sort', 'ASC')
@ -241,7 +277,8 @@ class ServerService
$this->getAllShadowsocks(),
$this->getAllVMess(),
$this->getAllTrojan(),
$this->getAllHysteria()
$this->getAllHysteria(),
$this->getAllVLess()
);
$this->mergeData($servers);
$tmp = array_column($servers, 'sort');
@ -272,6 +309,8 @@ class ServerService
return ServerTrojan::find($serverId);
case 'hysteria':
return ServerHysteria::find($serverId);
case 'vless':
return ServerVless::find($serverId);
default:
return false;
}