Print SSH upstream in brackets to distinguish port properly (#84)
Before: ``` % sshpiperd pipe list donatas -> root@2a02:4231:face:1001:1610:931c:2980:9d9d:22 ``` After: ``` % sshpiperd pipe list donatas -> root@[2a02:4231:face:1001:1610:931c:2980:9d9d]:22 ```
This commit is contained in:
parent
1aef76fd7a
commit
f14ff4278b
3 changed files with 21 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"github.com/tg123/sshpiper/sshpiperd/upstream"
|
||||
"github.com/tg123/sshpiper/sshpiperd/utils"
|
||||
)
|
||||
|
||||
func (p *pome) authWithPipe(conn ssh.ConnMetadata, challengeContext ssh.AdditionalChallengeContext) (net.Conn, *ssh.AuthPipe, error) {
|
||||
|
|
@ -22,7 +23,7 @@ func (p *pome) authWithPipe(conn ssh.ConnMetadata, challengeContext ssh.Addition
|
|||
return nil, nil, pipe.say("Not add Please check your configure")
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf("%v:%v", host, port)
|
||||
addr := fmt.Sprintf("%v:%v", utils.FormatIPAddress(host), port)
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, nil, pipe.say(fmt.Sprintf("Cannot connect to %v, reason: %v", addr, err))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/jinzhu/gorm"
|
||||
|
||||
upstreamprovider "github.com/tg123/sshpiper/sshpiperd/upstream"
|
||||
"github.com/tg123/sshpiper/sshpiperd/utils"
|
||||
)
|
||||
|
||||
func (p *plugin) ListPipe() ([]upstreamprovider.Pipe, error) {
|
||||
|
|
@ -33,7 +34,7 @@ func (p *plugin) ListPipe() ([]upstreamprovider.Pipe, error) {
|
|||
}
|
||||
|
||||
pipes = append(pipes, upstreamprovider.Pipe{
|
||||
Host: host,
|
||||
Host: utils.FormatIPAddress(host),
|
||||
Port: port,
|
||||
Username: d.Username,
|
||||
UpstreamUsername: upuser,
|
||||
|
|
|
|||
17
sshpiperd/utils/common.go
Normal file
17
sshpiperd/utils/common.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func FormatIPAddress(host string) string {
|
||||
ip4 := net.ParseIP(host).To4()
|
||||
|
||||
if ip4 != nil || !strings.Contains(host, ":") {
|
||||
return host
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[%s]", host)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue