2020-08-20 12:51:02 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2020-09-17 16:19:05 -04:00
|
|
|
"text/template"
|
|
|
|
|
2020-09-22 14:37:54 -04:00
|
|
|
"github.com/gorilla/mux"
|
2020-09-17 16:19:05 -04:00
|
|
|
"github.com/gorilla/securecookie"
|
2020-08-20 12:51:02 -04:00
|
|
|
)
|
|
|
|
|
2020-08-20 13:24:52 -04:00
|
|
|
var Conf *Config
|
2020-09-17 16:19:05 -04:00
|
|
|
var tpl *template.Template
|
|
|
|
var cookieHandler = securecookie.New(
|
|
|
|
securecookie.GenerateRandomKey(64),
|
|
|
|
securecookie.GenerateRandomKey(32))
|
2021-03-02 14:26:58 -05:00
|
|
|
var passwordTokenSet map[string]bool
|
2021-03-02 14:37:31 -05:00
|
|
|
var GitCommit string
|
2020-08-20 12:51:02 -04:00
|
|
|
|
|
|
|
func main() {
|
2020-08-20 13:24:52 -04:00
|
|
|
Conf, _ = LoadConfig()
|
2021-03-02 14:37:31 -05:00
|
|
|
version := GitCommit
|
2020-08-20 12:51:02 -04:00
|
|
|
log.Println("Loaded config")
|
2020-09-22 14:37:54 -04:00
|
|
|
router := mux.NewRouter().StrictSlash(true)
|
|
|
|
router.HandleFunc("/", homePage).Methods("GET")
|
|
|
|
router.HandleFunc("/register", signupPage).Methods("GET")
|
|
|
|
router.HandleFunc("/register", signup).Methods("POST")
|
|
|
|
router.HandleFunc("/login", loginPage).Methods("GET")
|
|
|
|
router.HandleFunc("/login", login).Methods("POST")
|
|
|
|
router.HandleFunc("/logout", logoutPage).Methods("GET")
|
|
|
|
router.HandleFunc("/token", tokenPage).Methods("GET")
|
2020-09-24 17:12:22 -04:00
|
|
|
router.HandleFunc("/profile/view", profilePage).Methods("GET")
|
|
|
|
router.HandleFunc("/profile/edit", profileEditPage).Methods("GET")
|
|
|
|
router.HandleFunc("/profile/edit", profileEdit).Methods("POST")
|
2020-11-10 17:58:24 -05:00
|
|
|
router.HandleFunc("/minecraft", minecraftPage).Methods("GET")
|
|
|
|
router.HandleFunc("/minecraft/link", minecraftLink).Methods("POST")
|
|
|
|
router.HandleFunc("/minecraft/link/success", minecraftLinkSuccessPage).Methods("GET")
|
|
|
|
router.HandleFunc("/minecraft/link/error", minecraftLinkErrorPage).Methods("GET")
|
2020-11-12 14:33:01 -05:00
|
|
|
router.HandleFunc("/reset", resetPageFront).Methods("GET")
|
|
|
|
router.HandleFunc("/reset", resetLookup).Methods("POST")
|
|
|
|
router.HandleFunc("/reset/form", resetPageBack).Methods("GET")
|
|
|
|
router.HandleFunc("/reset/form", reset).Methods("POST")
|
|
|
|
router.HandleFunc("/reset/success", resetSuccessPage).Methods("GET")
|
|
|
|
router.HandleFunc("/reset/error", resetErrorPage).Methods("GET")
|
2020-09-17 16:19:05 -04:00
|
|
|
log.Printf("Registering templates from %v/\n", Conf.TplPath)
|
2020-09-22 18:21:01 -04:00
|
|
|
tpl = template.Must(template.ParseGlob(Conf.TplPath + "/*"))
|
2020-11-12 14:51:48 -05:00
|
|
|
if Conf.UserTplPath != "" {
|
2020-11-12 14:54:18 -05:00
|
|
|
log.Printf("Registering user templates from %v/\n", Conf.UserTplPath)
|
2020-11-12 14:51:48 -05:00
|
|
|
tpl = template.Must(tpl.ParseGlob(Conf.UserTplPath + "/*"))
|
|
|
|
}
|
2020-09-24 16:14:54 -04:00
|
|
|
log.Println("Performing LDAP checks")
|
|
|
|
log.Println("Loading max employeeNumber for account creation")
|
|
|
|
i, err := findLDAPMaxID()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("WARN: Unable to calculate max employeeNumber: %v\n", err)
|
|
|
|
} else {
|
|
|
|
Conf.MaxID = i
|
|
|
|
log.Printf("Max employeeNumber set to %v\n", Conf.MaxID)
|
|
|
|
}
|
2021-03-02 14:26:58 -05:00
|
|
|
passwordTokenSet = make(map[string]bool)
|
2021-03-02 14:37:31 -05:00
|
|
|
log.Printf("Guildgate v%v starting on %v\n", version, Conf.Port)
|
2020-08-23 17:53:48 -04:00
|
|
|
if Conf.Tls {
|
2020-08-27 12:45:00 -04:00
|
|
|
log.Printf("Starting TLS\n")
|
|
|
|
if Conf.Cert == "" {
|
|
|
|
log.Fatalf("Need to specify a certificate if using TLS!\n")
|
|
|
|
} else if Conf.Key == "" {
|
|
|
|
log.Fatalf("Need to specify a private key is usingTLS!\n")
|
|
|
|
} else {
|
2020-09-22 14:37:54 -04:00
|
|
|
err = http.ListenAndServeTLS(":"+Conf.Port, Conf.Cert, Conf.Key, router)
|
2020-08-27 12:45:00 -04:00
|
|
|
}
|
2020-08-23 17:53:48 -04:00
|
|
|
} else {
|
2020-08-27 12:45:00 -04:00
|
|
|
log.Printf("Starting unencrypted\n")
|
2020-09-22 14:37:54 -04:00
|
|
|
err = http.ListenAndServe(":"+Conf.Port, router)
|
2020-08-27 12:45:00 -04:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("HTTP server failed with %v\n", err)
|
2020-08-23 17:53:48 -04:00
|
|
|
}
|
2020-08-20 12:51:02 -04:00
|
|
|
}
|