diff --git a/internal/dis/component/ssh2/server.go b/internal/dis/component/ssh2/server.go index aef1707..87915e0 100644 --- a/internal/dis/component/ssh2/server.go +++ b/internal/dis/component/ssh2/server.go @@ -12,16 +12,6 @@ const ( eot rune = 4 ) -const welcomeMessage = `Welcome to the WissKI SSH Server. -You've successfully authenticated, but we don't provide shell access to the main server. -You may use this connection as part of a proxy jump to connect to your server. -For example: - -ssh -J %s:2222 www-data@%s - -Press CTRL-C to close this connection. -` - // Server returns an ssh server that implements the main ssh server func (ssh2 *SSH2) Server(context context.Context, privateKeyPath string, io stream.IOStream) (*ssh.Server, error) { var server ssh.Server diff --git a/internal/dis/component/ssh2/server_handler.go b/internal/dis/component/ssh2/server_handler.go index 7faf9cc..2e84784 100644 --- a/internal/dis/component/ssh2/server_handler.go +++ b/internal/dis/component/ssh2/server_handler.go @@ -2,8 +2,8 @@ package ssh2 import ( "bufio" - "fmt" "io" + "strings" "github.com/gliderlabs/ssh" ) @@ -12,9 +12,78 @@ func (ssh2 *SSH2) setupHandler(server *ssh.Server) { server.Handle(ssh2.handleConnection) } +const welcomeMessage = ` +__ ___ _ _____ ____ _ _ _ _ _ +\ \ / (_)___ ___| |/ /_ _| | _ \(_)___| |_(_) | | ___ _ __ _ _ + \ \ /\ / /| / __/ __| ' / | | | | | | / __| __| | | |/ _ \ '__| | | | + \ V V / | \__ \__ \ . \ | | | |_| | \__ \ |_| | | | __/ | | |_| | + \_/\_/ |_|___/___/_|\_\___| |____/|_|___/\__|_|_|_|\___|_| \__, | + |___/ + +Welcome to the WissKI SSH Server. +You've successfully authenticated, but we don't provide shell access to +the main server. You may use this connection as part of a proxy jump to +connect to your WissKI Instance. + +In the following we will provide instructions on how to connect to your +distillery instance via this server. We will assume + +${SLUG} + +is the name of the WissKI you want to you want to connect to. + +From a linux (or mac, or windows 11) command line you may use: + +ssh -J ${DOMAIN}:2222 www-data@${HOSTNAME} + +You may also place the following into your $HOME/.ssh/config file: + +Host *.${DOMAIN} + ProxyJump ${DOMAIN}.proxy + User www-data +Host ${DOMAIN}.proxy + User www-data + Hostname ${DOMAIN} + Port 2222 + +and then connect simply via: + +ssh ${HOSTNAME} + +On windows you should use the "ssh" executable from the command line if +available. + +If you must, you can also use Putty. + +THIS IS NOT RECOMMENDED AND NOT OFFICIALLY SUPPORTED + +First make sure your SSH Key is configured under Connection > Auth > +Credentials. Then configure a proxy under Connection > Proxy. The Proxy +Hostname should be + +${DOMAIN} + +and the port "2222". The proxy type should be "SSH to proxy and use +port forwarding". Then you may enter the hostname + +www-data@${HOSTNAME} + +with port 22. + +Press CTRL-C to close this connection. +` + func (ssh2 *SSH2) handleConnection(session ssh.Session) { slug, _ := getAnyPermission(session.Context()) - banner := fmt.Sprintf(welcomeMessage, ssh2.Config.DefaultDomain, slug+"."+ssh2.Config.DefaultDomain) + + banner := welcomeMessage + for _, oldnew := range [][2]string{ + {"${SLUG}", slug}, + {"${DOMAIN}", ssh2.Config.DefaultDomain}, + {"${HOSTNAME}", slug + "." + ssh2.Config.DefaultDomain}, + } { + banner = strings.ReplaceAll(banner, oldnew[0], oldnew[1]) + } io.WriteString(session, banner)