webconsole: update aliyun vnc base url and uniq vnc session

This commit is contained in:
Zexi
2019-08-20 19:41:16 +08:00
parent d0906806e5
commit 20ce44d9b0
4 changed files with 47 additions and 15 deletions
+1 -1
View File
@@ -241,7 +241,7 @@ func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connPa
}
func handleCommandSession(cmd command.ICommand, w http.ResponseWriter) {
handleDataSession(cmd, w, nil)
handleDataSession(session.WrapCommandSession(cmd), w, nil)
}
func sendJSON(w http.ResponseWriter, body jsonutils.JSONObject) {
@@ -89,6 +89,10 @@ func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func (s *WebsockifyServer) doProxy(wsConn *websocket.Conn, tcpConn net.Conn) {
s.Session.RegisterDuplicateHook(func() {
wsConn.Close()
tcpConn.Close()
})
go s.wsToTcp(wsConn, tcpConn)
s.tcpToWs(wsConn, tcpConn)
}
+5 -1
View File
@@ -123,6 +123,10 @@ func (info *RemoteConsoleInfo) GetPassword() string {
return info.VncPassword
}
func (info *RemoteConsoleInfo) GetId() string {
return info.Id
}
func (info *RemoteConsoleInfo) getConnParamsURL(baseURL string, params url.Values) string {
if params == nil {
params = url.Values{}
@@ -142,7 +146,7 @@ func (info *RemoteConsoleInfo) getAliyunURL() (string, error) {
if info.OsName == "Windows" {
isWindows = "True"
}
base := "https://g.alicdn.com/aliyun/ecs-console-vnc/0.0.7/index.html"
base := "https://g.alicdn.com/aliyun/ecs-console-vnc2/0.0.5/index.html"
params := url.Values{
"vncUrl": {info.Url},
"instanceId": {info.InstanceId},
+37 -13
View File
@@ -21,9 +21,8 @@ import (
"sync"
"time"
"github.com/golang-plus/uuid"
"yunion.io/x/log"
"yunion.io/x/pkg/util/stringutils"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/webconsole/command"
@@ -52,23 +51,26 @@ func NewSessionManager() *SSessionManager {
return s
}
func (man *SSessionManager) Save(data ISessionData) (session *SSession, err error) {
key, err := uuid.NewV4()
if err != nil {
return
func (man *SSessionManager) Save(data ISessionData) (*SSession, error) {
idStr := data.GetId()
if os, ok := man.Load(idStr); ok {
oldSession := os.(*SSession)
if oldSession.duplicateHook != nil {
log.Warningf("session %s already exists, execute dupliate hook", idStr)
oldSession.duplicateHook()
}
}
idStr := key.String()
token, err := utils.EncryptAESBase64Url(AES_KEY, idStr)
if err != nil {
return
return nil, err
}
session = &SSession{
session := &SSession{
Id: idStr,
ISessionData: data,
AccessToken: token,
}
man.Store(idStr, session)
return
return session, nil
}
func (man *SSessionManager) Get(accessToken string) (*SSession, bool) {
@@ -92,13 +94,31 @@ func (man *SSessionManager) Get(accessToken string) (*SSession, bool) {
type ISessionData interface {
command.ICommand
GetId() string
}
type RandomSessionData struct {
command.ICommand
id string
}
func WrapCommandSession(cmd command.ICommand) *RandomSessionData {
return &RandomSessionData{
ICommand: cmd,
id: stringutils.UUID4(),
}
}
func (s *RandomSessionData) GetId() string {
return s.id
}
type SSession struct {
ISessionData
Id string
AccessToken string
AccessedAt time.Time
Id string
AccessToken string
AccessedAt time.Time
duplicateHook func()
}
func (s SSession) GetConnectParams(params url.Values) (string, error) {
@@ -118,3 +138,7 @@ func (s *SSession) Close() error {
Manager.Delete(s.Id)
return nil
}
func (s *SSession) RegisterDuplicateHook(f func()) {
s.duplicateHook = f
}