|
@@ -38,9 +38,25 @@ func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error) {
|
|
|
return inbounds, nil
|
|
|
}
|
|
|
|
|
|
-func (s *InboundService) checkPortExist(port int, ignoreId int) (bool, error) {
|
|
|
+func (s *InboundService) checkPortExist(listen string, port int, ignoreId int) (bool, error) {
|
|
|
db := database.GetDB()
|
|
|
- db = db.Model(model.Inbound{}).Where("port = ?", port)
|
|
|
+ if listen == "" || listen == "0.0.0.0" || listen == "::" || listen == "::0" {
|
|
|
+ db = db.Model(model.Inbound{}).Where("port = ?", port)
|
|
|
+ } else {
|
|
|
+ db = db.Model(model.Inbound{}).
|
|
|
+ Where("port = ?", port).
|
|
|
+ Where(
|
|
|
+ db.Model(model.Inbound{}).Where(
|
|
|
+ "listen = ?", listen,
|
|
|
+ ).Or(
|
|
|
+ "listen = \"\"",
|
|
|
+ ).Or(
|
|
|
+ "listen = \"0.0.0.0\"",
|
|
|
+ ).Or(
|
|
|
+ "listen = \"::\"",
|
|
|
+ ).Or(
|
|
|
+ "listen = \"::0\""))
|
|
|
+ }
|
|
|
if ignoreId > 0 {
|
|
|
db = db.Where("id != ?", ignoreId)
|
|
|
}
|
|
@@ -135,7 +151,7 @@ func (s *InboundService) checkEmailExistForInbound(inbound *model.Inbound) (stri
|
|
|
}
|
|
|
|
|
|
func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, bool, error) {
|
|
|
- exist, err := s.checkPortExist(inbound.Port, 0)
|
|
|
+ exist, err := s.checkPortExist(inbound.Listen, inbound.Port, 0)
|
|
|
if err != nil {
|
|
|
return inbound, false, err
|
|
|
}
|
|
@@ -252,7 +268,7 @@ func (s *InboundService) GetInbound(id int) (*model.Inbound, error) {
|
|
|
}
|
|
|
|
|
|
func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound, bool, error) {
|
|
|
- exist, err := s.checkPortExist(inbound.Port, inbound.Id)
|
|
|
+ exist, err := s.checkPortExist(inbound.Listen, inbound.Port, inbound.Id)
|
|
|
if err != nil {
|
|
|
return inbound, false, err
|
|
|
}
|
|
@@ -295,7 +311,12 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
|
|
|
oldInbound.Settings = inbound.Settings
|
|
|
oldInbound.StreamSettings = inbound.StreamSettings
|
|
|
oldInbound.Sniffing = inbound.Sniffing
|
|
|
- oldInbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port)
|
|
|
+ if inbound.Listen == "" || inbound.Listen == "0.0.0.0" || inbound.Listen == "::" || inbound.Listen == "::0" {
|
|
|
+ oldInbound.Tag = fmt.Sprintf("inbound-0.0.0.0:%v", inbound.Port)
|
|
|
+ } else {
|
|
|
+ oldInbound.Tag = fmt.Sprintf("inbound-%v:%v", inbound.Listen, inbound.Port)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
needRestart := false
|
|
|
s.xrayApi.Init(p.GetAPIPort())
|