fix old link removal on inbound tag change #633
This commit is contained in:
+10
-61
@@ -124,9 +124,6 @@ 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}
|
||||
|
||||
db := database.GetDB()
|
||||
@@ -134,18 +131,6 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initU
|
||||
defer func() {
|
||||
if err == nil {
|
||||
tx.Commit()
|
||||
if len(inboundIds) > 0 && corePtr.IsRunning() {
|
||||
err1 := s.InboundService.RestartInbounds(db, inboundIds)
|
||||
if err1 != nil {
|
||||
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("")
|
||||
@@ -157,12 +142,17 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initU
|
||||
|
||||
switch obj {
|
||||
case "clients":
|
||||
inboundIds, err = s.ClientService.Save(tx, act, data, hostname)
|
||||
objs = append(objs, "inbounds")
|
||||
inboundIds, err := s.ClientService.Save(tx, act, data, hostname)
|
||||
if err == nil && len(inboundIds) > 0 {
|
||||
objs = append(objs, "inbounds")
|
||||
err = s.InboundService.RestartInbounds(tx, inboundIds)
|
||||
}
|
||||
case "tls":
|
||||
serviceIds, inboundIds, err = s.TlsService.Save(tx, act, data)
|
||||
err = s.TlsService.Save(tx, act, data, hostname)
|
||||
objs = append(objs, "clients", "inbounds")
|
||||
case "inbounds":
|
||||
inboundId, err = s.InboundService.Save(tx, act, data, initUsers, hostname)
|
||||
err = s.InboundService.Save(tx, act, data, initUsers, hostname)
|
||||
objs = append(objs, "clients")
|
||||
case "outbounds":
|
||||
err = s.OutboundService.Save(tx, act, data)
|
||||
case "services":
|
||||
@@ -195,49 +185,8 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, initU
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Commit changes so far
|
||||
tx.Commit()
|
||||
|
||||
LastUpdate = time.Now().Unix()
|
||||
tx = db.Begin()
|
||||
|
||||
// Update side changes
|
||||
|
||||
// Update client links
|
||||
if obj == "tls" && len(inboundIds) > 0 {
|
||||
err = s.ClientService.UpdateLinksByInboundChange(tx, inboundIds, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objs = append(objs, "clients")
|
||||
}
|
||||
if obj == "inbounds" {
|
||||
switch act {
|
||||
case "new":
|
||||
err = s.ClientService.UpdateClientsOnInboundAdd(tx, initUsers, inboundId, hostname)
|
||||
case "edit":
|
||||
err = s.ClientService.UpdateLinksByInboundChange(tx, []uint{inboundId}, hostname)
|
||||
case "del":
|
||||
var tag string
|
||||
err = json.Unmarshal(data, &tag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = s.ClientService.UpdateClientsOnInboundDelete(tx, inboundId, tag)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objs = append(objs, "clients")
|
||||
}
|
||||
|
||||
// Update out_json of inbounds when tls is changed
|
||||
if obj == "tls" && len(inboundIds) > 0 {
|
||||
err = s.InboundService.UpdateOutJsons(tx, inboundIds, hostname)
|
||||
if err != nil {
|
||||
return nil, common.NewError("unable to update out_json of inbounds: ", err.Error())
|
||||
}
|
||||
objs = append(objs, "inbounds")
|
||||
}
|
||||
|
||||
return objs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user