-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (47 loc) · 1.45 KB
/
main.go
File metadata and controls
57 lines (47 loc) · 1.45 KB
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
package main
import (
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
// agentSocket is set by the -agent flag and used by bastion.go
var agentSocket string
func main() {
configFile := flag.String("config", "mews.yaml", "Path to configuration file")
port := flag.String("port", "6189", "Port to listen on (always binds to localhost)")
flag.StringVar(&agentSocket, "agent", "", "Path to SSH agent socket (overrides .ssh/config and SSH_AUTH_SOCK)")
flag.Parse()
cfg, err := LoadConfig(*configFile)
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
listenAddr := "localhost:" + *port
log.Printf("Loaded configuration:")
log.Printf(" Listen address: %s", listenAddr)
log.Printf(" Bastion sets: %d", len(cfg.BastionSets))
for name, bastions := range cfg.BastionSets {
log.Printf(" %s: %d bastions", name, len(bastions))
}
log.Printf(" Upstreams: %d", len(cfg.Upstreams))
for _, u := range cfg.Upstreams {
log.Printf(" %s -> %s (bastion_set: %s)", u.Local, u.Remote, u.BastionSet)
}
server := NewServer(cfg, *port)
defer server.Close()
// Handle graceful shutdown
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigCh
log.Println("Shutting down...")
server.Close()
os.Exit(0)
}()
log.Printf("Starting proxy server on http://%s", listenAddr)
if err := http.ListenAndServe(listenAddr, server); err != nil {
log.Fatalf("Server failed: %v", err)
}
}