v2board/app/Utils/Clash.php

65 lines
2.2 KiB
PHP
Raw Normal View History

2020-06-12 00:18:35 +08:00
<?php
namespace App\Utils;
class Clash
{
2020-10-04 14:21:09 +08:00
public static function buildShadowsocks($uuid, $server)
{
$array = [];
2020-11-15 17:10:32 +08:00
$array['name'] = $server['name'];
2020-10-04 14:21:09 +08:00
$array['type'] = 'ss';
2020-11-15 17:10:32 +08:00
$array['server'] = $server['host'];
$array['port'] = $server['port'];
$array['cipher'] = $server['cipher'];
2020-10-04 14:21:09 +08:00
$array['password'] = $uuid;
$array['udp'] = true;
return $array;
}
2020-06-12 00:18:35 +08:00
public static function buildVmess($uuid, $server)
{
$array = [];
2020-11-15 17:10:32 +08:00
$array['name'] = $server['name'];
2020-06-12 00:18:35 +08:00
$array['type'] = 'vmess';
2020-11-15 17:10:32 +08:00
$array['server'] = $server['host'];
$array['port'] = $server['port'];
2020-06-12 00:18:35 +08:00
$array['uuid'] = $uuid;
$array['alterId'] = 2;
$array['cipher'] = 'auto';
2020-07-12 11:19:38 +08:00
$array['udp'] = true;
2020-11-15 17:10:32 +08:00
if ($server['tls']) {
$tlsSettings = json_decode($server['tlsSettings'], true);
2020-06-12 00:18:35 +08:00
$array['tls'] = true;
2020-11-15 17:10:32 +08:00
if (!empty($tlsSettings['allowInsecure'])) $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false );
if (!empty($tlsSettings['serverName'])) $array['servername'] = $tlsSettings['serverName'];
2020-06-12 00:18:35 +08:00
}
2020-11-15 17:10:32 +08:00
if ($server['network'] == 'ws') {
$array['network'] = $server['network'];
if ($server['networkSettings']) {
$wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path'])) $array['ws-path'] = $wsSettings['path'];
if (isset($wsSettings['headers']['Host'])) $array['ws-headers'] = [
'Host' => $wsSettings['headers']['Host']
2020-06-12 00:18:35 +08:00
];
}
}
return $array;
}
public static function buildTrojan($password, $server)
{
$array = [];
2020-11-15 17:10:32 +08:00
$array['name'] = $server['name'];
2020-06-12 00:18:35 +08:00
$array['type'] = 'trojan';
2020-11-15 17:10:32 +08:00
$array['server'] = $server['host'];
$array['port'] = $server['port'];
2020-06-12 00:18:35 +08:00
$array['password'] = $password;
2020-07-12 11:19:38 +08:00
$array['udp'] = true;
2020-11-15 17:10:32 +08:00
if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false );
2020-06-12 00:18:35 +08:00
return $array;
}
}