This commit is contained in:
parent
6a166b5410
commit
b18b135513
|
@ -30,7 +30,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// 会话通道. <sid, *util.WSChannel>var
|
// 会话通道. <sid, *util.WSChannel>var
|
||||||
sessionWS = map[string]*util.WSChannel{}
|
SessionWS = map[string]*util.WSChannel{}
|
||||||
|
|
||||||
// 输出通道. <sid, *util.WSChannel>
|
// 输出通道. <sid, *util.WSChannel>
|
||||||
OutputWS = map[string]*util.WSChannel{}
|
OutputWS = map[string]*util.WSChannel{}
|
||||||
|
@ -98,12 +98,12 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
sessionWS[sid] = &wsChan
|
SessionWS[sid] = &wsChan
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-session"}
|
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-session"}
|
||||||
wsChan.Conn.WriteJSON(&ret)
|
wsChan.Conn.WriteJSON(&ret)
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(sessionWS))
|
glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(SessionWS))
|
||||||
|
|
||||||
input := map[string]interface{}{}
|
input := map[string]interface{}{}
|
||||||
|
|
||||||
|
@ -257,9 +257,9 @@ func (sessions *Sessions) Remove(sid string) {
|
||||||
delete(NotificationWS, sid)
|
delete(NotificationWS, sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ws, ok := sessionWS[sid]; ok {
|
if ws, ok := SessionWS[sid]; ok {
|
||||||
ws.Close()
|
ws.Close()
|
||||||
delete(sessionWS, sid)
|
delete(SessionWS, sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(3).Infof("Removed a session [%s]", s.Id)
|
glog.V(3).Infof("Removed a session [%s]", s.Id)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
|
|
||||||
// Shell 通道.
|
// Shell 通道.
|
||||||
// <sid, *util.WSChannel>>
|
// <sid, *util.WSChannel>>
|
||||||
var shellWS = map[string]*util.WSChannel{}
|
var ShellWS = map[string]*util.WSChannel{}
|
||||||
|
|
||||||
// Shell 首页.
|
// Shell 首页.
|
||||||
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -70,12 +70,12 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
shellWS[sid] = &wsChan
|
ShellWS[sid] = &wsChan
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Shell initialized", "cmd": "init-shell"}
|
ret := map[string]interface{}{"output": "Shell initialized", "cmd": "init-shell"}
|
||||||
wsChan.Conn.WriteJSON(&ret)
|
wsChan.Conn.WriteJSON(&ret)
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Shell] with session [%s], %d", sid, len(shellWS))
|
glog.V(4).Infof("Open a new [Shell] with session [%s], %d", sid, len(ShellWS))
|
||||||
|
|
||||||
input := map[string]interface{}{}
|
input := map[string]interface{}{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue