Skip to content

Commit

Permalink
Merge pull request #44 from jumpserver/dev
Browse files Browse the repository at this point in the history
v2.12 rc1
  • Loading branch information
BaiJiangJie authored Jul 8, 2021
2 parents a2c4178 + 614577e commit 8361311
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 68 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ jobs:
build/*.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: sync lion-release
env:
REPO_URL: jumpserver/lion-release
TAG_NAME: ${{ steps.get_version.outputs.TAG }}
BRANCH: master
ACCESS_TOKEN: ${{ secrets.PRIVATE_TOKEN }}
FILE_PATTERN: build/*.gz
run: |
wget "https://github.com/LeeEirc/ghaction/releases/download/v0.0.1/ghrcreate-linux-amd64"
chmod +x ghrcreate-linux-amd64 && ./ghrcreate-linux-amd64
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN export GOFlAGS="-X 'main.Buildstamp=`date -u '+%Y-%m-%d %I:%M:%S%p'`'" \
&& export GOFlAGS="${GOFlAGS} -X 'main.Version=${VERSION}'" \
&& go build -trimpath -x -ldflags "$GOFlAGS" -o lion . && ls -al .

FROM guacamole/guacd:1.3.0
FROM jumpserver/guacd:1.3.0
USER root
WORKDIR /opt/lion
ENV GUACD_LOG_LEVEL=debug
Expand All @@ -40,4 +40,4 @@ COPY --from=ui-build /opt/lion/ui/lion ui/lion/
COPY --from=go-build /opt/lion/lion .
COPY --from=go-build /opt/lion/config_example.yml .
COPY --from=go-build /opt/lion/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
CMD ["/usr/bin/supervisord"]
3 changes: 2 additions & 1 deletion pkg/common/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"compress/gzip"
"io"
"os"
"path/filepath"
"time"
)

Expand All @@ -19,7 +20,7 @@ func CompressToGzipFile(srcPath, dstPath string) error {
}
defer df.Close()
writer := gzip.NewWriter(df)
writer.Name = dstPath
writer.Name = filepath.Base(srcPath)
writer.ModTime = time.Now().UTC()
_, err = io.Copy(writer, sf)
if err != nil {
Expand Down
79 changes: 47 additions & 32 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ type Config struct {
}

func Setup(configPath string) {
viper.SetConfigFile(configPath)
viper.AutomaticEnv()
loadEnvToViper()
log.Println("Load config from env")
if err := viper.ReadInConfig(); err == nil {
log.Printf("Load config from %s success\n", configPath)
}
var conf = getDefaultConfig()
if err := viper.Unmarshal(&conf); err != nil {
log.Fatal(err)
}
loadConfigFromEnv(&conf)
loadConfigFromFile(configPath, &conf)
GlobalConfig = &conf
log.Printf("%+v\n", GlobalConfig)

Expand All @@ -61,9 +53,9 @@ func getDefaultConfig() Config {
rootPath := getPwdDirPath()
dataFolderPath := filepath.Join(rootPath, "data")
driveFolderPath := filepath.Join(dataFolderPath, "drive")
recordFolderPath := filepath.Join(dataFolderPath, "record")
LogDirPath := filepath.Join(dataFolderPath, "log")
keyFolderPath := filepath.Join(dataFolderPath, "key")
recordFolderPath := filepath.Join(dataFolderPath, "replays")
LogDirPath := filepath.Join(dataFolderPath, "logs")
keyFolderPath := filepath.Join(dataFolderPath, "keys")
accessKeyFilePath := filepath.Join(keyFolderPath, ".access_key")

folders := []string{dataFolderPath, driveFolderPath, recordFolderPath,
Expand All @@ -80,7 +72,7 @@ func getDefaultConfig() Config {
LogDirPath: LogDirPath,
DrivePath: driveFolderPath,
AccessKeyFilePath: accessKeyFilePath,
CoreHost: "http://127.0.0.1:8080",
CoreHost: "http://localhost:8080",
BootstrapToken: "",
BindHost: "0.0.0.0",
HTTPPort: "8081",
Expand All @@ -95,11 +87,13 @@ func getDefaultConfig() Config {

}

func getPwdDirPath() string {
if rootPath, err := os.Getwd(); err == nil {
return rootPath
func EnsureDirExist(path string) error {
if !haveDir(path) {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
}
return ""
return nil
}

func have(path string) bool {
Expand All @@ -112,13 +106,43 @@ func haveDir(file string) bool {
return err == nil && fi.IsDir()
}

func EnsureDirExist(path string) error {
if !haveDir(path) {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
func getPwdDirPath() string {
if rootPath, err := os.Getwd(); err == nil {
return rootPath
}
return ""
}

func loadConfigFromEnv(conf *Config) {
viper.AutomaticEnv() // 全局配置,用于其他 pkg 包可以用 viper 获取环境变量的值
envViper := viper.New()
for _, item := range os.Environ() {
envItem := strings.SplitN(item, "=", 2)
if len(envItem) == 2 {
envViper.Set(envItem[0], viper.Get(envItem[0]))
}
}
return nil
if err := envViper.Unmarshal(conf); err == nil {
log.Println("Load config from env")
}

}

func loadConfigFromFile(path string, conf *Config) {
var err error
if have(path) {
fileViper := viper.New()
fileViper.SetConfigFile(path)
if err = fileViper.ReadInConfig(); err == nil {
if err = fileViper.Unmarshal(conf); err == nil {
log.Printf("Load config from %s success\n", path)
return
}
}
}
if err != nil {
log.Fatalf("Load config from %s failed: %s\n", path, err)
}
}

const prefixName = "[Lion]"
Expand All @@ -135,12 +159,3 @@ func getDefaultName() string {
copy(name[16:], hostRune[start:])
return string(name)
}

func loadEnvToViper() {
for _, item := range os.Environ() {
envItem := strings.Split(item, "=")
if len(envItem) == 2 {
viper.Set(envItem[0], envItem[1])
}
}
}
32 changes: 3 additions & 29 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
package config

import (
"log"
"os"
"testing"

"github.com/spf13/viper"
)

func setupFromYmlFile() {
f, err := os.Open("config_test.yml")
if err != nil {
log.Fatal(err)
return
}
defer f.Close()
viper.SetConfigType("yml")
viper.AutomaticEnv()
err = viper.ReadConfig(f)
if err != nil {
log.Fatal(err)
}
}

func TestSetupByYml(t *testing.T) {
setupFromYmlFile()
var conf = getDefaultConfig()
if err := viper.Unmarshal(&conf); err != nil {
t.Fatalf("%s \n", err.Error())
}
loadConfigFromFile("config_test.yml", &conf)
t.Log(conf)
}

func TestSetupByEnv(t *testing.T) {
viper.AutomaticEnv()
loadEnvToViper()
var conf = getDefaultConfig()
if err := viper.Unmarshal(&conf); err != nil {
t.Fatalf("%s \n", err.Error())
}
t.Logf("%+v\n",conf)
loadConfigFromEnv(&conf)
t.Log(conf)
}
2 changes: 1 addition & 1 deletion pkg/config/config_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE_HSOT: http://10.0.0.5:8080
CORE_HOST: http://10.0.0.5:8080

BOOTSTRAP_TOKEN: ICAgICAgICBUWCBl

Expand Down
13 changes: 11 additions & 2 deletions pkg/tunnel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (g *GuacamoleTunnelServer) Connect(ctx *gin.Context) {
}
info := g.getClientInfo(ctx)
conf := tunnelSession.GuaConfiguration()
// 设置网域网关,替换本地
if tunnelSession.Domain != nil {
// 设置网域网关,替换本地。 兼容云平台同步 配置网域,但网关配置为空的情况
if tunnelSession.Domain != nil && len(tunnelSession.Domain.Gateways) != 0 {
dstAddr := net.JoinHostPort(conf.GetParameter(guacd.Hostname),
conf.GetParameter(guacd.Port))
domainGateway := gateway.DomainGateway{
Expand All @@ -121,6 +121,12 @@ func (g *GuacamoleTunnelServer) Connect(ctx *gin.Context) {
if err = domainGateway.Start(); err != nil {
logger.Errorf("Start domain gateway err: %+v", err)
_ = ws.WriteMessage(websocket.TextMessage, []byte(ErrGatewayFailed.String()))
if err = tunnelSession.ConnectedFailedCallback(err); err != nil {
logger.Errorf("Update session connect status failed %+v", err)
}
if err = tunnelSession.DisConnectedCallback(); err != nil {
logger.Errorf("Session DisConnectedCallback err: %+v", err)
}
return
}
defer domainGateway.Stop()
Expand All @@ -140,6 +146,9 @@ func (g *GuacamoleTunnelServer) Connect(ctx *gin.Context) {
if err = tunnelSession.ConnectedFailedCallback(err); err != nil {
logger.Errorf("Update session connect status failed %+v", err)
}
if err = tunnelSession.DisConnectedCallback(); err != nil {
logger.Errorf("Session DisConnectedCallback err: %+v", err)
}
return
}
defer tunnel.Close()
Expand Down
8 changes: 7 additions & 1 deletion ui/src/components/GuacamoleConnect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ export default {
var requestAudioStream = function requestAudioStream(client) {
// Create new audio stream, associating it with an AudioRecorder
const stream = client.createAudioStream(AUDIO_INPUT_MIMETYPE)
const recorder = Guacamole.AudioRecorder.getInstance(stream, AUDIO_INPUT_MIMETYPE)
let recorder
try {
recorder = Guacamole.AudioRecorder.getInstance(stream, AUDIO_INPUT_MIMETYPE)
} catch (e) {
console.log('Get audio recorder error, ignore')
recorder = null
}
// If creation of the AudioRecorder failed, simply end the stream
// eslint-disable-next-line brace-style
Expand Down

0 comments on commit 8361311

Please sign in to comment.