默认入站:显示可选出站,并给一条转成命名入站的路
上一版把默认入站的整个出站块都藏了,结果策略组也看不见。改成只藏 RULE/DIRECT/GLOBAL 那三张卡(它固定是 RULE),策略组和线路照常列出来当上下文,只是不可点。 顺带修一个显示错误:老式顶层端口没有 listen 字段,实际地址是内核从 allow-lan 和 bind-address 推出来的(listener/listener.go:709-718)——allow-lan 关着时绑的是 127.0.0.1,而界面一律显示 0.0.0.0,会让人以为局域网连得上。 转换时会把老式端口字段删掉并把推导出的地址显式写进 listen:不删会导致同一个端口被声明 两次内核起不来,不写 listen 则以后改 allow-lan 会连带影响这个端口。
This commit is contained in:
@@ -30,6 +30,8 @@ const done = ref('')
|
||||
const fields = ref<ListenerFields | null>(null)
|
||||
const formOpen = ref(false)
|
||||
const formEditing = ref<Inbound | null>(null)
|
||||
/** 正在把哪个老式端口字段转成命名入站。null 表示不是在做转换 */
|
||||
const convertingKey = ref<string | null>(null)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -109,12 +111,30 @@ async function pickOutbound(mode: OutboundMode) {
|
||||
|
||||
function openAdd() {
|
||||
formEditing.value = null
|
||||
convertingKey.value = null
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个老式顶层端口转成命名入站。
|
||||
*
|
||||
* 转完它才有 proxy 字段,才能单独指定出站。表单预填端口、类型和它当前实际绑定的地址
|
||||
* (老式端口的地址是内核从 allow-lan 和 bind-address 推出来的,转换后要显式写进 listen,
|
||||
* 否则改 allow-lan 会连带影响这个端口)。名字留空,让用户自己起一个——沿用 mixed-port
|
||||
* 当名字很难看。
|
||||
*/
|
||||
function openConvert() {
|
||||
const target = selected.value
|
||||
if (!target?.legacyKey) return
|
||||
formEditing.value = { ...target, name: '' }
|
||||
convertingKey.value = target.legacyKey
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
function openEdit() {
|
||||
if (!selected.value || selected.value.isDefault) return
|
||||
formEditing.value = selected.value
|
||||
convertingKey.value = null
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
@@ -122,13 +142,23 @@ async function submitForm(entry: ConfigObject) {
|
||||
const next = clone()
|
||||
const listeners = Array.isArray(next.listeners) ? (next.listeners as ConfigObject[]) : []
|
||||
const editingIndex = formEditing.value?.listenerIndex ?? null
|
||||
const converting = convertingKey.value
|
||||
|
||||
if (editingIndex === null) listeners.push(entry)
|
||||
else listeners[editingIndex] = entry
|
||||
next.listeners = listeners
|
||||
|
||||
// 转换时把老式端口字段去掉,否则同一个端口会被声明两次,内核起不来
|
||||
if (converting) delete next[converting]
|
||||
|
||||
formOpen.value = false
|
||||
await commit(next, editingIndex === null ? `新增了 ${String(entry.name)}` : '改动已保存')
|
||||
convertingKey.value = null
|
||||
const what = converting
|
||||
? `${converting} 转成了命名入站 ${String(entry.name)}`
|
||||
: editingIndex === null
|
||||
? `新增了 ${String(entry.name)}`
|
||||
: '改动已保存'
|
||||
await commit(next, what)
|
||||
if (editingIndex === null) selectedId.value = `listener:${String(listeners.length - 1)}`
|
||||
}
|
||||
|
||||
@@ -211,6 +241,7 @@ async function removeSelected() {
|
||||
@pick="pickOutbound"
|
||||
@edit="openEdit"
|
||||
@remove="removeSelected"
|
||||
@convert="openConvert"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user