Unverified Commit 6f1e6812 authored by Eric_Lee's avatar Eric_Lee Committed by GitHub

Db ws (#188)

* [update] add web database support

* [Update] update elfinder version
parent 5b3c461c
......@@ -6,7 +6,7 @@ require (
github.com/Azure/azure-pipeline-go v0.1.9 // indirect
github.com/Azure/azure-storage-blob-go v0.6.0
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/LeeEirc/elfinder v0.0.11-0.20191224095556-900471613ab8
github.com/LeeEirc/elfinder v0.0.11
github.com/aliyun/aliyun-oss-go-sdk v1.9.8
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
github.com/aws/aws-sdk-go v1.19.46
......
......@@ -5,8 +5,8 @@ github.com/Azure/azure-storage-blob-go v0.6.0 h1:SEATKb3LIHcaSIX+E6/K4kJpwfuozFE
github.com/Azure/azure-storage-blob-go v0.6.0/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/LeeEirc/elfinder v0.0.11-0.20191224095556-900471613ab8 h1:+q8TcqE/oiVu3B/rmlcsT9wZuzGLL3Wk7HGKVGuAHGo=
github.com/LeeEirc/elfinder v0.0.11-0.20191224095556-900471613ab8/go.mod h1:d1bMAAydkZSBxSN/EuQjBg6B0xcPP3boHuYEpzEHYTs=
github.com/LeeEirc/elfinder v0.0.11 h1:LP+53Q0V2WhxTqR720X7B8rkkX2YDq47dSIGLR1xA9s=
github.com/LeeEirc/elfinder v0.0.11/go.mod h1:d1bMAAydkZSBxSN/EuQjBg6B0xcPP3boHuYEpzEHYTs=
github.com/LeeEirc/sftp v1.10.2 h1:SGpj84RbStlwH+ThXYUsxtxtbzAzpUY8z5gQN4p12OI=
github.com/LeeEirc/sftp v1.10.2/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/aliyun/aliyun-oss-go-sdk v1.9.8 h1:BOflvK0Zs/zGmoabyFIzTg5c3kguktWTXEwewwbuba0=
......
package httpd
type HostMsg struct {
Uuid string `json:"uuid"`
UserID string `json:"userid"`
Secret string `json:"secret"`
Size []int `json:"size"`
Uuid string `json:"uuid"`
UserID string `json:"userid"`
Secret string `json:"secret"`
Size []int `json:"size"`
HostType string `json:"type"`
}
type ResizeMsg struct {
......
......@@ -20,6 +20,10 @@ import (
"github.com/jumpserver/koko/pkg/service"
)
type proxyServer interface {
Proxy()
}
func OnPingHandler(c *neffos.NSConn, msg neffos.Message) error {
c.Emit("pong", []byte(""))
return nil
......@@ -106,18 +110,32 @@ func OnHostHandler(c *neffos.NSConn, msg neffos.Message) (err error) {
emitMsg := RoomMsg{roomID, secret}
roomMsg, _ := json.Marshal(emitMsg)
c.Emit("room", roomMsg)
var databaseAsset model.Database
var asset model.Asset
asset := service.GetAsset(assetID)
systemUser := service.GetSystemUser(systemUserID)
if message.HostType == "database" {
databaseAsset = service.GetDatabase(assetID)
if databaseAsset.ID == "" || systemUser.ID == "" {
msg := "No database id or system user id found, exit"
logger.Info(msg)
dataMsg := DataMsg{Room: roomID, Data: msg}
c.Emit("data", neffos.Marshal(dataMsg))
return
}
if asset.ID == "" || systemUser.ID == "" {
msg := "No asset id or system user id found, exit"
logger.Debug(msg)
dataMsg := DataMsg{Room: roomID, Data: msg}
c.Emit("data", neffos.Marshal(dataMsg))
return
logger.Infof("Web terminal want to connect database: %s", databaseAsset.Name)
} else {
asset = service.GetAsset(assetID)
if asset.ID == "" || systemUser.ID == "" {
msg := "No asset id or system user id found, exit"
logger.Debug(msg)
dataMsg := DataMsg{Room: roomID, Data: msg}
c.Emit("data", neffos.Marshal(dataMsg))
return
}
logger.Infof("Web terminal want to connect host: %s", asset.Hostname)
}
logger.Debug("Web terminal want to connect host: ", asset.Hostname)
currentUser, ok := cc.Get("currentUser").(*model.User)
if !ok {
err = errors.New("not found current user")
......@@ -149,9 +167,20 @@ func OnHostHandler(c *neffos.NSConn, msg neffos.Message) (err error) {
client.WinChan <- win
clients.AddClient(roomID, client)
conns.AddClient(cc.ID(), roomID)
proxySrv := proxy.ProxyServer{
UserConn: client, User: currentUser,
Asset: &asset, SystemUser: &systemUser,
var proxySrv proxyServer
if message.HostType == "database" {
proxySrv = &proxy.DBProxyServer{
UserConn: client,
User: currentUser,
Database: &databaseAsset,
SystemUser: &systemUser,
}
} else {
proxySrv = &proxy.ProxyServer{
UserConn: client, User: currentUser,
Asset: &asset, SystemUser: &systemUser,
}
}
go func() {
defer logger.Infof("Request %s: Web ssh end proxy process", client.Uuid)
......
......@@ -33,3 +33,13 @@ func GetSystemUserDatabaseAuthInfo(systemUserID string) (info model.SystemUserAu
}
return
}
func GetDatabase(dbID string) (res model.Database) {
Url := fmt.Sprintf(DatabaseDetailURL, dbID)
_, err := authClient.Get(Url, &res)
if err != nil {
logger.Errorf("Get User databases err: %s", err)
}
return
}
\ No newline at end of file
......@@ -184,7 +184,7 @@ func GetUserNodeTreeWithAsset(userID, nodeID, cachePolicy string) (nodeTrees mod
}
func SearchPermAsset(uid, key string) (res model.NodeTreeList, err error) {
Url := fmt.Sprintf(UserAssetsTree, uid)
Url := fmt.Sprintf(UserAssetsTreeURL, uid)
payload := map[string]string{"search": key}
_, err = authClient.Get(Url, &res, payload)
if err != nil {
......
......@@ -50,5 +50,7 @@ const (
SystemUserAuthURL = "/api/v1/assets/system-users/%s/auth-info/"
UserAssetsTree = "/api/v1/perms/users/%s/assets/tree/"
UserAssetsTreeURL = "/api/v1/perms/users/%s/assets/tree/"
DatabaseDetailURL = "/api/v1/applications/database-apps/%s/"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment