Skip to content

Commit

Permalink
feat: add support for hysteria2 in Passwall and SSRPLUS
Browse files Browse the repository at this point in the history
  • Loading branch information
xboard committed Nov 9, 2024
1 parent ab52e61 commit e79465c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 52 deletions.
32 changes: 32 additions & 0 deletions app/Protocols/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function handle()
if ($item['type'] === 'trojan') {
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= self::buildHysteria($user['uuid'], $item);
}
}
return base64_encode($uri);
}
Expand Down Expand Up @@ -170,4 +173,33 @@ public static function buildTrojan($password, $server)
return $uri;
}

public static function buildHysteria($password, $server)
{
$params = [];
// Return empty if version is not 2
if ($server['version'] !== 2) {
return '';
}

if ($server['server_name']) {
$params['sni'] = $server['server_name'];
$params['security'] = 'tls';
}

if ($server['is_obfs']) {
$params['obfs'] = 'salamander';
$params['obfs-password'] = $server['server_key'];
}

$params['insecure'] = $server['insecure'] ? 1 : 0;

$query = http_build_query($params);
$name = rawurlencode($server['name']);

$uri = "hysteria2://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n";

return $uri;
}

}
3 changes: 3 additions & 0 deletions app/Protocols/Passwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function handle()
if ($item['type'] === 'trojan') {
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= General::buildHysteria($user['uuid'], $item);
}
}
return base64_encode($uri);
}
Expand Down
3 changes: 3 additions & 0 deletions app/Protocols/SSRPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function handle()
if ($item['type'] === 'trojan') {
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= General::buildHysteria($user['uuid'], $item);
}
}
return base64_encode($uri);
}
Expand Down
22 changes: 1 addition & 21 deletions app/Protocols/V2rayN.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle()
$uri .= self::buildTrojan($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= self::buildHysteria($user['uuid'], $item);
$uri .= General::buildHysteria($user['uuid'], $item);
}

}
Expand Down Expand Up @@ -192,25 +192,5 @@ public static function buildTrojan($password, $server)
return $uri;
}

public static function buildHysteria($password, $server)
{
$name = rawurlencode($server['name']);
$params = [];
if ($server['server_name']) $params['sni'] = $server['server_name'];
$params['insecure'] = $server['insecure'] ? 1 : 0;
if($server['is_obfs']) {
$params['obfs'] = 'salamander';
$params['obfs-password'] = $server['server_key'];
}
$query = http_build_query($params);
if ($server['version'] == 2) {
$uri = "hysteria2://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n";
} else {
// V2rayN似乎不支持v1, 返回空
$uri = "";
}
return $uri;
}

}
32 changes: 1 addition & 31 deletions app/Protocols/V2rayNG.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle()
$uri .= self::buildVless($user['uuid'], $item);
}
if ($item['type'] === 'hysteria') {
$uri .= self::buildHysteria($user['uuid'], $item);
$uri .= General::buildHysteria($user['uuid'], $item);
}
}
return base64_encode($uri);
Expand Down Expand Up @@ -193,34 +193,4 @@ public static function buildTrojan($password, $server)
return $uri;
}

public static function buildHysteria($password, $server)
{
$params = [];
// Return empty if version is not 2
if ($server['version'] !== 2) {
return '';
}

if ($server['server_name']) {
$params['sni'] = $server['server_name'];
$params['security'] = 'tls';
}

if ($server['is_obfs']) {
$params['obfs'] = 'salamander';
$params['obfs-password'] = $server['server_key'];
}

$params['insecure'] = $server['insecure'] ? 1 : 0;

$query = http_build_query($params);
$name = rawurlencode($server['name']);

$uri = "hysteria2://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
$uri .= "\r\n";

return $uri;
}


}

0 comments on commit e79465c

Please sign in to comment.