完善dockerfile构建镜像
This commit is contained in:
@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/model"
|
||||
"next-terminal/pkg/utils"
|
||||
"time"
|
||||
@ -29,7 +29,7 @@ func LoginEndpoint(c echo.Context) error {
|
||||
|
||||
token := utils.UUID()
|
||||
|
||||
config.Cache.Set(token, user, time.Minute*time.Duration(30))
|
||||
global.Cache.Set(token, user, time.Minute*time.Duration(30))
|
||||
|
||||
model.UpdateUserById(&model.User{Online: true}, user.ID)
|
||||
|
||||
@ -38,7 +38,7 @@ func LoginEndpoint(c echo.Context) error {
|
||||
|
||||
func LogoutEndpoint(c echo.Context) error {
|
||||
token := GetToken(c)
|
||||
config.Cache.Delete(token)
|
||||
global.Cache.Delete(token)
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,14 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Auth(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
urls := []string{"download", "login"}
|
||||
urls := []string{"download", "recording", "login", "static", "favicon", "logo"}
|
||||
|
||||
return func(c echo.Context) error {
|
||||
// 路由拦截 - 登录身份、资源权限判断等
|
||||
@ -23,12 +23,12 @@ func Auth(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
token := GetToken(c)
|
||||
user, found := config.Cache.Get(token)
|
||||
user, found := global.Cache.Get(token)
|
||||
if !found {
|
||||
c.Logger().Error("您的登录信息已失效,请重新登录后再试。")
|
||||
return Fail(c, 403, "您的登录信息已失效,请重新登录后再试。")
|
||||
}
|
||||
config.Cache.Set(token, user, time.Minute*time.Duration(30))
|
||||
global.Cache.Set(token, user, time.Minute*time.Duration(30))
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"net/http"
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/model"
|
||||
)
|
||||
|
||||
@ -12,7 +12,6 @@ const Token = "X-Auth-Token"
|
||||
|
||||
func SetupRoutes() *echo.Echo {
|
||||
|
||||
// Echo instance
|
||||
e := echo.New()
|
||||
|
||||
e.File("/", "web/build/index.html")
|
||||
@ -22,6 +21,15 @@ func SetupRoutes() *echo.Echo {
|
||||
|
||||
// Middleware
|
||||
e.Use(middleware.Logger())
|
||||
|
||||
//fd, _ := os.OpenFile(
|
||||
// "nt.log",
|
||||
// os.O_RDWR|os.O_APPEND,
|
||||
// 0666,
|
||||
//)
|
||||
//writer := io.MultiWriter(fd, os.Stdout)
|
||||
|
||||
//e.Logger.SetOutput(writer)
|
||||
e.Use(middleware.Recover())
|
||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
Skipper: middleware.DefaultSkipper,
|
||||
@ -92,6 +100,7 @@ func SetupRoutes() *echo.Echo {
|
||||
sessions.DELETE("/:id/rmdir", SessionRmDirEndpoint)
|
||||
sessions.DELETE("/:id/rm", SessionRmEndpoint)
|
||||
sessions.DELETE("/:id", SessionDeleteEndpoint)
|
||||
sessions.GET("/:id/recording", SessionRecordingEndpoint)
|
||||
}
|
||||
|
||||
e.GET("/properties", PropertyGetEndpoint)
|
||||
@ -137,7 +146,7 @@ func GetToken(c echo.Context) string {
|
||||
|
||||
func GetCurrentAccount(c echo.Context) (model.User, bool) {
|
||||
token := GetToken(c)
|
||||
get, b := config.Cache.Get(token)
|
||||
get, b := global.Cache.Get(token)
|
||||
if b {
|
||||
return get.(model.User), true
|
||||
}
|
||||
|
@ -5,10 +5,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/gommon/log"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/model"
|
||||
"next-terminal/pkg/utils"
|
||||
"os"
|
||||
@ -42,12 +43,14 @@ func SessionDeleteEndpoint(c echo.Context) error {
|
||||
sessionIds := c.Param("id")
|
||||
split := strings.Split(sessionIds, ",")
|
||||
for i := range split {
|
||||
model.DeleteSessionById(split[i])
|
||||
drivePath, err := model.GetRecordingPath()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_ = os.Remove(path.Join(drivePath, split[i]))
|
||||
if err := os.RemoveAll(path.Join(drivePath, split[i])); err != nil {
|
||||
return err
|
||||
}
|
||||
model.DeleteSessionById(split[i])
|
||||
}
|
||||
|
||||
return Success(c, nil)
|
||||
@ -70,7 +73,7 @@ func SessionDiscontentEndpoint(c echo.Context) error {
|
||||
|
||||
split := strings.Split(sessionIds, ",")
|
||||
for i := range split {
|
||||
tun, ok := config.Store.Get(split[i])
|
||||
tun, ok := global.Store.Get(split[i])
|
||||
if ok {
|
||||
CloseSession(split[i], tun)
|
||||
}
|
||||
@ -78,9 +81,9 @@ func SessionDiscontentEndpoint(c echo.Context) error {
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func CloseSession(sessionId string, tun config.Tun) {
|
||||
func CloseSession(sessionId string, tun global.Tun) {
|
||||
_ = tun.Tun.Close()
|
||||
config.Store.Del(sessionId)
|
||||
global.Store.Del(sessionId)
|
||||
|
||||
session := model.Session{}
|
||||
session.ID = sessionId
|
||||
@ -172,7 +175,7 @@ func SessionUploadEndpoint(c echo.Context) error {
|
||||
remoteFile := path.Join(remoteDir, filename)
|
||||
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -226,7 +229,7 @@ func SessionDownloadEndpoint(c echo.Context) error {
|
||||
remoteFile := c.QueryParam("file")
|
||||
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -273,7 +276,7 @@ func SessionLsEndpoint(c echo.Context) error {
|
||||
}
|
||||
remoteDir := c.QueryParam("dir")
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -334,7 +337,7 @@ func SessionMkDirEndpoint(c echo.Context) error {
|
||||
}
|
||||
remoteDir := c.QueryParam("dir")
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -365,7 +368,7 @@ func SessionRmDirEndpoint(c echo.Context) error {
|
||||
}
|
||||
remoteDir := c.QueryParam("dir")
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -407,7 +410,7 @@ func SessionRmEndpoint(c echo.Context) error {
|
||||
}
|
||||
remoteFile := c.QueryParam("file")
|
||||
if "ssh" == session.Protocol {
|
||||
tun, ok := config.Store.Get(sessionId)
|
||||
tun, ok := global.Store.Get(sessionId)
|
||||
if !ok {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
@ -428,3 +431,14 @@ func SessionRmEndpoint(c echo.Context) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SessionRecordingEndpoint(c echo.Context) error {
|
||||
sessionId := c.Param("id")
|
||||
recordingPath, err := model.GetRecordingPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
recording := path.Join(recordingPath, sessionId, "recording")
|
||||
log.Printf("读取录屏文件:%s", recording)
|
||||
return c.File(recording)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pkg/sftp"
|
||||
"log"
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/guacd"
|
||||
"next-terminal/pkg/model"
|
||||
"path"
|
||||
@ -60,9 +60,9 @@ func TunEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
if propertyMap[guacd.EnableRecording] == "true" {
|
||||
configuration.SetParameter(guacd.CreateRecordingPath, path.Join(propertyMap[guacd.CreateRecordingPath], sessionId))
|
||||
configuration.SetParameter(guacd.RecordingPath, path.Join(propertyMap[guacd.RecordingPath], sessionId))
|
||||
} else {
|
||||
configuration.SetParameter(guacd.CreateRecordingPath, "")
|
||||
configuration.SetParameter(guacd.RecordingPath, "")
|
||||
}
|
||||
|
||||
configuration.Protocol = session.Protocol
|
||||
@ -110,15 +110,15 @@ func TunEndpoint(c echo.Context) error {
|
||||
}
|
||||
|
||||
fmt.Printf("=====================================================\n")
|
||||
fmt.Printf("connect to %v with config: %+v\n", addr, configuration)
|
||||
fmt.Printf("connect to %v with global: %+v\n", addr, configuration)
|
||||
fmt.Printf("=====================================================\n")
|
||||
|
||||
tun := config.Tun{
|
||||
tun := global.Tun{
|
||||
Tun: tunnel,
|
||||
SftpClient: sftpClient,
|
||||
}
|
||||
|
||||
config.Store.Set(sessionId, tun)
|
||||
global.Store.Set(sessionId, tun)
|
||||
|
||||
if len(session.ConnectionId) == 0 {
|
||||
session.ConnectionId = tunnel.UUID
|
||||
|
Reference in New Issue
Block a user