Merge remote-tracking branch 'remotes/origin/develop' into ostatus-controller-no-auth-check-on-non-federating-instances
# Conflicts: # lib/pleroma/web/feed/user_controller.ex # lib/pleroma/web/o_status/o_status_controller.ex # lib/pleroma/web/router.ex # lib/pleroma/web/static_fe/static_fe_controller.exstable
commit
049ece1ef3
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"skip_files": [
|
"skip_files": [
|
||||||
"test/support",
|
"test/support",
|
||||||
"lib/mix/tasks/pleroma/benchmark.ex"
|
"lib/mix/tasks/pleroma/benchmark.ex",
|
||||||
|
"lib/credo/check/consistency/file_location.ex"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
# Generate release environment file
|
||||||
|
|
||||||
|
```sh tab="OTP"
|
||||||
|
./bin/pleroma_ctl release_env gen
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh tab="From Source"
|
||||||
|
mix pleroma.release_env gen
|
||||||
|
```
|
@ -0,0 +1,76 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Mix.Tasks.Pleroma.ReleaseEnv do
|
||||||
|
use Mix.Task
|
||||||
|
import Mix.Pleroma
|
||||||
|
|
||||||
|
@shortdoc "Generate Pleroma environment file."
|
||||||
|
@moduledoc File.read!("docs/administration/CLI_tasks/release_environments.md")
|
||||||
|
|
||||||
|
def run(["gen" | rest]) do
|
||||||
|
{options, [], []} =
|
||||||
|
OptionParser.parse(
|
||||||
|
rest,
|
||||||
|
strict: [
|
||||||
|
force: :boolean,
|
||||||
|
path: :string
|
||||||
|
],
|
||||||
|
aliases: [
|
||||||
|
p: :path,
|
||||||
|
f: :force
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
file_path =
|
||||||
|
get_option(
|
||||||
|
options,
|
||||||
|
:path,
|
||||||
|
"Environment file path",
|
||||||
|
"./config/pleroma.env"
|
||||||
|
)
|
||||||
|
|
||||||
|
env_path = Path.expand(file_path)
|
||||||
|
|
||||||
|
proceed? =
|
||||||
|
if File.exists?(env_path) do
|
||||||
|
get_option(
|
||||||
|
options,
|
||||||
|
:force,
|
||||||
|
"Environment file already exists. Do you want to overwrite the #{env_path} file? (y/n)",
|
||||||
|
"n"
|
||||||
|
) === "y"
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
if proceed? do
|
||||||
|
case do_generate(env_path) do
|
||||||
|
{:error, reason} ->
|
||||||
|
shell_error(
|
||||||
|
File.Error.message(%{action: "write to file", reason: reason, path: env_path})
|
||||||
|
)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
shell_info("\nThe file generated: #{env_path}.\n")
|
||||||
|
|
||||||
|
shell_info("""
|
||||||
|
WARNING: before start pleroma app please make sure to make the file read-only and non-modifiable.
|
||||||
|
Example:
|
||||||
|
chmod 0444 #{file_path}
|
||||||
|
chattr +i #{file_path}
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
shell_info("\nThe file is exist. #{env_path}.\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_generate(path) do
|
||||||
|
content = "RELEASE_COOKIE=#{Base.encode32(:crypto.strong_rand_bytes(32))}"
|
||||||
|
|
||||||
|
File.mkdir_p!(Path.dirname(path))
|
||||||
|
File.write(path, content)
|
||||||
|
end
|
||||||
|
end
|
@ -1,120 +0,0 @@
|
|||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.MIME do
|
|
||||||
@moduledoc """
|
|
||||||
Returns the mime-type of a binary and optionally a normalized file-name.
|
|
||||||
"""
|
|
||||||
@default "application/octet-stream"
|
|
||||||
@read_bytes 35
|
|
||||||
|
|
||||||
@spec file_mime_type(String.t(), String.t()) ::
|
|
||||||
{:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error
|
|
||||||
def file_mime_type(path, filename) do
|
|
||||||
with {:ok, content_type} <- file_mime_type(path),
|
|
||||||
filename <- fix_extension(filename, content_type) do
|
|
||||||
{:ok, content_type, filename}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec file_mime_type(String.t()) :: {:ok, String.t()} | {:error, any()} | :error
|
|
||||||
def file_mime_type(filename) do
|
|
||||||
File.open(filename, [:read], fn f ->
|
|
||||||
check_mime_type(IO.binread(f, @read_bytes))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def bin_mime_type(binary, filename) do
|
|
||||||
with {:ok, content_type} <- bin_mime_type(binary),
|
|
||||||
filename <- fix_extension(filename, content_type) do
|
|
||||||
{:ok, content_type, filename}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec bin_mime_type(binary()) :: {:ok, String.t()} | :error
|
|
||||||
def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do
|
|
||||||
{:ok, check_mime_type(head)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def bin_mime_type(_), do: :error
|
|
||||||
|
|
||||||
def mime_type(<<_::binary>>), do: {:ok, @default}
|
|
||||||
|
|
||||||
defp fix_extension(filename, content_type) do
|
|
||||||
parts = String.split(filename, ".")
|
|
||||||
|
|
||||||
new_filename =
|
|
||||||
if length(parts) > 1 do
|
|
||||||
Enum.drop(parts, -1) |> Enum.join(".")
|
|
||||||
else
|
|
||||||
Enum.join(parts)
|
|
||||||
end
|
|
||||||
|
|
||||||
cond do
|
|
||||||
content_type == "application/octet-stream" ->
|
|
||||||
filename
|
|
||||||
|
|
||||||
ext = List.first(MIME.extensions(content_type)) ->
|
|
||||||
new_filename <> "." <> ext
|
|
||||||
|
|
||||||
true ->
|
|
||||||
Enum.join([new_filename, String.split(content_type, "/") |> List.last()], ".")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _::binary>>) do
|
|
||||||
"image/png"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x47, 0x49, 0x46, 0x38, _, 0x61, _::binary>>) do
|
|
||||||
"image/gif"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0xFF, 0xD8, 0xFF, _::binary>>) do
|
|
||||||
"image/jpeg"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x1A, 0x45, 0xDF, 0xA3, _::binary>>) do
|
|
||||||
"video/webm"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x00, 0x00, 0x00, _, 0x66, 0x74, 0x79, 0x70, _::binary>>) do
|
|
||||||
"video/mp4"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x49, 0x44, 0x33, _::binary>>) do
|
|
||||||
"audio/mpeg"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<255, 251, _, 68, 0, 0, 0, 0, _::binary>>) do
|
|
||||||
"audio/mpeg"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(
|
|
||||||
<<0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, _::size(160), 0x80, 0x74, 0x68, 0x65,
|
|
||||||
0x6F, 0x72, 0x61, _::binary>>
|
|
||||||
) do
|
|
||||||
"video/ogg"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, _::binary>>) do
|
|
||||||
"audio/ogg"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do
|
|
||||||
"audio/wav"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do
|
|
||||||
"image/webp"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do
|
|
||||||
"video/avi"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp check_mime_type(_) do
|
|
||||||
@default
|
|
||||||
end
|
|
||||||
end
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue