-
Notifications
You must be signed in to change notification settings - Fork 14
/
lipwig.go
65 lines (56 loc) · 1.37 KB
/
lipwig.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
// Copyright (c) 2015, Air Computing Inc. <oss@aerofs.com>
// All rights reserved.
package main // github.com/aerofs/lipwig
import (
"bytes"
"crypto/tls"
"flag"
"fmt"
"github.com/aerofs/lipwig/cfg"
"github.com/aerofs/lipwig/server"
"io/ioutil"
"net"
)
func main() {
var address string
var insecure bool
var openLogin bool
cfg.InitConfig()
flag.StringVar(&address, "listen", "0.0.0.0:8787", "Listening address")
flag.BoolVar(&insecure, "insecure", false, "Disable TLS")
flag.BoolVar(&openLogin, "open", false, "Enable open login")
flag.Parse()
auth := &server.MultiSchemeAuthenticator{
Schemes: map[string]server.AuthenticatorFunc{},
}
if openLogin {
fmt.Println("WARN: open login is enabled")
auth.Schemes["open"] = func(_ net.Conn, _, _, _ []byte) bool { return true }
}
if len(cfg.Secret) > 0 {
b, err := ioutil.ReadFile(cfg.Secret)
if err != nil {
panic(err)
}
auth.Schemes["secret"] = server.SecretAuth(bytes.TrimSpace(b))
}
l, err := net.Listen("tcp", address)
if err != nil {
panic(err)
}
var tlsCfg *tls.Config = nil
if insecure {
fmt.Println("WARN: TLS is disabled")
} else {
tlsCfg = cfg.TLSConfig()
auth.Schemes["cert"] = server.CertAuth
}
s := server.NewServer(l, auth, tlsCfg)
SetupSignalHandler(s)
fmt.Println("lipwig serving at", s.ListeningPort())
err = s.Serve()
if err != nil {
panic(err)
}
fmt.Println("exit.")
}