Skip to content

CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.

wip

Tiger Wangdf0f0159443b
diff --git a/route/route.go b/route/route.go
index a876849..19f2b3b 100644
--- a/route/route.go
+++ b/route/route.go
@@ -146,9 +146,6 @@ func InitRouter() *gin.Engine {
// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
// v1SysGroup.GET("/network", v1.GetSystemNetInfo)
- v1SysGroup.PUT("/usb-auto-mount", v1.PutSystemUSBAutoMount) ///sys/usb/:status
- v1SysGroup.GET("/usb-auto-mount", v1.GetSystemUSBAutoMount) ///sys/usb/status
-
v1SysGroup.GET("/server-info", nil)
v1SysGroup.PUT("/server-info", nil)
v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)
diff --git a/route/v1/system.go b/route/v1/system.go
index 95674e7..9872ee3 100644
--- a/route/v1/system.go
+++ b/route/v1/system.go
@@ -164,51 +164,6 @@ func PostKillCasaOS(c *gin.Context) {
os.Exit(0)
}
-// @Summary Turn off usb auto-mount
-// @Produce application/json
-// @Accept application/json
-// @Tags sys
-// @Security ApiKeyAuth
-// @Success 200 {string} string "ok"
-// @Router /sys/usb/off [put]
-func PutSystemUSBAutoMount(c *gin.Context) {
- js := make(map[string]string)
- c.ShouldBind(&js)
- status := js["state"]
- if status == "on" {
- service.MyService.System().UpdateUSBAutoMount("True")
- service.MyService.System().ExecUSBAutoMountShell("True")
- } else {
- service.MyService.System().UpdateUSBAutoMount("False")
- service.MyService.System().ExecUSBAutoMountShell("False")
- }
- c.JSON(common_err.SUCCESS,
- model.Result{
- Success: common_err.SUCCESS,
- Message: common_err.GetMsg(common_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"
- }
- c.JSON(common_err.SUCCESS,
- model.Result{
- Success: common_err.SUCCESS,
- Message: common_err.GetMsg(common_err.SUCCESS),
- Data: state,
- })
-}
-
func GetSystemAppsStatus(c *gin.Context) {
systemAppList := service.MyService.App().GetSystemAppList()
appList := []model2.MyAppList{}
@@ -225,12 +180,12 @@ func GetSystemAppsStatus(c *gin.Context) {
Id: v.ID,
Port: v.Labels["web"],
Index: v.Labels["index"],
- //Order: m.Labels["order"],
+ // Order: m.Labels["order"],
Image: v.Image,
Latest: false,
- //Type: m.Labels["origin"],
- //Slogan: m.Slogan,
- //Rely: m.Rely,
+ // Type: m.Labels["origin"],
+ // Slogan: m.Slogan,
+ // Rely: m.Rely,
Host: v.Labels["host"],
Protocol: v.Labels["protocol"],
})
@@ -251,7 +206,6 @@ func GetSystemAppsStatus(c *gin.Context) {
// @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.System().GetDeviceTree()
c.JSON(common_err.SUCCESS,
@@ -270,7 +224,7 @@ func GetSystemHardwareInfo(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /sys/utilization [get]
func GetSystemUtilization(c *gin.Context) {
- var data = make(map[string]interface{})
+ data := make(map[string]interface{})
cpu := service.MyService.System().GetCpuPercent()
num := service.MyService.System().GetCpuCoreNum()
cpuData := make(map[string]interface{})
@@ -282,7 +236,7 @@ func GetSystemUtilization(c *gin.Context) {
data["cpu"] = cpuData
data["mem"] = service.MyService.System().GetMemInfo()
- //拼装网络信息
+ // 拼装网络信息
netList := service.MyService.System().GetNetInfo()
newNet := []model.IOCountersStat{}
nets := service.MyService.System().GetNet(true)
@@ -313,7 +267,6 @@ func GetSystemUtilization(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /sys/socket/port [get]
func GetSystemSocketPort(c *gin.Context) {
-
c.JSON(common_err.SUCCESS,
model.Result{
Success: common_err.SUCCESS,
@@ -336,7 +289,6 @@ func GetSystemCupInfo(c *gin.Context) {
data["percent"] = cpu
data["num"] = num
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
-
}
// @Summary get mem info
@@ -349,7 +301,6 @@ func GetSystemCupInfo(c *gin.Context) {
func GetSystemMemInfo(c *gin.Context) {
mem := service.MyService.System().GetMemInfo()
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem})
-
}
// @Summary get disk info
diff --git a/service/system.go b/service/system.go
index 8717e4c..b7feef8 100644
--- a/service/system.go
+++ b/service/system.go
@@ -30,8 +30,6 @@ type SystemService interface {
UpdateAssist()
UpSystemPort(port string)
GetTimeZone() string
- UpdateUSBAutoMount(state string)
- ExecUSBAutoMountShell(state string)
UpAppOrderFile(str, id string)
GetAppOrderFile(id string) []byte
GetNet(physics bool) []string
@@ -53,14 +51,7 @@ type SystemService interface {
GetCPUTemperature() int
GetCPUPower() map[string]string
}
-type systemService struct {
-}
-
-func (s *systemService) UpdateUSBAutoMount(state string) {
- config.ServerInfo.USBAutoMount = state
- config.Cfg.Section("server").Key("USBAutoMount").SetValue(state)
- config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
-}
+type systemService struct{}
func (c *systemService) MkdirAll(path string) (int, error) {
_, err := os.Stat(path)
@@ -76,8 +67,8 @@ func (c *systemService) MkdirAll(path string) (int, error) {
}
return common_err.SERVICE_ERROR, err
}
-func (c *systemService) RenameFile(oldF, newF string) (int, error) {
+func (c *systemService) RenameFile(oldF, newF string) (int, error) {
_, err := os.Stat(newF)
if err == nil {
return common_err.DIR_ALREADY_EXISTS, nil
@@ -92,6 +83,7 @@ func (c *systemService) RenameFile(oldF, newF string) (int, error) {
}
return common_err.SERVICE_ERROR, err
}
+
func (c *systemService) CreateFile(path string) (int, error) {
_, err := os.Stat(path)
if err == nil {
@@ -104,9 +96,11 @@ func (c *systemService) CreateFile(path string) (int, error) {
}
return common_err.SERVICE_ERROR, err
}
+
func (c *systemService) GetDeviceTree() string {
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
}
+
func (c *systemService) GetSysInfo() host.InfoStat {
info, _ := host.Info()
return *info
@@ -128,9 +122,7 @@ func (c *systemService) GetNetState(name string) string {
}
func (c *systemService) GetDirPathOne(path string) (m model.Path) {
-
f, err := os.Stat(path)
-
if err != nil {
return
}
@@ -175,6 +167,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {
}
return dirs
}
+
func (c *systemService) GetCpuInfo() []cpu.InfoStat {
info, _ := cpu.Info()
return info
@@ -207,6 +200,7 @@ func (c *systemService) GetNetInfo() []net.IOCountersStat {
parts, _ := net.IOCounters(true)
return parts
}
+
func (c *systemService) GetNet(physics bool) []string {
t := "1"
if physics {
@@ -220,11 +214,12 @@ func (s *systemService) UpdateSystemVersion(version string) {
os.Remove(config.AppInfo.LogPath + "/upgrade.log")
}
file.CreateFile(config.AppInfo.LogPath + "/upgrade.log")
- //go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/LinkLeong/casaos-alpha/main/update.sh | bash")
+ // go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/LinkLeong/casaos-alpha/main/update.sh | bash")
go command2.OnlyExec("curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/update.sh | bash")
- //s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
- //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
+ // s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
+ // s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
}
+
func (s *systemService) UpdateAssist() {
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh")
}
@@ -233,14 +228,6 @@ func (s *systemService) GetTimeZone() string {
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetTimeZone")
}
-func (s *systemService) ExecUSBAutoMountShell(state string) {
- if state == "False" {
- command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Stop_Auto")
- } else {
- command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Start_Auto")
- }
-}
-
func (s *systemService) GetSystemConfigDebug() []string {
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
}
@@ -248,9 +235,11 @@ func (s *systemService) GetSystemConfigDebug() []string {
func (s *systemService) UpAppOrderFile(str, id string) {
file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
}
+
func (s *systemService) GetAppOrderFile(id string) []byte {
return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
}
+
func (s *systemService) UpSystemPort(port string) {
if len(port) > 0 && port != config.ServerInfo.HttpPort {
config.Cfg.Section("server").Key("HttpPort").SetValue(port)
@@ -258,6 +247,7 @@ func (s *systemService) UpSystemPort(port string) {
}
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
}
+
func (s *systemService) GetCasaOSLogs(lineNumber int) string {
file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
config.AppInfo.LogSaveName,
@@ -294,8 +284,8 @@ func GetDeviceAllIP() []string {
func (s *systemService) IsServiceRunning(name string) bool {
status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
return strings.TrimSpace(status) == "running"
-
}
+
func (s *systemService) GetCPUTemperature() int {
outPut := ""
if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
@@ -313,6 +303,7 @@ func (s *systemService) GetCPUTemperature() int {
}
return celsius
}
+
func (s *systemService) GetCPUPower() map[string]string {
data := make(map[string]string, 2)
data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
@@ -323,6 +314,7 @@ func (s *systemService) GetCPUPower() map[string]string {
}
return data
}
+
func NewSystemService() SystemService {
return &systemService{}
}