feat(groups): assign host rules from client groups (#7064)

Host rules could only be given to clients one by one, so giving a set of customers their own endpoints meant editing every client. A client group can now carry host rules, chosen when the group is created, from its edit dialog or from a quick-assign action on the Groups page.

A subscription resolves a client's hosts in this order: the client's own host rules, then the host rules of its group, then the inbound's default pool. A group whose bound rules are all disabled or excluded from the requested format renders nothing for that inbound instead of falling back to the default pool. Binding a rule to a group narrows what its members get; other clients still see that rule in the default pool.

Group names are now matched case-insensitively. On upgrade, labels that differ only in case (VIP and vip) are merged into one group, the first by name order.

Adds POST /panel/api/clients/groups/:name/hosts and an optional hostGroupIds on group create and rename.
This commit is contained in:
Nethmina Yasas
2026-11-25 17:51:43 +05:30
committed by GitHub
parent 4013219698
commit e95d17a7db
46 changed files with 2222 additions and 285 deletions
+36 -6
View File
@@ -27,6 +27,7 @@ func (a *GroupController) initRouter(g *gin.RouterGroup) {
g.POST("/groups/rename", a.rename)
g.POST("/groups/delete", a.delete)
g.POST("/groups/resetTraffic", a.resetTraffic)
g.POST("/groups/:name/hosts", a.setHosts)
g.POST("/groups/bulkAdd", a.bulkAdd)
g.POST("/groups/bulkRemove", a.bulkRemove)
}
@@ -51,7 +52,8 @@ func (a *GroupController) emails(c *gin.Context) {
}
type groupCreateBody struct {
Name string `json:"name"`
Name string `json:"name"`
HostGroupIds []string `json:"hostGroupIds"`
}
func (a *GroupController) create(c *gin.Context) {
@@ -60,7 +62,7 @@ func (a *GroupController) create(c *gin.Context) {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
if err := a.clientService.CreateGroup(body.Name); err != nil {
if err := a.clientService.CreateGroup(body.Name, body.HostGroupIds); err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@@ -69,8 +71,9 @@ func (a *GroupController) create(c *gin.Context) {
}
type groupRenameBody struct {
OldName string `json:"oldName"`
NewName string `json:"newName"`
OldName string `json:"oldName"`
NewName string `json:"newName"`
HostGroupIds *[]string `json:"hostGroupIds"`
}
func (a *GroupController) rename(c *gin.Context) {
@@ -79,12 +82,20 @@ func (a *GroupController) rename(c *gin.Context) {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
affected, err := a.clientService.RenameGroup(body.OldName, body.NewName)
var affected int
var err error
if body.HostGroupIds != nil {
affected, err = a.clientService.UpdateGroup(body.OldName, body.NewName, *body.HostGroupIds)
} else {
affected, err = a.clientService.RenameGroup(body.OldName, body.NewName)
}
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
a.xrayService.SetToNeedRestart()
if strings.TrimSpace(body.OldName) != strings.TrimSpace(body.NewName) {
a.xrayService.SetToNeedRestart()
}
jsonObj(c, gin.H{"affected": affected}, nil)
notifyClientsChanged()
}
@@ -113,6 +124,25 @@ type groupResetTrafficBody struct {
Name string `json:"name"`
}
type groupHostsBody struct {
HostGroupIds []string `json:"hostGroupIds"`
}
func (a *GroupController) setHosts(c *gin.Context) {
var body groupHostsBody
if err := c.ShouldBindJSON(&body); err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
ids, err := a.clientService.SetGroupHostGroups(c.Param("name"), body.HostGroupIds)
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonObj(c, gin.H{"hostGroupIds": ids}, nil)
notifyClientsChanged()
}
func (a *GroupController) resetTraffic(c *gin.Context) {
var body groupResetTrafficBody
if err := c.ShouldBindJSON(&body); err != nil {