mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #5086 from zexi/automated-cherry-pick-of-#5085-upstream-release-3.1
Automated cherry pick of #5085: webconsole: use base64 encode connect_params
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
@@ -45,6 +46,9 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if decodeStr, err := base64.StdEncoding.DecodeString(connParams); err == nil {
|
||||
connParams = string(decodeStr)
|
||||
}
|
||||
var query url.Values
|
||||
connUrl, err := url.ParseRequestURI(connParams)
|
||||
if err == nil {
|
||||
@@ -64,7 +68,9 @@ func init() {
|
||||
return nil
|
||||
}
|
||||
|
||||
u.RawQuery = connParams
|
||||
newQuery := url.Values(make(map[string][]string))
|
||||
newQuery.Set("data", base64.StdEncoding.EncodeToString([]byte(connParams)))
|
||||
u.RawQuery = newQuery.Encode()
|
||||
fmt.Println(u.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package webconsole
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -206,7 +207,7 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht
|
||||
case session.ALIYUN, session.QCLOUD, session.OPENSTACK, session.VMRC, session.ZSTACK, session.CTYUN:
|
||||
responsePublicCloudConsole(info, w)
|
||||
case session.VNC, session.SPICE, session.WMKS:
|
||||
handleDataSession(info, w, url.Values{"password": {info.GetPassword()}})
|
||||
handleDataSession(info, w, url.Values{"password": {info.GetPassword()}}, true)
|
||||
default:
|
||||
httperrors.NotAcceptableError(w, "Unspported remote console protocol: %s", info.Protocol)
|
||||
}
|
||||
@@ -223,7 +224,7 @@ func responsePublicCloudConsole(info *session.RemoteConsoleInfo, w http.Response
|
||||
sendJSON(w, data)
|
||||
}
|
||||
|
||||
func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connParams url.Values) {
|
||||
func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connParams url.Values, b64Encode bool) {
|
||||
s, err := session.Manager.Save(sData)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(w, err)
|
||||
@@ -235,13 +236,16 @@ func handleDataSession(sData session.ISessionData, w http.ResponseWriter, connPa
|
||||
httperrors.GeneralServerError(w, err)
|
||||
return
|
||||
}
|
||||
if b64Encode {
|
||||
params = base64.StdEncoding.EncodeToString([]byte(params))
|
||||
}
|
||||
data.Add(jsonutils.NewString(params), "connect_params")
|
||||
data.Add(jsonutils.NewString(s.Id), "session")
|
||||
sendJSON(w, data)
|
||||
}
|
||||
|
||||
func handleCommandSession(cmd command.ICommand, w http.ResponseWriter) {
|
||||
handleDataSession(session.WrapCommandSession(cmd), w, nil)
|
||||
handleDataSession(session.WrapCommandSession(cmd), w, nil, false)
|
||||
}
|
||||
|
||||
func sendJSON(w http.ResponseWriter, body jsonutils.JSONObject) {
|
||||
|
||||
Reference in New Issue
Block a user