Mihomo improved

This commit is contained in:
MoonDev
2026-04-13 18:56:13 +03:00
parent 8c35022483
commit 6aa0349f5d
11 changed files with 3753 additions and 569 deletions

View File

@@ -45,9 +45,12 @@ func HandleInterfaces(w http.ResponseWriter, r *http.Request) {
type iface struct {
*network.InterfaceStats
Pending bool `json:"pending"`
Pending bool `json:"pending"`
Label string `json:"label,omitempty"`
}
appCfg, _ := config.Load()
result := make([]iface, 0, len(names))
existingNames := map[string]bool{}
for _, name := range names {
@@ -59,8 +62,14 @@ func HandleInterfaces(w http.ResponseWriter, r *http.Request) {
if cfg, ok := fileCfg[name]; ok {
s.Mode = cfg.Mode
}
_, hasPending := network.GetPendingConfig(name), network.GetPendingConfig(name) != nil
result = append(result, iface{s, hasPending})
hasPending := network.GetPendingConfig(name) != nil
label := ""
if appCfg != nil && appCfg.Interfaces != nil {
if ic, ok := appCfg.Interfaces[name]; ok {
label = ic.Label
}
}
result = append(result, iface{s, hasPending, label})
}
// Also include pending VLAN configs not yet present in the system.
@@ -79,7 +88,13 @@ func HandleInterfaces(w http.ResponseWriter, r *http.Request) {
s.IPv4Mask = cfg.Netmask
s.Gateway = cfg.Gateway
}
result = append(result, iface{s, true})
label := cfg.Label
if label == "" && appCfg != nil && appCfg.Interfaces != nil {
if ic, ok := appCfg.Interfaces[name]; ok {
label = ic.Label
}
}
result = append(result, iface{s, true, label})
}
ok(w, result)
@@ -149,8 +164,18 @@ func HandleConfig(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
appCfg, _ := config.Load()
label := ""
if appCfg != nil && appCfg.Interfaces != nil {
if ic, ok2 := appCfg.Interfaces[name]; ok2 {
label = ic.Label
}
}
if cfg := network.GetPendingConfig(name); cfg != nil {
ok(w, map[string]interface{}{"config": cfg, "pending": true})
if cfg.Label != "" {
label = cfg.Label
}
ok(w, map[string]interface{}{"config": cfg, "pending": true, "label": label})
return
}
fileCfg, err := network.ParseConfig()
@@ -159,11 +184,12 @@ func HandleConfig(w http.ResponseWriter, r *http.Request) {
return
}
if cfg, exists := fileCfg[name]; exists {
ok(w, map[string]interface{}{"config": cfg, "pending": false})
ok(w, map[string]interface{}{"config": cfg, "pending": false, "label": label})
} else {
ok(w, map[string]interface{}{
"config": &network.InterfaceConfig{Name: name, Auto: true, Mode: "dhcp", Extra: map[string]string{}},
"pending": false,
"label": label,
})
}
@@ -188,6 +214,7 @@ func HandleConfig(w http.ResponseWriter, r *http.Request) {
appCfg.Interfaces = map[string]*config.InterfaceConfig{}
}
appCfg.Interfaces[name] = &config.InterfaceConfig{
Label: cfg.Label,
Auto: cfg.Auto,
Mode: cfg.Mode,
Address: cfg.Address,