mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9599 from yousong/bugfix/yousong-climc-ssh
Bugfix/yousong climc ssh
This commit is contained in:
@@ -42,34 +42,24 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
connParams, err := obj.GetString("connect_params")
|
||||
if err != nil {
|
||||
|
||||
resp := &webconsole_api.ServerRemoteConsoleResponse{}
|
||||
if err := obj.Unmarshal(resp); 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 {
|
||||
query = connUrl.Query()
|
||||
} else {
|
||||
query, err = url.ParseQuery(connParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
protocol := query.Get("protocol")
|
||||
if !utils.IsInStringArray(protocol, []string{
|
||||
connectParams := resp.GetConnectParams()
|
||||
if protocol, err := resp.GetConnectProtocol(); err != nil {
|
||||
return err
|
||||
} else if !utils.IsInStringArray(protocol, []string{
|
||||
command.PROTOCOL_TTY, webconsole_api.VNC,
|
||||
webconsole_api.SPICE, webconsole_api.WMKS,
|
||||
}) {
|
||||
fmt.Println(connParams)
|
||||
fmt.Println(connectParams)
|
||||
return nil
|
||||
}
|
||||
|
||||
newQuery := url.Values(make(map[string][]string))
|
||||
newQuery.Set("data", base64.StdEncoding.EncodeToString([]byte(connParams)))
|
||||
newQuery := url.Values{}
|
||||
newQuery.Set("data", base64.StdEncoding.EncodeToString([]byte(connectParams)))
|
||||
u.RawQuery = newQuery.Encode()
|
||||
fmt.Println(u.String())
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package webconsole
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type ServerRemoteConsoleResponse struct {
|
||||
ConnectParams string `json:"connect_params"`
|
||||
Session string `json:"session,omitempty"`
|
||||
|
||||
apis.Meta
|
||||
}
|
||||
|
||||
func (resp *ServerRemoteConsoleResponse) GetConnectParams() string {
|
||||
params := resp.ConnectParams
|
||||
if data, err := base64.StdEncoding.DecodeString(params); err == nil {
|
||||
params = string(data)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (resp *ServerRemoteConsoleResponse) GetConnectProtocol() (string, error) {
|
||||
var (
|
||||
params = resp.GetConnectParams()
|
||||
query url.Values
|
||||
)
|
||||
if uri, err := url.ParseRequestURI(params); err == nil {
|
||||
query = uri.Query()
|
||||
} else if q, err := url.ParseQuery(params); err == nil {
|
||||
query = q
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
protocol := query.Get("protocol")
|
||||
return protocol, nil
|
||||
}
|
||||
@@ -71,12 +71,18 @@ func (opt *WebConsoleBaremetalOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
|
||||
type WebConsoleSshOptions struct {
|
||||
WebConsoleOptions
|
||||
IP string `help:"IP to connect"`
|
||||
IP string `help:"IP to connect" json:"-"`
|
||||
Port int `help:"Remote server port"`
|
||||
}
|
||||
|
||||
func (opt *WebConsoleSshOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
return StructToParams(opt)
|
||||
data, err := StructToParams(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("webconsole", data)
|
||||
return params, nil
|
||||
}
|
||||
|
||||
type WebConsoleServerOptions struct {
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
webconsole_api "yunion.io/x/onecloud/pkg/apis/webconsole"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -214,14 +215,15 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht
|
||||
}
|
||||
|
||||
func responsePublicCloudConsole(ctx context.Context, info *session.RemoteConsoleInfo, w http.ResponseWriter) {
|
||||
data := jsonutils.NewDict()
|
||||
params, err := info.GetConnectParams()
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
return
|
||||
}
|
||||
data.Add(jsonutils.NewString(params), "connect_params")
|
||||
sendJSON(w, data)
|
||||
resp := webconsole_api.ServerRemoteConsoleResponse{
|
||||
ConnectParams: params,
|
||||
}
|
||||
sendJSON(w, resp.JSON(resp))
|
||||
}
|
||||
|
||||
func handleDataSession(ctx context.Context, sData session.ISessionData, w http.ResponseWriter, connParams url.Values, b64Encode bool) {
|
||||
@@ -230,7 +232,6 @@ func handleDataSession(ctx context.Context, sData session.ISessionData, w http.R
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
return
|
||||
}
|
||||
data := jsonutils.NewDict()
|
||||
params, err := s.GetConnectParams(connParams)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -239,9 +240,11 @@ func handleDataSession(ctx context.Context, sData session.ISessionData, w http.R
|
||||
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)
|
||||
resp := webconsole_api.ServerRemoteConsoleResponse{
|
||||
ConnectParams: params,
|
||||
Session: s.Id,
|
||||
}
|
||||
sendJSON(w, resp.JSON(resp))
|
||||
}
|
||||
|
||||
func handleCommandSession(ctx context.Context, cmd command.ICommand, w http.ResponseWriter) {
|
||||
|
||||
Reference in New Issue
Block a user