update trojan

This commit is contained in:
Tokumeikoi 2020-07-01 15:23:39 +08:00
parent 37449b6640
commit 75588d46f1
8 changed files with 40 additions and 16 deletions

View File

@ -10,9 +10,12 @@ class ServerTrojanSave extends FormRequest
'show' => '',
'name' => 'required',
'group_id' => 'required|array',
'host' => 'required|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
'parent_id' => 'nullable|integer',
'host' => 'required',
'port' => 'required',
'server_port' => 'required',
'allow_insecure' => 'nullable|in:0,1',
'server_name' => 'nullable',
'tags' => 'nullable|array',
'rate' => 'required|numeric'
];
@ -32,10 +35,11 @@ class ServerTrojanSave extends FormRequest
'name.required' => '节点名称不能为空',
'group_id.required' => '权限组不能为空',
'group_id.array' => '权限组格式不正确',
'parent_id.integer' => '父节点格式不正确',
'host.required' => '节点地址不能为空',
'host.regex' => '节点地址必须为域名',
'port.required' => '连接端口不能为空',
'server_port.required' => '后端服务端口不能为空',
'allow_insecure.in' => '允许不安全格式不正确',
'tags.array' => '标签格式不正确',
'rate.required' => '倍率不能为空',
'rate.numeric' => '倍率格式不正确'

View File

@ -119,7 +119,7 @@ class ServerService
$json = json_decode(self::TROJAN_CONFIG);
$json->local_port = $server->server_port;
$json->ssl->sni = $server->host;
$json->ssl->sni = $server->server_name ? $server->server_name : $server->host;
$json->ssl->cert = "/root/.cert/{$server->host}.crt";
$json->ssl->key = "/root/.cert/{$server->host}.key";
$json->api->api_port = $localPort;

View File

@ -41,6 +41,8 @@ class Clash
$array['server'] = $server->host;
$array['port'] = $server->port;
$array['password'] = $password;
$array['sni'] = $server->server_name;
$array['skip-cert-verify'] = $server->allow_insecure ? true : false;
return $array;
}
}

View File

@ -60,7 +60,11 @@ class Helper
public static function buildTrojanLink(ServerTrojan $server, User $user)
{
$server->name = rawurlencode($server->name);
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}#{$server->name}";
$query = http_build_query([
'allowInsecure' => $server->allow_insecure,
'peer' => $server->server_name
]);
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$server->name}";
$uri .= "\r\n";
return $uri;
}

View File

@ -33,7 +33,8 @@ class QuantumultX
public static function buildTrojan($password, $server)
{
$uri = "trojan={$server->host}:{$server->port}, password={$password}, over-tls=true, tls-verification=true, fast-open=false, udp-relay=false, tag={$server->name}";
$tlsVerification = $server->allow_insecure ? true : false;
$uri = "trojan={$server->host}:{$server->port}, password={$password}, over-tls=true, tls-host={$server->server_name}, tls-verification={$tlsVerification}, fast-open=false, udp-relay=false, tag={$server->name}";
$uri .= "\r\n";
return $uri;
}

View File

@ -190,15 +190,18 @@ CREATE TABLE `v2_server_stat` (
DROP TABLE IF EXISTS `v2_server_trojan`;
CREATE TABLE `v2_server_trojan` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) NOT NULL,
`tags` varchar(255) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`rate` varchar(11) NOT NULL,
`host` varchar(255) NOT NULL,
`port` int(11) NOT NULL,
`server_port` int(11) NOT NULL,
`show` tinyint(1) NOT NULL DEFAULT '0',
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '节点ID',
`group_id` varchar(255) NOT NULL COMMENT '节点组',
`parent_id` int(11) DEFAULT NULL COMMENT '父节点',
`tags` varchar(255) DEFAULT NULL COMMENT '节点标签',
`name` varchar(255) NOT NULL COMMENT '节点名称',
`rate` varchar(11) NOT NULL COMMENT '倍率',
`host` varchar(255) NOT NULL COMMENT '主机名',
`port` int(11) NOT NULL COMMENT '连接端口',
`server_port` int(11) NOT NULL COMMENT '服务端口',
`allow_insecure` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否允许不安全',
`server_name` varchar(255) DEFAULT NULL,
`show` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否显示',
`sort` int(11) DEFAULT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
@ -283,4 +286,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2020-06-18 12:12:19
-- 2020-07-01 07:01:59

View File

@ -286,3 +286,13 @@ ADD `limit_plan_ids` varchar(255) NULL AFTER `limit_use`;
ALTER TABLE `v2_server_trojan`
ADD `server_port` int(11) NOT NULL AFTER `port`;
ALTER TABLE `v2_server_trojan`
ADD `parent_id` int(11) NULL AFTER `group_id`;
ALTER TABLE `v2_server_trojan`
ADD `allow_insecure` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否允许不安全' AFTER `server_port`,
CHANGE `show` `show` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否显示' AFTER `allow_insecure`;
ALTER TABLE `v2_server_trojan`
ADD `server_name` varchar(255) NULL AFTER `allow_insecure`;

File diff suppressed because one or more lines are too long