Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/controllers/files/establish_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/genshen/ssh-web-console/src/models"
"github.com/genshen/ssh-web-console/src/utils"
"github.com/oklog/ulid/v2"
"golang.org/x/crypto/ssh"
"log"
"math/rand"
"net/http"
Expand Down Expand Up @@ -34,7 +33,7 @@ func (e SftpEstablish) ServeAfterAuthenticated(w http.ResponseWriter, r *http.Re

// add sftp client to list if success.
user := session.Value.(models.UserInfo)
sftpEntity, err := utils.NewSftpEntity(utils.SftpNode(utils.NewSSHNode(user.Host, user.Port)), user.Username, ssh.Password(user.Password))
sftpEntity, err := utils.NewSftpEntity(utils.SftpNode(utils.NewSSHNode(user.Host, user.Port)), user.Username, (user.Password))
if err != nil {
http.Error(w, "Error while establishing sftp connection", 400)
log.Println("Error: while establishing sftp connection", err)
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/main_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"github.com/genshen/ssh-web-console/src/models"
"github.com/genshen/ssh-web-console/src/utils"
"golang.org/x/crypto/ssh"
"net/http"
"strconv"
)
Expand Down Expand Up @@ -33,7 +32,7 @@ func SignIn(w http.ResponseWriter, r *http.Request) {
//try to login session account
session := utils.SSHShellSession{}
session.Node = utils.NewSSHNode(userinfo.Host, userinfo.Port)
err := session.Connect(userinfo.Username, ssh.Password(userinfo.Password))
err := session.Connect(userinfo.Username, (userinfo.Password))
if err != nil {
errUnmarshal = models.JsonResponse{HasError: true, Message: models.SIGN_IN_FORM_TYPE_ERROR_PASSWORD}
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/genshen/ssh-web-console/src/models"
"github.com/genshen/ssh-web-console/src/utils"
"golang.org/x/crypto/ssh"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (c *SSHWebSocketHandle) ServeAfterAuthenticated(w http.ResponseWriter, r *h
userInfo := session.Value.(models.UserInfo)
cols := utils.GetQueryInt32(r, "cols", 120)
rows := utils.GetQueryInt32(r, "rows", 32)
sshAuth := ssh.Password(userInfo.Password)
sshAuth := (userInfo.Password)
if err := c.SSHShellOverWS(r.Context(), conn, claims.Host, claims.Port, userInfo.Username, sshAuth, cols, rows); err != nil {
log.Println("Error,", err)
utils.Abort(w, err.Error(), 500)
Expand All @@ -56,7 +55,7 @@ func (c *SSHWebSocketHandle) ServeAfterAuthenticated(w http.ResponseWriter, r *h
// then we deliver ssh data via ssh connection between browser and ssh server.
// That is, read webSocket data from browser (e.g. 'ls' command) and send data to ssh server via ssh connection;
// the other hand, read returned ssh data from ssh server and write back to browser via webSocket API.
func (c *SSHWebSocketHandle) SSHShellOverWS(ctx context.Context, ws *websocket.Conn, host string, port int, username string, auth ssh.AuthMethod, cols, rows uint32) error {
func (c *SSHWebSocketHandle) SSHShellOverWS(ctx context.Context, ws *websocket.Conn, host string, port int, username string, auth string, cols, rows uint32) error {
//setup ssh connection
sshEntity := utils.SSHShellSession{
Node: utils.NewSSHNode(host, port),
Expand Down
5 changes: 2 additions & 3 deletions src/utils/sftp_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"sync"
)

Expand Down Expand Up @@ -36,12 +35,12 @@ var (
subscribers = make(map[string]SftpEntity)
)

func NewSftpEntity(user SftpNode, username string, auth ssh.AuthMethod) (SftpEntity, error) {
func NewSftpEntity(user SftpNode, username string, pwd string) (SftpEntity, error) {
sshEntity := SSHShellSession{
Node: NewSSHNode(user.Host, user.Port),
}
// init ssh connection.
err := sshEntity.Connect(username, auth)
err := sshEntity.Connect(username, pwd)
if err != nil {
return SftpEntity{}, err
}
Expand Down
13 changes: 10 additions & 3 deletions src/utils/ssh_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type SSHConnInterface interface {
// close ssh connection
Close() error
// connect using username and password
Connect(username string, auth ssh.AuthMethod) error
Connect(username string, pwd string) error
// config connection after connected and may also create a ssh session.
Config(cols, rows uint32) (*ssh.Session, error)
}
Expand All @@ -43,7 +43,7 @@ func (node *Node) GetClient() (*ssh.Client, error) {

//see: http://www.nljb.net/default/Go-SSH-%E4%BD%BF%E7%94%A8/
// establish a ssh connection. if success return nil, than can operate ssh connection via pointer Node.client in struct Node.
func (node *Node) Connect(username string, auth ssh.AuthMethod) error {
func (node *Node) Connect(username string, pwd string) error {
//var hostKey ssh.PublicKey

// An SSH client is represented with a ClientConn.
Expand All @@ -54,7 +54,14 @@ func (node *Node) Connect(username string, auth ssh.AuthMethod) error {
config := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
auth,
ssh.Password(pwd),
ssh.KeyboardInteractive(func(name, instruction string, questions []string, echos []bool) ([]string, error){
answers := make([]string, len(questions))
for i := range answers {
answers[i] = pwd
}
return answers, nil
}),
},
//HostKeyCallback: ssh.FixedHostKey(hostKey),
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
Expand Down