Skip to content

Commit

Permalink
Merge pull request #223 from jumpserver/dev
Browse files Browse the repository at this point in the history
v3.4.0
  • Loading branch information
BaiJiangJie authored Jun 15, 2023
2 parents 5ca2681 + f7db4bd commit 0404600
Show file tree
Hide file tree
Showing 22 changed files with 488 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ADD ui .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=lion \
yarn build

FROM golang:1.19-bullseye as stage-build
FROM golang:1.19-buster as stage-build
LABEL stage=stage-build
ARG TARGETARCH

Expand Down Expand Up @@ -47,7 +47,7 @@ RUN --mount=type=cache,target=/root/.cache \

RUN chmod +x entrypoint.sh

FROM jumpserver/guacd:1.4.0
FROM jumpserver/guacd:1.5.2
ARG TARGETARCH

USER root
Expand Down
82 changes: 0 additions & 82 deletions Dockerfile.loong64

This file was deleted.

52 changes: 50 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"lion/pkg/jms-sdk-go/service/videoworker"
"lion/pkg/logger"
"lion/pkg/middleware"
"lion/pkg/proxy"
"lion/pkg/session"
"lion/pkg/storage"
"lion/pkg/tunnel"
Expand Down Expand Up @@ -304,14 +305,61 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo

func bootstrap(jmsService *service.JMService) {
replayDir := config.GlobalConfig.RecordPath
ftpFilePath := config.GlobalConfig.FTPFilePath
allRemainFiles := scanRemainReplay(jmsService, replayDir)
go uploadRemainReplay(jmsService, allRemainFiles)
go uploadRemainFTPFile(jmsService, ftpFilePath)
}

func uploadRemainFTPFile(jmsService *service.JMService, fileStoreDir string) {
err := config.EnsureDirExist(fileStoreDir)
if err != nil {
logger.Debugf("upload failed FTP file err: %s", err.Error())
return
}

terminalConf, _ := jmsService.GetTerminalConfig()
ftpFileStorage := storage.NewFTPFileStorage(jmsService, terminalConf.ReplayStorage)

allRemainFiles := make(map[string]string)
_ = filepath.Walk(fileStoreDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
var fid string
filename := info.Name()
if len(filename) == 36 {
fid = filename
}
if fid != "" {
allRemainFiles[path] = fid
}
return nil
})

for path, fid := range allRemainFiles {
dateTarget, _ := filepath.Rel(fileStoreDir, path)
target := strings.Join([]string{proxy.FTPTargetPrefix, dateTarget}, "/")
logger.Infof("Upload FTP file: %s, type: %s", path, ftpFileStorage.TypeName())
if err = ftpFileStorage.Upload(path, target); err != nil {
logger.Errorf("Upload remain FTP file %s failed: %s", path, err)
continue
}
if err := jmsService.FinishFTPFile(fid); err != nil {
logger.Errorf("Notify FTP file %s upload failed: %s", fid, err)
continue
}
_ = os.Remove(path)
logger.Infof("Upload remain FTP file %s success", path)
}
logger.Debug("Upload remain replay done")
}

func uploadRemainReplay(jmsService *service.JMService, remainFiles map[string]string) {
var replayStorage storage.ReplayStorage
terminalConf, _ := jmsService.GetTerminalConfig()
replayStorage = storage.NewReplayStorage(terminalConf.ReplayStorage)
replayStorage = storage.NewReplayStorage(jmsService, terminalConf.ReplayStorage)
defaultStorage := storage.FTPServerStorage{StorageType: "server", JmsService: jmsService}
for sid, path := range remainFiles {
absGzPath := path
replayDateDirName := filepath.Base(filepath.Dir(path))
Expand Down Expand Up @@ -339,7 +387,7 @@ func uploadRemainReplay(jmsService *service.JMService, remainFiles map[string]st
sid + session.ReplayFileNameSuffix}, "/")
err = replayStorage.Upload(absGzPath, targetName)
} else {
err = jmsService.Upload(sid, absGzPath)
err = defaultStorage.Upload(sid, absGzPath)
}
if err != nil {
logger.Errorf("Upload replay failed: %s", err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common

import "os"

func FileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
Root string
DrivePath string
RecordPath string
FTPFilePath string
LogDirPath string
AccessKeyFilePath string
CertsFolderPath string
Expand Down Expand Up @@ -65,6 +66,7 @@ func getDefaultConfig() Config {
dataFolderPath := filepath.Join(rootPath, "data")
driveFolderPath := filepath.Join(dataFolderPath, "drive")
recordFolderPath := filepath.Join(dataFolderPath, "replays")
ftpFileFolderPath := filepath.Join(dataFolderPath, "ftp_files")
LogDirPath := filepath.Join(dataFolderPath, "logs")
keyFolderPath := filepath.Join(dataFolderPath, "keys")
CertsFolderPath := filepath.Join(dataFolderPath, "certs")
Expand All @@ -81,6 +83,7 @@ func getDefaultConfig() Config {
Name: defaultName,
Root: rootPath,
RecordPath: recordFolderPath,
FTPFilePath: ftpFileFolderPath,
LogDirPath: LogDirPath,
DrivePath: driveFolderPath,
CertsFolderPath: CertsFolderPath,
Expand Down
2 changes: 2 additions & 0 deletions pkg/jms-sdk-go/model/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

type FTPLog struct {
ID string `json:"id"`
User string `json:"user"`
Hostname string `json:"asset"`
OrgID string `json:"org_id"`
Expand All @@ -14,6 +15,7 @@ type FTPLog struct {
Path string `json:"filename"`
DateStart common.UTCTime `json:"date_start"`
IsSuccess bool `json:"is_success"`
Session string `json:"session"`
}

const (
Expand Down
1 change: 1 addition & 0 deletions pkg/jms-sdk-go/model/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type TerminalConfig struct {
MaxIdleTime int `json:"SECURITY_MAX_IDLE_TIME"`
HeartbeatDuration int `json:"TERMINAL_HEARTBEAT_INTERVAL"`
HostKey string `json:"TERMINAL_HOST_KEY"`
MaxStoreFTPFileSize int `json:"FTP_FILE_MAX_STORE"`
}

type Terminal struct {
Expand Down
9 changes: 9 additions & 0 deletions pkg/jms-sdk-go/model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type ConnectToken struct {

ConnectMethod ConnectMethod `json:"connect_method"`

ConnectOptions ConnectOptions `json:"connect_options"`

Ticket *ObjectId `json:"from_ticket,omitempty"`
TicketInfo interface{} `json:"from_ticket_info,omitempty"`

Expand All @@ -34,3 +36,10 @@ type ConnectMethod struct {
type ObjectId struct {
ID string `json:"id"`
}

type ConnectOptions struct {
Charset string `json:"charset"`
DisableAutoHash bool `json:"disableautohash"`
Resolution string `json:"resolution"`
BackspaceAsCtrlH bool `json:"backspaceAsCtrlH"`
}
15 changes: 15 additions & 0 deletions pkg/jms-sdk-go/service/jms_audit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package service

import (
"fmt"

"lion/pkg/jms-sdk-go/model"
)

Expand All @@ -13,3 +15,16 @@ func (s *JMService) PushSessionCommand(commands []*model.Command) (err error) {
_, err = s.authClient.Post(SessionCommandURL, commands, nil)
return
}

func (s *JMService) UploadFTPFile(fid, file string) error {
var res map[string]interface{}
url := fmt.Sprintf(FTPLogFileURL, fid)
return s.authClient.PostFileWithFields(url, file, nil, &res)
}

func (s *JMService) FinishFTPFile(fid string) error {
data := map[string]bool{"has_file": true}
url := fmt.Sprintf(FTPLogUpdateURL, fid)
_, err := s.authClient.Patch(url, data, nil)
return err
}
6 changes: 1 addition & 5 deletions pkg/jms-sdk-go/service/jms_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import (
"lion/pkg/jms-sdk-go/model"
)

func (s *JMService) Upload(sessionID, gZipFile string) error {
func (s *JMService) UploadReplay(sid, gZipFile string) error {
version := model.ParseReplayVersion(gZipFile, model.Version2)
return s.UploadReplay(sessionID, gZipFile, version)
}

func (s *JMService) UploadReplay(sid, gZipFile string, version model.ReplayVersion) error {
var res map[string]interface{}
Url := fmt.Sprintf(SessionReplayURL, sid)
fields := make(map[string]string)
Expand Down
2 changes: 2 additions & 0 deletions pkg/jms-sdk-go/service/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
FinishTaskURL = "/api/v1/terminal/tasks/%s/"
JoinRoomValidateURL = "/api/v1/terminal/sessions/join/validate/"
FTPLogListURL = "/api/v1/audits/ftp-logs/" // 上传 ftp日志
FTPLogFileURL = "/api/v1/audits/ftp-logs/%s/upload/"
FTPLogUpdateURL = "/api/v1/audits/ftp-logs/%s/"
)

// 各资源详情相关API
Expand Down
Loading

0 comments on commit 0404600

Please sign in to comment.