Compare commits

..

7 Commits

Author SHA1 Message Date
link
493dc5c032 Merge pull request #89 from IceWhaleTech/dev
Compatible with more types of disks
2022-01-28 14:06:58 +08:00
link
9a73bc2a18 Compatible with more types of disks
Add usb display
2022-01-28 14:06:27 +08:00
link
55a9acd9f6 Merge pull request #85 from IceWhaleTech/dev
Apply multilingual support
2022-01-26 18:51:14 +08:00
link
d060968b7a Apply multilingual support 2022-01-26 18:50:34 +08:00
link
88a7f53130 Merge pull request #82 from IceWhaleTech/dev
Dev
2022-01-26 11:33:33 +08:00
link
26e5b18a5d Merge branch 'dev' of ssh://github.com/IceWhaleTech/CasaOS into dev 2022-01-26 11:33:02 +08:00
link
011ace96f6 update ui 2022-01-26 11:32:57 +08:00
21 changed files with 2541 additions and 281 deletions

2
UI

Submodule UI updated: 8146d1f4cb...25c7eec90d

View File

@@ -20,6 +20,7 @@ type LSBLKModel struct {
Format string `json:"format"` Format string `json:"format"`
Health string `json:"health"` Health string `json:"health"`
HotPlug bool `json:"hotplug"` HotPlug bool `json:"hotplug"`
UUID string `json:"uuid"`
FSUsed string `json:"fsused"` FSUsed string `json:"fsused"`
Temperature int `json:"temperature"` Temperature int `json:"temperature"`
Tran string `json:"tran"` Tran string `json:"tran"`
@@ -47,6 +48,15 @@ type Drive struct {
Path string `json:"path"` Path string `json:"path"`
} }
type DriveUSB struct {
Name string `json:"name"`
Size uint64 `json:"size"`
Used uint64 `json:"use"`
Model string `json:"model"`
Mount bool `json:"mount"` //是否完全挂载
Avail uint64 `json:"avail"` //可用空间
}
type Storage struct { type Storage struct {
Name string `json:"name"` Name string `json:"name"`
MountPoint string `json:"mountpoint"` MountPoint string `json:"mountpoint"`

View File

@@ -101,7 +101,6 @@ func ExecSmartCTLByPath(path string) []byte {
output, err := exec.CommandContext(ctx, "smartctl", "-a", path, "-j").Output() output, err := exec.CommandContext(ctx, "smartctl", "-a", path, "-j").Output()
if err != nil { if err != nil {
fmt.Println("smartctl", err) fmt.Println("smartctl", err)
fmt.Println("output", string(output))
return nil return nil
} }
return output return output

View File

@@ -35,7 +35,7 @@ func installSyncthing(appId string) {
m := model.CustomizationPostData{} m := model.CustomizationPostData{}
var dockerImage string var dockerImage string
var dockerImageVersion string var dockerImageVersion string
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system") appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system", "us_en")
dockerImage = appInfo.Image dockerImage = appInfo.Image
dockerImageVersion = appInfo.ImageVersion dockerImageVersion = appInfo.ImageVersion
@@ -195,18 +195,18 @@ func CheckSerialDiskMount() {
// check mount point // check mount point
dbList := service.MyService.Disk().GetSerialAll() dbList := service.MyService.Disk().GetSerialAll()
list := service.MyService.Disk().LSBLK() list := service.MyService.Disk().LSBLK(true)
mountPoint := make(map[string]string, len(dbList)) mountPoint := make(map[string]string, len(dbList))
//remount //remount
for _, v := range dbList { for _, v := range dbList {
mountPoint[v.Path] = v.MountPoint mountPoint[v.UUID] = v.MountPoint
} }
for _, v := range list { for _, v := range list {
command.ExecEnabledSMART(v.Path) command.ExecEnabledSMART(v.Path)
if v.Children != nil { if v.Children != nil {
for _, h := range v.Children { for _, h := range v.Children {
if len(h.MountPoint) == 0 && len(v.Children) == 1 && h.FsType == "ext4" { if len(h.MountPoint) == 0 && len(v.Children) == 1 && h.FsType == "ext4" {
if m, ok := mountPoint[h.Path]; ok { if m, ok := mountPoint[h.UUID]; ok {
//mount point check //mount point check
volume := m volume := m
if !file.CheckNotExist(m) { if !file.CheckNotExist(m) {
@@ -217,7 +217,8 @@ func CheckSerialDiskMount() {
service.MyService.Disk().MountDisk(h.Path, volume) service.MyService.Disk().MountDisk(h.Path, volume)
if volume != m { if volume != m {
ms := model2.SerialDisk{} ms := model2.SerialDisk{}
ms.Serial = v.Serial ms.UUID = v.UUID
ms.MountPoint = volume
service.MyService.Disk().UpdateMountPoint(ms) service.MyService.Disk().UpdateMountPoint(ms)
} }

View File

@@ -241,6 +241,7 @@ func InitRouter() *gin.Engine {
//删除分区 //删除分区
v1DiskGroup.DELETE("/delpart", v1.RemovePartition) v1DiskGroup.DELETE("/delpart", v1.RemovePartition)
v1DiskGroup.GET("/usb", v1.GetUSBList)
} }
v1ShareGroup := v1Group.Group("/share") v1ShareGroup := v1Group.Group("/share")

View File

@@ -35,7 +35,8 @@ func AppList(c *gin.Context) {
t := c.DefaultQuery("type", "rank") t := c.DefaultQuery("type", "rank")
categoryId := c.DefaultQuery("category_id", "0") categoryId := c.DefaultQuery("category_id", "0")
key := c.DefaultQuery("key", "") key := c.DefaultQuery("key", "")
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key) language := c.GetHeader("Language")
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key, language)
// for i := 0; i < len(recommend); i++ { // for i := 0; i < len(recommend); i++ {
// ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion) // ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion)
// if ct != nil { // if ct != nil {
@@ -137,7 +138,8 @@ func AppUsageList(c *gin.Context) {
func AppInfo(c *gin.Context) { func AppInfo(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
info := service.MyService.OAPI().GetServerAppInfo(id, "") language := c.GetHeader("Language")
info := service.MyService.OAPI().GetServerAppInfo(id, "", language)
if info.NetworkModel != "host" { if info.NetworkModel != "host" {
for i := 0; i < len(info.Ports); i++ { for i := 0; i < len(info.Ports); i++ {
if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) { if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) {

View File

@@ -27,7 +27,7 @@ var diskMap = make(map[string]string)
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /disk/list [get] // @Router /disk/list [get]
func GetDiskList(c *gin.Context) { func GetDiskList(c *gin.Context) {
list := service.MyService.Disk().LSBLK() list := service.MyService.Disk().LSBLK(false)
dbList := service.MyService.Disk().GetSerialAll() dbList := service.MyService.Disk().GetSerialAll()
part := make(map[string]int64, len(dbList)) part := make(map[string]int64, len(dbList))
for _, v := range dbList { for _, v := range dbList {
@@ -53,28 +53,56 @@ func GetDiskList(c *gin.Context) {
if len(list[i].Children) > 0 && findSystem == 0 { if len(list[i].Children) > 0 && findSystem == 0 {
for j := 0; j < len(list[i].Children); j++ { for j := 0; j < len(list[i].Children); j++ {
if list[i].Children[j].MountPoint == "/" { if len(list[i].Children[j].Children) > 0 {
stor := model.Storage{} for _, v := range list[i].Children[j].Children {
stor.Name = "System" if v.MountPoint == "/" {
stor.MountPoint = list[i].Children[j].MountPoint stor := model.Storage{}
stor.Size = list[i].Children[j].FSSize stor.Name = "System"
stor.Avail = list[i].Children[j].FSAvail stor.MountPoint = v.MountPoint
stor.Path = list[i].Children[j].Path stor.Size = v.FSSize
stor.Type = list[i].Children[j].FsType stor.Avail = v.FSAvail
stor.DriveName = "System" stor.Path = v.Path
disk.Model = "System" stor.Type = v.FsType
if strings.Contains(list[i].Children[j].SubSystems, "mmc") { stor.DriveName = "System"
disk.DiskType = "MMC" disk.Model = "System"
} else if strings.Contains(list[i].Children[j].SubSystems, "usb") { if strings.Contains(v.SubSystems, "mmc") {
disk.DiskType = "USB" disk.DiskType = "MMC"
} } else if strings.Contains(v.SubSystems, "usb") {
disk.Health = "true" disk.DiskType = "USB"
}
disk.Health = "true"
disks = append(disks, disk) disks = append(disks, disk)
storage = append(storage, stor) storage = append(storage, stor)
findSystem = 1 findSystem = 1
break break
}
}
} else {
if list[i].Children[j].MountPoint == "/" {
stor := model.Storage{}
stor.Name = "System"
stor.MountPoint = list[i].Children[j].MountPoint
stor.Size = list[i].Children[j].FSSize
stor.Avail = list[i].Children[j].FSAvail
stor.Path = list[i].Children[j].Path
stor.Type = list[i].Children[j].FsType
stor.DriveName = "System"
disk.Model = "System"
if strings.Contains(list[i].Children[j].SubSystems, "mmc") {
disk.DiskType = "MMC"
} else if strings.Contains(list[i].Children[j].SubSystems, "usb") {
disk.DiskType = "USB"
}
disk.Health = "true"
disks = append(disks, disk)
storage = append(storage, stor)
findSystem = 1
break
}
} }
} }
} }
if findSystem == 1 { if findSystem == 1 {
@@ -82,10 +110,10 @@ func GetDiskList(c *gin.Context) {
continue continue
} }
if list[i].Tran == "sata" { 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) temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) { if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue temp.SmartStatus.Passed = true
} }
if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 { if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 {
stor := model.Storage{} stor := model.Storage{}
@@ -137,7 +165,7 @@ func GetDiskList(c *gin.Context) {
// @Router /disk/lists [get] // @Router /disk/lists [get]
func GetPlugInDisks(c *gin.Context) { func GetPlugInDisks(c *gin.Context) {
list := service.MyService.Disk().LSBLK() list := service.MyService.Disk().LSBLK(true)
var result []*disk.UsageStat var result []*disk.UsageStat
for _, item := range list { for _, item := range list {
result = append(result, service.MyService.Disk().GetDiskInfoByPath(item.Path)) result = append(result, service.MyService.Disk().GetDiskInfoByPath(item.Path))
@@ -252,13 +280,12 @@ func RemovePartition(c *gin.Context) {
func AddPartition(c *gin.Context) { func AddPartition(c *gin.Context) {
name := c.PostForm("name") name := c.PostForm("name")
path := c.PostForm("path") path := c.PostForm("path")
serial := c.PostForm("serial")
format, _ := strconv.ParseBool(c.PostForm("format")) format, _ := strconv.ParseBool(c.PostForm("format"))
if len(name) == 0 || len(path) == 0 || len(serial) == 0 { if len(name) == 0 || len(path) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.INVALID_PARAMS, Message: oasis_err.GetMsg(oasis_err.INVALID_PARAMS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.INVALID_PARAMS, Message: oasis_err.GetMsg(oasis_err.INVALID_PARAMS)})
return return
} }
if _, ok := diskMap[serial]; ok { if _, ok := diskMap[path]; ok {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.DISK_BUSYING, Message: oasis_err.GetMsg(oasis_err.DISK_BUSYING)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.DISK_BUSYING, Message: oasis_err.GetMsg(oasis_err.DISK_BUSYING)})
return return
} }
@@ -267,36 +294,49 @@ func AddPartition(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.NAME_NOT_AVAILABLE, Message: oasis_err.GetMsg(oasis_err.NAME_NOT_AVAILABLE)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.NAME_NOT_AVAILABLE, Message: oasis_err.GetMsg(oasis_err.NAME_NOT_AVAILABLE)})
return return
} }
diskMap[serial] = "busying" diskMap[path] = "busying"
currentDisk := service.MyService.Disk().GetDiskInfo(path) currentDisk := service.MyService.Disk().GetDiskInfo(path)
if !format { if !format {
if len(currentDisk.Children) != 1 || !(len(currentDisk.Children) > 0 && currentDisk.Children[0].FsType == "ext4") { if len(currentDisk.Children) != 1 || !(len(currentDisk.Children) > 0 && currentDisk.Children[0].FsType == "ext4") {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.DISK_NEEDS_FORMAT, Message: oasis_err.GetMsg(oasis_err.DISK_NEEDS_FORMAT)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.DISK_NEEDS_FORMAT, Message: oasis_err.GetMsg(oasis_err.DISK_NEEDS_FORMAT)})
delete(diskMap, serial) delete(diskMap, path)
return return
} }
} else { } else {
service.MyService.Disk().AddPartition(path) service.MyService.Disk().AddPartition(path)
} }
formatBool := true
for formatBool {
currentDisk = service.MyService.Disk().GetDiskInfo(path)
if len(currentDisk.Children) != 1 {
formatBool = false
break
}
time.Sleep(time.Second)
}
currentDisk = service.MyService.Disk().GetDiskInfo(path)
if len(currentDisk.Children) != 1 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.DISK_NEEDS_FORMAT, Message: oasis_err.GetMsg(oasis_err.DISK_NEEDS_FORMAT)})
return
}
mountPath := "/DATA/" + name mountPath := "/DATA/" + name
service.MyService.Disk().MountDisk(path, mountPath)
m := model2.SerialDisk{} m := model2.SerialDisk{}
m.MountPoint = mountPath m.MountPoint = mountPath
m.Path = path + "1" m.Path = currentDisk.Children[0].Path
m.Serial = serial m.UUID = currentDisk.Children[0].UUID
m.State = 0 m.State = 0
m.CreatedAt = time.Now().Unix() m.CreatedAt = time.Now().Unix()
service.MyService.Disk().SaveMountPoint(m) service.MyService.Disk().SaveMountPoint(m)
//mount dir //mount dir
service.MyService.Disk().MountDisk(path+"1", mountPath) service.MyService.Disk().MountDisk(currentDisk.Children[0].Path, mountPath)
service.MyService.Disk().RemoveLSBLKCache() service.MyService.Disk().RemoveLSBLKCache()
delete(diskMap, serial) delete(diskMap, path)
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
} }
@@ -334,7 +374,7 @@ func PostMountDisk(c *gin.Context) {
m := model2.SerialDisk{} m := model2.SerialDisk{}
m.MountPoint = mountPath m.MountPoint = mountPath
m.Path = path m.Path = path
m.Serial = serial m.UUID = serial
m.State = 0 m.State = 0
//service.MyService.Disk().SaveMountPoint(m) //service.MyService.Disk().SaveMountPoint(m)
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
@@ -401,7 +441,7 @@ func DeleteDisk(c *gin.Context) {
func GetDiskCheck(c *gin.Context) { func GetDiskCheck(c *gin.Context) {
dbList := service.MyService.Disk().GetSerialAll() dbList := service.MyService.Disk().GetSerialAll()
list := service.MyService.Disk().LSBLK() list := service.MyService.Disk().LSBLK(true)
mapList := make(map[string]string) mapList := make(map[string]string)
@@ -410,7 +450,7 @@ func GetDiskCheck(c *gin.Context) {
} }
for _, v := range dbList { for _, v := range dbList {
if _, ok := mapList[v.Serial]; !ok { if _, ok := mapList[v.UUID]; !ok {
//disk undefind //disk undefind
c.JSON(http.StatusOK, model.Result{Success: oasis_err.ERROR, Message: oasis_err.GetMsg(oasis_err.ERROR), Data: "disk undefind"}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.ERROR, Message: oasis_err.GetMsg(oasis_err.ERROR), Data: "disk undefind"})
return return
@@ -419,3 +459,38 @@ func GetDiskCheck(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
} }
// @Summary check mount point
// @Produce application/json
// @Accept application/json
// @Tags disk
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /disk/usb [get]
func GetUSBList(c *gin.Context) {
list := service.MyService.Disk().LSBLK(false)
data := []model.DriveUSB{}
for _, v := range list {
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
} else {
mountTemp = false
}
}
temp.Mount = mountTemp
data = append(data, temp)
}
}
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: data})
}

View File

@@ -145,6 +145,7 @@ func SpeedPush(c *gin.Context) {
// @Router /app/install/{id} [post] // @Router /app/install/{id} [post]
func InstallApp(c *gin.Context) { func InstallApp(c *gin.Context) {
appId := c.Param("id") appId := c.Param("id")
language := c.GetHeader("Language")
var appInfo model.ServerAppList var appInfo model.ServerAppList
m := model.CustomizationPostData{} m := model.CustomizationPostData{}
c.BindJSON(&m) c.BindJSON(&m)
@@ -174,7 +175,7 @@ func InstallApp(c *gin.Context) {
dockerImageVersion = "latest" dockerImageVersion = "latest"
} }
if m.Origin != "custom" { if m.Origin != "custom" {
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "") appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "", language)
} else { } else {

View File

@@ -259,9 +259,9 @@ func PostKillCasaOS(c *gin.Context) {
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /sys/info [get] // @Router /sys/info [get]
func Info(c *gin.Context) { func Info(c *gin.Context) {
var data = make(map[string]interface{}, 5) var data = make(map[string]interface{}, 6)
list := service.MyService.Disk().LSBLK() list := service.MyService.Disk().LSBLK(true)
summary := model.Summary{} summary := model.Summary{}
healthy := true healthy := true
@@ -269,24 +269,42 @@ func Info(c *gin.Context) {
for i := 0; i < len(list); i++ { for i := 0; i < len(list); i++ {
if len(list[i].Children) > 0 && findSystem == 0 { if len(list[i].Children) > 0 && findSystem == 0 {
for j := 0; j < len(list[i].Children); j++ { for j := 0; j < len(list[i].Children); j++ {
if list[i].Children[j].MountPoint == "/" {
s, _ := strconv.ParseUint(list[i].Children[j].FSSize, 10, 64) if len(list[i].Children[j].Children) > 0 {
a, _ := strconv.ParseUint(list[i].Children[j].FSAvail, 10, 64) for _, v := range list[i].Children[j].Children {
u, _ := strconv.ParseUint(list[i].Children[j].FSUsed, 10, 64) if v.MountPoint == "/" {
summary.Size += s s, _ := strconv.ParseUint(v.FSSize, 10, 64)
summary.Avail += a a, _ := strconv.ParseUint(v.FSAvail, 10, 64)
summary.Used += u u, _ := strconv.ParseUint(v.FSUsed, 10, 64)
findSystem = 1 summary.Size += s
break 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 { if findSystem == 1 {
findSystem += 1 findSystem += 1
continue continue
} }
if list[i].Tran == "sata" { 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) temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) { if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue continue
@@ -312,6 +330,33 @@ func Info(c *gin.Context) {
summary.Health = healthy summary.Health = healthy
data["disk"] = summary data["disk"] = summary
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
cpu := service.MyService.ZiMa().GetCpuPercent() cpu := service.MyService.ZiMa().GetCpuPercent()
num := service.MyService.ZiMa().GetCpuCoreNum() num := service.MyService.ZiMa().GetCpuCoreNum()
cpuData := make(map[string]interface{}) cpuData := make(map[string]interface{})

View File

@@ -2,12 +2,13 @@ package v1
import ( import (
json2 "encoding/json" json2 "encoding/json"
"net/http"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/config"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err" oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
) )
// @Summary 登录zerotier获取token // @Summary 登录zerotier获取token
@@ -432,11 +433,17 @@ func ZeroTierDeleteNetwork(c *gin.Context) {
// @Router /zerotier/join/{id} [post] // @Router /zerotier/join/{id} [post]
func ZeroTierJoinNetwork(c *gin.Context) { func ZeroTierJoinNetwork(c *gin.Context) {
networkId := c.Param("id") networkId := c.Param("id")
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId) if len(networkId) != 16 {
if len(networkId) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return return
} }
for _, v := range networkId {
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return
}
}
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId)
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
} }
@@ -450,10 +457,19 @@ func ZeroTierJoinNetwork(c *gin.Context) {
// @Router /zerotier/leave/{id} [post] // @Router /zerotier/leave/{id} [post]
func ZeroTierLeaveNetwork(c *gin.Context) { func ZeroTierLeaveNetwork(c *gin.Context) {
networkId := c.Param("id") networkId := c.Param("id")
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
if len(networkId) == 0 { if len(networkId) != 16 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return return
} }
for _, v := range networkId {
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return
}
}
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
} }

View File

@@ -13,10 +13,10 @@ import (
) )
type CasaService interface { type CasaService interface {
GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList) GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList)
GetServerCategoryList() []model.ServerCategoryList GetServerCategoryList() []model.ServerCategoryList
GetTaskList(size int) []model2.TaskDBModel GetTaskList(size int) []model2.TaskDBModel
GetServerAppInfo(id, t string) model.ServerAppList GetServerAppInfo(id, t string, language string) model.ServerAppList
ShareAppFile(body []byte) string ShareAppFile(body []byte) string
} }
@@ -45,9 +45,9 @@ func (o *casaService) GetTaskList(size int) []model2.TaskDBModel {
return list return list
} }
func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList) { func (o *casaService) GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList) {
keyName := fmt.Sprintf("list_%s_%s_%s_%s", index, size, tp, categoryId) keyName := fmt.Sprintf("list_%s_%s_%s_%s_%s", index, size, tp, categoryId, language)
if result, ok := Cache.Get(keyName); ok { if result, ok := Cache.Get(keyName); ok {
res, ok := result.(string) res, ok := result.(string)
@@ -63,7 +63,7 @@ func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (re
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key, head) listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key+"&language="+language, head)
json2.Unmarshal([]byte(gjson.Get(listS, "data.list").String()), &list) json2.Unmarshal([]byte(gjson.Get(listS, "data.list").String()), &list)
json2.Unmarshal([]byte(gjson.Get(listS, "data.recommend").String()), &recommend) json2.Unmarshal([]byte(gjson.Get(listS, "data.recommend").String()), &recommend)
@@ -88,12 +88,12 @@ func (o *casaService) GetServerCategoryList() []model.ServerCategoryList {
return list return list
} }
func (o *casaService) GetServerAppInfo(id, t string) model.ServerAppList { func (o *casaService) GetServerAppInfo(id, t string, language string) model.ServerAppList {
head := make(map[string]string) head := make(map[string]string)
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t, head) infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t+"&language="+language, head)
info := model.ServerAppList{} info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info) json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)

View File

@@ -20,7 +20,7 @@ import (
type DiskService interface { type DiskService interface {
GetPlugInDisk() []string GetPlugInDisk() []string
LSBLK() []model.LSBLKModel LSBLK(isUseCache bool) []model.LSBLKModel
SmartCTL(path string) model.SmartctlA SmartCTL(path string) model.SmartctlA
FormatDisk(path, format string) []string FormatDisk(path, format string) []string
UmountPointAndRemoveDir(path string) []string UmountPointAndRemoveDir(path string) []string
@@ -119,11 +119,11 @@ func (d *diskService) GetDiskInfoByPath(path string) *disk.UsageStat {
} }
//get disk details //get disk details
func (d *diskService) LSBLK() []model.LSBLKModel { func (d *diskService) LSBLK(isUseCache bool) []model.LSBLKModel {
key := "system_lsblk" key := "system_lsblk"
var n []model.LSBLKModel var n []model.LSBLKModel
if result, ok := Cache.Get(key); ok { if result, ok := Cache.Get(key); ok && isUseCache {
res, ok := result.([]model.LSBLKModel) res, ok := result.([]model.LSBLKModel)
if ok { if ok {
@@ -247,12 +247,12 @@ func (d *diskService) MountDisk(path, volume string) {
} }
func (d *diskService) SaveMountPoint(m model2.SerialDisk) { func (d *diskService) SaveMountPoint(m model2.SerialDisk) {
d.db.Where("serial = ?", m.Serial).Delete(&model2.SerialDisk{}) d.db.Where("uuid = ?", m.UUID).Delete(&model2.SerialDisk{})
d.db.Create(&m) d.db.Create(&m)
} }
func (d *diskService) UpdateMountPoint(m model2.SerialDisk) { func (d *diskService) UpdateMountPoint(m model2.SerialDisk) {
d.db.Model(&model2.SerialDisk{}).Where("serial = ?", m.Serial).Update("mount_point", m.MountPoint) d.db.Model(&model2.SerialDisk{}).Where("uui = ?", m.UUID).Update("mount_point", m.MountPoint)
} }
func (d *diskService) DeleteMount(id string) { func (d *diskService) DeleteMount(id string) {

View File

@@ -3,7 +3,7 @@ package model
//SerialAdvanced Technology Attachment (STAT) //SerialAdvanced Technology Attachment (STAT)
type SerialDisk struct { type SerialDisk struct {
Id uint `gorm:"column:id;primary_key" json:"id"` Id uint `gorm:"column:id;primary_key" json:"id"`
Serial string `json:"serial"` UUID string `json:"uuid"`
Path string `json:"path"` Path string `json:"path"`
State int `json:"state"` State int `json:"state"`
MountPoint string `json:"mount_point"` MountPoint string `json:"mount_point"`

View File

@@ -4,18 +4,20 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
"github.com/PuerkitoBio/goquery"
"github.com/tidwall/gjson"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"unicode"
"github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
"github.com/PuerkitoBio/goquery"
"github.com/tidwall/gjson"
) )
type ZeroTierService interface { type ZeroTierService interface {
@@ -33,6 +35,7 @@ type ZeroTierService interface {
DeleteMember(token string, id, mId string) interface{} DeleteMember(token string, id, mId string) interface{}
DeleteNetwork(token, id string) interface{} DeleteNetwork(token, id string) interface{}
GetJoinNetworks() string GetJoinNetworks() string
NetworkIdFilter(letter rune) bool
} }
type zerotierStruct struct { type zerotierStruct struct {
} }
@@ -333,6 +336,13 @@ func (c *zerotierStruct) GetJoinNetworks() string {
return json return json
} }
func (c *zerotierStruct) NetworkIdFilter(letter rune) bool {
if unicode.IsNumber(letter) || unicode.IsLetter(letter) {
return true
} else {
return false
}
}
func NewZeroTierService() ZeroTierService { func NewZeroTierService() ZeroTierService {
//初始化client //初始化client
client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error { client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error {

View File

@@ -115,8 +115,8 @@ AddPartition() {
parted -s $1 mklabel gpt parted -s $1 mklabel gpt
parted -s $1 mkpart primary ext4 0 100% parted -s $1 mkpart primary ext4 0 100%
PATH=`lsblk -r $1 | sort | grep part | head -n 1 | awk '{print $1}'`
mkfs.ext4 -m 1 $11 mkfs.ext4 -m 1 /dev/${PATH}
partprobe $1 partprobe $1
@@ -156,8 +156,8 @@ GetPartitionSectors() {
#检查没有使用的挂载点删除文件夹 #检查没有使用的挂载点删除文件夹
AutoRemoveUnuseDir() { AutoRemoveUnuseDir() {
DIRECTORY="/mnt/" DIRECTORY="/DATA/"
dir=$(ls -l $DIRECTORY | awk '/^d/ {print $NF}') dir=$(ls -l $DIRECTORY | grep "Storage[0-9]" | awk '/^d/ {print $NF}')
for i in $dir; do for i in $dir; do
path="$DIRECTORY$i" path="$DIRECTORY$i"

View File

@@ -1,5 +1,5 @@
package types package types
const CURRENTVERSION = "0.2.6" const CURRENTVERSION = "0.2.8"
const BODY = "<li>Fix a disk that cannot be formatted under certain circumstances</li>" const BODY = "<li>Compatible with more types of disks</li><li>Add usb display</li><li>Change translation</li>"

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

File diff suppressed because one or more lines are too long