You've already forked CasaOS
mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-07-06 23:37:26 +02:00
feat: migrate gin to echo (#1854)
This commit is contained in:
@ -10,8 +10,9 @@ import (
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
sshHelper "github.com/IceWhaleTech/CasaOS-Common/utils/ssh"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@ -26,44 +27,41 @@ var upgrader = websocket.Upgrader{
|
||||
HandshakeTimeout: time.Duration(time.Second * 5),
|
||||
}
|
||||
|
||||
func PostSshLogin(c *gin.Context) {
|
||||
func PostSshLogin(ctx echo.Context) error {
|
||||
j := make(map[string]string)
|
||||
c.ShouldBind(&j)
|
||||
ctx.Bind(&j)
|
||||
userName := j["username"]
|
||||
password := j["password"]
|
||||
port := j["port"]
|
||||
if userName == "" || password == "" || port == "" {
|
||||
c.JSON(common_err.CLIENT_ERROR, modelCommon.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "Username or password or port is empty"})
|
||||
return
|
||||
return ctx.JSON(common_err.CLIENT_ERROR, modelCommon.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "Username or password or port is empty"})
|
||||
}
|
||||
_, err := sshHelper.NewSshClient(userName, password, port)
|
||||
if err != nil {
|
||||
c.JSON(common_err.CLIENT_ERROR, modelCommon.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: "Please check if the username and port are correct, and make sure that ssh server is installed."})
|
||||
return ctx.JSON(common_err.CLIENT_ERROR, modelCommon.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: "Please check if the username and port are correct, and make sure that ssh server is installed."})
|
||||
logger.Error("connect ssh error", zap.Any("error", err))
|
||||
return
|
||||
}
|
||||
c.JSON(common_err.SUCCESS, modelCommon.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
||||
return ctx.JSON(common_err.SUCCESS, modelCommon.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
||||
}
|
||||
|
||||
func WsSsh(c *gin.Context) {
|
||||
func WsSsh(ctx echo.Context) error {
|
||||
_, e := exec.LookPath("ssh")
|
||||
if e != nil {
|
||||
c.JSON(common_err.SERVICE_ERROR, modelCommon.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: "ssh server not found"})
|
||||
return
|
||||
return ctx.JSON(common_err.SERVICE_ERROR, modelCommon.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: "ssh server not found"})
|
||||
}
|
||||
|
||||
userName := c.Query("username")
|
||||
password := c.Query("password")
|
||||
port := c.Query("port")
|
||||
wsConn, _ := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
userName := ctx.QueryParam("username")
|
||||
password := ctx.QueryParam("password")
|
||||
port := ctx.QueryParam("port")
|
||||
wsConn, _ := upgrader.Upgrade(ctx.Response().Writer, ctx.Request(), nil)
|
||||
logBuff := new(bytes.Buffer)
|
||||
|
||||
quitChan := make(chan bool, 3)
|
||||
// user := ""
|
||||
// password := ""
|
||||
var login int = 1
|
||||
cols, _ := strconv.Atoi(c.DefaultQuery("cols", "200"))
|
||||
rows, _ := strconv.Atoi(c.DefaultQuery("rows", "32"))
|
||||
cols, _ := strconv.Atoi(utils.DefaultQuery(ctx, "cols", "200"))
|
||||
rows, _ := strconv.Atoi(utils.DefaultQuery(ctx, "rows", "32"))
|
||||
var client *ssh.Client
|
||||
for login != 0 {
|
||||
|
||||
@ -93,4 +91,5 @@ func WsSsh(c *gin.Context) {
|
||||
go ssConn.SessionWait(quitChan)
|
||||
|
||||
<-quitChan
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user