-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
62 lines (46 loc) · 1.16 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
package main
import (
"errors"
"log"
"os"
"path"
"github.com/fasmide/remotemoe/http"
"github.com/fasmide/remotemoe/routertwo"
"github.com/fasmide/remotemoe/services"
"github.com/fasmide/remotemoe/ssh"
)
func main() {
routerData := "routerdata"
if os.Getenv("STATE_DIRECTORY") != "" {
routerData = path.Join(os.Getenv("STATE_DIRECTORY"), "routerdata")
}
err := os.Mkdir(routerData, 0700)
// we are not going to be stopping on ErrExists errors
if errors.Is(err, os.ErrExist) {
err = nil
}
if err != nil {
log.Fatalf("unable to make directory for router data: %s", err)
}
router, err := routertwo.NewRouter(routerData)
if err != nil {
panic(err)
}
proxy := &http.Proxy{}
proxy.Initialize(router)
server, err := http.NewServer(router.Exists)
if err != nil {
panic(err)
}
server.Handler = proxy
services.Serve("http", server)
services.ServeTLS("https", server)
sshConfig, err := ssh.DefaultConfig()
if err != nil {
log.Fatalf("cannot get default ssh config: %s", err)
}
sshServer := &ssh.Server{Config: sshConfig, Router: router}
services.Serve("ssh", sshServer)
// we shall be dealing with shutting down in the future :)
select {}
}