mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-16 05:55:33 +00:00
Merge branch 'v0.3.7' of https://github.com/IceWhaleTech/CasaOS into v0.3.7
This commit is contained in:
commit
4bb81e4669
@ -11,18 +11,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
interfaces "github.com/IceWhaleTech/CasaOS-Common"
|
interfaces "github.com/IceWhaleTech/CasaOS-Common"
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/version"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/version"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type migrationTool struct{}
|
type migrationTool struct{}
|
||||||
|
|
||||||
func (u *migrationTool) IsMigrationNeeded() (bool, error) {
|
func (u *migrationTool) IsMigrationNeeded() (bool, error) {
|
||||||
|
|
||||||
majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
|
majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == version.ErrLegacyVersionNotFound {
|
if err == version.ErrLegacyVersionNotFound {
|
||||||
@ -46,22 +41,13 @@ func (u *migrationTool) IsMigrationNeeded() (bool, error) {
|
|||||||
|
|
||||||
_logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
|
_logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *migrationTool) PreMigrate() error {
|
func (u *migrationTool) PreMigrate() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *migrationTool) Migrate() error {
|
func (u *migrationTool) Migrate() error {
|
||||||
|
|
||||||
if service.MyService.System().GetSysInfo().KernelArch == "aarch64" && config.ServerInfo.USBAutoMount != "True" && strings.Contains(service.MyService.System().GetDeviceTree(), "Raspberry Pi") {
|
|
||||||
service.MyService.System().UpdateUSBAutoMount("False")
|
|
||||||
service.MyService.System().ExecUSBAutoMountShell("False")
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("update done")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -146,9 +146,6 @@ func InitRouter() *gin.Engine {
|
|||||||
// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
|
// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
|
||||||
// v1SysGroup.GET("/network", v1.GetSystemNetInfo)
|
// 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.GET("/server-info", nil)
|
||||||
v1SysGroup.PUT("/server-info", nil)
|
v1SysGroup.PUT("/server-info", nil)
|
||||||
v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)
|
v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)
|
||||||
|
@ -164,51 +164,6 @@ func PostKillCasaOS(c *gin.Context) {
|
|||||||
os.Exit(0)
|
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) {
|
func GetSystemAppsStatus(c *gin.Context) {
|
||||||
systemAppList := service.MyService.App().GetSystemAppList()
|
systemAppList := service.MyService.App().GetSystemAppList()
|
||||||
appList := []model2.MyAppList{}
|
appList := []model2.MyAppList{}
|
||||||
@ -251,7 +206,6 @@ func GetSystemAppsStatus(c *gin.Context) {
|
|||||||
// @Success 200 {string} string "ok"
|
// @Success 200 {string} string "ok"
|
||||||
// @Router /sys/hardware/info [get]
|
// @Router /sys/hardware/info [get]
|
||||||
func GetSystemHardwareInfo(c *gin.Context) {
|
func GetSystemHardwareInfo(c *gin.Context) {
|
||||||
|
|
||||||
data := make(map[string]string, 1)
|
data := make(map[string]string, 1)
|
||||||
data["drive_model"] = service.MyService.System().GetDeviceTree()
|
data["drive_model"] = service.MyService.System().GetDeviceTree()
|
||||||
c.JSON(common_err.SUCCESS,
|
c.JSON(common_err.SUCCESS,
|
||||||
@ -270,7 +224,7 @@ func GetSystemHardwareInfo(c *gin.Context) {
|
|||||||
// @Success 200 {string} string "ok"
|
// @Success 200 {string} string "ok"
|
||||||
// @Router /sys/utilization [get]
|
// @Router /sys/utilization [get]
|
||||||
func GetSystemUtilization(c *gin.Context) {
|
func GetSystemUtilization(c *gin.Context) {
|
||||||
var data = make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
cpu := service.MyService.System().GetCpuPercent()
|
cpu := service.MyService.System().GetCpuPercent()
|
||||||
num := service.MyService.System().GetCpuCoreNum()
|
num := service.MyService.System().GetCpuCoreNum()
|
||||||
cpuData := make(map[string]interface{})
|
cpuData := make(map[string]interface{})
|
||||||
@ -313,7 +267,6 @@ func GetSystemUtilization(c *gin.Context) {
|
|||||||
// @Success 200 {string} string "ok"
|
// @Success 200 {string} string "ok"
|
||||||
// @Router /sys/socket/port [get]
|
// @Router /sys/socket/port [get]
|
||||||
func GetSystemSocketPort(c *gin.Context) {
|
func GetSystemSocketPort(c *gin.Context) {
|
||||||
|
|
||||||
c.JSON(common_err.SUCCESS,
|
c.JSON(common_err.SUCCESS,
|
||||||
model.Result{
|
model.Result{
|
||||||
Success: common_err.SUCCESS,
|
Success: common_err.SUCCESS,
|
||||||
@ -336,7 +289,6 @@ func GetSystemCupInfo(c *gin.Context) {
|
|||||||
data["percent"] = cpu
|
data["percent"] = cpu
|
||||||
data["num"] = num
|
data["num"] = num
|
||||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary get mem info
|
// @Summary get mem info
|
||||||
@ -349,7 +301,6 @@ func GetSystemCupInfo(c *gin.Context) {
|
|||||||
func GetSystemMemInfo(c *gin.Context) {
|
func GetSystemMemInfo(c *gin.Context) {
|
||||||
mem := service.MyService.System().GetMemInfo()
|
mem := service.MyService.System().GetMemInfo()
|
||||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem})
|
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary get disk info
|
// @Summary get disk info
|
||||||
|
@ -30,8 +30,6 @@ type SystemService interface {
|
|||||||
UpdateAssist()
|
UpdateAssist()
|
||||||
UpSystemPort(port string)
|
UpSystemPort(port string)
|
||||||
GetTimeZone() string
|
GetTimeZone() string
|
||||||
UpdateUSBAutoMount(state string)
|
|
||||||
ExecUSBAutoMountShell(state string)
|
|
||||||
UpAppOrderFile(str, id string)
|
UpAppOrderFile(str, id string)
|
||||||
GetAppOrderFile(id string) []byte
|
GetAppOrderFile(id string) []byte
|
||||||
GetNet(physics bool) []string
|
GetNet(physics bool) []string
|
||||||
@ -53,14 +51,7 @@ type SystemService interface {
|
|||||||
GetCPUTemperature() int
|
GetCPUTemperature() int
|
||||||
GetCPUPower() map[string]string
|
GetCPUPower() map[string]string
|
||||||
}
|
}
|
||||||
type systemService struct {
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *systemService) MkdirAll(path string) (int, error) {
|
func (c *systemService) MkdirAll(path string) (int, error) {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
@ -76,8 +67,8 @@ func (c *systemService) MkdirAll(path string) (int, error) {
|
|||||||
}
|
}
|
||||||
return common_err.SERVICE_ERROR, err
|
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)
|
_, err := os.Stat(newF)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return common_err.DIR_ALREADY_EXISTS, 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
|
return common_err.SERVICE_ERROR, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) CreateFile(path string) (int, error) {
|
func (c *systemService) CreateFile(path string) (int, error) {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -104,9 +96,11 @@ func (c *systemService) CreateFile(path string) (int, error) {
|
|||||||
}
|
}
|
||||||
return common_err.SERVICE_ERROR, err
|
return common_err.SERVICE_ERROR, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) GetDeviceTree() string {
|
func (c *systemService) GetDeviceTree() string {
|
||||||
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
|
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) GetSysInfo() host.InfoStat {
|
func (c *systemService) GetSysInfo() host.InfoStat {
|
||||||
info, _ := host.Info()
|
info, _ := host.Info()
|
||||||
return *info
|
return *info
|
||||||
@ -128,9 +122,7 @@ func (c *systemService) GetNetState(name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) GetDirPathOne(path string) (m model.Path) {
|
func (c *systemService) GetDirPathOne(path string) (m model.Path) {
|
||||||
|
|
||||||
f, err := os.Stat(path)
|
f, err := os.Stat(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -175,6 +167,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {
|
|||||||
}
|
}
|
||||||
return dirs
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) GetCpuInfo() []cpu.InfoStat {
|
func (c *systemService) GetCpuInfo() []cpu.InfoStat {
|
||||||
info, _ := cpu.Info()
|
info, _ := cpu.Info()
|
||||||
return info
|
return info
|
||||||
@ -207,6 +200,7 @@ func (c *systemService) GetNetInfo() []net.IOCountersStat {
|
|||||||
parts, _ := net.IOCounters(true)
|
parts, _ := net.IOCounters(true)
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemService) GetNet(physics bool) []string {
|
func (c *systemService) GetNet(physics bool) []string {
|
||||||
t := "1"
|
t := "1"
|
||||||
if physics {
|
if physics {
|
||||||
@ -230,6 +224,7 @@ func (s *systemService) UpdateSystemVersion(version string) {
|
|||||||
//s.log.Error(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))
|
//s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) UpdateAssist() {
|
func (s *systemService) UpdateAssist() {
|
||||||
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh")
|
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh")
|
||||||
}
|
}
|
||||||
@ -238,14 +233,6 @@ func (s *systemService) GetTimeZone() string {
|
|||||||
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetTimeZone")
|
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 {
|
func (s *systemService) GetSystemConfigDebug() []string {
|
||||||
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
|
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
|
||||||
}
|
}
|
||||||
@ -253,9 +240,11 @@ func (s *systemService) GetSystemConfigDebug() []string {
|
|||||||
func (s *systemService) UpAppOrderFile(str, id string) {
|
func (s *systemService) UpAppOrderFile(str, id string) {
|
||||||
file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
|
file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) GetAppOrderFile(id string) []byte {
|
func (s *systemService) GetAppOrderFile(id string) []byte {
|
||||||
return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
|
return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) UpSystemPort(port string) {
|
func (s *systemService) UpSystemPort(port string) {
|
||||||
if len(port) > 0 && port != config.ServerInfo.HttpPort {
|
if len(port) > 0 && port != config.ServerInfo.HttpPort {
|
||||||
config.Cfg.Section("server").Key("HttpPort").SetValue(port)
|
config.Cfg.Section("server").Key("HttpPort").SetValue(port)
|
||||||
@ -263,6 +252,7 @@ func (s *systemService) UpSystemPort(port string) {
|
|||||||
}
|
}
|
||||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) GetCasaOSLogs(lineNumber int) string {
|
func (s *systemService) GetCasaOSLogs(lineNumber int) string {
|
||||||
file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
|
file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
|
||||||
config.AppInfo.LogSaveName,
|
config.AppInfo.LogSaveName,
|
||||||
@ -299,8 +289,8 @@ func GetDeviceAllIP() []string {
|
|||||||
func (s *systemService) IsServiceRunning(name string) bool {
|
func (s *systemService) IsServiceRunning(name string) bool {
|
||||||
status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
|
status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
|
||||||
return strings.TrimSpace(status) == "running"
|
return strings.TrimSpace(status) == "running"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) GetCPUTemperature() int {
|
func (s *systemService) GetCPUTemperature() int {
|
||||||
outPut := ""
|
outPut := ""
|
||||||
if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
|
if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
|
||||||
@ -318,6 +308,7 @@ func (s *systemService) GetCPUTemperature() int {
|
|||||||
}
|
}
|
||||||
return celsius
|
return celsius
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemService) GetCPUPower() map[string]string {
|
func (s *systemService) GetCPUPower() map[string]string {
|
||||||
data := make(map[string]string, 2)
|
data := make(map[string]string, 2)
|
||||||
data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
|
data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
@ -328,6 +319,7 @@ func (s *systemService) GetCPUPower() map[string]string {
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSystemService() SystemService {
|
func NewSystemService() SystemService {
|
||||||
return &systemService{}
|
return &systemService{}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user