'use client'; import { useState } from 'react'; import { buildOutboundJson, type OutboundInput, type OutboundKind, type Network, type Security, type ProxyServerInput, type StreamInput, type WireguardInput, } from '@/lib/xray/outbounds'; import { ToolFrame } from './tool-frame'; import { TextField, SelectField } from './shared/fields'; import { OutputBlock } from './shared/output-block'; const KINDS: readonly OutboundKind[] = [ 'freedom', 'blackhole', 'vless', 'vmess', 'trojan', 'shadowsocks', 'socks', 'http', 'wireguard', 'warp', ]; const NETWORKS: readonly Network[] = ['tcp', 'kcp', 'ws', 'grpc', 'httpupgrade', 'xhttp']; const SECURITIES: readonly Security[] = ['none', 'tls', 'reality']; const FINGERPRINTS = ['chrome', 'firefox', 'safari', 'ios', 'android', 'edge', 'random']; const DOMAIN_STRATEGIES = ['AsIs', 'UseIP', 'UseIPv4', 'UseIPv6', 'ForceIP']; const PROXY_KINDS = new Set([ 'vless', 'vmess', 'trojan', 'shadowsocks', 'socks', 'http', ]); const STREAM_KINDS = new Set(['vless', 'vmess', 'trojan', 'shadowsocks']); const WG_KINDS = new Set(['wireguard', 'warp']); export function OutboundGenerator() { const [kind, setKind] = useState('vless'); const [tag, setTag] = useState('proxy'); // proxy server const [address, setAddress] = useState('example.com'); const [port, setPort] = useState('443'); const [id, setId] = useState(''); const [password, setPassword] = useState(''); const [method, setMethod] = useState('2022-blake3-aes-128-gcm'); const [flow, setFlow] = useState(''); const [username, setUsername] = useState(''); // stream const [network, setNetwork] = useState('tcp'); const [security, setSecurity] = useState('reality'); const [host, setHost] = useState(''); const [path, setPath] = useState('/'); const [serviceName, setServiceName] = useState(''); const [sni, setSni] = useState('www.microsoft.com'); const [fingerprint, setFingerprint] = useState('chrome'); const [publicKey, setPublicKey] = useState(''); const [shortId, setShortId] = useState(''); // freedom const [domainStrategy, setDomainStrategy] = useState('AsIs'); // wireguard const [wgSecretKey, setWgSecretKey] = useState(''); const [wgAddress, setWgAddress] = useState('172.16.0.2/32'); const [wgPublicKey, setWgPublicKey] = useState(''); const [wgEndpoint, setWgEndpoint] = useState(''); const isProxy = PROXY_KINDS.has(kind); const hasStream = STREAM_KINDS.has(kind); const isWg = WG_KINDS.has(kind); const hasPath = network === 'ws' || network === 'httpupgrade' || network === 'xhttp'; const server: ProxyServerInput = { address, port: Number(port), id, password, method, flow, username, }; const stream: StreamInput = { network, security, host, path, serviceName, sni, fingerprint, publicKey, shortId, }; const wireguard: WireguardInput = { secretKey: wgSecretKey, address: wgAddress .split(',') .map((a) => a.trim()) .filter(Boolean), publicKey: wgPublicKey, endpoint: wgEndpoint, }; const input: OutboundInput = { kind, tag, server: isProxy ? server : undefined, wireguard: isWg ? wireguard : undefined, stream: hasStream ? stream : undefined, domainStrategy: kind === 'freedom' ? domainStrategy : undefined, }; function reset() { setKind('vless'); setTag('proxy'); setAddress('example.com'); setPort('443'); setId(''); setPassword(''); setMethod('2022-blake3-aes-128-gcm'); setFlow(''); setUsername(''); setNetwork('tcp'); setSecurity('reality'); setHost(''); setPath('/'); setServiceName(''); setSni('www.microsoft.com'); setFingerprint('chrome'); setPublicKey(''); setShortId(''); setDomainStrategy('AsIs'); setWgSecretKey(''); setWgAddress('172.16.0.2/32'); setWgPublicKey(''); setWgEndpoint(''); } return (
setKind(v as OutboundKind)} options={KINDS} /> {kind === 'freedom' ? ( ) : null} {isProxy ? ( <> {(kind === 'vless' || kind === 'vmess') && ( )} {kind === 'vless' && ( )} {(kind === 'trojan' || kind === 'shadowsocks') && ( )} {kind === 'shadowsocks' && ( )} {(kind === 'socks' || kind === 'http') && ( <> )} ) : null} {isWg ? ( <> ) : null}
{hasStream ? (
setNetwork(v as Network)} options={NETWORKS} /> setSecurity(v as Security)} options={SECURITIES} /> {hasPath ? ( <> ) : null} {network === 'grpc' ? ( ) : null} {security !== 'none' ? ( <> ) : null} {security === 'reality' ? ( <> ) : null}
) : null}
); }