2021-11-11 15:56:02 +08:00
|
|
|
package router
|
2021-04-16 15:10:07 +08:00
|
|
|
|
|
|
|
|
import (
|
2022-09-09 18:26:08 +08:00
|
|
|
"mayfly-go/internal/machine/api"
|
|
|
|
|
"mayfly-go/internal/machine/application"
|
2022-10-26 20:49:29 +08:00
|
|
|
tagapp "mayfly-go/internal/tag/application"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/ctx"
|
2021-04-16 15:10:07 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func InitMachineRouter(router *gin.RouterGroup) {
|
2022-04-22 17:49:21 +08:00
|
|
|
m := &api.Machine{
|
2022-09-09 18:26:08 +08:00
|
|
|
MachineApp: application.GetMachineApp(),
|
2022-10-26 20:49:29 +08:00
|
|
|
TagApp: tagapp.GetTagTreeApp(),
|
2022-04-22 17:49:21 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-11 15:56:02 +08:00
|
|
|
machines := router.Group("machines")
|
2021-04-16 15:10:07 +08:00
|
|
|
{
|
2021-11-11 15:56:02 +08:00
|
|
|
machines.GET("", func(c *gin.Context) {
|
2021-05-08 18:00:33 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(m.Machines)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
2022-08-02 21:44:01 +08:00
|
|
|
machines.GET(":machineId/pwd", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(m.GetMachinePwd)
|
|
|
|
|
})
|
|
|
|
|
|
2021-11-25 14:34:15 +08:00
|
|
|
machines.GET(":machineId/stats", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(m.MachineStats)
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-16 21:45:00 +08:00
|
|
|
machines.GET(":machineId/process", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(m.GetProcess)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 终止进程
|
2022-07-14 11:39:12 +08:00
|
|
|
killProcessL := ctx.NewLogInfo("终止进程").WithSave(true)
|
2022-01-16 21:45:00 +08:00
|
|
|
killProcessP := ctx.NewPermission("machine:killprocess")
|
|
|
|
|
machines.DELETE(":machineId/process", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(killProcessL).
|
|
|
|
|
WithRequiredPermission(killProcessP).
|
|
|
|
|
Handle(m.KillProcess)
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
saveMachine := ctx.NewLogInfo("保存机器信息").WithSave(true)
|
2022-08-29 21:43:24 +08:00
|
|
|
saveMachineP := ctx.NewPermission("machine:update")
|
2021-11-11 15:56:02 +08:00
|
|
|
machines.POST("", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(saveMachine).
|
2022-08-29 21:43:24 +08:00
|
|
|
WithRequiredPermission(saveMachineP).
|
2021-07-28 18:03:19 +08:00
|
|
|
Handle(m.SaveMachine)
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
changeStatus := ctx.NewLogInfo("调整机器状态").WithSave(true)
|
2022-04-27 10:59:02 +08:00
|
|
|
machines.PUT(":machineId/:status", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(changeStatus).
|
|
|
|
|
Handle(m.ChangeStatus)
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
delMachine := ctx.NewLogInfo("删除机器").WithSave(true)
|
2021-11-11 15:56:02 +08:00
|
|
|
machines.DELETE(":machineId", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(delMachine).
|
|
|
|
|
Handle(m.DeleteMachine)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
closeCli := ctx.NewLogInfo("关闭机器客户端").WithSave(true)
|
2021-11-11 15:56:02 +08:00
|
|
|
machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
|
2021-09-08 17:55:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
2021-11-11 15:56:02 +08:00
|
|
|
machines.GET(":machineId/terminal", m.WsSSH)
|
2022-08-29 21:43:24 +08:00
|
|
|
|
|
|
|
|
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
|
|
|
|
|
machines.GET("rec/names", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(saveMachineP).
|
|
|
|
|
Handle(m.MachineRecDirNames)
|
|
|
|
|
})
|
2021-04-16 15:10:07 +08:00
|
|
|
}
|
|
|
|
|
}
|