add outbound by link #156

This commit is contained in:
Alireza Ahmadi
2024-06-28 18:17:45 +02:00
parent ba06ad598d
commit 5b6f6daaa8
3 changed files with 123 additions and 61 deletions
+5
View File
@@ -3,6 +3,7 @@ package api
import ( import (
"s-ui/logger" "s-ui/logger"
"s-ui/service" "s-ui/service"
"s-ui/util"
"strconv" "strconv"
"strings" "strings"
@@ -95,6 +96,10 @@ func (a *APIHandler) postHandler(c *gin.Context) {
case "restartApp": case "restartApp":
err = a.PanelService.RestartPanel(3) err = a.PanelService.RestartPanel(3)
jsonMsg(c, "restartApp", err) jsonMsg(c, "restartApp", err)
case "linkConvert":
link := c.Request.FormValue("link")
result, _, err := util.GetOutbound(link, 0)
jsonObj(c, result, err)
default: default:
jsonMsg(c, "API call", nil) jsonMsg(c, "API call", nil)
} }
+27 -7
View File
@@ -109,7 +109,9 @@ func vmess(data string, i int) (*map[string]interface{}, string, error) {
} }
} }
tag, _ := dataJson["ps"].(string) tag, _ := dataJson["ps"].(string)
tag = fmt.Sprintf("%d.%s", i, tag) if i > 0 {
tag = fmt.Sprintf("%d.%s", i, tag)
}
alter_id, ok := dataJson["aid"].(int) alter_id, ok := dataJson["aid"].(int)
if !ok { if !ok {
alter_id = 0 alter_id = 0
@@ -141,7 +143,10 @@ func vless(u *url.URL, i int) (*map[string]interface{}, string, error) {
} }
} }
tp_type := query.Get("type") tp_type := query.Get("type")
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
vless := map[string]interface{}{ vless := map[string]interface{}{
"type": "vless", "type": "vless",
"tag": tag, "tag": tag,
@@ -168,7 +173,10 @@ func trojan(u *url.URL, i int) (*map[string]interface{}, string, error) {
} }
} }
tp_type := query.Get("type") tp_type := query.Get("type")
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
trojan := map[string]interface{}{ trojan := map[string]interface{}{
"type": "trojan", "type": "trojan",
"tag": tag, "tag": tag,
@@ -202,7 +210,10 @@ func hy(u *url.URL, i int) (*map[string]interface{}, string, error) {
tls["insecure"] = true tls["insecure"] = true
} }
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
hy := map[string]interface{}{ hy := map[string]interface{}{
"type": "hysteria", "type": "hysteria",
"tag": tag, "tag": tag,
@@ -252,7 +263,10 @@ func hy2(u *url.URL, i int) (*map[string]interface{}, string, error) {
tls["insecure"] = true tls["insecure"] = true
} }
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
hy2 := map[string]interface{}{ hy2 := map[string]interface{}{
"type": "hysteria2", "type": "hysteria2",
"tag": tag, "tag": tag,
@@ -304,7 +318,10 @@ func tuic(u *url.URL, i int) (*map[string]interface{}, string, error) {
tls["disable_sni"] = true tls["disable_sni"] = true
} }
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
password, _ := u.User.Password() password, _ := u.User.Password()
tuic := map[string]interface{}{ tuic := map[string]interface{}{
"type": "tuic", "type": "tuic",
@@ -340,7 +357,10 @@ func ss(u *url.URL, i int) (*map[string]interface{}, string, error) {
} }
} }
tag := fmt.Sprintf("%d.%s", i, u.Fragment) tag := u.Fragment
if i > 0 {
tag = fmt.Sprintf("%d.%s", i, u.Fragment)
}
ss := map[string]interface{}{ ss := map[string]interface{}{
"type": "shadowsocks", "type": "shadowsocks",
"tag": tag, "tag": tag,
+91 -54
View File
@@ -5,61 +5,84 @@
{{ $t('actions.' + title) + " " + $t('objects.outbound') }} {{ $t('actions.' + title) + " " + $t('objects.outbound') }}
</v-card-title> </v-card-title>
<v-divider></v-divider> <v-divider></v-divider>
<v-card-text> <v-card-text style="padding: 0 16px; overflow-y: scroll;">
<v-row> <v-container style="padding: 0;">
<v-col cols="12" sm="6" md="4"> <v-tabs
<v-select v-model="tab"
hide-details align-tabs="center"
:label="$t('type')" >
:items="Object.keys(outTypes).map((key,index) => ({title: key, value: Object.values(outTypes)[index]}))" <v-tab value="t1">{{ $t('client.basics') }}</v-tab>
v-model="outbound.type" <v-tab value="t2">{{ $t('client.external') }}</v-tab>
@update:modelValue="changeType"> </v-tabs>
</v-select> <v-window v-model="tab">
</v-col> <v-window-item value="t1">
<v-col cols="12" sm="6" md="4"> <v-row>
<v-text-field v-model="outbound.tag" :label="$t('objects.tag')" hide-details></v-text-field> <v-col cols="12" sm="6" md="4">
</v-col> <v-select
</v-row> hide-details
<v-row v-if="!NoServer.includes(outbound.type)"> :label="$t('type')"
<v-col cols="12" sm="6" md="4"> :items="Object.keys(outTypes).map((key,index) => ({title: key, value: Object.values(outTypes)[index]}))"
<v-text-field v-model="outbound.type"
:label="$t('out.addr')" @update:modelValue="changeType">
hide-details </v-select>
v-model="outbound.server"> </v-col>
</v-text-field> <v-col cols="12" sm="6" md="4">
</v-col> <v-text-field v-model="outbound.tag" :label="$t('objects.tag')" hide-details></v-text-field>
<v-col cols="12" sm="6" md="4"> </v-col>
<v-text-field </v-row>
:label="$t('out.port')" <v-row v-if="!NoServer.includes(outbound.type)">
type="number" <v-col cols="12" sm="6" md="4">
min="0" <v-text-field
hide-details :label="$t('out.addr')"
v-model.number="outbound.server_port"> hide-details
</v-text-field> v-model="outbound.server">
</v-col> </v-text-field>
</v-row> </v-col>
<Direct v-if="outbound.type == outTypes.Direct" direction="out" :data="outbound" /> <v-col cols="12" sm="6" md="4">
<Socks v-if="outbound.type == outTypes.SOCKS" :data="outbound" /> <v-text-field
<Http v-if="outbound.type == outTypes.HTTP" :data="outbound" /> :label="$t('out.port')"
<Shadowsocks v-if="outbound.type == outTypes.Shadowsocks" direction="out" :data="outbound" /> type="number"
<Vmess v-if="outbound.type == outTypes.VMess" :data="outbound" /> min="0"
<Trojan v-if="outbound.type == outTypes.Trojan" :data="outbound" /> hide-details
<Wireguard v-if="outbound.type == outTypes.Wireguard" :data="outbound" /> v-model.number="outbound.server_port">
<Hysteria v-if="outbound.type == outTypes.Hysteria" direction="out" :data="outbound" /> </v-text-field>
<ShadowTls v-if="outbound.type == outTypes.ShadowTLS" :data="outbound" /> </v-col>
<Vless v-if="outbound.type == outTypes.VLESS" :data="outbound" /> </v-row>
<Tuic v-if="outbound.type == outTypes.TUIC" direction="out" :data="outbound" /> <Direct v-if="outbound.type == outTypes.Direct" direction="out" :data="outbound" />
<Hysteria2 v-if="outbound.type == outTypes.Hysteria2" direction="out" :data="outbound" /> <Socks v-if="outbound.type == outTypes.SOCKS" :data="outbound" />
<Tor v-if="outbound.type == outTypes.Tor" :data="outbound" /> <Http v-if="outbound.type == outTypes.HTTP" :data="outbound" />
<Ssh v-if="outbound.type == outTypes.SSH" :data="outbound" /> <Shadowsocks v-if="outbound.type == outTypes.Shadowsocks" direction="out" :data="outbound" />
<Selector v-if="outbound.type == outTypes.Selector" :data="outbound" :tags="tags" /> <Vmess v-if="outbound.type == outTypes.VMess" :data="outbound" />
<UrlTest v-if="outbound.type == outTypes.URLTest" :data="outbound" :tags="tags" /> <Trojan v-if="outbound.type == outTypes.Trojan" :data="outbound" />
<Wireguard v-if="outbound.type == outTypes.Wireguard" :data="outbound" />
<Hysteria v-if="outbound.type == outTypes.Hysteria" direction="out" :data="outbound" />
<ShadowTls v-if="outbound.type == outTypes.ShadowTLS" :data="outbound" />
<Vless v-if="outbound.type == outTypes.VLESS" :data="outbound" />
<Tuic v-if="outbound.type == outTypes.TUIC" direction="out" :data="outbound" />
<Hysteria2 v-if="outbound.type == outTypes.Hysteria2" direction="out" :data="outbound" />
<Tor v-if="outbound.type == outTypes.Tor" :data="outbound" />
<Ssh v-if="outbound.type == outTypes.SSH" :data="outbound" />
<Selector v-if="outbound.type == outTypes.Selector" :data="outbound" :tags="tags" />
<UrlTest v-if="outbound.type == outTypes.URLTest" :data="outbound" :tags="tags" />
<Transport v-if="Object.hasOwn(outbound,'transport')" :data="outbound" /> <Transport v-if="Object.hasOwn(outbound,'transport')" :data="outbound" />
<OutTLS v-if="Object.hasOwn(outbound,'tls')" :outbound="outbound" /> <OutTLS v-if="Object.hasOwn(outbound,'tls')" :outbound="outbound" />
<Multiplex v-if="Object.hasOwn(outbound,'multiplex')" direction="out" :data="outbound" /> <Multiplex v-if="Object.hasOwn(outbound,'multiplex')" direction="out" :data="outbound" />
<Dial v-if="!NoDial.includes(outbound.type)" :dial="outbound" :outTags="tags" /> <Dial v-if="!NoDial.includes(outbound.type)" :dial="outbound" :outTags="tags" />
<v-switch v-model="outboundStats" color="primary" :label="$t('stats.enable')" hide-details></v-switch> <v-switch v-model="outboundStats" color="primary" :label="$t('stats.enable')" hide-details></v-switch>
</v-window-item>
<v-window-item value="t2">
<v-row>
<v-col cols="12">
<v-text-field v-model="link" :label="$t('client.external')" hide-details />
</v-col>
<v-col cols="12" align="center">
<v-btn hide-details variant="tonal" :loading="loading" @click="linkConvert">{{ $t('submit') }}</v-btn>
</v-col>
</v-row>
</v-window-item>
</v-window>
</v-container>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-spacer></v-spacer> <v-spacer></v-spacer>
@@ -106,6 +129,7 @@ import Tor from '@/components/protocols/Tor.vue'
import Ssh from '@/components/protocols/Ssh.vue' import Ssh from '@/components/protocols/Ssh.vue'
import Selector from '@/components/protocols/Selector.vue' import Selector from '@/components/protocols/Selector.vue'
import UrlTest from '@/components/protocols/UrlTest.vue' import UrlTest from '@/components/protocols/UrlTest.vue'
import HttpUtils from '@/plugins/httputil'
export default { export default {
props: ['visible', 'data', 'id', 'stats', 'tags'], props: ['visible', 'data', 'id', 'stats', 'tags'],
emits: ['close', 'save'], emits: ['close', 'save'],
@@ -113,6 +137,8 @@ export default {
return { return {
outbound: createOutbound("direct",{ "tag": "" }), outbound: createOutbound("direct",{ "tag": "" }),
title: "add", title: "add",
tab: "t1",
link: "",
loading: false, loading: false,
outTypes: OutTypes, outTypes: OutTypes,
outboundStats: false, outboundStats: false,
@@ -149,6 +175,17 @@ export default {
this.$emit('save', this.outbound, this.outboundStats) this.$emit('save', this.outbound, this.outboundStats)
this.loading = false this.loading = false
}, },
async linkConvert() {
if (this.link.length>0){
this.loading = true
const msg = await HttpUtils.post('api/linkConvert', { link: this.link })
this.loading = false
if (msg.success) {
this.outbound = msg.obj
this.tab = "t1"
}
}
}
}, },
watch: { watch: {
visible(newValue) { visible(newValue) {