Compare commits
11 Commits
8ef9e31446
...
076a0faea3
Author | SHA1 | Date | |
---|---|---|---|
076a0faea3 | |||
cad14ac461 | |||
f927362c0b | |||
3f00d820dd | |||
4131f77e9f | |||
369849a493 | |||
462ee38b96 | |||
59fcb1fc47 | |||
bcdb16bc6e | |||
bae6ae44ef | |||
fe88320675 |
|
@ -2,7 +2,7 @@ pipeline:
|
||||||
build:
|
build:
|
||||||
image: golang
|
image: golang
|
||||||
commands:
|
commands:
|
||||||
- go get github.com/pstuifzand/microsub-server/cmd/eksterd
|
- go get github.com/pstuifzand/microsub-server/...
|
||||||
- go build github.com/pstuifzand/microsub-server/cmd/eksterd
|
- go build github.com/pstuifzand/microsub-server/cmd/eksterd
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
FROM ubuntu
|
FROM ubuntu
|
||||||
RUN apt-get -y update && apt-get install -y ca-certificates
|
RUN apt-get -y update && apt-get install -y ca-certificates
|
||||||
|
RUN ["mkdir", "/usr/share/eksterd"]
|
||||||
ADD ./eksterd /usr/local/bin
|
ADD ./eksterd /usr/local/bin
|
||||||
|
ADD ./templates /usr/share/eksterd
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
ENV EKSTER_TEMPLATES "/usr/share/eksterd"
|
||||||
ENTRYPOINT ["/usr/local/bin/eksterd"]
|
ENTRYPOINT ["/usr/local/bin/eksterd"]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# build stage
|
# build stage
|
||||||
FROM golang:1.10.2-alpine3.7 AS build-env
|
FROM golang:1.10.2-alpine3.7 AS build-env
|
||||||
RUN apk --no-cache add git
|
RUN apk --no-cache add git
|
||||||
RUN go get github.com/pstuifzand/ekster/cmd/eksterd
|
RUN go get github.com/pstuifzand/ekster/...
|
||||||
|
|
||||||
# final stage
|
# final stage
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
@ -10,5 +10,6 @@ RUN ["mkdir", "-p", "/opt/micropub"]
|
||||||
WORKDIR /opt/micropub
|
WORKDIR /opt/micropub
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
COPY --from=build-env /go/bin/eksterd /app/
|
COPY --from=build-env /go/bin/eksterd /app/
|
||||||
COPY --from=build-env /go/bin/ek /app/
|
RUN ["mkdir", "/app/templates"]
|
||||||
|
COPY --from=build-env /go/src/github.com/pstuifzand/ekster/templates /app/templates
|
||||||
ENTRYPOINT ["/app/eksterd"]
|
ENTRYPOINT ["/app/eksterd"]
|
||||||
|
|
|
@ -131,7 +131,8 @@ func (h *hubIncomingBackend) GetFeeds() []Feed {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
feeds := []Feed{}
|
feeds := []Feed{}
|
||||||
|
|
||||||
feedKeys, err := redis.Strings(conn.Do("KEYS feed:*"))
|
// FIXME(peter): replace with set of currently checked feeds
|
||||||
|
feedKeys, err := redis.Strings(conn.Do("KEYS", "feed:*"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return feeds
|
return feeds
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -68,17 +69,24 @@ type authResponse struct {
|
||||||
Me string `json:"me"`
|
Me string `json:"me"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type indexPage struct {
|
||||||
|
Session session
|
||||||
|
}
|
||||||
|
type settingsPage struct {
|
||||||
|
Session session
|
||||||
|
}
|
||||||
|
|
||||||
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
conn := pool.Get()
|
conn := pool.Get()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
|
@ -109,27 +117,22 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(w, "<h1>Ekster - Microsub server</h1>")
|
t, err := template.ParseFiles(
|
||||||
fmt.Fprintln(w, `<p><a href="/settings">Settings</a></p>`)
|
os.Getenv("EKSTER_TEMPLATES") + "/index.html",
|
||||||
|
)
|
||||||
if sess.LoggedIn {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "SUCCESS Me = %s", sess.Me)
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
fmt.Fprintln(w, `
|
return
|
||||||
<h2>Logout</h2>
|
|
||||||
<form action="/auth/logout" method="post">
|
|
||||||
<button type="submit">Logout</button>
|
|
||||||
</form>
|
|
||||||
`)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintln(w, `
|
|
||||||
<h2>Sign in to Ekster</h2>
|
|
||||||
<form action="/auth" method="post">
|
|
||||||
<input type="text" name="url" placeholder="https://example.com/">
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var page indexPage
|
||||||
|
page.Session = sess
|
||||||
|
|
||||||
|
err = t.ExecuteTemplate(w, "index.html", page)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/auth/callback" {
|
} else if r.URL.Path == "/auth/callback" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
|
@ -203,6 +206,43 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "ERROR: HTTP response code from authorization_endpoint (%s) %d \n", sess.AuthorizationEndpoint, resp.StatusCode)
|
fmt.Fprintf(w, "ERROR: HTTP response code from authorization_endpoint (%s) %d \n", sess.AuthorizationEndpoint, resp.StatusCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if r.URL.Path == "/settings" {
|
||||||
|
c, err := r.Cookie("session")
|
||||||
|
if err == http.ErrNoCookie {
|
||||||
|
http.Redirect(w, r, "/", 302)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sessionVar := c.Value
|
||||||
|
var sess session
|
||||||
|
sessionKey := "session:" + sessionVar
|
||||||
|
data, err := redis.Values(conn.Do("HGETALL", sessionKey))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = redis.ScanStruct(data, &sess)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t, err := template.ParseFiles(
|
||||||
|
os.Getenv("EKSTER_TEMPLATES") + "/settings.html",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var page settingsPage
|
||||||
|
page.Session = sess
|
||||||
|
|
||||||
|
err = t.ExecuteTemplate(w, "settings.html", page)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} else if r.Method == http.MethodPost {
|
} else if r.Method == http.MethodPost {
|
||||||
if r.URL.Path == "/auth" {
|
if r.URL.Path == "/auth" {
|
||||||
|
|
65
templates/index.html
Normal file
65
templates/index.html
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Ekster</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||||
|
<div class="navbar-brand">
|
||||||
|
<a class="navbar-item" href="/">
|
||||||
|
Ekster
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="menu">
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ if .Session.LoggedIn }}
|
||||||
|
<div id="menu" class="navbar-menu">
|
||||||
|
<a class="navbar-item" href="/settings">
|
||||||
|
Settings
|
||||||
|
</a>
|
||||||
|
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||||
|
Profile
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1 class="title">Ekster - Microsub server</h1>
|
||||||
|
|
||||||
|
{{ if .Session.LoggedIn }}
|
||||||
|
<h2 class="title">Logout</h2>
|
||||||
|
<form action="/auth/logout" method="post">
|
||||||
|
<button type="submit" class="button is-info">Logout</button>
|
||||||
|
</form>
|
||||||
|
{{ else }}
|
||||||
|
<h2 class="title">Sign in to Ekster</h2>
|
||||||
|
<form action="/auth" method="post">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="url"></label>
|
||||||
|
<div class="control">
|
||||||
|
<input type="text" name="url" id="url" class="input" placeholder="https://example.com/">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field is-grouped">
|
||||||
|
<div class="control">
|
||||||
|
<button type="submit" class="button is-info">Login</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</body>
|
||||||
|
</html>
|
46
templates/settings.html
Normal file
46
templates/settings.html
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Ekster</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||||
|
<div class="navbar-brand">
|
||||||
|
<a class="navbar-item" href="/">
|
||||||
|
Ekster
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="menu">
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
<span aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ if .Session.LoggedIn }}
|
||||||
|
<div id="menu" class="navbar-menu">
|
||||||
|
<a class="navbar-item" href="/settings">
|
||||||
|
Settings
|
||||||
|
</a>
|
||||||
|
<a class="navbar-item" href="{{ .Session.Me }}">
|
||||||
|
Profile
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1 class="title">Ekster - Microsub server</h1>
|
||||||
|
|
||||||
|
{{ if .Session.LoggedIn }}
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user