尝试增加ClashMeta的hy2订阅,调整hy数据库以储存混淆obfs

This commit is contained in:
root
2023-09-30 21:35:31 +09:00
parent 28ad50650e
commit 21c03fc1e1
7 changed files with 144 additions and 11 deletions

View File

@ -52,6 +52,10 @@ class ClashMeta
array_push($proxy, self::buildTrojan($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'hysteria') {
array_push($proxy, self::buildHysteria($user['uuid'], $item));
array_push($proxies, $item['name']);
}
}
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
@ -244,6 +248,38 @@ class ClashMeta
return $array;
}
public static function buildHysteria($password, $server)
{
$array = [];
$array['name'] = $server['name'];
$array['server'] = $server['host'];
$array['port'] = $server['port'];
$array['udp'] = true;
//Todo:完善客户端上下行
//$array['up'] = $server['up_mbps'];
//$array['down'] = $server['down_mbps'];
if (isset($server['server_name'])) $array['sni'] = $server['server_name'];
if ($server['version'] === 2) {
$array['type'] = 'hysteria2';
$array['password'] = $password;
if (isset($server['obfs'])){
$array['obfs'] = $server['obfs'];
$array['obfs-password'] = $server['obfs_password'];
}
} else {
$array['type'] = 'hysteria';
$array['auth_str'] = $password;
if (isset($server['obfs']) && isset($server['obfs_password'])){
$array['obfs'] = $server['obfs_password'];
}
$array['protocol'] = 'udp';
}
return $array;
}
private function isMatch($exp, $str)
{
return @preg_match($exp, $str);

View File

@ -36,6 +36,9 @@ class General
if ($item['type'] === 'trojan') {
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= self::buildHysteria($user['uuid'], $item);
}
}
return base64_encode($uri);
}
@ -147,7 +150,7 @@ class General
if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type'];
if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']);
$output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}";
}
}
if ((string)$server['network'] === 'ws') {
$wsSettings = $server['network_settings'];
if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']);
@ -164,11 +167,11 @@ class General
$quicSettings = $server['network_settings'];
if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security'];
if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type'];
$output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}";
if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']);
$output .= "&key={$config['path']}";
}
if ((string)$server['network'] === 'grpc') {
@ -195,4 +198,33 @@ class General
return $uri;
}
public static function buildHysteria($password, $server)
{
$remote = filter_var($server['host'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? '[' . $server['host'] . ']' : $server['host'];
$name = Helper::encodeURIComponent($server['name']);
if ($server['version'] == 2) {
$uri = "hysteria2://{$password}@{$remote}:{$server['port']}/?insecure={$server['insecure']}&sni={$server['server_name']}";
if (isset($server['obfs']) && isset($server['obfs_password'])) {
$uri .= "&obfs={$server['obfs']}&obfs-password={$server['obfs_password']}";
}
} else {
$uri = "hysteria://{$remote}:{$server['port']}/?";
$query = http_build_query([
'protocol' => 'udp',
'auth' => $password,
'insecure' => $server['insecure'],
'peer' => $server['server_name']
//'upmbps' => $server['up_mbps'],
//'downmbps' => $server['up_mbps']
]);
$uri .= $query;
if (isset($server['obfs']) && isset($server['obfs_password'])) {
$uri .= "&obfs={$server['obfs']}&obfsParam{$server['obfs_password']}";
}
}
$uri .= "#{$name}\r\n";
return $uri;
}
}