Files
umbrix-libcore/custom/command_server.go

41 lines
1.1 KiB
Go
Raw Normal View History

2023-08-28 13:07:21 +03:30
package main
2023-10-27 14:36:00 +03:30
import (
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
)
2023-08-28 13:07:21 +03:30
var commandServer *libbox.CommandServer
type CommandServerHandler struct{}
func (csh *CommandServerHandler) ServiceReload() error {
2023-10-27 14:36:00 +03:30
log.Trace("[Command Server Handler] Reloading service")
2023-09-10 20:18:33 +03:30
propagateStatus(Starting)
if commandServer != nil {
commandServer.SetService(nil)
commandServer = nil
}
if box != nil {
box.Close()
box = nil
}
2023-10-27 14:36:00 +03:30
return startService(true)
2023-08-28 13:07:21 +03:30
}
2023-09-05 19:00:24 +03:30
func (csh *CommandServerHandler) GetSystemProxyStatus() *libbox.SystemProxyStatus {
2023-10-27 14:36:00 +03:30
log.Trace("[Command Server Handler] Getting system proxy status")
2023-09-05 19:00:24 +03:30
return &libbox.SystemProxyStatus{Available: true, Enabled: false}
}
func (csh *CommandServerHandler) SetSystemProxyEnabled(isEnabled bool) error {
2023-10-27 14:36:00 +03:30
log.Trace("[Command Server Handler] Setting system proxy status")
return csh.ServiceReload()
2023-09-05 19:00:24 +03:30
}
2023-08-28 13:07:21 +03:30
func startCommandServer() error {
2023-10-27 14:36:00 +03:30
log.Trace("[Command Server Handler] Starting command server")
2023-08-28 13:07:21 +03:30
commandServer = libbox.NewCommandServer(&CommandServerHandler{}, 300)
return commandServer.Start()
}