new main page

This commit is contained in:
samantha42
2026-05-29 10:38:23 +02:00
parent ce552fa365
commit d8903a42ed
26 changed files with 4454 additions and 30 deletions
+25 -1
View File
@@ -7,6 +7,8 @@ import (
"log"
"net/http"
"os"
"github.com/joho/godotenv"
)
type Config struct {
@@ -25,13 +27,19 @@ func loadConfig() (*Config, error) {
// ---------- Main ----------
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
port := flag.String("port", "8081", "port to listen on")
flag.Parse()
fs := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/about.html") })
http.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/index.html") })
http.HandleFunc("GET /infra", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/infra.html") })
http.HandleFunc("GET /finance", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/finance.html") })
http.HandleFunc("GET /cinema", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/cinema.html") })
@@ -39,6 +47,22 @@ func main() {
http.HandleFunc("GET /42", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/42.html") })
http.HandleFunc("GET /secret", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/secret.html") })
http.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/icon.png") })
http.HandleFunc("GET /login", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/login.html") })
http.HandleFunc("POST /login", func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
password := r.FormValue("password")
totp := r.FormValue("totp")
if os.Getenv("password") == password && os.Getenv("auth") == totp {
fmt.Fprintf(w, "logged in")
http.Redirect(w, r, "/admin", http.StatusAccepted)
} else {
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, "password or auth is wrong")
}
})
http.HandleFunc("GET /status", func(w http.ResponseWriter, r *http.Request) {
config, err := loadConfig()