From 7990689949c6442c166b1d07218782e04aba8301 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 19 Aug 2021 00:04:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=20Windows=20W?= =?UTF-8?q?ebTerminal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/agent/pty/pty.go | 13 +++++++++++-- cmd/agent/pty/pty_windows.go | 4 ++-- resource/static/main.js | 2 ++ resource/template/common/footer.html | 2 +- resource/template/dashboard/terminal.html | 4 ++++ script/config.yaml | 3 ++- script/docker-compose.yaml | 2 +- script/install.sh | 1 + service/dao/dao.go | 2 +- 10 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8de6a6e808..af3721c06d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。

diff --git a/cmd/agent/pty/pty.go b/cmd/agent/pty/pty.go index c9d578cfa1..81e7497a15 100644 --- a/cmd/agent/pty/pty.go +++ b/cmd/agent/pty/pty.go @@ -4,12 +4,15 @@ package pty import ( + "errors" "os" "os/exec" opty "github.com/creack/pty" ) +var defaultShells = []string{"zsh", "fish", "bash", "sh"} + type Pty struct { tty *os.File cmd *exec.Cmd @@ -19,9 +22,15 @@ func DownloadDependency() { } func Start() (*Pty, error) { - shellPath := os.Getenv("SHELL") + var shellPath string + for i := 0; i < len(defaultShells); i++ { + shellPath, _ = exec.LookPath(defaultShells[i]) + if shellPath != "" { + break + } + } if shellPath == "" { - shellPath = "sh" + return nil, errors.New("没有可用终端") } cmd := exec.Command(shellPath) cmd.Env = append(os.Environ(), "TERM=xterm") diff --git a/cmd/agent/pty/pty_windows.go b/cmd/agent/pty/pty_windows.go index 19b4c9459c..2190419c71 100644 --- a/cmd/agent/pty/pty_windows.go +++ b/cmd/agent/pty/pty_windows.go @@ -73,12 +73,12 @@ func Start() (*Pty, error) { if err != nil { return nil, err } - tty, err := winpty.Open(path, shellPath) + tty, err := winpty.OpenDefault(path, shellPath) return &Pty{tty: tty}, err } func (pty *Pty) Write(p []byte) (n int, err error) { - return pty.tty.StdIn.Read(p) + return pty.tty.StdIn.Write(p) } func (pty *Pty) Read(p []byte) (n int, err error) { diff --git a/resource/static/main.js b/resource/static/main.js index cd0d1ad8f5..8292c14f32 100644 --- a/resource/static/main.js +++ b/resource/static/main.js @@ -163,6 +163,7 @@ function post(path, params, method = 'post') { const form = document.createElement('form'); form.method = method; form.action = path; + form.target = "_blank"; for (const key in params) { if (params.hasOwnProperty(key)) { @@ -176,6 +177,7 @@ function post(path, params, method = 'post') { document.body.appendChild(form); form.submit(); + document.removeChild(form); } function addOrEditServer(server, conf) { diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html index 19fcc82f93..ef19ded76b 100644 --- a/resource/template/common/footer.html +++ b/resource/template/common/footer.html @@ -9,7 +9,7 @@ - + diff --git a/resource/template/dashboard/terminal.html b/resource/template/dashboard/terminal.html index ce1081b048..9e2b8df1ee 100644 --- a/resource/template/dashboard/terminal.html +++ b/resource/template/dashboard/terminal.html @@ -40,6 +40,10 @@ term.loadAddon(fitAddon); term.open(document.getElementById('terminal-container')); + socket.onopen = () => { + onResize() + } + function onResize() { fitAddon.fit() const w = fitAddon.proposeDimensions(); diff --git a/script/config.yaml b/script/config.yaml index 60b6d4da64..5a94d60e75 100644 --- a/script/config.yaml +++ b/script/config.yaml @@ -1,5 +1,6 @@ debug: false -httpport: 80 +httpport: nz_grpc_port +grpcport: oauth2: type: "nz_oauth2_type" #Oauth2 登录接入类型,gitee/github admin: "nz_admin_logins" #管理员列表,半角逗号隔开 diff --git a/script/docker-compose.yaml b/script/docker-compose.yaml index 0f76d55e31..025d481bcc 100644 --- a/script/docker-compose.yaml +++ b/script/docker-compose.yaml @@ -8,4 +8,4 @@ services: - ./data:/dashboard/data ports: - nz_site_port:80 - - nz_grpc_port:5555 + - nz_grpc_port:nz_grpc_port diff --git a/script/install.sh b/script/install.sh index 6671a715cc..b0e05c56d8 100755 --- a/script/install.sh +++ b/script/install.sh @@ -305,6 +305,7 @@ modify_dashboard_config() { sed -i "s/nz_oauth2_type/${nz_oauth2_type}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_admin_logins/${nz_admin_logins}/" ${NZ_DASHBOARD_PATH}/data/config.yaml + sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" ${NZ_DASHBOARD_PATH}/data/config.yaml sed -i "s/nz_site_title/${nz_site_title}/" ${NZ_DASHBOARD_PATH}/data/config.yaml diff --git a/service/dao/dao.go b/service/dao/dao.go index 151f81cd4d..45392d67d1 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.9.22" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.9.23" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config