forked from dannluciano/vpnweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpnweb.go
60 lines (49 loc) · 1.1 KB
/
vpnweb.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
package main
import (
"golang.org/x/net/http2"
"log"
"net/http"
"os"
)
var (
statusFile = "/etc/openvpn/openvpn-status.log"
username = "dannluciano"
password = "dlcorp"
env = "dev"
cwd = "."
)
func Setup() {
log.SetPrefix("VPNWEB: ")
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
log.Println("CWD:", cwd)
environment := os.Getenv("ENV")
if environment == "" {
os.Setenv("ENV", "dev")
} else {
env = environment
}
log.Println("ENV:", env)
if env == "dev" {
statusFile = "public/openvpn-status.log"
}
LoadTemplates()
}
func main() {
Setup()
http.HandleFunc("/", HomeHandler)
http.HandleFunc("/env/", EnvHandler)
http.HandleFunc("/reload/", ReloadHandler)
http.HandleFunc("/status/", StatusHandler)
http.Handle("/static/", http.StripPrefix("/static/",
http.FileServer(http.Dir(cwd + "/public"))))
srv := &http.Server{
Addr: ":8000",
}
http2.ConfigureServer(srv, &http2.Server{})
log.Println("https://localhost:8000")
log.Fatal(srv.ListenAndServeTLS(cwd + "/keys/cert.pem", cwd + "/keys/key.pem"))
}