From 223c6d95a2541cb2c9734a3af43e164c50179bfc Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Sat, 19 Jan 2019 17:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20webconsole=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5vnc=E8=AE=BE=E7=BD=AE=20password=20=E7=9A=84=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/webconsole/handlers.go | 9 +++++---- pkg/webconsole/session/remote_console.go | 20 +++++++++++++++----- pkg/webconsole/session/session.go | 11 ++++++----- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/webconsole/handlers.go b/pkg/webconsole/handlers.go index 3df99cc575..8af86d3181 100644 --- a/pkg/webconsole/handlers.go +++ b/pkg/webconsole/handlers.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "net/http" + "net/url" "yunion.io/x/jsonutils" @@ -191,7 +192,7 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht case session.ALIYUN, session.QCLOUD: responsePublicCloudConsole(info, w) case session.VNC, session.SPICE, session.WMKS: - handleDataSession(info, w) + handleDataSession(info, w, url.Values{"password": {info.GetPassword()}}) default: httperrors.NotAcceptableError(w, "Unspported remote console protocol: %s", info.Protocol) } @@ -208,14 +209,14 @@ func responsePublicCloudConsole(info *session.RemoteConsoleInfo, w http.Response sendJSON(w, data) } -func handleDataSession(sData session.ISessionData, w http.ResponseWriter) { +func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connParams url.Values) { s, err := session.Manager.Save(sData) if err != nil { httperrors.GeneralServerError(w, err) return } data := jsonutils.NewDict() - params, err := s.GetConnectParams() + params, err := s.GetConnectParams(connParams) if err != nil { httperrors.GeneralServerError(w, err) return @@ -226,7 +227,7 @@ func handleDataSession(sData session.ISessionData, w http.ResponseWriter) { } func handleCommandSession(cmd command.ICommand, w http.ResponseWriter) { - handleDataSession(cmd, w) + handleDataSession(cmd, w, nil) } func sendJSON(w http.ResponseWriter, body jsonutils.JSONObject) { diff --git a/pkg/webconsole/session/remote_console.go b/pkg/webconsole/session/remote_console.go index 3059f8e916..693889329a 100644 --- a/pkg/webconsole/session/remote_console.go +++ b/pkg/webconsole/session/remote_console.go @@ -19,11 +19,12 @@ const ( ) type RemoteConsoleInfo struct { - Host string `json:"host"` - Port int64 `json:"port"` - Protocol string `json:"protocol"` - Id string `json:"id"` - OsName string `json:"osName"` + Host string `json:"host"` + Port int64 `json:"port"` + Protocol string `json:"protocol"` + Id string `json:"id"` + OsName string `json:"osName"` + VncPassword string `json:"vncPassword"` // used by aliyun server InstanceId string `json:"instance_id"` @@ -37,6 +38,7 @@ func NewRemoteConsoleInfoByCloud(s *mcclient.ClientSession, serverId string) (*R return nil, err } osName, _ := metadata.GetString("os_name") + vncPasswd, _ := metadata.GetString("__vnc_password") ret, err := modules.Servers.GetSpecific(s, serverId, "vnc", nil) if err != nil { return nil, err @@ -47,6 +49,7 @@ func NewRemoteConsoleInfoByCloud(s *mcclient.ClientSession, serverId string) (*R return nil, err } vncInfo.OsName = osName + vncInfo.VncPassword = vncPasswd return &vncInfo, nil } @@ -93,6 +96,13 @@ func (info *RemoteConsoleInfo) GetConnectParams() (string, error) { } } +func (info *RemoteConsoleInfo) GetPassword() string { + if len(info.Password) != 0 { + return info.Password + } + return info.VncPassword +} + func (info *RemoteConsoleInfo) getOpenStackURL() (string, error) { return info.Url, nil } diff --git a/pkg/webconsole/session/session.go b/pkg/webconsole/session/session.go index 3936585a1a..70b35ce0fb 100644 --- a/pkg/webconsole/session/session.go +++ b/pkg/webconsole/session/session.go @@ -87,12 +87,13 @@ type SSession struct { AccessedAt time.Time } -func (s SSession) GetConnectParams() (string, error) { - params := url.Values{ - "api_server": {o.Options.ApiServer}, - "access_token": {s.AccessToken}, - "protocol": {s.GetProtocol()}, +func (s SSession) GetConnectParams(params url.Values) (string, error) { + if params == nil { + params = url.Values(make(map[string][]string)) } + params.Set("api_server", o.Options.ApiServer) + params.Set("access_token", s.AccessToken) + params.Set("protocol", s.GetProtocol()) return params.Encode(), nil }