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 = [
|
2020-11-15 17:10:32 +08:00
|
|
|
"shadowsocks={$server['host']}:{$server['port']}",
|
|
|
|
"method={$server['cipher']}",
|
2020-10-04 22:55:40 +08:00
|
|
|
"password={$password}",
|
2020-10-09 21:47:36 +08:00
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
2020-11-15 17:10:32 +08:00
|
|
|
"tag={$server['name']}"
|
2020-10-04 22:55:40 +08:00
|
|
|
];
|
|
|
|
$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 = [
|
2020-11-15 17:10:32 +08:00
|
|
|
"vmess={$server['host']}:{$server['port']}",
|
2020-10-09 21:47:36 +08:00
|
|
|
'method=chacha20-poly1305',
|
2020-07-25 15:34:25 +08:00
|
|
|
"password={$uuid}",
|
2020-10-09 21:47:36 +08:00
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
2020-11-15 17:10:32 +08:00
|
|
|
"tag={$server['name']}"
|
2020-07-25 15:34:25 +08:00
|
|
|
];
|
2020-11-20 00:26:39 +08:00
|
|
|
|
|
|
|
if ($server['tls']) {
|
2020-12-16 23:49:34 +08:00
|
|
|
if ($server['network'] === 'tcp')
|
2020-07-25 15:34:25 +08:00
|
|
|
array_push($config, 'obfs=over-tls');
|
2020-11-20 00:26:39 +08:00
|
|
|
if ($server['tlsSettings']) {
|
2020-11-15 17:10:32 +08:00
|
|
|
$tlsSettings = json_decode($server['tlsSettings'], true);
|
2020-11-20 00:26:39 +08:00
|
|
|
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
2020-12-11 01:09:49 +08:00
|
|
|
array_push($config, 'tls-verification=' . ($tlsSettings['allowInsecure'] ? 'false' : 'true'));
|
2020-12-16 23:49:34 +08:00
|
|
|
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
|
|
|
$host = $tlsSettings['serverName'];
|
2020-07-25 15:34:25 +08:00
|
|
|
}
|
2020-11-20 00:26:39 +08:00
|
|
|
}
|
|
|
|
if ($server['network'] === 'ws') {
|
2020-12-16 23:49:34 +08:00
|
|
|
if ($server['tls'])
|
|
|
|
array_push($config, 'obfs=wss');
|
|
|
|
else
|
|
|
|
array_push($config, 'obfs=ws');
|
2020-11-15 17:10:32 +08:00
|
|
|
if ($server['networkSettings']) {
|
|
|
|
$wsSettings = json_decode($server['networkSettings'], true);
|
2020-11-20 00:26:39 +08:00
|
|
|
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
|
|
|
array_push($config, "obfs-uri={$wsSettings['path']}");
|
2020-12-16 23:49:34 +08:00
|
|
|
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']) && !isset($host))
|
|
|
|
$host = $wsSettings['headers']['Host'];
|
2020-06-12 00:35:35 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-16 23:49:34 +08:00
|
|
|
if (isset($host)) {
|
|
|
|
array_push($config, "obfs-host={$host}");
|
|
|
|
}
|
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 = [
|
2020-11-15 17:10:32 +08:00
|
|
|
"trojan={$server['host']}:{$server['port']}",
|
2020-07-01 18:31:44 +08:00
|
|
|
"password={$password}",
|
2020-10-09 21:47:36 +08:00
|
|
|
'over-tls=true',
|
2020-11-15 17:10:32 +08:00
|
|
|
$server['server_name'] ? "tls-host={$server['server_name']}" : "",
|
2020-07-29 20:08:51 +08:00
|
|
|
// Tips: allowInsecure=false = tls-verification=true
|
2020-11-15 17:10:32 +08:00
|
|
|
$server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
|
2020-10-09 21:47:36 +08:00
|
|
|
'fast-open=true',
|
|
|
|
'udp-relay=true',
|
2020-11-15 17:10:32 +08:00
|
|
|
"tag={$server['name']}"
|
2020-07-01 18:31:44 +08:00
|
|
|
];
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|