From 867761a2e764c6c6327434585498ed62c54f6eac Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sun, 3 Dec 2023 12:52:07 -0600 Subject: Formatting, support whitelist --- bin/main.ml | 86 +++++++++++++++++++++++++++++--------------------------- bin/template.eml | 39 +++++++++++++++++-------- 2 files changed, 72 insertions(+), 53 deletions(-) (limited to 'bin') diff --git a/bin/main.ml b/bin/main.ml index 29dea84..579b334 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,21 +1,26 @@ open Wormhole let (fake_post : Post.t) = - { - link = "https://mccd.space"; - summary = "My personal blog"; - tags = [ "cool"; "article" ]; - published = "2020-01-01T00:00:00Z"; - author = "Marc"; - } - -let (fake_post_2 : Post.t) = { link = "https://google.com"; - summary = "Some other cool article that I just made"; - tags = [ "cool"; "something" ]; - published = "2020-01-02T00:00:00Z"; - author = "Bob"; + summary = + "

@wormhole

https://google.com

This is a place on the web where \ + you can search for things

#goodie #othergoodie

"; + tags = [ "#goodie" ]; + published = "2023-08-23"; + author = "marcc.rooted"; + author_link = "https://www.fosstodon.org/@marcc"; } let webfinger = @@ -109,38 +114,37 @@ let () = Dream.post "/inbox" (fun request -> let%lwt body = Dream.body request in Dream.log "Got body: %s" body; - let signature = Dream.headers request "signature" in - Dream.log "Got signature: %s" (String.concat " " signature); let message_object = Yojson.Safe.from_string body |> Post.mastodon_post_of_yojson in let%lwt actor = User.get_user (Post.mastodon_actor message_object) in - match actor with - | Error e -> - Dream.log "User not found %s" (Printexc.to_string e); - let code = Some 400 in - Dream.json ?code "User not found" - | Ok actor -> - Dream.log "User found"; - let pem = User.get_public_pem actor |> Result.to_option in - let%lwt valid_request = Sig.verify_request pem request in - (match valid_request with - | Error e -> - Dream.log "Error verifying request %s" - Printexc.(to_string e); - let code = Some 500 in - Dream.json ?code "Invalid request" - | Ok false -> - Dream.log "Unauthorized request"; - let code = Some 501 in - Dream.json ?code "Unauthorized" - | Ok true -> - message_object - |> Post.post_of_mastodon_post (User.name actor) - |> Post.add; - message_object |> Post.yojson_of_mastodon_post - |> Yojson.Safe.to_string |> Dream.log "Added post %s"; - Dream.json "Added user")); + Dream.log "User found"; + let pem = User.get_public_pem actor |> Result.to_option in + let%lwt valid_request = Sig.verify_request pem request in + let post = + message_object |> Post.post_of_mastodon_post (User.name actor) + in + let in_whitelist = + List.mem (Post.mastodon_actor message_object) actor_whitelist + in + match (valid_request, disable_auth, in_whitelist) with + | Error e, "false", _ -> + Dream.log "Error verifying request %s" Printexc.(to_string e); + let code = Some 500 in + Dream.json ?code "Invalid request" + | Ok false, "false", _ -> + Dream.log "Unauthorized request"; + let code = Some 401 in + Dream.json ?code "Unauthorized" + | _, _, false -> + Dream.log "Unauthorized request"; + let code = Some 401 in + Dream.json ?code "Unauthorized, not in whitelist" + | _, _, _ -> + post |> Post.add; + message_object |> Post.yojson_of_mastodon_post + |> Yojson.Safe.to_string |> Dream.log "Added post %s"; + Dream.json "Added user"); ] diff --git a/bin/template.eml b/bin/template.eml index 96e4f62..1a3c888 100644 --- a/bin/template.eml +++ b/bin/template.eml @@ -4,6 +4,11 @@ open Wormhole.Post let render (posts: Post.t list) = + + Sensemaking Galaxy - -

Sensemaking Galaxy

-
- rss + +
+

SENSEMAKING GALAXY

+ + rss +
-

Links that have ended up in this Galaxy were sent through space -and time by the Sensemaking Wormhole.

-% posts |> List.iter begin fun { author; link; summary; tags; _ } -> -
- + +

Haling from other points in time and space, these posts traveled +here from across the cybernet via a Mastodon Wormhole.

+ Source code +
+% posts |> List.iter begin fun { published; author; author_link; summary; tags; _ } -> +
+ +
+ <%s published %> + ><%s author %> +
- <%s summary %> - >Link (<%s Post.get_tld link %>) + <%s! summary %>
- Submitted by: <%s author %>
% tags |> List.iter begin fun tag -> <%s tag %> @@ -40,5 +53,7 @@ and time by the Sensemaking Wormhole.

% end; +
+ -- cgit v1.2.3