IB v1.0
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 = `
|
||||
<input type="text" name="title" placeholder="Naslov" value="{{.Title}}" />
|
||||
<input name="ID" type="hidden" value="{{.ID}}" />
|
||||
<div id="editorcontainer">
|
||||
<textarea id="editor" name="editor">{{.GemtextContent.String}}</textarea>
|
||||
<textarea id="editor" name="editor" rows="40" columns="80">{{.GemtextContent.String}}</textarea>
|
||||
</div>
|
||||
<input type="submit" value="Sačuvaj" />
|
||||
</form>
|
||||
|
||||
@@ -50,6 +50,11 @@ const html5Template = `
|
||||
h1 {
|
||||
color: #e6fbfb;
|
||||
}
|
||||
|
||||
.hidden_link {
|
||||
color: #f9f5c3;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -66,8 +71,9 @@ const html5Template = `
|
||||
<div>
|
||||
<br><br>
|
||||
<h2>Ostalo</h2>
|
||||
<a href="/a/">Arhiva</a><br>
|
||||
<a href="/a/">Arhiva</a><br>
|
||||
<a href="gemini://gemini.islambosna.ba/">Gemini stranica</a>
|
||||
<a class="hidden_link" href="/editor/n/">🌙</a>
|
||||
</div>
|
||||
</content>
|
||||
<footer>
|
||||
|
||||
Reference in New Issue
Block a user