Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/app/api/v2/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
sshService = service.NewISSHService()
firewallService = service.NewIFirewallService()
monitorService = service.NewIMonitorService()
systemService = service.NewISystemService()

deviceService = service.NewIDeviceService()
fail2banService = service.NewIFail2BanService()
Expand Down
26 changes: 26 additions & 0 deletions agent/app/api/v2/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v2

import (
"errors"
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
"github.com/gin-gonic/gin"
)

// @Tags Host
// @Summary Check if a system component exists
// @Accept json
// @Param name query string true "Component name to check (e.g., rsync, docker)"
// @Success 200 {object} response.ComponentInfo
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/components/{name} [get]
func (b *BaseApi) CheckComponentExistence(c *gin.Context) {
name := c.Param("name")
if name == "" {
helper.BadRequest(c, errors.New("empty component name"))
return
}

info := systemService.IsComponentExist(name)
helper.SuccessWithData(c, info)
}
8 changes: 8 additions & 0 deletions agent/app/dto/response/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package response

type ComponentInfo struct {
Exists bool `json:"exists"`
Version string `json:"version"`
Path string `json:"path"`
Error string `json:"error"`
}
29 changes: 29 additions & 0 deletions agent/app/service/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package service

import (
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
"os/exec"
)

type SystemService struct{}

type ISystemService interface {
IsComponentExist(name string) response.ComponentInfo
}

func NewISystemService() ISystemService {
return &SystemService{}
}

func (s *SystemService) IsComponentExist(name string) response.ComponentInfo {
info := response.ComponentInfo{}
path, err := exec.LookPath(name)
if err != nil {
info.Exists = false
info.Error = err.Error()
return info
}
info.Exists = true
info.Path = path
return info
}
2 changes: 2 additions & 0 deletions agent/router/ro_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) {
hostRouter.POST("/disks/partition", baseApi.PartitionDisk)
hostRouter.POST("/disks/mount", baseApi.MountDisk)
hostRouter.POST("/disks/unmount", baseApi.UnmountDisk)

hostRouter.GET("/components/:name", baseApi.CheckComponentExistence)
}
}
7 changes: 7 additions & 0 deletions frontend/src/api/interface/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,11 @@ export namespace Host {
export interface DiskUmount {
mountPoint: string;
}

export interface ComponentInfo {
exists: boolean;
version: string;
path: string;
error: string;
}
}
9 changes: 9 additions & 0 deletions frontend/src/api/modules/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,12 @@ export const mountDisk = (params: Host.DiskMount) => {
export const unmountDisk = (params: Host.DiskUmount) => {
return http.post(`/hosts/disks/unmount`, params, TimeoutEnum.T_60S);
};

export const getComponentInfo = (name: string, operateNode?: string) => {
if (operateNode) {
return http.get<Host.ComponentInfo>(`/hosts/components/${name}`, {
CurrentNode: operateNode,
});
}
return http.get<Host.ComponentInfo>(`/hosts/components/${name}`);
};
Loading