mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-23 13:04:42 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94d0efdb12 | ||
|
|
1e821d1c10 | ||
|
|
2c80b53ee8 | ||
|
|
c33af66c6e | ||
|
|
9d47874ae3 |
@@ -18,7 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
## [0.3.2-pre] - 2022-06-08
|
||||
## [0.3.2.1] - 2022-06-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix the problem of application opening failure on non-80 ports ([#283](https://github.com/IceWhaleTech/CasaOS/issues/283) [#280](https://github.com/IceWhaleTech/CasaOS/issues/280))
|
||||
- Modify port failure problem ([#282](https://github.com/IceWhaleTech/CasaOS/issues/282))
|
||||
- Modify environment variables disappearing problem([#284](https://github.com/IceWhaleTech/CasaOS/issues/284))
|
||||
## [0.3.2] - 2022-06-10
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
2
UI
2
UI
Submodule UI updated: 694c60e3a1...62a6bd44d5
@@ -21,20 +21,10 @@ Handshake = socket.casaos.io
|
||||
Token =
|
||||
USBAutoMount =
|
||||
|
||||
[user]
|
||||
UserName =
|
||||
PWD =
|
||||
Email = user@gmail.com
|
||||
Description = description
|
||||
Initialized = false
|
||||
Avatar =
|
||||
NickName =
|
||||
PublicKey =
|
||||
|
||||
[system]
|
||||
ConfigStr =
|
||||
WidgetList =
|
||||
Analyse =
|
||||
|
||||
|
||||
[file]
|
||||
|
||||
13
main.go
13
main.go
@@ -100,13 +100,14 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = cron2.AddFunc("0/3 * * * * *", func() {
|
||||
err = cron2.AddFunc("0/5 * * * * *", func() {
|
||||
if service.ClientCount > 0 {
|
||||
route.SendNetINfoBySocket()
|
||||
route.SendCPUBySocket()
|
||||
route.SendMemBySocket()
|
||||
route.SendDiskBySocket()
|
||||
route.SendUSBBySocket()
|
||||
// route.SendNetINfoBySocket()
|
||||
// route.SendCPUBySocket()
|
||||
// route.SendMemBySocket()
|
||||
// route.SendDiskBySocket()
|
||||
// route.SendUSBBySocket()
|
||||
route.SendAllHardwareStatusBySocket()
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-20 16:27:12
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-08 15:40:33
|
||||
* @LastEditTime: 2022-06-09 18:18:46
|
||||
* @FilePath: /CasaOS/model/file.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -16,6 +16,8 @@ type FileOperate struct {
|
||||
TotalSize int64 `json:"total_size"`
|
||||
ProcessedSize int64 `json:"processed_size"`
|
||||
To string `json:"to" binding:"required"`
|
||||
Style string `json:"style"`
|
||||
Finished bool `json:"finished"`
|
||||
}
|
||||
|
||||
type FileItem struct {
|
||||
|
||||
@@ -186,7 +186,7 @@ func ReadFullFile(path string) []byte {
|
||||
}
|
||||
|
||||
// File copies a single file from src to dst
|
||||
func CopyFile(src, dst string) error {
|
||||
func CopyFile(src, dst, style string) error {
|
||||
var err error
|
||||
var srcfd *os.File
|
||||
var dstfd *os.File
|
||||
@@ -197,20 +197,13 @@ func CopyFile(src, dst string) error {
|
||||
if !strings.HasSuffix(dst, "/") {
|
||||
dst += "/"
|
||||
}
|
||||
dstPath := dst
|
||||
dst += lastPath
|
||||
for i := 0; Exists(dst); i++ {
|
||||
name := strings.Split(lastPath, ".")
|
||||
nameIndex := 0
|
||||
if len(name) > 2 {
|
||||
nameIndex = len(name) - 2
|
||||
if Exists(dst) {
|
||||
if style == "skip" {
|
||||
return nil
|
||||
} else {
|
||||
os.Remove(dst)
|
||||
}
|
||||
name[nameIndex] = name[nameIndex] + "(Copy)"
|
||||
dst = dstPath
|
||||
for _, v := range name {
|
||||
dst += v + "."
|
||||
}
|
||||
dst = strings.TrimSuffix(dst, ".")
|
||||
}
|
||||
|
||||
if srcfd, err = os.Open(src); err != nil {
|
||||
@@ -244,7 +237,7 @@ func GetNoDuplicateFileName(fullPath string) string {
|
||||
}
|
||||
|
||||
// Dir copies a whole directory recursively
|
||||
func CopyDir(src string, dst string) error {
|
||||
func CopyDir(src string, dst string, style string) error {
|
||||
var err error
|
||||
var fds []os.FileInfo
|
||||
var srcinfo os.FileInfo
|
||||
@@ -253,16 +246,23 @@ func CopyDir(src string, dst string) error {
|
||||
return err
|
||||
}
|
||||
if !srcinfo.IsDir() {
|
||||
if err = CopyFile(src, dst); err != nil {
|
||||
if err = CopyFile(src, dst, style); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
dstPath := dst
|
||||
//dstPath := dst
|
||||
lastPath := src[strings.LastIndex(src, "/")+1:]
|
||||
dst += "/" + lastPath
|
||||
for i := 0; Exists(dst); i++ {
|
||||
dst = dstPath + "/" + lastPath + strconv.Itoa(i+1)
|
||||
// for i := 0; Exists(dst); i++ {
|
||||
// dst = dstPath + "/" + lastPath + strconv.Itoa(i+1)
|
||||
// }
|
||||
if Exists(dst) {
|
||||
if style == "skip" {
|
||||
return nil
|
||||
} else {
|
||||
os.Remove(dst)
|
||||
}
|
||||
}
|
||||
if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
|
||||
return err
|
||||
@@ -275,11 +275,11 @@ func CopyDir(src string, dst string) error {
|
||||
dstfp := dst //path.Join(dst, fd.Name())
|
||||
|
||||
if fd.IsDir() {
|
||||
if err = CopyDir(srcfp, dstfp); err != nil {
|
||||
if err = CopyDir(srcfp, dstfp, style); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else {
|
||||
if err = CopyFile(srcfp, dstfp); err != nil {
|
||||
if err = CopyFile(srcfp, dstfp, style); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ const (
|
||||
FILE_READ_ERROR = 60002
|
||||
FILE_DELETE_ERROR = 60003
|
||||
DIR_NOT_EXISTS = 60004
|
||||
SOURCE_DES_SAME = 60005
|
||||
|
||||
//shortcuts
|
||||
SHORTCUTS_URL_ERROR = 70001
|
||||
@@ -88,6 +89,7 @@ var MsgFlags = map[int]string{
|
||||
FORMAT_ERROR: "Formatting failed, please check if the directory is occupied",
|
||||
|
||||
//
|
||||
SOURCE_DES_SAME: "Source and destination cannot be the same.",
|
||||
FILE_DOES_NOT_EXIST: "File does not exist",
|
||||
|
||||
DIR_NOT_EXISTS: "Directory does not exist",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-27 15:55:36
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-05-27 18:57:40
|
||||
* @LastEditTime: 2022-06-10 12:17:59
|
||||
* @FilePath: /CasaOS/route/periodical.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -153,3 +153,133 @@ func SendUSBBySocket() {
|
||||
}
|
||||
service.MyService.Notify().SendUSBInfoBySocket(usb)
|
||||
}
|
||||
|
||||
func SendAllHardwareStatusBySocket() {
|
||||
|
||||
netList := service.MyService.System().GetNetInfo()
|
||||
newNet := []model.IOCountersStat{}
|
||||
nets := service.MyService.System().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))
|
||||
item.Time = time.Now().Unix()
|
||||
newNet = append(newNet, item)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cpu := service.MyService.System().GetCpuPercent()
|
||||
num := service.MyService.System().GetCpuCoreNum()
|
||||
cpuData := make(map[string]interface{})
|
||||
cpuData["percent"] = cpu
|
||||
cpuData["num"] = num
|
||||
|
||||
list := service.MyService.Disk().LSBLK(true)
|
||||
|
||||
summary := model.Summary{}
|
||||
healthy := true
|
||||
findSystem := 0
|
||||
|
||||
for i := 0; i < len(list); i++ {
|
||||
if len(list[i].Children) > 0 && findSystem == 0 {
|
||||
|
||||
for j := 0; j < len(list[i].Children); j++ {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if findSystem == 1 {
|
||||
findSystem += 1
|
||||
continue
|
||||
}
|
||||
if list[i].Tran == "sata" || list[i].Tran == "nvme" || list[i].Tran == "spi" || list[i].Tran == "sas" {
|
||||
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
||||
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
||||
continue
|
||||
}
|
||||
|
||||
//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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
summary.Health = healthy
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
memInfo := service.MyService.System().GetMemInfo()
|
||||
memData := make(map[string]interface{})
|
||||
memData["total"] = memInfo.Total
|
||||
memData["available"] = memInfo.Available
|
||||
memData["used"] = memInfo.Used
|
||||
memData["free"] = memInfo.Free
|
||||
memData["usedPercent"] = memInfo.UsedPercent
|
||||
|
||||
service.MyService.Notify().SendAllHardwareStatusBySocket(summary, usb, memData, cpuData, newNet)
|
||||
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ func InitRouter() *gin.Engine {
|
||||
v1UserGroup.POST("/person/info", v1.PostUserPersonInfo)
|
||||
|
||||
v1UserGroup.GET("/shareid", v1.GetUserShareID)
|
||||
// v1UserGroup.GET("/custom/:name")
|
||||
// v1UserGroup.POST("/custom/:name")
|
||||
|
||||
}
|
||||
v1AppGroup := v1Group.Group("/app")
|
||||
@@ -112,7 +114,7 @@ func InitRouter() *gin.Engine {
|
||||
v1SysGroup := v1Group.Group("/sys")
|
||||
v1SysGroup.Use()
|
||||
{
|
||||
v1SysGroup.GET("/check", v1.CheckVersion)
|
||||
v1SysGroup.GET("/version/check", v1.GetSystemCheckVersion)
|
||||
v1SysGroup.GET("/hardware/info", v1.GetSystemHardwareInfo)
|
||||
v1SysGroup.POST("/update", v1.SystemUpdate)
|
||||
v1SysGroup.GET("/wsssh", v1.WsSsh)
|
||||
@@ -123,15 +125,14 @@ func InitRouter() *gin.Engine {
|
||||
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
|
||||
v1SysGroup.GET("/port", v1.GetCasaOSPort)
|
||||
v1SysGroup.PUT("/port", v1.PutCasaOSPort)
|
||||
v1SysGroup.POST("/kill", v1.PostKillCasaOS)
|
||||
v1SysGroup.GET("/info", v1.Info)
|
||||
v1SysGroup.PUT("/usb/off", v1.PutSystemOffUSBAutoMount)
|
||||
v1SysGroup.PUT("/usb/on", v1.PutSystemOnUSBAutoMount)
|
||||
v1SysGroup.GET("/usb", v1.GetSystemUSBAutoMount)
|
||||
v1SysGroup.GET("/cpu", v1.CupInfo)
|
||||
v1SysGroup.GET("/mem", v1.MemInfo)
|
||||
v1SysGroup.GET("/disk", v1.DiskInfo)
|
||||
v1SysGroup.GET("/network", v1.NetInfo)
|
||||
v1SysGroup.POST("/stop", v1.PostKillCasaOS)
|
||||
v1SysGroup.GET("/utilization", v1.GetSystemUtilization)
|
||||
v1SysGroup.PUT("/usb/:status", v1.PutSystemUSBAutoMount)
|
||||
v1SysGroup.GET("/usb/status", v1.GetSystemUSBAutoMount)
|
||||
v1SysGroup.GET("/cpu", v1.GetSystemCupInfo)
|
||||
v1SysGroup.GET("/mem", v1.GetSystemMemInfo)
|
||||
v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
|
||||
v1SysGroup.GET("/network", v1.GetSystemNetInfo)
|
||||
|
||||
}
|
||||
v1FileGroup := v1Group.Group("/file")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-23 17:18:56
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-08 16:31:24
|
||||
* @LastEditTime: 2022-06-09 21:48:10
|
||||
* @FilePath: /CasaOS/route/socket.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -49,7 +49,7 @@ func SocketInit(msg chan notify.Message) {
|
||||
go func(msg chan notify.Message) {
|
||||
for v := range msg {
|
||||
f.Broadcast("", v.Path, &v.Msg)
|
||||
time.Sleep(time.Millisecond * 300)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
|
||||
}(msg)
|
||||
|
||||
@@ -1184,14 +1184,24 @@ func ContainerUpdateInfo(c *gin.Context) {
|
||||
var envs model.EnvArray
|
||||
// json2.Unmarshal([]byte(appInfo.Envs), &envs)
|
||||
|
||||
for _, v := range info.Config.Env {
|
||||
showENV := info.Config.Labels["show_env"]
|
||||
showENVList := strings.Split(showENV, ",")
|
||||
showENVMap := make(map[string]string)
|
||||
showENV := info.Config.Labels["show_env"]
|
||||
showENVList := strings.Split(showENV, ",")
|
||||
showENVMap := make(map[string]string)
|
||||
if len(showENVList) > 1 {
|
||||
for _, name := range showENVList {
|
||||
showENVMap[name] = "1"
|
||||
}
|
||||
if _, ok := showENVMap[v]; ok {
|
||||
}
|
||||
for _, v := range info.Config.Env {
|
||||
if len(showENVList) > 1 {
|
||||
if _, ok := showENVMap[strings.Split(v, "=")[0]]; ok {
|
||||
temp := model.Env{
|
||||
Name: strings.Split(v, "=")[0],
|
||||
Value: strings.Split(v, "=")[1],
|
||||
}
|
||||
envs = append(envs, temp)
|
||||
}
|
||||
} else {
|
||||
temp := model.Env{
|
||||
Name: strings.Split(v, "=")[0],
|
||||
Value: strings.Split(v, "=")[1],
|
||||
|
||||
@@ -199,7 +199,6 @@ func GetDownloadFile(c *gin.Context) {
|
||||
defer ar.Close()
|
||||
commonDir := file.CommonPrefix(filepath.Separator, list...)
|
||||
|
||||
|
||||
currentPath := filepath.Base(commonDir)
|
||||
|
||||
name := "_" + currentPath
|
||||
@@ -278,17 +277,20 @@ func DirPath(c *gin.Context) {
|
||||
|
||||
//Hide the files or folders in operation
|
||||
fileQueue := make(map[string]string)
|
||||
for _, v := range service.OpStrArr {
|
||||
v, ok := service.FileQueue.Load(v)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
vt := v.(model.FileOperate)
|
||||
for _, i := range vt.Item {
|
||||
lastPath := i.From[strings.LastIndex(i.From, "/")+1:]
|
||||
fileQueue[vt.To+"/"+lastPath] = i.From
|
||||
if len(service.OpStrArr) > 0 {
|
||||
for _, v := range service.OpStrArr {
|
||||
v, ok := service.FileQueue.Load(v)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
vt := v.(model.FileOperate)
|
||||
for _, i := range vt.Item {
|
||||
lastPath := i.From[strings.LastIndex(i.From, "/")+1:]
|
||||
fileQueue[vt.To+"/"+lastPath] = i.From
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pathList := []model.Path{}
|
||||
for i := 0; i < len(info); i++ {
|
||||
if _, ok := fileQueue[info[i].Path]; !ok {
|
||||
@@ -495,6 +497,11 @@ func PostOperateFileOrDir(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
||||
return
|
||||
}
|
||||
if list.To == list.Item[0].From[:strings.LastIndex(list.Item[0].From, "/")] {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SOURCE_DES_SAME, Message: oasis_err2.GetMsg(oasis_err2.SOURCE_DES_SAME)})
|
||||
return
|
||||
}
|
||||
|
||||
var total int64 = 0
|
||||
for i := 0; i < len(list.Item); i++ {
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import (
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/check [get]
|
||||
func CheckVersion(c *gin.Context) {
|
||||
// @Router /sys/version/check [get]
|
||||
func GetSystemCheckVersion(c *gin.Context) {
|
||||
need, version := version.IsNeedUpdate()
|
||||
if need {
|
||||
installLog := model2.AppNotify{}
|
||||
@@ -47,7 +47,6 @@ func CheckVersion(c *gin.Context) {
|
||||
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
|
||||
}
|
||||
|
||||
// @Summary 系统信息
|
||||
@@ -65,7 +64,7 @@ func SystemUpdate(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
|
||||
}
|
||||
|
||||
//系统配置
|
||||
//Get system config
|
||||
func GetSystemConfig(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.ConfigStr)})
|
||||
}
|
||||
@@ -182,11 +181,14 @@ func GetCasaOSPort(c *gin.Context) {
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Param port formData string true "port"
|
||||
// @Param port json string true "port"
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/port [put]
|
||||
func PutCasaOSPort(c *gin.Context) {
|
||||
port, err := strconv.Atoi(c.PostForm("port"))
|
||||
json := make(map[string]string)
|
||||
c.BindJSON(&json)
|
||||
portStr := json["port"]
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
@@ -241,7 +243,7 @@ func GetGuideCheck(c *gin.Context) {
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/kill [post]
|
||||
// @Router /sys/restart [post]
|
||||
func PostKillCasaOS(c *gin.Context) {
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -253,9 +255,16 @@ func PostKillCasaOS(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/usb/off [put]
|
||||
func PutSystemOffUSBAutoMount(c *gin.Context) {
|
||||
service.MyService.System().UpdateUSBAutoMount("False")
|
||||
service.MyService.System().ExecUSBAutoMountShell("False")
|
||||
func PutSystemUSBAutoMount(c *gin.Context) {
|
||||
status := c.Param("status")
|
||||
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(http.StatusOK,
|
||||
model.Result{
|
||||
Success: oasis_err.SUCCESS,
|
||||
@@ -303,31 +312,14 @@ func GetSystemHardwareInfo(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Turn off usb auto-mount
|
||||
// @Summary system utilization
|
||||
// @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),
|
||||
})
|
||||
}
|
||||
|
||||
// @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) {
|
||||
// @Router /sys/utilization [get]
|
||||
func GetSystemUtilization(c *gin.Context) {
|
||||
var data = make(map[string]interface{}, 6)
|
||||
|
||||
list := service.MyService.Disk().LSBLK(true)
|
||||
@@ -471,3 +463,71 @@ func GetSystemSocketPort(c *gin.Context) {
|
||||
Data: config.ServerInfo.SocketPort,
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary get cpu info
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/cpu [get]
|
||||
func GetSystemCupInfo(c *gin.Context) {
|
||||
cpu := service.MyService.System().GetCpuPercent()
|
||||
num := service.MyService.System().GetCpuCoreNum()
|
||||
data := make(map[string]interface{})
|
||||
data["percent"] = cpu
|
||||
data["num"] = num
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
||||
|
||||
}
|
||||
|
||||
// @Summary get mem info
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/mem [get]
|
||||
func GetSystemMemInfo(c *gin.Context) {
|
||||
mem := service.MyService.System().GetMemInfo()
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: mem})
|
||||
|
||||
}
|
||||
|
||||
// @Summary get disk info
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/disk [get]
|
||||
func GetSystemDiskInfo(c *gin.Context) {
|
||||
disk := service.MyService.ZiMa().GetDiskInfo()
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: disk})
|
||||
}
|
||||
|
||||
// @Summary get Net info
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/net [get]
|
||||
func GetSystemNetInfo(c *gin.Context) {
|
||||
netList := service.MyService.System().GetNetInfo()
|
||||
|
||||
newNet := []model.IOCountersStat{}
|
||||
for _, n := range netList {
|
||||
for _, netCardName := range service.MyService.System().GetNet(true) {
|
||||
if n.Name == netCardName {
|
||||
item := *(*model.IOCountersStat)(unsafe.Pointer(&n))
|
||||
item.State = strings.TrimSpace(service.MyService.ZiMa().GetNetState(n.Name))
|
||||
item.Time = time.Now().Unix()
|
||||
newNet = append(newNet, item)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: newNet})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-09-30 18:18:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-05-27 18:07:13
|
||||
* @LastEditTime: 2022-06-13 15:20:56
|
||||
* @FilePath: /CasaOS/route/v1/zima_info.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -12,9 +12,6 @@ package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
@@ -22,77 +19,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Summary 获取cpu信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags zima
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /zima/getcpuinfo [get]
|
||||
func CupInfo(c *gin.Context) {
|
||||
//检查参数是否正确
|
||||
cpu := service.MyService.System().GetCpuPercent()
|
||||
num := service.MyService.System().GetCpuCoreNum()
|
||||
data := make(map[string]interface{})
|
||||
data["percent"] = cpu
|
||||
data["num"] = num
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
||||
|
||||
}
|
||||
|
||||
// @Summary 获取内存信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags zima
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /zima/getmeminfo [get]
|
||||
func MemInfo(c *gin.Context) {
|
||||
|
||||
//检查参数是否正确
|
||||
mem := service.MyService.System().GetMemInfo()
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: mem})
|
||||
|
||||
}
|
||||
|
||||
// @Summary 获取硬盘信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags zima
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /zima/getdiskinfo [get]
|
||||
func DiskInfo(c *gin.Context) {
|
||||
disk := service.MyService.ZiMa().GetDiskInfo()
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: disk})
|
||||
}
|
||||
|
||||
// @Summary 获取网络信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags zima
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /zima/getnetinfo [get]
|
||||
func NetInfo(c *gin.Context) {
|
||||
netList := service.MyService.System().GetNetInfo()
|
||||
|
||||
newNet := []model.IOCountersStat{}
|
||||
for _, n := range netList {
|
||||
for _, netCardName := range service.MyService.System().GetNet(true) {
|
||||
if n.Name == netCardName {
|
||||
item := *(*model.IOCountersStat)(unsafe.Pointer(&n))
|
||||
item.State = strings.TrimSpace(service.MyService.ZiMa().GetNetState(n.Name))
|
||||
item.Time = time.Now().Unix()
|
||||
newNet = append(newNet, item)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: newNet})
|
||||
}
|
||||
|
||||
// @Summary 获取信息系统信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
|
||||
@@ -67,7 +67,7 @@ func (d *diskService) SmartCTL(path string) model.SmartctlA {
|
||||
loger.Error("Failed to unmarshal json", zap.Any("err", err))
|
||||
}
|
||||
if !reflect.DeepEqual(m, model.SmartctlA{}) {
|
||||
Cache.Add(key, m, time.Second*10)
|
||||
Cache.Add(key, m, time.Hour*24)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -438,13 +438,14 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi
|
||||
|
||||
var envArr []string
|
||||
var showENV []string
|
||||
showENV = append(showENV, "casaos")
|
||||
for _, e := range m.Envs {
|
||||
showENV = append(showENV, e.Name)
|
||||
if strings.HasPrefix(e.Value, "$") {
|
||||
envArr = append(envArr, e.Name+"="+env_helper.ReplaceDefaultENV(e.Value, MyService.System().GetTimeZone()))
|
||||
continue
|
||||
}
|
||||
if len(e.Value) > 0 {
|
||||
showENV = append(showENV, e.Name)
|
||||
if e.Value == "port_map" {
|
||||
envArr = append(envArr, e.Name+"="+m.PortMap)
|
||||
continue
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-12-20 14:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-08 15:46:36
|
||||
* @LastEditTime: 2022-06-09 18:15:54
|
||||
* @FilePath: /CasaOS/service/file.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var FileQueue sync.Map
|
||||
@@ -87,26 +89,37 @@ func FileOperate(k string) {
|
||||
if temp.ProcessedSize > 0 {
|
||||
return
|
||||
}
|
||||
for _, v := range temp.Item {
|
||||
for i := 0; i < len(temp.Item); i++ {
|
||||
v := temp.Item[i]
|
||||
if temp.Type == "move" {
|
||||
lastPath := v.From[strings.LastIndex(v.From, "/")+1:]
|
||||
|
||||
if !file.CheckNotExist(temp.To + "/" + lastPath) {
|
||||
continue
|
||||
if temp.Style == "skip" {
|
||||
temp.Item[i].Finished = true
|
||||
continue
|
||||
} else {
|
||||
os.Remove(temp.To + "/" + lastPath)
|
||||
}
|
||||
}
|
||||
|
||||
err := os.Rename(v.From, temp.To+"/"+lastPath)
|
||||
if err != nil {
|
||||
loger.Debug("file move error", zap.Any("err", err))
|
||||
continue
|
||||
}
|
||||
} else if temp.Type == "copy" {
|
||||
err := file.CopyDir(v.From, temp.To)
|
||||
err := file.CopyDir(v.From, temp.To, temp.Style)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
temp.Finished = true
|
||||
FileQueue.Store(k, temp)
|
||||
}
|
||||
|
||||
func ExecOpFile() {
|
||||
|
||||
@@ -37,12 +37,39 @@ type NotifyServer interface {
|
||||
SendPersonStatusBySocket(status notify.Person)
|
||||
SendFileOperateNotify(nowSend bool)
|
||||
SendInstallAppBySocket(app notify.Application)
|
||||
SendAllHardwareStatusBySocket(disk model2.Summary, list []model2.DriveUSB, mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat)
|
||||
}
|
||||
|
||||
type notifyServer struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (i *notifyServer) SendAllHardwareStatusBySocket(disk model2.Summary, list []model2.DriveUSB, mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat) {
|
||||
|
||||
body := make(map[string]interface{})
|
||||
body["sys_disk"] = disk
|
||||
|
||||
body["sys_usb"] = list
|
||||
|
||||
body["sys_mem"] = mem
|
||||
|
||||
body["sys_cpu"] = cpu
|
||||
|
||||
body["sys_net"] = netList
|
||||
|
||||
msg := gosf.Message{}
|
||||
msg.Body = body
|
||||
msg.Success = true
|
||||
msg.Text = "sys_hardware_status"
|
||||
|
||||
notify := notify.Message{}
|
||||
notify.Path = "sys_hardware_status"
|
||||
notify.Msg = msg
|
||||
|
||||
NotifyMsg <- notify
|
||||
|
||||
}
|
||||
|
||||
// Send periodic broadcast messages
|
||||
func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
||||
|
||||
@@ -94,7 +121,7 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
||||
task.Status = "PROCESSING"
|
||||
}
|
||||
|
||||
if temp.ProcessedSize >= temp.TotalSize {
|
||||
if temp.Finished || temp.ProcessedSize >= temp.TotalSize {
|
||||
|
||||
task.Finished = true
|
||||
task.Status = "FINISHED"
|
||||
@@ -160,7 +187,8 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
||||
} else {
|
||||
task.Status = "PROCESSING"
|
||||
}
|
||||
if temp.ProcessedSize >= temp.TotalSize {
|
||||
if temp.Finished || temp.ProcessedSize >= temp.TotalSize {
|
||||
|
||||
task.Finished = true
|
||||
task.Status = "FINISHED"
|
||||
FileQueue.Delete(v)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-02-17 18:53:22
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-02 20:40:36
|
||||
* @LastEditTime: 2022-06-13 19:24:15
|
||||
* @FilePath: /CasaOS/types/system.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -10,6 +10,6 @@
|
||||
*/
|
||||
package types
|
||||
|
||||
const CURRENTVERSION = "0.3.2"
|
||||
const CURRENTVERSION = "0.3.2.1"
|
||||
|
||||
const BODY = "<li></li>"
|
||||
const BODY = ""
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<title>
|
||||
CasaOS
|
||||
</title>
|
||||
<link href="/ui/css/10.32be8789.css" rel="prefetch"><link href="/ui/css/11.dc77452d.css" rel="prefetch"><link href="/ui/css/16.1f93b660.css" rel="prefetch"><link href="/ui/css/17.046fd3d8.css" rel="prefetch"><link href="/ui/css/8.eb842258.css" rel="prefetch"><link href="/ui/css/9.e1b97a16.css" rel="prefetch"><link href="/ui/js/0.js" rel="prefetch"><link href="/ui/js/1.js" rel="prefetch"><link href="/ui/js/10.js" rel="prefetch"><link href="/ui/js/11.js" rel="prefetch"><link href="/ui/js/12.js" rel="prefetch"><link href="/ui/js/13.js" rel="prefetch"><link href="/ui/js/14.js" rel="prefetch"><link href="/ui/js/15.js" rel="prefetch"><link href="/ui/js/16.js" rel="prefetch"><link href="/ui/js/17.js" rel="prefetch"><link href="/ui/js/18.js" rel="prefetch"><link href="/ui/js/2.js" rel="prefetch"><link href="/ui/js/3.js" rel="prefetch"><link href="/ui/js/4.js" rel="prefetch"><link href="/ui/js/5.js" rel="prefetch"><link href="/ui/js/6.js" rel="prefetch"><link href="/ui/js/7.js" rel="prefetch"><link href="/ui/js/8.js" rel="prefetch"><link href="/ui/js/9.js" rel="prefetch"><link href="/ui/css/app.87502768.css" rel="preload" as="style"><link href="/ui/css/vendors~app.a048753d.css" rel="preload" as="style"><link href="/ui/js/app.js" rel="preload" as="script"><link href="/ui/js/vendors~app.js" rel="preload" as="script"><link href="/ui/css/vendors~app.a048753d.css" rel="stylesheet"><link href="/ui/css/app.87502768.css" rel="stylesheet"></head>
|
||||
<link href="/ui/css/10.d72d6157.css" rel="prefetch"><link href="/ui/css/11.f8326b27.css" rel="prefetch"><link href="/ui/css/16.a16d5119.css" rel="prefetch"><link href="/ui/css/17.cf8c898a.css" rel="prefetch"><link href="/ui/css/8.11ecc7a4.css" rel="prefetch"><link href="/ui/css/9.e57f27f9.css" rel="prefetch"><link href="/ui/js/0.js" rel="prefetch"><link href="/ui/js/1.js" rel="prefetch"><link href="/ui/js/10.js" rel="prefetch"><link href="/ui/js/11.js" rel="prefetch"><link href="/ui/js/12.js" rel="prefetch"><link href="/ui/js/13.js" rel="prefetch"><link href="/ui/js/14.js" rel="prefetch"><link href="/ui/js/15.js" rel="prefetch"><link href="/ui/js/16.js" rel="prefetch"><link href="/ui/js/17.js" rel="prefetch"><link href="/ui/js/18.js" rel="prefetch"><link href="/ui/js/2.js" rel="prefetch"><link href="/ui/js/3.js" rel="prefetch"><link href="/ui/js/4.js" rel="prefetch"><link href="/ui/js/5.js" rel="prefetch"><link href="/ui/js/6.js" rel="prefetch"><link href="/ui/js/7.js" rel="prefetch"><link href="/ui/js/8.js" rel="prefetch"><link href="/ui/js/9.js" rel="prefetch"><link href="/ui/css/app.4293eecd.css" rel="preload" as="style"><link href="/ui/css/vendors~app.8a2c28d7.css" rel="preload" as="style"><link href="/ui/js/app.js" rel="preload" as="script"><link href="/ui/js/vendors~app.js" rel="preload" as="script"><link href="/ui/css/vendors~app.8a2c28d7.css" rel="stylesheet"><link href="/ui/css/app.4293eecd.css" rel="stylesheet"></head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
|
||||
10
web/js/11.js
10
web/js/11.js
File diff suppressed because one or more lines are too long
10
web/js/12.js
10
web/js/12.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
22
web/js/3.js
22
web/js/3.js
File diff suppressed because one or more lines are too long
104
web/js/4.js
104
web/js/4.js
File diff suppressed because one or more lines are too long
374
web/js/8.js
374
web/js/8.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user