diff --git a/backend/cmd/migration/1_2.go b/backend/cmd/migration/1_2.go index f808db9..0e138a7 100644 --- a/backend/cmd/migration/1_2.go +++ b/backend/cmd/migration/1_2.go @@ -113,6 +113,11 @@ func moveJsonToDb(db *gorm.DB) error { inbObj["out_json"] = json.RawMessage("{}") inbObj["addrs"] = json.RawMessage("[]") } + // Delete deprecated fields + delete(inbObj, "sniff") + delete(inbObj, "sniff_override_destination") + delete(inbObj, "sniff_timeout") + delete(inbObj, "domain_strategy") inbJson, _ := json.Marshal(inbObj) var newInbound model.Inbound @@ -127,6 +132,9 @@ func moveJsonToDb(db *gorm.DB) error { } delete(oldConfig, "inbounds") + blockOutboundTags := []string{} + dnsOutboundTags := []string{} + oldOutbounds := oldConfig["outbounds"].([]interface{}) db.Migrator().DropTable(&model.Outbound{}, &model.Endpoint{}) db.AutoMigrate(&model.Outbound{}, &model.Endpoint{}) @@ -149,14 +157,69 @@ func moveJsonToDb(db *gorm.DB) error { if err != nil { return err } - err = db.Create(&newOutbound).Error - if err != nil { - return err + // Delete deprecated fields + if newOutbound.Type == "direct" { + var options map[string]interface{} + json.Unmarshal(newOutbound.Options, &options) + delete(options, "override_address") + delete(options, "override_port") + newOutbound.Options, _ = json.Marshal(options) + } + + switch newOutbound.Type { + case "dns": + dnsOutboundTags = append(dnsOutboundTags, newOutbound.Tag) + case "block": + blockOutboundTags = append(blockOutboundTags, newOutbound.Tag) + default: + err = db.Create(&newOutbound).Error + if err != nil { + return err + } } } } delete(oldConfig, "outbounds") + // Check routing rules + if routingRules, ok := oldConfig["route"].(map[string]interface{}); ok { + if rules, hasRules := routingRules["rules"].([]interface{}); hasRules { + hasDns := false + for index, rule := range rules { + ruleObj, _ := rule.(map[string]interface{}) + isBlock := false + isDns := false + outboundTag, _ := ruleObj["outbound"].(string) + for _, tag := range blockOutboundTags { + if tag == outboundTag { + isBlock = true + delete(ruleObj, "outbound") + ruleObj["action"] = "reject" + break + } + } + for _, tag := range dnsOutboundTags { + if tag == outboundTag { + isDns = true + hasDns = true + delete(ruleObj, "outbound") + ruleObj["action"] = "hijack-dns" + break + } + } + if !isBlock && !isDns { + ruleObj["action"] = "route" + } + rules[index] = ruleObj + } + if hasDns { + rules = append(rules, map[string]interface{}{"action": "sniff"}) + } + routingRules["rules"] = rules + } + oldConfig["route"] = routingRules + } + // Remove v2rayapi and clashapi from experimental config experimental := oldConfig["experimental"].(map[string]interface{}) delete(experimental, "v2ray_api") diff --git a/frontend/src/components/Listen.vue b/frontend/src/components/Listen.vue index 8ea85dc..d037edb 100644 --- a/frontend/src/components/Listen.vue +++ b/frontend/src/components/Listen.vue @@ -29,24 +29,6 @@ v-model="inbound.detour"> - - - - - - - - - - - @@ -70,16 +52,6 @@ v-model.number="udpTimeout"> - - - - - - @@ -97,9 +69,6 @@ - - - @@ -120,10 +89,6 @@ export default { get() { return this.$props.inbound.udp_timeout ? parseInt(this.$props.inbound.udp_timeout.replace('m','')) : 5 }, set(newValue:number) { this.$props.inbound.udp_timeout = newValue > 0 ? newValue + 'm' : '5m' } }, - sniffTimeout: { - get() { return this.$props.inbound.sniff_timeout ? parseInt(this.$props.inbound.sniff_timeout.replace('ms','')) : 300 }, - set(newValue:number) { this.$props.inbound.sniff_timeout = newValue > 0 ? newValue + 'ms' : '300ms' } - }, optionTCP: { get(): boolean { return this.$props.inbound.tcp_fast_open != undefined && @@ -147,10 +112,6 @@ export default { optionDetour: { get(): boolean { return this.$props.inbound.detour != undefined }, set(v:boolean) { this.$props.inbound.detour = v ? this.inTags[0]?? '' : undefined } - }, - optionDS: { - get(): boolean { return this.$props.inbound.domain_strategy != undefined }, - set(v:boolean) { this.$props.inbound.domain_strategy = v ? 'prefer_ipv4' : undefined } } } } diff --git a/frontend/src/components/protocols/Direct.vue b/frontend/src/components/protocols/Direct.vue index c88423a..34823fc 100644 --- a/frontend/src/components/protocols/Direct.vue +++ b/frontend/src/components/protocols/Direct.vue @@ -1,7 +1,7 @@