mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2026-01-04 18:34:21 +00:00
0.3.4 (#385)
* delete connect * update user * change branch * API feedback (#341) * wip * wip * wip * wip * wip * wip * wip * wip * change branch * update route * change branch * Update route.go * 0.3.4 Function development completed * Update system.go * update ui * Completed v0.3.4 and released alpha Co-authored-by: Tiger Wang (王豫) <tigerwang@outlook.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-21 16:01:26
|
||||
* @LastEditTime: 2022-07-14 10:58:45
|
||||
* @FilePath: /CasaOS/pkg/config/init.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -15,7 +14,7 @@ import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func NewSshClient(user, password string) (*ssh.Client, error) {
|
||||
func NewSshClient(user, password string, port string) (*ssh.Client, error) {
|
||||
|
||||
// connet to ssh
|
||||
// addr = fmt.Sprintf("%s:%d", host, port)
|
||||
@@ -32,7 +31,7 @@ func NewSshClient(user, password string) (*ssh.Client, error) {
|
||||
//} else {
|
||||
// config.Auth = []ssh.AuthMethod{publicKeyAuthFunc(h.Key)}
|
||||
//}
|
||||
addr := fmt.Sprintf("%s:%d", "127.0.0.1", 22)
|
||||
addr := fmt.Sprintf("%s:%s", "127.0.0.1", port)
|
||||
c, err := ssh.Dial("tcp", addr, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -396,7 +395,7 @@ func WsReaderCopy(reader *websocket.Conn, writer io.Writer) {
|
||||
if err = json2.Unmarshal(p, &msgObj); err != nil {
|
||||
writer.Write(p)
|
||||
} else if msgObj.Type == wsMsgResize {
|
||||
writer.Write([]byte("stty rows " + strconv.Itoa(msgObj.Rows) + " && stty cols " + strconv.Itoa(msgObj.Cols) + " \r"))
|
||||
//writer.Write([]byte("stty rows " + strconv.Itoa(msgObj.Rows) + " && stty cols " + strconv.Itoa(msgObj.Cols) + " \r"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-22 18:50:44
|
||||
* @LastEditTime: 2022-07-11 18:10:53
|
||||
* @FilePath: /CasaOS/pkg/sqlite/db.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -42,8 +42,22 @@ func GetDb(dbPath string) *gorm.DB {
|
||||
return nil
|
||||
}
|
||||
gdb = db
|
||||
err = db.AutoMigrate(&model2.AppNotify{}, &model2.AppListDBModel{}, &model2.SerialDisk{}, model2.PersonDownloadDBModel{}, model2.FriendModel{}, model2.PersonDownRecordDBModel{}, model2.UserDBModel{})
|
||||
|
||||
db.Exec(`alter table o_user rename to old_user;
|
||||
|
||||
create table o_users ( id integer primary key,username text,password text,role text,email text,nickname text,avatar text,description text,created_at datetime,updated_at datetime);
|
||||
|
||||
insert into o_users select id,user_name,password,role,email,nick_name,avatar,description,created_at,updated_at from old_user;
|
||||
|
||||
drop table old_user;
|
||||
drop table o_user;
|
||||
`)
|
||||
|
||||
err = db.AutoMigrate(&model2.AppNotify{}, &model2.AppListDBModel{}, &model2.SerialDisk{}, model2.UserDBModel{})
|
||||
db.Exec("DROP TABLE IF EXISTS o_application")
|
||||
db.Exec("DROP TABLE IF EXISTS o_friend")
|
||||
db.Exec("DROP TABLE IF EXISTS o_person_download")
|
||||
db.Exec("DROP TABLE IF EXISTS o_person_down_record")
|
||||
if err != nil {
|
||||
loger.Error("check or create db error", zap.Any("error", err))
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package common_err
|
||||
|
||||
const (
|
||||
SUCCESS = 200
|
||||
ERROR = 500
|
||||
INVALID_PARAMS = 400
|
||||
SERVICE_ERROR = 500
|
||||
CLIENT_ERROR = 400
|
||||
ERROR_AUTH_TOKEN = 401
|
||||
|
||||
INVALID_PARAMS = 4000
|
||||
//user
|
||||
PWD_INVALID = 10001
|
||||
PWD_IS_EMPTY = 10002
|
||||
@@ -49,19 +50,12 @@ const (
|
||||
|
||||
//shortcuts
|
||||
SHORTCUTS_URL_ERROR = 70001
|
||||
|
||||
//person
|
||||
PERSON_REMOTE_ERROR = 80001
|
||||
PERSON_DOWN_NOT_EXIST = 80002
|
||||
PERSON_EXIST_DOWNLOAD = 80003
|
||||
PERSON_NOT_EXIST_USER = 80004
|
||||
PERSON_EXIST_FRIEND = 80005
|
||||
PERSON_MYSELF = 80006
|
||||
)
|
||||
|
||||
var MsgFlags = map[int]string{
|
||||
SUCCESS: "ok",
|
||||
ERROR: "fail",
|
||||
SERVICE_ERROR: "Fail",
|
||||
CLIENT_ERROR: "Fail",
|
||||
INVALID_PARAMS: "Parameters Error",
|
||||
ERROR_AUTH_TOKEN: "Error auth token",
|
||||
|
||||
@@ -108,12 +102,6 @@ var MsgFlags = map[int]string{
|
||||
FILE_DELETE_ERROR: "Delete error",
|
||||
SHORTCUTS_URL_ERROR: "URL error",
|
||||
|
||||
PERSON_REMOTE_ERROR: "Remote connection error",
|
||||
PERSON_DOWN_NOT_EXIST: "Download record does not exist",
|
||||
PERSON_EXIST_DOWNLOAD: "The same download task exists",
|
||||
PERSON_EXIST_FRIEND: "Friend already exist",
|
||||
PERSON_NOT_EXIST_USER: "User does not exist",
|
||||
PERSON_MYSELF: "You can not add yourself",
|
||||
COMMAND_ERROR_INVALID_OPERATION: "invalid operation",
|
||||
}
|
||||
|
||||
@@ -123,5 +111,5 @@ func GetMsg(code int) string {
|
||||
if ok {
|
||||
return msg
|
||||
}
|
||||
return MsgFlags[ERROR]
|
||||
return MsgFlags[SERVICE_ERROR]
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-09-30 18:18:14
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-24 10:02:46
|
||||
* @LastEditTime: 2022-07-18 17:30:38
|
||||
* @FilePath: /CasaOS/pkg/utils/jwt/jwt.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -16,67 +16,26 @@ import (
|
||||
jwt "github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
// 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, 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()),
|
||||
// NotBefore: jwt.NewNumericDate(time.Now()),
|
||||
// Issuer: issuer,
|
||||
// },
|
||||
// }
|
||||
|
||||
// tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, clims)
|
||||
// token, err := tokenClaims.SignedString(jwtSecret)
|
||||
// return token, err
|
||||
|
||||
// }
|
||||
|
||||
// //解析token
|
||||
// func ParseToken(token string) (*Claims, error) {
|
||||
// tokenClaims, err := jwt.ParseWithClaims(token, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
// return jwtSecret, nil
|
||||
// })
|
||||
// if tokenClaims != nil {
|
||||
// if clims, ok := tokenClaims.Claims.(*Claims); ok && tokenClaims.Valid {
|
||||
// return clims, nil
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
//****************** soon to be removed ******************
|
||||
|
||||
type Claims struct {
|
||||
UserName string `json:"username"`
|
||||
Username string `json:"username"`
|
||||
PassWord string `json:"password"`
|
||||
jwt.StandardClaims
|
||||
Id int `json:"id"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
var jwtSecret []byte
|
||||
|
||||
//创建token
|
||||
func GenerateToken(username, password string) (string, error) {
|
||||
expireTime := time.Now().AddDate(999, 0, 0)
|
||||
func GenerateToken(username, password string, id int, issuer string, t time.Duration) (string, error) {
|
||||
clims := Claims{
|
||||
username,
|
||||
password,
|
||||
jwt.StandardClaims{
|
||||
ExpiresAt: expireTime.Unix(),
|
||||
Issuer: "gin-blog",
|
||||
id,
|
||||
jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(t)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||
Issuer: issuer,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -87,13 +46,17 @@ func GenerateToken(username, password string) (string, error) {
|
||||
}
|
||||
|
||||
//解析token
|
||||
func ParseToken(token string) (*Claims, error) {
|
||||
func ParseToken(token string, valid bool) (*Claims, error) {
|
||||
tokenClaims, err := jwt.ParseWithClaims(token, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return jwtSecret, nil
|
||||
})
|
||||
if tokenClaims != nil {
|
||||
if clims, ok := tokenClaims.Claims.(*Claims); ok && tokenClaims.Valid {
|
||||
return clims, nil
|
||||
if clims, ok := tokenClaims.Claims.(*Claims); ok {
|
||||
if valid && tokenClaims.Valid {
|
||||
return clims, nil
|
||||
} else if !valid {
|
||||
return clims, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-06-17 14:01:25
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-04 16:26:22
|
||||
* @LastEditTime: 2022-07-18 17:31:15
|
||||
* @FilePath: /CasaOS/pkg/utils/jwt/jwt_helper.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -11,65 +11,16 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// func JWT() gin.HandlerFunc {
|
||||
// return func(c *gin.Context) {
|
||||
// var code int
|
||||
// code = common_err.SUCCESS
|
||||
// token := c.GetHeader("Authorization")
|
||||
// if len(token) == 0 {
|
||||
// token = c.Query("token")
|
||||
// }
|
||||
// if token == "" {
|
||||
// code = common_err.INVALID_PARAMS
|
||||
// }
|
||||
|
||||
// claims, err := ParseToken(token)
|
||||
// //_, err := ParseToken(token)
|
||||
// if err != nil {
|
||||
// code = common_err.ERROR_AUTH_TOKEN
|
||||
// } else if !claims.VerifyExpiresAt(time.Now(), true) || !claims.VerifyIssuer("casaos", true) {
|
||||
// code = common_err.ERROR_AUTH_TOKEN
|
||||
// }
|
||||
// if code != common_err.SUCCESS {
|
||||
// c.JSON(code, model.Result{Success: code, Message: common_err.GetMsg(code)})
|
||||
// c.Abort()
|
||||
// return
|
||||
// }
|
||||
// c.Request.Header.Add("user_id", strconv.Itoa(claims.Id))
|
||||
// c.Next()
|
||||
// }
|
||||
// }
|
||||
|
||||
// //get AccessToken
|
||||
// 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 {
|
||||
// loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
// return ""
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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 {
|
||||
// loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
// return ""
|
||||
// }
|
||||
// }
|
||||
|
||||
//*************** soon to be removed *****************
|
||||
|
||||
func JWT() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var code int
|
||||
@@ -82,32 +33,43 @@ func JWT() gin.HandlerFunc {
|
||||
code = common_err.INVALID_PARAMS
|
||||
}
|
||||
|
||||
//claims, err := ParseToken(token)
|
||||
_, err := ParseToken(token)
|
||||
claims, err := ParseToken(token, false)
|
||||
|
||||
//_, err := ParseToken(token)
|
||||
if err != nil {
|
||||
code = common_err.ERROR_AUTH_TOKEN
|
||||
|
||||
} else if (c.Request.URL.Path == "/v1/file" || c.Request.URL.Path == "/v1/image" || c.Request.URL.Path == "/v1/file/upload" || c.Request.URL.Path == "/v1/batch") && claims.VerifyIssuer("casaos", true) {
|
||||
//Special treatment
|
||||
} else if !claims.VerifyExpiresAt(time.Now(), true) || !claims.VerifyIssuer("casaos", true) {
|
||||
code = common_err.ERROR_AUTH_TOKEN
|
||||
}
|
||||
//else if time.Now().Unix() > claims.ExpiresAt {
|
||||
// code = oasis_err2.ERROR_AUTH_TOKEN
|
||||
//}
|
||||
|
||||
if code != common_err.SUCCESS {
|
||||
c.JSON(http.StatusOK, model.Result{Success: code, Message: common_err.GetMsg(code)})
|
||||
c.JSON(code, model.Result{Success: code, Message: common_err.GetMsg(code)})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Request.Header.Add("user_id", strconv.Itoa(claims.Id))
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
//获取token
|
||||
func GetToken(username, pwd string) string {
|
||||
token, err := GenerateToken(username, pwd)
|
||||
//get AccessToken
|
||||
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 {
|
||||
//loger2.NewOLoger().Fatal(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func GetRefreshToken(username, pwd string, id int) string {
|
||||
token, err := GenerateToken(username, pwd, id, "refresh", 7*24*time.Hour*time.Duration(1))
|
||||
if err == nil {
|
||||
return token
|
||||
} else {
|
||||
loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-13 18:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-29 14:29:34
|
||||
* @LastEditTime: 2022-07-21 15:27:53
|
||||
* @FilePath: /CasaOS/pkg/utils/version/version.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
@@ -33,9 +33,6 @@ func IsNeedUpdate(version model.Version) (bool, model.Version) {
|
||||
for i := 0; i < len(v1); i++ {
|
||||
a, _ := strconv.Atoi(v1[i])
|
||||
b, _ := strconv.Atoi(v2[i])
|
||||
if i == 0 && a > b {
|
||||
continue
|
||||
}
|
||||
if a > b {
|
||||
return true, version
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user