Skip to content

Commit b174b88

Browse files
authored
Merge branch 'master' into master
2 parents 843451c + e4fbd53 commit b174b88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+23089
-28738
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ _testmain.go
2222
*.bak
2323
*.[568vq]
2424
[568vq].out
25-
bin/*
2625
bin/apibox
2726

2827
.vscode/tasks.json

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// 将设置放入此文件中以覆盖默认值和用户设置。
22
{
3-
"go.gopath": "/Users/shibingli/Develop/Go_Code/webconsole"
3+
"go.gopath": "${workspaceRoot}"
44
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.8.1-alpine
1+
FROM golang:1.8.3-alpine
22

33
MAINTAINER Eric Shi <[email protected]>
44
ADD . /go/

README.md

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
##欢迎大家踊跃报名,利用业余时间来拓展此项目,增加更多的功能服务大家。
2-
==================
1+
# 欢迎大家踊跃报名,利用业余时间来拓展此项目,增加更多的功能服务大家。
32

4-
##常规部署
5-
------------------
3+
## 常规部署
64
```
75
1、下载 go1.8.1.linux-amd64.tar.gz
86
2、tar zxvf go1.8.1.linux-amd64.tar.gz -C /usr/local
@@ -11,49 +9,54 @@
119
5、cd /opt && git clone --recurse-submodules https://github.com/shibingli/webconsole.git && cd webconsole && git submodule update --init --recursive
1210
6、cd /opt/webconsole/src/apibox.club/apibox
1311
7、GOPATH=/opt/webconsole go install
12+
8、设置开机自动启动
13+
cp /opt/webconsole/bin/webconsole /etc/init.d/ && chmod 755 /etc/init.d/webconsole
14+
chkconfig --add webconsole && chkconfig webconsole on && service webconsole start
15+
16+
1417
```
1518

1619
[下载 Golang](https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz)
1720

1821

19-
##容器部署
20-
------------------
22+
## 容器部署
2123
```
2224
1、下载并安装 Docker
2325
2、cd /opt && git clone --recurse-submodules https://github.com/shibingli/webconsole.git && cd webconsole && git submodule update --init --recursive
24-
3、cd /opt/webconsole
25-
4、docker build -t webconsole:latest .
26-
5、docker run -d -p 8080:8080 --restart=always --name webconsole webconsole:latest
26+
3、cd /opt/webconsole/src/apibox.club/apibox
27+
4、GOPATH=/opt/webconsole go install
28+
5、cd /opt/webconsole
29+
6、docker build -t webconsole:latest .
30+
7、docker run -d -p 8080:8080 --restart=always --name webconsole webconsole:latest
2731
```
2832

2933
[安装 Docker](https://docs.docker.com/engine/installation/)
3034

3135

32-
##开源捐献日志(感谢各位网友的支持)
33-
==================
34-
35-
2017.04.05
36+
## 更新日志
3637

37-
@木乃伊(qq:357573995) 捐献:100.00 元(人民币)
38+
2018.12.28
3839

39-
2017.04.05
40-
41-
@朱小四(weichat:juechengke) 捐献:200.00 元(人民币)
40+
更新:
4241

43-
2017.02.25
42+
1、更新核心js库
43+
2、合并 pczchen 提交的分支,支持 Docker 容器访问
44+
3、常规修复
4445

45-
@jerry2049 捐献:100.00 元(人民币)
46+
2017.07.31
4647

47-
2016.03.13
48+
更新:
4849

49-
@非非不在家(qq:762810120) 捐献:8.88 元(人民币)
50+
1、更新 xTerm.js
5051

51-
2016.05.16
52+
2017.07.20
5253

53-
@玩蝴蝶的法师(qq:43588476) 捐献:50.00 元(人民币)
54+
修证:
5455

55-
##更新日志
56-
==================
56+
1、修证UTF-8字符集展示BUG;
57+
2、修证大文件展示BUG。
58+
59+
    本次BUG由 @AEGQ 修证和贡献代码
5760

5861
2017.04.19
5962

@@ -156,14 +159,12 @@
156159
1、增加后台运行模式(conf/conf.json. daemon:true/false);
157160
2、增加程序运行时的PID文件(log/apibox.pid);
158161

159-
##大概的数据流向:
160-
==================
162+
## 大概的数据流向:
161163
```
162164
浏览器--》WebSocket--》SSH--》Linux OS
163165
```
164166

165-
###代码地址
166-
=================
167+
### 代码地址
167168

168169
[Git@OSC](http://git.oschina.net/shibingli/webconsole)
169170

@@ -174,8 +175,7 @@
174175
[演示地址](http://webconsole.realclouds.org)
175176

176177

177-
##程序包结构:
178-
================
178+
## 程序包结构:
179179

180180
```
181181
├── bin
@@ -235,12 +235,11 @@
235235

236236
2)、成功获取到加密的 en_addr 信息后,以 GET 或 POST 方式访问 "http(s)://ip:port/console/login/'en_addr'" 即可。注: "en_addr" 是通过第 1)步操作获取的数据。
237237

238-
##JQuery Demo:
239-
======
238+
## JQuery Demo:
240239

241240
242-
###第一种方式(需要二次登陆,同一个域的情况,同样可以使用跨域的方式访问):
243-
======
241+
### 第一种方式(需要二次登陆,同一个域的情况,同样可以使用跨域的方式访问):
242+
244243

245244
```javascript
246245
var protocol = (location.protocol === "https:") ? "https://" : "http://";
@@ -261,8 +260,7 @@ $.post(addr+"/console/chksshdaddr?rnd=" + Math.random(), {
261260

262261

263262

264-
###第二种方式(直接输入远端的主机地址、用户名、密码,然后直接登陆。跨域的情况):
265-
======
263+
### 第二种方式(直接输入远端的主机地址、用户名、密码,然后直接登陆。跨域的情况):
266264

267265
```html
268266
<button class="btn btn-primary" onclick="testDemo();">Test</button>

bin/webconsole

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#! /bin/sh
2+
# chkconfig: 2345 85 15
3+
# Description: Startup script for webconsole webserver on Debian. Place in /etc/init.d and
4+
# run 'update-rc.d -f webconsole defaults', or use the appropriate command on your
5+
# distro. For CentOS/Redhat run: 'chkconfig --add webconsole'
6+
7+
### BEGIN INIT INFO
8+
# Provides: webconsole
9+
# Required-Start: $all
10+
# Required-Stop: $all
11+
# Default-Start: 2 3 4 5
12+
# Default-Stop: 0 1 6
13+
# Short-Description: starts the webconsole web server
14+
# Description: starts webconsole using start-stop-daemon
15+
### END INIT INFO
16+
17+
# Author: licess
18+
# website: https://webconsole.realclouds.org
19+
20+
NAME=webconsole
21+
22+
PIDFILE=/opt/webconsole/log/apibox.pid
23+
. /etc/init.d/functions
24+
webconsole_start() {
25+
nohup /opt/webconsole/bin/apibox start >/dev/null 2>&1 &
26+
}
27+
28+
webconsole_stop() {
29+
/opt/webconsole/bin/apibox stop >/dev/null 2>&1 &
30+
rm -f $PIDFILE
31+
32+
}
33+
34+
case "$1" in
35+
start)
36+
37+
if [ -f "$PIDFILE" ]; then
38+
echo "$NAME (pid `pidof $NAME`) already running..."
39+
exit 1
40+
fi
41+
webconsole_start
42+
echo "$NAME (pid `pidof $NAME`) is running..."
43+
;;
44+
45+
stop)
46+
echo -n "Stoping $NAME... "
47+
webconsole_stop
48+
echo "$NAME is stopped..."
49+
exit 1
50+
;;
51+
52+
status)
53+
if [ -f "$PIDFILE" ]; then
54+
echo "$NAME (pid `pidof $NAME`) is running..."
55+
else
56+
echo "$NAME is stopped."
57+
exit 0
58+
fi
59+
;;
60+
restart)
61+
webconsole_stop
62+
echo -n "Stoping $NAME... "
63+
echo "$NAME is stopped..."
64+
sleep 1
65+
webconsole_start
66+
echo "$NAME (pid `pidof $NAME`) is running..."
67+
;;
68+
*)
69+
echo "Usage: $0 {start|stop|restart|status}"
70+
exit 1
71+
72+
esac
73+
exit 0

src/apibox.club/website/console.go

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package website
22

33
import (
4+
"bufio"
45
"bytes"
5-
"io"
66
"net"
77
"net/http"
88
"net/url"
99
"strings"
10+
"time"
11+
"unicode/utf8"
1012

1113
"apibox.club/utils"
1214
"github.com/gorilla/websocket"
@@ -258,25 +260,49 @@ func SSHWebSocketHandler(w http.ResponseWriter, r *http.Request) {
258260
defer func() {
259261
done <- true
260262
}()
261-
rbuf := make([]byte, 1024)
262-
for {
263-
n, err := channel.Read(rbuf)
263+
br := bufio.NewReader(channel)
264+
buf := []byte{}
264265

265-
if io.EOF == err {
266-
return
267-
}
268-
if err != nil {
269-
apibox.Log_Err(err.Error())
270-
return
271-
}
272-
if n > 0 {
273-
err = ws.WriteMessage(websocket.TextMessage, rbuf[:n])
266+
t := time.NewTimer(time.Millisecond * 100)
267+
defer t.Stop()
268+
r := make(chan rune)
269+
270+
go func() {
271+
for {
272+
x, size, err := br.ReadRune()
274273
if err != nil {
275-
apibox.Log_Err(err)
274+
apibox.Log_Err(err.Error())
276275
return
277276
}
277+
if size > 0 {
278+
r <- x
279+
}
280+
}
281+
}()
282+
283+
for {
284+
select {
285+
case <-t.C:
286+
if len(buf) != 0 {
287+
err = ws.WriteMessage(websocket.TextMessage, buf)
288+
buf = []byte{}
289+
if err != nil {
290+
apibox.Log_Err(err.Error())
291+
return
292+
}
293+
}
294+
t.Reset(time.Millisecond * 100)
295+
case d := <-r:
296+
if d != utf8.RuneError {
297+
p := make([]byte, utf8.RuneLen(d))
298+
utf8.EncodeRune(p, d)
299+
buf = append(buf, p...)
300+
} else {
301+
buf = append(buf, []byte("@")...)
302+
}
278303
}
279304
}
305+
280306
}()
281307
<-done
282308
} else {
@@ -340,10 +366,11 @@ func (c *Console) ConsoleMainPage(w http.ResponseWriter, r *http.Request) {
340366
user_name := strings.TrimSpace(de_vm_info_arr[0])
341367
user_pwd := strings.TrimSpace(de_vm_info_arr[1])
342368
vm_addr := strings.TrimSpace(de_vm_info_arr[2])
343-
vm_time := strings.TrimSpace(de_vm_info_arr[3])
369+
vm_time := strings.TrimSpace(de_vm_info_arr[3])
344370

345371
now := time.Now()
346372
start, _ := time.Parse(Time.RFC3339, vm_time)
373+
347374
url_timeout, err := time.ParseDuration(Conf.Web.UrlTimeout)
348375
if nil != err {
349376
url_timeout, _ = time.ParseDuration("60s")
@@ -375,10 +402,10 @@ func (c *Console) ConsoleLogin(w http.ResponseWriter, r *http.Request) {
375402
user_name := ctx.GetFormValue("user_name")
376403
user_pwd := ctx.GetFormValue("user_pwd")
377404
vm_addr := ctx.GetFormValue("vm_addr")
378-
vm_cid := ctx.GetFormValue("vm_cid")
405+
vm_cid := ctx.GetFormValue("vm_cid")
379406
vm_time := time.Now().Format(Time.RFC3339)
380407

381-
apibox.Log_Debug(user_name,user_pwd,vm_addr,vm_cid,vm_time)
408+
apibox.Log_Debug(user_name,user_pwd,vm_addr,vm_cid,vm_time)
382409

383410
if vm_cid == "" {
384411
vm_cid = "none"
@@ -415,7 +442,7 @@ func (c *Console) ConsoleLogin(w http.ResponseWriter, r *http.Request) {
415442
ssh_info = append(ssh_info, user_name)
416443
ssh_info = append(ssh_info, user_pwd)
417444
ssh_info = append(ssh_info, vm_addr)
418-
ssh_info = append(ssh_info, vm_time)
445+
ssh_info = append(ssh_info, vm_time)
419446
ssh_info = append(ssh_info, vm_cid)
420447
b64_ssh_info, err := apibox.AESEncode(strings.Join(ssh_info, "\n"), aesKey)
421448
if nil != err {

0 commit comments

Comments
 (0)