Skip to content

Commit

Permalink
perf: support to write part replay
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Sep 2, 2024
1 parent c7966ce commit 7021ce4
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 25 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo
ctx.File("./ui/dist/index.html")
})
}
{
monitorGroup := lionGroup.Group("/replay")
monitorGroup.Use(middleware.JmsCookieAuth(jmsService))
monitorGroup.Any("", func(ctx *gin.Context) {
ctx.File("./ui/dist/index.html")
})
}

{
shareGroup := lionGroup.Group("/share")
Expand Down Expand Up @@ -282,6 +289,7 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo

wsGroup.Group("/token").Use(
middleware.SessionAuth(jmsService)).GET("/", tunnelService.Connect)

}

{
Expand Down
11 changes: 10 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
LogDirPath string
AccessKeyFilePath string
CertsFolderPath string
SessionFolderPath string

Name string `mapstructure:"NAME"`
CoreHost string `mapstructure:"CORE_HOST"`
Expand Down Expand Up @@ -56,6 +57,8 @@ type Config struct {
IgnoreVerifyCerts bool `mapstructure:"IGNORE_VERIFY_CERTS"`
PandaHost string `mapstructure:"PANDA_HOST"`
EnablePanda bool `mapstructure:"ENABLE_PANDA"`

ReplayMaxSize int `mapstructure:"REPLAY_MAX_SIZE"`
}

func (c *Config) SelectGuacdAddr() string {
Expand All @@ -81,14 +84,15 @@ func getDefaultConfig() Config {
dataFolderPath := filepath.Join(rootPath, "data")
driveFolderPath := filepath.Join(dataFolderPath, "drive")
recordFolderPath := filepath.Join(dataFolderPath, "replays")
sessionsPath := filepath.Join(dataFolderPath, "sessions")
ftpFileFolderPath := filepath.Join(dataFolderPath, "ftp_files")
LogDirPath := filepath.Join(dataFolderPath, "logs")
keyFolderPath := filepath.Join(dataFolderPath, "keys")
CertsFolderPath := filepath.Join(dataFolderPath, "certs")
accessKeyFilePath := filepath.Join(keyFolderPath, ".access_key")

folders := []string{dataFolderPath, driveFolderPath, recordFolderPath,
keyFolderPath, LogDirPath, CertsFolderPath}
keyFolderPath, LogDirPath, CertsFolderPath, sessionsPath}
for i := range folders {
if err := EnsureDirExist(folders[i]); err != nil {
log.Fatalf("Create folder failed: %s", err.Error())
Expand All @@ -103,6 +107,7 @@ func getDefaultConfig() Config {
DrivePath: driveFolderPath,
CertsFolderPath: CertsFolderPath,
AccessKeyFilePath: accessKeyFilePath,
SessionFolderPath: sessionsPath,
CoreHost: "http://localhost:8080",
BootstrapToken: "",
BindHost: "0.0.0.0",
Expand All @@ -116,10 +121,14 @@ func getDefaultConfig() Config {
EnableRemoteAPPCopyPaste: false,
CleanDriveScheduleTime: 1,
PandaHost: "http://localhost:9001",
ReplayMaxSize: defaultMaxSize,
}

}

// 300MB
const defaultMaxSize = 1024 * 1024 * 300

func EnsureDirExist(path string) error {
if !haveDir(path) {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/guacd/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ func (conf *Configuration) UnSetParameter(name string) {
func (conf *Configuration) GetParameter(name string) string {
return conf.Parameters[name]
}

func (conf *Configuration) Clone() Configuration {
newConf := NewConfiguration()
newConf.ConnectionID = conf.ConnectionID
newConf.Protocol = conf.Protocol
for k, v := range conf.Parameters {
newConf.Parameters[k] = v
}
return newConf
}
11 changes: 11 additions & 0 deletions pkg/guacd/information.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ func (info *ClientInformation) ExtraConfig() map[string]string {
}
return ret
}

func (info *ClientInformation) Clone() ClientInformation {
return ClientInformation{
OptimalScreenWidth: info.OptimalScreenWidth,
OptimalScreenHeight: info.OptimalScreenHeight,
OptimalResolution: info.OptimalResolution,
ImageMimetypes: []string{"image/jpeg", "image/png", "image/webp"},
Timezone: info.Timezone,
KeyboardLayout: info.KeyboardLayout,
}
}
2 changes: 0 additions & 2 deletions pkg/guacd/instruction_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package guacd

import (
"errors"
"testing"
)

Expand All @@ -28,7 +27,6 @@ func TestValidateInstructionString(t *testing.T) {
for i := range tests {
ins, err := ParseInstructionString(tests[i])
if err != nil {
t.Log(errors.As(err, &ErrInstructionBadDigit))
t.Log(err)
continue
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/guacd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ const (
WolBroadcastAddr = "wol-broadcast-addr"
WolWaitTime = "wol-wait-time"
)

const (
READONLY = "read-only"
)

const (
BoolFalse = "false"
BoolTrue = "true"
)
1 change: 1 addition & 0 deletions pkg/guacd/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func NewTunnel(address string, config Configuration, info ClientInformation) (tu

tunnel.uuid = ready.Args[0]
tunnel.IsOpen = true
tunnel.Config = config
return tunnel, nil
}

Expand Down
44 changes: 22 additions & 22 deletions pkg/session/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ func (r RDPConfiguration) GetGuacdConfiguration() guacd.Configuration {
conf.SetParameter(guacd.RDPDomain, adDomain)
}

// 设置 录像路径
if r.TerminalConfig.ReplayStorage.TypeName != "null" {
recordDirPath := filepath.Join(config.GlobalConfig.RecordPath,
r.Created.Format(recordDirTimeFormat))
conf.SetParameter(guacd.RecordingPath, recordDirPath)
conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
conf.SetParameter(guacd.RecordingName, r.SessionId)
}
//// 设置 录像路径
//if r.TerminalConfig.ReplayStorage.TypeName != "null" {
// recordDirPath := filepath.Join(config.GlobalConfig.RecordPath,
// r.Created.Format(recordDirTimeFormat))
// conf.SetParameter(guacd.RecordingPath, recordDirPath)
// conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
// conf.SetParameter(guacd.RecordingName, r.SessionId)
//}

// display 相关
{
Expand Down Expand Up @@ -181,13 +181,13 @@ func (r VNCConfiguration) GetGuacdConfiguration() guacd.Configuration {
conf.SetParameter(guacd.VNCAutoretry, "3")
}
// 设置存储
replayCfg := r.TerminalConfig.ReplayStorage
if replayCfg.TypeName != "null" {
recordDirPath := filepath.Join(config.GlobalConfig.RecordPath, r.Created.Format(recordDirTimeFormat))
conf.SetParameter(guacd.RecordingPath, recordDirPath)
conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
conf.SetParameter(guacd.RecordingName, r.SessionId)
}
//replayCfg := r.TerminalConfig.ReplayStorage
//if replayCfg.TypeName != "null" {
// recordDirPath := filepath.Join(config.GlobalConfig.RecordPath, r.Created.Format(recordDirTimeFormat))
// conf.SetParameter(guacd.RecordingPath, recordDirPath)
// conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
// conf.SetParameter(guacd.RecordingName, r.SessionId)
//}
{
for key, value := range VNCDisplay.GetDisplayParams() {
conf.SetParameter(key, value)
Expand Down Expand Up @@ -247,13 +247,13 @@ func (r VirtualAppConfiguration) GetGuacdConfiguration() guacd.Configuration {
conf.SetParameter(guacd.VNCAutoretry, "10")
}
// 设置存储
replayCfg := r.TerminalConfig.ReplayStorage
if replayCfg.TypeName != "null" {
recordDirPath := filepath.Join(config.GlobalConfig.RecordPath, r.Created.Format(recordDirTimeFormat))
conf.SetParameter(guacd.RecordingPath, recordDirPath)
conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
conf.SetParameter(guacd.RecordingName, r.SessionId)
}
//replayCfg := r.TerminalConfig.ReplayStorage
//if replayCfg.TypeName != "null" {
// recordDirPath := filepath.Join(config.GlobalConfig.RecordPath, r.Created.Format(recordDirTimeFormat))
// conf.SetParameter(guacd.RecordingPath, recordDirPath)
// conf.SetParameter(guacd.CreateRecordingPath, BoolTrue)
// conf.SetParameter(guacd.RecordingName, r.SessionId)
//}
{
for key, value := range VNCDisplay.GetDisplayParams() {
conf.SetParameter(key, value)
Expand Down
1 change: 1 addition & 0 deletions pkg/session/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func (s *Server) Create(ctx *gin.Context, opts ...TunnelOption) (sess TunnelSess
AccountID: opt.Account.ID,
Comment: comment,
}
sess.ModelSession = &jmsSession
sess.ConnectedCallback = s.RegisterConnectedCallback(jmsSession)
sess.ConnectedSuccessCallback = s.RegisterConnectedSuccessCallback(jmsSession)
sess.ConnectedFailedCallback = s.RegisterConnectedFailedCallback(jmsSession)
Expand Down
2 changes: 2 additions & 0 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type TunnelSession struct {
FinishReplayCallback func(guacd.ClientInformation) error `json:"-"`

ReleaseAppletAccount func() error `json:"-"`

ModelSession *model.Session `json:"-"`
}

const (
Expand Down
Loading

0 comments on commit 7021ce4

Please sign in to comment.