all adjustments
This commit is contained in:
+82
-71
@@ -2,19 +2,19 @@
|
||||
<TlsVue
|
||||
v-model="modal.visible"
|
||||
:visible="modal.visible"
|
||||
:index="modal.index"
|
||||
:id="modal.id"
|
||||
:data="modal.data"
|
||||
@close="closeModal"
|
||||
@save="saveModal"
|
||||
/>
|
||||
<v-row>
|
||||
<v-col cols="12" justify="center" align="center">
|
||||
<v-btn color="primary" @click="showModal(-1)">{{ $t('actions.add') }}</v-btn>
|
||||
<v-btn color="primary" @click="showModal(0)">{{ $t('actions.add') }}</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
<v-col cols="12" sm="4" md="3" lg="2" v-for="(item, index) in <any[]>tlsConfigs" :key="item.id">
|
||||
<v-card rounded="xl" elevation="5" min-width="200" :title="(item.id? item.id + '. ' : '*') + item.name">
|
||||
<v-card rounded="xl" elevation="5" min-width="200" :title="item.name">
|
||||
<v-card-subtitle style="margin-top: -20px;">
|
||||
{{ item.server?.server_name?.length>0 ? item.server.server_name : "-" }}
|
||||
</v-card-subtitle>
|
||||
@@ -22,10 +22,13 @@
|
||||
<v-row>
|
||||
<v-col>{{ $t('pages.inbounds') }}</v-col>
|
||||
<v-col dir="ltr">
|
||||
<v-tooltip activator="parent" dir="ltr" location="bottom" v-if="item.inbounds?.length>0">
|
||||
<span v-for="i in item.inbounds">{{ i }}<br /></span>
|
||||
</v-tooltip>
|
||||
{{ item.inbounds?.length }}
|
||||
<template v-if="tlsInbounds(item.id).length>0">
|
||||
<v-tooltip activator="parent" dir="ltr" location="bottom">
|
||||
<span v-for="i in tlsInbounds(item.id)">{{ i }}<br /></span>
|
||||
</v-tooltip>
|
||||
{{ tlsInbounds.length }}
|
||||
</template>
|
||||
<template v-else>-</template>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
@@ -49,11 +52,11 @@
|
||||
</v-card-text>
|
||||
<v-divider></v-divider>
|
||||
<v-card-actions style="padding: 0;">
|
||||
<v-btn icon="mdi-file-edit" @click="showModal(index)">
|
||||
<v-btn icon="mdi-file-edit" @click="showModal(item.id)">
|
||||
<v-icon />
|
||||
<v-tooltip activator="parent" location="top" :text="$t('actions.edit')"></v-tooltip>
|
||||
</v-btn>
|
||||
<v-btn v-if="item.inbounds?.length == 0" icon="mdi-file-remove" style="margin-inline-start:0;" color="warning" @click="delOverlay[index] = true">
|
||||
<v-btn v-if="tlsInbounds(item.id).length == 0" icon="mdi-file-remove" style="margin-inline-start:0;" color="warning" @click="delOverlay[index] = true">
|
||||
<v-icon />
|
||||
<v-tooltip activator="parent" location="top" :text="$t('actions.del')"></v-tooltip>
|
||||
</v-btn>
|
||||
@@ -66,12 +69,12 @@
|
||||
<v-divider></v-divider>
|
||||
<v-card-text>{{ $t('confirm') }}</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn color="error" variant="outlined" @click="delTls(index)">{{ $t('yes') }}</v-btn>
|
||||
<v-btn color="error" variant="outlined" @click="delTls(item.id)">{{ $t('yes') }}</v-btn>
|
||||
<v-btn color="success" variant="outlined" @click="delOverlay[index] = false">{{ $t('no') }}</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-overlay>
|
||||
<v-btn icon="mdi-content-duplicate" @click="clone(index)">
|
||||
<v-btn icon="mdi-content-duplicate" @click="clone(item)">
|
||||
<v-icon />
|
||||
<v-tooltip activator="parent" location="top" :text="$t('actions.clone')"></v-tooltip>
|
||||
</v-btn>
|
||||
@@ -85,8 +88,7 @@
|
||||
import TlsVue from '@/layouts/modals/Tls.vue'
|
||||
import Data from '@/store/modules/data'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Config } from '@/types/config'
|
||||
import { Inbound } from '@/types/inbounds'
|
||||
import { Inbound, inboundWithUsers } from '@/types/inbounds'
|
||||
import { Client } from '@/types/clients'
|
||||
import { Link, LinkUtil } from '@/plugins/link'
|
||||
import { fillData } from '@/plugins/outJson'
|
||||
@@ -95,13 +97,13 @@ const tlsConfigs = computed((): any[] => {
|
||||
return Data().tlsConfigs
|
||||
})
|
||||
|
||||
const inbounds = computed((): any[] => {
|
||||
return <any[]>(<Config>Data().config)?.inbounds
|
||||
const inbounds = computed((): Inbound[] => {
|
||||
return Data().inbounds
|
||||
})
|
||||
|
||||
const inData = computed((): any[] => {
|
||||
return <any[]> Data().inData
|
||||
})
|
||||
const tlsInbounds = (id: number): string[] => {
|
||||
return inbounds.value.filter(i => i.tls_id == id).map(i => i.tag)
|
||||
}
|
||||
|
||||
const clients = computed((): any[] => {
|
||||
return <Client[]>Data().clients
|
||||
@@ -109,21 +111,20 @@ const clients = computed((): any[] => {
|
||||
|
||||
const modal = ref({
|
||||
visible: false,
|
||||
index: -1,
|
||||
id: 0,
|
||||
data: "",
|
||||
})
|
||||
|
||||
const delOverlay = ref(new Array<boolean>(tlsConfigs.value.length).fill(false))
|
||||
|
||||
const showModal = (index: number) => {
|
||||
modal.value.index = index
|
||||
modal.value.data = index == -1 ? '{}' : JSON.stringify(tlsConfigs.value[index])
|
||||
const showModal = (id: number) => {
|
||||
modal.value.id = id
|
||||
modal.value.data = id == 0 ? '{}' : JSON.stringify(tlsConfigs.value.findLast(t => t.id == id))
|
||||
modal.value.visible = true
|
||||
}
|
||||
const clone = (index: number) => {
|
||||
let data = JSON.parse(JSON.stringify(tlsConfigs.value[index]))
|
||||
const clone = (obj: any) => {
|
||||
let data = JSON.parse(JSON.stringify(obj))
|
||||
data.id = 0
|
||||
data.inbounds = []
|
||||
while (tlsConfigs.value.findIndex(t => t.name == data.name) != -1){
|
||||
data.name += "-copy"
|
||||
}
|
||||
@@ -132,57 +133,67 @@ const clone = (index: number) => {
|
||||
const closeModal = () => {
|
||||
modal.value.visible = false
|
||||
}
|
||||
const saveModal = (data:any) => {
|
||||
const saveModal = async (data:any) => {
|
||||
let outJsons = <any[]>[]
|
||||
let userLinks = <any[]>[]
|
||||
// New or Edit
|
||||
if (modal.value.index == -1) {
|
||||
tlsConfigs.value.push(data)
|
||||
} else {
|
||||
tlsConfigs.value[modal.value.index] = data
|
||||
inbounds?.value.filter(i => tlsConfigs.value[modal.value.index].inbounds.includes(i.tag)).forEach(i =>{
|
||||
if (i.tls != undefined) i.tls = data.server
|
||||
updateInData(i,data.client)
|
||||
updateLinks(i,data.client)
|
||||
})
|
||||
}
|
||||
modal.value.visible = false
|
||||
}
|
||||
|
||||
const delTls = (index: number) => {
|
||||
if (index < Data().oldData.tlsConfigs.length){
|
||||
Data().delTls(tlsConfigs.value[index].id)
|
||||
}
|
||||
tlsConfigs.value.splice(index,1)
|
||||
delOverlay.value[index] = false
|
||||
}
|
||||
|
||||
const updateLinks = (i:any,tlsClient:any) => {
|
||||
if(i.users){
|
||||
const uClients = clients.value.filter(c => c.inbounds.includes(i.tag))
|
||||
uClients.forEach((client:any) => {
|
||||
const clientInbounds = <Inbound[]>inbounds.value.filter(inb => client?.inbounds.includes(inb.tag))
|
||||
const newLinks = <Link[]>[]
|
||||
clientInbounds.forEach(i =>{
|
||||
const cData = <any>Data().inData?.findLast((d:any) => d.tag == i.tag)
|
||||
const addrs = cData ? <any[]>cData.addrs : []
|
||||
const uris = LinkUtil.linkGenerator(client,i, tlsClient, addrs)
|
||||
if (uris.length>0){
|
||||
uris.forEach(uri => {
|
||||
newLinks.push(<Link>{ type: 'local', remark: i.tag, uri: uri })
|
||||
})
|
||||
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) {
|
||||
// Fill outjson
|
||||
if (inbound.out_json) {
|
||||
fillData(inbound, data)
|
||||
}
|
||||
})
|
||||
let links = client.links && client.links.length>0? client.links : <Link[]>[]
|
||||
links = [...newLinks, ...links.filter((l:Link) => l.type != 'local')]
|
||||
outJsons.push({tag: inbound.tag,out_jsons: inbound.out_json})
|
||||
// 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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
client.links = links
|
||||
}
|
||||
const success = await Data().save("tls", data.id == 0 ? "new" : "edit", data, userLinks.length > 0 ? null: userLinks, outJsons.length > 0 ? null: outJsons)
|
||||
if (success) modal.value.visible = false
|
||||
}
|
||||
|
||||
const delTls = async (id: number) => {
|
||||
const index = tlsConfigs.value.findIndex(t => t.id == id)
|
||||
const success = await Data().save("tls", "del", id)
|
||||
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
|
||||
}
|
||||
|
||||
const updateInData = (i:any, c:any) => {
|
||||
const inDataIndex = inData.value.findIndex(d => d.tag == i.tag)
|
||||
if (inDataIndex != -1) {
|
||||
fillData(inData.value[inDataIndex].outJson, i, c)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user