Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
749eac74fe | ||
|
|
ac39908737 | ||
|
|
bb8f4bf488 | ||
|
|
db0d157a74 | ||
|
|
bd8e1bbe71 | ||
|
|
7aba898cf5 | ||
|
|
baf039755f | ||
|
|
70977f7d80 | ||
|
|
884342d6af | ||
|
|
411b0fb4c2 | ||
|
|
8053fb2399 | ||
|
|
ed42dcab9c | ||
|
|
866b5b0f2f | ||
|
|
5834a1a0fa | ||
|
|
8c6d845603 | ||
|
|
667f363f3c | ||
|
|
e209ff38d9 | ||
|
|
ea915993b6 | ||
|
|
72d0468c6a | ||
|
|
35ae13b1c3 | ||
|
|
1d9460f565 | ||
|
|
e9a3ed71b4 | ||
|
|
e344e5b7e6 | ||
|
|
e814064403 | ||
|
|
f5aeb5cbcd | ||
|
|
f41164b892 | ||
|
|
03073c8364 | ||
|
|
a359bff531 | ||
|
|
3789ac6433 | ||
|
|
9f53f59f18 | ||
|
|
521bd746e3 | ||
|
|
3d8e43a42b | ||
|
|
9452e1852d | ||
|
|
3920d24af6 | ||
|
|
3af11e6ba8 | ||
|
|
7bcde46d49 | ||
|
|
0b73041718 | ||
|
|
dcdc0cb8c1 | ||
|
|
ad6ac1aad6 | ||
|
|
249dc6accd |
@@ -67,6 +67,7 @@ function build() {
|
|||||||
find $DIST -name ".gitignore" -delete
|
find $DIST -name ".gitignore" -delete
|
||||||
find $DIST -name "*.less" -delete
|
find $DIST -name "*.less" -delete
|
||||||
find $DIST -name "*.css.map" -delete
|
find $DIST -name "*.css.map" -delete
|
||||||
|
find $DIST -name "*.js.map" -delete
|
||||||
|
|
||||||
# zip
|
# zip
|
||||||
echo "zip files ..."
|
echo "zip files ..."
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.3.3"
|
Version = "0.3.5"
|
||||||
|
|
||||||
APINodeVersion = "0.3.3"
|
APINodeVersion = "0.3.5"
|
||||||
|
|
||||||
ProductName = "Edge Admin"
|
ProductName = "Edge Admin"
|
||||||
ProcessName = "edge-admin"
|
ProcessName = "edge-admin"
|
||||||
|
|||||||
@@ -326,6 +326,16 @@ func (this *AdminNode) listenSock() error {
|
|||||||
case "demo":
|
case "demo":
|
||||||
teaconst.IsDemoMode = !teaconst.IsDemoMode
|
teaconst.IsDemoMode = !teaconst.IsDemoMode
|
||||||
_ = cmd.ReplyOk()
|
_ = cmd.ReplyOk()
|
||||||
|
case "info":
|
||||||
|
exePath, _ := os.Executable()
|
||||||
|
_ = cmd.Reply(&gosock.Command{
|
||||||
|
Code: "info",
|
||||||
|
Params: map[string]interface{}{
|
||||||
|
"pid": os.Getpid(),
|
||||||
|
"version": teaconst.Version,
|
||||||
|
"path": exePath,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ type RPCClient struct {
|
|||||||
apiConfig *configs.APIConfig
|
apiConfig *configs.APIConfig
|
||||||
conns []*grpc.ClientConn
|
conns []*grpc.ClientConn
|
||||||
|
|
||||||
locker sync.Mutex
|
locker sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRPCClient 构造新的RPC客户端
|
// NewRPCClient 构造新的RPC客户端
|
||||||
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
func NewRPCClient(apiConfig *configs.APIConfig, isPrimary bool) (*RPCClient, error) {
|
||||||
if apiConfig == nil {
|
if apiConfig == nil {
|
||||||
return nil, errors.New("api config should not be nil")
|
return nil, errors.New("api config should not be nil")
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,9 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置RPC
|
// 设置RPC
|
||||||
dao.SetRPC(client)
|
if isPrimary {
|
||||||
|
dao.SetRPC(client)
|
||||||
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
@@ -380,6 +382,18 @@ func (this *RPCClient) UserBillRPC() pb.UserBillServiceClient {
|
|||||||
return pb.NewUserBillServiceClient(this.pickConn())
|
return pb.NewUserBillServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountRPC() pb.UserAccountServiceClient {
|
||||||
|
return pb.NewUserAccountServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountLogRPC() pb.UserAccountLogServiceClient {
|
||||||
|
return pb.NewUserAccountLogServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountDailyStatRPC() pb.UserAccountDailyStatServiceClient {
|
||||||
|
return pb.NewUserAccountDailyStatServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
||||||
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -521,7 +535,11 @@ func (this *RPCClient) APIContext(apiNodeId int64) context.Context {
|
|||||||
// UpdateConfig 修改配置
|
// UpdateConfig 修改配置
|
||||||
func (this *RPCClient) UpdateConfig(config *configs.APIConfig) error {
|
func (this *RPCClient) UpdateConfig(config *configs.APIConfig) error {
|
||||||
this.apiConfig = config
|
this.apiConfig = config
|
||||||
return this.init()
|
|
||||||
|
this.locker.Lock()
|
||||||
|
err := this.init()
|
||||||
|
this.locker.Unlock()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
@@ -599,3 +617,20 @@ func (this *RPCClient) pickConn() *grpc.ClientConn {
|
|||||||
|
|
||||||
return this.conns[rands.Int(0, len(this.conns)-1)]
|
return this.conns[rands.Int(0, len(this.conns)-1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close 关闭
|
||||||
|
func (this *RPCClient) Close() error {
|
||||||
|
this.locker.Lock()
|
||||||
|
defer this.locker.Unlock()
|
||||||
|
|
||||||
|
var lastErr error
|
||||||
|
for _, conn := range this.conns {
|
||||||
|
var err = conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastErr
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func SharedRPC() (*RPCClient, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client, err := NewRPCClient(config)
|
client, err := NewRPCClient(config, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package setup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isConfigured bool
|
var isConfigured bool
|
||||||
@@ -16,3 +18,16 @@ func IsConfigured() bool {
|
|||||||
isConfigured = err == nil
|
isConfigured = err == nil
|
||||||
return isConfigured
|
return isConfigured
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewInstalled IsNew 检查是否新安装
|
||||||
|
func IsNewInstalled() bool {
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/api.yaml")
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newEndpoints := []string{}
|
newEndpoints := []string{}
|
||||||
for _, node := range resp.Nodes {
|
for _, node := range resp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,35 @@ type DeleteAction struct {
|
|||||||
func (this *DeleteAction) RunPost(params struct {
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
// TODO 检查权限
|
// 创建日志
|
||||||
|
defer this.CreateLog(oplogs.LevelInfo, "删除API节点 %d", params.NodeId)
|
||||||
|
|
||||||
_, err := this.RPC().APINodeRPC().DeleteAPINode(this.AdminContext(), &pb.DeleteAPINodeRequest{NodeId: params.NodeId})
|
// 检查是否是唯一的节点
|
||||||
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var apiNode = nodeResp.ApiNode
|
||||||
|
if apiNode == nil {
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
if apiNode.IsOn {
|
||||||
|
countResp, err := this.RPC().APINodeRPC().CountAllEnabledAndOnAPINodes(this.AdminContext(), &pb.CountAllEnabledAndOnAPINodesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count == 1 {
|
||||||
|
this.Fail("无法删除此节点:必须保留至少一个可用的API节点")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().APINodeRPC().DeleteAPINode(this.AdminContext(), &pb.DeleteAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除API节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
// 状态
|
// 状态
|
||||||
status := &nodeconfigs.NodeStatus{}
|
status := &nodeconfigs.NodeStatus{}
|
||||||
if len(node.StatusJSON) > 0 {
|
if len(node.StatusJSON) > 0 {
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建API节点 %d", createResp.NodeId)
|
defer this.CreateLog(oplogs.LevelInfo, "创建API节点 %d", createResp.ApiNodeId)
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
// API节点信息
|
// API节点信息
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
this.Data["level"] = params.Level
|
this.Data["level"] = params.Level
|
||||||
|
|
||||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
if apiNode == nil {
|
if apiNode == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
|
||||||
NodeId: params.NodeId,
|
ApiNodeId: params.NodeId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.WriteString("要操作的节点不存在")
|
this.WriteString("要操作的节点不存在")
|
||||||
return
|
return
|
||||||
@@ -281,7 +281,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
|
_, err = this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
|
||||||
NodeId: params.NodeId,
|
ApiNodeId: params.NodeId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
HttpJSON: httpJSON,
|
HttpJSON: httpJSON,
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (this *CreateNodeAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (this *InstallNodesAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, apiNode := range apiNodesResp.Nodes {
|
for _, apiNode := range apiNodesResp.ApiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -69,6 +69,20 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
|
|
||||||
logs := []maps.Map{}
|
logs := []maps.Map{}
|
||||||
for _, log := range logsResp.NodeLogs {
|
for _, log := range logsResp.NodeLogs {
|
||||||
|
// 服务信息
|
||||||
|
var serverMap = maps.Map{"id": 0}
|
||||||
|
if log.ServerId > 0 {
|
||||||
|
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: log.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var server = serverResp.Server
|
||||||
|
if server != nil {
|
||||||
|
serverMap = maps.Map{"id": server.Id, "name": server.Name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
logs = append(logs, maps.Map{
|
||||||
"tag": log.Tag,
|
"tag": log.Tag,
|
||||||
"description": log.Description,
|
"description": log.Description,
|
||||||
@@ -76,6 +90,7 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
"level": log.Level,
|
"level": log.Level,
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
||||||
"count": log.Count,
|
"count": log.Count,
|
||||||
|
"server": serverMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["logs"] = logs
|
this.Data["logs"] = logs
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -58,6 +59,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -59,6 +60,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ func (this *GrantAction) RunGet(params struct {
|
|||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": strings.Repeat("*", len(grant.Password)),
|
"password": strings.Repeat("*", len(grant.Password)),
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": strings.Repeat("*", len(grant.Passphrase)),
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": grant.Password,
|
"password": grant.Password,
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": grant.Passphrase,
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
@@ -57,6 +58,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -93,6 +95,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
|||||||
"password": grant.Password,
|
"password": grant.Password,
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": grant.Passphrase,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
@@ -56,6 +57,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -91,6 +93,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -90,6 +90,20 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 服务信息
|
||||||
|
var serverMap = maps.Map{"id": 0}
|
||||||
|
if log.ServerId > 0 {
|
||||||
|
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: log.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var server = serverResp.Server
|
||||||
|
if server != nil {
|
||||||
|
serverMap = maps.Map{"id": server.Id, "name": server.Name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
logs = append(logs, maps.Map{
|
||||||
"id": log.Id,
|
"id": log.Id,
|
||||||
"tag": log.Tag,
|
"tag": log.Tag,
|
||||||
@@ -107,6 +121,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
},
|
},
|
||||||
"name": node.Name,
|
"name": node.Name,
|
||||||
},
|
},
|
||||||
|
"server": serverMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["logs"] = logs
|
this.Data["logs"] = logs
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func init() {
|
|||||||
Prefix("/clusters/logs").
|
Prefix("/clusters/logs").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
Post("/readLogs", new(ReadLogsAction)).
|
Post("/readLogs", new(ReadLogsAction)).
|
||||||
|
Post("/readAllLogs", new(ReadAllLogsAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
24
internal/web/actions/default/clusters/logs/readAllLogs.go
Normal file
24
internal/web/actions/default/clusters/logs/readAllLogs.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadAllLogsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ReadAllLogsAction) RunPost(params struct {
|
||||||
|
LogIds []int64
|
||||||
|
}) {
|
||||||
|
_, err := this.RPC().NodeLogRPC().UpdateAllNodeLogsRead(this.AdminContext(), &pb.UpdateAllNodeLogsReadRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 域名列表选项
|
// DomainOptionsAction 域名列表选项
|
||||||
type DomainOptionsAction struct {
|
type DomainOptionsAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,8 @@ func (this *DomainOptionsAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
domainMaps := []maps.Map{}
|
domainMaps := []maps.Map{}
|
||||||
for _, domain := range domainsResp.DnsDomains {
|
for _, domain := range domainsResp.DnsDomains {
|
||||||
// 未开启的先跳过
|
// 未开启或者已删除的先跳过
|
||||||
if !domain.IsOn {
|
if !domain.IsOn || domain.IsDeleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
internal/web/actions/default/dns/domains/recover.go
Normal file
27
internal/web/actions/default/dns/domains/recover.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package domains
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RecoverAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RecoverAction) RunPost(params struct {
|
||||||
|
DomainId int64
|
||||||
|
}) {
|
||||||
|
// 记录日志
|
||||||
|
defer this.CreateLog(oplogs.LevelInfo, "从DNS服务商中恢复域名 %d", params.DomainId)
|
||||||
|
|
||||||
|
// 执行恢复
|
||||||
|
_, err := this.RPC().DNSDomainRPC().RecoverDNSDomain(this.AdminContext(), &pb.RecoverDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
// TODO 检查DomainId
|
// TODO 检查DomainId
|
||||||
|
|
||||||
// 记录日志
|
// 记录日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改管理域名到DNS服务商 %d", params.DomainId)
|
defer this.CreateLog(oplogs.LevelInfo, "修改DNS服务商域名 %d", params.DomainId)
|
||||||
|
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func init() {
|
|||||||
GetPost("/createPopup", new(domains.CreatePopupAction)).
|
GetPost("/createPopup", new(domains.CreatePopupAction)).
|
||||||
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
|
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
|
||||||
Post("/delete", new(domains.DeleteAction)).
|
Post("/delete", new(domains.DeleteAction)).
|
||||||
|
Post("/recover", new(domains.RecoverAction)).
|
||||||
Post("/sync", new(domains.SyncAction)).
|
Post("/sync", new(domains.SyncAction)).
|
||||||
Get("/routesPopup", new(domains.RoutesPopupAction)).
|
Get("/routesPopup", new(domains.RoutesPopupAction)).
|
||||||
GetPost("/selectPopup", new(domains.SelectPopupAction)).
|
GetPost("/selectPopup", new(domains.SelectPopupAction)).
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func (this *ProviderAction) RunGet(params struct {
|
|||||||
"name": domain.Name,
|
"name": domain.Name,
|
||||||
"isOn": domain.IsOn,
|
"isOn": domain.IsOn,
|
||||||
"isUp": domain.IsUp,
|
"isUp": domain.IsUp,
|
||||||
|
"isDeleted": domain.IsDeleted,
|
||||||
"dataUpdatedTime": dataUpdatedTime,
|
"dataUpdatedTime": dataUpdatedTime,
|
||||||
"countRoutes": len(domain.Routes),
|
"countRoutes": len(domain.Routes),
|
||||||
"countServerRecords": domain.CountServerRecords,
|
"countServerRecords": domain.CountServerRecords,
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// 是否新安装
|
||||||
|
if setup.IsNewInstalled() {
|
||||||
|
this.RedirectURL("/setup/confirm")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 已登录跳转到dashboard
|
// 已登录跳转到dashboard
|
||||||
if params.Auth.IsUser() {
|
if params.Auth.IsUser() {
|
||||||
this.RedirectURL("/dashboard")
|
this.RedirectURL("/dashboard")
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(len(nodes))
|
wg.Add(len(nodes))
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// TODO 检查是否在线
|
// TODO 检查是否在线
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
apiNodeId := node.ConnectedAPINodeIds[0]
|
apiNodeId := node.ConnectedAPINodeIds[0]
|
||||||
rpcClient, ok := rpcMap[apiNodeId]
|
rpcClient, ok := rpcMap[apiNodeId]
|
||||||
if !ok {
|
if !ok {
|
||||||
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{NodeId: apiNodeId})
|
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{ApiNodeId: apiNodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -82,7 +83,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiNodeResp.Node == nil {
|
if apiNodeResp.ApiNode == nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
NodeId: node.Id,
|
NodeId: node.Id,
|
||||||
@@ -94,7 +95,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
@@ -104,7 +105,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
},
|
},
|
||||||
NodeId: apiNode.UniqueId,
|
NodeId: apiNode.UniqueId,
|
||||||
Secret: apiNode.Secret,
|
Secret: apiNode.Secret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -162,6 +163,11 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭RPC
|
||||||
|
for _, rpcClient := range rpcMap {
|
||||||
|
_ = rpcClient.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +249,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
apiNodeId := node.ConnectedAPINodeIds[0]
|
apiNodeId := node.ConnectedAPINodeIds[0]
|
||||||
rpcClient, ok := rpcMap[apiNodeId]
|
rpcClient, ok := rpcMap[apiNodeId]
|
||||||
if !ok {
|
if !ok {
|
||||||
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{NodeId: apiNodeId})
|
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{ApiNodeId: apiNodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -257,7 +263,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiNodeResp.Node == nil {
|
if apiNodeResp.ApiNode == nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
NodeId: node.Id,
|
NodeId: node.Id,
|
||||||
@@ -269,7 +275,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
@@ -279,7 +285,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
},
|
},
|
||||||
NodeId: apiNode.UniqueId,
|
NodeId: apiNode.UniqueId,
|
||||||
Secret: apiNode.Secret,
|
Secret: apiNode.Secret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -337,5 +343,10 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭RPC
|
||||||
|
for _, rpcClient := range rpcMap {
|
||||||
|
_ = rpcClient.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
},
|
},
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Secret: params.NodeSecret,
|
Secret: params.NodeSecret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,10 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
// 获取管理员节点信息
|
// 获取管理员节点信息
|
||||||
apiTokensResp, err := client.APITokenRPC().FindAllEnabledAPITokens(client.APIContext(0), &pb.FindAllEnabledAPITokensRequest{Role: "admin"})
|
apiTokensResp, err := client.APITokenRPC().FindAllEnabledAPITokens(client.APIContext(0), &pb.FindAllEnabledAPITokensRequest{Role: "admin"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +73,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
||||||
}
|
}
|
||||||
var endpoints = []string{}
|
var endpoints = []string{}
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -144,7 +148,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
_, err = client.APINodeRPC().UpdateAPINode(client.Context(0), &pb.UpdateAPINodeRequest{
|
_, err = client.APINodeRPC().UpdateAPINode(client.Context(0), &pb.UpdateAPINodeRequest{
|
||||||
NodeId: node.Id,
|
ApiNodeId: node.Id,
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
Description: node.Description,
|
Description: node.Description,
|
||||||
HttpJSON: node.HttpJSON,
|
HttpJSON: node.HttpJSON,
|
||||||
|
|||||||
@@ -49,10 +49,15 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
},
|
},
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Secret: params.NodeSecret,
|
Secret: params.NodeSecret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.APIContext(0), &pb.FindCurrentAPINodeVersionRequest{})
|
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.APIContext(0), &pb.FindCurrentAPINodeVersionRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
||||||
@@ -64,7 +69,7 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
||||||
}
|
}
|
||||||
var hosts = []string{}
|
var hosts = []string{}
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除SSL证书 %d", params.CertId)
|
defer this.CreateLog(oplogs.LevelInfo, "删除SSL证书 %d", params.CertId)
|
||||||
|
|
||||||
// 是否正在被使用
|
// 是否正在被服务使用
|
||||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{SslCertId: params.CertId})
|
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -26,6 +26,26 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
this.Fail("此证书正在被某些服务引用,请先修改服务后再删除。")
|
this.Fail("此证书正在被某些服务引用,请先修改服务后再删除。")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否正在被API节点使用
|
||||||
|
countResp, err = this.RPC().APINodeRPC().CountAllEnabledAPINodesWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledAPINodesWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count > 0 {
|
||||||
|
this.Fail("此证书正在被某些API节点引用,请先修改API节点后再删除")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否正在被用户节点使用
|
||||||
|
countResp, err = this.RPC().UserNodeRPC().CountAllEnabledUserNodesWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledUserNodesWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count > 0 {
|
||||||
|
this.Fail("此证书正在被某些用户节点引用,请先修改用户节点后再删除")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = this.RPC().SSLCertRPC().DeleteSSLCert(this.AdminContext(), &pb.DeleteSSLCertRequest{SslCertId: params.CertId})
|
_, err = this.RPC().SSLCertRPC().DeleteSSLCert(this.AdminContext(), &pb.DeleteSSLCertRequest{SslCertId: params.CertId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -59,14 +59,56 @@ func (this *ListsAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (this *TestAction) RunPost(params struct {
|
|||||||
"ipFrom": resp.IpItem.IpFrom,
|
"ipFrom": resp.IpItem.IpFrom,
|
||||||
"ipTo": resp.IpItem.IpTo,
|
"ipTo": resp.IpItem.IpTo,
|
||||||
"reason": resp.IpItem.Reason,
|
"reason": resp.IpItem.Reason,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
|
||||||
"expiredAt": resp.IpItem.ExpiredAt,
|
"expiredAt": resp.IpItem.ExpiredAt,
|
||||||
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
||||||
"type": resp.IpItem.Type,
|
"type": resp.IpItem.Type,
|
||||||
|
|||||||
@@ -63,8 +63,12 @@ func (this *CreateAction) RunGet(params struct{}) {
|
|||||||
func (this *CreateAction) RunPost(params struct {
|
func (this *CreateAction) RunPost(params struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
ClusterId int64
|
|
||||||
GroupIds []int64
|
UserId int64
|
||||||
|
UserPlanId int64
|
||||||
|
ClusterId int64
|
||||||
|
|
||||||
|
GroupIds []int64
|
||||||
|
|
||||||
ServerType string
|
ServerType string
|
||||||
Addresses string
|
Addresses string
|
||||||
@@ -86,11 +90,22 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入服务名称")
|
Require("请输入服务名称")
|
||||||
|
|
||||||
if params.ClusterId <= 0 {
|
var clusterId = params.ClusterId
|
||||||
|
|
||||||
|
// 用户
|
||||||
|
var userId = params.UserId
|
||||||
|
clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clusterId = clusterIdResp.NodeClusterId
|
||||||
|
if clusterId <= 0 {
|
||||||
this.Fail("请选择部署的集群")
|
this.Fail("请选择部署的集群")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 验证集群ID
|
// 套餐
|
||||||
|
var userPlanId = params.UserPlanId
|
||||||
|
|
||||||
// 端口地址
|
// 端口地址
|
||||||
var httpConfig *serverconfigs.HTTPProtocolConfig = nil
|
var httpConfig *serverconfigs.HTTPProtocolConfig = nil
|
||||||
@@ -260,7 +275,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
if len(allServerNames) > 0 {
|
if len(allServerNames) > 0 {
|
||||||
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
||||||
ServerNames: allServerNames,
|
ServerNames: allServerNames,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: clusterId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -359,13 +374,14 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := &pb.CreateServerRequest{
|
req := &pb.CreateServerRequest{
|
||||||
UserId: 0,
|
UserId: userId,
|
||||||
|
UserPlanId: userPlanId,
|
||||||
AdminId: this.AdminId(),
|
AdminId: this.AdminId(),
|
||||||
Type: params.ServerType,
|
Type: params.ServerType,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
ServerNamesJON: []byte(params.ServerNames),
|
ServerNamesJON: []byte(params.ServerNames),
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: clusterId,
|
||||||
IncludeNodesJSON: includeNodesJSON,
|
IncludeNodesJSON: includeNodesJSON,
|
||||||
ExcludeNodesJSON: excludeNodesJSON,
|
ExcludeNodesJSON: excludeNodesJSON,
|
||||||
WebId: webId,
|
WebId: webId,
|
||||||
@@ -496,7 +512,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
AddStatusHeader: true,
|
AddStatusHeader: true,
|
||||||
PurgeIsOn: false,
|
PurgeIsOn: false,
|
||||||
PurgeKey: "",
|
PurgeKey: "",
|
||||||
CacheRefs: nil,
|
CacheRefs: []*serverconfigs.HTTPCacheRef{},
|
||||||
}
|
}
|
||||||
cacheConfigJSON, err := json.Marshal(cacheConfig)
|
cacheConfigJSON, err := json.Marshal(cacheConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -70,15 +70,57 @@ func (this *AllowListAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -70,15 +70,57 @@ func (this *DenyListAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func (this *TestAction) RunPost(params struct {
|
|||||||
"ipTo": resp.IpItem.IpTo,
|
"ipTo": resp.IpItem.IpTo,
|
||||||
"reason": resp.IpItem.Reason,
|
"reason": resp.IpItem.Reason,
|
||||||
"expiredAt": resp.IpItem.ExpiredAt,
|
"expiredAt": resp.IpItem.ExpiredAt,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
|
||||||
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
||||||
"type": resp.IpItem.Type,
|
"type": resp.IpItem.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package servers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/users"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
"github.com/iwind/TeaGo"
|
"github.com/iwind/TeaGo"
|
||||||
)
|
)
|
||||||
@@ -24,6 +25,12 @@ func init() {
|
|||||||
GetPost("/addOriginPopup", new(AddOriginPopupAction)).
|
GetPost("/addOriginPopup", new(AddOriginPopupAction)).
|
||||||
Get("/serverNamesPopup", new(ServerNamesPopupAction)).
|
Get("/serverNamesPopup", new(ServerNamesPopupAction)).
|
||||||
Post("/status", new(StatusAction)).
|
Post("/status", new(StatusAction)).
|
||||||
|
|
||||||
|
//
|
||||||
|
Post("/users/options", new(users.OptionsAction)).
|
||||||
|
Post("/users/plans", new(users.PlansAction)).
|
||||||
|
|
||||||
|
//
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
Description string
|
Description string
|
||||||
|
IsGlobal bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
@@ -49,6 +50,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
TimeoutJSON: nil,
|
TimeoutJSON: nil,
|
||||||
IsPublic: true,
|
IsPublic: true,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
IsGlobal: params.IsGlobal,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
37
internal/web/actions/default/servers/iplists/deleteItems.go
Normal file
37
internal/web/actions/default/servers/iplists/deleteItems.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package iplists
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteItemsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteItemsAction) RunPost(params struct {
|
||||||
|
ItemIds []int64
|
||||||
|
}) {
|
||||||
|
if len(params.ItemIds) == 0 {
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemIdStrings = []string{}
|
||||||
|
for _, itemId := range params.ItemIds {
|
||||||
|
itemIdStrings = append(itemIdStrings, types.String(itemId))
|
||||||
|
}
|
||||||
|
|
||||||
|
defer this.CreateLogInfo("批量删除IP名单中的IP:" + strings.Join(itemIdStrings, ", "))
|
||||||
|
|
||||||
|
_, err := this.RPC().IPItemRPC().DeleteIPItems(this.AdminContext(), &pb.DeleteIPItemsRequest{IpItemIds: params.ItemIds})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -5,8 +5,10 @@ package iplists
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -18,59 +20,123 @@ func (this *IndexAction) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
Type string
|
Ip string
|
||||||
Keyword string
|
GlobalOnly bool
|
||||||
}) {
|
}) {
|
||||||
if len(params.Type) == 0 {
|
this.Data["type"] = ""
|
||||||
params.Type = ipconfigs.IPListTypeBlack
|
this.Data["ip"] = params.Ip
|
||||||
}
|
this.Data["globalOnly"] = params.GlobalOnly
|
||||||
this.Data["type"] = params.Type
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
|
|
||||||
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
|
countResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.AdminContext(), &pb.CountAllEnabledIPItemsRequest{
|
||||||
Type: params.Type,
|
Ip: params.Ip,
|
||||||
IsPublic: true,
|
GlobalOnly: params.GlobalOnly,
|
||||||
Keyword: params.Keyword,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count := countResp.Count
|
var count = countResp.Count
|
||||||
page := this.NewPage(count)
|
var page = this.NewPage(count)
|
||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
|
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{
|
||||||
Type: params.Type,
|
Ip: params.Ip,
|
||||||
IsPublic: true,
|
GlobalOnly: params.GlobalOnly,
|
||||||
Keyword: params.Keyword,
|
Offset: page.Offset,
|
||||||
Offset: page.Offset,
|
Size: page.Size,
|
||||||
Size: page.Size,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var listMaps = []maps.Map{}
|
|
||||||
for _, list := range listsResp.IpLists {
|
|
||||||
// 包含的IP数量
|
|
||||||
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var countItems = countItemsResp.Count
|
|
||||||
|
|
||||||
listMaps = append(listMaps, maps.Map{
|
var itemMaps = []maps.Map{}
|
||||||
"id": list.Id,
|
for _, result := range itemsResp.Results {
|
||||||
"isOn": list.IsOn,
|
var item = result.IpItem
|
||||||
"name": list.Name,
|
expiredTime := ""
|
||||||
"description": list.Description,
|
if item.ExpiredAt > 0 {
|
||||||
"countItems": countItems,
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
"type": list.Type,
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP名单
|
||||||
|
var listMap = maps.Map{"id": 0}
|
||||||
|
if result.IpList != nil {
|
||||||
|
listMap = maps.Map{
|
||||||
|
"id": result.IpList.Id,
|
||||||
|
"name": result.IpList.Name,
|
||||||
|
"type": result.IpList.Type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var policyMap = maps.Map{"id": 0}
|
||||||
|
if result.HttpFirewallPolicy != nil {
|
||||||
|
policyMap = maps.Map{
|
||||||
|
"id": result.HttpFirewallPolicy.Id,
|
||||||
|
"name": result.HttpFirewallPolicy.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Server != nil {
|
||||||
|
policyMap["server"] = maps.Map{"id": result.Server.Id, "name": result.Server.Name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
|
"id": item.Id,
|
||||||
|
"ipFrom": item.IpFrom,
|
||||||
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
|
"isExpired": item.ExpiredAt < time.Now().Unix(),
|
||||||
|
"expiredTime": expiredTime,
|
||||||
|
"reason": item.Reason,
|
||||||
|
"type": item.Type,
|
||||||
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
|
"list": listMap,
|
||||||
|
"policy": policyMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["lists"] = listMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ func init() {
|
|||||||
Data("teaSubMenu", "iplist").
|
Data("teaSubMenu", "iplist").
|
||||||
Prefix("/servers/iplists").
|
Prefix("/servers/iplists").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
|
Get("/lists", new(ListsAction)).
|
||||||
GetPost("/createPopup", new(CreatePopupAction)).
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
Get("/list", new(ListAction)).
|
Get("/list", new(ListAction)).
|
||||||
GetPost("/import", new(ImportAction)).
|
GetPost("/import", new(ImportAction)).
|
||||||
GetPost("/export", new(ExportAction)).
|
GetPost("/export", new(ExportAction)).
|
||||||
Get("/exportData", new(ExportDataAction)).
|
Get("/exportData", new(ExportDataAction)).
|
||||||
Post("/delete", new(DeleteAction)).
|
Post("/delete", new(DeleteAction)).
|
||||||
|
Post("/deleteItems", new(DeleteItemsAction)).
|
||||||
GetPost("/test", new(TestAction)).
|
GetPost("/test", new(TestAction)).
|
||||||
GetPost("/update", new(UpdateAction)).
|
GetPost("/update", new(UpdateAction)).
|
||||||
Get("/items", new(ItemsAction)).
|
Get("/items", new(ItemsAction)).
|
||||||
@@ -38,7 +40,6 @@ func init() {
|
|||||||
|
|
||||||
// 选项数据
|
// 选项数据
|
||||||
Post("/levelOptions", new(LevelOptionsAction)).
|
Post("/levelOptions", new(LevelOptionsAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,14 +62,56 @@ func (this *ItemsAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
77
internal/web/actions/default/servers/iplists/lists.go
Normal file
77
internal/web/actions/default/servers/iplists/lists.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package iplists
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListsAction) Init() {
|
||||||
|
this.Nav("", "", "lists")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListsAction) RunGet(params struct {
|
||||||
|
Type string
|
||||||
|
Keyword string
|
||||||
|
}) {
|
||||||
|
if len(params.Type) == 0 {
|
||||||
|
params.Type = ipconfigs.IPListTypeBlack
|
||||||
|
}
|
||||||
|
this.Data["type"] = params.Type
|
||||||
|
this.Data["keyword"] = params.Keyword
|
||||||
|
|
||||||
|
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
|
||||||
|
Type: params.Type,
|
||||||
|
IsPublic: true,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count := countResp.Count
|
||||||
|
page := this.NewPage(count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
|
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
|
||||||
|
Type: params.Type,
|
||||||
|
IsPublic: true,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var listMaps = []maps.Map{}
|
||||||
|
for _, list := range listsResp.IpLists {
|
||||||
|
// 包含的IP数量
|
||||||
|
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var countItems = countItemsResp.Count
|
||||||
|
|
||||||
|
listMaps = append(listMaps, maps.Map{
|
||||||
|
"id": list.Id,
|
||||||
|
"isOn": list.IsOn,
|
||||||
|
"name": list.Name,
|
||||||
|
"description": list.Description,
|
||||||
|
"countItems": countItems,
|
||||||
|
"type": list.Type,
|
||||||
|
"isGlobal": list.IsGlobal,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["lists"] = listMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ func (this *TestAction) RunPost(params struct {
|
|||||||
"ipTo": resp.IpItem.IpTo,
|
"ipTo": resp.IpItem.IpTo,
|
||||||
"reason": resp.IpItem.Reason,
|
"reason": resp.IpItem.Reason,
|
||||||
"expiredAt": resp.IpItem.ExpiredAt,
|
"expiredAt": resp.IpItem.ExpiredAt,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
|
||||||
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
||||||
"type": resp.IpItem.Type,
|
"type": resp.IpItem.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func InitIPList(action *actionutils.ParentAction, listId int64) error {
|
|||||||
"description": list.Description,
|
"description": list.Description,
|
||||||
"isOn": list.IsOn,
|
"isOn": list.IsOn,
|
||||||
"countItems": countItems,
|
"countItems": countItems,
|
||||||
|
"isGlobal": list.IsGlobal,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cacheConfig.Init()
|
err = cacheConfig.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("检查配置失败:" + err.Error())
|
this.Fail("检查配置失败:" + err.Error())
|
||||||
|
|||||||
@@ -64,6 +64,36 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["user"] = nil
|
this.Data["user"] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 套餐
|
||||||
|
var userPlanMap = maps.Map{"id": server.UserPlanId, "dayTo": "", "plan": maps.Map{}}
|
||||||
|
if server.UserPlanId > 0 {
|
||||||
|
userPlanResp, err := this.RPC().UserPlanRPC().FindEnabledUserPlan(this.AdminContext(), &pb.FindEnabledUserPlanRequest{UserPlanId: server.UserPlanId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var userPlan = userPlanResp.UserPlan
|
||||||
|
if userPlan != nil {
|
||||||
|
planResp, err := this.RPC().PlanRPC().FindEnabledPlan(this.AdminContext(), &pb.FindEnabledPlanRequest{PlanId: userPlan.PlanId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var plan = planResp.Plan
|
||||||
|
if plan != nil {
|
||||||
|
userPlanMap = maps.Map{
|
||||||
|
"id": userPlan.Id,
|
||||||
|
"dayTo": userPlan.DayTo,
|
||||||
|
"plan": maps.Map{
|
||||||
|
"id": plan.Id,
|
||||||
|
"name": plan.Name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Data["userPlan"] = userPlanMap
|
||||||
|
|
||||||
// 集群
|
// 集群
|
||||||
clusterId := int64(0)
|
clusterId := int64(0)
|
||||||
this.Data["clusterName"] = ""
|
this.Data["clusterName"] = ""
|
||||||
@@ -123,6 +153,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
ClusterId int64
|
ClusterId int64
|
||||||
GroupIds []int64
|
GroupIds []int64
|
||||||
IsOn bool
|
IsOn bool
|
||||||
|
UserPlanId int64
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -137,6 +168,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
this.Fail("请选择部署的集群")
|
this.Fail("请选择部署的集群")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改基本信息
|
||||||
_, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{
|
_, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{
|
||||||
ServerId: params.ServerId,
|
ServerId: params.ServerId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
@@ -150,5 +182,17 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改套餐
|
||||||
|
if params.UserPlanId > 0 {
|
||||||
|
_, err = this.RPC().ServerRPC().UpdateServerUserPlan(this.AdminContext(), &pb.UpdateServerUserPlanRequest{
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
UserPlanId: params.UserPlanId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
|
|||||||
"name": "缓存",
|
"name": "缓存",
|
||||||
"url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString,
|
"url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString,
|
||||||
"isActive": secondMenuItem == "cache",
|
"isActive": secondMenuItem == "cache",
|
||||||
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn && len(locationConfig.Web.Cache.CacheRefs) > 0,
|
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn,
|
||||||
})
|
})
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "访问控制",
|
"name": "访问控制",
|
||||||
|
|||||||
@@ -70,15 +70,57 @@ func (this *AllowListAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -70,15 +70,57 @@ func (this *DenyListAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
"isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(),
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func (this *TestAction) RunPost(params struct {
|
|||||||
"ipTo": resp.IpItem.IpTo,
|
"ipTo": resp.IpItem.IpTo,
|
||||||
"reason": resp.IpItem.Reason,
|
"reason": resp.IpItem.Reason,
|
||||||
"expiredAt": resp.IpItem.ExpiredAt,
|
"expiredAt": resp.IpItem.ExpiredAt,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
|
||||||
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
||||||
"type": resp.IpItem.Type,
|
"type": resp.IpItem.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel),
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
|||||||
"name": "缓存",
|
"name": "缓存",
|
||||||
"url": "/servers/server/settings/cache?serverId=" + serverIdString,
|
"url": "/servers/server/settings/cache?serverId=" + serverIdString,
|
||||||
"isActive": secondMenuItem == "cache",
|
"isActive": secondMenuItem == "cache",
|
||||||
"isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn && len(serverConfig.Web.Cache.CacheRefs) > 0,
|
"isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn,
|
||||||
})
|
})
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "访问控制",
|
"name": "访问控制",
|
||||||
@@ -351,10 +351,10 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
|||||||
|
|
||||||
if teaconst.IsPlus {
|
if teaconst.IsPlus {
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "带宽限制",
|
"name": "流量限制",
|
||||||
"url": "/servers/server/settings/bandwidth?serverId=" + serverIdString,
|
"url": "/servers/server/settings/traffic?serverId=" + serverIdString,
|
||||||
"isActive": secondMenuItem == "bandwidth",
|
"isActive": secondMenuItem == "traffic",
|
||||||
"isOn": serverConfig.BandwidthLimit != nil && serverConfig.BandwidthLimit.IsOn,
|
"isOn": serverConfig.TrafficLimit != nil && serverConfig.TrafficLimit.IsOn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if serverConfig.IsTCPFamily() {
|
} else if serverConfig.IsTCPFamily() {
|
||||||
|
|||||||
37
internal/web/actions/default/servers/users/options.go
Normal file
37
internal/web/actions/default/servers/users/options.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package users
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OptionsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *OptionsAction) RunPost(params struct {
|
||||||
|
Keyword string
|
||||||
|
}) {
|
||||||
|
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Offset: 0,
|
||||||
|
Size: 10000, // TODO 改进 <plan-user-selector> 组件
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userMaps := []maps.Map{}
|
||||||
|
for _, user := range usersResp.Users {
|
||||||
|
userMaps = append(userMaps, maps.Map{
|
||||||
|
"id": user.Id,
|
||||||
|
"fullname": user.Fullname,
|
||||||
|
"username": user.Username,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["users"] = userMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
49
internal/web/actions/default/servers/users/plans.go
Normal file
49
internal/web/actions/default/servers/users/plans.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package users
|
||||||
|
|
||||||
|
import (
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PlansAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlansAction) RunPost(params struct {
|
||||||
|
UserId int64
|
||||||
|
ServerId int64
|
||||||
|
}) {
|
||||||
|
if !teaconst.IsPlus || params.UserId <= 0 {
|
||||||
|
this.Data["plans"] = []maps.Map{}
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 优化用户套餐查询
|
||||||
|
userPlansResp, err := this.RPC().UserPlanRPC().FindAllEnabledUserPlansForServer(this.AdminContext(), &pb.FindAllEnabledUserPlansForServerRequest{
|
||||||
|
UserId: params.UserId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var userPlanMaps = []maps.Map{}
|
||||||
|
for _, userPlan := range userPlansResp.UserPlans {
|
||||||
|
if userPlan.Plan == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
userPlanMaps = append(userPlanMaps, maps.Map{
|
||||||
|
"id": userPlan.Id,
|
||||||
|
"name": userPlan.Plan.Name,
|
||||||
|
"dayTo": userPlan.DayTo,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["plans"] = userPlanMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -43,7 +43,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package monitornodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
// TODO 检查权限
|
|
||||||
|
|
||||||
_, err := this.RPC().MonitorNodeRPC().DeleteMonitorNode(this.AdminContext(), &pb.DeleteMonitorNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除监控节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package monitornodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Helper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHelper() *Helper {
|
|
||||||
return &Helper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package monitornodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "node", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
countResp, err := this.RPC().MonitorNodeRPC().CountAllEnabledMonitorNodes(this.AdminContext(), &pb.CountAllEnabledMonitorNodesRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
nodeMaps := []maps.Map{}
|
|
||||||
if count > 0 {
|
|
||||||
nodesResp, err := this.RPC().MonitorNodeRPC().ListEnabledMonitorNodes(this.AdminContext(), &pb.ListEnabledMonitorNodesRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, node := range nodesResp.Nodes {
|
|
||||||
// 状态
|
|
||||||
status := &nodeconfigs.NodeStatus{}
|
|
||||||
if len(node.StatusJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.StatusJSON, &status)
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"name": node.Name,
|
|
||||||
"status": maps.Map{
|
|
||||||
"isActive": status.IsActive,
|
|
||||||
"updatedAt": status.UpdatedAt,
|
|
||||||
"hostname": status.Hostname,
|
|
||||||
"cpuUsage": status.CPUUsage,
|
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
|
||||||
"memUsage": status.MemoryUsage,
|
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
|
||||||
"buildVersion": status.BuildVersion,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMaps
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package monitornodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/monitor-nodes/node"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
|
|
||||||
Helper(NewHelper()).
|
|
||||||
Helper(settingutils.NewAdvancedHelper("monitorNodes")).
|
|
||||||
Prefix("/settings/monitorNodes").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/node/createPopup", new(node.CreatePopupAction)).
|
|
||||||
Post("/delete", new(DeleteAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreatePopupAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) Init() {
|
|
||||||
this.Nav("", "node", "create")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
IsOn bool
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入监控节点名称")
|
|
||||||
|
|
||||||
createResp, err := this.RPC().MonitorNodeRPC().CreateMonitorNode(this.AdminContext(), &pb.CreateMonitorNodeRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
Description: params.Description,
|
|
||||||
IsOn: params.IsOn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建监控节点 %d", createResp.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Helper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHelper() *Helper {
|
|
||||||
return &Helper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Helper) BeforeAction(action *actions.ActionObject) (goNext bool) {
|
|
||||||
if action.Request.Method != http.MethodGet {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().MonitorNodeRPC().FindEnabledMonitorNode(this.AdminContext(), &pb.FindEnabledMonitorNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.NotFound("monitorNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"description": node.Description,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type InstallAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *InstallAction) Init() {
|
|
||||||
this.Nav("", "", "install")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *InstallAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
// 监控节点信息
|
|
||||||
nodeResp, err := this.RPC().MonitorNodeRPC().FindEnabledMonitorNode(this.AdminContext(), &pb.FindEnabledMonitorNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.NotFound("monitorNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"uniqueId": node.UniqueId,
|
|
||||||
"secret": node.Secret,
|
|
||||||
}
|
|
||||||
|
|
||||||
// API节点列表
|
|
||||||
apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
apiNodes := apiNodesResp.Nodes
|
|
||||||
apiEndpoints := []string{}
|
|
||||||
for _, apiNode := range apiNodes {
|
|
||||||
if !apiNode.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
apiEndpoints = append(apiEndpoints, apiNode.AccessAddrs...)
|
|
||||||
}
|
|
||||||
this.Data["apiEndpoints"] = "\"" + strings.Join(apiEndpoints, "\", \"") + "\""
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LogsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *LogsAction) Init() {
|
|
||||||
this.Nav("", "node", "log")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *LogsAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
|
|
||||||
DayFrom string
|
|
||||||
DayTo string
|
|
||||||
Keyword string
|
|
||||||
Level string
|
|
||||||
}) {
|
|
||||||
this.Data["nodeId"] = params.NodeId
|
|
||||||
this.Data["dayFrom"] = params.DayFrom
|
|
||||||
this.Data["dayTo"] = params.DayTo
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["level"] = params.Level
|
|
||||||
|
|
||||||
monitorNodeResp, err := this.RPC().MonitorNodeRPC().FindEnabledMonitorNode(this.AdminContext(), &pb.FindEnabledMonitorNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
monitorNode := monitorNodeResp.Node
|
|
||||||
if monitorNode == nil {
|
|
||||||
this.NotFound("monitorNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": monitorNode.Id,
|
|
||||||
"name": monitorNode.Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
|
||||||
Role: nodeconfigs.NodeRoleMonitor,
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count, 20)
|
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleMonitor,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
|
|
||||||
logs := []maps.Map{}
|
|
||||||
for _, log := range logsResp.NodeLogs {
|
|
||||||
logs = append(logs, maps.Map{
|
|
||||||
"tag": log.Tag,
|
|
||||||
"description": log.Description,
|
|
||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
|
||||||
"level": log.Level,
|
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["logs"] = logs
|
|
||||||
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAction) Init() {
|
|
||||||
this.Nav("", "", "update")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().MonitorNodeRPC().FindEnabledMonitorNode(this.AdminContext(), &pb.FindEnabledMonitorNodeRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.WriteString("要操作的节点不存在")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"description": node.Description,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存基础设置
|
|
||||||
func (this *UpdateAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
IsOn bool
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入监控节点名称")
|
|
||||||
|
|
||||||
_, err := this.RPC().MonitorNodeRPC().UpdateMonitorNode(this.AdminContext(), &pb.UpdateMonitorNodeRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Name: params.Name,
|
|
||||||
Description: params.Description,
|
|
||||||
IsOn: params.IsOn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改监控节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -40,6 +40,7 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
|
|||||||
if teaconst.IsPlus {
|
if teaconst.IsPlus {
|
||||||
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
|
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
|
||||||
}
|
}
|
||||||
|
tabbar.Add("迁移", "", "/settings/transfer", "", this.tab == "transfer")
|
||||||
if teaconst.BuildPlus {
|
if teaconst.BuildPlus {
|
||||||
tabbar.Add("商业版认证", "", "/settings/authority", "", this.tab == "authority")
|
tabbar.Add("商业版认证", "", "/settings/authority", "", this.tab == "authority")
|
||||||
}
|
}
|
||||||
|
|||||||
17
internal/web/actions/default/settings/transfer/index.go
Normal file
17
internal/web/actions/default/settings/transfer/index.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package transfer
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "transfer", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package node
|
package transfer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
@@ -11,16 +11,13 @@ func init() {
|
|||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
server.
|
server.
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
|
||||||
Helper(settingutils.NewAdvancedHelper("monitorNodes")).
|
Helper(settingutils.NewAdvancedHelper("transfer")).
|
||||||
Prefix("/settings/monitorNodes/node").
|
Prefix("/settings/transfer").
|
||||||
|
|
||||||
// 节点相关
|
|
||||||
Helper(NewHelper()).
|
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
Get("/logs", new(LogsAction)).
|
Post("/validateAPI", new(ValidateAPIAction)).
|
||||||
GetPost("/update", new(UpdateAction)).
|
Post("/updateHosts", new(UpdateHostsAction)).
|
||||||
Get("/install", new(InstallAction)).
|
Post("/upgradeNodes", new(UpgradeNodesAction)).
|
||||||
|
Post("/statNodes", new(StatNodesAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
23
internal/web/actions/default/settings/transfer/statNodes.go
Normal file
23
internal/web/actions/default/settings/transfer/statNodes.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package transfer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StatNodesAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *StatNodesAction) RunPost(params struct{}) {
|
||||||
|
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ActiveState: 1})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["countNodes"] = countNodesResp.Count
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
158
internal/web/actions/default/settings/transfer/updateHosts.go
Normal file
158
internal/web/actions/default/settings/transfer/updateHosts.go
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package transfer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateHostsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateHostsAction) RunPost(params struct {
|
||||||
|
Protocol string
|
||||||
|
Host string
|
||||||
|
Port string
|
||||||
|
|
||||||
|
OldHosts []string
|
||||||
|
NewHosts []string
|
||||||
|
}) {
|
||||||
|
if len(params.OldHosts) != len(params.NewHosts) {
|
||||||
|
this.Fail("参数配置错误,请刷新页面后重试")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查端口
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
||||||
|
}
|
||||||
|
var apiURL = params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port
|
||||||
|
config.RPC.Endpoints = []string{apiURL}
|
||||||
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("检查API节点地址出错:" + err.Error())
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
|
}
|
||||||
|
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.APIContext(0), &pb.FindCurrentAPINodeVersionRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// API节点列表
|
||||||
|
nodesResp, err := client.APINodeRPC().FindAllEnabledAPINodes(client.Context(0), &pb.FindAllEnabledAPINodesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
||||||
|
}
|
||||||
|
var endpoints = []string{}
|
||||||
|
for _, node := range nodesResp.ApiNodes {
|
||||||
|
if !node.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// http
|
||||||
|
if len(node.HttpJSON) > 0 {
|
||||||
|
for index, oldHost := range params.OldHosts {
|
||||||
|
if len(params.NewHosts[index]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node.HttpJSON = bytes.ReplaceAll(node.HttpJSON, []byte("\""+oldHost+"\""), []byte("\""+params.NewHosts[index]+"\""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https
|
||||||
|
if len(node.HttpsJSON) > 0 {
|
||||||
|
for index, oldHost := range params.OldHosts {
|
||||||
|
if len(params.NewHosts[index]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node.HttpsJSON = bytes.ReplaceAll(node.HttpsJSON, []byte("\""+oldHost+"\""), []byte("\""+params.NewHosts[index]+"\""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restHTTP
|
||||||
|
if len(node.RestHTTPJSON) > 0 {
|
||||||
|
for index, oldHost := range params.OldHosts {
|
||||||
|
if len(params.NewHosts[index]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node.RestHTTPJSON = bytes.ReplaceAll(node.RestHTTPJSON, []byte("\""+oldHost+"\""), []byte("\""+params.NewHosts[index]+"\""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restHTTPS
|
||||||
|
if len(node.RestHTTPSJSON) > 0 {
|
||||||
|
for index, oldHost := range params.OldHosts {
|
||||||
|
if len(params.NewHosts[index]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node.RestHTTPSJSON = bytes.ReplaceAll(node.RestHTTPSJSON, []byte("\""+oldHost+"\""), []byte("\""+params.NewHosts[index]+"\""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// access addrs
|
||||||
|
if len(node.AccessAddrsJSON) > 0 {
|
||||||
|
for index, oldHost := range params.OldHosts {
|
||||||
|
if len(params.NewHosts[index]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node.AccessAddrsJSON = bytes.ReplaceAll(node.AccessAddrsJSON, []byte("\""+oldHost+"\""), []byte("\""+params.NewHosts[index]+"\""))
|
||||||
|
}
|
||||||
|
|
||||||
|
var addrs []*serverconfigs.NetworkAddressConfig
|
||||||
|
err = json.Unmarshal(node.AccessAddrsJSON, &addrs)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点访问地址失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
err = addr.Init()
|
||||||
|
if err != nil {
|
||||||
|
// 暂时不提示错误
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, a := range addr.FullAddresses() {
|
||||||
|
if !lists.ContainsString(endpoints, a) {
|
||||||
|
endpoints = append(endpoints, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存
|
||||||
|
_, err = client.APINodeRPC().UpdateAPINode(client.Context(0), &pb.UpdateAPINodeRequest{
|
||||||
|
ApiNodeId: node.Id,
|
||||||
|
Name: node.Name,
|
||||||
|
Description: node.Description,
|
||||||
|
HttpJSON: node.HttpJSON,
|
||||||
|
HttpsJSON: node.HttpsJSON,
|
||||||
|
AccessAddrsJSON: node.AccessAddrsJSON,
|
||||||
|
IsOn: node.IsOn,
|
||||||
|
RestIsOn: node.RestIsOn,
|
||||||
|
RestHTTPJSON: node.RestHTTPJSON,
|
||||||
|
RestHTTPSJSON: node.RestHTTPSJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("保存API节点信息失败:" + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package transfer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpgradeNodesAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpgradeNodesAction) RunPost(params struct {
|
||||||
|
ApiNodeProtocol string
|
||||||
|
ApiNodeHost string
|
||||||
|
ApiNodePort int
|
||||||
|
}) {
|
||||||
|
nodesResp, err := this.RPC().NodeRPC().ListEnabledNodesMatch(this.AdminContext(), &pb.ListEnabledNodesMatchRequest{
|
||||||
|
ActiveState: 1,
|
||||||
|
Size: 100,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var nodes = nodesResp.Nodes
|
||||||
|
this.Data["hasNext"] = len(nodes) > 0
|
||||||
|
this.Data["count"] = len(nodes)
|
||||||
|
|
||||||
|
if len(nodes) > 0 {
|
||||||
|
var message = &messageconfigs.ChangeAPINodeMessage{
|
||||||
|
Addr: params.ApiNodeProtocol + "://" + configutils.QuoteIP(params.ApiNodeHost) + ":" + types.String(params.ApiNodePort),
|
||||||
|
}
|
||||||
|
messageJSON, err := json.Marshal(message)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, node := range nodesResp.Nodes {
|
||||||
|
resp, err := this.RPC().NodeRPC().SendCommandToNode(this.AdminContext(), &pb.NodeStreamMessage{
|
||||||
|
NodeId: node.Id,
|
||||||
|
TimeoutSeconds: 3,
|
||||||
|
Code: messageconfigs.MessageCodeChangeAPINode,
|
||||||
|
DataJSON: messageJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !resp.IsOk {
|
||||||
|
this.Fail(resp.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
152
internal/web/actions/default/settings/transfer/validateAPI.go
Normal file
152
internal/web/actions/default/settings/transfer/validateAPI.go
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package transfer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValidateAPIAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ValidateAPIAction) RunPost(params struct {
|
||||||
|
Host string
|
||||||
|
Port string
|
||||||
|
Protocol string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("newAPINodeHost", params.Host).
|
||||||
|
Require("请输入新的API节点IP或域名").
|
||||||
|
Field("newAPINodePort", params.Port).
|
||||||
|
Require("请输入新的API节点端口")
|
||||||
|
|
||||||
|
if !regexp.MustCompile(`^\d{1,5}$`).MatchString(params.Port) {
|
||||||
|
this.FailField("newAPINodePort", "请输入正确的端口")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查端口
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
||||||
|
}
|
||||||
|
config.RPC.Endpoints = []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}
|
||||||
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("检查API节点地址出错:" + err.Error())
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
_, err = client.AdminRPC().FindAdminFullname(this.AdminContext(), &pb.FindAdminFullnameRequest{AdminId: this.AdminId()})
|
||||||
|
if err != nil {
|
||||||
|
statusErr, ok := status.FromError(err)
|
||||||
|
if ok {
|
||||||
|
if statusErr.Code() == codes.Unavailable {
|
||||||
|
this.Fail("测试新API节点失败:无法连接新的API节点:请检查:1、API节点地址和端口是否正确;2、防火墙或安全策略是否已正确设置。详细原因:" + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Fail("测试新API节点失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所有API节点
|
||||||
|
apiNodesResp, err := client.APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var apiNodes = apiNodesResp.ApiNodes
|
||||||
|
var hosts = []string{}
|
||||||
|
for _, node := range apiNodes {
|
||||||
|
if !node.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// http
|
||||||
|
if len(node.HttpJSON) > 0 {
|
||||||
|
var config = &serverconfigs.HTTPProtocolConfig{}
|
||||||
|
err = json.Unmarshal(node.HttpJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点HTTP信息失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, listen := range config.Listen {
|
||||||
|
if len(listen.Host) > 0 && !lists.ContainsString(hosts, listen.Host) {
|
||||||
|
hosts = append(hosts, listen.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https
|
||||||
|
if len(node.HttpsJSON) > 0 {
|
||||||
|
var config = &serverconfigs.HTTPSProtocolConfig{}
|
||||||
|
err = json.Unmarshal(node.HttpsJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点HTTPS信息失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, listen := range config.Listen {
|
||||||
|
if len(listen.Host) > 0 && !lists.ContainsString(hosts, listen.Host) {
|
||||||
|
hosts = append(hosts, listen.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restHTTP
|
||||||
|
if len(node.RestHTTPJSON) > 0 {
|
||||||
|
var config = &serverconfigs.HTTPProtocolConfig{}
|
||||||
|
err = json.Unmarshal(node.RestHTTPJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点REST HTTP信息失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, listen := range config.Listen {
|
||||||
|
if len(listen.Host) > 0 && !lists.ContainsString(hosts, listen.Host) {
|
||||||
|
hosts = append(hosts, listen.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restHTTPS
|
||||||
|
if len(node.RestHTTPSJSON) > 0 {
|
||||||
|
var config = &serverconfigs.HTTPSProtocolConfig{}
|
||||||
|
err = json.Unmarshal(node.RestHTTPSJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点REST HTTPS信息失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, listen := range config.Listen {
|
||||||
|
if len(listen.Host) > 0 && !lists.ContainsString(hosts, listen.Host) {
|
||||||
|
hosts = append(hosts, listen.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// access addrs
|
||||||
|
if len(node.AccessAddrsJSON) > 0 {
|
||||||
|
var addrs []*serverconfigs.NetworkAddressConfig
|
||||||
|
err = json.Unmarshal(node.AccessAddrsJSON, &addrs)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("读取节点访问地址失败:" + err.Error())
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if len(addr.Host) > 0 && !lists.ContainsString(hosts, addr.Host) {
|
||||||
|
hosts = append(hosts, addr.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Data["hosts"] = hosts
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package usernodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *DeleteAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
// TODO 检查权限
|
|
||||||
|
|
||||||
_, err := this.RPC().UserNodeRPC().DeleteUserNode(this.AdminContext(), &pb.DeleteUserNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除用户节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package usernodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Helper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHelper() *Helper {
|
|
||||||
return &Helper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package usernodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "node", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
|
||||||
if !teaconst.IsPlus {
|
|
||||||
this.RedirectURL("/")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
countResp, err := this.RPC().UserNodeRPC().CountAllEnabledUserNodes(this.AdminContext(), &pb.CountAllEnabledUserNodesRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
nodeMaps := []maps.Map{}
|
|
||||||
if count > 0 {
|
|
||||||
nodesResp, err := this.RPC().UserNodeRPC().ListEnabledUserNodes(this.AdminContext(), &pb.ListEnabledUserNodesRequest{
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, node := range nodesResp.Nodes {
|
|
||||||
// 状态
|
|
||||||
status := &nodeconfigs.NodeStatus{}
|
|
||||||
if len(node.StatusJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.StatusJSON, &status)
|
|
||||||
if err != nil {
|
|
||||||
logs.Error(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"name": node.Name,
|
|
||||||
"accessAddrs": node.AccessAddrs,
|
|
||||||
"status": maps.Map{
|
|
||||||
"isActive": status.IsActive,
|
|
||||||
"updatedAt": status.UpdatedAt,
|
|
||||||
"hostname": status.Hostname,
|
|
||||||
"cpuUsage": status.CPUUsage,
|
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
|
||||||
"memUsage": status.MemoryUsage,
|
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
|
||||||
"buildVersion": status.BuildVersion,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Data["nodes"] = nodeMaps
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package usernodes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-nodes/node"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
|
|
||||||
Helper(NewHelper()).
|
|
||||||
Helper(settingutils.NewAdvancedHelper("userNodes")).
|
|
||||||
Prefix("/settings/userNodes").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/node/createPopup", new(node.CreatePopupAction)).
|
|
||||||
Post("/delete", new(DeleteAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 添加地址
|
|
||||||
type CreateAddrPopupAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAddrPopupAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAddrPopupAction) RunGet(params struct {
|
|
||||||
}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreateAddrPopupAction) RunPost(params struct {
|
|
||||||
Protocol string
|
|
||||||
Addr string
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("addr", params.Addr).
|
|
||||||
Require("请输入访问地址")
|
|
||||||
|
|
||||||
|
|
||||||
host, port, err := net.SplitHostPort(params.Addr)
|
|
||||||
if err != nil {
|
|
||||||
this.FailField("addr", "错误的访问地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
addrConfig := &serverconfigs.NetworkAddressConfig{
|
|
||||||
Protocol: serverconfigs.Protocol(params.Protocol),
|
|
||||||
Host: host,
|
|
||||||
PortRange: port,
|
|
||||||
}
|
|
||||||
this.Data["addr"] = addrConfig
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreatePopupAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) Init() {
|
|
||||||
this.Nav("", "node", "create")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *CreatePopupAction) RunPost(params struct {
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
ListensJSON []byte
|
|
||||||
CertIdsJSON []byte
|
|
||||||
AccessAddrsJSON []byte
|
|
||||||
IsOn bool
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入用户节点名称")
|
|
||||||
|
|
||||||
httpConfig := &serverconfigs.HTTPProtocolConfig{}
|
|
||||||
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
|
|
||||||
|
|
||||||
// 监听地址
|
|
||||||
listens := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
err := json.Unmarshal(params.ListensJSON, &listens)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(listens) == 0 {
|
|
||||||
this.Fail("请添加至少一个进程监听地址")
|
|
||||||
}
|
|
||||||
for _, addr := range listens {
|
|
||||||
if addr.Protocol.IsHTTPFamily() {
|
|
||||||
httpConfig.IsOn = true
|
|
||||||
httpConfig.Listen = append(httpConfig.Listen, addr)
|
|
||||||
} else if addr.Protocol.IsHTTPSFamily() {
|
|
||||||
httpsConfig.IsOn = true
|
|
||||||
httpsConfig.Listen = append(httpsConfig.Listen, addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 证书
|
|
||||||
certIds := []int64{}
|
|
||||||
if len(params.CertIdsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(params.CertIdsJSON, &certIds)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if httpsConfig.IsOn && len(httpsConfig.Listen) > 0 && len(certIds) == 0 {
|
|
||||||
this.Fail("请添加至少一个证书")
|
|
||||||
}
|
|
||||||
|
|
||||||
certRefs := []*sslconfigs.SSLCertRef{}
|
|
||||||
for _, certId := range certIds {
|
|
||||||
certRefs = append(certRefs, &sslconfigs.SSLCertRef{
|
|
||||||
IsOn: true,
|
|
||||||
CertId: certId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
certRefsJSON, err := json.Marshal(certRefs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建策略
|
|
||||||
if len(certIds) > 0 {
|
|
||||||
sslPolicyCreateResp, err := this.RPC().SSLPolicyRPC().CreateSSLPolicy(this.AdminContext(), &pb.CreateSSLPolicyRequest{
|
|
||||||
SslCertsJSON: certRefsJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sslPolicyId := sslPolicyCreateResp.SslPolicyId
|
|
||||||
httpsConfig.SSLPolicyRef = &sslconfigs.SSLPolicyRef{
|
|
||||||
IsOn: true,
|
|
||||||
SSLPolicyId: sslPolicyId,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 访问地址
|
|
||||||
accessAddrs := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
err = json.Unmarshal(params.AccessAddrsJSON, &accessAddrs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(accessAddrs) == 0 {
|
|
||||||
this.Fail("请添加至少一个外部访问地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
httpJSON, err := json.Marshal(httpConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
httpsJSON, err := json.Marshal(httpsConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
createResp, err := this.RPC().UserNodeRPC().CreateUserNode(this.AdminContext(), &pb.CreateUserNodeRequest{
|
|
||||||
Name: params.Name,
|
|
||||||
Description: params.Description,
|
|
||||||
HttpJSON: httpJSON,
|
|
||||||
HttpsJSON: httpsJSON,
|
|
||||||
AccessAddrsJSON: params.AccessAddrsJSON,
|
|
||||||
IsOn: params.IsOn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建用户节点 %d", createResp.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Helper struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHelper() *Helper {
|
|
||||||
return &Helper{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Helper) BeforeAction(action *actions.ActionObject) (goNext bool) {
|
|
||||||
if action.Request.Method != http.MethodGet {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IndexAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
|
||||||
this.Nav("", "", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().UserNodeRPC().FindEnabledUserNode(this.AdminContext(), &pb.FindEnabledUserNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.NotFound("userNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听地址
|
|
||||||
httpConfig := &serverconfigs.HTTPProtocolConfig{}
|
|
||||||
if len(node.HttpJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.HttpJSON, httpConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
|
|
||||||
if len(node.HttpsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.HttpsJSON, httpsConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听地址
|
|
||||||
listens := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
listens = append(listens, httpConfig.Listen...)
|
|
||||||
listens = append(listens, httpsConfig.Listen...)
|
|
||||||
|
|
||||||
// 证书信息
|
|
||||||
certs := []*sslconfigs.SSLCertConfig{}
|
|
||||||
sslPolicyId := int64(0)
|
|
||||||
if httpsConfig.SSLPolicyRef != nil && httpsConfig.SSLPolicyRef.SSLPolicyId > 0 {
|
|
||||||
sslPolicyConfigResp, err := this.RPC().SSLPolicyRPC().FindEnabledSSLPolicyConfig(this.AdminContext(), &pb.FindEnabledSSLPolicyConfigRequest{SslPolicyId: httpsConfig.SSLPolicyRef.SSLPolicyId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sslPolicyConfigJSON := sslPolicyConfigResp.SslPolicyJSON
|
|
||||||
if len(sslPolicyConfigJSON) > 0 {
|
|
||||||
sslPolicyId = httpsConfig.SSLPolicyRef.SSLPolicyId
|
|
||||||
|
|
||||||
sslPolicy := &sslconfigs.SSLPolicy{}
|
|
||||||
err = json.Unmarshal(sslPolicyConfigJSON, sslPolicy)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
certs = sslPolicy.Certs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 访问地址
|
|
||||||
accessAddrs := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
if len(node.AccessAddrsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.AccessAddrsJSON, &accessAddrs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"description": node.Description,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"listens": listens,
|
|
||||||
"accessAddrs": accessAddrs,
|
|
||||||
"hasHTTPS": sslPolicyId > 0,
|
|
||||||
"certs": certs,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
|
|
||||||
Helper(settingutils.NewAdvancedHelper("userNodes")).
|
|
||||||
Prefix("/settings/userNodes/node").
|
|
||||||
|
|
||||||
// 这里不受Helper的约束
|
|
||||||
GetPost("/createAddrPopup", new(CreateAddrPopupAction)).
|
|
||||||
GetPost("/updateAddrPopup", new(UpdateAddrPopupAction)).
|
|
||||||
|
|
||||||
// 节点相关
|
|
||||||
Helper(NewHelper()).
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
Get("/logs", new(LogsAction)).
|
|
||||||
GetPost("/update", new(UpdateAction)).
|
|
||||||
Get("/install", new(InstallAction)).
|
|
||||||
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type InstallAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *InstallAction) Init() {
|
|
||||||
this.Nav("", "", "install")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *InstallAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
// 用户节点信息
|
|
||||||
nodeResp, err := this.RPC().UserNodeRPC().FindEnabledUserNode(this.AdminContext(), &pb.FindEnabledUserNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.NotFound("userNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"uniqueId": node.UniqueId,
|
|
||||||
"secret": node.Secret,
|
|
||||||
}
|
|
||||||
|
|
||||||
// API节点列表
|
|
||||||
apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
apiNodes := apiNodesResp.Nodes
|
|
||||||
apiEndpoints := []string{}
|
|
||||||
for _, apiNode := range apiNodes {
|
|
||||||
if !apiNode.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
apiEndpoints = append(apiEndpoints, apiNode.AccessAddrs...)
|
|
||||||
}
|
|
||||||
this.Data["apiEndpoints"] = "\"" + strings.Join(apiEndpoints, "\", \"") + "\""
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LogsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *LogsAction) Init() {
|
|
||||||
this.Nav("", "node", "log")
|
|
||||||
this.SecondMenu("nodes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *LogsAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
|
|
||||||
DayFrom string
|
|
||||||
DayTo string
|
|
||||||
Keyword string
|
|
||||||
Level string
|
|
||||||
}) {
|
|
||||||
this.Data["nodeId"] = params.NodeId
|
|
||||||
this.Data["dayFrom"] = params.DayFrom
|
|
||||||
this.Data["dayTo"] = params.DayTo
|
|
||||||
this.Data["keyword"] = params.Keyword
|
|
||||||
this.Data["level"] = params.Level
|
|
||||||
|
|
||||||
userNodeResp, err := this.RPC().UserNodeRPC().FindEnabledUserNode(this.AdminContext(), &pb.FindEnabledUserNodeRequest{NodeId: params.NodeId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userNode := userNodeResp.Node
|
|
||||||
if userNode == nil {
|
|
||||||
this.NotFound("userNode", params.NodeId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": userNode.Id,
|
|
||||||
"name": userNode.Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
|
||||||
Role: nodeconfigs.NodeRoleUser,
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
count := countResp.Count
|
|
||||||
page := this.NewPage(count, 20)
|
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Role: nodeconfigs.NodeRoleUser,
|
|
||||||
DayFrom: params.DayFrom,
|
|
||||||
DayTo: params.DayTo,
|
|
||||||
Keyword: params.Keyword,
|
|
||||||
Level: params.Level,
|
|
||||||
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
|
|
||||||
logs := []maps.Map{}
|
|
||||||
for _, log := range logsResp.NodeLogs {
|
|
||||||
logs = append(logs, maps.Map{
|
|
||||||
"tag": log.Tag,
|
|
||||||
"description": log.Description,
|
|
||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
|
||||||
"level": log.Level,
|
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["logs"] = logs
|
|
||||||
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAction) Init() {
|
|
||||||
this.Nav("", "", "update")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAction) RunGet(params struct {
|
|
||||||
NodeId int64
|
|
||||||
}) {
|
|
||||||
nodeResp, err := this.RPC().UserNodeRPC().FindEnabledUserNode(this.AdminContext(), &pb.FindEnabledUserNodeRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
node := nodeResp.Node
|
|
||||||
if node == nil {
|
|
||||||
this.WriteString("要操作的节点不存在")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
httpConfig := &serverconfigs.HTTPProtocolConfig{}
|
|
||||||
if len(node.HttpJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.HttpJSON, httpConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
|
|
||||||
if len(node.HttpsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.HttpsJSON, httpsConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听地址
|
|
||||||
listens := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
listens = append(listens, httpConfig.Listen...)
|
|
||||||
listens = append(listens, httpsConfig.Listen...)
|
|
||||||
|
|
||||||
// 证书信息
|
|
||||||
certs := []*sslconfigs.SSLCertConfig{}
|
|
||||||
sslPolicyId := int64(0)
|
|
||||||
if httpsConfig.SSLPolicyRef != nil && httpsConfig.SSLPolicyRef.SSLPolicyId > 0 {
|
|
||||||
sslPolicyConfigResp, err := this.RPC().SSLPolicyRPC().FindEnabledSSLPolicyConfig(this.AdminContext(), &pb.FindEnabledSSLPolicyConfigRequest{SslPolicyId: httpsConfig.SSLPolicyRef.SSLPolicyId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sslPolicyConfigJSON := sslPolicyConfigResp.SslPolicyJSON
|
|
||||||
if len(sslPolicyConfigJSON) > 0 {
|
|
||||||
sslPolicyId = httpsConfig.SSLPolicyRef.SSLPolicyId
|
|
||||||
|
|
||||||
sslPolicy := &sslconfigs.SSLPolicy{}
|
|
||||||
err = json.Unmarshal(sslPolicyConfigJSON, sslPolicy)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
certs = sslPolicy.Certs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
accessAddrs := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
if len(node.AccessAddrsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(node.AccessAddrsJSON, &accessAddrs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
|
||||||
"id": node.Id,
|
|
||||||
"name": node.Name,
|
|
||||||
"description": node.Description,
|
|
||||||
"isOn": node.IsOn,
|
|
||||||
"listens": listens,
|
|
||||||
"certs": certs,
|
|
||||||
"sslPolicyId": sslPolicyId,
|
|
||||||
"accessAddrs": accessAddrs,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存基础设置
|
|
||||||
func (this *UpdateAction) RunPost(params struct {
|
|
||||||
NodeId int64
|
|
||||||
Name string
|
|
||||||
SslPolicyId int64
|
|
||||||
ListensJSON []byte
|
|
||||||
CertIdsJSON []byte
|
|
||||||
AccessAddrsJSON []byte
|
|
||||||
Description string
|
|
||||||
IsOn bool
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("name", params.Name).
|
|
||||||
Require("请输入用户节点名称")
|
|
||||||
|
|
||||||
httpConfig := &serverconfigs.HTTPProtocolConfig{}
|
|
||||||
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
|
|
||||||
|
|
||||||
// 监听地址
|
|
||||||
listens := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
err := json.Unmarshal(params.ListensJSON, &listens)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(listens) == 0 {
|
|
||||||
this.Fail("请添加至少一个进程监听地址")
|
|
||||||
}
|
|
||||||
for _, addr := range listens {
|
|
||||||
if addr.Protocol.IsHTTPFamily() {
|
|
||||||
httpConfig.IsOn = true
|
|
||||||
httpConfig.Listen = append(httpConfig.Listen, addr)
|
|
||||||
} else if addr.Protocol.IsHTTPSFamily() {
|
|
||||||
httpsConfig.IsOn = true
|
|
||||||
httpsConfig.Listen = append(httpsConfig.Listen, addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 证书
|
|
||||||
certIds := []int64{}
|
|
||||||
if len(params.CertIdsJSON) > 0 {
|
|
||||||
err = json.Unmarshal(params.CertIdsJSON, &certIds)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if httpsConfig.IsOn && len(httpsConfig.Listen) > 0 && len(certIds) == 0 {
|
|
||||||
this.Fail("请添加至少一个证书")
|
|
||||||
}
|
|
||||||
|
|
||||||
certRefs := []*sslconfigs.SSLCertRef{}
|
|
||||||
for _, certId := range certIds {
|
|
||||||
certRefs = append(certRefs, &sslconfigs.SSLCertRef{
|
|
||||||
IsOn: true,
|
|
||||||
CertId: certId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
certRefsJSON, err := json.Marshal(certRefs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建策略
|
|
||||||
sslPolicyId := params.SslPolicyId
|
|
||||||
if sslPolicyId == 0 {
|
|
||||||
if len(certIds) > 0 {
|
|
||||||
sslPolicyCreateResp, err := this.RPC().SSLPolicyRPC().CreateSSLPolicy(this.AdminContext(), &pb.CreateSSLPolicyRequest{
|
|
||||||
SslCertsJSON: certRefsJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sslPolicyId = sslPolicyCreateResp.SslPolicyId
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_, err = this.RPC().SSLPolicyRPC().UpdateSSLPolicy(this.AdminContext(), &pb.UpdateSSLPolicyRequest{
|
|
||||||
SslPolicyId: sslPolicyId,
|
|
||||||
SslCertsJSON: certRefsJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpsConfig.SSLPolicyRef = &sslconfigs.SSLPolicyRef{
|
|
||||||
IsOn: true,
|
|
||||||
SSLPolicyId: sslPolicyId,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 访问地址
|
|
||||||
accessAddrs := []*serverconfigs.NetworkAddressConfig{}
|
|
||||||
err = json.Unmarshal(params.AccessAddrsJSON, &accessAddrs)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(accessAddrs) == 0 {
|
|
||||||
this.Fail("请添加至少一个外部访问地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
httpJSON, err := json.Marshal(httpConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
httpsJSON, err := json.Marshal(httpsConfig)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = this.RPC().UserNodeRPC().UpdateUserNode(this.AdminContext(), &pb.UpdateUserNodeRequest{
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Name: params.Name,
|
|
||||||
Description: params.Description,
|
|
||||||
HttpJSON: httpJSON,
|
|
||||||
HttpsJSON: httpsJSON,
|
|
||||||
AccessAddrsJSON: params.AccessAddrsJSON,
|
|
||||||
IsOn: params.IsOn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改用户节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package node
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateAddrPopupAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAddrPopupAction) Init() {
|
|
||||||
this.Nav("", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAddrPopupAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *UpdateAddrPopupAction) RunPost(params struct {
|
|
||||||
Protocol string
|
|
||||||
Addr string
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
params.Must.
|
|
||||||
Field("addr", params.Addr).
|
|
||||||
Require("请输入访问地址")
|
|
||||||
host, port, err := net.SplitHostPort(params.Addr)
|
|
||||||
if err != nil {
|
|
||||||
this.FailField("addr", "错误的访问地址")
|
|
||||||
}
|
|
||||||
|
|
||||||
addrConfig := &serverconfigs.NetworkAddressConfig{
|
|
||||||
Protocol: serverconfigs.Protocol(params.Protocol),
|
|
||||||
Host: host,
|
|
||||||
PortRange: port,
|
|
||||||
}
|
|
||||||
this.Data["addr"] = addrConfig
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
17
internal/web/actions/default/setup/confirm/helper.go
Normal file
17
internal/web/actions/default/setup/confirm/helper.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package confirm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Helper struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
|
||||||
|
if !setup.IsNewInstalled() {
|
||||||
|
actionPtr.Object().RedirectURL("/")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
126
internal/web/actions/default/setup/confirm/index.go
Normal file
126
internal/web/actions/default/setup/confirm/index.go
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package confirm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
|
var endpoints = []string{}
|
||||||
|
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err == nil {
|
||||||
|
endpoints = config.RPC.Endpoints
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["nodeId"] = config.NodeId
|
||||||
|
this.Data["secret"] = config.Secret
|
||||||
|
|
||||||
|
if len(endpoints) == 0 {
|
||||||
|
endpoints = []string{""} // 初始化一个空的
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["endpoints"] = endpoints
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
Endpoints []string
|
||||||
|
NodeId string
|
||||||
|
Secret string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
var endpoints = []string{}
|
||||||
|
for _, endpoint := range params.Endpoints {
|
||||||
|
if len(endpoint) > 0 {
|
||||||
|
u, err := url.Parse(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("API节点地址'" + endpoint + "'格式错误")
|
||||||
|
}
|
||||||
|
endpoint = u.Scheme + "://" + u.Host
|
||||||
|
if u.Scheme != "http" && u.Scheme != "https" {
|
||||||
|
this.Fail("API节点地址'" + endpoint + "'中的协议错误,目前只支持http或者https")
|
||||||
|
}
|
||||||
|
switch u.Scheme {
|
||||||
|
case "http":
|
||||||
|
if len(u.Port()) == 0 {
|
||||||
|
endpoint += ":80"
|
||||||
|
}
|
||||||
|
case "https":
|
||||||
|
if len(u.Port()) == 0 {
|
||||||
|
endpoint += ":443"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测是否连接
|
||||||
|
var config = &configs.APIConfig{}
|
||||||
|
config.NodeId = params.NodeId
|
||||||
|
config.Secret = params.Secret
|
||||||
|
config.RPC.Endpoints = []string{endpoint}
|
||||||
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("无法连接到API节点地址'" + endpoint + "':" + err.Error())
|
||||||
|
}
|
||||||
|
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.Context(0), &pb.FindCurrentAPINodeVersionRequest{})
|
||||||
|
if err != nil {
|
||||||
|
_ = client.Close()
|
||||||
|
this.Fail("无法连接到API节点地址'" + endpoint + "':" + err.Error())
|
||||||
|
}
|
||||||
|
_ = client.Close()
|
||||||
|
|
||||||
|
endpoints = append(endpoints, endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(endpoints) == 0 {
|
||||||
|
this.Fail("请输入至少一个API节点地址")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params.NodeId) == 0 {
|
||||||
|
this.Fail("请输入NodeId")
|
||||||
|
}
|
||||||
|
if len(params.Secret) == 0 {
|
||||||
|
this.Fail("请输入Secret")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建配置文件
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
config = &configs.APIConfig{}
|
||||||
|
}
|
||||||
|
config.NodeId = params.NodeId
|
||||||
|
config.Secret = params.Secret
|
||||||
|
config.RPC.Endpoints = endpoints
|
||||||
|
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("配置保存失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("RPC配置无法读取:" + err.Error())
|
||||||
|
}
|
||||||
|
err = rpcClient.UpdateConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("重载RPC配置失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
13
internal/web/actions/default/setup/confirm/init.go
Normal file
13
internal/web/actions/default/setup/confirm/init.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package confirm
|
||||||
|
|
||||||
|
import "github.com/iwind/TeaGo"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(new(Helper)).
|
||||||
|
Prefix("/setup/confirm").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
61
internal/web/actions/default/setup/detectDB.go
Normal file
61
internal/web/actions/default/setup/detectDB.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package setup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DetectDBAction 尝试从本地服务器中发现MySQL
|
||||||
|
type DetectDBAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DetectDBAction) RunPost(params struct{}) {
|
||||||
|
var localHost = ""
|
||||||
|
var localPort = ""
|
||||||
|
var localUsername = ""
|
||||||
|
var localPassword = ""
|
||||||
|
|
||||||
|
// 本地的3306端口是否可以连接
|
||||||
|
conn, err := net.DialTimeout("tcp", "127.0.0.1:3306", 3*time.Second)
|
||||||
|
if err == nil {
|
||||||
|
_ = conn.Close()
|
||||||
|
localHost = "127.0.0.1"
|
||||||
|
localPort = "3306"
|
||||||
|
|
||||||
|
var username = "root"
|
||||||
|
for _, pass := range []string{"", "123456", "654321", "Aa_123456"} {
|
||||||
|
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||||
|
Driver: "mysql",
|
||||||
|
Dsn: username + ":" + pass + "@tcp(" + configutils.QuoteIP(localHost) + ":" + localPort + ")/edges11111",
|
||||||
|
Prefix: "",
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
err = db.Raw().Ping()
|
||||||
|
_ = db.Close()
|
||||||
|
|
||||||
|
if err == nil || strings.Contains(err.Error(), "Error 1049") {
|
||||||
|
localUsername = username
|
||||||
|
localPassword = pass
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["localDB"] = maps.Map{
|
||||||
|
"host": localHost,
|
||||||
|
"port": localPort,
|
||||||
|
"username": localUsername,
|
||||||
|
"password": localPassword,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ func init() {
|
|||||||
Post("/validateDb", new(ValidateDbAction)).
|
Post("/validateDb", new(ValidateDbAction)).
|
||||||
Post("/validateAdmin", new(ValidateAdminAction)).
|
Post("/validateAdmin", new(ValidateAdminAction)).
|
||||||
Post("/install", new(InstallAction)).
|
Post("/install", new(InstallAction)).
|
||||||
|
Post("/status", new(StatusAction)).
|
||||||
|
Post("/detectDB", new(DetectDBAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -32,7 +33,13 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
|
currentStatusText = ""
|
||||||
|
defer func() {
|
||||||
|
currentStatusText = ""
|
||||||
|
}()
|
||||||
|
|
||||||
// API节点配置
|
// API节点配置
|
||||||
|
currentStatusText = "正在检查API节点配置"
|
||||||
apiNodeMap := maps.Map{}
|
apiNodeMap := maps.Map{}
|
||||||
err := json.Unmarshal(params.ApiNodeJSON, &apiNodeMap)
|
err := json.Unmarshal(params.ApiNodeJSON, &apiNodeMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -40,6 +47,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 数据库
|
// 数据库
|
||||||
|
currentStatusText = "正在检查数据库配置"
|
||||||
dbMap := maps.Map{}
|
dbMap := maps.Map{}
|
||||||
err = json.Unmarshal(params.DbJSON, &dbMap)
|
err = json.Unmarshal(params.DbJSON, &dbMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,6 +55,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 管理员
|
// 管理员
|
||||||
|
currentStatusText = "正在检查管理员配置"
|
||||||
adminMap := maps.Map{}
|
adminMap := maps.Map{}
|
||||||
err = json.Unmarshal(params.AdminJSON, &adminMap)
|
err = json.Unmarshal(params.AdminJSON, &adminMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,6 +65,8 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
// 安装API节点
|
// 安装API节点
|
||||||
mode := apiNodeMap.GetString("mode")
|
mode := apiNodeMap.GetString("mode")
|
||||||
if mode == "new" {
|
if mode == "new" {
|
||||||
|
currentStatusText = "准备启动新API节点"
|
||||||
|
|
||||||
// 整个系统目录结构为:
|
// 整个系统目录结构为:
|
||||||
// edge-admin/
|
// edge-admin/
|
||||||
// edge-api/
|
// edge-api/
|
||||||
@@ -136,7 +147,9 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 开始安装
|
// 开始安装
|
||||||
|
currentStatusText = "正在安装数据库表结构并写入数据"
|
||||||
var resultMap = maps.Map{}
|
var resultMap = maps.Map{}
|
||||||
|
logs.Println("[INSTALL]setup edge-api")
|
||||||
{
|
{
|
||||||
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "setup", "-api-node-protocol=http", "-api-node-host=\""+apiNodeMap.GetString("newHost")+"\"", "-api-node-port=\""+apiNodeMap.GetString("newPort")+"\"")
|
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "setup", "-api-node-protocol=http", "-api-node-host=\""+apiNodeMap.GetString("newHost")+"\"", "-api-node-port=\""+apiNodeMap.GetString("newPort")+"\"")
|
||||||
output := bytes.NewBuffer([]byte{})
|
output := bytes.NewBuffer([]byte{})
|
||||||
@@ -156,7 +169,16 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭正在运行的API节点,防止冲突
|
||||||
|
logs.Println("[INSTALL]stop edge-api")
|
||||||
|
{
|
||||||
|
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "stop")
|
||||||
|
_ = cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
// 启动API节点
|
// 启动API节点
|
||||||
|
currentStatusText = "正在启动API节点"
|
||||||
|
logs.Println("[INSTALL]start edge-api")
|
||||||
{
|
{
|
||||||
cmd := exec.Command(apiNodeDir + "/bin/edge-api")
|
cmd := exec.Command(apiNodeDir + "/bin/edge-api")
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
@@ -183,7 +205,8 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置管理员
|
// 设置管理员
|
||||||
client, err := rpc.NewRPCClient(apiConfig)
|
currentStatusText = "正在设置管理员"
|
||||||
|
client, err := rpc.NewRPCClient(apiConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
@@ -203,6 +226,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置访问日志保留天数
|
// 设置访问日志保留天数
|
||||||
|
currentStatusText = "正在配置访问日志保留天数"
|
||||||
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
|
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
|
||||||
if accessLogKeepDays > 0 {
|
if accessLogKeepDays > 0 {
|
||||||
var config = &systemconfigs.DatabaseConfig{}
|
var config = &systemconfigs.DatabaseConfig{}
|
||||||
@@ -239,11 +263,15 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
NodeId: apiNodeMap.GetString("oldNodeId"),
|
NodeId: apiNodeMap.GetString("oldNodeId"),
|
||||||
Secret: apiNodeMap.GetString("oldNodeSecret"),
|
Secret: apiNodeMap.GetString("oldNodeSecret"),
|
||||||
}
|
}
|
||||||
client, err := rpc.NewRPCClient(apiConfig)
|
client, err := rpc.NewRPCClient(apiConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
// 设置管理员
|
// 设置管理员
|
||||||
ctx := client.APIContext(0)
|
ctx := client.APIContext(0)
|
||||||
_, err = client.AdminRPC().CreateOrUpdateAdmin(ctx, &pb.CreateOrUpdateAdminRequest{
|
_, err = client.AdminRPC().CreateOrUpdateAdmin(ctx, &pb.CreateOrUpdateAdminRequest{
|
||||||
|
|||||||
16
internal/web/actions/default/setup/status.go
Normal file
16
internal/web/actions/default/setup/status.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package setup
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
var currentStatusText = ""
|
||||||
|
|
||||||
|
type StatusAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *StatusAction) RunPost(params struct{}) {
|
||||||
|
this.Data["statusText"] = currentStatusText
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -19,10 +19,10 @@ func (this *ValidateAdminAction) RunPost(params struct {
|
|||||||
}) {
|
}) {
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("adminUsername", params.AdminUsername).
|
Field("adminUsername", params.AdminUsername).
|
||||||
Require("请输入登录用户名").
|
Require("请输入管理员登录用户名").
|
||||||
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能包含英文、数字或下划线").
|
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能包含英文、数字或下划线").
|
||||||
Field("adminPassword", params.AdminPassword).
|
Field("adminPassword", params.AdminPassword).
|
||||||
Require("请输入登录密码").
|
Require("请输入管理员登录密码").
|
||||||
Match(`^[a-zA-Z0-9_]+$`, "密码中只能包含英文、数字或下划线").
|
Match(`^[a-zA-Z0-9_]+$`, "密码中只能包含英文、数字或下划线").
|
||||||
Field("adminPassword2", params.AdminPassword2).
|
Field("adminPassword2", params.AdminPassword2).
|
||||||
Require("请输入确认密码").
|
Require("请输入确认密码").
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user