diff --git a/apis/admin/server.api b/apis/admin/server.api index 4dfe5eb..52b7715 100644 --- a/apis/admin/server.api +++ b/apis/admin/server.api @@ -89,16 +89,20 @@ type ( CreateRuleGroupRequest { Name string `json:"name" validate:"required"` Icon string `json:"icon"` + Type string `json:"type"` Tags []string `json:"tags"` Rules string `json:"rules"` + Default bool `json:"default"` Enable bool `json:"enable"` } UpdateRuleGroupRequest { Id int64 `json:"id" validate:"required"` Icon string `json:"icon"` + Type string `json:"type"` Name string `json:"name" validate:"required"` Tags []string `json:"tags"` Rules string `json:"rules"` + Default bool `json:"default"` Enable bool `json:"enable"` } DeleteRuleGroupRequest { diff --git a/initialize/migrate/database/02007_adapte_rule.down.sql b/initialize/migrate/database/02007_adapte_rule.down.sql new file mode 100644 index 0000000..ed5d22f --- /dev/null +++ b/initialize/migrate/database/02007_adapte_rule.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE `server_rule_group` +DROP COLUMN `default`, +DROP COLUMN `type`; diff --git a/initialize/migrate/database/02007_adapte_rule.up.sql b/initialize/migrate/database/02007_adapte_rule.up.sql new file mode 100644 index 0000000..0c30d54 --- /dev/null +++ b/initialize/migrate/database/02007_adapte_rule.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE `server_rule_group` +ADD COLUMN `default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is Default Group', +ADD COLUMN `type` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'Rule Group Type'; \ No newline at end of file diff --git a/internal/handler/admin/server/createRuleGroupHandler.go b/internal/handler/admin/server/createRuleGroupHandler.go index 08791b0..89a436a 100644 --- a/internal/handler/admin/server/createRuleGroupHandler.go +++ b/internal/handler/admin/server/createRuleGroupHandler.go @@ -8,7 +8,7 @@ import ( "github.com/perfect-panel/server/pkg/result" ) -// Create rule group +// CreateRuleGroupHandler Create rule group func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) { return func(c *gin.Context) { var req types.CreateRuleGroupRequest diff --git a/internal/logic/admin/server/createRuleGroupLogic.go b/internal/logic/admin/server/createRuleGroupLogic.go index d136f9b..9fb5125 100644 --- a/internal/logic/admin/server/createRuleGroupLogic.go +++ b/internal/logic/admin/server/createRuleGroupLogic.go @@ -55,11 +55,13 @@ func (l *CreateRuleGroupLogic) CreateRuleGroup(req *types.CreateRuleGroupRequest } err = l.svcCtx.ServerModel.InsertRuleGroup(l.ctx, &server.RuleGroup{ - Name: req.Name, - Icon: req.Icon, - Tags: tool.StringSliceToString(req.Tags), - Rules: strings.Join(rs, "\n"), - Enable: req.Enable, + Name: req.Name, + Icon: req.Icon, + Type: req.Type, + Tags: tool.StringSliceToString(req.Tags), + Rules: strings.Join(rs, "\n"), + Default: req.Default, + Enable: req.Enable, }) if err != nil { l.Errorw("[CreateRuleGroup] Insert Database Error: ", logger.Field("error", err.Error())) diff --git a/internal/logic/admin/server/updateRuleGroupLogic.go b/internal/logic/admin/server/updateRuleGroupLogic.go index 7463bfd..9d36ce8 100644 --- a/internal/logic/admin/server/updateRuleGroupLogic.go +++ b/internal/logic/admin/server/updateRuleGroupLogic.go @@ -36,12 +36,14 @@ func (l *UpdateRuleGroupLogic) UpdateRuleGroup(req *types.UpdateRuleGroupRequest return err } err = l.svcCtx.ServerModel.UpdateRuleGroup(l.ctx, &server.RuleGroup{ - Id: req.Id, - Icon: req.Icon, - Name: req.Name, - Tags: tool.StringSliceToString(req.Tags), - Rules: strings.Join(rs, "\n"), - Enable: req.Enable, + Id: req.Id, + Icon: req.Icon, + Type: req.Type, + Name: req.Name, + Tags: tool.StringSliceToString(req.Tags), + Rules: strings.Join(rs, "\n"), + Default: req.Default, + Enable: req.Enable, }) if err != nil { return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), err.Error()) diff --git a/internal/model/server/server.go b/internal/model/server/server.go index f36fe10..beae1c5 100644 --- a/internal/model/server/server.go +++ b/internal/model/server/server.go @@ -12,6 +12,8 @@ const ( RelayModeNone = "none" RelayModeAll = "all" RelayModeRandom = "random" + RuleGroupType = "ban" + RuleGroupAuto = "auto" ) type ServerFilter struct { @@ -178,9 +180,11 @@ type RuleGroup struct { Id int64 `gorm:"primary_key"` Icon string `gorm:"type:MEDIUMTEXT;comment:Rule Group Icon"` Name string `gorm:"type:varchar(100);not null;default:'';comment:Rule Group Name"` + Type string `gorm:"type:varchar(100);not null;default:'';comment:Rule Group Type"` Tags string `gorm:"type:text;comment:Selected Node Tags"` Rules string `gorm:"type:MEDIUMTEXT;comment:Rules"` Enable bool `gorm:"type:tinyint(1);not null;default:1;comment:Rule Group Enable"` + Default bool `gorm:"type:tinyint(1);not null;default:0;comment:Rule Group is Default"` CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"` UpdatedAt time.Time `gorm:"comment:Update Time"` } diff --git a/internal/types/types.go b/internal/types/types.go index ad8157c..195b825 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -32,6 +32,11 @@ type Announcement struct { UpdatedAt int64 `json:"updated_at"` } +type AnyTLS struct { + Port int `json:"port" validate:"required"` + SecurityConfig SecurityConfig `json:"security_config"` +} + type AppAuthCheckRequest struct { Method string `json:"method" validate:"required" validate:"required,oneof=device email mobile"` Account string `json:"account"` @@ -441,11 +446,13 @@ type CreatePaymentMethodRequest struct { } type CreateRuleGroupRequest struct { - Name string `json:"name" validate:"required"` - Icon string `json:"icon"` - Tags []string `json:"tags"` - Rules string `json:"rules"` - Enable bool `json:"enable"` + Name string `json:"name" validate:"required"` + Icon string `json:"icon"` + Type string `json:"type"` + Tags []string `json:"tags"` + Rules string `json:"rules"` + Default bool `json:"default"` + Enable bool `json:"enable"` } type CreateSubscribeGroupRequest struct { @@ -1955,12 +1962,14 @@ type UpdatePaymentMethodRequest struct { } type UpdateRuleGroupRequest struct { - Id int64 `json:"id" validate:"required"` - Icon string `json:"icon"` - Name string `json:"name" validate:"required"` - Tags []string `json:"tags"` - Rules string `json:"rules"` - Enable bool `json:"enable"` + Id int64 `json:"id" validate:"required"` + Icon string `json:"icon"` + Type string `json:"type"` + Name string `json:"name" validate:"required"` + Tags []string `json:"tags"` + Rules string `json:"rules"` + Default bool `json:"default"` + Enable bool `json:"enable"` } type UpdateSubscribeGroupRequest struct { diff --git a/pkg/adapter/adapter.go b/pkg/adapter/adapter.go index 4ad1e38..f687663 100644 --- a/pkg/adapter/adapter.go +++ b/pkg/adapter/adapter.go @@ -27,7 +27,7 @@ func NewAdapter(cfg *Config) *Adapter { // 转换服务器列表 proxies := adapterProxies(cfg.Nodes) // 生成代理组 - proxyGroup, region := generateProxyGroup(proxies) + proxyGroup, nodes := generateProxyGroup(proxies) // 转换规则组 g, r := adapterRules(cfg.Rules) @@ -35,7 +35,8 @@ func NewAdapter(cfg *Config) *Adapter { // 加入兜底节点 for i, group := range g { if len(group.Proxies) == 0 { - g[i].Proxies = append([]string{"DIRECT"}, region...) + p := append([]string{"智能线路"}, nodes...) + g[i].Proxies = append(p, "REJECT", "DIRECT") } } @@ -48,7 +49,7 @@ func NewAdapter(cfg *Config) *Adapter { Proxies: proxies, Group: proxyGroup, Rules: r, - Region: region, + Nodes: nodes, }, } } diff --git a/pkg/adapter/proxy/proxy.go b/pkg/adapter/proxy/proxy.go index ee74d72..458ac7b 100644 --- a/pkg/adapter/proxy/proxy.go +++ b/pkg/adapter/proxy/proxy.go @@ -4,8 +4,9 @@ package proxy type Adapter struct { Proxies []Proxy Group []Group - Rules []string - Region []string + Rules []string // rule + Nodes []string // all node + Default string // Default Node } // Proxy represents a proxy server diff --git a/pkg/adapter/uilts.go b/pkg/adapter/uilts.go index a9858ed..309b32e 100644 --- a/pkg/adapter/uilts.go +++ b/pkg/adapter/uilts.go @@ -121,7 +121,7 @@ func adapterTags(tags map[string][]*server.Server, group []proxy.Group) (proxyGr return group } -func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, region []string) { +func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, nodes []string) { // 设置手动选择分组 proxyGroup = append(proxyGroup, []proxy.Group{ { @@ -139,17 +139,13 @@ func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, region }...) for _, node := range servers { - if node.Country != "" { - proxyGroup = addProxyToGroup(node.Name, node.Country, proxyGroup) - region = append(region, node.Country) - - proxyGroup = addProxyToGroup(node.Country, "智能线路", proxyGroup) - } - + proxyGroup = addProxyToGroup(node.Name, "智能线路", proxyGroup) proxyGroup = addProxyToGroup(node.Name, "手动选择", proxyGroup) + nodes = append(nodes, node.Name) } + proxyGroup = addProxyToGroup("DIRECT", "手动选择", proxyGroup) - return proxyGroup, tool.RemoveDuplicateElements(region...) + return proxyGroup, tool.RemoveDuplicateElements(nodes...) } func adapterProxies(servers []*server.Server) []proxy.Proxy {