mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-02-05 15:35:47 +08:00
增加SysLockerService,修改用户相关的一些服务
This commit is contained in:
@@ -70,10 +70,10 @@ func (this *ServerDAO) DisableServer(tx *dbs.Tx, id int64) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, id int64) (*Server, error) {
|
||||
// 查找启用中的服务
|
||||
func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Pk(serverId).
|
||||
Attr("state", ServerStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
@@ -82,6 +82,19 @@ func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, id int64) (*Server, error)
|
||||
return result.(*Server), err
|
||||
}
|
||||
|
||||
// 查找服务基本信息
|
||||
func (this *ServerDAO) FindEnabledServerBasic(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(serverId).
|
||||
State(ServerStateEnabled).
|
||||
Result("id", "name", "description", "isOn", "type", "clusterId").
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*Server), err
|
||||
}
|
||||
|
||||
// 查找服务类型
|
||||
func (this *ServerDAO) FindEnabledServerType(tx *dbs.Tx, serverId int64) (string, error) {
|
||||
return this.Query(tx).
|
||||
@@ -232,6 +245,28 @@ func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string
|
||||
return this.createEvent()
|
||||
}
|
||||
|
||||
// 设置用户相关的基本信息
|
||||
func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name string) error {
|
||||
if serverId <= 0 {
|
||||
return errors.New("serverId should not be smaller than 0")
|
||||
}
|
||||
op := NewServerOperator()
|
||||
op.Id = serverId
|
||||
op.Name = name
|
||||
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = this.RenewServerConfig(tx, serverId, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.createEvent()
|
||||
}
|
||||
|
||||
// 修复服务是否启用
|
||||
func (this *ServerDAO) UpdateServerIsOn(tx *dbs.Tx, serverId int64, isOn bool) error {
|
||||
_, err := this.Query(tx).
|
||||
@@ -558,7 +593,7 @@ func (this *ServerDAO) UpdateServerReverseProxy(tx *dbs.Tx, serverId int64, conf
|
||||
}
|
||||
|
||||
// 计算所有可用服务数量
|
||||
func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag configutils.BoolState) (int64, error) {
|
||||
func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag configutils.BoolState, protocolFamily string) (int64, error) {
|
||||
query := this.Query(tx).
|
||||
State(ServerStateEnabled)
|
||||
if groupId > 0 {
|
||||
@@ -578,11 +613,16 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
|
||||
if auditingFlag == configutils.BoolStateYes {
|
||||
query.Attr("isAuditing", true)
|
||||
}
|
||||
if protocolFamily == "http" {
|
||||
query.Where("(http IS NOT NULL OR https IS NOT NULL)")
|
||||
} else if protocolFamily == "tcp" {
|
||||
query.Where("(tcp IS NOT NULL OR tls IS NOT NULL)")
|
||||
}
|
||||
return query.Count()
|
||||
}
|
||||
|
||||
// 列出单页的服务
|
||||
func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32) (result []*Server, err error) {
|
||||
func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32, protocolFamily string) (result []*Server, err error) {
|
||||
query := this.Query(tx).
|
||||
State(ServerStateEnabled).
|
||||
Offset(offset).
|
||||
@@ -607,6 +647,11 @@ func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size in
|
||||
if auditingFlag == 1 {
|
||||
query.Attr("isAuditing", true)
|
||||
}
|
||||
if protocolFamily == "http" {
|
||||
query.Where("(http IS NOT NULL OR https IS NOT NULL)")
|
||||
} else if protocolFamily == "tcp" {
|
||||
query.Where("(tcp IS NOT NULL OR tls IS NOT NULL)")
|
||||
}
|
||||
|
||||
_, err = query.FindAll()
|
||||
return
|
||||
@@ -1089,6 +1134,20 @@ func (this *ServerDAO) FindEnabledServerIdWithWebId(tx *dbs.Tx, webId int64) (se
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 检查端口是否被使用
|
||||
func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, port int) (bool, error) {
|
||||
listen := maps.Map{
|
||||
"portRange": strconv.Itoa(port),
|
||||
}
|
||||
|
||||
return this.Query(tx).
|
||||
Attr("clusterId", clusterId).
|
||||
State(ServerStateEnabled).
|
||||
Where("(JSON_CONTAINS(http, :listen) OR JSON_CONTAINS(https, :listen) OR JSON_CONTAINS(tcp, :listen) OR JSON_CONTAINS(tls, :listen))").
|
||||
Param(":listen", string(listen.AsJSON())).
|
||||
Exist()
|
||||
}
|
||||
|
||||
// 生成DNS Name
|
||||
func (this *ServerDAO) genDNSName(tx *dbs.Tx) (string, error) {
|
||||
for {
|
||||
|
||||
@@ -30,7 +30,7 @@ func init() {
|
||||
}
|
||||
|
||||
// 开锁
|
||||
func (this *SysLockerDAO) Lock(tx *dbs.Tx, key string, timeout int64) (bool, error) {
|
||||
func (this *SysLockerDAO) Lock(tx *dbs.Tx, key string, timeout int64) (ok bool, err error) {
|
||||
maxErrors := 5
|
||||
for {
|
||||
one, err := this.Query(tx).
|
||||
|
||||
@@ -15,11 +15,21 @@ var (
|
||||
Code: "server.accessLog.forward",
|
||||
Description: "用户可以配置访问日志转发到自定义的API",
|
||||
},
|
||||
{
|
||||
Name: "负载均衡",
|
||||
Code: "server.tcp",
|
||||
Description: "用户可以添加TCP/TLS负载均衡服务",
|
||||
},
|
||||
{
|
||||
Name: "开启WAF",
|
||||
Code: "server.waf",
|
||||
Description: "用户可以开启WAF功能并可以设置黑白名单等",
|
||||
},
|
||||
{
|
||||
Name: "费用账单",
|
||||
Code: "finance",
|
||||
Description: "开启费用账单相关功能",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user