Commit 8077bf91 authored by Eric's avatar Eric

修改配置, 并移除无效的配置项

parent 57f5c221
...@@ -24,16 +24,9 @@ BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver> ...@@ -24,16 +24,9 @@ BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>
# ACCESS KEY 保存的地址, 默认注册后会保存到该文件中 # ACCESS KEY 保存的地址, 默认注册后会保存到该文件中
# ACCESS_KEY_FILE: data/keys/.access_key # ACCESS_KEY_FILE: data/keys/.access_key
# 加密密钥
# SECRET_KEY: null
# 设置日志级别 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL] # 设置日志级别 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL]
# LOG_LEVEL: INFO # LOG_LEVEL: INFO
# 和Jumpserver 保持心跳时间间隔 (seconds)
# HEARTBEAT_INTERVAL: 5
# SSH连接超时时间 (default 15 seconds) # SSH连接超时时间 (default 15 seconds)
# SSH_TIMEOUT: 15 # SSH_TIMEOUT: 15
......
...@@ -24,11 +24,11 @@ type Config struct { ...@@ -24,11 +24,11 @@ type Config struct {
SessionKeepDuration time.Duration `json:"TERMINAL_SESSION_KEEP_DURATION"` SessionKeepDuration time.Duration `json:"TERMINAL_SESSION_KEEP_DURATION"`
TelnetRegex string `json:"TERMINAL_TELNET_REGEX"` TelnetRegex string `json:"TERMINAL_TELNET_REGEX"`
MaxIdleTime time.Duration `json:"SECURITY_MAX_IDLE_TIME"` MaxIdleTime time.Duration `json:"SECURITY_MAX_IDLE_TIME"`
HeartbeatDuration time.Duration `json:"TERMINAL_HEARTBEAT_INTERVAL"`
SftpRoot string `json:"TERMINAL_SFTP_ROOT" yaml:"SFTP_ROOT"` SftpRoot string `json:"TERMINAL_SFTP_ROOT" yaml:"SFTP_ROOT"`
ShowHiddenFile bool `yaml:"SFTP_SHOW_HIDDEN_FILE"` ShowHiddenFile bool `yaml:"SFTP_SHOW_HIDDEN_FILE"`
ReuseConnection bool `yaml:"REUSE_CONNECTION"` ReuseConnection bool `yaml:"REUSE_CONNECTION"`
Name string `yaml:"NAME"` Name string `yaml:"NAME"`
SecretKey string `yaml:"SECRET_KEY"`
HostKeyFile string `yaml:"HOST_KEY_FILE"` HostKeyFile string `yaml:"HOST_KEY_FILE"`
CoreHost string `yaml:"CORE_HOST"` CoreHost string `yaml:"CORE_HOST"`
BootstrapToken string `yaml:"BOOTSTRAP_TOKEN"` BootstrapToken string `yaml:"BOOTSTRAP_TOKEN"`
...@@ -39,7 +39,6 @@ type Config struct { ...@@ -39,7 +39,6 @@ type Config struct {
AccessKey string `yaml:"ACCESS_KEY"` AccessKey string `yaml:"ACCESS_KEY"`
AccessKeyFile string `yaml:"ACCESS_KEY_FILE"` AccessKeyFile string `yaml:"ACCESS_KEY_FILE"`
LogLevel string `yaml:"LOG_LEVEL"` LogLevel string `yaml:"LOG_LEVEL"`
HeartbeatDuration time.Duration `yaml:"HEARTBEAT_INTERVAL"`
RootPath string `yaml:"ROOT_PATH"` RootPath string `yaml:"ROOT_PATH"`
Comment string `yaml:"COMMENT"` Comment string `yaml:"COMMENT"`
Language string `yaml:"LANG"` Language string `yaml:"LANG"`
...@@ -55,6 +54,9 @@ func (c *Config) EnsureConfigValid() { ...@@ -55,6 +54,9 @@ func (c *Config) EnsureConfigValid() {
if c.LanguageCode != "" && c.Language == "" { if c.LanguageCode != "" && c.Language == "" {
c.Language = c.LanguageCode c.Language = c.LanguageCode
} }
if c.Language == ""{
c.Language = "zh"
}
// 确保至少有一个认证 // 确保至少有一个认证
if !c.PublicKeyAuth && !c.PasswordAuth { if !c.PublicKeyAuth && !c.PasswordAuth {
c.PasswordAuth = true c.PasswordAuth = true
...@@ -129,7 +131,6 @@ var Conf = &Config{ ...@@ -129,7 +131,6 @@ var Conf = &Config{
HostKey: "", HostKey: "",
RootPath: rootPath, RootPath: rootPath,
Comment: "Coco", Comment: "Coco",
Language: "zh",
ReplayStorage: map[string]interface{}{"TYPE": "server"}, ReplayStorage: map[string]interface{}{"TYPE": "server"},
CommandStorage: map[string]interface{}{"TYPE": "server"}, CommandStorage: map[string]interface{}{"TYPE": "server"},
UploadFailedReplay: true, UploadFailedReplay: true,
......
...@@ -31,7 +31,7 @@ func (c *Coco) Start() { ...@@ -31,7 +31,7 @@ func (c *Coco) Start() {
func (c *Coco) Stop() { func (c *Coco) Stop() {
sshd.StopServer() sshd.StopServer()
httpd.StopHTTPServer() httpd.StopHTTPServer()
logger.Debug("Quit The Coco") logger.Info("Quit The Coco")
} }
func RunForever() { func RunForever() {
......
...@@ -19,7 +19,7 @@ func Initial() { ...@@ -19,7 +19,7 @@ func Initial() {
go uploadRemainReplay(conf.RootPath) go uploadRemainReplay(conf.RootPath)
} }
go keepHeartbeat(conf.HeartbeatDuration) go keepHeartbeat()
} }
// uploadRemainReplay 上传遗留的录像 // uploadRemainReplay 上传遗留的录像
...@@ -37,7 +37,7 @@ func uploadRemainReplay(rootPath string) { ...@@ -37,7 +37,7 @@ func uploadRemainReplay(rootPath string) {
} }
var sid string var sid string
filename := info.Name() filename := info.Name()
if len(filename) == 36{ if len(filename) == 36 {
sid = filename sid = filename
} }
if strings.HasSuffix(filename, ".replay.gz") { if strings.HasSuffix(filename, ".replay.gz") {
...@@ -46,8 +46,8 @@ func uploadRemainReplay(rootPath string) { ...@@ -46,8 +46,8 @@ func uploadRemainReplay(rootPath string) {
sid = sidName sid = sidName
} }
} }
if sid != ""{ if sid != "" {
data := map[string]interface{}{"id":sid,"date_end":info.ModTime().UTC().Format( data := map[string]interface{}{"id": sid, "date_end": info.ModTime().UTC().Format(
"2006-01-02 15:04:05 +0000")} "2006-01-02 15:04:05 +0000")}
service.FinishSession(data) service.FinishSession(data)
allRemainFiles[sid] = path allRemainFiles[sid] = path
...@@ -56,21 +56,21 @@ func uploadRemainReplay(rootPath string) { ...@@ -56,21 +56,21 @@ func uploadRemainReplay(rootPath string) {
return nil return nil
}) })
for sid, path := range allRemainFiles{ for sid, path := range allRemainFiles {
var absGzPath string var absGzPath string
if strings.HasSuffix(path, ".replay.gz") { if strings.HasSuffix(path, ".replay.gz") {
absGzPath = path absGzPath = path
}else if strings.HasSuffix(path, sid) { } else if strings.HasSuffix(path, sid) {
if err := ValidateRemainReplayFile(path); err != nil{ if err := ValidateRemainReplayFile(path); err != nil {
continue continue
} }
absGzPath = path + ".replay.gz" absGzPath = path + ".replay.gz"
if err := common.GzipCompressFile(path,absGzPath); err != nil{ if err := common.GzipCompressFile(path, absGzPath); err != nil {
continue continue
} }
_ = os.Remove(path) _ = os.Remove(path)
} }
relayRecord := &proxy.ReplyRecorder{SessionID:sid} relayRecord := &proxy.ReplyRecorder{SessionID: sid}
relayRecord.AbsGzFilePath = absGzPath relayRecord.AbsGzFilePath = absGzPath
relayRecord.Target, _ = filepath.Rel(path, rootPath) relayRecord.Target, _ = filepath.Rel(path, rootPath)
relayRecord.UploadGzipFile(3) relayRecord.UploadGzipFile(3)
...@@ -79,44 +79,41 @@ func uploadRemainReplay(rootPath string) { ...@@ -79,44 +79,41 @@ func uploadRemainReplay(rootPath string) {
} }
// keepHeartbeat 保持心跳 // keepHeartbeat 保持心跳
func keepHeartbeat(interval time.Duration) { func keepHeartbeat() {
tick := time.Tick(interval * time.Second)
for { for {
select { time.Sleep(config.GetConf().HeartbeatDuration * time.Second)
case <-tick: data := proxy.GetAliveSessions()
data := proxy.GetAliveSessions() tasks := service.TerminalHeartBeat(data)
tasks := service.TerminalHeartBeat(data) if len(tasks) != 0 {
if len(tasks) != 0 { for _, task := range tasks {
for _, task := range tasks { proxy.HandleSessionTask(task)
proxy.HandleSessionTask(task)
}
} }
} }
} }
} }
func ValidateRemainReplayFile(path string) error{ func ValidateRemainReplayFile(path string) error {
f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND,os.ModePerm) f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND, os.ModePerm)
if err != nil{ if err != nil {
return err return err
} }
defer f.Close() defer f.Close()
tmp := make([]byte,1) tmp := make([]byte, 1)
_, err = f.Seek(-1,2) _, err = f.Seek(-1, 2)
if err != nil{ if err != nil {
return err return err
} }
_, err = f.Read(tmp) _, err = f.Read(tmp)
if err != nil{ if err != nil {
return err return err
} }
switch string(tmp) { switch string(tmp) {
case "}": case "}":
return nil return nil
case ",": case ",":
_,err = f.Write([]byte(`"0":""}`)) _, err = f.Write([]byte(`"0":""}`))
default: default:
_,err = f.Write([]byte(`}`)) _, err = f.Write([]byte(`}`))
} }
return err return err
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment