3 * _| || |_/ ___| ___ _ __ _ __ ___ | |
4 * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
5 * |_ _|___) | __/ |_) | |_) | (_) |_|
6 * |_||_| |____/ \___| .__/| .__/ \___/(_)
11 * Copyright (C) The #Seppo contributors. All rights reserved.
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 (* https://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html *)
29 let ( >>= ) = Result.bind
30 let ( let* ) = Result.bind
33 let exe = Filename.basename
Sys.executable_name
in
34 msgs
|> List.cons
exe |> String.concat
": " |> prerr_endline
;
40 let w = acct
|> Webfinger.well_known_uri
in
41 (try w |> Webfinger.Client.http_get
43 Ezjsonm.Parse_error
(_
, e
) ->
44 Logr.err (fun m
-> m
"%s failed to decipher %a" E.e9001
Uri.pp
w);
48 (* TODO add more compliance rules. Check pk. *)
49 let actor ?
(key
= None
) u
=
51 |> Ap.Actor.http_get ~key
54 >>= As2.Profile.pubkey_pem
55 >>= As2.PubKeyPem.pub_from_pem
56 >>= As2.PubKeyPem.check
59 let exec (args
: string list
) =
60 let print_version oc
=
61 let exe = Filename.basename
Sys.executable_name
in
62 Printf.fprintf oc
"%s: https://Seppo.Social/v/%s+%s\n" exe Version.dune_project_version
Version.git_sha
;
65 let _exe = Filename.basename
Sys.executable_name
in
68 Query AP servers.\n\n\
69 If run from commandline:\n\n\
72 \ print this help\n\n\
76 \ webfinger alice@example.org\n\
77 \ the webfinger json parsed and re-written.\n\n\
78 \ actor https://example.org/actors/alice\n\
79 \ the AP profile page parsed and re-written.\n\n\
81 \ show 'description of a project'\n\n";
86 Logr.err (fun m
-> m
"%s '%s': %s" E.e1006 s e
);
89 Logr.info
(fun m
-> m
"%s." s
);
93 | [ _
; "-h" ] | [ _
; "--help" ] -> print_help oc
94 | [ _
; "-V" ] | [ _
; "--version" ] -> print_version oc
96 (match "doap.rdf" |> Res.read
with
97 | Some v
-> Printf.fprintf oc
"%s" v
100 | [ _
; "webfinger"; acct
] ->
106 |> As2_vocab.Encode.Webfinger.query_result ~base
:Uri.empty
107 |> Ezjsonm.value_to_channel stdout
;
110 | [ _
; "actor"; url
] ->
111 (let* p
= url
|> Uri.of_string
|> actor in
112 let lang = As2_vocab.Constants.ActivityStreams.und
in
114 |> As2_vocab.Encode.person ~
lang ~base
:Uri.empty
115 |> Ezjsonm.value_to_channel stdout
;
118 | _
-> err 2 [ "get help with -h" ]