Tunnel implementation, allow using ssh on connection screen

This commit is contained in:
Dan Sosedoff
2016-01-14 19:50:01 -06:00
parent fb66acebc3
commit f0f447857f
11 changed files with 229 additions and 93 deletions

View File

@@ -8,10 +8,12 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/sosedoff/pgweb/pkg/bookmarks"
"github.com/sosedoff/pgweb/pkg/client"
"github.com/sosedoff/pgweb/pkg/command"
"github.com/sosedoff/pgweb/pkg/connection"
"github.com/sosedoff/pgweb/pkg/shared"
)
var (
@@ -67,6 +69,7 @@ func GetSessions(c *gin.Context) {
}
func Connect(c *gin.Context) {
var sshInfo *shared.SSHInfo
url := c.Request.FormValue("url")
if url == "" {
@@ -82,7 +85,11 @@ func Connect(c *gin.Context) {
return
}
cl, err := client.NewFromUrl(url)
if c.Request.FormValue("ssh") != "" {
sshInfo = parseSshInfo(c)
}
cl, err := client.NewFromUrl(url, sshInfo)
if err != nil {
c.JSON(400, Error{err.Error()})
return

View File

@@ -7,6 +7,8 @@ import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/sosedoff/pgweb/pkg/shared"
)
var extraMimeTypes = map[string]string{
@@ -69,6 +71,21 @@ func parseIntFormValue(c *gin.Context, name string, defValue int) (int, error) {
return num, nil
}
func parseSshInfo(c *gin.Context) *shared.SSHInfo {
info := shared.SSHInfo{
Host: c.Request.FormValue("ssh_host"),
Port: c.Request.FormValue("ssh_port"),
User: c.Request.FormValue("ssh_user"),
Password: c.Request.FormValue("ssh_password"),
}
if info.Port == "" {
info.Port = "22"
}
return &info
}
func assetContentType(name string) string {
ext := filepath.Ext(name)
result := mime.TypeByExtension(ext)