all adjustments
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
<template>
|
||||
<v-dialog transition="dialog-bottom-transition" width="800">
|
||||
<v-card class="rounded-lg">
|
||||
<v-dialog transition="dialog-bottom-transition" width="800" @after-enter="updateData">
|
||||
<v-card class="rounded-lg" :loading="loading">
|
||||
<v-card-title>
|
||||
{{ $t('actions.' + title) + " " + $t('objects.inbound') }}
|
||||
</v-card-title>
|
||||
<v-divider></v-divider>
|
||||
<v-skeleton-loader
|
||||
class="mx-auto border"
|
||||
width="95%"
|
||||
type="card, text, divider, list-item-two-line"
|
||||
v-if="loading"
|
||||
></v-skeleton-loader>
|
||||
<v-card-text style="padding: 0 16px; overflow-y: scroll;">
|
||||
<v-container style="padding: 0;">
|
||||
<v-container style="padding: 0;" :hidden="loading">
|
||||
<v-row>
|
||||
<v-col cols="12" sm="6" md="4">
|
||||
<v-select
|
||||
@@ -45,19 +51,18 @@
|
||||
<TProxy v-if="inbound.type == inTypes.TProxy" :inbound="inbound" />
|
||||
<Transport v-if="Object.hasOwn(inbound,'transport')" :data="inbound" />
|
||||
<Users v-if="HasOptionalUser.includes(inbound.type)" :inbound="inbound" />
|
||||
<InTls v-if="Object.hasOwn(inbound,'tls')" :inbound="inbound" :tlsConfigs="tlsConfigs" :tls_id="tls_id" />
|
||||
<InTls v-if="HasTls.includes(inbound.type)" :inbound="inbound" :tlsConfigs="tlsConfigs" :tls_id="inbound.tls_id" />
|
||||
<Multiplex v-if="Object.hasOwn(inbound,'multiplex')" direction="in" :data="inbound" />
|
||||
<v-switch v-model="inboundStats" color="primary" :label="$t('stats.enable')" hide-details></v-switch>
|
||||
</v-window-item>
|
||||
<v-window-item value="c">
|
||||
<OutJsonVue :inData="inData" :type="inbound.type" />
|
||||
<Multiplex v-if="Object.hasOwn(inbound,'multiplex')" direction="out" :data="inData.outJson" />
|
||||
<OutJsonVue :inData="inbound" :type="inbound.type" />
|
||||
<Multiplex v-if="Object.hasOwn(inbound,'multiplex')" direction="out" :data="inbound.out_json" />
|
||||
<v-card>
|
||||
<v-card-subtitle>{{ $t('in.multiDomain') }}
|
||||
<v-icon @click="add_addr" icon="mdi-plus"></v-icon>
|
||||
</v-card-subtitle>
|
||||
<template v-for="addr,index in inData.addrs">
|
||||
{{ $t('in.addr') }} #{{ (index+1) }} <v-icon icon="mdi-delete" @click="inData.addrs.splice(index,1)" />
|
||||
<template v-for="addr,index in inbound.addrs">
|
||||
{{ $t('in.addr') }} #{{ (index+1) }} <v-icon icon="mdi-delete" @click="inbound.addrs?.splice(index,1)" />
|
||||
<v-divider></v-divider>
|
||||
<AddrVue :addr="addr" :hasTls="Object.hasOwn(inbound,'tls')" />
|
||||
</template>
|
||||
@@ -79,6 +84,7 @@
|
||||
color="blue-darken-1"
|
||||
variant="text"
|
||||
:loading="loading"
|
||||
:disabled="!validate"
|
||||
@click="saveChanges"
|
||||
>
|
||||
{{ $t('actions.save') }}
|
||||
@@ -89,8 +95,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { InTypes, createInbound } from '@/types/inbounds'
|
||||
import { Addr, InData } from '@/plugins/inData'
|
||||
import { InTypes, createInbound, Addr } from '@/types/inbounds'
|
||||
import RandomUtil from '@/plugins/randomUtil'
|
||||
|
||||
import Listen from '@/components/Listen.vue'
|
||||
@@ -109,19 +114,17 @@ import Multiplex from '@/components/Multiplex.vue'
|
||||
import Transport from '@/components/Transport.vue'
|
||||
import AddrVue from '@/components/Addr.vue'
|
||||
import OutJsonVue from '@/components/OutJson.vue'
|
||||
import Data from '@/store/modules/data'
|
||||
export default {
|
||||
props: ['visible', 'data', 'cData', 'index', 'stats', 'inTags', 'outTags', 'tlsConfigs'],
|
||||
props: ['visible', 'id', 'inTags', 'outTags', 'tlsConfigs'],
|
||||
emits: ['close', 'save'],
|
||||
data() {
|
||||
return {
|
||||
inbound: createInbound("direct",{ "tag": "" }),
|
||||
inData: <InData>{},
|
||||
inbound: createInbound("direct",{ id:0, "tag": "" }),
|
||||
title: "add",
|
||||
loading: false,
|
||||
side: "s",
|
||||
inTypes: InTypes,
|
||||
inboundStats: false,
|
||||
tls_id: { value: 0 },
|
||||
HasOptionalUser: [InTypes.Mixed,InTypes.SOCKS,InTypes.HTTP,InTypes.Shadowsocks],
|
||||
HasInData: [
|
||||
InTypes.SOCKS,
|
||||
@@ -136,56 +139,65 @@ export default {
|
||||
InTypes.TUIC,
|
||||
InTypes.Hysteria2,
|
||||
InTypes.Naive,
|
||||
]
|
||||
],
|
||||
HasTls: [
|
||||
InTypes.HTTP,
|
||||
InTypes.VMess,
|
||||
InTypes.Trojan,
|
||||
InTypes.Naive,
|
||||
InTypes.Hysteria,
|
||||
InTypes.TUIC,
|
||||
InTypes.Hysteria2,
|
||||
InTypes.VLESS,
|
||||
],
|
||||
OnlyTLS: [InTypes.Hysteria, InTypes.Hysteria2, InTypes.TUIC, InTypes.Naive ],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadData() {
|
||||
this.loading = true
|
||||
const inboundArray = await Data().loadInbounds([this.$props.id])
|
||||
this.inbound = inboundArray[0]
|
||||
this.loading = false
|
||||
},
|
||||
updateData() {
|
||||
if (this.$props.index != -1) {
|
||||
const newData = JSON.parse(this.$props.data)
|
||||
this.inbound = createInbound(newData.type, newData)
|
||||
this.tls_id.value = this.$props.tlsConfigs?.findLast((t:any) => t.inbounds?.includes(this.inbound.tag))?.id?? 0
|
||||
if (this.HasInData.includes(this.inbound.type)){
|
||||
this.inData = this.$props.cData?.length> 0 ? <InData>JSON.parse(this.$props.cData) : <InData>{id: 0, tag: this.inbound.tag, addrs: [], outJson: {}}
|
||||
} else {
|
||||
this.inData = <InData>{id: -1}
|
||||
}
|
||||
if (this.$props.id > 0) {
|
||||
this.loadData()
|
||||
this.title = "edit"
|
||||
}
|
||||
else {
|
||||
const port = RandomUtil.randomIntRange(10000, 60000)
|
||||
this.inbound = createInbound("direct",{ tag: "direct-"+port ,listen: "::", listen_port: port })
|
||||
this.tls_id.value = 0
|
||||
this.inbound = createInbound("direct",{ id: 0, tag: "direct-"+port ,listen: "::", listen_port: port })
|
||||
if (this.HasInData.includes(this.inbound.type)){
|
||||
this.inData = <InData>{id: 0, tag: this.inbound.tag, addrs: [], outJson: {}}
|
||||
this.inbound.addrs = []
|
||||
this.inbound.out_json = {}
|
||||
} else {
|
||||
this.inData = <InData>{id: -1}
|
||||
delete this.inbound.addrs
|
||||
delete this.inbound.out_json
|
||||
}
|
||||
this.title = "add"
|
||||
this.loading = false
|
||||
}
|
||||
this.inboundStats = this.$props.stats
|
||||
this.side = "s"
|
||||
},
|
||||
changeType() {
|
||||
if (!this.inbound.listen_port) this.inbound.listen_port = RandomUtil.randomIntRange(10000, 60000)
|
||||
// Tag change only in add inbound
|
||||
const tag = this.$props.index != -1 ? this.inbound.tag : this.inbound.type + "-" + this.inbound.listen_port
|
||||
const tag = this.$props.id > 0 ? this.inbound.tag : this.inbound.type + "-" + this.inbound.listen_port
|
||||
// Use previous data
|
||||
const prevConfig = { tag: tag ,listen: this.inbound.listen?? "::", listen_port: this.inbound.listen_port }
|
||||
const prevConfig = { id: this.inbound.id, tag: tag ,listen: this.inbound.listen?? "::", listen_port: this.inbound.listen_port }
|
||||
this.inbound = createInbound(this.inbound.type, this.inbound.type != this.inTypes.Tun ? prevConfig : { tag: tag })
|
||||
if (this.HasInData.includes(this.inbound.type)){
|
||||
if (this.inData.id == -1) this.inData.id = 0
|
||||
this.inData.addrs = []
|
||||
this.inData.outJson = {}
|
||||
this.inData.tag = tag
|
||||
this.inbound.addrs = []
|
||||
this.inbound.out_json = {}
|
||||
} else {
|
||||
this.inData = <InData>{id: -1}
|
||||
delete this.inbound.addrs
|
||||
delete this.inbound.out_json
|
||||
}
|
||||
this.tls_id.value = 0
|
||||
this.side = "s"
|
||||
},
|
||||
add_addr() {
|
||||
this.inData.addrs.push(<Addr>{ server: location.hostname, server_port: this.inbound.listen_port })
|
||||
this.inbound.addrs?.push(<Addr>{ server: location.hostname, server_port: this.inbound.listen_port })
|
||||
},
|
||||
closeModal() {
|
||||
this.updateData() // reset
|
||||
@@ -193,14 +205,23 @@ export default {
|
||||
},
|
||||
saveChanges() {
|
||||
this.loading = true
|
||||
this.$emit('save', this.inbound, this.inboundStats, this.tls_id.value, this.inData)
|
||||
this.$emit('save', this.inbound)
|
||||
this.loading = false
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
validate() {
|
||||
if (this.inbound == undefined) return false
|
||||
if (this.inbound.tag == "") return false
|
||||
if (this.inbound.listen_port > 65535 || this.inbound.listen_port < 1) return false
|
||||
if (this.OnlyTLS.includes(this.inbound.type) && this.inbound.tls_id == 0) return false
|
||||
return true
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
visible(newValue) {
|
||||
if (newValue) {
|
||||
this.updateData()
|
||||
this.loading = true
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user