2023-11-17 01:44:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Protocols;
|
|
|
|
|
2025-01-06 12:20:11 -05:00
|
|
|
use App\Contracts\ProtocolInterface;
|
2023-11-17 01:44:01 -05:00
|
|
|
|
2025-01-06 12:20:11 -05:00
|
|
|
class QuantumultX implements ProtocolInterface
|
2023-11-17 01:44:01 -05:00
|
|
|
{
|
2025-01-06 12:20:11 -05:00
|
|
|
public $flags = ['quantumult%20x'];
|
2023-11-17 01:44:01 -05:00
|
|
|
private $servers;
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function __construct($user, $servers)
|
|
|
|
{
|
|
|
|
$this->user = $user;
|
|
|
|
$this->servers = $servers;
|
|
|
|
}
|
|
|
|
|
2025-01-06 12:20:11 -05:00
|
|
|
public function getFlags(): array
|
|
|
|
{
|
|
|
|
return $this->flags;
|
|
|
|
}
|
|
|
|
|
2023-11-17 01:44:01 -05:00
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$servers = $this->servers;
|
|
|
|
$user = $this->user;
|
|
|
|
$uri = '';
|
|
|
|
foreach ($servers as $item) {
|
|
|
|
if ($item['type'] === 'shadowsocks') {
|
2024-05-24 10:45:27 -04:00
|
|
|
$uri .= self::buildShadowsocks($item['password'], $item);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
if ($item['type'] === 'vmess') {
|
|
|
|
$uri .= self::buildVmess($user['uuid'], $item);
|
|
|
|
}
|
|
|
|
if ($item['type'] === 'trojan') {
|
|
|
|
$uri .= self::buildTrojan($user['uuid'], $item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response(base64_encode($uri), 200)
|
2025-01-06 12:20:11 -05:00
|
|
|
->header('subscription-userinfo', "upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildShadowsocks($password, $server)
|
|
|
|
{
|
2025-01-06 12:20:11 -05:00
|
|
|
$protocol_settings = $server['protocol_settings'];
|
2025-01-09 02:58:32 -05:00
|
|
|
$password = data_get($server, 'password', $password);
|
2023-11-17 01:44:01 -05:00
|
|
|
$config = [
|
|
|
|
"shadowsocks={$server['host']}:{$server['port']}",
|
2025-01-06 12:20:11 -05:00
|
|
|
"method={$protocol_settings['cipher']}",
|
2023-11-17 01:44:01 -05:00
|
|
|
"password={$password}",
|
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
|
|
|
"tag={$server['name']}"
|
|
|
|
];
|
|
|
|
$config = array_filter($config);
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildVmess($uuid, $server)
|
|
|
|
{
|
2025-01-06 12:20:11 -05:00
|
|
|
$protocol_settings = $server['protocol_settings'];
|
2023-11-17 01:44:01 -05:00
|
|
|
$config = [
|
|
|
|
"vmess={$server['host']}:{$server['port']}",
|
|
|
|
'method=chacha20-poly1305',
|
|
|
|
"password={$uuid}",
|
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
|
|
|
"tag={$server['name']}"
|
|
|
|
];
|
|
|
|
|
2025-01-06 12:20:11 -05:00
|
|
|
if (data_get($protocol_settings, 'tls')) {
|
|
|
|
if (data_get($protocol_settings, 'network') === 'tcp')
|
2023-11-17 01:44:01 -05:00
|
|
|
array_push($config, 'obfs=over-tls');
|
2025-01-06 12:20:11 -05:00
|
|
|
if (data_get($protocol_settings, 'tls_settings')) {
|
|
|
|
if (data_get($protocol_settings, 'tls_settings.allow_insecure'))
|
|
|
|
array_push($config, 'tls-verification=' . ($protocol_settings['tls_settings']['allow_insecure'] ? 'false' : 'true'));
|
|
|
|
if (data_get($protocol_settings, 'tls_settings.server_name'))
|
|
|
|
$host = data_get($protocol_settings, 'tls_settings.server_name');
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
}
|
2025-01-06 12:20:11 -05:00
|
|
|
if (data_get($protocol_settings, 'network') === 'ws') {
|
|
|
|
if (data_get($protocol_settings, 'tls'))
|
2023-11-17 01:44:01 -05:00
|
|
|
array_push($config, 'obfs=wss');
|
|
|
|
else
|
|
|
|
array_push($config, 'obfs=ws');
|
2025-01-06 12:20:11 -05:00
|
|
|
if (data_get($protocol_settings, 'network_settings')) {
|
|
|
|
if (data_get($protocol_settings, 'network_settings.path'))
|
|
|
|
array_push($config, "obfs-uri={$protocol_settings['network_settings']['path']}");
|
|
|
|
if (data_get($protocol_settings, 'network_settings.headers.Host') && !isset($host))
|
|
|
|
$host = data_get($protocol_settings, 'network_settings.headers.Host');
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($host)) {
|
|
|
|
array_push($config, "obfs-host={$host}");
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildTrojan($password, $server)
|
|
|
|
{
|
2025-01-06 12:20:11 -05:00
|
|
|
$protocol_settings = $server['protocol_settings'];
|
2023-11-17 01:44:01 -05:00
|
|
|
$config = [
|
|
|
|
"trojan={$server['host']}:{$server['port']}",
|
|
|
|
"password={$password}",
|
|
|
|
'over-tls=true',
|
2025-01-06 12:20:11 -05:00
|
|
|
$protocol_settings['server_name'] ? "tls-host={$protocol_settings['server_name']}" : "",
|
2023-11-17 01:44:01 -05:00
|
|
|
// Tips: allowInsecure=false = tls-verification=true
|
2025-01-06 12:20:11 -05:00
|
|
|
$protocol_settings['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
|
2023-11-17 01:44:01 -05:00
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
|
|
|
"tag={$server['name']}"
|
|
|
|
];
|
|
|
|
$config = array_filter($config);
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|