feature: shadowsocks and more

This commit is contained in:
Tokumeikoi
2020-10-04 14:21:09 +08:00
parent ac48f90678
commit ba2e0a6b66
23 changed files with 657 additions and 150 deletions

View File

@ -11,6 +11,8 @@ class CacheKey
'SERVER_V2RAY_LAST_CHECK_AT' => '节点最后检查时间',
'SERVER_TROJAN_ONLINE_USER' => 'trojan节点在线用户',
'SERVER_TROJAN_LAST_CHECK_AT' => 'trojan节点最后检查时间',
'SERVER_SHADOWSOCKS_ONLINE_USER' => 'ss节点在线用户',
'SERVER_SHADOWSOCKS_LAST_CHECK_AT' => 'ss节点最后检查时间',
'TEMP_TOKEN' => '临时令牌',
'LAST_SEND_EMAIL_REMIND_TRAFFIC'
];

View File

@ -5,6 +5,19 @@ namespace App\Utils;
class Clash
{
public static function buildShadowsocks($uuid, $server)
{
$array = [];
$array['name'] = $server->name;
$array['type'] = 'ss';
$array['server'] = $server->host;
$array['port'] = $server->port;
$array['cipher'] = $server->cipher;
$array['password'] = $uuid;
$array['udp'] = true;
return $array;
}
public static function buildVmess($uuid, $server)
{
$array = [];

View File

@ -3,6 +3,7 @@
namespace App\Utils;
use App\Models\Server;
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Models\User;
@ -57,42 +58,6 @@ class Helper
return $str;
}
public static function buildTrojanLink(ServerTrojan $server, User $user)
{
$server->name = rawurlencode($server->name);
$query = http_build_query([
'allowInsecure' => $server->allow_insecure,
'peer' => $server->server_name,
'sni' => $server->server_name
]);
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$server->name}";
$uri .= "\r\n";
return $uri;
}
public static function buildVmessLink(Server $server, User $user)
{
$config = [
"v" => "2",
"ps" => $server->name,
"add" => $server->host,
"port" => $server->port,
"id" => $user->uuid,
"aid" => "2",
"net" => $server->network,
"type" => "none",
"host" => "",
"path" => "",
"tls" => $server->tls ? "tls" : ""
];
if ((string)$server->network === 'ws') {
$wsSettings = json_decode($server->networkSettings);
if (isset($wsSettings->path)) $config['path'] = $wsSettings->path;
if (isset($wsSettings->headers->Host)) $config['host'] = $wsSettings->headers->Host;
}
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
}
public static function multiPasswordVerify($algo, $password, $hash)
{
switch($algo) {

57
app/Utils/URLSchemes.php Normal file
View File

@ -0,0 +1,57 @@
<?php
namespace App\Utils;
use App\Models\Server;
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Models\User;
class URLSchemes
{
public static function buildShadowsocks(ServerShadowsocks $server, User $user)
{
$str = str_replace(
['+', '/', '='],
['-', '_', ''],
base64_encode("{$server->cipher}:{$user->uuid}")
);
return "ss://{$str}@{$server->host}:{$server->port}#{$server->name}\r\n";
}
public static function buildVmess(Server $server, User $user)
{
$config = [
"v" => "2",
"ps" => $server->name,
"add" => $server->host,
"port" => $server->port,
"id" => $user->uuid,
"aid" => "2",
"net" => $server->network,
"type" => "none",
"host" => "",
"path" => "",
"tls" => $server->tls ? "tls" : ""
];
if ((string)$server->network === 'ws') {
$wsSettings = json_decode($server->networkSettings);
if (isset($wsSettings->path)) $config['path'] = $wsSettings->path;
if (isset($wsSettings->headers->Host)) $config['host'] = $wsSettings->headers->Host;
}
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
}
public static function buildTrojan(ServerTrojan $server, User $user)
{
$server->name = rawurlencode($server->name);
$query = http_build_query([
'allowInsecure' => $server->allow_insecure,
'peer' => $server->server_name,
'sni' => $server->server_name
]);
$uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$server->name}";
$uri .= "\r\n";
return $uri;
}
}