remove trailingplug dep

This commit is contained in:
FloatingGhost 2022-12-14 01:45:26 +00:00
parent bd6f1d6249
commit 04807c72f0
8 changed files with 42 additions and 78 deletions

View File

@ -116,7 +116,6 @@ defmodule Pleroma.Web.Endpoint do
plug(Phoenix.CodeReloader)
end
plug(Pleroma.Web.Plugs.TrailingFormatPlug)
plug(Plug.RequestId)
plug(Plug.Logger, log: :debug)

View File

@ -35,6 +35,8 @@ defmodule Pleroma.Web.Feed.UserController do
end
def feed(conn, %{"nickname" => nickname} = params) do
[nickname | _rest] = String.split(nickname, ".")
IO.puts(nickname)
format = get_format(conn)
format =

View File

@ -96,7 +96,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
# and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do
# and some backwards-compatibility to allow the `.json` extension
def nodeinfo(conn, %{"version" => version}) when version in ["2.0", "2.0.json"] do
conn
|> put_resp_header(
"content-type",
@ -105,7 +106,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
|> json(raw_nodeinfo())
end
def nodeinfo(conn, %{"version" => "2.1"}) do
def nodeinfo(conn, %{"version" => version}) when version in ["2.1", "2.1.json"] do
raw_response = raw_nodeinfo()
updated_software =

View File

@ -8,7 +8,6 @@ defmodule Pleroma.Web.Plugs.RemoteIp do
"""
alias Pleroma.Config
import Plug.Conn
@behaviour Plug
@ -16,15 +15,20 @@ defmodule Pleroma.Web.Plugs.RemoteIp do
def call(%{remote_ip: original_remote_ip} = conn, _) do
if Config.get([__MODULE__, :enabled]) do
%{remote_ip: new_remote_ip} = conn = RemoteIp.call(conn, remote_ip_opts())
assign(conn, :remote_ip_found, original_remote_ip != new_remote_ip)
{headers, proxies} = remote_ip_opts()
new_remote_ip = RemoteIp.from(conn.req_headers, headers: headers, proxies: proxies)
if new_remote_ip != original_remote_ip do
Map.put(conn, :remote_ip, new_remote_ip)
else
conn
end
else
conn
end
end
defp remote_ip_opts do
headers = Config.get([__MODULE__, :headers], []) |> MapSet.new()
headers = Config.get([__MODULE__, :headers], [])
reserved = Config.get([__MODULE__, :reserved], [])
proxies =
@ -36,13 +40,10 @@ defmodule Pleroma.Web.Plugs.RemoteIp do
end
defp maybe_add_cidr(proxy) when is_binary(proxy) do
proxy =
cond do
"/" in String.codepoints(proxy) -> proxy
InetCidr.v4?(InetCidr.parse_address!(proxy)) -> proxy <> "/32"
InetCidr.v6?(InetCidr.parse_address!(proxy)) -> proxy <> "/128"
end
InetCidr.parse(proxy, true)
cond do
"/" in String.codepoints(proxy) -> proxy
InetCidr.v4?(InetCidr.parse_address!(proxy)) -> proxy <> "/32"
InetCidr.v6?(InetCidr.parse_address!(proxy)) -> proxy <> "/128"
end
end
end

View File

@ -1,42 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.TrailingFormatPlug do
@moduledoc "Calls TrailingFormatPlug for specific paths. Ideally we would just do this in the router, but TrailingFormatPlug needs to be called before Plug.Parsers."
@behaviour Plug
@paths [
"/api/statusnet",
"/api/statuses",
"/api/qvitter",
"/api/search",
"/api/account",
"/api/friends",
"/api/mutes",
"/api/media",
"/api/favorites",
"/api/blocks",
"/api/friendships",
"/api/users",
"/users",
"/nodeinfo",
"/api/help",
"/api/externalprofile",
"/notice",
"/api/pleroma/emoji",
"/api/oauth_tokens"
]
def init(opts) do
TrailingFormatPlug.init(opts)
end
for path <- @paths do
def call(%{request_path: unquote(path) <> _} = conn, opts) do
TrailingFormatPlug.call(conn, opts)
end
end
def call(conn, _opts), do: conn
end

View File

@ -7,7 +7,7 @@ defmodule Pleroma.Mixfile do
version: version("3.5.0"),
elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
compilers: [:phoenix] ++ Mix.compilers(),
elixirc_options: [warnings_as_errors: warnings_as_errors()],
xref: [exclude: [:eldap]],
start_permanent: Mix.env() == :prod,
@ -94,7 +94,8 @@ defmodule Pleroma.Mixfile do
# Specifies OAuth dependencies.
defp oauth_deps do
oauth_strategy_packages =
System.get_env("OAUTH_CONSUMER_STRATEGIES")
"OAUTH_CONSUMER_STRATEGIES"
|> System.get_env()
|> to_string()
|> String.split()
|> Enum.map(fn strategy_entry ->
@ -118,13 +119,13 @@ defmodule Pleroma.Mixfile do
{:plug_cowboy, "~> 2.6"},
{:phoenix_pubsub, "~> 2.1"},
{:phoenix_ecto, "~> 4.4"},
{:inet_cidr, "~> 1.0.0"},
{:ecto_enum, "~> 1.4"},
{:ecto_sql, "~> 3.9.0"},
{:postgrex, ">= 0.16.3"},
{:oban, "~> 2.12.1"},
{:gettext, "~> 0.20.0"},
{:bcrypt_elixir, "~> 2.2"},
{:trailing_format_plug, "~> 0.0.7"},
{:fast_sanitize, "~> 0.2.3"},
{:html_entities, "~> 0.5"},
{:phoenix_html, "~> 3.2"},
@ -333,7 +334,7 @@ defmodule Pleroma.Mixfile do
# Pleroma: A lightweight social networking server
# Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
# Akkoma: The cooler pleroma
# Akkoma: Magically expressive social media
# Copyright © 2022-#{year} Akkoma Authors <https://akkoma.dev/>
# SPDX-License-Identifier: AGPL-3.0-only

View File

@ -115,7 +115,6 @@
"temple": {:git, "https://akkoma.dev/AkkomaGang/temple.git", "066a699ade472d8fa42a9d730b29a61af9bc8b59", [ref: "066a699ade472d8fa42a9d730b29a61af9bc8b59"]},
"tesla": {:hex, :tesla, "1.4.4", "bb89aa0c9745190930366f6a2ac612cdf2d0e4d7fff449861baa7875afd797b2", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.3", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "d5503a49f9dec1b287567ea8712d085947e247cb11b06bc54adb05bfde466457"},
"timex": {:hex, :timex, "3.7.9", "790cdfc4acfce434e442f98c02ea6d84d0239073bfd668968f82ac63e9a6788d", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "64691582e5bb87130f721fc709acfb70f24405833998fabf35be968984860ce1"},
"trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bd4fde4c15f3e993a999e019d64347489b91b7a9096af68b2bdadd192afa693f"},
"tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"},
"ueberauth": {:hex, :ueberauth, "0.10.3", "4a3bd7ab7b5d93d301d264f0f6858392654ee92171f4437d067d1ae227c051d9", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "1394f36a6c64e97f2038cf95228e7e52b4cb75417962e30418fbe9902b30e6d3"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},

View File

@ -10,23 +10,25 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
import Pleroma.Tests.Helpers, only: [clear_config: 2]
setup do:
clear_config(RemoteIp,
enabled: true,
headers: ["x-forwarded-for"],
proxies: [],
reserved: [
"127.0.0.0/8",
"::1/128",
"fc00::/7",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
)
setup do
clear_config([RemoteIp, :enabled], true)
clear_config([RemoteIp, :headers], ["x-forwarded-for"])
clear_config([RemoteIp, :proxies], [])
clear_config(
[RemoteIp, :reserved],
[
"127.0.0.0/8",
"::1/128",
"fc00::/7",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
)
end
test "disabled" do
clear_config(RemoteIp, enabled: false)
clear_config([RemoteIp, :enabled], false)
%{remote_ip: remote_ip} = conn(:get, "/")
@ -48,7 +50,8 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "custom headers" do
clear_config(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
clear_config([RemoteIp, :enabled], true)
clear_config([RemoteIp, :headers], ["cf-connecting-ip"])
conn =
conn(:get, "/")