update new features service-dns

This commit is contained in:
Alireza Ahmadi
2025-05-28 23:00:19 +02:00
parent d873c86ef8
commit fc410c9a8d
11 changed files with 538 additions and 67 deletions
+16 -1
View File
@@ -22,6 +22,7 @@ type ConfigService struct {
SettingService
InboundService
OutboundService
ServicesService
EndpointService
}
@@ -31,6 +32,7 @@ type SingBoxConfig struct {
Ntp json.RawMessage `json:"ntp"`
Inbounds []json.RawMessage `json:"inbounds"`
Outbounds []json.RawMessage `json:"outbounds"`
Services []json.RawMessage `json:"services"`
Endpoints []json.RawMessage `json:"endpoints"`
Route json.RawMessage `json:"route"`
Experimental json.RawMessage `json:"experimental"`
@@ -63,6 +65,10 @@ func (s *ConfigService) GetConfig(data string) (*SingBoxConfig, error) {
if err != nil {
return nil, err
}
singboxConfig.Services, err = s.ServicesService.GetAllConfig(database.GetDB())
if err != nil {
return nil, err
}
singboxConfig.Endpoints, err = s.EndpointService.GetAllConfig(database.GetDB())
if err != nil {
return nil, err
@@ -119,6 +125,7 @@ func (s *ConfigService) StopCore() error {
func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initUsers string, loginUser string, hostname string) ([]string, error) {
var err error
var inboundIds []uint
var serviceIds []uint
var inboundId uint
var objs []string = []string{obj}
@@ -133,6 +140,12 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initU
logger.Error("unable to restart inbounds: ", err1)
}
}
if len(serviceIds) > 0 && corePtr.IsRunning() {
err1 := s.ServicesService.RestartServices(db, serviceIds)
if err1 != nil {
logger.Error("unable to restart services: ", err1)
}
}
// Try to start core if it is not running
if !corePtr.IsRunning() {
s.StartCore("")
@@ -147,11 +160,13 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initU
inboundIds, err = s.ClientService.Save(tx, act, data, hostname)
objs = append(objs, "inbounds")
case "tls":
inboundIds, err = s.TlsService.Save(tx, act, data)
serviceIds, inboundIds, err = s.TlsService.Save(tx, act, data)
case "inbounds":
inboundId, err = s.InboundService.Save(tx, act, data, initUsers, hostname)
case "outbounds":
err = s.OutboundService.Save(tx, act, data)
case "services":
err = s.ServicesService.Save(tx, act, data)
case "endpoints":
err = s.EndpointService.Save(tx, act, data)
case "config":