diff --git a/cethttp/cethttp.go b/cethttp/cethttp.go index 5916cac..9696a7f 100644 --- a/cethttp/cethttp.go +++ b/cethttp/cethttp.go @@ -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 { diff --git a/cethttp/editor.go b/cethttp/editor.go index 7c3f02b..24b78bf 100644 --- a/cethttp/editor.go +++ b/cethttp/editor.go @@ -53,6 +53,15 @@ const editorTemplate = ` color: #e6fbfb; } +textarea +{ + border:1px solid #999999; + width:98%; + margin:5px 0; + padding:1%; +} + + #editorcontainer { background-color: #ffffff; } @@ -71,7 +80,7 @@ const editorTemplate = `
- +
diff --git a/cethttp/template.go b/cethttp/template.go index 7d98910..d302e3b 100644 --- a/cethttp/template.go +++ b/cethttp/template.go @@ -50,6 +50,11 @@ const html5Template = ` h1 { color: #e6fbfb; } + + .hidden_link { + color: #f9f5c3; + text-decoration: none; + } @@ -66,8 +71,9 @@ const html5Template = `


Ostalo

- Arhiva
+ Arhiva
Gemini stranica + 🌙