2023-11-17 20:39:00 +03:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
2023-11-19 13:06:38 +03:00
|
|
|
"errors"
|
|
|
|
|
2023-11-18 16:14:39 +03:00
|
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/ssh/types"
|
2023-11-17 20:39:00 +03:00
|
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Params struct {
|
2023-11-18 22:29:18 +03:00
|
|
|
Address string `mapstructure:"address" validate:"required"`
|
|
|
|
DefaultHost *string `mapstructure:"default_host,omitempty"`
|
|
|
|
ForwardPort uint16 `mapstructure:"forward_port"`
|
|
|
|
Auth types.Auth `mapstructure:"auth"`
|
|
|
|
KeepAlive types.KeepAlive `mapstructure:"keepalive"`
|
|
|
|
DomainExtractRegex string `mapstructure:"domain_extract_regex" validate:"validregexp"`
|
|
|
|
Mode types.DomainMode `mapstructure:"mode" validate:"required,oneof=single multi"`
|
|
|
|
FakeRemoteHost bool `mapstructure:"fake_remote_host"`
|
2023-11-19 13:06:38 +03:00
|
|
|
NoPTY bool `mapstructure:"nopty"`
|
|
|
|
Commands types.Commands `mapstructure:"commands"`
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Params) Validate() error {
|
|
|
|
if err := util.Validator.Struct(p); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-11-19 13:06:38 +03:00
|
|
|
if p.NoPTY && (len(p.Commands.OnConnect) > 0 || len(p.Commands.OnDisconnect) > 0) {
|
|
|
|
return errors.New("commands aren't available without PTY (nopty = true)")
|
|
|
|
}
|
2023-11-18 16:14:39 +03:00
|
|
|
return p.Auth.Validate()
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|