2021-09-26 02:35:02 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2021-10-15 03:43:41 +00:00
|
|
|
"encoding/json"
|
2021-09-26 02:35:02 +00:00
|
|
|
"fmt"
|
2021-10-15 03:43:41 +00:00
|
|
|
"net/http"
|
2021-12-06 09:08:36 +00:00
|
|
|
"os"
|
2022-01-20 10:38:59 +00:00
|
|
|
"reflect"
|
2021-10-15 03:43:41 +00:00
|
|
|
"strconv"
|
2021-12-29 08:42:20 +00:00
|
|
|
"strings"
|
2021-10-15 03:43:41 +00:00
|
|
|
"time"
|
2021-12-29 08:42:20 +00:00
|
|
|
"unsafe"
|
2021-10-15 03:43:41 +00:00
|
|
|
|
2021-09-27 06:17:36 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/model"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
2021-12-29 08:42:20 +00:00
|
|
|
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
2021-12-06 09:08:36 +00:00
|
|
|
port2 "github.com/IceWhaleTech/CasaOS/pkg/utils/port"
|
2021-09-27 06:17:36 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/version"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/service"
|
|
|
|
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/types"
|
2021-09-26 02:35:02 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-05-05 05:46:55 +00:00
|
|
|
// @Summary check version
|
2021-09-26 02:35:02 +00:00
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/chackversion [get]
|
|
|
|
func CheckVersion(c *gin.Context) {
|
|
|
|
need, version := version.IsNeedUpdate()
|
|
|
|
if need {
|
|
|
|
installLog := model2.AppNotify{}
|
|
|
|
installLog.State = 0
|
|
|
|
installLog.Message = "New version " + version.Version + " is ready, ready to upgrade"
|
|
|
|
installLog.Type = types.NOTIFY_TYPE_NEED_CONFIRM
|
|
|
|
installLog.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
|
installLog.UpdatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
2021-10-29 10:37:27 +00:00
|
|
|
installLog.Name = "CasaOS System"
|
2021-09-26 02:35:02 +00:00
|
|
|
service.MyService.Notify().AddLog(installLog)
|
|
|
|
}
|
|
|
|
data := make(map[string]interface{}, 1)
|
|
|
|
data["is_need"] = need
|
|
|
|
data["version"] = version
|
|
|
|
data["current_version"] = types.CURRENTVERSION
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: data})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:46:55 +00:00
|
|
|
// @Summary check client version
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/client/version [get]
|
|
|
|
func GetClientVersion(c *gin.Context) {
|
|
|
|
need, version := version.IsClientNeedUpdate()
|
|
|
|
if need {
|
|
|
|
installLog := model2.AppNotify{}
|
|
|
|
installLog.State = 0
|
|
|
|
installLog.Message = "New version " + version.Version + " is ready, ready to upgrade"
|
|
|
|
installLog.Type = types.NOTIFY_TYPE_NEED_CONFIRM
|
|
|
|
installLog.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
|
installLog.UpdatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
|
installLog.Name = "CasaOS System"
|
|
|
|
service.MyService.Notify().AddLog(installLog)
|
|
|
|
}
|
|
|
|
data := make(map[string]interface{}, 1)
|
|
|
|
data["is_need"] = need
|
|
|
|
data["version"] = version
|
|
|
|
data["current_version"] = types.CURRENTVERSION
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: data})
|
|
|
|
}
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
// @Summary 系统信息
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/update [post]
|
|
|
|
func SystemUpdate(c *gin.Context) {
|
|
|
|
need, version := version.IsNeedUpdate()
|
|
|
|
if need {
|
|
|
|
service.MyService.System().UpdateSystemVersion(version.Version)
|
|
|
|
}
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
|
|
|
|
}
|
|
|
|
|
|
|
|
//系统配置
|
|
|
|
func GetSystemConfig(c *gin.Context) {
|
2021-10-15 03:43:41 +00:00
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: json.RawMessage(config.SystemConfigInfo.ConfigStr)})
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:27:46 +00:00
|
|
|
// @Summary get logs
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/error/logs [get]
|
|
|
|
func GetCasaOSErrorLogs(c *gin.Context) {
|
|
|
|
line, _ := strconv.Atoi(c.DefaultQuery("line", "100"))
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: service.MyService.System().GetCasaOSLogs(line)})
|
|
|
|
}
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
// @Summary 修改配置文件
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept multipart/form-data
|
2021-10-27 09:27:46 +00:00
|
|
|
// @Tags sys
|
2021-12-06 09:08:36 +00:00
|
|
|
// @Param config formData string true "config json string"
|
2021-09-26 02:35:02 +00:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
2021-10-27 09:27:46 +00:00
|
|
|
// @Router /sys/changhead [post]
|
2021-09-26 02:35:02 +00:00
|
|
|
func PostSetSystemConfig(c *gin.Context) {
|
2021-10-15 03:43:41 +00:00
|
|
|
buf := make([]byte, 1024)
|
|
|
|
n, _ := c.Request.Body.Read(buf)
|
|
|
|
|
|
|
|
service.MyService.System().UpSystemConfig(string(buf[0:n]), "")
|
2021-09-26 02:35:02 +00:00
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
2021-10-15 03:43:41 +00:00
|
|
|
Data: json.RawMessage(config.SystemConfigInfo.ConfigStr),
|
2021-09-26 02:35:02 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//系统配置
|
|
|
|
func GetSystemConfigDebug(c *gin.Context) {
|
|
|
|
|
|
|
|
array := service.MyService.System().GetSystemConfigDebug()
|
|
|
|
disk := service.MyService.ZiMa().GetDiskInfo()
|
2022-01-20 10:38:59 +00:00
|
|
|
sys := service.MyService.ZiMa().GetSysInfo()
|
|
|
|
//todo 准备sync需要显示的数据(镜像,容器)
|
|
|
|
var systemAppStatus string
|
|
|
|
images := service.MyService.Docker().IsExistImage("linuxserver/syncthing")
|
|
|
|
systemAppStatus += "Sync img: " + strconv.FormatBool(images) + "\n\t"
|
2021-09-26 02:35:02 +00:00
|
|
|
|
2022-01-20 10:38:59 +00:00
|
|
|
list := service.MyService.App().GetSystemAppList()
|
2022-05-13 10:12:26 +00:00
|
|
|
for _, v := range list {
|
2022-01-20 10:38:59 +00:00
|
|
|
systemAppStatus += v.Image + ",\n\t"
|
|
|
|
}
|
2022-01-26 02:44:55 +00:00
|
|
|
|
|
|
|
systemAppStatus += "Sync Key length: " + strconv.Itoa(len(config.SystemConfigInfo.SyncKey))
|
2022-01-20 10:38:59 +00:00
|
|
|
|
|
|
|
var bugContent string = fmt.Sprintf(`
|
|
|
|
- OS: %s
|
|
|
|
- CasaOS Version: %s
|
|
|
|
- Disk Total: %v
|
|
|
|
- Disk Used: %v
|
|
|
|
- Sync State: %s
|
|
|
|
- System Info: %s
|
|
|
|
- Browser: $Browser$
|
|
|
|
- Version: $Version$
|
|
|
|
`, sys.OS, types.CURRENTVERSION, disk.Total>>20, disk.Used>>20, systemAppStatus, array)
|
|
|
|
|
|
|
|
// array = append(array, fmt.Sprintf("disk,total:%v,used:%v,UsedPercent:%v", disk.Total>>20, disk.Used>>20, disk.UsedPercent))
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: bugContent})
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2021-10-15 03:43:41 +00:00
|
|
|
|
|
|
|
//widget配置
|
|
|
|
func GetWidgetConfig(c *gin.Context) {
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: json.RawMessage(config.SystemConfigInfo.WidgetList)})
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary 修改组件配置文件
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
2021-10-22 08:49:09 +00:00
|
|
|
// @Router /sys/widget/config [post]
|
2021-10-15 03:43:41 +00:00
|
|
|
func PostSetWidgetConfig(c *gin.Context) {
|
|
|
|
buf := make([]byte, 1024)
|
|
|
|
n, _ := c.Request.Body.Read(buf)
|
|
|
|
service.MyService.System().UpSystemConfig("", string(buf[0:n]))
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
Data: json.RawMessage(config.SystemConfigInfo.WidgetList),
|
|
|
|
})
|
|
|
|
}
|
2021-10-22 08:49:09 +00:00
|
|
|
|
2021-12-09 11:02:41 +00:00
|
|
|
// @Summary get casaos server port
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/port [get]
|
|
|
|
func GetCasaOSPort(c *gin.Context) {
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
Data: config.ServerInfo.HttpPort,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-06 09:08:36 +00:00
|
|
|
// @Summary edit casaos server port
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
2021-12-09 11:02:41 +00:00
|
|
|
// @Param port formData string true "port"
|
2021-12-06 09:08:36 +00:00
|
|
|
// @Success 200 {string} string "ok"
|
2021-12-09 11:02:41 +00:00
|
|
|
// @Router /sys/port [put]
|
2021-12-06 09:08:36 +00:00
|
|
|
func PutCasaOSPort(c *gin.Context) {
|
|
|
|
port, err := strconv.Atoi(c.PostForm("port"))
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.ERROR,
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
isAvailable := port2.IsPortAvailable(port, "tcp")
|
|
|
|
if !isAvailable {
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.PORT_IS_OCCUPIED,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.PORT_IS_OCCUPIED),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
service.MyService.System().UpSystemPort(strconv.Itoa(port))
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-22 08:49:09 +00:00
|
|
|
// @Summary 检查是否进入引导状态
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /guide/check [get]
|
|
|
|
func GetGuideCheck(c *gin.Context) {
|
|
|
|
initUser := false
|
2021-10-22 09:57:22 +00:00
|
|
|
if !config.UserInfo.Initialized {
|
2021-10-22 08:49:09 +00:00
|
|
|
initUser = true
|
|
|
|
}
|
|
|
|
data := make(map[string]interface{}, 1)
|
|
|
|
data["need_init_user"] = initUser
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
Data: data,
|
|
|
|
})
|
|
|
|
}
|
2021-12-06 09:08:36 +00:00
|
|
|
|
|
|
|
// @Summary active killing casaos
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/kill [post]
|
|
|
|
func PostKillCasaOS(c *gin.Context) {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2021-12-29 08:42:20 +00:00
|
|
|
|
2022-04-06 04:10:51 +00:00
|
|
|
// @Summary Turn off usb auto-mount
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
2022-05-13 10:12:26 +00:00
|
|
|
// @Router /sys/usb/off [put]
|
2022-04-06 04:10:51 +00:00
|
|
|
func PutSystemOffUSBAutoMount(c *gin.Context) {
|
|
|
|
service.MyService.System().UpdateUSBAutoMount("False")
|
|
|
|
service.MyService.System().ExecUSBAutoMountShell("False")
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary Turn off usb auto-mount
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/usb [get]
|
|
|
|
func GetSystemUSBAutoMount(c *gin.Context) {
|
|
|
|
state := "True"
|
|
|
|
if config.ServerInfo.USBAutoMount == "False" {
|
|
|
|
state = "False"
|
|
|
|
}
|
2022-05-13 10:12:26 +00:00
|
|
|
|
2022-04-06 04:10:51 +00:00
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
Data: state,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-13 10:12:26 +00:00
|
|
|
// @Summary get system hardware info
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/hardware/info [get]
|
|
|
|
func GetSystemHardwareInfo(c *gin.Context) {
|
|
|
|
|
|
|
|
data := make(map[string]string, 1)
|
|
|
|
data["drive_model"] = service.MyService.ZiMa().GetDeviceTree()
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
Data: data,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-06 04:10:51 +00:00
|
|
|
// @Summary Turn off usb auto-mount
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/usb/on [put]
|
|
|
|
func PutSystemOnUSBAutoMount(c *gin.Context) {
|
|
|
|
service.MyService.System().UpdateUSBAutoMount("True")
|
|
|
|
service.MyService.System().ExecUSBAutoMountShell("True")
|
|
|
|
c.JSON(http.StatusOK,
|
|
|
|
model.Result{
|
|
|
|
Success: oasis_err.SUCCESS,
|
|
|
|
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 08:42:20 +00:00
|
|
|
// @Summary system info
|
|
|
|
// @Produce application/json
|
|
|
|
// @Accept application/json
|
|
|
|
// @Tags sys
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {string} string "ok"
|
|
|
|
// @Router /sys/info [get]
|
|
|
|
func Info(c *gin.Context) {
|
2022-01-28 06:06:27 +00:00
|
|
|
var data = make(map[string]interface{}, 6)
|
2021-12-29 08:42:20 +00:00
|
|
|
|
2022-01-28 06:06:27 +00:00
|
|
|
list := service.MyService.Disk().LSBLK(true)
|
2022-01-20 10:38:59 +00:00
|
|
|
|
2022-01-21 09:50:12 +00:00
|
|
|
summary := model.Summary{}
|
|
|
|
healthy := true
|
|
|
|
findSystem := 0
|
|
|
|
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
if len(list[i].Children) > 0 && findSystem == 0 {
|
2022-01-28 06:06:27 +00:00
|
|
|
|
2022-01-21 09:50:12 +00:00
|
|
|
for j := 0; j < len(list[i].Children); j++ {
|
2022-01-28 06:06:27 +00:00
|
|
|
|
|
|
|
if len(list[i].Children[j].Children) > 0 {
|
|
|
|
for _, v := range list[i].Children[j].Children {
|
|
|
|
if v.MountPoint == "/" {
|
|
|
|
s, _ := strconv.ParseUint(v.FSSize, 10, 64)
|
|
|
|
a, _ := strconv.ParseUint(v.FSAvail, 10, 64)
|
|
|
|
u, _ := strconv.ParseUint(v.FSUsed, 10, 64)
|
|
|
|
summary.Size += s
|
|
|
|
summary.Avail += a
|
|
|
|
summary.Used += u
|
|
|
|
findSystem = 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if list[i].Children[j].MountPoint == "/" {
|
|
|
|
s, _ := strconv.ParseUint(list[i].Children[j].FSSize, 10, 64)
|
|
|
|
a, _ := strconv.ParseUint(list[i].Children[j].FSAvail, 10, 64)
|
|
|
|
u, _ := strconv.ParseUint(list[i].Children[j].FSUsed, 10, 64)
|
|
|
|
summary.Size += s
|
|
|
|
summary.Avail += a
|
|
|
|
summary.Used += u
|
|
|
|
findSystem = 1
|
|
|
|
break
|
|
|
|
}
|
2022-01-21 09:50:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 06:06:27 +00:00
|
|
|
|
2022-01-21 09:50:12 +00:00
|
|
|
}
|
|
|
|
if findSystem == 1 {
|
|
|
|
findSystem += 1
|
|
|
|
continue
|
2022-01-20 10:38:59 +00:00
|
|
|
}
|
2022-01-28 06:06:27 +00:00
|
|
|
if list[i].Tran == "sata" || list[i].Tran == "nvme" || list[i].Tran == "spi" || list[i].Tran == "sas" {
|
2022-01-20 10:38:59 +00:00
|
|
|
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
|
|
|
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
|
|
|
continue
|
|
|
|
}
|
2022-01-21 09:50:12 +00:00
|
|
|
|
|
|
|
//list[i].Temperature = temp.Temperature.Current
|
|
|
|
if !temp.SmartStatus.Passed {
|
|
|
|
healthy = false
|
|
|
|
}
|
|
|
|
if len(list[i].Children) > 0 {
|
|
|
|
for _, v := range list[i].Children {
|
|
|
|
s, _ := strconv.ParseUint(v.FSSize, 10, 64)
|
|
|
|
a, _ := strconv.ParseUint(v.FSAvail, 10, 64)
|
|
|
|
u, _ := strconv.ParseUint(v.FSUsed, 10, 64)
|
|
|
|
summary.Size += s
|
|
|
|
summary.Avail += a
|
|
|
|
summary.Used += u
|
2022-01-20 10:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 09:50:12 +00:00
|
|
|
summary.Health = healthy
|
|
|
|
data["disk"] = summary
|
2022-01-28 06:06:27 +00:00
|
|
|
usbList := service.MyService.Disk().LSBLK(false)
|
|
|
|
usb := []model.DriveUSB{}
|
|
|
|
for _, v := range usbList {
|
|
|
|
if v.Tran == "usb" {
|
|
|
|
temp := model.DriveUSB{}
|
|
|
|
temp.Model = v.Model
|
|
|
|
temp.Name = v.Name
|
|
|
|
temp.Size = v.Size
|
|
|
|
mountTemp := true
|
|
|
|
if len(v.Children) == 0 {
|
|
|
|
mountTemp = false
|
|
|
|
}
|
|
|
|
for _, child := range v.Children {
|
|
|
|
if len(child.MountPoint) > 0 {
|
|
|
|
avail, _ := strconv.ParseUint(child.FSAvail, 10, 64)
|
|
|
|
temp.Avail += avail
|
|
|
|
used, _ := strconv.ParseUint(child.FSUsed, 10, 64)
|
|
|
|
temp.Used += used
|
|
|
|
} else {
|
|
|
|
mountTemp = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp.Mount = mountTemp
|
|
|
|
usb = append(usb, temp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data["usb"] = usb
|
2021-12-29 08:42:20 +00:00
|
|
|
cpu := service.MyService.ZiMa().GetCpuPercent()
|
|
|
|
num := service.MyService.ZiMa().GetCpuCoreNum()
|
|
|
|
cpuData := make(map[string]interface{})
|
|
|
|
cpuData["percent"] = cpu
|
|
|
|
cpuData["num"] = num
|
|
|
|
data["cpu"] = cpuData
|
|
|
|
data["mem"] = service.MyService.ZiMa().GetMemInfo()
|
|
|
|
|
|
|
|
//拼装网络信息
|
|
|
|
netList := service.MyService.ZiMa().GetNetInfo()
|
|
|
|
newNet := []model.IOCountersStat{}
|
|
|
|
nets := service.MyService.ZiMa().GetNet(true)
|
|
|
|
for _, n := range netList {
|
|
|
|
for _, netCardName := range nets {
|
|
|
|
if n.Name == netCardName {
|
|
|
|
item := *(*model.IOCountersStat)(unsafe.Pointer(&n))
|
|
|
|
item.State = strings.TrimSpace(service.MyService.ZiMa().GetNetState(n.Name))
|
2022-04-06 04:10:51 +00:00
|
|
|
item.Time = time.Now().Unix()
|
2021-12-29 08:42:20 +00:00
|
|
|
newNet = append(newNet, item)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data["net"] = newNet
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
|
|
|
}
|