move LinkGenerator ro backend
This commit is contained in:
@@ -178,8 +178,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Link } from '@/plugins/link'
|
||||
import { createClient, randomConfigs, updateConfigs } from '@/types/clients'
|
||||
import { createClient, randomConfigs, updateConfigs, Link } from '@/types/clients'
|
||||
import DatePick from '@/components/DateTime.vue'
|
||||
import { HumanReadable } from '@/plugins/utils'
|
||||
|
||||
@@ -225,7 +224,6 @@ export default {
|
||||
this.loading = true
|
||||
this.client.config = updateConfigs(this.clientConfig, this.client.name)
|
||||
this.client.links = [
|
||||
...this.links,
|
||||
...this.extLinks.filter(l => l.uri != ''),
|
||||
...this.subLinks.filter(l => l.uri != '')]
|
||||
this.$emit('save', this.client, this.clientStats)
|
||||
|
||||
@@ -1,465 +0,0 @@
|
||||
import { Hysteria, Hysteria2, InTypes, Inbound, Naive, Shadowsocks, TUIC, Trojan, VLESS, VMess } from "@/types/inbounds"
|
||||
import { HTTP, WebSocket, gRPC, HTTPUpgrade, Transport, TrspTypes } from "@/types/transport"
|
||||
import RandomUtil from "./randomUtil"
|
||||
import { Client } from "@/types/clients"
|
||||
|
||||
export interface Link {
|
||||
type: "local" | "external" | "sub"
|
||||
remark?: string
|
||||
uri: string
|
||||
}
|
||||
|
||||
function utf8ToBase64(utf8String: string): string {
|
||||
const encodedUtf8 = encodeURIComponent(utf8String).replace(/%([0-9A-F]{2})/g, (_, p1) => String.fromCharCode(parseInt(p1, 16)))
|
||||
return btoa(encodedUtf8)
|
||||
}
|
||||
|
||||
export namespace LinkUtil {
|
||||
export function linkGenerator(user: Client, inbound: Inbound, tls: any = {}, addrs: any[] = []): string[] {
|
||||
switch(inbound.type){
|
||||
case InTypes.Shadowsocks:
|
||||
return shadowsocksLink(user,<Shadowsocks>inbound, addrs)
|
||||
case InTypes.Naive:
|
||||
return naiveLink(user,<Naive>inbound, addrs, tls)
|
||||
case InTypes.Hysteria:
|
||||
return hysteriaLink(user,<Hysteria>inbound, addrs, tls)
|
||||
case InTypes.Hysteria2:
|
||||
return hysteria2Link(user,<Hysteria2>inbound, addrs, tls)
|
||||
case InTypes.TUIC:
|
||||
return tuicLink(user,<TUIC>inbound, addrs, tls)
|
||||
case InTypes.VLESS:
|
||||
return vlessLink(user,<VLESS>inbound, addrs, tls)
|
||||
case InTypes.Trojan:
|
||||
return trojanLink(user,<Trojan>inbound, addrs, tls)
|
||||
case InTypes.VMess:
|
||||
return vmessLink(user,<VMess>inbound, addrs, tls)
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function shadowsocksLink(user: Client, inbound: Shadowsocks, addrs: any[]): string[] {
|
||||
const userPass = inbound.method == "2022-blake3-aes-128-gcm" ? user.config.shadowsocks16?.password : user.config.shadowsocks?.password
|
||||
const password = [userPass]
|
||||
if (inbound.method.startsWith('2022')) password.push(inbound.password)
|
||||
const params = {
|
||||
tfo: inbound.tcp_fast_open? 1 : null,
|
||||
network: inbound.network?? null
|
||||
}
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`ss://${utf8ToBase64(inbound.method + ':' + password.join(':'))}@${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`ss://${utf8ToBase64(inbound.method + ':' + password.join(':'))}@${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function hysteriaLink(user: Client, inbound: Hysteria, addrs: any[], tls: any): string[] {
|
||||
const auth = user.config.hysteria.auth_str
|
||||
const params = {
|
||||
upmbps: inbound.up_mbps?? null,
|
||||
downmbps: inbound.down_mbps?? null,
|
||||
auth: auth?? null,
|
||||
peer: tls?.server?.server_name?? null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
obfsParam: inbound.obfs?? null,
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0,
|
||||
insecure: tls?.client?.insecure ? 1 : null
|
||||
}
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`hysteria://${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`hysteria://${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
uri.searchParams.set('peer', a.server_name)
|
||||
} else {
|
||||
tls?.server?.server_name ? uri.searchParams.set('peer', tls?.server?.server_name) : uri.searchParams.delete('peer')
|
||||
}
|
||||
if (a.insecure) {
|
||||
uri.searchParams.set('insecure', '1')
|
||||
} else {
|
||||
tls?.client?.insecure ? uri.searchParams.set('insecure', '1') : uri.searchParams.delete('insecure')
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function hysteria2Link(user: Client, inbound: Hysteria2, addrs: any[], tls: any): string[] {
|
||||
const password = user.config.hysteria2.password
|
||||
const params = {
|
||||
upmbps: inbound.up_mbps?? null,
|
||||
downmbps: inbound.down_mbps?? null,
|
||||
sni: tls?.server?.server_name?? null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
obfs: inbound.obfs?.type?? null,
|
||||
'obfs-password': inbound.obfs?.password?? null,
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0,
|
||||
insecure: tls?.client?.insecure ? 1 : null
|
||||
}
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`hysteria2://${password}@${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`hysteria2://${password}@${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
uri.searchParams.set('sni', a.server_name)
|
||||
} else {
|
||||
tls?.server?.server_name ? uri.searchParams.set('sni', tls?.server?.server_name) : uri.searchParams.delete('sni')
|
||||
}
|
||||
if (a.insecure) {
|
||||
uri.searchParams.set('insecure', '1')
|
||||
} else {
|
||||
tls?.client?.insecure ? uri.searchParams.set('insecure', '1') : uri.searchParams.delete('insecure')
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function naiveLink(user: Client, inbound: Naive, addrs: any[], tls: any): string[] {
|
||||
const password = user.config.naive.password
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const params = {
|
||||
padding: 1,
|
||||
peer: tls?.server?.server_name?? null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
tfo: inbound.tcp_fast_open? 1 : 0,
|
||||
allowInsecure: tls?.client?.insecure ? 1 : null
|
||||
}
|
||||
const uri = `http2://${utf8ToBase64(user.name + ":" + password + "@" + location.hostname + ":" + inbound.listen_port)}`
|
||||
const paramsArray = []
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
paramsArray.push(`${key}=${encodeURIComponent(value.toString())}`)
|
||||
}
|
||||
}
|
||||
links.push(uri.toString() + "?" + paramsArray.join('&') + "#" + inbound.tag)
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const params = {
|
||||
padding: 1,
|
||||
peer: a.server_name?.length>0 ? a.server_name : tls?.server?.server_name?? null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
tfo: inbound.tcp_fast_open? 1 : 0,
|
||||
allowInsecure: a.insecure ? 1 : tls?.client?.insecure ? 1 : null
|
||||
}
|
||||
const uri = `http2://${utf8ToBase64(user + ":" + password + "@" + a.server + ":" + a.server_port)}`
|
||||
const paramsArray = []
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
paramsArray.push(`${key}=${encodeURIComponent(value.toString())}`)
|
||||
}
|
||||
}
|
||||
links.push(uri.toString() + "?" + paramsArray.join('&') + "#" + encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag))
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function tuicLink(user: Client, inbound: TUIC, addrs: any[], tls: any): string[] {
|
||||
const u = user.config.tuic
|
||||
const params = {
|
||||
sni: tls?.server?.server_name?? null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
congestion_control: inbound.congestion_control?? null,
|
||||
allowInsecure: tls?.client?.insecure ? 1 : null,
|
||||
disable_sni: tls?.client?.disable_sni ? 1 : null
|
||||
}
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`tuic://${u?.uuid}:${u?.password}@${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`tuic://${u?.uuid}:${u?.password}@${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
uri.searchParams.set('sni', a.server_name)
|
||||
} else {
|
||||
tls?.server?.server_name ? uri.searchParams.set('sni', tls?.server?.server_name) : uri.searchParams.delete('sni')
|
||||
}
|
||||
if (a.insecure) {
|
||||
uri.searchParams.set('allowInsecure', '1')
|
||||
} else {
|
||||
tls?.client?.insecure ? uri.searchParams.set('allowInsecure', '1') : uri.searchParams.delete('allowInsecure')
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function getTransportParams(t:Transport): any {
|
||||
if (Object.keys(t).length == 0) return {}
|
||||
|
||||
const params = {
|
||||
host: <string|null>'',
|
||||
path: <string|null>'',
|
||||
serviceName: <string|null>'',
|
||||
}
|
||||
switch (t.type){
|
||||
case TrspTypes.HTTP:
|
||||
const th = <HTTP>t
|
||||
params.host = th.host?.join(',')?? null
|
||||
params.path = th.path?? null
|
||||
break
|
||||
case TrspTypes.WebSocket:
|
||||
const tw = <WebSocket>t
|
||||
params.path = tw.path?? null
|
||||
params.host = tw.headers?.Host?? null
|
||||
break
|
||||
case TrspTypes.gRPC:
|
||||
const tg = <gRPC>t
|
||||
params.serviceName = tg.service_name?? null
|
||||
break
|
||||
case TrspTypes.HTTPUpgrade:
|
||||
const tu = <HTTPUpgrade>t
|
||||
params.host = tu.host?? null
|
||||
params.path = tu.path?? null
|
||||
break
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
function vlessLink(user: Client, inbound: VLESS, addrs: any[], tls: any): string[] {
|
||||
const u = user.config.vless
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
const tParams = getTransportParams(transport)
|
||||
|
||||
const params = {
|
||||
type: transport?.type?? 'tcp',
|
||||
security: tls?.server?.enabled? tls?.server?.reality?.enabled ? 'reality' : 'tls' : null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
sni: tls?.server?.server_name?? null,
|
||||
flow: tls?.server?.enabled ? u?.flow?? null : null,
|
||||
allowInsecure: tls?.client?.insecure ? 1 : null,
|
||||
fp: tls?.client?.utls?.enabled ? tls.client.utls.fingerprint : null,
|
||||
pbk: tls?.client?.reality?.public_key?? null,
|
||||
sid: tls?.server?.reality?.enabled ? (tls?.server?.reality?.short_id?.length>0 ? tls.server.reality.short_id[RandomUtil.randomInt(tls.server.reality.short_id.length)] : null) : null
|
||||
}
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`vless://${u?.uuid}@${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`vless://${u?.uuid}@${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
if (a.tls != undefined){
|
||||
if (a.tls) {
|
||||
uri.searchParams.set('security','tls')
|
||||
} else {
|
||||
uri.searchParams.delete('security')
|
||||
uri.searchParams.delete('sni')
|
||||
uri.searchParams.delete('alpn')
|
||||
uri.searchParams.delete('allowInsecure')
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
uri.searchParams.set('sni', a.server_name)
|
||||
} else {
|
||||
tls?.server?.server_name ? uri.searchParams.set('sni', tls?.server?.server_name) : uri.searchParams.delete('sni')
|
||||
}
|
||||
if (a.insecure) {
|
||||
uri.searchParams.set('allowInsecure', '1')
|
||||
} else {
|
||||
tls?.client?.insecure ? uri.searchParams.set('allowInsecure', '1') : uri.searchParams.delete('allowInsecure')
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function trojanLink(user: Client, inbound: Trojan, addrs: any[], tls: any): string[] {
|
||||
const u = user.config.trojan
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
const tParams = getTransportParams(transport)
|
||||
|
||||
const params = {
|
||||
type: transport?.type?? 'tcp',
|
||||
security: tls?.server?.enabled? tls?.server?.reality?.enabled ? 'reality' : 'tls' : null,
|
||||
alpn: tls?.server?.alpn?.join(',')?? null,
|
||||
sni: tls?.server?.server_name?? null,
|
||||
allowInsecure: tls?.client?.insecure ? 1 : null,
|
||||
fp: tls?.client?.utls?.enabled ? tls.client.utls.fingerprint : null,
|
||||
pbk: tls?.client?.reality?.public_key?? null,
|
||||
sid: tls?.server?.reality?.enabled ? (tls?.server?.reality?.short_id?.length>0 ? tls?.server?.reality.short_id[RandomUtil.randomInt(tls?.server?.reality.short_id.length)] : null) : null
|
||||
}
|
||||
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
const uri = new URL(`trojan://${u?.password}@${location.hostname}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
uri.hash = encodeURIComponent(inbound.tag)
|
||||
links.push(uri.toString())
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
const uri = new URL(`trojan://${u?.password}@${a.server}:${a.server_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
if (value) {
|
||||
uri.searchParams.set(key, value.toString())
|
||||
}
|
||||
}
|
||||
if (a.tls != undefined){
|
||||
if (a.tls) {
|
||||
uri.searchParams.set('security','tls')
|
||||
} else {
|
||||
uri.searchParams.delete('security')
|
||||
uri.searchParams.delete('sni')
|
||||
uri.searchParams.delete('alpn')
|
||||
uri.searchParams.delete('allowInsecure')
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
uri.searchParams.set('sni', a.server_name)
|
||||
} else {
|
||||
tls?.server?.server_name ? uri.searchParams.set('sni', tls?.server?.server_name) : uri.searchParams.delete('sni')
|
||||
}
|
||||
if (a.insecure) {
|
||||
uri.searchParams.set('allowInsecure', '1')
|
||||
} else {
|
||||
tls?.client?.insecure ? uri.searchParams.set('allowInsecure', '1') : uri.searchParams.delete('allowInsecure')
|
||||
}
|
||||
uri.hash = encodeURIComponent(a.remark ? inbound.tag + a.remark : inbound.tag)
|
||||
links.push(uri.toString())
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
function vmessLink(user: Client, inbound: VMess, addrs: any[], tls: any): string[] {
|
||||
const u = user.config.vmess
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
const tParams = getTransportParams(transport)
|
||||
if (transport.type == TrspTypes.gRPC) tParams.path = tParams.serviceName
|
||||
|
||||
const params = {
|
||||
v: 2,
|
||||
add: location.hostname,
|
||||
aid: u?.alterId,
|
||||
host: tParams.host?? undefined,
|
||||
id: u?.uuid,
|
||||
net: transport?.type == undefined || transport?.type == 'http' ? 'tcp' : transport.type,
|
||||
type: transport?.type == 'http' ? 'http' : undefined,
|
||||
path: tParams.path?? undefined,
|
||||
port: inbound.listen_port,
|
||||
ps: inbound.tag,
|
||||
sni: tls?.server?.server_name?? undefined,
|
||||
tls: tls?.server && Object.keys(tls.server).length>0? 'tls' : 'none',
|
||||
allowInsecure: tls?.client?.insecure ? 1 : undefined
|
||||
}
|
||||
let links = <string[]>[]
|
||||
if (addrs.length == 0) {
|
||||
links.push('vmess://' + utf8ToBase64(JSON.stringify(params, null, 2)))
|
||||
} else {
|
||||
addrs.forEach(a => {
|
||||
let newParams = {...params}
|
||||
newParams.add = a.server
|
||||
newParams.port = a.server_port
|
||||
if (a.tls != undefined){
|
||||
if (a.tls) {
|
||||
newParams.tls = 'tls'
|
||||
} else {
|
||||
newParams.tls = 'none'
|
||||
delete newParams.sni
|
||||
delete newParams.allowInsecure
|
||||
}
|
||||
}
|
||||
if (a.server_name?.length>0) {
|
||||
newParams.sni = a.server_name
|
||||
}
|
||||
if (a.insecure) {
|
||||
newParams.allowInsecure = 1
|
||||
}
|
||||
newParams.ps = inbound.tag + (a.remark??'')
|
||||
links.push('vmess://' + utf8ToBase64(JSON.stringify(newParams, null, 2)))
|
||||
})
|
||||
}
|
||||
return links
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,8 @@ const Data = defineStore('Data', {
|
||||
let postData = {
|
||||
object: object,
|
||||
action: action,
|
||||
data: JSON.stringify(data),
|
||||
data: JSON.stringify(data, null, 2),
|
||||
userLinks: userLinks == null ? undefined : JSON.stringify(userLinks),
|
||||
outJsons: outJsons == null ? undefined : JSON.stringify(outJsons),
|
||||
}
|
||||
if (userLinks == null) {
|
||||
delete postData.userLinks
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { Link } from "@/plugins/link"
|
||||
import RandomUtil from "@/plugins/randomUtil"
|
||||
|
||||
export interface Link {
|
||||
type: "local" | "external" | "sub"
|
||||
remark?: string
|
||||
uri: string
|
||||
}
|
||||
|
||||
export interface Client {
|
||||
id?: number
|
||||
enable: boolean
|
||||
|
||||
@@ -345,10 +345,9 @@ import ClientModal from '@/layouts/modals/Client.vue'
|
||||
import ClientBulk from '@/layouts/modals/ClientBulk.vue'
|
||||
import QrCode from '@/layouts/modals/QrCode.vue'
|
||||
import Stats from '@/layouts/modals/Stats.vue'
|
||||
import { Client, createClient } from '@/types/clients'
|
||||
import { Client } from '@/types/clients'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Inbound, inboundWithUsers } from '@/types/inbounds'
|
||||
import { Link, LinkUtil } from '@/plugins/link'
|
||||
import { HumanReadable } from '@/plugins/utils'
|
||||
import { i18n } from '@/locales'
|
||||
import { push } from 'notivue'
|
||||
@@ -443,31 +442,11 @@ const saveModal = async (data:any) => {
|
||||
return
|
||||
}
|
||||
|
||||
// Rebuild links
|
||||
const clientInbounds = data.inbounds.length == 0 ? [] : await Data().loadInbounds(data.inbounds)
|
||||
data.links = updateLinks(data, clientInbounds)
|
||||
|
||||
// save data
|
||||
const success = await Data().save("clients", modal.value.id == 0 ? "new" : "edit", data)
|
||||
if (success) modal.value.visible = false
|
||||
}
|
||||
|
||||
const updateLinks = (c:Client, clientInbounds:Inbound[]):Link[] => {
|
||||
const newLinks = <Link[]>[]
|
||||
clientInbounds.forEach(i =>{
|
||||
const tls = i.tls_id && i.tls_id>0 ? Data().tlsConfigs?.findLast((t:any) => t.id == i.tls_id) : undefined
|
||||
const uris = LinkUtil.linkGenerator(c,i, tls, i.addrs)
|
||||
if (uris.length>0){
|
||||
uris.forEach(uri => {
|
||||
newLinks.push(<Link>{ type: 'local', remark: i.tag, uri: uri })
|
||||
})
|
||||
}
|
||||
})
|
||||
let links = c.links && c.links.length>0? c.links : <Link[]>[]
|
||||
links = [...newLinks, ...links.filter(l => l.type != 'local')]
|
||||
|
||||
return links
|
||||
}
|
||||
const delClient = async (id: number) => {
|
||||
const index = clients.value.findIndex(c => c.id === id)
|
||||
const success = await Data().save("clients", "del", id)
|
||||
@@ -557,10 +536,6 @@ const closeBulk = () => {
|
||||
}
|
||||
|
||||
const saveBulk = async (bulkClients: Client[], clientInbounds: number[]) => {
|
||||
const inboundData = clientInbounds.length == 0 ? [] : await Data().loadInbounds(clientInbounds)
|
||||
bulkClients.forEach((c,c_index) => {
|
||||
bulkClients[c_index].links = updateLinks(c, inboundData)
|
||||
})
|
||||
clients.value.push(...bulkClients)
|
||||
closeBulk()
|
||||
}
|
||||
|
||||
@@ -112,7 +112,6 @@ import { Config } from '@/types/config'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { Inbound, inboundWithUsers } from '@/types/inbounds'
|
||||
import { Client } from '@/types/clients'
|
||||
import { Link, LinkUtil } from '@/plugins/link'
|
||||
import { i18n } from '@/locales'
|
||||
import { push } from 'notivue'
|
||||
|
||||
@@ -167,68 +166,17 @@ const saveModal = async (data:Inbound) => {
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let userLinkDiff = []
|
||||
// Update links
|
||||
if (data.id > 0 && oldInbound != null) {
|
||||
userLinkDiff = updateLinks(data,oldInbound)
|
||||
}
|
||||
|
||||
// save data
|
||||
const success = await Data().save("inbounds", modal.value.id == 0 ? "new" : "edit", data, userLinkDiff)
|
||||
const success = await Data().save("inbounds", modal.value.id == 0 ? "new" : "edit", data)
|
||||
if (success) modal.value.visible = false
|
||||
}
|
||||
const updateLinks = (i: Inbound, o: Inbound): any[] => {
|
||||
let diff = <any[]>[]
|
||||
const uClients = clients.value.filter(c => c.inbounds.includes(i.id))
|
||||
if (uClients.length == 0) return diff
|
||||
|
||||
if (inboundWithUsers.includes(o.type) && !inboundWithUsers.includes(i.type)){
|
||||
// Remove old inbound links if new type does not support users
|
||||
uClients.forEach((u:Client) => {
|
||||
u.inbounds = u.inbounds.filter(i => i != o.id)
|
||||
const otherLocalLinks = u.links.filter(l => l.type == 'local' && l.remark != o.tag)
|
||||
let links = u.links && u.links.length>0? u.links : <Link[]>[]
|
||||
links = [...otherLocalLinks, ...links.filter(l => l.type != 'local')]
|
||||
|
||||
diff.push({ id: u.id, links: links, inbounds: u.inbounds })
|
||||
})
|
||||
} else if(inboundWithUsers.includes(i.type)){
|
||||
// Add new inbound links if new type supports users
|
||||
const tls = tlsConfigs?.value.findLast((t:any) => t.id == i.tls_id)
|
||||
uClients.forEach((u:Client) => {
|
||||
const otherLocalLinks = u.links.filter(l => l.type == 'local' && l.remark != i.tag)
|
||||
const uris = LinkUtil.linkGenerator(u,i, tls, i.addrs)
|
||||
let newLinks = <Link[]>[]
|
||||
if (uris.length>0){
|
||||
uris.forEach(uri => {
|
||||
newLinks.push(<Link>{ type: 'local', remark: i.tag, uri: uri })
|
||||
})
|
||||
}
|
||||
let links = u.links && u.links.length>0? u.links : <Link[]>[]
|
||||
links = [...otherLocalLinks, ...newLinks, ...links.filter(l => l.type != 'local')]
|
||||
|
||||
diff.push({ id: u.id, links: links, inbounds: u.inbounds })
|
||||
})
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
const delInbound = async (id: number) => {
|
||||
const index = inbounds.value.findIndex(i => i.id == id)
|
||||
const inb = inbounds.value[index]
|
||||
const tag = inb.tag
|
||||
const tag = inbounds.value[index].tag
|
||||
|
||||
let diff = <any[]>[]
|
||||
// delete inbound in client table
|
||||
const inboundClients = clients.value.filter(c => c.inbounds.includes(id))
|
||||
inboundClients.forEach((c:Client) => {
|
||||
c.inbounds = c.inbounds.filter((x:number) => x!=id)
|
||||
c.links = c.links.filter((x:any) => x.remark!=tag)
|
||||
diff.push({ id: c.id, links: c.links, inbounds: c.inbounds })
|
||||
})
|
||||
|
||||
const success = await Data().save("inbounds", "del", tag, diff)
|
||||
const success = await Data().save("inbounds", "del", tag)
|
||||
if (success) delOverlay.value[index] = false
|
||||
}
|
||||
|
||||
|
||||
@@ -132,29 +132,8 @@ const clone = (obj: any) => {
|
||||
const closeModal = () => {
|
||||
modal.value.visible = false
|
||||
}
|
||||
const saveModal = async (data:any) => {
|
||||
let userLinks = <any[]>[]
|
||||
// New or Edit
|
||||
if (modal.value.id > 0) {
|
||||
const inboundIds = inbounds.value.filter(i => i.tls_id == modal.value.id).map(i => i.id)
|
||||
if (inboundIds.length > 0) {
|
||||
const tlsInbounds = inboundIds.length == 0 ? [] : await Data().loadInbounds(inboundIds)
|
||||
for (const inbound of tlsInbounds) {
|
||||
// Update links
|
||||
const diff = updateLinks(inbound)
|
||||
diff.forEach((d: any) => {
|
||||
if (userLinks.findIndex(l => l.id == d.id) == -1) {
|
||||
userLinks.push(d)
|
||||
} else {
|
||||
const index = userLinks.findIndex(l => l.id == d.id)
|
||||
userLinks[index].links = d.links
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
const success = await Data().save("tls", data.id == 0 ? "new" : "edit", data, userLinks.length > 0 ? null: userLinks)
|
||||
const saveModal = async (data:tls) => {
|
||||
const success = await Data().save("tls", data.id == 0 ? "new" : "edit", data)
|
||||
if (success) modal.value.visible = false
|
||||
}
|
||||
|
||||
@@ -164,29 +143,4 @@ const delTls = async (id: number) => {
|
||||
if (success) delOverlay.value[index] = false
|
||||
}
|
||||
|
||||
const updateLinks = (i: Inbound): any[] => {
|
||||
let diff = <any[]>[]
|
||||
if(inboundWithUsers.includes(i.type) && i.id != 0){
|
||||
const uClients = clients.value.filter(c => c.inbounds.includes(i.id))
|
||||
const tlsClient = tlsConfigs?.value.findLast((t:any) => t.id == i.tls_id)
|
||||
uClients.forEach((u:Client) => {
|
||||
const otherLocalLinks = u.links.filter(l => l.type == 'local' && l.remark != i.tag)
|
||||
const uris = LinkUtil.linkGenerator(u,i, tlsClient, i.addrs)
|
||||
let newLinks = <Link[]>[]
|
||||
if (uris.length>0){
|
||||
uris.forEach(uri => {
|
||||
newLinks.push(<Link>{ type: 'local', remark: i.tag, uri: uri })
|
||||
})
|
||||
}
|
||||
let links = u.links && u.links.length>0? u.links : <Link[]>[]
|
||||
links = [...otherLocalLinks, ...newLinks, ...links.filter(l => l.type != 'local')]
|
||||
|
||||
u.links = links
|
||||
diff.push({ id: u.id, links: links })
|
||||
})
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user