", "~", "+", "=", ",", "." )); } $charsLen = count($chars) - 1; shuffle($chars); $str = ''; for ($i = 0; $i < $len; $i++) { $str .= $chars[mt_rand(0, $charsLen)]; } 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) { case 'md5': return md5($password) === $hash; case 'sha256': return hash('sha256', $password) === $hash; default: return password_verify($password, $hash); } } public static function emailSuffixVerify($email, $suffixs) { $suffix = preg_split('/@/', $email)[1]; if (!$suffix) return false; if (!is_array($suffixs)) { $suffixs = preg_split('/,/', $suffixs); } if (!in_array($suffix, $suffixs)) return false; return true; } public static function trafficConvert(int $byte) { $kb = 1024; $mb = 1048576; $gb = 1073741824; if ($byte > $gb) { return round($byte / $gb, 2) . ' GB'; } else if ($byte > $mb) { return round($byte / $mb, 2) . ' MB'; } else if ($byte > $kb) { return round($byte / $kb, 2) . ' KB'; } else if ($byte < 0) { return 0; } else { return round($byte, 2) . ' B'; } } }