This commit is contained in:
2023-11-27 19:44:23 +01:00
parent 477db1afa0
commit 091c333081
38 changed files with 48333 additions and 8334 deletions

View File

@@ -13,6 +13,26 @@ import (
//go:embed static/*
var staticFiles embed.FS
// Hardcoded list of usernames and passwords
var users = map[string]string{
"zahf": "Mikrofon savijen dvije case *55",
"teha4": "Subara zvucnik kontroler mobitel *-12",
// Add more users as needed
}
// Middleware for basic authentication
func basicAuthMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if !ok || users[username] != password {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, "Unauthorized.", http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}
func StartServer(waitgroup *sync.WaitGroup) {
defer waitgroup.Done()
@@ -30,8 +50,12 @@ func StartServer(waitgroup *sync.WaitGroup) {
r.HandleFunc("/a/", archiveHandler)
r.HandleFunc("/y/{year}/", yearHandler)
r.HandleFunc("/y/{year}/m/{month}/", monthHandler)
r.HandleFunc("/editor/e/{postID}", editHandler)
r.HandleFunc("/editor/n/", newHandler)
// Apply basic authentication middleware to /editor/ routes
editorRouter := r.PathPrefix("/editor/").Subrouter()
editorRouter.Use(basicAuthMiddleware)
editorRouter.HandleFunc("/e/{postID}", editHandler)
editorRouter.HandleFunc("/n/", newHandler)
err = http.ListenAndServe(":8018", r)
if err != nil {