initial commit
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
import RandomUtil from "@/plugins/randomUtil"
|
||||
|
||||
export interface Client {
|
||||
id?: number
|
||||
enable: boolean
|
||||
name: string
|
||||
config: string
|
||||
inbounds: string
|
||||
links: string
|
||||
volume: number
|
||||
expiry: number
|
||||
up: number
|
||||
down: number
|
||||
}
|
||||
|
||||
const defaultClient: Client = {
|
||||
enable: true,
|
||||
name: "",
|
||||
config: "[]",
|
||||
inbounds: "",
|
||||
links: "[]",
|
||||
volume: 0,
|
||||
expiry: 0,
|
||||
up: 0,
|
||||
down: 0,
|
||||
}
|
||||
|
||||
type Config = {
|
||||
[key: string]: {
|
||||
name?: string
|
||||
username?: string
|
||||
[key: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
export function updateConfigs(configs: string, newUserName: string): string {
|
||||
const updatedConfigs: Config = JSON.parse(configs)
|
||||
|
||||
for (const key in updatedConfigs) {
|
||||
if (updatedConfigs.hasOwnProperty(key)) {
|
||||
const config = updatedConfigs[key]
|
||||
if (config.hasOwnProperty("name")) {
|
||||
config.name = newUserName
|
||||
} else if (config.hasOwnProperty("username")) {
|
||||
config.username = newUserName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(updatedConfigs)
|
||||
}
|
||||
|
||||
export function randomConfigs(user: string): Config {
|
||||
const mixedPassword = RandomUtil.randomSeq(10)
|
||||
const ssPassword = RandomUtil.randomShadowsocksPassword(32)
|
||||
const uuid = RandomUtil.randomUUID()
|
||||
return {
|
||||
mixed: {
|
||||
username: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
socks: {
|
||||
username: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
http: {
|
||||
username: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
shadowsocks: {
|
||||
name: user,
|
||||
password: ssPassword,
|
||||
},
|
||||
shadowtls: {
|
||||
name: user,
|
||||
password: ssPassword,
|
||||
},
|
||||
vmess: {
|
||||
name: user,
|
||||
uuid: uuid,
|
||||
alterId: 0,
|
||||
},
|
||||
vless: {
|
||||
name: user,
|
||||
uuid: uuid,
|
||||
flow: "xtls-rprx-vision",
|
||||
},
|
||||
trojan: {
|
||||
name: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
naive: {
|
||||
username: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
hysteria: {
|
||||
name: user,
|
||||
auth_str: mixedPassword,
|
||||
},
|
||||
tuic: {
|
||||
name: user,
|
||||
uuid: uuid,
|
||||
password: mixedPassword,
|
||||
},
|
||||
hysteria2: {
|
||||
name: user,
|
||||
password: mixedPassword,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function createClient<T extends Client>(json?: Partial<T>): Client {
|
||||
const defaultObject: Client = { ...defaultClient, ...(json || {}) }
|
||||
return defaultObject
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Inbound } from './inbounds'
|
||||
import { Dial, Outbound } from './outbounds'
|
||||
|
||||
interface Log {
|
||||
disabled?: boolean
|
||||
level?: string
|
||||
output?: string
|
||||
timestamp?: boolean
|
||||
}
|
||||
|
||||
interface Dns {
|
||||
servers: DnsServer[]
|
||||
final?: string
|
||||
strategy?: string
|
||||
}
|
||||
|
||||
interface DnsServer{
|
||||
tag?: string,
|
||||
address: string,
|
||||
address_resolver?: string,
|
||||
address_strategy?: string,
|
||||
strategy?: string,
|
||||
detour?: string
|
||||
}
|
||||
|
||||
export interface Ntp extends Dial{
|
||||
enabled?: boolean
|
||||
server: string
|
||||
server_port?: number
|
||||
interval?: string
|
||||
}
|
||||
|
||||
interface Route {
|
||||
rules: RouteRule[] | RouteRuleLogical[]
|
||||
rule_set: RouteRuleSet[]
|
||||
final?: string,
|
||||
auto_detect_interface?: boolean
|
||||
default_interface?: string
|
||||
default_mark?: number
|
||||
}
|
||||
|
||||
interface RouteRule {
|
||||
inbound?: string[] | string
|
||||
ip_version?: 4 | 6,
|
||||
network?: "tcp" | "udp"
|
||||
auth_user?: string[]
|
||||
protocol?: string[] | string
|
||||
domain?: string[] | string
|
||||
domain_suffix?: string[] | string
|
||||
domain_keyword?: string[] | string
|
||||
domain_regex?: string[] | string
|
||||
source_ip_cidr?: string[] | string
|
||||
source_ip_is_private?: boolean
|
||||
ip_cidr?: string[] | string
|
||||
ip_is_private?: boolean
|
||||
source_port?: number[] | number
|
||||
source_port_range?: string[] | string
|
||||
port?: number[] | number
|
||||
port_range?: string[] | string
|
||||
clash_mode?: string
|
||||
rule_set?: string[] | string
|
||||
invert?: boolean
|
||||
outbound: string
|
||||
}
|
||||
|
||||
interface RouteRuleLogical {
|
||||
type: "logical"
|
||||
mode: "and" | "or"
|
||||
rules: RouteRule[]
|
||||
invert?: boolean
|
||||
outbound: string
|
||||
}
|
||||
|
||||
interface RouteRuleSet {
|
||||
type: string
|
||||
tag: string
|
||||
format: string
|
||||
path?: string
|
||||
url?: string
|
||||
download_detour?: string
|
||||
update_interval?: string
|
||||
}
|
||||
|
||||
interface Experimental {
|
||||
cache_file?: CacheFile
|
||||
clash_api?: ClashApi
|
||||
v2ray_api: V2rayApi
|
||||
}
|
||||
|
||||
interface CacheFile {
|
||||
enabled?: boolean
|
||||
path?: string
|
||||
cache_id?: string
|
||||
store_fakeip?: boolean
|
||||
}
|
||||
|
||||
interface V2rayApi {
|
||||
listen: string
|
||||
stats: V2rayApiStats
|
||||
}
|
||||
|
||||
export interface V2rayApiStats {
|
||||
enabled: boolean
|
||||
inbounds: string[]
|
||||
outbounds: string[]
|
||||
users: string[]
|
||||
}
|
||||
|
||||
interface ClashApi {
|
||||
external_controller?: string
|
||||
external_ui?: string
|
||||
external_ui_download_url?: string
|
||||
external_ui_download_detour?: string
|
||||
secret?: string
|
||||
default_mode?: string
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
log: Log
|
||||
dns: Dns
|
||||
ntp?: Ntp
|
||||
inbounds: Inbound[]
|
||||
outbounds: Outbound[]
|
||||
route: Route
|
||||
experimental: Experimental
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export interface Dial {
|
||||
detour?: string
|
||||
bind_interface?: string
|
||||
inet4_bind_address?: string
|
||||
inet6_bind_address?:string
|
||||
routing_mark?: number
|
||||
reuse_addr?: boolean
|
||||
connect_timeout?: string
|
||||
tcp_fast_open?: boolean
|
||||
tcp_multi_path?: boolean
|
||||
udp_fragment?: boolean
|
||||
domain_strategy?: string
|
||||
fallback_delay?: string
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
interface Brutal {
|
||||
enabled: boolean
|
||||
up_mbps: number
|
||||
down_mbps: number
|
||||
}
|
||||
|
||||
export interface iMultiplex{
|
||||
enabled: boolean
|
||||
padding?: boolean
|
||||
brutal?: Brutal
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export interface iTls {
|
||||
enabled?: boolean
|
||||
server_name?: string
|
||||
alpn?: string[]
|
||||
min_version?: string
|
||||
max_version?: string
|
||||
cipher_suites?: string[]
|
||||
certificate?: string[]
|
||||
certificate_path?: string
|
||||
key?: string[]
|
||||
key_path?: string
|
||||
}
|
||||
|
||||
export const defaultInTls: iTls = {
|
||||
alpn: ['HTTP/3', 'HTTP/2', 'HTTP/1.1'],
|
||||
min_version: "1.2",
|
||||
max_version: "1.3",
|
||||
cipher_suites: [""],
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
import { iMultiplex } from "./inMultiplex"
|
||||
import { iTls } from "./inTls"
|
||||
import { Dial } from "./outbounds"
|
||||
import { Transport } from "./transport"
|
||||
|
||||
export const InTypes = {
|
||||
Direct: 'direct',
|
||||
Mixed: 'mixed',
|
||||
SOCKS: 'socks',
|
||||
HTTP: 'http',
|
||||
Shadowsocks: 'shadowsocks',
|
||||
VMess: 'vmess',
|
||||
Trojan: 'trojan',
|
||||
Naive: 'naive',
|
||||
Hysteria: 'hysteria',
|
||||
ShadowTLS: 'shadowtls',
|
||||
TUIC: 'tuic',
|
||||
Hysteria2: 'hysteria2',
|
||||
VLESS: 'vless',
|
||||
// Tun: 'tun',
|
||||
Redirect: 'redirect',
|
||||
TProxy: 'tproxy',
|
||||
}
|
||||
|
||||
type InType = typeof InTypes[keyof typeof InTypes]
|
||||
|
||||
export interface Listen {
|
||||
listen: string
|
||||
listen_port: number
|
||||
tcp_fast_open?: boolean
|
||||
tcp_multi_path?: boolean
|
||||
udp_fragment?: boolean
|
||||
udp_timeout?: string
|
||||
detour?: string
|
||||
sniff?: boolean
|
||||
sniff_override_destination?: boolean
|
||||
sniff_timeout?: string
|
||||
domain_strategy?: string
|
||||
}
|
||||
|
||||
interface InboundBasics extends Listen {
|
||||
type: InType
|
||||
tag: string
|
||||
}
|
||||
|
||||
interface UsernamePass {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
interface NamePass {
|
||||
name: string
|
||||
password: string
|
||||
}
|
||||
interface NameUUID {
|
||||
name: string
|
||||
uuid: string
|
||||
}
|
||||
interface NameAuth {
|
||||
name: string
|
||||
auth_str: string
|
||||
}
|
||||
interface VmessUser extends NameUUID {
|
||||
alterId: number
|
||||
}
|
||||
interface VlessUser extends NameUUID {
|
||||
flow: string
|
||||
}
|
||||
interface TuicUser extends NameUUID {
|
||||
password?: string
|
||||
}
|
||||
|
||||
interface ShadowTLSHandShake extends Dial {
|
||||
server: string
|
||||
server_port: number
|
||||
}
|
||||
|
||||
export interface Direct extends InboundBasics {
|
||||
network?: "udp" | "tcp"
|
||||
override_address?: string
|
||||
override_port?: number
|
||||
}
|
||||
export interface Mixed extends InboundBasics {
|
||||
users?: UsernamePass[]
|
||||
}
|
||||
export interface SOCKS extends InboundBasics {
|
||||
users?: UsernamePass[]
|
||||
}
|
||||
export interface HTTP extends InboundBasics {
|
||||
users?: UsernamePass[]
|
||||
tls?: iTls,
|
||||
}
|
||||
export interface Shadowsocks extends InboundBasics {
|
||||
method: string
|
||||
password: string
|
||||
network?: "udp" | "tcp"
|
||||
users?: NamePass[]
|
||||
multiplex?: iMultiplex
|
||||
}
|
||||
export interface VMess extends InboundBasics {
|
||||
users: VmessUser[]
|
||||
tls: iTls
|
||||
multiplex?: iMultiplex
|
||||
transport?: Transport
|
||||
}
|
||||
export interface Trojan extends InboundBasics {
|
||||
users: NamePass[]
|
||||
tls: iTls
|
||||
fallback?: {
|
||||
server: string
|
||||
server_port: number
|
||||
}
|
||||
multiplex?: iMultiplex
|
||||
transport?: Transport
|
||||
}
|
||||
export interface Naive extends InboundBasics {
|
||||
users: UsernamePass[]
|
||||
tls: iTls,
|
||||
}
|
||||
export interface Hysteria extends InboundBasics {
|
||||
up_mbps: number
|
||||
down_mbps: number
|
||||
obfs?: {
|
||||
type?: "salamander"
|
||||
password?: string
|
||||
}
|
||||
users: NameAuth[]
|
||||
recv_window_conn?: number
|
||||
recv_window_client?: number
|
||||
max_conn_client?: number
|
||||
disable_mtu_discovery?: boolean
|
||||
tls: iTls
|
||||
}
|
||||
export interface ShadowTLS extends InboundBasics {
|
||||
version: 1|2|3
|
||||
password?: string
|
||||
users?: NamePass[]
|
||||
handshake: ShadowTLSHandShake
|
||||
handshake_for_server_name?: {
|
||||
[server_name: string]: ShadowTLSHandShake
|
||||
}
|
||||
strict_mode?: boolean
|
||||
}
|
||||
export interface VLESS extends InboundBasics {
|
||||
users: VlessUser[]
|
||||
tls?: iTls
|
||||
multiplex?: iMultiplex
|
||||
transport?: Transport
|
||||
}
|
||||
export interface TUIC extends InboundBasics {
|
||||
users: TuicUser[]
|
||||
congestion_control: ""|"cubic"|"new_reno"|"bbr"
|
||||
auth_timeout?: string
|
||||
zero_rtt_handshake?: boolean
|
||||
heartbeat?: string
|
||||
tls: iTls
|
||||
}
|
||||
export interface Hysteria2 extends InboundBasics {
|
||||
up_mbps?: number
|
||||
down_mbps?: number
|
||||
obfs?: {
|
||||
type?: "salamander"
|
||||
password: string
|
||||
}
|
||||
users: NamePass[]
|
||||
ignore_client_bandwidth?: boolean
|
||||
tls: iTls
|
||||
masquerade?: string
|
||||
brutal_debug?: boolean
|
||||
}
|
||||
export interface Tun extends InboundBasics {
|
||||
[otherProperties: string]: any
|
||||
}
|
||||
export interface Redirect extends InboundBasics {}
|
||||
export interface TProxy extends InboundBasics {
|
||||
network?: "udp" | "tcp"
|
||||
}
|
||||
|
||||
// Create interfaces dynamically based on InTypes keys
|
||||
type InterfaceMap = {
|
||||
direct: Direct
|
||||
mixed: Mixed
|
||||
socks: SOCKS
|
||||
http: SOCKS
|
||||
shadowsocks: Shadowsocks
|
||||
vmess: VMess
|
||||
trojan: Trojan
|
||||
naive: Naive
|
||||
hysteria: Hysteria
|
||||
shadowtls: ShadowTLS
|
||||
tuic: TUIC
|
||||
hysteria2: Hysteria2
|
||||
vless: VLESS
|
||||
// tun: Tun
|
||||
redirect: Redirect
|
||||
tproxy: TProxy
|
||||
}
|
||||
|
||||
// Create union type from InterfaceMap
|
||||
export type Inbound = InterfaceMap[keyof InterfaceMap]
|
||||
|
||||
type userEnabledTypes = {
|
||||
mixed: Mixed
|
||||
socks: SOCKS
|
||||
http: SOCKS
|
||||
shadowsocks: Shadowsocks
|
||||
vmess: VMess
|
||||
trojan: Trojan
|
||||
naive: Naive
|
||||
hysteria: Hysteria
|
||||
shadowtls: ShadowTLS
|
||||
tuic: TUIC
|
||||
hysteria2: Hysteria2
|
||||
vless: VLESS
|
||||
}
|
||||
|
||||
// Create union type from userEnabledTypes
|
||||
export type InboundWithUser = userEnabledTypes[keyof userEnabledTypes]
|
||||
|
||||
// Create defaultValues object dynamically
|
||||
const defaultValues: Record<InType, Inbound> = {
|
||||
direct: <Direct>{ type: InTypes.Direct },
|
||||
mixed: <Mixed>{ type: InTypes.Mixed },
|
||||
socks: <SOCKS>{ type: InTypes.SOCKS },
|
||||
http: <HTTP>{ type: InTypes.HTTP, tls: {} },
|
||||
shadowsocks: <Shadowsocks>{ type: InTypes.Shadowsocks, method: 'none', multiplex: {} },
|
||||
vmess: <VMess>{ type: InTypes.VMess, users: <VmessUser[]>[], tls: {}, multiplex: {}, transport: {} },
|
||||
trojan: <Trojan>{ type: InTypes.Trojan, users: <NamePass[]>[], tls: {}, multiplex: {}, transport: {} },
|
||||
naive: <Naive>{ type: InTypes.Naive, users: <UsernamePass[]>[], tls: { enabled: true } },
|
||||
hysteria: <Hysteria>{ type: InTypes.Hysteria, users: <NameAuth[]>[], up_mbps: 100, down_mbps: 100, tls: { enabled: true } },
|
||||
shadowtls: <ShadowTLS>{ type: InTypes.ShadowTLS, version: 3, users: <NamePass[]>[], handshake: {}, handshake_for_server_name: {} },
|
||||
tuic: <TUIC>{ type: InTypes.TUIC, users: <TuicUser[]>[], congestion_control: "cubic", tls: { enabled: true } },
|
||||
hysteria2: <Hysteria2>{ type: InTypes.Hysteria2, users: <NamePass[]>[], tls: { enabled: true } },
|
||||
vless: <VLESS>{ type: InTypes.VLESS, users: <VlessUser[]>[], tls: {}, multiplex: {}, transport: {} },
|
||||
// tun: <Tun>{ type: InTypes.Tun },
|
||||
redirect: <Redirect>{ type: InTypes.Redirect },
|
||||
tproxy: <TProxy>{ type: InTypes.TProxy },
|
||||
}
|
||||
|
||||
export function createInbound<T extends Inbound>(type: InType,json?: Partial<T>): Inbound {
|
||||
const defaultObject: Inbound = { ...defaultValues[type] ?? {}, ...(json ?? {}) }
|
||||
return defaultObject
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface oTls {
|
||||
enabled?: boolean
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { oTls } from "./outTls"
|
||||
|
||||
export const OutTypes = {
|
||||
Direct: 'direct',
|
||||
Block: 'block',
|
||||
SOCKS: 'socks',
|
||||
HTTP: 'http',
|
||||
Shadowsocks: 'shadowsocks',
|
||||
VMess: 'vmess',
|
||||
Trojan: 'trojan',
|
||||
Wireguard: 'wireguard',
|
||||
Hysteria: 'hysteria',
|
||||
VLESS: 'vless',
|
||||
ShadowTLS: 'shadowtls',
|
||||
TUIC: 'tuic',
|
||||
Hysteria2: 'hysteria2',
|
||||
Tur: 'tur',
|
||||
SSH: 'ssh',
|
||||
DNS: 'dns',
|
||||
Selector: 'selector',
|
||||
URLTest: 'urltest',
|
||||
}
|
||||
|
||||
type OutType = typeof OutTypes[keyof typeof OutTypes]
|
||||
|
||||
export interface Dial {
|
||||
detour?: string
|
||||
bind_interface?: string
|
||||
inet4_bind_address?: string
|
||||
inet6_bind_address?: string
|
||||
routing_mark?: number
|
||||
reuse_addr?: boolean
|
||||
connect_timeout?: string
|
||||
tcp_fast_open?: boolean
|
||||
tcp_multi_path?: boolean
|
||||
udp_fragment?: boolean
|
||||
domain_strategy?: string
|
||||
fallback_delay?: string
|
||||
}
|
||||
|
||||
interface OutboundBasics {
|
||||
type: OutType
|
||||
tag: string
|
||||
}
|
||||
|
||||
export interface Direct extends OutboundBasics, Dial {
|
||||
override_address?: string
|
||||
override_port?: number
|
||||
proxy_protocol?: 0 | 1 | 2
|
||||
}
|
||||
|
||||
// Create interfaces dynamically based on OutTypes keys
|
||||
type InterfaceMap = {
|
||||
[Key in keyof typeof OutTypes]: {
|
||||
type: string
|
||||
[otherProperties: string]: any; // You can add other properties as needed
|
||||
}
|
||||
}
|
||||
|
||||
// Create union type from InterfaceMap
|
||||
export type Outbound = InterfaceMap[keyof InterfaceMap]
|
||||
|
||||
// Create defaultValues object dynamically
|
||||
const defaultValues: Record<OutType, Outbound> = {
|
||||
direct: { type: OutTypes.Direct },
|
||||
block: { type: OutTypes.Block },
|
||||
socks: { type: OutTypes.SOCKS },
|
||||
http: { type: OutTypes.HTTP },
|
||||
shadowsocks: { type: OutTypes.Shadowsocks },
|
||||
vmess: { type: OutTypes.VMess, tls: { enabled: true } },
|
||||
trojan: { type: OutTypes.Trojan },
|
||||
wireguard: { type: OutTypes.Wireguard },
|
||||
hysteria: { type: OutTypes.Hysteria },
|
||||
vless: { type: OutTypes.VLESS },
|
||||
shadowtls: { type: OutTypes.ShadowTLS },
|
||||
tuic: { type: OutTypes.TUIC },
|
||||
hysteria2: { type: OutTypes.Hysteria2, users: [], tls: {} },
|
||||
tur: { type: OutTypes.Tur },
|
||||
ssh: { type: OutTypes.SSH },
|
||||
dns: { type: OutTypes.DNS },
|
||||
selector: { type: OutTypes.Selector },
|
||||
urltest: { type: OutTypes.URLTest },
|
||||
}
|
||||
|
||||
export function createOutbound<T extends Outbound>(type: string,json?: Partial<T>): Outbound {
|
||||
const defaultObject: Outbound = { ...defaultValues[type], ...(json || {}) }
|
||||
return defaultObject
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
export const TrspTypes = {
|
||||
HTTP: 'http',
|
||||
WebSocket: 'ws',
|
||||
QUIC: 'quic',
|
||||
gRPC: 'grpc',
|
||||
HTTPUpgrade: "httpupgrade"
|
||||
}
|
||||
|
||||
export type TrspType = typeof TrspTypes[keyof typeof TrspTypes]
|
||||
|
||||
export type Transport = HTTP|WebSocket|QUIC|gRPC|HTTPUpgrade
|
||||
|
||||
interface TransportBasics {
|
||||
type: TrspType
|
||||
}
|
||||
|
||||
export interface HTTP extends TransportBasics {
|
||||
host?: string[]
|
||||
path?: string
|
||||
method?: string
|
||||
headers?: {}
|
||||
idle_timeout?: string
|
||||
ping_timeout?: string
|
||||
}
|
||||
|
||||
export interface WebSocket extends TransportBasics {
|
||||
path: string
|
||||
headers?: {}
|
||||
max_early_data?: number
|
||||
early_data_header_name?: string
|
||||
}
|
||||
|
||||
export interface QUIC extends TransportBasics {}
|
||||
|
||||
export interface gRPC extends TransportBasics {
|
||||
service_name?: string
|
||||
idle_timeout?: string
|
||||
ping_timeout?: string
|
||||
permit_without_stream?: boolean
|
||||
}
|
||||
|
||||
export interface HTTPUpgrade extends TransportBasics {
|
||||
host?: string
|
||||
path?: string
|
||||
headers?: {}
|
||||
}
|
||||
Reference in New Issue
Block a user