chore: tuic-server support restful api patch

This commit is contained in:
wwqgtxx
2022-11-28 18:53:09 +08:00
parent 4b1d4a3e20
commit 01e382285d
3 changed files with 63 additions and 6 deletions

View File

@ -41,7 +41,7 @@ type configSchema struct {
TProxyPort *int `json:"tproxy-port"`
MixedPort *int `json:"mixed-port"`
Tun *tunSchema `json:"tun"`
TuicServer *config.TuicServer `json:"tuic-server"`
TuicServer *tuicServerSchema `json:"tuic-server"`
ShadowSocksConfig *string `json:"ss-config"`
VmessConfig *string `json:"vmess-config"`
TcptunConfig *string `json:"tcptun-config"`
@ -82,6 +82,19 @@ type tunSchema struct {
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
}
type tuicServerSchema struct {
Enable bool `yaml:"enable" json:"enable"`
Listen *string `yaml:"listen" json:"listen"`
Token *[]string `yaml:"token" json:"token"`
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"`
}
func getConfigs(w http.ResponseWriter, r *http.Request) {
general := executor.GetGeneral()
render.JSON(w, r, general)
@ -161,6 +174,40 @@ func pointerOrDefaultTun(p *tunSchema, def config.Tun) config.Tun {
return def
}
func pointerOrDefaultTuicServer(p *tuicServerSchema, def config.TuicServer) config.TuicServer {
if p != nil {
def.Enable = p.Enable
if p.Listen != nil {
def.Listen = *p.Listen
}
if p.Token != nil {
def.Token = *p.Token
}
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
}
}
return def
}
func patchConfigs(w http.ResponseWriter, r *http.Request) {
general := &configSchema{}
if err := render.DecodeJSON(r.Body, general); err != nil {
@ -204,9 +251,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
P.ReCreateVmess(pointerOrDefaultString(general.VmessConfig, ports.VmessConfig), tcpIn, udpIn)
P.ReCreateTcpTun(pointerOrDefaultString(general.TcptunConfig, ports.TcpTunConfig), tcpIn, udpIn)
P.ReCreateUdpTun(pointerOrDefaultString(general.UdptunConfig, ports.UdpTunConfig), tcpIn, udpIn)
if general.TuicServer != nil {
P.ReCreateTuic(*general.TuicServer, tcpIn, udpIn)
}
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tcpIn, udpIn)
if general.Mode != nil {
tunnel.SetMode(*general.Mode)