Allowing Commands to reconfigure app Configuration, this is will allow default ports to be currently added to remote presets
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
// New creates a new commands group
|
||||
func New() command.Commands {
|
||||
return command.Commands{
|
||||
newTelnet,
|
||||
newSSH,
|
||||
command.Register(newTelnet, parseTelnetConfig),
|
||||
command.Register(newSSH, parseSSHConfig),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"github.com/niruix/sshwifty/application/command"
|
||||
"github.com/niruix/sshwifty/application/configuration"
|
||||
"github.com/niruix/sshwifty/application/log"
|
||||
"github.com/niruix/sshwifty/application/network"
|
||||
"github.com/niruix/sshwifty/application/rw"
|
||||
@@ -107,6 +108,10 @@ var (
|
||||
sshEmptyTime = time.Time{}
|
||||
)
|
||||
|
||||
const (
|
||||
sshDefaultPortString = "22"
|
||||
)
|
||||
|
||||
type sshRemoteConnWrapper struct {
|
||||
net.Conn
|
||||
|
||||
@@ -198,6 +203,30 @@ func newSSH(
|
||||
}
|
||||
}
|
||||
|
||||
func parseSSHConfig(p configuration.Configuration) configuration.Configuration {
|
||||
for i := range p.Presets {
|
||||
if p.Presets[i].Type != "SSH" {
|
||||
continue
|
||||
}
|
||||
|
||||
oldHost := p.Presets[i].Host
|
||||
|
||||
_, _, sErr := net.SplitHostPort(p.Presets[i].Host)
|
||||
|
||||
if sErr != nil {
|
||||
p.Presets[i].Host = net.JoinHostPort(
|
||||
p.Presets[i].Host,
|
||||
sshDefaultPortString)
|
||||
}
|
||||
|
||||
if len(p.Presets[i].Host) <= 0 {
|
||||
p.Presets[i].Host = oldHost
|
||||
}
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (d *sshClient) Bootup(
|
||||
r *rw.LimitedReader,
|
||||
b []byte,
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/niruix/sshwifty/application/command"
|
||||
"github.com/niruix/sshwifty/application/configuration"
|
||||
"github.com/niruix/sshwifty/application/log"
|
||||
"github.com/niruix/sshwifty/application/network"
|
||||
"github.com/niruix/sshwifty/application/rw"
|
||||
@@ -40,6 +41,10 @@ const (
|
||||
TelnetRequestErrorBadRemoteAddress = command.StreamError(0x01)
|
||||
)
|
||||
|
||||
const (
|
||||
telnetDefaultPortString = "23"
|
||||
)
|
||||
|
||||
// Server signal codes
|
||||
const (
|
||||
TelnetServerRemoteBand = 0x00
|
||||
@@ -71,6 +76,32 @@ func newTelnet(
|
||||
}
|
||||
}
|
||||
|
||||
func parseTelnetConfig(
|
||||
p configuration.Configuration,
|
||||
) configuration.Configuration {
|
||||
for i := range p.Presets {
|
||||
if p.Presets[i].Type != "Telnet" {
|
||||
continue
|
||||
}
|
||||
|
||||
oldHost := p.Presets[i].Host
|
||||
|
||||
_, _, sErr := net.SplitHostPort(p.Presets[i].Host)
|
||||
|
||||
if sErr != nil {
|
||||
p.Presets[i].Host = net.JoinHostPort(
|
||||
p.Presets[i].Host,
|
||||
telnetDefaultPortString)
|
||||
}
|
||||
|
||||
if len(p.Presets[i].Host) <= 0 {
|
||||
p.Presets[i].Host = oldHost
|
||||
}
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (d *telnetClient) Bootup(
|
||||
r *rw.LimitedReader,
|
||||
b []byte) (command.FSMState, command.FSMError) {
|
||||
|
||||
Reference in New Issue
Block a user