-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
99 lines (93 loc) · 2.85 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"crypto/tls"
_ "embed"
"fmt"
. "github.com/mickael-kerjean/webpty/common"
"github.com/mickael-kerjean/webpty/common/ssl"
"github.com/mickael-kerjean/webpty/ctrl"
"net/http"
"os"
"strconv"
)
var (
port int = 3456
srv *http.Server
)
func init() {
if pStr := os.Getenv("PORT"); pStr != "" {
if pInt, err := strconv.Atoi(pStr); err == nil {
port = pInt
}
}
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", ctrl.Main)
mux.HandleFunc("/tunnel.js", ctrl.RedirectTunnel)
mux.HandleFunc("/healthz", ctrl.HealthCheck)
mux.HandleFunc("/favicon.ico", ctrl.ServeFavicon)
msg := `
██╗ ██╗███████╗██████╗ ██████╗ ████████╗██╗ ██╗
██║ ██║██╔════╝██╔══██╗██╔══██╗╚══██╔══╝╚██╗ ██╔╝
██║ █╗ ██║█████╗ ██████╔╝██████╔╝ ██║ ╚████╔╝
██║███╗██║██╔══╝ ██╔══██╗██╔═══╝ ██║ ╚██╔╝
╚███╔███╔╝███████╗██████╔╝██║ ██║ ██║
╚══╝╚══╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═╝
Web Interface:
`
if FLEET_MODE {
msg += fmt.Sprintf(" - https://%s\n", FLEET_SRV)
} else {
for _, url := range GetAddress() {
msg += fmt.Sprintf(" - https://%s:%d\n", url, port)
}
}
Log.Stdout(msg + "\nLOGS:")
TLSCert, _, err := ssl.GenerateSelfSigned()
if err != nil {
Log.Error("ssl.GenerateSelfSigned %s", err.Error())
return
}
srv = &http.Server{
Addr: fmt.Sprintf(
":%d",
port,
),
Handler: mux,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
},
PreferServerCipherSuites: true,
CurvePreferences: []tls.CurveID{
tls.CurveP256,
tls.X25519,
},
Certificates: []tls.Certificate{TLSCert},
},
ErrorLog: NewNilLogger(),
}
if FLEET_MODE {
go func() {
if _, err = ctrl.InitTunnel(FLEET_SRV); err != nil {
Log.Error("WebPty tunnel couldn't be established ...")
srv.Close()
return
}
Log.Info("WebPty is ready to go")
}()
} else {
Log.Info("WebPty is ready to go")
}
if err := srv.ListenAndServeTLS("", ""); err != nil {
Log.Error("[https]: listen_serve %v", err)
}
}