mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-11-07 07:09:46 +00:00
switch branch
This commit is contained in:
parent
6343e889e8
commit
493c1170f9
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,6 +31,7 @@ gen
|
||||
/docs/
|
||||
/web/
|
||||
/conf/conf.ini
|
||||
/conf/conf.json
|
||||
__debug_bin
|
||||
main
|
||||
CasaOS
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
[app]
|
||||
PAGE_SIZE = 10
|
||||
RuntimeRootPath = runtime/
|
||||
LogSavePath = /casaOS/logs/server/
|
||||
LogSavePath = /var/log/casaos/
|
||||
LogSaveName = log
|
||||
LogFileExt = log
|
||||
DateStrFormat = 20060102
|
||||
DateTimeFormat = 2006-01-02 15:04:05
|
||||
TimeFormat = 15:04:05
|
||||
DateFormat = 2006-01-02
|
||||
ProjectPath = /casaOS/server
|
||||
RootPath = /casaOS
|
||||
|
||||
DBPath = /var/lib/casaos
|
||||
ShellPath = /usr/share/casaos/shell
|
||||
UserDataPath = /var/lib/casaos/conf
|
||||
TempPath = /var/lib/casaos/temp
|
||||
|
||||
[server]
|
||||
HttpPort = 8089
|
||||
2
main.go
2
main.go
@ -30,7 +30,7 @@ func init() {
|
||||
config.UpdateSetup()
|
||||
loger.LogInit()
|
||||
if len(*dbFlag) == 0 {
|
||||
*dbFlag = config.AppInfo.ProjectPath + "/db"
|
||||
*dbFlag = config.AppInfo.DBPath + "/db"
|
||||
}
|
||||
sqliteDB = sqlite.GetDb(*dbFlag)
|
||||
//gredis.GetRedisConn(config.RedisInfo),
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-05-30 16:43:59
|
||||
* @LastEditTime: 2022-06-16 17:50:56
|
||||
* @FilePath: /CasaOS/model/sys_common.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -46,15 +46,17 @@ type ServerModel struct {
|
||||
|
||||
//服务配置
|
||||
type APPModel struct {
|
||||
LogSavePath string
|
||||
LogPath string
|
||||
LogSaveName string
|
||||
LogFileExt string
|
||||
DateStrFormat string
|
||||
DateTimeFormat string
|
||||
UserDataPath string
|
||||
TimeFormat string
|
||||
DateFormat string
|
||||
ProjectPath string
|
||||
RootPath string
|
||||
DBPath string
|
||||
ShellPath string
|
||||
TempPath string
|
||||
}
|
||||
|
||||
//公共返回模型
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-09-30 18:18:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-16 18:11:41
|
||||
* @FilePath: /CasaOS/pkg/config/config.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package config
|
||||
|
||||
const (
|
||||
USERCONFIGURL = "conf/conf.ini"
|
||||
USERCONFIGURL = "conf/conf.json"
|
||||
)
|
||||
|
||||
@ -1,3 +1,13 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-16 17:44:23
|
||||
* @FilePath: /CasaOS/pkg/config/init.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
@ -57,6 +67,21 @@ func InitSetup(config string) {
|
||||
mapTo("system", SystemConfigInfo)
|
||||
mapTo("file", FileSettingInfo)
|
||||
SystemConfigInfo.ConfigPath = configDir
|
||||
if len(AppInfo.DBPath) == 0 {
|
||||
AppInfo.DBPath = "/var/lib/casaos"
|
||||
}
|
||||
if len(AppInfo.LogPath) == 0 {
|
||||
AppInfo.LogPath = "/var/log/casaos/"
|
||||
}
|
||||
if len(AppInfo.ShellPath) == 0 {
|
||||
AppInfo.ShellPath = "/usr/share/casaos/shell"
|
||||
}
|
||||
if len(AppInfo.UserDataPath) == 0 {
|
||||
AppInfo.UserDataPath = "/var/lib/casaos/conf"
|
||||
}
|
||||
if len(AppInfo.TempPath) == 0 {
|
||||
AppInfo.TempPath = "/var/lib/casaos/temp"
|
||||
}
|
||||
// AppInfo.ProjectPath = getCurrentDirectory() //os.Getwd()
|
||||
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ const (
|
||||
PWD_IS_TOO_SIMPLE = 10005
|
||||
USER_NOT_EXIST = 10006
|
||||
USER_EXIST = 10007
|
||||
KEY_NOT_EXIST = 10008
|
||||
|
||||
//system
|
||||
DIR_ALREADY_EXISTS = 20001
|
||||
@ -69,6 +70,7 @@ var MsgFlags = map[int]string{
|
||||
PWD_IS_TOO_SIMPLE: "Password is too simple",
|
||||
USER_NOT_EXIST: "User does not exist",
|
||||
USER_EXIST: "User already exists",
|
||||
KEY_NOT_EXIST: "Key does not exist",
|
||||
|
||||
//system
|
||||
DIR_ALREADY_EXISTS: "Folder already exists",
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-09-30 18:18:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-15 15:07:16
|
||||
* @LastEditTime: 2022-06-16 18:05:00
|
||||
* @FilePath: /CasaOS/pkg/utils/jwt/jwt.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -19,16 +19,18 @@ import (
|
||||
type Claims struct {
|
||||
UserName string `json:"username"`
|
||||
PassWord string `json:"password"`
|
||||
Id int `json:"id"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
var jwtSecret []byte
|
||||
|
||||
//创建token
|
||||
func GenerateToken(username, password string, issuer string, t time.Duration) (string, error) {
|
||||
func GenerateToken(username, password string, id int, issuer string, t time.Duration) (string, error) {
|
||||
clims := Claims{
|
||||
username,
|
||||
password,
|
||||
id,
|
||||
jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(t)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
|
||||
@ -3,6 +3,7 @@ package jwt
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
@ -30,6 +31,7 @@ func JWT(swagHandler gin.HandlerFunc) gin.HandlerFunc {
|
||||
} else if claims.VerifyExpiresAt(time.Now(), true) || claims.VerifyIssuer("casaos", true) {
|
||||
code = common_err.ERROR_AUTH_TOKEN
|
||||
}
|
||||
c.Header("user_id", strconv.Itoa(claims.Id))
|
||||
}
|
||||
|
||||
if code != common_err.SUCCESS {
|
||||
@ -37,13 +39,14 @@ func JWT(swagHandler gin.HandlerFunc) gin.HandlerFunc {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
//get AccessToken
|
||||
func GetAccessToken(username, pwd string) string {
|
||||
token, err := GenerateToken(username, pwd, "casaos", 3*time.Hour*time.Duration(1))
|
||||
func GetAccessToken(username, pwd string, id int) string {
|
||||
token, err := GenerateToken(username, pwd, id, "casaos", 3*time.Hour*time.Duration(1))
|
||||
if err == nil {
|
||||
return token
|
||||
} else {
|
||||
@ -52,8 +55,8 @@ func GetAccessToken(username, pwd string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func GetRefreshToken(username, pwd string) string {
|
||||
token, err := GenerateToken(username, pwd, "fresh", 7*24*time.Hour*time.Duration(1))
|
||||
func GetRefreshToken(username, pwd string, id int) string {
|
||||
token, err := GenerateToken(username, pwd, id, "fresh", 7*24*time.Hour*time.Duration(1))
|
||||
if err == nil {
|
||||
return token
|
||||
} else {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-06-02 15:09:38
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-02 17:43:38
|
||||
* @LastEditTime: 2022-06-16 18:15:58
|
||||
* @FilePath: /CasaOS/pkg/utils/loger/log.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -28,7 +28,7 @@ var loggers *zap.Logger
|
||||
func getFileLogWriter() (writeSyncer zapcore.WriteSyncer) {
|
||||
// 使用 lumberjack 实现 log rotate
|
||||
lumberJackLogger := &lumberjack.Logger{
|
||||
Filename: filepath.Join(config.AppInfo.LogSavePath, fmt.Sprintf("%s.%s",
|
||||
Filename: filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
|
||||
config.AppInfo.LogSaveName,
|
||||
config.AppInfo.LogFileExt,
|
||||
)),
|
||||
|
||||
@ -47,7 +47,7 @@ const (
|
||||
//日志初始化
|
||||
func LogSetupOld() {
|
||||
var err error
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogSavePath)
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogPath)
|
||||
fileName := fmt.Sprintf("%s.%s",
|
||||
config.AppInfo.LogSaveName,
|
||||
config.AppInfo.LogFileExt,
|
||||
@ -61,7 +61,7 @@ func LogSetupOld() {
|
||||
|
||||
}
|
||||
func (o *oLog) Path() string {
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogSavePath)
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogPath)
|
||||
fileName := fmt.Sprintf("%s.%s",
|
||||
config.AppInfo.LogSaveName,
|
||||
config.AppInfo.LogFileExt,
|
||||
|
||||
@ -3,6 +3,7 @@ package route
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@ -197,10 +198,10 @@ func CheckSerialDiskMount() {
|
||||
}
|
||||
}
|
||||
service.MyService.Disk().RemoveLSBLKCache()
|
||||
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;AutoRemoveUnuseDir")
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;AutoRemoveUnuseDir")
|
||||
}
|
||||
func Update2_3() {
|
||||
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/assist.sh")
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/assist.sh")
|
||||
|
||||
}
|
||||
func CheckToken2_11() {
|
||||
@ -210,11 +211,6 @@ func CheckToken2_11() {
|
||||
config.Cfg.Section("server").Key("Token").SetValue(token())
|
||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||
}
|
||||
if len(config.AppInfo.RootPath) == 0 {
|
||||
config.Cfg.Section("app").Key("RootPath").SetValue("/casaOS")
|
||||
config.AppInfo.RootPath = "/casaOS"
|
||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||
}
|
||||
|
||||
sysType := runtime.GOOS
|
||||
if len(config.FileSettingInfo.DownloadDir) == 0 {
|
||||
@ -305,6 +301,12 @@ func MoveUserToDB() {
|
||||
user.NickName = config.UserInfo.NickName
|
||||
user.Password = encryption.GetMD5ByStr(config.UserInfo.PWD)
|
||||
user.Role = "admin"
|
||||
service.MyService.User().CreateUser(user)
|
||||
user = service.MyService.User().CreateUser(user)
|
||||
if user.Id > 0 {
|
||||
userPath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id)
|
||||
file.MkDir(userPath)
|
||||
os.Rename("/casaOS/server/conf/app_order.json", userPath+"/app_order.json")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ func InitRouter() *gin.Engine {
|
||||
//chang head
|
||||
//v1UserGroup.POST("/head", v1.PostUserHead)
|
||||
//chang user name
|
||||
v1UserGroup.PUT("/username:/id", v1.PutUserName)
|
||||
v1UserGroup.PUT("/username/:id", v1.PutUserName)
|
||||
//chang pwd
|
||||
v1UserGroup.PUT("/password/:id", v1.PutUserPwd)
|
||||
//edit user info
|
||||
//v1UserGroup.POST("/info", v1.PostUserChangeInfo)
|
||||
v1UserGroup.PUT("/nick:/id", v1.PutUserNick)
|
||||
v1UserGroup.PUT("/nick/:id", v1.PutUserNick)
|
||||
v1UserGroup.PUT("/desc/:id", v1.PutUserDesc)
|
||||
v1UserGroup.GET("/v1/user/info/:id", v1.GetUserInfo)
|
||||
//v1UserGroup.POST("/person/info", v1.PostUserPersonInfo)
|
||||
|
||||
@ -1050,7 +1050,8 @@ func PutAppUpdate(c *gin.Context) {
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /app/order [get]
|
||||
func GetAppOrder(c *gin.Context) {
|
||||
data := service.MyService.System().GetAppOrderFile()
|
||||
id := c.GetHeader("user_id")
|
||||
data := service.MyService.System().GetAppOrderFile(id)
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json.RawMessage(data)})
|
||||
}
|
||||
|
||||
@ -1063,7 +1064,8 @@ func GetAppOrder(c *gin.Context) {
|
||||
// @Router /app/order [post]
|
||||
func PostAppOrder(c *gin.Context) {
|
||||
data := c.PostForm("data")
|
||||
service.MyService.System().UpAppOrderFile(data)
|
||||
id := c.GetHeader("user_id")
|
||||
service.MyService.System().UpAppOrderFile(data, id)
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: common_err.SUCCESS,
|
||||
|
||||
@ -392,7 +392,7 @@ func GetFileUpload(c *gin.Context) {
|
||||
path := c.Query("path")
|
||||
dirPath := ""
|
||||
hash := file.GetHashByContent([]byte(fileName))
|
||||
tempDir := config.AppInfo.RootPath + "/temp/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||
tempDir := config.AppInfo.TempPath + "/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||
if fileName != relative {
|
||||
dirPath = strings.TrimSuffix(relative, fileName)
|
||||
tempDir += dirPath
|
||||
@ -431,7 +431,7 @@ func PostFileUpload(c *gin.Context) {
|
||||
c.JSON(common_err.INVALID_PARAMS, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
||||
return
|
||||
}
|
||||
tempDir := config.AppInfo.RootPath + "/temp/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||
tempDir := config.AppInfo.TempPath + "/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||
|
||||
if fileName != relative {
|
||||
dirPath = strings.TrimSuffix(relative, fileName)
|
||||
|
||||
@ -181,7 +181,7 @@ func GetPersonDownloadList(c *gin.Context) {
|
||||
//if it is downloading, it need to add 'already'
|
||||
for i := 0; i < len(list); i++ {
|
||||
if list[i].State == types.DOWNLOADING {
|
||||
tempDir := config.AppInfo.RootPath + "/temp" + "/" + list[i].UUID
|
||||
tempDir := config.AppInfo.TempPath + "/" + list[i].UUID
|
||||
files, err := ioutil.ReadDir(tempDir)
|
||||
if err == nil {
|
||||
list[i].Already = len(files)
|
||||
|
||||
@ -22,6 +22,7 @@ import (
|
||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
// @Summary check version
|
||||
@ -222,19 +223,21 @@ func PutCasaOSPort(c *gin.Context) {
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /guide/check [get]
|
||||
// @Router /sys/init/check [get]
|
||||
func GetGuideCheck(c *gin.Context) {
|
||||
initUser := false
|
||||
if !config.UserInfo.Initialized {
|
||||
initUser = true
|
||||
data := make(map[string]interface{}, 2)
|
||||
|
||||
if service.MyService.User().GetUserCount() > 0 {
|
||||
data["initialized"] = true
|
||||
} else {
|
||||
data["key"] = uuid.NewV4().String()
|
||||
data["initialized"] = false
|
||||
}
|
||||
data := make(map[string]interface{}, 1)
|
||||
data["need_init_user"] = initUser
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: common_err.SUCCESS,
|
||||
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||
Data: data,
|
||||
Data: true,
|
||||
})
|
||||
}
|
||||
|
||||
@ -547,14 +550,14 @@ func PostSystemRefreshToken(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.VERIFICATION_FAILURE, Message: common_err.GetMsg(common_err.VERIFICATION_FAILURE)})
|
||||
return
|
||||
}
|
||||
newToken := jwt.GetAccessToken(claims.UserName, claims.PassWord)
|
||||
newToken := jwt.GetAccessToken(claims.UserName, claims.PassWord, claims.Id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR), Data: err.Error()})
|
||||
return
|
||||
}
|
||||
verifyInfo := system_model.VerifyInformation{}
|
||||
verifyInfo.AccessToken = newToken
|
||||
verifyInfo.RefreshToken = jwt.GetRefreshToken(claims.UserName, claims.PassWord)
|
||||
verifyInfo.RefreshToken = jwt.GetRefreshToken(claims.UserName, claims.PassWord, claims.Id)
|
||||
verifyInfo.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Format("2006-01-02 15:04:05")
|
||||
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: verifyInfo})
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
|
||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||
|
||||
@ -25,8 +26,11 @@ func PostUserRegister(c *gin.Context) {
|
||||
username := json["user_name"]
|
||||
pwd := json["password"]
|
||||
key := c.GetHeader("key")
|
||||
//TODO:检查hash
|
||||
fmt.Println(key)
|
||||
if _, ok := service.UserRegisterHash[key]; !ok {
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{Success: common_err.KEY_NOT_EXIST, Message: common_err.GetMsg(common_err.KEY_NOT_EXIST)})
|
||||
return
|
||||
}
|
||||
|
||||
if len(username) == 0 || len(pwd) == 0 {
|
||||
c.JSON(http.StatusOK,
|
||||
@ -55,7 +59,8 @@ func PostUserRegister(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
|
||||
return
|
||||
}
|
||||
//TODO:创建文件夹
|
||||
file.MkDir(config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id))
|
||||
delete(service.UserRegisterHash, key)
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
||||
|
||||
}
|
||||
@ -96,8 +101,8 @@ func Login(c *gin.Context) {
|
||||
}
|
||||
user.Password = ""
|
||||
token := system_model.VerifyInformation{}
|
||||
token.AccessToken = jwt.GetAccessToken(user.UserName, user.Password)
|
||||
token.RefreshToken = jwt.GetRefreshToken(user.UserName, user.Password)
|
||||
token.AccessToken = jwt.GetAccessToken(user.UserName, user.Password, user.Id)
|
||||
token.RefreshToken = jwt.GetRefreshToken(user.UserName, user.Password, user.Id)
|
||||
token.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Format("2006-01-02 15:04:05")
|
||||
data := make(map[string]interface{}, 2)
|
||||
data["token"] = token
|
||||
|
||||
32
route/v1/zima_info.go
Normal file
32
route/v1/zima_info.go
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-09-30 18:18:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-16 17:54:10
|
||||
* @FilePath: /CasaOS/route/v1/zima_info.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Summary 获取信息系统信息
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags zima
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /zima/sysinfo [get]
|
||||
func SysInfo(c *gin.Context) {
|
||||
info := service.MyService.ZiMa().GetSysInfo()
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: info})
|
||||
}
|
||||
@ -403,7 +403,7 @@ func (a *appStruct) UpdateApp(m model2.AppListDBModel) {
|
||||
}
|
||||
|
||||
func (a *appStruct) DelAppConfigDir(path string) {
|
||||
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;DelAppConfigDir " + path)
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;DelAppConfigDir " + path)
|
||||
}
|
||||
|
||||
func (a *appStruct) DeleteApp(id string) {
|
||||
|
||||
@ -74,31 +74,31 @@ func (d *diskService) SmartCTL(path string) model.SmartctlA {
|
||||
|
||||
//通过脚本获取外挂磁盘
|
||||
func (d *diskService) GetPlugInDisk() []string {
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetPlugInDisk")
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetPlugInDisk")
|
||||
}
|
||||
|
||||
//格式化硬盘
|
||||
func (d *diskService) FormatDisk(path, format string) []string {
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;FormatDisk " + path + " " + format)
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;FormatDisk " + path + " " + format)
|
||||
return r
|
||||
}
|
||||
|
||||
//移除挂载点,删除目录
|
||||
func (d *diskService) UmountPointAndRemoveDir(path string) []string {
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;UMountPorintAndRemoveDir " + path)
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;UMountPorintAndRemoveDir " + path)
|
||||
return r
|
||||
}
|
||||
|
||||
//删除分区
|
||||
func (d *diskService) DelPartition(path, num string) string {
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;DelPartition " + path + " " + num)
|
||||
r := command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;DelPartition " + path + " " + num)
|
||||
fmt.Println(r)
|
||||
return ""
|
||||
}
|
||||
|
||||
//part
|
||||
func (d *diskService) AddPartition(path string) string {
|
||||
command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;AddPartition " + path)
|
||||
command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;AddPartition " + path)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func (d *diskService) LSBLK(isUseCache bool) []model.LSBLKModel {
|
||||
fsused = 0
|
||||
for _, child := range i.Children {
|
||||
if child.RM {
|
||||
child.Health = strings.TrimSpace(command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetDiskHealthState " + child.Path))
|
||||
child.Health = strings.TrimSpace(command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDiskHealthState " + child.Path))
|
||||
if strings.ToLower(strings.TrimSpace(child.State)) != "ok" {
|
||||
health = false
|
||||
}
|
||||
@ -163,7 +163,7 @@ func (d *diskService) LSBLK(isUseCache bool) []model.LSBLKModel {
|
||||
}
|
||||
c = append(c, child)
|
||||
}
|
||||
i.Format = strings.TrimSpace(command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetDiskType " + i.Path))
|
||||
i.Format = strings.TrimSpace(command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDiskType " + i.Path))
|
||||
if health {
|
||||
i.Health = "OK"
|
||||
}
|
||||
@ -208,7 +208,7 @@ func (d *diskService) GetDiskInfo(path string) model.LSBLKModel {
|
||||
return m
|
||||
// 下面为计算是否可以继续分区的部分,暂时不需要
|
||||
chiArr := make(map[string]string)
|
||||
chiList := command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetPartitionSectors " + m.Path)
|
||||
chiList := command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetPartitionSectors " + m.Path)
|
||||
if len(chiList) == 0 {
|
||||
loger.Error("chiList length error", zap.Any("err", "chiList length error"))
|
||||
}
|
||||
@ -226,7 +226,7 @@ func (d *diskService) GetDiskInfo(path string) model.LSBLKModel {
|
||||
}
|
||||
|
||||
}
|
||||
diskEndSector := command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetDiskSizeAndSectors " + m.Path)
|
||||
diskEndSector := command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDiskSizeAndSectors " + m.Path)
|
||||
|
||||
if len(diskEndSector) < 2 {
|
||||
loger.Error("diskEndSector length error", zap.Any("err", "diskEndSector length error"))
|
||||
@ -242,7 +242,7 @@ func (d *diskService) GetDiskInfo(path string) model.LSBLKModel {
|
||||
}
|
||||
|
||||
func (d *diskService) MountDisk(path, volume string) {
|
||||
r := command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;do_mount " + path + " " + volume)
|
||||
r := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;do_mount " + path + " " + volume)
|
||||
fmt.Print(r)
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ func (d *diskService) DeleteMountPoint(path, mountPoint string) {
|
||||
|
||||
d.db.Where("path = ? AND mount_point = ?", path, mountPoint).Delete(&model2.SerialDisk{})
|
||||
|
||||
command2.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;do_umount " + path)
|
||||
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;do_umount " + path)
|
||||
}
|
||||
|
||||
func (d *diskService) GetSerialAll() []model2.SerialDisk {
|
||||
|
||||
@ -310,7 +310,7 @@ func (s *shareDirService) UpConfig() {
|
||||
} else {
|
||||
defer f.Close()
|
||||
f.WriteString(str)
|
||||
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;ReloadSamba")
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;ReloadSamba")
|
||||
}
|
||||
}
|
||||
func (s *shareDirService) Info(id string) model.ShareDirDBModel {
|
||||
|
||||
@ -26,8 +26,8 @@ type SystemService interface {
|
||||
GetTimeZone() string
|
||||
UpdateUSBAutoMount(state string)
|
||||
ExecUSBAutoMountShell(state string)
|
||||
UpAppOrderFile(str string)
|
||||
GetAppOrderFile() []byte
|
||||
UpAppOrderFile(str, id string)
|
||||
GetAppOrderFile(id string) []byte
|
||||
GetNet(physics bool) []string
|
||||
GetNetInfo() []net.IOCountersStat
|
||||
GetCpuCoreNum() int
|
||||
@ -64,34 +64,34 @@ func (c *systemService) GetNet(physics bool) []string {
|
||||
if physics {
|
||||
t = "2"
|
||||
}
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetNetCard " + t)
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetNetCard " + t)
|
||||
}
|
||||
|
||||
func (s *systemService) UpdateSystemVersion(version string) {
|
||||
//command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version))
|
||||
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/tools.sh ;update " + version))
|
||||
//s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
|
||||
}
|
||||
func (s *systemService) UpdateAssist() {
|
||||
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/assist.sh"))
|
||||
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh"))
|
||||
}
|
||||
|
||||
func (s *systemService) GetTimeZone() string {
|
||||
return command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/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.ProjectPath + "/shell/helper.sh ;USB_Remove_File")
|
||||
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Remove_File")
|
||||
} else {
|
||||
command2.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;USB_Move_File")
|
||||
command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Move_File")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *systemService) GetSystemConfigDebug() []string {
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
|
||||
}
|
||||
func (s *systemService) UpSystemConfig(str string, widget string) {
|
||||
if len(str) > 0 && str != config.SystemConfigInfo.ConfigStr {
|
||||
@ -104,11 +104,11 @@ func (s *systemService) UpSystemConfig(str string, widget string) {
|
||||
}
|
||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||
}
|
||||
func (s *systemService) UpAppOrderFile(str string) {
|
||||
file.WriteToPath([]byte(str), config.AppInfo.ProjectPath+"/conf", "app_order.json")
|
||||
func (s *systemService) UpAppOrderFile(str, id string) {
|
||||
file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
|
||||
}
|
||||
func (s *systemService) GetAppOrderFile() []byte {
|
||||
return file.ReadFullFile(config.AppInfo.ProjectPath + "/conf/app_order.json")
|
||||
func (s *systemService) GetAppOrderFile(id string) []byte {
|
||||
return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
|
||||
}
|
||||
func (s *systemService) UpdateUSBAutoMount(state string) {
|
||||
config.ServerInfo.USBAutoMount = state
|
||||
|
||||
@ -186,7 +186,7 @@ func ReadContent(stream quic.Stream) {
|
||||
fmt.Println(err)
|
||||
time.Sleep(time.Second * 1)
|
||||
for k, v := range CancelList {
|
||||
tempPath := config.AppInfo.RootPath + "/temp" + "/" + v
|
||||
tempPath := config.AppInfo.TempPath + "/" + v
|
||||
fmt.Println(file.RMDir(tempPath))
|
||||
delete(CancelList, k)
|
||||
}
|
||||
@ -445,7 +445,7 @@ func SaveFile(m model.MessageModel, stream quic.Stream) bool {
|
||||
fmt.Println("hash不匹配", hash, dataModel.Hash)
|
||||
return false
|
||||
}
|
||||
tempPath := config.AppInfo.RootPath + "/temp" + "/" + m.UUId
|
||||
tempPath := config.AppInfo.TempPath + "/" + m.UUId
|
||||
file.IsNotExistMkDir(tempPath)
|
||||
filepath := tempPath + "/" + strconv.Itoa(dataModel.Index)
|
||||
_, err = os.Stat(filepath)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-03-18 11:40:55
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-15 17:09:20
|
||||
* @LastEditTime: 2022-06-16 19:08:09
|
||||
* @FilePath: /CasaOS/service/user.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@ -31,6 +31,8 @@ type UserService interface {
|
||||
GetAllUserName() (list []model.UserDBModel)
|
||||
}
|
||||
|
||||
var UserRegisterHash = make(map[string]string)
|
||||
|
||||
type userService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
@ -115,12 +115,12 @@ func (c *zima) GetSysInfo() host.InfoStat {
|
||||
}
|
||||
|
||||
func (c *zima) GetDeviceTree() string {
|
||||
return command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetDeviceTree")
|
||||
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
|
||||
}
|
||||
|
||||
//shell脚本参数 { 网卡名称 }
|
||||
func (c *zima) GetNetState(name string) string {
|
||||
return command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;CatNetCardState " + name)
|
||||
return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CatNetCardState " + name)
|
||||
}
|
||||
|
||||
//mkdir
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user