Skip to content

Commit

Permalink
Merge pull request #358 from jumpserver/dev
Browse files Browse the repository at this point in the history
merge: from dev to master
  • Loading branch information
BaiJiangJie authored Sep 19, 2024
2 parents 414785b + 7bc9390 commit 3acc785
Show file tree
Hide file tree
Showing 22 changed files with 875 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: golangci-lint
on:
pull_request:
push:
branches:
- dev

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Create ui/dist directory
run: |
mkdir -p ui/dist
touch ui/dist/.gitkeep
- uses: actions/setup-go@v5
with:
go-version: stable

- uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
45 changes: 28 additions & 17 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,49 @@ jobs:
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
/usr/local/share/.cache/yarn
key: ${{ runner.os }}-lion
restore-keys: ${{ runner.os }}-lion

- name: Get version
id: get_version
run: |
TAG=$(basename ${GITHUB_REF})
VERSION=${TAG/v/}
echo "::set-output name=TAG::$TAG"
echo "::set-output name=VERSION::$VERSION"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: release-drafter/release-drafter@v5
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config-name: release-config.yml
version: ${{ steps.get_version.outputs.TAG }}
tag: ${{ steps.get_version.outputs.TAG }}
- uses: actions/setup-node@v2
version: ${{ env.TAG }}
tag: ${{ env.TAG }}

- uses: actions/setup-node@v4
with:
node-version: '16.20'
- uses: actions/setup-go@v2
node-version: '20.15'

- uses: actions/setup-go@v5
with:
go-version: '1.22.x' # The Go version to download (if necessary) and use.
go-version: '1.22' # The Go version to download (if necessary) and use.

- name: Make Build
id: make_build
env:
VERSION: ${{ steps.get_version.outputs.TAG }}
run: |
make all -s && ls build
make all -s && ls build
env:
VERSION: ${{ env.TAG }}

- name: Release Upload Assets
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
Expand Down
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
run:
timeout: 5m
modules-download-mode: readonly

issues:
exclude-dirs:
- docs
- ui
- .git

exclude-files:
- pkg/utils/terminal.go

linters:
enable:
- govet
- staticcheck

output:
format: colored-line-number
70 changes: 70 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2

project_name: lion

before:
hooks:
- go mod tidy
- go generate ./...

snapshot:
version_template: "{{ .Tag }}-next"

builds:
- id: lion
main: main.go
binary: lion
goos:
- linux
- darwin
- freebsd
- netbsd
goarch:
- amd64
- arm64
- mips64le
- ppc64le
- s390x
- riscv64
- loong64
env:
- CGO_ENABLED=0
ldflags:
- -w -s
- -X 'main.Buildstamp={{ .Date }}'
- -X 'main.Githash={{ .ShortCommit }}'
- -X 'main.Goversion={{ .Env.GOVERSION }}'
- -X 'main.Version={{ .Tag }}'

archives:
- format: tar.gz
wrap_in_directory: true
files:
- LICENSE
- README.md
- config_example.yml
- ui/dist/**

format_overrides:
- goos: windows
format: zip
name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{- if .Arm }}v{{ .Arm }}{{ end }}"

checksum:
name_template: "{{ .ProjectName }}_checksums.txt"

release:
draft: true
mode: append
extra_files:
- glob: dist/*.tar.gz
- glob: dist/*.txt
name_template: "Release {{.Tag}}"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
NAME=lion
BUILDDIR=build
VERSION ?=Unknown
BuildTime:=$(shell date -u '+%Y-%m-%d %I:%M:%S%p')
COMMIT:=$(shell git rev-parse HEAD)
GOVERSION:=$(shell go version)

GOOS:=$(shell go env GOOS)
GOARCH:=$(shell go env GOARCH)
VERSION ?= Unknown
BuildTime := $(shell date -u '+%Y-%m-%d %I:%M:%S%p')
COMMIT := $(shell git rev-parse HEAD)
GOVERSION := $(shell go version)

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

LDFLAGS=-w -s

Expand All @@ -18,8 +19,6 @@ GOLDFLAGS+=-X 'main.Goversion=$(GOVERSION)'
GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(GOLDFLAGS) ${LDFLAGS}"

UIDIR=ui
NPMINSTALL=yarn
NPMBUILD=yarn build

define make_artifact_full
GOOS=$(1) GOARCH=$(2) $(GOBUILD) -o $(BUILDDIR)/$(NAME)-$(1)-$(2)
Expand Down Expand Up @@ -80,7 +79,7 @@ docker:

lion-ui:
@echo "build ui"
@cd $(UIDIR) && $(NPMINSTALL) && $(NPMBUILD)
@cd $(UIDIR) && yarn install && yarn build

clean:
rm -rf $(BUILDDIR)
Expand Down
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo

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

}

{
Expand Down Expand Up @@ -316,9 +317,11 @@ func registerRouter(jmsService *service.JMService, tunnelService *tunnel.Guacamo
func bootstrap(jmsService *service.JMService) {
replayDir := config.GlobalConfig.RecordPath
ftpFilePath := config.GlobalConfig.FTPFilePath
sessionDir := config.GlobalConfig.SessionFolderPath
allRemainFiles := scanRemainReplay(jmsService, replayDir)
go uploadRemainReplay(jmsService, allRemainFiles)
go uploadRemainFTPFile(jmsService, ftpFilePath)
go uploadRemainSessionPartReplay(jmsService, sessionDir)
}

func uploadRemainFTPFile(jmsService *service.JMService, fileStoreDir string) {
Expand Down Expand Up @@ -434,6 +437,30 @@ func scanRemainReplay(jmsService *service.JMService, replayDir string) map[strin
return allRemainFiles
}

func uploadRemainSessionPartReplay(jmsService *service.JMService, sessionDir string) {
sessions, err := os.ReadDir(sessionDir)
if err != nil {
logger.Errorf("Read session dir failed: %s", err)
return
}
terminalConf, _ := jmsService.GetTerminalConfig()
for _, sessionEntry := range sessions {
sessionId := sessionEntry.Name()
if !common.ValidUUIDString(sessionId) {
continue
}
sessionRootPath := filepath.Join(sessionDir, sessionId)
uploader := tunnel.PartUploader{
RootPath: sessionRootPath,
SessionId: sessionId,
ApiClient: jmsService,
TermCfg: &terminalConf,
}
uploader.Start()
logger.Infof("Upload remain session part replay %s finish", sessionId)
}
}

func GetStatusData(tunnelCache *tunnel.GuaTunnelCacheManager) interface{} {
sids := tunnelCache.RangeActiveSessionIds()
payload := model.HeartbeatData{
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,
}
}
Loading

0 comments on commit 3acc785

Please sign in to comment.