2024-08-07 13:52:34 +08:00
|
|
|
package v2
|
2024-07-23 14:48:37 +08:00
|
|
|
|
|
|
|
|
import (
|
2024-08-07 13:52:34 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
|
2024-07-23 14:48:37 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
|
|
|
|
|
websocket2 "github.com/1Panel-dev/1Panel/agent/utils/websocket"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2026-05-09 17:04:16 +08:00
|
|
|
"github.com/gorilla/websocket"
|
2024-07-23 14:48:37 +08:00
|
|
|
)
|
|
|
|
|
|
2026-06-02 15:11:43 +08:00
|
|
|
// @Tags Process
|
|
|
|
|
// @Summary Process ws
|
|
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
|
// @Security Timestamp
|
|
|
|
|
// @Router /process/ws [get]
|
2024-07-23 14:48:37 +08:00
|
|
|
func (b *BaseApi) ProcessWs(c *gin.Context) {
|
2026-05-09 17:04:16 +08:00
|
|
|
if !websocket.IsWebSocketUpgrade(c.Request) {
|
|
|
|
|
helper.Success(c)
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-07-23 14:48:37 +08:00
|
|
|
ws, err := wsUpgrade.Upgrade(c.Writer, c.Request, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
wsClient := websocket2.NewWsClient("processClient", ws)
|
|
|
|
|
go wsClient.Read()
|
|
|
|
|
go wsClient.Write()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Tags Process
|
|
|
|
|
// @Summary Stop Process
|
|
|
|
|
// @Param request body request.ProcessReq true "request"
|
|
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2024-07-23 14:48:37 +08:00
|
|
|
// @Router /process/stop [post]
|
|
|
|
|
// @x-panel-log {"bodyKeys":["PID"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"结束进程 [PID]","formatEN":"结束进程 [PID]"}
|
|
|
|
|
func (b *BaseApi) StopProcess(c *gin.Context) {
|
|
|
|
|
var req request.ProcessReq
|
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := processService.StopProcess(req); err != nil {
|
2024-10-29 18:42:12 +08:00
|
|
|
helper.BadRequest(c, err)
|
2024-07-23 14:48:37 +08:00
|
|
|
return
|
|
|
|
|
}
|
2025-04-18 15:44:28 +08:00
|
|
|
helper.Success(c)
|
2024-07-23 14:48:37 +08:00
|
|
|
}
|
2025-09-10 17:02:53 +08:00
|
|
|
|
|
|
|
|
// @Tags Process
|
|
|
|
|
// @Summary Get Process Info By PID
|
|
|
|
|
// @Param pid path int true "PID"
|
2025-10-30 16:50:18 +08:00
|
|
|
// @Success 200
|
2025-09-10 17:02:53 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
|
// @Security Timestamp
|
|
|
|
|
// @Router /process/{pid} [get]
|
|
|
|
|
func (b *BaseApi) GetProcessInfoByPID(c *gin.Context) {
|
|
|
|
|
pid, err := helper.GetParamInt32("pid", c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
helper.BadRequest(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
data, err := processService.GetProcessInfoByPID(pid)
|
|
|
|
|
if err != nil {
|
|
|
|
|
helper.BadRequest(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
|
}
|
2026-01-16 16:54:15 +08:00
|
|
|
|
|
|
|
|
// @Tags Process
|
|
|
|
|
// @Summary Get Listening Process
|
|
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
|
// @Security Timestamp
|
|
|
|
|
// @Router /process/listening [post]
|
|
|
|
|
func (b *BaseApi) GetListeningProcess(c *gin.Context) {
|
|
|
|
|
procs, err := processService.GetListeningProcess(c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
helper.BadRequest(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
helper.SuccessWithData(c, procs)
|
|
|
|
|
}
|