-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
75 lines (60 loc) · 1.45 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
package main
import (
"embed"
"flag"
"io/fs"
"log"
"net/http"
)
/*
Uptime Monitor ToolBox
Author: tobychui
This is a generic tool for hosting basic information required for my server daily operations
*/
//go:embed web/*
var content embed.FS
// Default configs
var configFilepath = "config.json"
var logFilepath = "uptime.log"
var exampleTarget = Target{
ID: "example",
Name: "Example",
URL: "example.com",
Protocol: "https",
}
var usingConfig *Config
var onlineStatusLog = map[string][]*Record{}
// TOTP configs
var totpConfig *TotpConfig
// Set this to true to use file system based UI files
var uiDebugMode = false
// Flags
var listeningPort = flag.String("p", ":8089", "Listening endpoint for http server")
func main() {
flag.Parse()
//Start the uptime monitor
err := UptimeMonitorInit()
if err != nil {
panic(err)
}
//Start TOTP resolver
err = totpInit()
if err != nil {
panic(err)
}
http.HandleFunc("/utm/update", HandleUptimeLogRead)
http.HandleFunc("/totp/update", HandleTOTPUpdate)
var webfs, _ = fs.Sub(content, "web")
if uiDebugMode {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.Dir("./web")).ServeHTTP(w, r)
})
} else {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.FileServer(http.FS(webfs)).ServeHTTP(w, r)
})
}
//Start the web server interface
log.Println("Listening on :8089")
http.ListenAndServe(*listeningPort, nil)
}