2020-06-12 00:35:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
|
|
|
|
class QuantumultX
|
|
|
|
{
|
2020-10-04 22:55:40 +08:00
|
|
|
public static function buildShadowsocks($password, $server)
|
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
"shadowsocks={$server->host}:{$server->port}",
|
|
|
|
"method={$server->cipher}",
|
|
|
|
"password={$password}",
|
|
|
|
"fast-open=true",
|
|
|
|
"udp-relay=true",
|
|
|
|
"tag={$server->name}"
|
|
|
|
];
|
|
|
|
$config = array_filter($config);
|
|
|
|
$uri = implode(',', $config);
|
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
2020-06-12 00:35:35 +08:00
|
|
|
public static function buildVmess($uuid, $server)
|
|
|
|
{
|
2020-07-25 15:34:25 +08:00
|
|
|
$config = [
|
|
|
|
"vmess={$server->host}:{$server->port}",
|
|
|
|
"method=chacha20-poly1305",
|
|
|
|
"password={$uuid}",
|
|
|
|
"tag={$server->name}"
|
|
|
|
];
|
|
|
|
if ($server->network === 'tcp') {
|
|
|
|
if ($server->tls) {
|
|
|
|
$tlsSettings = json_decode($server->tlsSettings);
|
|
|
|
array_push($config, 'obfs=over-tls');
|
|
|
|
if (isset($tlsSettings->allowInsecure)) {
|
2020-07-29 20:08:51 +08:00
|
|
|
// Tips: allowInsecure=false = tls-verification=true
|
|
|
|
array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true');
|
2020-07-25 15:34:25 +08:00
|
|
|
}
|
|
|
|
if (isset($tlsSettings->serverName)) {
|
|
|
|
array_push($config, "obfs-host={$tlsSettings->serverName}");
|
|
|
|
}
|
2020-06-12 00:35:35 +08:00
|
|
|
}
|
|
|
|
}
|
2020-07-25 15:34:25 +08:00
|
|
|
|
2020-06-12 00:35:35 +08:00
|
|
|
if ($server->network === 'ws') {
|
2020-07-25 15:34:25 +08:00
|
|
|
if ($server->tls) {
|
|
|
|
$tlsSettings = json_decode($server->tlsSettings);
|
|
|
|
array_push($config, 'obfs=wss');
|
|
|
|
if (isset($tlsSettings->allowInsecure)) {
|
2020-07-29 20:08:51 +08:00
|
|
|
array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true');
|
2020-07-25 15:34:25 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
array_push($config, 'obfs=ws');
|
|
|
|
}
|
2020-06-12 00:35:35 +08:00
|
|
|
if ($server->networkSettings) {
|
|
|
|
$wsSettings = json_decode($server->networkSettings);
|
2020-07-25 15:34:25 +08:00
|
|
|
if (isset($wsSettings->path)) array_push($config, "obfs-uri={$wsSettings->path}");
|
|
|
|
if (isset($wsSettings->headers->Host)) array_push($config, "obfs-host={$wsSettings->headers->Host}");
|
2020-06-12 00:35:35 +08:00
|
|
|
}
|
|
|
|
}
|
2020-07-25 15:34:25 +08:00
|
|
|
|
2020-07-28 16:11:27 +08:00
|
|
|
$uri = implode(',', $config);
|
2020-06-12 00:35:35 +08:00
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function buildTrojan($password, $server)
|
|
|
|
{
|
2020-07-01 18:31:44 +08:00
|
|
|
$config = [
|
|
|
|
"trojan={$server->host}:{$server->port}",
|
|
|
|
"password={$password}",
|
|
|
|
"over-tls=true",
|
|
|
|
$server->server_name ? "tls-host={$server->server_name}" : "",
|
2020-07-29 20:08:51 +08:00
|
|
|
// Tips: allowInsecure=false = tls-verification=true
|
|
|
|
$server->allow_insecure ? 'tls-verification=false' : 'tls-verification=true',
|
2020-07-01 18:31:44 +08:00
|
|
|
"fast-open=false",
|
|
|
|
"udp-relay=false",
|
|
|
|
"tag={$server->name}"
|
|
|
|
];
|
|
|
|
$config = array_filter($config);
|
2020-07-28 16:11:27 +08:00
|
|
|
$uri = implode(',', $config);
|
2020-06-12 00:35:35 +08:00
|
|
|
$uri .= "\r\n";
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|