ctucx.git: alpine-pkgs

My personal alpine-packages [deprecated in favor of nixos]

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
From 2a57ef2f0aaaec3bc2d8061368d23f02bbd09452 Mon Sep 17 00:00:00 2001
From: "Leah (ctucx)" <leah@ctu.cx>
Date: Wed, 3 Mar 2021 19:19:59 +0100
Subject: [PATCH] Separate webfinger domain from host domain

---
 lib/pleroma/web/web_finger.ex | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/web/web_finger.ex b/lib/pleroma/web/web_finger.ex
index 15002b2..124367d 100644
--- a/lib/pleroma/web/web_finger.ex
+++ b/lib/pleroma/web/web_finger.ex
@@ -31,8 +31,15 @@ def host_meta do
   end

   def webfinger(resource, fmt) when fmt in ["XML", "JSON"] do
+    domain = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:domain]
     host = Pleroma.Web.Endpoint.host()
-    regex = ~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@#{host}/
+
+    regex =
+      if domain do
+        ~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@(#{host}|#{domain})/
+      else
+        ~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@#{host}/
+      end

     with %{"username" => username} <- Regex.named_captures(regex, resource),
          %User{} = user <- User.get_cached_by_nickname(username) do
@@ -65,8 +72,15 @@ defp gather_aliases(%User{} = user) do
   def represent_user(user, "JSON") do
     {:ok, user} = User.ensure_keys_present(user)

+    host =
+      if Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:domain] do
+        Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:domain]
+      else
+        Pleroma.Web.Endpoint.host()
+      end
+
     %{
-      "subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}",
+      "subject" => "acct:#{user.nickname}@#{host}",
       "aliases" => gather_aliases(user),
       "links" => gather_links(user)
     }
@@ -84,11 +98,18 @@ def represent_user(user, "XML") do
       gather_links(user)
       |> Enum.map(fn link -> {:Link, link} end)

+    host =
+      if Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:domain] do
+        Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:domain]
+      else
+        Pleroma.Web.Endpoint.host()
+      end
+
     {
       :XRD,
       %{xmlns: "http://docs.oasis-open.org/ns/xri/xrd-1.0"},
       [
-        {:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"}
+        {:Subject, "acct:#{user.nickname}@#{host}"}
       ] ++ aliases ++ links
     }
     |> XmlBuilder.to_doc()
--
2.30.1