small pixel drawing of a pufferfish j3s.sh

yuuuge updates
Jesse Olson j3s@c3f.net
Fri, 11 Feb 2022 07:16:49 +0000
commit

f153148ea4fb8cbbe67a395b66e7429a0d6a84ff

parent

ff2b4b24fc02d38cac64b5fc7afaede0381ecb1b

M go.modgo.mod

@@ -2,4 +2,7 @@ module git.j3s.sh/j3s.sh

go 1.16 -require github.com/SlyMarbo/rss v1.0.1 +require ( + filippo.io/age v1.0.0 + github.com/SlyMarbo/rss v1.0.1 +)
M go.sumgo.sum

@@ -1,4 +1,18 @@

+filippo.io/age v1.0.0 h1:V6q14n0mqYU3qKFkZ6oOaF9oXneOviS3ubXsSVBRSzc= +filippo.io/age v1.0.0/go.mod h1:PaX+Si/Sd5G8LgfCwldsSba3H1DDQZhIhFGkhbHaBq8= +filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/SlyMarbo/rss v1.0.1 h1:fiaIU5UhcXauVOniHOIocWG7uj8Ej6pHNarMGPJilzA= github.com/SlyMarbo/rss v1.0.1/go.mod h1:JNF+T33oj4m5WLCQXpBTCgO+SxRbYVgdiiimHNgzcbA= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg= +golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
M main.gomain.go

@@ -5,11 +5,15 @@ "html/template"

"log" "net/http" "os" + "io" "path/filepath" "strings" + "bytes" "git.j3s.sh/j3s.sh/feed" "github.com/SlyMarbo/rss" + "filippo.io/age" + "filippo.io/age/armor" ) // templateData is a mega-struct that gets

@@ -38,8 +42,9 @@

fs := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", fs)) + http.HandleFunc("/age.html", serveAge) http.HandleFunc("/review/", babyHandler) - http.HandleFunc("/idea/", babyHandler) + http.HandleFunc("/thought/", babyHandler) http.HandleFunc("/", serveTemplate) log.Println("listening on :4666 tbh")

@@ -121,3 +126,65 @@ log.Println(err.Error())

http.Error(w, http.StatusText(500), 500) } } + +type AgeForm struct { + Success bool + PublicKey string + Message string +} + +func serveAge(w http.ResponseWriter, r *http.Request) { + lp := filepath.Join("templates", "layout.html") + fp := filepath.Join("templates", "age.html") + + tmpl, err := template.ParseFiles(lp, fp) + if err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + + if r.Method != http.MethodPost { + tmpl.ExecuteTemplate(w, "layout", nil) + return + } + + formdeets := AgeForm{ + PublicKey: r.FormValue("pubkey"), + Message: r.FormValue("message"), + } + + recipient, err := age.ParseX25519Recipient(formdeets.PublicKey) + if err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + + buf := &bytes.Buffer{} + armorWriter := armor.NewWriter(buf) + + write, err := age.Encrypt(armorWriter, recipient) + if err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + if _, err := io.WriteString(write, formdeets.Message); err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + if err := write.Close(); err != nil { + log.Println(err.Error()) + http.Error(w, http.StatusText(500), 500) + return + } + if err := armorWriter.Close(); err != nil { + log.Fatalf("Failed to close armor: %v", err) + } + + log.Printf("%+v", buf) + + tmpl.ExecuteTemplate(w, "layout", buf.String()) +}
M templates/about.htmltemplates/about.html

@@ -7,5 +7,5 @@ <p><i>existential crisis actor</p></i>

<b><p>email:</b> <a href="mailto:j3s@c3f.net">j3s@c3f.net</a></p> <b><p>matrix:</b> <a href="https://matrix.to/#/@j3s:cyberia.club">@j3s:cyberia.club</a></p> <b><p>twitter:</b> <a href="https://twitter.com/j3sj3sj3s">@j3sj3sj3s</a></p> -<p><b>age pubkey:</b> age12amwzaps3lfy5y7kup5h730d2alfcpxlrnahgxv7u4a877hl9c8s6h2wuf</p> +<p><b>age pubkey:</b> <a href="/age.html">/age.html</a></p> {{end}}
A templates/age.html

@@ -0,0 +1,19 @@

+{{define "title"}}jes age tool{{end}} +{{ define "body" }} +{{ if . }} +<p>encrypted data:</p> +<pre> +{{ . }} +</pre> +{{ else }} +<h1>age form</h1> +<p>use this form to encrypt age data for people, if you want. my public key is <pre>age12amwzaps3lfy5y7kup5h730d2alfcpxlrnahgxv7u4a877hl9c8s6h2wuf</pre></p> +<form method="POST"> + <label>age public key</label><br /> + <input type="text" name="pubkey" size="60"><br /> + <label>text to encrypt</label><br /> + <textarea name="message" rows="10" cols="60"></textarea><br /> + <input type="submit"> +</form> +{{ end }} +{{ end }}
D templates/ideas.html

@@ -1,23 +0,0 @@

-{{define "title"}}small ideas{{end}} -{{define "body"}} -<p><i>these are all tiny ideas</p></i> -<p><i>that don't deserve their own blog posts</p></i> -<h4>2022</h4> -<li><a href="/idea/dynamic-blog.html">making a dynamic blog</a></li> -<h4>2021</h4> -<li><a href="/idea/using-discord-is-morally-lazy.html">using-discord-is-morally-lazy</a></li> -<li><a href="/idea/git-necronomicon.html">git-necronomicon</a></li> -<li><a href="/idea/alpine-rock64.html">alpine-rock64</a></li> -<li><a href="/idea/storing-passwords-with-age.html">storing-passwords-with-age</a></li> -<h4>2020</h4> -<li><a href="/idea/building-a-fixed-gear-bicycle.html">building-a-fixed-gear-bicycle</a></li> -<li><a href="/idea/email-is-good-actually.html">email-is-good-actually</a></li> -<li><a href="/idea/fail2ban-sux.html">fail2ban-sux</a></li> -<li><a href="/idea/fixed-gear-update.html">fixed-gear-update</a></li> -<li><a href="/idea/holy-is-thy-name.html">holy-is-thy-name</a></li> -<li><a href="/idea/no-hacktober.html">no-hacktober</a></li> -<li><a href="/idea/pumpernickel-bread.html">pumpernickel-bread</a></li> -<li><a href="/idea/something-is-different.html">something-is-different</a></li> -<hr> -<img src="/static/thoughtscrombles.png" alt="scrombles the cat"> -{{end}}
M templates/layout.htmltemplates/layout.html

@@ -41,7 +41,7 @@ <p>

<a href="/now.html">now</a> <a href="/about.html">about</a> <a href="/reviews.html">reviews</a> - <a href="/ideas.html">ideas</a> + <a href="/thoughts.html">thoughts</a> </p> <p> <a href="https://git.j3s.sh">git -></a>
A templates/thoughts.html

@@ -0,0 +1,24 @@

+{{define "title"}}small thoughts and ideas{{end}} +{{define "body"}} +<p><i>these are all tiny thoughts</p></i> +<p><i>that don't deserve their own blog posts</p></i> +<h4>2022</h4> +<li><a href="/thought/being-alive-sucks.html">being alive sucks</a></li> +<li><a href="/thought/dynamic-blog.html">making a dynamic blog</a></li> +<h4>2021</h4> +<li><a href="/thought/using-discord-is-morally-lazy.html">using-discord-is-morally-lazy</a></li> +<li><a href="/thought/git-necronomicon.html">git-necronomicon</a></li> +<li><a href="/thought/alpine-rock64.html">alpine-rock64</a></li> +<li><a href="/thought/storing-passwords-with-age.html">storing-passwords-with-age</a></li> +<h4>2020</h4> +<li><a href="/thought/building-a-fixed-gear-bicycle.html">building-a-fixed-gear-bicycle</a></li> +<li><a href="/thought/email-is-good-actually.html">email-is-good-actually</a></li> +<li><a href="/thought/fail2ban-sux.html">fail2ban-sux</a></li> +<li><a href="/thought/fixed-gear-update.html">fixed-gear-update</a></li> +<li><a href="/thought/holy-is-thy-name.html">holy-is-thy-name</a></li> +<li><a href="/thought/no-hacktober.html">no-hacktober</a></li> +<li><a href="/thought/pumpernickel-bread.html">pumpernickel-bread</a></li> +<li><a href="/thought/something-is-different.html">something-is-different</a></li> +<hr> +<img src="/static/thoughtscrombles.png" alt="scrombles the cat"> +{{end}}