mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-30 23:16:35 +08:00
增加DEMO模式、修复监控节点、用户节点、认证节点无法查看运行日志的Bug
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
// +build demo
|
||||
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
IsDemo = true
|
||||
)
|
||||
@@ -1,7 +0,0 @@
|
||||
// +build !demo
|
||||
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
IsDemo = false
|
||||
)
|
||||
@@ -5,3 +5,8 @@ package teaconst
|
||||
var (
|
||||
IsRecoverMode = false
|
||||
)
|
||||
|
||||
var (
|
||||
IsDemoMode = false
|
||||
ErrorDemoOperation = "DEMO模式下无法进行创建、修改、删除等操作"
|
||||
)
|
||||
|
||||
@@ -323,6 +323,9 @@ func (this *AdminNode) listenSock() error {
|
||||
case "recover":
|
||||
teaconst.IsRecoverMode = true
|
||||
_ = cmd.ReplyOk()
|
||||
case "demo":
|
||||
teaconst.IsDemoMode = !teaconst.IsDemoMode
|
||||
_ = cmd.ReplyOk()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ func (this *IndexAction) RunGet(params struct {
|
||||
|
||||
Auth *helpers.UserShouldAuth
|
||||
}) {
|
||||
// DEMO模式
|
||||
this.Data["isDemo"] = teaconst.IsDemoMode
|
||||
|
||||
// 检查系统是否已经配置过
|
||||
if !setup.IsConfigured() {
|
||||
this.RedirectURL("/setup")
|
||||
|
||||
@@ -132,7 +132,7 @@ func (this *CreateAction) RunPost(params struct {
|
||||
}
|
||||
case serverconfigs.ServerTypeTCPProxy:
|
||||
// 在DEMO模式下不能创建
|
||||
if teaconst.IsDemo {
|
||||
if teaconst.IsDemoMode {
|
||||
this.Fail("DEMO模式下不能创建TCP反向代理")
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (this *CreateAction) RunPost(params struct {
|
||||
}
|
||||
case serverconfigs.ServerTypeUDPProxy:
|
||||
// 在DEMO模式下不能创建
|
||||
if teaconst.IsDemo {
|
||||
if teaconst.IsDemoMode {
|
||||
this.Fail("DEMO模式下不能创建UDP反向代理")
|
||||
}
|
||||
|
||||
|
||||
@@ -31,20 +31,20 @@ func (this *LogsAction) RunGet(params struct {
|
||||
this.Data["keyword"] = params.Keyword
|
||||
this.Data["level"] = params.Level
|
||||
|
||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||
authorityNodeResp, err := this.RPC().AuthorityNodeRPC().FindEnabledAuthorityNode(this.AdminContext(), &pb.FindEnabledAuthorityNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
apiNode := apiNodeResp.Node
|
||||
if apiNode == nil {
|
||||
this.NotFound("apiNode", params.NodeId)
|
||||
authorityNode := authorityNodeResp.Node
|
||||
if authorityNode == nil {
|
||||
this.NotFound("authorityNode", params.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": apiNode.Id,
|
||||
"name": apiNode.Name,
|
||||
"id": authorityNode.Id,
|
||||
"name": authorityNode.Name,
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
|
||||
@@ -31,20 +31,20 @@ func (this *LogsAction) RunGet(params struct {
|
||||
this.Data["keyword"] = params.Keyword
|
||||
this.Data["level"] = params.Level
|
||||
|
||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||
monitorNodeResp, err := this.RPC().MonitorNodeRPC().FindEnabledMonitorNode(this.AdminContext(), &pb.FindEnabledMonitorNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
apiNode := apiNodeResp.Node
|
||||
if apiNode == nil {
|
||||
this.NotFound("apiNode", params.NodeId)
|
||||
monitorNode := monitorNodeResp.Node
|
||||
if monitorNode == nil {
|
||||
this.NotFound("monitorNode", params.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": apiNode.Id,
|
||||
"name": apiNode.Name,
|
||||
"id": monitorNode.Id,
|
||||
"name": monitorNode.Name,
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
|
||||
@@ -31,20 +31,20 @@ func (this *LogsAction) RunGet(params struct {
|
||||
this.Data["keyword"] = params.Keyword
|
||||
this.Data["level"] = params.Level
|
||||
|
||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||
userNodeResp, err := this.RPC().UserNodeRPC().FindEnabledUserNode(this.AdminContext(), &pb.FindEnabledUserNodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
apiNode := apiNodeResp.Node
|
||||
if apiNode == nil {
|
||||
this.NotFound("apiNode", params.NodeId)
|
||||
userNode := userNodeResp.Node
|
||||
if userNode == nil {
|
||||
this.NotFound("userNode", params.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": apiNode.Id,
|
||||
"name": apiNode.Name,
|
||||
"id": userNode.Id,
|
||||
"name": userNode.Name,
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 认证拦截
|
||||
@@ -21,12 +22,32 @@ func NewUserMustAuth(module string) *userMustAuth {
|
||||
}
|
||||
|
||||
func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) {
|
||||
var action = actionPtr.Object()
|
||||
|
||||
// 恢复模式
|
||||
if teaconst.IsRecoverMode {
|
||||
actionPtr.Object().RedirectURL("/recover")
|
||||
action.RedirectURL("/recover")
|
||||
return false
|
||||
}
|
||||
|
||||
var action = actionPtr.Object()
|
||||
|
||||
// DEMO模式
|
||||
if teaconst.IsDemoMode {
|
||||
if action.Request.Method == http.MethodPost {
|
||||
var actionName = action.Spec.ClassName[strings.LastIndex(action.Spec.ClassName, ".")+1:]
|
||||
var denyPrefixes = []string{"Update", "Create", "Delete", "Truncate", "Clean", "Clear", "Reset", "Add", "Remove"}
|
||||
for _, prefix := range denyPrefixes {
|
||||
if strings.HasPrefix(actionName, prefix) {
|
||||
action.Fail(teaconst.ErrorDemoOperation)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Index(action.Spec.PkgPath, "settings") > 0 || strings.Index(action.Spec.PkgPath, "delete") > 0 || strings.Index(action.Spec.PkgPath, "update") > 0 {
|
||||
action.Fail(teaconst.ErrorDemoOperation)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 安全相关
|
||||
securityConfig, _ := configloaders.LoadSecurityConfig()
|
||||
@@ -114,7 +135,7 @@ func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
action.Data["teaShowOpenSourceInfo"] = config.ShowOpenSourceInfo
|
||||
action.Data["teaIsSuper"] = false
|
||||
action.Data["teaIsPlus"] = teaconst.IsPlus
|
||||
action.Data["teaDemoEnabled"] = teaconst.IsDemo
|
||||
action.Data["teaDemoEnabled"] = teaconst.IsDemoMode
|
||||
action.Data["teaShowFinance"] = configloaders.ShowFinance()
|
||||
if !action.Data.Has("teaSubMenu") {
|
||||
action.Data["teaSubMenu"] = ""
|
||||
|
||||
Reference in New Issue
Block a user