Skip to content

Commit

Permalink
🐛 修复 Windows WebTerminal
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Aug 18, 2021
1 parent 2d30b2c commit 7990689
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.22&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.6.7-brightgreen?style=for-the-badge&logo=linux">
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.23&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.6.7-brightgreen?style=for-the-badge&logo=linux">
<br>
<br>
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
Expand Down
13 changes: 11 additions & 2 deletions cmd/agent/pty/pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/pty/pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions resource/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -176,6 +177,7 @@ function post(path, params, method = 'post') {

document.body.appendChild(form);
form.submit();
document.removeChild(form);
}

function addOrEditServer(server, conf) {
Expand Down
2 changes: 1 addition & 1 deletion resource/template/common/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script>
<script src="/static/semantic-ui-alerts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="/static/main.js?v20210817"></script>
<script src="/static/main.js?v20210818"></script>
</body>

</html>
Expand Down
4 changes: 4 additions & 0 deletions resource/template/dashboard/terminal.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
term.loadAddon(fitAddon);
term.open(document.getElementById('terminal-container'));

socket.onopen = () => {
onResize()
}

function onResize() {
fitAddon.fit()
const w = fitAddon.proposeDimensions();
Expand Down
3 changes: 2 additions & 1 deletion script/config.yaml
Original file line number Diff line number Diff line change
@@ -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" #管理员列表,半角逗号隔开
Expand Down
2 changes: 1 addition & 1 deletion script/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
- ./data:/dashboard/data
ports:
- nz_site_port:80
- nz_grpc_port:5555
- nz_grpc_port:nz_grpc_port
1 change: 1 addition & 0 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7990689

Please sign in to comment.