Files
komari/api/client/getRemoteConfig.go
T
Akizon77 95c080d110 feat: 实现 Komari 服务器监控工具的基本功能
- 添加用户认证和权限控制
- 实现客户端管理功能,包括添加、编辑和删除客户端
- 支持客户端上传基础信息和监控报告
- 提供基本的自定义配置功能
- 实现数据库初始化和数据存储
2025-04-12 22:48:38 +08:00

72 lines
1.6 KiB
Go

package client
import (
"database/sql"
"fmt"
"komari/database"
"net/http"
"github.com/gin-gonic/gin"
)
type RemoteConfig struct {
Cpu bool `json:"cpu"`
Gpu bool `json:"gpu"`
Ram bool `json:"ram"`
Swap bool `json:"swap"`
Load bool `json:"load"`
Uptime bool `json:"uptime"`
Temperature bool `json:"temperature"`
Os bool `json:"os"`
Disk bool `json:"disk"`
Network bool `json:"network"`
Process bool `json:"process"`
Interval int `json:"interval"`
Connections bool `json:"connections"`
}
func GetRemoteConfig(c *gin.Context) {
token := c.Query("token")
db := database.GetSQLiteInstance()
clientUUID, err := database.GetClientUUIDByToken(token)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": fmt.Sprintf("%v", err)})
return
}
var config RemoteConfig
query := `
SELECT CPU, GPU, RAM, SWAP, LOAD, UPTIME, TEMP, OS, DISK, NET, PROCESS, Connections, Interval
FROM Clients
WHERE UUID = ?
`
row := db.QueryRow(query, clientUUID)
err = row.Scan(
&config.Cpu,
&config.Gpu,
&config.Ram,
&config.Swap,
&config.Load,
&config.Uptime,
&config.Temperature,
&config.Os,
&config.Disk,
&config.Network,
&config.Process,
&config.Connections,
&config.Interval,
)
if err == sql.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{"status": "error", "error": "No data found"})
return
} else if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error": fmt.Errorf("error querying client: %v", err)})
return
}
c.JSON(http.StatusOK, config)
}