From 47dca324a446bf088164a8e27404c2b8db89ccf5 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sat, 21 Aug 2021 18:28:30 -0400 Subject: Turn it into a simple rough draft of an API driven pastebin --- templates/base.tpl | 21 +++++++++++++++++++ templates/error.tpl | 11 ++++++++++ templates/index.tpl | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/view.tpl | 9 ++++++++ 4 files changed, 101 insertions(+) create mode 100644 templates/base.tpl create mode 100644 templates/error.tpl create mode 100644 templates/index.tpl create mode 100644 templates/view.tpl (limited to 'templates') diff --git a/templates/base.tpl b/templates/base.tpl new file mode 100644 index 0000000..ec1aeb5 --- /dev/null +++ b/templates/base.tpl @@ -0,0 +1,21 @@ +{{define "base"}} + + + + + + {{template "title" .}} + + + + + +{{template "content" .}} + + + +{{end}} diff --git a/templates/error.tpl b/templates/error.tpl new file mode 100644 index 0000000..4b36bdb --- /dev/null +++ b/templates/error.tpl @@ -0,0 +1,11 @@ +{{template "base" .}} + +{{define "title"}}Error {{.Short}}{{end}} + +{{define "content"}} + +

{{.Short}}

+ +{{.Long}} + +{{end}} diff --git a/templates/index.tpl b/templates/index.tpl new file mode 100644 index 0000000..10ede35 --- /dev/null +++ b/templates/index.tpl @@ -0,0 +1,60 @@ +{{template "base" .}} + +{{define "title"}}Simple Pastebin{{end}} + +{{define "content"}} +

Simple pastebin

+ +This is a simple pastebin that effectively only has API access. + +Usernames are hard coded into the configuration file. The format is simple: + +
Users:
+  username:
+    Password: "password"
+
+ +If there are any non empty `Password` fields they will be replaced with the +hash on first run. + + +Run a request to `/login` to receieve a token: + +
$ curl -D /dev/fd/2 -d '{"Username": "mitch", "Password": "secret"}' localhost:6130/login
+HTTP/1.1 200 OK
+Authorization: Bearer eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjk2MjY4ODMsInN1YiI6Im1pdGNoIn0.8t5IU8WCVWwMozWyufGqFFmKF1mggLI7V8U1tX-u3yllTalbQRgG2PrxPQeVU9pAM6fuapmydXXZYGpehezqDw
+Content-Type: application/json
+Date: Sat, 21 Aug 2021 22:08:03 GMT
+Content-Length: 180
+
+{"token":"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjk2MjY4ODMsInN1YiI6Im1pdGNoIn0.8t5IU8WCVWwMozWyufGqFFmKF1mggLI7V8U1tX-u3yllTalbQRgG2PrxPQeVU9pAM6fuapmydXXZYGpehezqDw"}
+$ 
+
+ +To add a paste use `/new`: + +
$ export token=eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjk2MjY4ODMsInN1YiI6Im1pdGNoIn0.8t5IU8WCVWwMozWyufGqFFmKF1mggLI7V8U1tX-u3yllTalbQRgG2PrxPQeVU9pAM6fuapmydXXZYGpehezqDw
+$ curl -D /dev/fd/2 -X POST -d '
+	{
+		"Title": "My title!",
+		"Tags": {"code": null, "c": null},
+		"Content": "This is my test content.\n\n\n"
+	}' -H "Authorization: Bearer $token" localhost:6130/new
+HTTP/1.1 200 OK
+Content-Type: application/json
+Date: Sat, 21 Aug 2021 22:20:53 GMT
+Content-Length: 46
+
+{"id":"YAv-lFYh9xpnP6ZZ0-Hu_w","status":"ok"}
+$ 
+
+ +Viewing the json is pretty easy: + +
$ curl localhost:6130/view/json/YAv-lFYh9xpnP6ZZ0-Hu_w
+{"Id":"YAv-lFYh9xpnP6ZZ0-Hu_w","Title":"My
+title!","Tags":{"c":{},"code":{}},"Content":"This is my test content.\n\n\n"}
+$ 
+
+ +{{end}} diff --git a/templates/view.tpl b/templates/view.tpl new file mode 100644 index 0000000..76efe57 --- /dev/null +++ b/templates/view.tpl @@ -0,0 +1,9 @@ +{{template "base" .}} + +{{define "title"}}Paste: {{.Title}}{{end}} + +{{define "content"}} +

Paste: "{{.Title}}"

+ +
{{.GetContent}}
+{{end}} -- cgit v1.2.3