-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (65 loc) · 1.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"fmt"
"github.com/charmbracelet/wish/logging"
"github.com/deemkeen/stegodon/middleware"
"github.com/deemkeen/stegodon/util"
"github.com/deemkeen/stegodon/web"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/charmbracelet/wish"
"github.com/gliderlabs/ssh"
)
func main() {
conf, err := util.ReadConf()
if err != nil {
log.Fatalln(err)
}
fmt.Println("Configuration: ")
fmt.Println(util.PrettyPrint(conf))
util.GeneratePemKeypair()
s, err := wish.NewServer(
wish.WithAddress(fmt.Sprintf("%s:%d", conf.Conf.Host, conf.Conf.SshPort)),
wish.WithHostKeyPath(".ssh/hostkey"),
wish.WithPublicKeyAuth(publicKeyHandler),
//wish.WithAuthorizedKeys(".ssh"),
wish.WithMiddleware(
middleware.MainTui(),
middleware.AuthMiddleware(),
logging.Middleware(), // last middleware executed first
),
)
if err != nil {
log.Fatalln(err)
}
startServing(err, s, conf)
}
func startServing(err error, s *ssh.Server, conf *util.AppConfig) {
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
log.Printf("Starting SSH server on %s:%d", conf.Conf.Host, conf.Conf.SshPort)
go func() {
if err = s.ListenAndServe(); err != nil {
log.Fatalln(err)
}
}()
go func() {
if err = web.Router(conf); err != nil {
log.Fatalln(err)
}
}()
<-done
log.Println("Stopping SSH server")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer func() { cancel() }()
if err := s.Shutdown(ctx); err != nil {
log.Fatalln(err)
}
}
func publicKeyHandler(ssh.Context, ssh.PublicKey) bool {
return true
}