2018-11-21 13:47:46 +08:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-10-10 19:43:26 +08:00
|
|
|
"net/netip"
|
2018-11-30 17:42:40 +08:00
|
|
|
"path/filepath"
|
2018-11-21 13:47:46 +08:00
|
|
|
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/adapter/inbound"
|
|
|
|
"github.com/metacubex/mihomo/component/dialer"
|
|
|
|
"github.com/metacubex/mihomo/component/resolver"
|
2024-05-17 11:49:09 +08:00
|
|
|
"github.com/metacubex/mihomo/component/updater"
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/config"
|
|
|
|
C "github.com/metacubex/mihomo/constant"
|
|
|
|
"github.com/metacubex/mihomo/hub/executor"
|
|
|
|
P "github.com/metacubex/mihomo/listener"
|
|
|
|
LC "github.com/metacubex/mihomo/listener/config"
|
|
|
|
"github.com/metacubex/mihomo/log"
|
|
|
|
"github.com/metacubex/mihomo/tunnel"
|
2018-11-21 13:47:46 +08:00
|
|
|
|
2021-04-03 14:59:03 +08:00
|
|
|
"github.com/go-chi/chi/v5"
|
2018-11-21 13:47:46 +08:00
|
|
|
"github.com/go-chi/render"
|
|
|
|
)
|
|
|
|
|
|
|
|
func configRouter() http.Handler {
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Get("/", getConfigs)
|
2018-11-30 17:42:40 +08:00
|
|
|
r.Put("/", updateConfigs)
|
2022-05-24 15:04:13 +08:00
|
|
|
r.Post("/geo", updateGeoDatabases)
|
2018-11-28 10:38:30 +08:00
|
|
|
r.Patch("/", patchConfigs)
|
2018-11-21 13:47:46 +08:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
type configSchema struct {
|
2022-11-11 20:56:08 +08:00
|
|
|
Port *int `json:"port"`
|
|
|
|
SocksPort *int `json:"socks-port"`
|
|
|
|
RedirPort *int `json:"redir-port"`
|
|
|
|
TProxyPort *int `json:"tproxy-port"`
|
|
|
|
MixedPort *int `json:"mixed-port"`
|
|
|
|
Tun *tunSchema `json:"tun"`
|
2022-11-28 18:53:09 +08:00
|
|
|
TuicServer *tuicServerSchema `json:"tuic-server"`
|
2022-11-11 20:56:08 +08:00
|
|
|
ShadowSocksConfig *string `json:"ss-config"`
|
|
|
|
VmessConfig *string `json:"vmess-config"`
|
|
|
|
TcptunConfig *string `json:"tcptun-config"`
|
|
|
|
UdptunConfig *string `json:"udptun-config"`
|
|
|
|
AllowLan *bool `json:"allow-lan"`
|
2023-10-10 19:43:26 +08:00
|
|
|
SkipAuthPrefixes *[]netip.Prefix `json:"skip-auth-prefixes"`
|
2023-12-12 20:39:11 +08:00
|
|
|
LanAllowedIPs *[]netip.Prefix `json:"lan-allowed-ips"`
|
|
|
|
LanDisAllowedIPs *[]netip.Prefix `json:"lan-disallowed-ips"`
|
2022-11-11 20:56:08 +08:00
|
|
|
BindAddress *string `json:"bind-address"`
|
|
|
|
Mode *tunnel.TunnelMode `json:"mode"`
|
|
|
|
LogLevel *log.LogLevel `json:"log-level"`
|
|
|
|
IPv6 *bool `json:"ipv6"`
|
|
|
|
Sniffing *bool `json:"sniffing"`
|
|
|
|
TcpConcurrent *bool `json:"tcp-concurrent"`
|
|
|
|
InterfaceName *string `json:"interface-name"`
|
2018-11-21 13:47:46 +08:00
|
|
|
}
|
|
|
|
|
2022-11-04 08:52:30 +08:00
|
|
|
type tunSchema struct {
|
2022-12-06 09:04:30 +08:00
|
|
|
Enable bool `yaml:"enable" json:"enable"`
|
|
|
|
Device *string `yaml:"device" json:"device"`
|
|
|
|
Stack *C.TUNStack `yaml:"stack" json:"stack"`
|
|
|
|
DNSHijack *[]string `yaml:"dns-hijack" json:"dns-hijack"`
|
|
|
|
AutoRoute *bool `yaml:"auto-route" json:"auto-route"`
|
|
|
|
AutoDetectInterface *bool `yaml:"auto-detect-interface" json:"auto-detect-interface"`
|
2022-11-04 08:52:30 +08:00
|
|
|
//RedirectToTun []string `yaml:"-" json:"-"`
|
|
|
|
|
2023-12-10 08:32:54 +08:00
|
|
|
MTU *uint32 `yaml:"mtu" json:"mtu,omitempty"`
|
|
|
|
GSO *bool `yaml:"gso" json:"gso,omitempty"`
|
|
|
|
GSOMaxSize *uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
|
2023-10-10 19:49:16 +08:00
|
|
|
//Inet4Address *[]netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
|
2023-11-02 11:37:40 +08:00
|
|
|
Inet6Address *[]netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
|
|
|
|
StrictRoute *bool `yaml:"strict-route" json:"strict-route,omitempty"`
|
|
|
|
Inet4RouteAddress *[]netip.Prefix `yaml:"inet4-route-address" json:"inet4-route-address,omitempty"`
|
|
|
|
Inet6RouteAddress *[]netip.Prefix `yaml:"inet6-route-address" json:"inet6-route-address,omitempty"`
|
|
|
|
Inet4RouteExcludeAddress *[]netip.Prefix `yaml:"inet4-route-exclude-address" json:"inet4-route-exclude-address,omitempty"`
|
|
|
|
Inet6RouteExcludeAddress *[]netip.Prefix `yaml:"inet6-route-exclude-address" json:"inet6-route-exclude-address,omitempty"`
|
2023-12-10 08:32:54 +08:00
|
|
|
IncludeInterface *[]string `yaml:"include-interface" json:"include-interface,omitempty"`
|
|
|
|
ExcludeInterface *[]string `yaml:"exclude-interface" json:"exclude-interface,omitempty"`
|
2023-11-02 11:37:40 +08:00
|
|
|
IncludeUID *[]uint32 `yaml:"include-uid" json:"include-uid,omitempty"`
|
|
|
|
IncludeUIDRange *[]string `yaml:"include-uid-range" json:"include-uid-range,omitempty"`
|
|
|
|
ExcludeUID *[]uint32 `yaml:"exclude-uid" json:"exclude-uid,omitempty"`
|
|
|
|
ExcludeUIDRange *[]string `yaml:"exclude-uid-range" json:"exclude-uid-range,omitempty"`
|
|
|
|
IncludeAndroidUser *[]int `yaml:"include-android-user" json:"include-android-user,omitempty"`
|
|
|
|
IncludePackage *[]string `yaml:"include-package" json:"include-package,omitempty"`
|
|
|
|
ExcludePackage *[]string `yaml:"exclude-package" json:"exclude-package,omitempty"`
|
|
|
|
EndpointIndependentNat *bool `yaml:"endpoint-independent-nat" json:"endpoint-independent-nat,omitempty"`
|
|
|
|
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
|
|
|
|
FileDescriptor *int `yaml:"file-descriptor" json:"file-descriptor"`
|
2024-03-24 21:31:52 +08:00
|
|
|
TableIndex *int `yaml:"table-index" json:"table-index"`
|
2022-11-04 08:52:30 +08:00
|
|
|
}
|
|
|
|
|
2022-11-28 18:53:09 +08:00
|
|
|
type tuicServerSchema struct {
|
2023-06-12 17:44:22 +08:00
|
|
|
Enable bool `yaml:"enable" json:"enable"`
|
|
|
|
Listen *string `yaml:"listen" json:"listen"`
|
|
|
|
Token *[]string `yaml:"token" json:"token"`
|
|
|
|
Users *map[string]string `yaml:"users" json:"users,omitempty"`
|
|
|
|
Certificate *string `yaml:"certificate" json:"certificate"`
|
|
|
|
PrivateKey *string `yaml:"private-key" json:"private-key"`
|
|
|
|
CongestionController *string `yaml:"congestion-controller" json:"congestion-controller,omitempty"`
|
|
|
|
MaxIdleTime *int `yaml:"max-idle-time" json:"max-idle-time,omitempty"`
|
|
|
|
AuthenticationTimeout *int `yaml:"authentication-timeout" json:"authentication-timeout,omitempty"`
|
|
|
|
ALPN *[]string `yaml:"alpn" json:"alpn,omitempty"`
|
|
|
|
MaxUdpRelayPacketSize *int `yaml:"max-udp-relay-packet-size" json:"max-udp-relay-packet-size,omitempty"`
|
2023-06-21 14:00:49 +08:00
|
|
|
CWND *int `yaml:"cwnd" json:"cwnd,omitempty"`
|
2022-11-28 18:53:09 +08:00
|
|
|
}
|
|
|
|
|
2018-11-21 13:47:46 +08:00
|
|
|
func getConfigs(w http.ResponseWriter, r *http.Request) {
|
|
|
|
general := executor.GetGeneral()
|
2018-12-10 11:33:37 +08:00
|
|
|
render.JSON(w, r, general)
|
2018-11-21 13:47:46 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 10:38:30 +08:00
|
|
|
func pointerOrDefault(p *int, def int) int {
|
2018-11-21 13:47:46 +08:00
|
|
|
if p != nil {
|
|
|
|
return *p
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2022-11-11 20:56:08 +08:00
|
|
|
func pointerOrDefaultString(p *string, def string) string {
|
|
|
|
if p != nil {
|
|
|
|
return *p
|
|
|
|
}
|
|
|
|
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2022-12-04 14:37:52 +08:00
|
|
|
func pointerOrDefaultTun(p *tunSchema, def LC.Tun) LC.Tun {
|
2022-11-04 08:52:30 +08:00
|
|
|
if p != nil {
|
|
|
|
def.Enable = p.Enable
|
|
|
|
if p.Device != nil {
|
|
|
|
def.Device = *p.Device
|
|
|
|
}
|
|
|
|
if p.Stack != nil {
|
|
|
|
def.Stack = *p.Stack
|
|
|
|
}
|
|
|
|
if p.DNSHijack != nil {
|
|
|
|
def.DNSHijack = *p.DNSHijack
|
|
|
|
}
|
|
|
|
if p.AutoRoute != nil {
|
|
|
|
def.AutoRoute = *p.AutoRoute
|
|
|
|
}
|
|
|
|
if p.AutoDetectInterface != nil {
|
|
|
|
def.AutoDetectInterface = *p.AutoDetectInterface
|
|
|
|
}
|
|
|
|
if p.MTU != nil {
|
|
|
|
def.MTU = *p.MTU
|
|
|
|
}
|
2023-12-10 08:32:54 +08:00
|
|
|
if p.GSO != nil {
|
|
|
|
def.GSO = *p.GSO
|
|
|
|
}
|
|
|
|
if p.GSOMaxSize != nil {
|
|
|
|
def.GSOMaxSize = *p.GSOMaxSize
|
|
|
|
}
|
2022-11-04 08:52:30 +08:00
|
|
|
//if p.Inet4Address != nil {
|
|
|
|
// def.Inet4Address = *p.Inet4Address
|
|
|
|
//}
|
|
|
|
if p.Inet6Address != nil {
|
|
|
|
def.Inet6Address = *p.Inet6Address
|
|
|
|
}
|
2023-11-02 11:37:40 +08:00
|
|
|
if p.Inet4RouteAddress != nil {
|
|
|
|
def.Inet4RouteAddress = *p.Inet4RouteAddress
|
|
|
|
}
|
|
|
|
if p.Inet6RouteAddress != nil {
|
|
|
|
def.Inet6RouteAddress = *p.Inet6RouteAddress
|
|
|
|
}
|
|
|
|
if p.Inet4RouteExcludeAddress != nil {
|
|
|
|
def.Inet4RouteExcludeAddress = *p.Inet4RouteExcludeAddress
|
|
|
|
}
|
|
|
|
if p.Inet6RouteExcludeAddress != nil {
|
|
|
|
def.Inet6RouteExcludeAddress = *p.Inet6RouteExcludeAddress
|
|
|
|
}
|
2023-12-10 08:32:54 +08:00
|
|
|
if p.IncludeInterface != nil {
|
|
|
|
def.IncludeInterface = *p.IncludeInterface
|
|
|
|
}
|
|
|
|
if p.ExcludeInterface != nil {
|
|
|
|
def.ExcludeInterface = *p.ExcludeInterface
|
|
|
|
}
|
2022-11-04 08:52:30 +08:00
|
|
|
if p.IncludeUID != nil {
|
|
|
|
def.IncludeUID = *p.IncludeUID
|
|
|
|
}
|
|
|
|
if p.IncludeUIDRange != nil {
|
|
|
|
def.IncludeUIDRange = *p.IncludeUIDRange
|
|
|
|
}
|
|
|
|
if p.ExcludeUID != nil {
|
|
|
|
def.ExcludeUID = *p.ExcludeUID
|
|
|
|
}
|
|
|
|
if p.ExcludeUIDRange != nil {
|
|
|
|
def.ExcludeUIDRange = *p.ExcludeUIDRange
|
|
|
|
}
|
|
|
|
if p.IncludeAndroidUser != nil {
|
|
|
|
def.IncludeAndroidUser = *p.IncludeAndroidUser
|
|
|
|
}
|
|
|
|
if p.IncludePackage != nil {
|
|
|
|
def.IncludePackage = *p.IncludePackage
|
|
|
|
}
|
|
|
|
if p.ExcludePackage != nil {
|
|
|
|
def.ExcludePackage = *p.ExcludePackage
|
|
|
|
}
|
|
|
|
if p.EndpointIndependentNat != nil {
|
|
|
|
def.EndpointIndependentNat = *p.EndpointIndependentNat
|
|
|
|
}
|
|
|
|
if p.UDPTimeout != nil {
|
|
|
|
def.UDPTimeout = *p.UDPTimeout
|
|
|
|
}
|
2023-03-15 23:43:58 +08:00
|
|
|
if p.FileDescriptor != nil {
|
|
|
|
def.FileDescriptor = *p.FileDescriptor
|
|
|
|
}
|
2024-03-24 21:31:52 +08:00
|
|
|
if p.TableIndex != nil {
|
|
|
|
def.TableIndex = *p.TableIndex
|
|
|
|
}
|
2022-11-04 08:52:30 +08:00
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2022-12-04 14:37:52 +08:00
|
|
|
func pointerOrDefaultTuicServer(p *tuicServerSchema, def LC.TuicServer) LC.TuicServer {
|
2022-11-28 18:53:09 +08:00
|
|
|
if p != nil {
|
|
|
|
def.Enable = p.Enable
|
|
|
|
if p.Listen != nil {
|
|
|
|
def.Listen = *p.Listen
|
|
|
|
}
|
|
|
|
if p.Token != nil {
|
|
|
|
def.Token = *p.Token
|
|
|
|
}
|
2023-06-12 17:44:22 +08:00
|
|
|
if p.Users != nil {
|
|
|
|
def.Users = *p.Users
|
|
|
|
}
|
2022-11-28 18:53:09 +08:00
|
|
|
if p.Certificate != nil {
|
|
|
|
def.Certificate = *p.Certificate
|
|
|
|
}
|
|
|
|
if p.PrivateKey != nil {
|
|
|
|
def.PrivateKey = *p.PrivateKey
|
|
|
|
}
|
|
|
|
if p.CongestionController != nil {
|
|
|
|
def.CongestionController = *p.CongestionController
|
|
|
|
}
|
|
|
|
if p.MaxIdleTime != nil {
|
|
|
|
def.MaxIdleTime = *p.MaxIdleTime
|
|
|
|
}
|
|
|
|
if p.AuthenticationTimeout != nil {
|
|
|
|
def.AuthenticationTimeout = *p.AuthenticationTimeout
|
|
|
|
}
|
|
|
|
if p.ALPN != nil {
|
|
|
|
def.ALPN = *p.ALPN
|
|
|
|
}
|
|
|
|
if p.MaxUdpRelayPacketSize != nil {
|
|
|
|
def.MaxUdpRelayPacketSize = *p.MaxUdpRelayPacketSize
|
|
|
|
}
|
2023-06-21 14:00:49 +08:00
|
|
|
if p.CWND != nil {
|
|
|
|
def.CWND = *p.CWND
|
|
|
|
}
|
2022-11-28 18:53:09 +08:00
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2018-11-28 10:38:30 +08:00
|
|
|
func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
2018-11-21 13:47:46 +08:00
|
|
|
general := &configSchema{}
|
2023-01-16 15:20:39 +08:00
|
|
|
if err := render.DecodeJSON(r.Body, &general); err != nil {
|
2018-12-10 11:33:37 +08:00
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, ErrBadRequest)
|
2018-11-21 13:47:46 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if general.AllowLan != nil {
|
|
|
|
P.SetAllowLan(*general.AllowLan)
|
|
|
|
}
|
2018-11-28 10:38:30 +08:00
|
|
|
|
2023-10-10 19:43:26 +08:00
|
|
|
if general.SkipAuthPrefixes != nil {
|
|
|
|
inbound.SetSkipAuthPrefixes(*general.SkipAuthPrefixes)
|
|
|
|
}
|
|
|
|
|
2023-12-12 20:39:11 +08:00
|
|
|
if general.LanAllowedIPs != nil {
|
|
|
|
inbound.SetAllowedIPs(*general.LanAllowedIPs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if general.LanDisAllowedIPs != nil {
|
|
|
|
inbound.SetDisAllowedIPs(*general.LanDisAllowedIPs)
|
|
|
|
}
|
|
|
|
|
2019-08-08 13:45:07 +08:00
|
|
|
if general.BindAddress != nil {
|
|
|
|
P.SetBindAddress(*general.BindAddress)
|
|
|
|
}
|
|
|
|
|
2022-05-24 12:43:26 +08:00
|
|
|
if general.Sniffing != nil {
|
|
|
|
tunnel.SetSniffing(*general.Sniffing)
|
|
|
|
}
|
|
|
|
|
2022-05-26 19:49:12 +08:00
|
|
|
if general.TcpConcurrent != nil {
|
2023-03-06 23:23:05 +08:00
|
|
|
dialer.SetTcpConcurrent(*general.TcpConcurrent)
|
2022-05-26 19:49:12 +08:00
|
|
|
}
|
|
|
|
|
2022-06-18 17:29:19 +08:00
|
|
|
if general.InterfaceName != nil {
|
|
|
|
dialer.DefaultInterface.Store(*general.InterfaceName)
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:47:46 +08:00
|
|
|
ports := P.GetPorts()
|
2021-06-13 17:23:10 +08:00
|
|
|
|
2023-09-28 18:59:31 +08:00
|
|
|
P.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel)
|
|
|
|
P.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel)
|
|
|
|
P.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel)
|
|
|
|
P.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
|
|
|
|
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
|
|
|
|
P.ReCreateTun(pointerOrDefaultTun(general.Tun, P.LastTunConf), tunnel.Tunnel)
|
|
|
|
P.ReCreateShadowSocks(pointerOrDefaultString(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
|
|
|
|
P.ReCreateVmess(pointerOrDefaultString(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
|
|
|
|
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tunnel.Tunnel)
|
2018-11-21 13:47:46 +08:00
|
|
|
|
|
|
|
if general.Mode != nil {
|
2020-02-15 21:42:46 +08:00
|
|
|
tunnel.SetMode(*general.Mode)
|
2018-11-21 13:47:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if general.LogLevel != nil {
|
|
|
|
log.SetLevel(*general.LogLevel)
|
|
|
|
}
|
|
|
|
|
2021-02-05 16:43:42 +08:00
|
|
|
if general.IPv6 != nil {
|
|
|
|
resolver.DisableIPv6 = !*general.IPv6
|
|
|
|
}
|
|
|
|
|
2018-12-10 11:33:37 +08:00
|
|
|
render.NoContent(w, r)
|
2018-11-21 13:47:46 +08:00
|
|
|
}
|
2018-11-30 17:42:40 +08:00
|
|
|
|
|
|
|
func updateConfigs(w http.ResponseWriter, r *http.Request) {
|
2023-01-16 15:20:39 +08:00
|
|
|
req := struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
}{}
|
2018-11-30 17:42:40 +08:00
|
|
|
if err := render.DecodeJSON(r.Body, &req); err != nil {
|
2018-12-10 11:33:37 +08:00
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, ErrBadRequest)
|
2018-11-30 17:42:40 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
force := r.URL.Query().Get("force") == "true"
|
2019-12-01 13:22:47 +08:00
|
|
|
var cfg *config.Config
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if req.Payload != "" {
|
|
|
|
cfg, err = executor.ParseWithBytes([]byte(req.Payload))
|
|
|
|
if err != nil {
|
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, newError(err.Error()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
2021-06-21 17:33:34 +08:00
|
|
|
if req.Path == "" {
|
2023-12-12 20:39:11 +08:00
|
|
|
req.Path = C.Path.Config()
|
2021-06-21 17:33:34 +08:00
|
|
|
}
|
2019-12-01 13:22:47 +08:00
|
|
|
if !filepath.IsAbs(req.Path) {
|
|
|
|
render.Status(r, http.StatusBadRequest)
|
2020-10-14 19:56:02 +08:00
|
|
|
render.JSON(w, r, newError("path is not a absolute path"))
|
2019-12-01 13:22:47 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err = executor.ParseWithPath(req.Path)
|
|
|
|
if err != nil {
|
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, newError(err.Error()))
|
|
|
|
return
|
|
|
|
}
|
2018-11-30 17:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
executor.ApplyConfig(cfg, force)
|
2018-12-10 11:33:37 +08:00
|
|
|
render.NoContent(w, r)
|
2018-11-30 17:42:40 +08:00
|
|
|
}
|
2022-05-24 15:04:13 +08:00
|
|
|
|
|
|
|
func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
2024-05-17 11:49:09 +08:00
|
|
|
if updater.UpdatingGeo.Load() {
|
2022-05-24 15:04:13 +08:00
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, newError("updating..."))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-17 11:49:09 +08:00
|
|
|
err := updater.UpdateGeoDatabases()
|
|
|
|
if err != nil {
|
|
|
|
render.Status(r, http.StatusBadRequest)
|
|
|
|
render.JSON(w, r, newError(err.Error()))
|
|
|
|
return
|
|
|
|
}
|
2022-05-24 15:04:13 +08:00
|
|
|
|
|
|
|
go func() {
|
2023-12-12 20:39:11 +08:00
|
|
|
cfg, err := executor.ParseWithPath(C.Path.Config())
|
2022-05-24 15:04:13 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Errorln("[REST-API] update GEO databases failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Warnln("[REST-API] update GEO databases successful, apply config...")
|
|
|
|
|
|
|
|
executor.ApplyConfig(cfg, false)
|
|
|
|
}()
|
|
|
|
|
|
|
|
render.NoContent(w, r)
|
|
|
|
}
|