From 0c888eab1ca000166fe8997650f88cf4078e5bb9 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Wed, 15 Mar 2023 11:26:03 +0100 Subject: [PATCH] internal/dis/component/ssh: Shorten help text --- internal/config/http.go | 15 ++++++ internal/dis/component/ssh2/server_handler.go | 48 +++---------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/internal/config/http.go b/internal/config/http.go index bdb4876..c0bffbf 100644 --- a/internal/config/http.go +++ b/internal/config/http.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "net/url" "strings" "github.com/tkw1536/pkglib/collection" @@ -23,6 +24,20 @@ type HTTPConfig struct { CertbotEmail string `yaml:"certbot_email" validate:"email"` } +// JoinPath returns the root public url joined with the provided parts. +func (hcfg HTTPConfig) JoinPath(elem ...string) *url.URL { + u := url.URL{ + Scheme: "http", + Host: hcfg.PrimaryDomain, + Path: "/", + } + if hcfg.HTTPSEnabled() { + u.Scheme = "https" + } + + return u.JoinPath(elem...) +} + // TCPMuxCommand generates a command line for the sslh executable. func (hcfg HTTPConfig) TCPMuxCommand(addr string, http string, https string, ssh string) string { if hcfg.HTTPSEnabled() { diff --git a/internal/dis/component/ssh2/server_handler.go b/internal/dis/component/ssh2/server_handler.go index f999613..e6fd798 100644 --- a/internal/dis/component/ssh2/server_handler.go +++ b/internal/dis/component/ssh2/server_handler.go @@ -26,50 +26,13 @@ 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: +To connect to a WissKI named ${SLUG} you may use: ssh -J ${DOMAIN}:${PORT} www-data@${HOSTNAME} -You may also place the following into your $HOME/.ssh/config file: +For more details see: -Host *.${DOMAIN} - ProxyJump ${DOMAIN}.proxy - User www-data -Host ${DOMAIN}.proxy - User www-data - Hostname ${DOMAIN} - Port ${PORT} - -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 "${PORT}". The proxy type should be "SSH to proxy and use -port forwarding". Then you may enter the hostname - -www-data@${HOSTNAME} - -with port 22. +${HELP_URL} Press CTRL-C to close this connection. ` @@ -80,9 +43,12 @@ func (ssh2 *SSH2) handleConnection(session ssh.Session) { banner := welcomeMessage for _, oldnew := range [][2]string{ {"${SLUG}", slug}, - {"${DOMAIN}", ssh2.Config.HTTP.PrimaryDomain}, {"${HOSTNAME}", slug + "." + ssh2.Config.HTTP.PrimaryDomain}, + + {"${DOMAIN}", ssh2.Config.HTTP.PrimaryDomain}, {"${PORT}", strconv.FormatUint(uint64(ssh2.Config.Listen.SSHPort), 10)}, + + {"${HELP_URL}", ssh2.Config.HTTP.JoinPath("user", "ssh").String()}, } { banner = strings.ReplaceAll(banner, oldnew[0], oldnew[1]) }