repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
7405bc8
parent
43ef9bb
author
Eric Bower
date
2024-02-24 20:51:38 +0000 UTC
chore(pgs): web tunnel cleanup
3 files changed,  +14, -12
M go.mod
M go.sum
M go.mod
+3, -1
 1@@ -2,6 +2,8 @@ module github.com/picosh/pico
 2 
 3 go 1.22.0
 4 
 5+// replace github.com/picosh/ptun => /home/erock/dev/pico/ptun
 6+
 7 require (
 8 	github.com/alecthomas/chroma v0.10.0
 9 	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
10@@ -21,7 +23,7 @@ require (
11 	github.com/neurosnap/go-exif-remove v0.0.0-20221010134343-50d1e3c35577
12 	github.com/patrickmn/go-cache v2.1.0+incompatible
13 	github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf
14-	github.com/picosh/ptun v0.0.0-20240220214714-1c94994f91cc
15+	github.com/picosh/ptun v0.0.0-20240224204132-32279ba91baf
16 	github.com/picosh/send v0.0.0-20240217194807-77b972121e63
17 	github.com/sendgrid/sendgrid-go v3.13.0+incompatible
18 	github.com/yuin/goldmark v1.6.0
M go.sum
+2, -2
 1@@ -190,8 +190,8 @@ github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
 2 github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
 3 github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf h1:xtr5DoSgoOqbPFnm8p5YjTqrRKVW8KYI0bDwwRiG8yI=
 4 github.com/picosh/pobj v0.0.0-20240218150308-1dc70e819bbf/go.mod h1:ILtZ0GOqkozrrGCvyJqCSUIwal2XQqzSfbKCNdS+HyU=
 5-github.com/picosh/ptun v0.0.0-20240220214714-1c94994f91cc h1:DYPOyRg5z5BLGwbQMGnnTP4iBCEmb3k7OxQNJguD7iA=
 6-github.com/picosh/ptun v0.0.0-20240220214714-1c94994f91cc/go.mod h1:uQfDebjN3JJPsI3PAx8T5rmJwdpfmjvdRe7fXY33Kbw=
 7+github.com/picosh/ptun v0.0.0-20240224204132-32279ba91baf h1:vnG5rYDPzSg0DFBK78zuRm/0DaiEUycmduwAjrTKzfg=
 8+github.com/picosh/ptun v0.0.0-20240224204132-32279ba91baf/go.mod h1:uQfDebjN3JJPsI3PAx8T5rmJwdpfmjvdRe7fXY33Kbw=
 9 github.com/picosh/send v0.0.0-20240217194807-77b972121e63 h1:VSSbAejFzj2KBThfVnMcNXQwzHmwjPUridgi29LxihU=
10 github.com/picosh/send v0.0.0-20240217194807-77b972121e63/go.mod h1:1JCq0NVOdTDenQ0/Kd8e4rP80lu06UHJJ+6dQxhcpew=
11 github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
M pgs/ssh.go
+9, -9
 1@@ -30,8 +30,6 @@ import (
 2 	"github.com/picosh/send/send/sftp"
 3 )
 4 
 5-type SSHServer struct{}
 6-
 7 type ctxPublicKey struct{}
 8 
 9 func getPublicKeyCtx(ctx ssh.Context) (ssh.PublicKey, error) {
10@@ -45,7 +43,7 @@ func setPublicKeyCtx(ctx ssh.Context, pk ssh.PublicKey) {
11 	ctx.SetValue(ctxPublicKey{}, pk)
12 }
13 
14-func (me *SSHServer) authHandler(ctx ssh.Context, key ssh.PublicKey) bool {
15+func authHandler(ctx ssh.Context, key ssh.PublicKey) bool {
16 	setPublicKeyCtx(ctx, key)
17 	return true
18 }
19@@ -116,6 +114,7 @@ func StartSshServer() {
20 	cache := gocache.New(2*time.Minute, 5*time.Minute)
21 
22 	webTunnel := &ptun.WebTunnelHandler{
23+		Logger: logger,
24 		HttpHandler: func(ctx ssh.Context) http.Handler {
25 			subdomain := ctx.User()
26 			log := logger.With(
27@@ -205,11 +204,10 @@ func StartSshServer() {
28 		},
29 	}
30 
31-	sshServer := &SSHServer{}
32 	s, err := wish.NewServer(
33 		wish.WithAddress(fmt.Sprintf("%s:%s", host, port)),
34 		wish.WithHostKeyPath("ssh_data/term_info_ed25519"),
35-		wish.WithPublicKeyAuth(sshServer.authHandler),
36+		wish.WithPublicKeyAuth(authHandler),
37 		ptun.WithWebTunnel(webTunnel),
38 		withProxy(
39 			cfg,
40@@ -224,18 +222,20 @@ func StartSshServer() {
41 
42 	done := make(chan os.Signal, 1)
43 	signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
44-	logger.Info("Starting SSH server on", "host", host, "port", port)
45+	logger.Info("starting SSH server on", "host", host, "port", port)
46 	go func() {
47 		if err = s.ListenAndServe(); err != nil {
48-			logger.Error(err.Error())
49+			logger.Error("serve", "err", err.Error())
50+			os.Exit(1)
51 		}
52 	}()
53 
54 	<-done
55-	logger.Info("Stopping SSH server")
56+	logger.Info("stopping SSH server")
57 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
58 	defer func() { cancel() }()
59 	if err := s.Shutdown(ctx); err != nil {
60-		logger.Error(err.Error())
61+		logger.Error("shutdown", "err", err.Error())
62+		os.Exit(1)
63 	}
64 }