add env var to set opml route secret
This commit is contained in:
parent
886d1c37ff
commit
349795d012
6 changed files with 25 additions and 8 deletions
|
|
@ -24,6 +24,7 @@ config :pinchflat,
|
||||||
# If either is unset, basic auth will not be used.
|
# If either is unset, basic auth will not be used.
|
||||||
basic_auth_username: "",
|
basic_auth_username: "",
|
||||||
basic_auth_password: "",
|
basic_auth_password: "",
|
||||||
|
route_secret: "",
|
||||||
expose_feed_endpoints: false,
|
expose_feed_endpoints: false,
|
||||||
file_watcher_poll_interval: 1000,
|
file_watcher_poll_interval: 1000,
|
||||||
timezone: "UTC",
|
timezone: "UTC",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ end
|
||||||
|
|
||||||
config :pinchflat,
|
config :pinchflat,
|
||||||
basic_auth_username: System.get_env("BASIC_AUTH_USERNAME"),
|
basic_auth_username: System.get_env("BASIC_AUTH_USERNAME"),
|
||||||
basic_auth_password: System.get_env("BASIC_AUTH_PASSWORD")
|
basic_auth_password: System.get_env("BASIC_AUTH_PASSWORD"),
|
||||||
|
route_secret: System.get_env("ROUTE_SECRET")
|
||||||
|
|
||||||
arch_string = to_string(:erlang.system_info(:system_architecture))
|
arch_string = to_string(:erlang.system_info(:system_architecture))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,5 @@ services:
|
||||||
command: bash -c "chmod +x docker/docker-run.dev.sh && docker/docker-run.dev.sh"
|
command: bash -c "chmod +x docker/docker-run.dev.sh && docker/docker-run.dev.sh"
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
|
environment:
|
||||||
|
- ROUTE_SECRET=J8vaF1t
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ defmodule PinchflatWeb.Sources.SourceHTML do
|
||||||
end
|
end
|
||||||
|
|
||||||
def opml_feed_url(conn) do
|
def opml_feed_url(conn) do
|
||||||
url(conn, ~p"/sources/opml") <> ".xml"
|
url(conn, ~p"/secret/#{Application.get_env(:pinchflat, :route_secret)}/opml/feed") <> ".xml"
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_path_template_override_placeholders(media_profiles) do
|
def output_path_template_override_placeholders(media_profiles) do
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
|
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
|
||||||
<h2 class="text-title-md2 font-bold text-black dark:text-white">Sources</h2>
|
<h2 class="text-title-md2 font-bold text-black dark:text-white">Sources</h2>
|
||||||
<nav>
|
<nav>
|
||||||
<.button color="bg-transparent" x-data="{ copied: false }" x-on:click={~s"
|
<.button :if={Application.get_env(:pinchflat, :route_secret)} color="bg-transparent" x-data="{ copied: false }" x-on:click={~s"
|
||||||
copyWithCallbacks(
|
copyWithCallbacks(
|
||||||
'#{opml_feed_url(@conn)}',
|
'#{opml_feed_url(@conn)}',
|
||||||
() => copied = true,
|
() => copied = true,
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@ defmodule PinchflatWeb.Router do
|
||||||
plug :maybe_basic_auth
|
plug :maybe_basic_auth
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :protected_feeds do
|
pipeline :secret do
|
||||||
plug :basic_auth
|
plug :validate_secret
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/", PinchflatWeb do
|
scope "/secret/:secret", PinchflatWeb do
|
||||||
pipe_through :protected_feeds
|
pipe_through :secret
|
||||||
# has to match before /sources/:id
|
# has to match before /sources/:id
|
||||||
get "/sources/opml", Podcasts.PodcastController, :opml_feed
|
get "/opml/feed", Podcasts.PodcastController, :opml_feed
|
||||||
end
|
end
|
||||||
|
|
||||||
# Routes in here _may not be_ protected by basic auth. This is necessary for
|
# Routes in here _may not be_ protected by basic auth. This is necessary for
|
||||||
|
|
@ -108,6 +108,19 @@ defmodule PinchflatWeb.Router do
|
||||||
credential && credential != ""
|
credential && credential != ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp validate_secret(conn, _opts) do
|
||||||
|
expected_secret = Application.get_env(:pinchflat, :route_secret)
|
||||||
|
provided_secret = conn.params["secret"]
|
||||||
|
|
||||||
|
if expected_secret && provided_secret == expected_secret do
|
||||||
|
conn
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> Plug.Conn.send_resp(:unauthorized, "Unauthorized")
|
||||||
|
|> Plug.Conn.halt()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp allow_iframe_embed(conn, _opts) do
|
defp allow_iframe_embed(conn, _opts) do
|
||||||
delete_resp_header(conn, "x-frame-options")
|
delete_resp_header(conn, "x-frame-options")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue