Added skeleton for basic admin auth system

This commit is contained in:
2026-05-16 17:01:34 +02:00
parent d5c4cfa9d0
commit 4d53a6b471
9 changed files with 179 additions and 12 deletions
+18 -8
View File
@@ -8,29 +8,39 @@ import (
"192.168.1.180/odonax/filehost-athome/config"
"192.168.1.180/odonax/filehost-athome/database"
"192.168.1.180/odonax/filehost-athome/handlers"
)
func main() {
cfg := config.Load("config.toml")
cfgPath := "config.toml"
cfg := config.Load(cfgPath)
handlers.Cfg = &cfg
handlers.CfgPath = cfgPath
os.MkdirAll(cfg.DataDir+"/files", 0755)
db := database.Open(cfg.DataDir+"/hub.db")
defer db.Close()
tmpl, err := template.ParseFiles("templates/home.html")
if err != nil {
log.Fatal("Failed to load template:", err)
}
tmpl := template.Must(template.ParseGlob("templates/*.html"))
// tmpl, err := template.ParseFiles("templates/home.html")
// if err != nil {
// log.Fatal("Failed to load template:", err)
// }
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := map[string]string{
"Name": cfg.SiteName,
"Description": "This is where you'll own your files and share them freely.",
}
tmpl.Execute(w, data)
tmpl.ExecuteTemplate(w, "home.html", data)
})
log.Println("Starting filehost on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
http.HandleFunc("/setup", handlers.Setup(tmpl.Lookup("setup.html")))
http.HandleFunc("/login", handlers.Login(tmpl.Lookup("login.html")))
log.Printf("Starting filehost on %s\n", cfg.Port)
log.Fatal(http.ListenAndServe(cfg.Port, nil))
}