mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-26 17:30:26 +08:00
update
This commit is contained in:
@@ -45,12 +45,18 @@ func (p *procApi) DeleteNewProcess(ctx *gin.Context, req struct {
|
||||
func (p *procApi) KillProcess(ctx *gin.Context, req struct {
|
||||
Uuid int `form:"uuid" binding:"required"`
|
||||
}) (err error) {
|
||||
if !hasOprPermission(ctx, req.Uuid, eum.OperationStop) {
|
||||
return errors.New("not permission")
|
||||
}
|
||||
return logic.ProcessCtlLogic.KillProcess(req.Uuid)
|
||||
}
|
||||
|
||||
func (p *procApi) StartProcess(ctx *gin.Context, req struct {
|
||||
Uuid int `form:"uuid" binding:"required"`
|
||||
Uuid int `json:"uuid" binding:"required"`
|
||||
}) (err error) {
|
||||
if !hasOprPermission(ctx, req.Uuid, eum.OperationStart) {
|
||||
return errors.New("not permission")
|
||||
}
|
||||
prod, err := logic.ProcessCtlLogic.GetProcess(req.Uuid)
|
||||
if err != nil { // 进程不存在则创建
|
||||
proConfig, err := repository.ProcessRepository.GetProcessConfigById(req.Uuid)
|
||||
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -46,9 +47,15 @@ func (w *WsConnetInstance) Cancel() {
|
||||
var upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true // 允许所有跨域请求
|
||||
},
|
||||
}
|
||||
|
||||
func (w *wsApi) WebsocketHandle(ctx *gin.Context, req model.WebsocketHandleReq) (err error) {
|
||||
if !hasOprPermission(ctx, req.Uuid, eum.OperationTerminal) {
|
||||
return errors.New("not permission")
|
||||
}
|
||||
reqUser := getUserName(ctx)
|
||||
proc, err := logic.ProcessCtlLogic.GetProcess(req.Uuid)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/google/shlex"
|
||||
"github.com/lzh-1625/go_process_manager/config"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
@@ -116,10 +115,8 @@ func (p *processCtlLogic) getProcessInfoList(processConfiglist []model.Process)
|
||||
pi.User = process.GetUserString()
|
||||
pi.Usage.Cpu = process.performanceStatus.cpu
|
||||
pi.Usage.Mem = process.performanceStatus.mem
|
||||
if config.CF.PerformanceCapacityDisplay {
|
||||
pi.Usage.CpuCapacity = float64(runtime.NumCPU()) * 100.0
|
||||
pi.Usage.MemCapacity = float64(utils.UnwarpIgnore(mem.VirtualMemory()).Total >> 10)
|
||||
}
|
||||
pi.Usage.CpuCapacity = float64(runtime.NumCPU()) * 100.0
|
||||
pi.Usage.MemCapacity = float64(utils.UnwarpIgnore(mem.VirtualMemory()).Total >> 10)
|
||||
pi.Usage.Time = process.performanceStatus.time
|
||||
pi.TermType = process.Type()
|
||||
pi.CgroupEnable = process.Config.cgroupEnable
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package middle
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -20,24 +16,3 @@ func RolePermission(needPermission eum.Role) func(ctx *gin.Context) {
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func OprPermission(op eum.OprPermission) func(ctx *gin.Context) {
|
||||
return func(ctx *gin.Context) {
|
||||
uuid, err := strconv.Atoi(ctx.Query("uuid"))
|
||||
if err != nil {
|
||||
rErr(ctx, -1, "Invalid parameters!", nil)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
if v, ok := ctx.Get(eum.CtxRole); !ok || v.(eum.Role) <= eum.RoleAdmin {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
if !reflect.ValueOf(repository.PermissionRepository.GetPermission(ctx.GetString(eum.CtxUserName), uuid)).FieldByName(string(op)).Bool() {
|
||||
rErr(ctx, -1, "Insufficient permissions; please check your access rights!", nil)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (p *waitCond) Trigger() {
|
||||
}
|
||||
|
||||
func (p *waitCond) WaitGetMiddel(c *gin.Context) {
|
||||
reqUser := c.GetHeader("token")
|
||||
reqUser := c.GetHeader("Uuid")
|
||||
defer p.timeMap.Store(reqUser, p.ts)
|
||||
if ts, ok := p.timeMap.Load(reqUser); !ok || ts.(int64) > p.ts {
|
||||
c.Next()
|
||||
|
||||
@@ -9,7 +9,7 @@ type Process struct {
|
||||
Cwd string `gorm:"column:cwd" json:"cwd"`
|
||||
AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"`
|
||||
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"`
|
||||
PushIds string `gorm:"column:push_ids" json:"pushIds"`
|
||||
PushIds string `gorm:"column:push_ids;type:json" json:"pushIds"`
|
||||
LogReport bool `gorm:"column:log_report" json:"logReport"`
|
||||
TermType eum.TerminalType `gorm:"column:term_type" json:"termType"`
|
||||
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`
|
||||
|
||||
@@ -58,16 +58,16 @@ func routePathInit(r *gin.Engine) {
|
||||
{
|
||||
wsGroup := apiGroup.Group("/ws")
|
||||
{
|
||||
wsGroup.GET("", middle.OprPermission(eum.OperationTerminal), bind(api.WsApi.WebsocketHandle, Query))
|
||||
wsGroup.GET("", bind(api.WsApi.WebsocketHandle, Query))
|
||||
wsGroup.GET("/share", bind(api.WsApi.WebsocketShareHandle, Query))
|
||||
}
|
||||
|
||||
processGroup := apiGroup.Group("/process")
|
||||
{
|
||||
processGroup.DELETE("", middle.OprPermission(eum.OperationStop), bind(api.ProcApi.KillProcess, Query))
|
||||
processGroup.DELETE("", bind(api.ProcApi.KillProcess, Query))
|
||||
processGroup.GET("", bind(api.ProcApi.GetProcessList, None))
|
||||
processGroup.GET("/wait", middle.ProcessWaitCond.WaitGetMiddel, bind(api.ProcApi.GetProcessList, None))
|
||||
processGroup.PUT("", middle.OprPermission(eum.OperationStart), bind(api.ProcApi.StartProcess, Query))
|
||||
processGroup.PUT("", bind(api.ProcApi.StartProcess, Body))
|
||||
processGroup.PUT("/all", bind(api.ProcApi.StartAllProcess, None))
|
||||
processGroup.DELETE("/all", bind(api.ProcApi.KillAllProcess, None))
|
||||
processGroup.POST("/share", middle.RolePermission(eum.RoleAdmin), bind(api.ProcApi.ProcessCreateShare, Body))
|
||||
|
||||
Reference in New Issue
Block a user