Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
This commit is contained in:
commit
0f2f7d2cec
12
.credo.exs
12
.credo.exs
@ -69,8 +69,8 @@
|
|||||||
# You can also customize the exit_status of each check.
|
# You can also customize the exit_status of each check.
|
||||||
# If you don't want TODO comments to cause `mix credo` to fail, just
|
# If you don't want TODO comments to cause `mix credo` to fail, just
|
||||||
# set this value to 0 (zero).
|
# set this value to 0 (zero).
|
||||||
{Credo.Check.Design.TagTODO, exit_status: 2},
|
{Credo.Check.Design.TagTODO, exit_status: 0},
|
||||||
{Credo.Check.Design.TagFIXME},
|
{Credo.Check.Design.TagFIXME, exit_status: 0},
|
||||||
|
|
||||||
{Credo.Check.Readability.FunctionNames},
|
{Credo.Check.Readability.FunctionNames},
|
||||||
{Credo.Check.Readability.LargeNumbers},
|
{Credo.Check.Readability.LargeNumbers},
|
||||||
@ -81,7 +81,9 @@
|
|||||||
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
|
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
|
||||||
{Credo.Check.Readability.ParenthesesInCondition},
|
{Credo.Check.Readability.ParenthesesInCondition},
|
||||||
{Credo.Check.Readability.PredicateFunctionNames},
|
{Credo.Check.Readability.PredicateFunctionNames},
|
||||||
{Credo.Check.Readability.PreferImplicitTry},
|
# lanodan: I think PreferImplicitTry should be consistency, and the behaviour seems
|
||||||
|
# inconsistent, see: https://github.com/rrrene/credo/issues/224
|
||||||
|
{Credo.Check.Readability.PreferImplicitTry, false},
|
||||||
{Credo.Check.Readability.RedundantBlankLines},
|
{Credo.Check.Readability.RedundantBlankLines},
|
||||||
{Credo.Check.Readability.StringSigils},
|
{Credo.Check.Readability.StringSigils},
|
||||||
{Credo.Check.Readability.TrailingBlankLine},
|
{Credo.Check.Readability.TrailingBlankLine},
|
||||||
@ -126,10 +128,6 @@
|
|||||||
|
|
||||||
# Deprecated checks (these will be deleted after a grace period)
|
# Deprecated checks (these will be deleted after a grace period)
|
||||||
{Credo.Check.Readability.Specs, false},
|
{Credo.Check.Readability.Specs, false},
|
||||||
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
|
|
||||||
{Credo.Check.Warning.NameRedeclarationByCase, false},
|
|
||||||
{Credo.Check.Warning.NameRedeclarationByDef, false},
|
|
||||||
{Credo.Check.Warning.NameRedeclarationByFn, false},
|
|
||||||
|
|
||||||
# Custom checks can be created using `mix credo.gen.check`.
|
# Custom checks can be created using `mix credo.gen.check`.
|
||||||
#
|
#
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -35,3 +35,6 @@ erl_crash.dump
|
|||||||
|
|
||||||
# Editor config
|
# Editor config
|
||||||
/.vscode/
|
/.vscode/
|
||||||
|
|
||||||
|
# Prevent committing docs files
|
||||||
|
/priv/static/doc/*
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
image: elixir:1.7.2
|
image: elixir:1.8.1
|
||||||
|
|
||||||
services:
|
|
||||||
- name: postgres:9.6.2
|
|
||||||
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
POSTGRES_DB: pleroma_test
|
POSTGRES_DB: pleroma_test
|
||||||
@ -17,23 +13,68 @@ cache:
|
|||||||
- deps
|
- deps
|
||||||
- _build
|
- _build
|
||||||
stages:
|
stages:
|
||||||
- lint
|
- build
|
||||||
- test
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mix local.hex --force
|
- mix local.hex --force
|
||||||
- mix local.rebar --force
|
- mix local.rebar --force
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
- mix deps.get
|
- mix deps.get
|
||||||
- mix compile --force
|
- mix compile --force
|
||||||
- mix ecto.create
|
|
||||||
- mix ecto.migrate
|
|
||||||
|
|
||||||
lint:
|
docs-build:
|
||||||
stage: lint
|
stage: build
|
||||||
|
only:
|
||||||
|
- master@pleroma/pleroma
|
||||||
|
- develop@pleroma/pleroma
|
||||||
|
variables:
|
||||||
|
MIX_ENV: dev
|
||||||
script:
|
script:
|
||||||
- mix format --check-formatted
|
- mix deps.get
|
||||||
|
- mix compile
|
||||||
|
- mix docs
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- priv/static/doc
|
||||||
|
|
||||||
unit-testing:
|
unit-testing:
|
||||||
stage: test
|
stage: test
|
||||||
|
services:
|
||||||
|
- name: postgres:9.6.2
|
||||||
|
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
||||||
script:
|
script:
|
||||||
|
- mix ecto.create
|
||||||
|
- mix ecto.migrate
|
||||||
- mix test --trace --preload-modules
|
- mix test --trace --preload-modules
|
||||||
|
|
||||||
|
lint:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- mix format --check-formatted
|
||||||
|
|
||||||
|
analysis:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- mix deps.get
|
||||||
|
- mix credo --strict --only=warnings,todo,fixme,consistency,readability
|
||||||
|
|
||||||
|
|
||||||
|
docs-deploy:
|
||||||
|
stage: deploy
|
||||||
|
image: alpine:3.9
|
||||||
|
only:
|
||||||
|
- master@pleroma/pleroma
|
||||||
|
- develop@pleroma/pleroma
|
||||||
|
before_script:
|
||||||
|
- apk update && apk add openssh-client rsync
|
||||||
|
script:
|
||||||
|
- mkdir -p ~/.ssh
|
||||||
|
- echo "${SSH_HOST_KEY}" > ~/.ssh/known_hosts
|
||||||
|
- eval $(ssh-agent -s)
|
||||||
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
|
||||||
|
- rsync -hrvz --delete -e "ssh -p ${SSH_PORT}" priv/static/doc/ "${SSH_USER_HOST_LOCATION}/${CI_COMMIT_REF_NAME}"
|
||||||
|
403
CC-BY-NC-ND-4.0
Normal file
403
CC-BY-NC-ND-4.0
Normal file
@ -0,0 +1,403 @@
|
|||||||
|
Attribution-NonCommercial-NoDerivatives 4.0 International
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||||
|
does not provide legal services or legal advice. Distribution of
|
||||||
|
Creative Commons public licenses does not create a lawyer-client or
|
||||||
|
other relationship. Creative Commons makes its licenses and related
|
||||||
|
information available on an "as-is" basis. Creative Commons gives no
|
||||||
|
warranties regarding its licenses, any material licensed under their
|
||||||
|
terms and conditions, or any related information. Creative Commons
|
||||||
|
disclaims all liability for damages resulting from their use to the
|
||||||
|
fullest extent possible.
|
||||||
|
|
||||||
|
Using Creative Commons Public Licenses
|
||||||
|
|
||||||
|
Creative Commons public licenses provide a standard set of terms and
|
||||||
|
conditions that creators and other rights holders may use to share
|
||||||
|
original works of authorship and other material subject to copyright
|
||||||
|
and certain other rights specified in the public license below. The
|
||||||
|
following considerations are for informational purposes only, are not
|
||||||
|
exhaustive, and do not form part of our licenses.
|
||||||
|
|
||||||
|
Considerations for licensors: Our public licenses are
|
||||||
|
intended for use by those authorized to give the public
|
||||||
|
permission to use material in ways otherwise restricted by
|
||||||
|
copyright and certain other rights. Our licenses are
|
||||||
|
irrevocable. Licensors should read and understand the terms
|
||||||
|
and conditions of the license they choose before applying it.
|
||||||
|
Licensors should also secure all rights necessary before
|
||||||
|
applying our licenses so that the public can reuse the
|
||||||
|
material as expected. Licensors should clearly mark any
|
||||||
|
material not subject to the license. This includes other CC-
|
||||||
|
licensed material, or material used under an exception or
|
||||||
|
limitation to copyright. More considerations for licensors:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensors
|
||||||
|
|
||||||
|
Considerations for the public: By using one of our public
|
||||||
|
licenses, a licensor grants the public permission to use the
|
||||||
|
licensed material under specified terms and conditions. If
|
||||||
|
the licensor's permission is not necessary for any reason--for
|
||||||
|
example, because of any applicable exception or limitation to
|
||||||
|
copyright--then that use is not regulated by the license. Our
|
||||||
|
licenses grant only permissions under copyright and certain
|
||||||
|
other rights that a licensor has authority to grant. Use of
|
||||||
|
the licensed material may still be restricted for other
|
||||||
|
reasons, including because others have copyright or other
|
||||||
|
rights in the material. A licensor may make special requests,
|
||||||
|
such as asking that all changes be marked or described.
|
||||||
|
Although not required by our licenses, you are encouraged to
|
||||||
|
respect those requests where reasonable. More considerations
|
||||||
|
for the public:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensees
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0
|
||||||
|
International Public License
|
||||||
|
|
||||||
|
By exercising the Licensed Rights (defined below), You accept and agree
|
||||||
|
to be bound by the terms and conditions of this Creative Commons
|
||||||
|
Attribution-NonCommercial-NoDerivatives 4.0 International Public
|
||||||
|
License ("Public License"). To the extent this Public License may be
|
||||||
|
interpreted as a contract, You are granted the Licensed Rights in
|
||||||
|
consideration of Your acceptance of these terms and conditions, and the
|
||||||
|
Licensor grants You such rights in consideration of benefits the
|
||||||
|
Licensor receives from making the Licensed Material available under
|
||||||
|
these terms and conditions.
|
||||||
|
|
||||||
|
|
||||||
|
Section 1 -- Definitions.
|
||||||
|
|
||||||
|
a. Adapted Material means material subject to Copyright and Similar
|
||||||
|
Rights that is derived from or based upon the Licensed Material
|
||||||
|
and in which the Licensed Material is translated, altered,
|
||||||
|
arranged, transformed, or otherwise modified in a manner requiring
|
||||||
|
permission under the Copyright and Similar Rights held by the
|
||||||
|
Licensor. For purposes of this Public License, where the Licensed
|
||||||
|
Material is a musical work, performance, or sound recording,
|
||||||
|
Adapted Material is always produced where the Licensed Material is
|
||||||
|
synched in timed relation with a moving image.
|
||||||
|
|
||||||
|
b. Copyright and Similar Rights means copyright and/or similar rights
|
||||||
|
closely related to copyright including, without limitation,
|
||||||
|
performance, broadcast, sound recording, and Sui Generis Database
|
||||||
|
Rights, without regard to how the rights are labeled or
|
||||||
|
categorized. For purposes of this Public License, the rights
|
||||||
|
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||||
|
Rights.
|
||||||
|
|
||||||
|
c. Effective Technological Measures means those measures that, in the
|
||||||
|
absence of proper authority, may not be circumvented under laws
|
||||||
|
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||||
|
Treaty adopted on December 20, 1996, and/or similar international
|
||||||
|
agreements.
|
||||||
|
|
||||||
|
d. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||||
|
any other exception or limitation to Copyright and Similar Rights
|
||||||
|
that applies to Your use of the Licensed Material.
|
||||||
|
|
||||||
|
e. Licensed Material means the artistic or literary work, database,
|
||||||
|
or other material to which the Licensor applied this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
f. Licensed Rights means the rights granted to You subject to the
|
||||||
|
terms and conditions of this Public License, which are limited to
|
||||||
|
all Copyright and Similar Rights that apply to Your use of the
|
||||||
|
Licensed Material and that the Licensor has authority to license.
|
||||||
|
|
||||||
|
g. Licensor means the individual(s) or entity(ies) granting rights
|
||||||
|
under this Public License.
|
||||||
|
|
||||||
|
h. NonCommercial means not primarily intended for or directed towards
|
||||||
|
commercial advantage or monetary compensation. For purposes of
|
||||||
|
this Public License, the exchange of the Licensed Material for
|
||||||
|
other material subject to Copyright and Similar Rights by digital
|
||||||
|
file-sharing or similar means is NonCommercial provided there is
|
||||||
|
no payment of monetary compensation in connection with the
|
||||||
|
exchange.
|
||||||
|
|
||||||
|
i. Share means to provide material to the public by any means or
|
||||||
|
process that requires permission under the Licensed Rights, such
|
||||||
|
as reproduction, public display, public performance, distribution,
|
||||||
|
dissemination, communication, or importation, and to make material
|
||||||
|
available to the public including in ways that members of the
|
||||||
|
public may access the material from a place and at a time
|
||||||
|
individually chosen by them.
|
||||||
|
|
||||||
|
j. Sui Generis Database Rights means rights other than copyright
|
||||||
|
resulting from Directive 96/9/EC of the European Parliament and of
|
||||||
|
the Council of 11 March 1996 on the legal protection of databases,
|
||||||
|
as amended and/or succeeded, as well as other essentially
|
||||||
|
equivalent rights anywhere in the world.
|
||||||
|
|
||||||
|
k. You means the individual or entity exercising the Licensed Rights
|
||||||
|
under this Public License. Your has a corresponding meaning.
|
||||||
|
|
||||||
|
|
||||||
|
Section 2 -- Scope.
|
||||||
|
|
||||||
|
a. License grant.
|
||||||
|
|
||||||
|
1. Subject to the terms and conditions of this Public License,
|
||||||
|
the Licensor hereby grants You a worldwide, royalty-free,
|
||||||
|
non-sublicensable, non-exclusive, irrevocable license to
|
||||||
|
exercise the Licensed Rights in the Licensed Material to:
|
||||||
|
|
||||||
|
a. reproduce and Share the Licensed Material, in whole or
|
||||||
|
in part, for NonCommercial purposes only; and
|
||||||
|
|
||||||
|
b. produce and reproduce, but not Share, Adapted Material
|
||||||
|
for NonCommercial purposes only.
|
||||||
|
|
||||||
|
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||||
|
Exceptions and Limitations apply to Your use, this Public
|
||||||
|
License does not apply, and You do not need to comply with
|
||||||
|
its terms and conditions.
|
||||||
|
|
||||||
|
3. Term. The term of this Public License is specified in Section
|
||||||
|
6(a).
|
||||||
|
|
||||||
|
4. Media and formats; technical modifications allowed. The
|
||||||
|
Licensor authorizes You to exercise the Licensed Rights in
|
||||||
|
all media and formats whether now known or hereafter created,
|
||||||
|
and to make technical modifications necessary to do so. The
|
||||||
|
Licensor waives and/or agrees not to assert any right or
|
||||||
|
authority to forbid You from making technical modifications
|
||||||
|
necessary to exercise the Licensed Rights, including
|
||||||
|
technical modifications necessary to circumvent Effective
|
||||||
|
Technological Measures. For purposes of this Public License,
|
||||||
|
simply making modifications authorized by this Section 2(a)
|
||||||
|
(4) never produces Adapted Material.
|
||||||
|
|
||||||
|
5. Downstream recipients.
|
||||||
|
|
||||||
|
a. Offer from the Licensor -- Licensed Material. Every
|
||||||
|
recipient of the Licensed Material automatically
|
||||||
|
receives an offer from the Licensor to exercise the
|
||||||
|
Licensed Rights under the terms and conditions of this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
b. No downstream restrictions. You may not offer or impose
|
||||||
|
any additional or different terms or conditions on, or
|
||||||
|
apply any Effective Technological Measures to, the
|
||||||
|
Licensed Material if doing so restricts exercise of the
|
||||||
|
Licensed Rights by any recipient of the Licensed
|
||||||
|
Material.
|
||||||
|
|
||||||
|
6. No endorsement. Nothing in this Public License constitutes or
|
||||||
|
may be construed as permission to assert or imply that You
|
||||||
|
are, or that Your use of the Licensed Material is, connected
|
||||||
|
with, or sponsored, endorsed, or granted official status by,
|
||||||
|
the Licensor or others designated to receive attribution as
|
||||||
|
provided in Section 3(a)(1)(A)(i).
|
||||||
|
|
||||||
|
b. Other rights.
|
||||||
|
|
||||||
|
1. Moral rights, such as the right of integrity, are not
|
||||||
|
licensed under this Public License, nor are publicity,
|
||||||
|
privacy, and/or other similar personality rights; however, to
|
||||||
|
the extent possible, the Licensor waives and/or agrees not to
|
||||||
|
assert any such rights held by the Licensor to the limited
|
||||||
|
extent necessary to allow You to exercise the Licensed
|
||||||
|
Rights, but not otherwise.
|
||||||
|
|
||||||
|
2. Patent and trademark rights are not licensed under this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
3. To the extent possible, the Licensor waives any right to
|
||||||
|
collect royalties from You for the exercise of the Licensed
|
||||||
|
Rights, whether directly or through a collecting society
|
||||||
|
under any voluntary or waivable statutory or compulsory
|
||||||
|
licensing scheme. In all other cases the Licensor expressly
|
||||||
|
reserves any right to collect such royalties, including when
|
||||||
|
the Licensed Material is used other than for NonCommercial
|
||||||
|
purposes.
|
||||||
|
|
||||||
|
|
||||||
|
Section 3 -- License Conditions.
|
||||||
|
|
||||||
|
Your exercise of the Licensed Rights is expressly made subject to the
|
||||||
|
following conditions.
|
||||||
|
|
||||||
|
a. Attribution.
|
||||||
|
|
||||||
|
1. If You Share the Licensed Material, You must:
|
||||||
|
|
||||||
|
a. retain the following if it is supplied by the Licensor
|
||||||
|
with the Licensed Material:
|
||||||
|
|
||||||
|
i. identification of the creator(s) of the Licensed
|
||||||
|
Material and any others designated to receive
|
||||||
|
attribution, in any reasonable manner requested by
|
||||||
|
the Licensor (including by pseudonym if
|
||||||
|
designated);
|
||||||
|
|
||||||
|
ii. a copyright notice;
|
||||||
|
|
||||||
|
iii. a notice that refers to this Public License;
|
||||||
|
|
||||||
|
iv. a notice that refers to the disclaimer of
|
||||||
|
warranties;
|
||||||
|
|
||||||
|
v. a URI or hyperlink to the Licensed Material to the
|
||||||
|
extent reasonably practicable;
|
||||||
|
|
||||||
|
b. indicate if You modified the Licensed Material and
|
||||||
|
retain an indication of any previous modifications; and
|
||||||
|
|
||||||
|
c. indicate the Licensed Material is licensed under this
|
||||||
|
Public License, and include the text of, or the URI or
|
||||||
|
hyperlink to, this Public License.
|
||||||
|
|
||||||
|
For the avoidance of doubt, You do not have permission under
|
||||||
|
this Public License to Share Adapted Material.
|
||||||
|
|
||||||
|
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||||
|
reasonable manner based on the medium, means, and context in
|
||||||
|
which You Share the Licensed Material. For example, it may be
|
||||||
|
reasonable to satisfy the conditions by providing a URI or
|
||||||
|
hyperlink to a resource that includes the required
|
||||||
|
information.
|
||||||
|
|
||||||
|
3. If requested by the Licensor, You must remove any of the
|
||||||
|
information required by Section 3(a)(1)(A) to the extent
|
||||||
|
reasonably practicable.
|
||||||
|
|
||||||
|
|
||||||
|
Section 4 -- Sui Generis Database Rights.
|
||||||
|
|
||||||
|
Where the Licensed Rights include Sui Generis Database Rights that
|
||||||
|
apply to Your use of the Licensed Material:
|
||||||
|
|
||||||
|
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||||
|
to extract, reuse, reproduce, and Share all or a substantial
|
||||||
|
portion of the contents of the database for NonCommercial purposes
|
||||||
|
only and provided You do not Share Adapted Material;
|
||||||
|
|
||||||
|
b. if You include all or a substantial portion of the database
|
||||||
|
contents in a database in which You have Sui Generis Database
|
||||||
|
Rights, then the database in which You have Sui Generis Database
|
||||||
|
Rights (but not its individual contents) is Adapted Material; and
|
||||||
|
|
||||||
|
c. You must comply with the conditions in Section 3(a) if You Share
|
||||||
|
all or a substantial portion of the contents of the database.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 4 supplements and does not
|
||||||
|
replace Your obligations under this Public License where the Licensed
|
||||||
|
Rights include other Copyright and Similar Rights.
|
||||||
|
|
||||||
|
|
||||||
|
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||||
|
|
||||||
|
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||||
|
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||||
|
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||||
|
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||||
|
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||||
|
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||||
|
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||||
|
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||||
|
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||||
|
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||||
|
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||||
|
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||||
|
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||||
|
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||||
|
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||||
|
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
c. The disclaimer of warranties and limitation of liability provided
|
||||||
|
above shall be interpreted in a manner that, to the extent
|
||||||
|
possible, most closely approximates an absolute disclaimer and
|
||||||
|
waiver of all liability.
|
||||||
|
|
||||||
|
|
||||||
|
Section 6 -- Term and Termination.
|
||||||
|
|
||||||
|
a. This Public License applies for the term of the Copyright and
|
||||||
|
Similar Rights licensed here. However, if You fail to comply with
|
||||||
|
this Public License, then Your rights under this Public License
|
||||||
|
terminate automatically.
|
||||||
|
|
||||||
|
b. Where Your right to use the Licensed Material has terminated under
|
||||||
|
Section 6(a), it reinstates:
|
||||||
|
|
||||||
|
1. automatically as of the date the violation is cured, provided
|
||||||
|
it is cured within 30 days of Your discovery of the
|
||||||
|
violation; or
|
||||||
|
|
||||||
|
2. upon express reinstatement by the Licensor.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||||
|
right the Licensor may have to seek remedies for Your violations
|
||||||
|
of this Public License.
|
||||||
|
|
||||||
|
c. For the avoidance of doubt, the Licensor may also offer the
|
||||||
|
Licensed Material under separate terms or conditions or stop
|
||||||
|
distributing the Licensed Material at any time; however, doing so
|
||||||
|
will not terminate this Public License.
|
||||||
|
|
||||||
|
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 7 -- Other Terms and Conditions.
|
||||||
|
|
||||||
|
a. The Licensor shall not be bound by any additional or different
|
||||||
|
terms or conditions communicated by You unless expressly agreed.
|
||||||
|
|
||||||
|
b. Any arrangements, understandings, or agreements regarding the
|
||||||
|
Licensed Material not stated herein are separate from and
|
||||||
|
independent of the terms and conditions of this Public License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 8 -- Interpretation.
|
||||||
|
|
||||||
|
a. For the avoidance of doubt, this Public License does not, and
|
||||||
|
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||||
|
conditions on any use of the Licensed Material that could lawfully
|
||||||
|
be made without permission under this Public License.
|
||||||
|
|
||||||
|
b. To the extent possible, if any provision of this Public License is
|
||||||
|
deemed unenforceable, it shall be automatically reformed to the
|
||||||
|
minimum extent necessary to make it enforceable. If the provision
|
||||||
|
cannot be reformed, it shall be severed from this Public License
|
||||||
|
without affecting the enforceability of the remaining terms and
|
||||||
|
conditions.
|
||||||
|
|
||||||
|
c. No term or condition of this Public License will be waived and no
|
||||||
|
failure to comply consented to unless expressly agreed to by the
|
||||||
|
Licensor.
|
||||||
|
|
||||||
|
d. Nothing in this Public License constitutes or may be interpreted
|
||||||
|
as a limitation upon, or waiver of, any privileges and immunities
|
||||||
|
that apply to the Licensor or You, including from the legal
|
||||||
|
processes of any jurisdiction or authority.
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons is not a party to its public
|
||||||
|
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||||
|
its public licenses to material it publishes and in those instances
|
||||||
|
will be considered the “Licensor.” The text of the Creative Commons
|
||||||
|
public licenses is dedicated to the public domain under the CC0 Public
|
||||||
|
Domain Dedication. Except for the limited purpose of indicating that
|
||||||
|
material is shared under a Creative Commons public license or as
|
||||||
|
otherwise permitted by the Creative Commons policies published at
|
||||||
|
creativecommons.org/policies, Creative Commons does not authorize the
|
||||||
|
use of the trademark "Creative Commons" or any other trademark or logo
|
||||||
|
of Creative Commons without its prior written consent including,
|
||||||
|
without limitation, in connection with any unauthorized modifications
|
||||||
|
to any of its public licenses or any other arrangements,
|
||||||
|
understandings, or agreements concerning use of licensed material. For
|
||||||
|
the avoidance of doubt, this paragraph does not form part of the
|
||||||
|
public licenses.
|
||||||
|
|
||||||
|
Creative Commons may be contacted at creativecommons.org.
|
||||||
|
|
427
CC-BY-SA-4.0
Normal file
427
CC-BY-SA-4.0
Normal file
@ -0,0 +1,427 @@
|
|||||||
|
Attribution-ShareAlike 4.0 International
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||||
|
does not provide legal services or legal advice. Distribution of
|
||||||
|
Creative Commons public licenses does not create a lawyer-client or
|
||||||
|
other relationship. Creative Commons makes its licenses and related
|
||||||
|
information available on an "as-is" basis. Creative Commons gives no
|
||||||
|
warranties regarding its licenses, any material licensed under their
|
||||||
|
terms and conditions, or any related information. Creative Commons
|
||||||
|
disclaims all liability for damages resulting from their use to the
|
||||||
|
fullest extent possible.
|
||||||
|
|
||||||
|
Using Creative Commons Public Licenses
|
||||||
|
|
||||||
|
Creative Commons public licenses provide a standard set of terms and
|
||||||
|
conditions that creators and other rights holders may use to share
|
||||||
|
original works of authorship and other material subject to copyright
|
||||||
|
and certain other rights specified in the public license below. The
|
||||||
|
following considerations are for informational purposes only, are not
|
||||||
|
exhaustive, and do not form part of our licenses.
|
||||||
|
|
||||||
|
Considerations for licensors: Our public licenses are
|
||||||
|
intended for use by those authorized to give the public
|
||||||
|
permission to use material in ways otherwise restricted by
|
||||||
|
copyright and certain other rights. Our licenses are
|
||||||
|
irrevocable. Licensors should read and understand the terms
|
||||||
|
and conditions of the license they choose before applying it.
|
||||||
|
Licensors should also secure all rights necessary before
|
||||||
|
applying our licenses so that the public can reuse the
|
||||||
|
material as expected. Licensors should clearly mark any
|
||||||
|
material not subject to the license. This includes other CC-
|
||||||
|
licensed material, or material used under an exception or
|
||||||
|
limitation to copyright. More considerations for licensors:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensors
|
||||||
|
|
||||||
|
Considerations for the public: By using one of our public
|
||||||
|
licenses, a licensor grants the public permission to use the
|
||||||
|
licensed material under specified terms and conditions. If
|
||||||
|
the licensor's permission is not necessary for any reason--for
|
||||||
|
example, because of any applicable exception or limitation to
|
||||||
|
copyright--then that use is not regulated by the license. Our
|
||||||
|
licenses grant only permissions under copyright and certain
|
||||||
|
other rights that a licensor has authority to grant. Use of
|
||||||
|
the licensed material may still be restricted for other
|
||||||
|
reasons, including because others have copyright or other
|
||||||
|
rights in the material. A licensor may make special requests,
|
||||||
|
such as asking that all changes be marked or described.
|
||||||
|
Although not required by our licenses, you are encouraged to
|
||||||
|
respect those requests where reasonable. More considerations
|
||||||
|
for the public:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensees
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Attribution-ShareAlike 4.0 International Public
|
||||||
|
License
|
||||||
|
|
||||||
|
By exercising the Licensed Rights (defined below), You accept and agree
|
||||||
|
to be bound by the terms and conditions of this Creative Commons
|
||||||
|
Attribution-ShareAlike 4.0 International Public License ("Public
|
||||||
|
License"). To the extent this Public License may be interpreted as a
|
||||||
|
contract, You are granted the Licensed Rights in consideration of Your
|
||||||
|
acceptance of these terms and conditions, and the Licensor grants You
|
||||||
|
such rights in consideration of benefits the Licensor receives from
|
||||||
|
making the Licensed Material available under these terms and
|
||||||
|
conditions.
|
||||||
|
|
||||||
|
|
||||||
|
Section 1 -- Definitions.
|
||||||
|
|
||||||
|
a. Adapted Material means material subject to Copyright and Similar
|
||||||
|
Rights that is derived from or based upon the Licensed Material
|
||||||
|
and in which the Licensed Material is translated, altered,
|
||||||
|
arranged, transformed, or otherwise modified in a manner requiring
|
||||||
|
permission under the Copyright and Similar Rights held by the
|
||||||
|
Licensor. For purposes of this Public License, where the Licensed
|
||||||
|
Material is a musical work, performance, or sound recording,
|
||||||
|
Adapted Material is always produced where the Licensed Material is
|
||||||
|
synched in timed relation with a moving image.
|
||||||
|
|
||||||
|
b. Adapter's License means the license You apply to Your Copyright
|
||||||
|
and Similar Rights in Your contributions to Adapted Material in
|
||||||
|
accordance with the terms and conditions of this Public License.
|
||||||
|
|
||||||
|
c. BY-SA Compatible License means a license listed at
|
||||||
|
creativecommons.org/compatiblelicenses, approved by Creative
|
||||||
|
Commons as essentially the equivalent of this Public License.
|
||||||
|
|
||||||
|
d. Copyright and Similar Rights means copyright and/or similar rights
|
||||||
|
closely related to copyright including, without limitation,
|
||||||
|
performance, broadcast, sound recording, and Sui Generis Database
|
||||||
|
Rights, without regard to how the rights are labeled or
|
||||||
|
categorized. For purposes of this Public License, the rights
|
||||||
|
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||||
|
Rights.
|
||||||
|
|
||||||
|
e. Effective Technological Measures means those measures that, in the
|
||||||
|
absence of proper authority, may not be circumvented under laws
|
||||||
|
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||||
|
Treaty adopted on December 20, 1996, and/or similar international
|
||||||
|
agreements.
|
||||||
|
|
||||||
|
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||||
|
any other exception or limitation to Copyright and Similar Rights
|
||||||
|
that applies to Your use of the Licensed Material.
|
||||||
|
|
||||||
|
g. License Elements means the license attributes listed in the name
|
||||||
|
of a Creative Commons Public License. The License Elements of this
|
||||||
|
Public License are Attribution and ShareAlike.
|
||||||
|
|
||||||
|
h. Licensed Material means the artistic or literary work, database,
|
||||||
|
or other material to which the Licensor applied this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
i. Licensed Rights means the rights granted to You subject to the
|
||||||
|
terms and conditions of this Public License, which are limited to
|
||||||
|
all Copyright and Similar Rights that apply to Your use of the
|
||||||
|
Licensed Material and that the Licensor has authority to license.
|
||||||
|
|
||||||
|
j. Licensor means the individual(s) or entity(ies) granting rights
|
||||||
|
under this Public License.
|
||||||
|
|
||||||
|
k. Share means to provide material to the public by any means or
|
||||||
|
process that requires permission under the Licensed Rights, such
|
||||||
|
as reproduction, public display, public performance, distribution,
|
||||||
|
dissemination, communication, or importation, and to make material
|
||||||
|
available to the public including in ways that members of the
|
||||||
|
public may access the material from a place and at a time
|
||||||
|
individually chosen by them.
|
||||||
|
|
||||||
|
l. Sui Generis Database Rights means rights other than copyright
|
||||||
|
resulting from Directive 96/9/EC of the European Parliament and of
|
||||||
|
the Council of 11 March 1996 on the legal protection of databases,
|
||||||
|
as amended and/or succeeded, as well as other essentially
|
||||||
|
equivalent rights anywhere in the world.
|
||||||
|
|
||||||
|
m. You means the individual or entity exercising the Licensed Rights
|
||||||
|
under this Public License. Your has a corresponding meaning.
|
||||||
|
|
||||||
|
|
||||||
|
Section 2 -- Scope.
|
||||||
|
|
||||||
|
a. License grant.
|
||||||
|
|
||||||
|
1. Subject to the terms and conditions of this Public License,
|
||||||
|
the Licensor hereby grants You a worldwide, royalty-free,
|
||||||
|
non-sublicensable, non-exclusive, irrevocable license to
|
||||||
|
exercise the Licensed Rights in the Licensed Material to:
|
||||||
|
|
||||||
|
a. reproduce and Share the Licensed Material, in whole or
|
||||||
|
in part; and
|
||||||
|
|
||||||
|
b. produce, reproduce, and Share Adapted Material.
|
||||||
|
|
||||||
|
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||||
|
Exceptions and Limitations apply to Your use, this Public
|
||||||
|
License does not apply, and You do not need to comply with
|
||||||
|
its terms and conditions.
|
||||||
|
|
||||||
|
3. Term. The term of this Public License is specified in Section
|
||||||
|
6(a).
|
||||||
|
|
||||||
|
4. Media and formats; technical modifications allowed. The
|
||||||
|
Licensor authorizes You to exercise the Licensed Rights in
|
||||||
|
all media and formats whether now known or hereafter created,
|
||||||
|
and to make technical modifications necessary to do so. The
|
||||||
|
Licensor waives and/or agrees not to assert any right or
|
||||||
|
authority to forbid You from making technical modifications
|
||||||
|
necessary to exercise the Licensed Rights, including
|
||||||
|
technical modifications necessary to circumvent Effective
|
||||||
|
Technological Measures. For purposes of this Public License,
|
||||||
|
simply making modifications authorized by this Section 2(a)
|
||||||
|
(4) never produces Adapted Material.
|
||||||
|
|
||||||
|
5. Downstream recipients.
|
||||||
|
|
||||||
|
a. Offer from the Licensor -- Licensed Material. Every
|
||||||
|
recipient of the Licensed Material automatically
|
||||||
|
receives an offer from the Licensor to exercise the
|
||||||
|
Licensed Rights under the terms and conditions of this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
b. Additional offer from the Licensor -- Adapted Material.
|
||||||
|
Every recipient of Adapted Material from You
|
||||||
|
automatically receives an offer from the Licensor to
|
||||||
|
exercise the Licensed Rights in the Adapted Material
|
||||||
|
under the conditions of the Adapter's License You apply.
|
||||||
|
|
||||||
|
c. No downstream restrictions. You may not offer or impose
|
||||||
|
any additional or different terms or conditions on, or
|
||||||
|
apply any Effective Technological Measures to, the
|
||||||
|
Licensed Material if doing so restricts exercise of the
|
||||||
|
Licensed Rights by any recipient of the Licensed
|
||||||
|
Material.
|
||||||
|
|
||||||
|
6. No endorsement. Nothing in this Public License constitutes or
|
||||||
|
may be construed as permission to assert or imply that You
|
||||||
|
are, or that Your use of the Licensed Material is, connected
|
||||||
|
with, or sponsored, endorsed, or granted official status by,
|
||||||
|
the Licensor or others designated to receive attribution as
|
||||||
|
provided in Section 3(a)(1)(A)(i).
|
||||||
|
|
||||||
|
b. Other rights.
|
||||||
|
|
||||||
|
1. Moral rights, such as the right of integrity, are not
|
||||||
|
licensed under this Public License, nor are publicity,
|
||||||
|
privacy, and/or other similar personality rights; however, to
|
||||||
|
the extent possible, the Licensor waives and/or agrees not to
|
||||||
|
assert any such rights held by the Licensor to the limited
|
||||||
|
extent necessary to allow You to exercise the Licensed
|
||||||
|
Rights, but not otherwise.
|
||||||
|
|
||||||
|
2. Patent and trademark rights are not licensed under this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
3. To the extent possible, the Licensor waives any right to
|
||||||
|
collect royalties from You for the exercise of the Licensed
|
||||||
|
Rights, whether directly or through a collecting society
|
||||||
|
under any voluntary or waivable statutory or compulsory
|
||||||
|
licensing scheme. In all other cases the Licensor expressly
|
||||||
|
reserves any right to collect such royalties.
|
||||||
|
|
||||||
|
|
||||||
|
Section 3 -- License Conditions.
|
||||||
|
|
||||||
|
Your exercise of the Licensed Rights is expressly made subject to the
|
||||||
|
following conditions.
|
||||||
|
|
||||||
|
a. Attribution.
|
||||||
|
|
||||||
|
1. If You Share the Licensed Material (including in modified
|
||||||
|
form), You must:
|
||||||
|
|
||||||
|
a. retain the following if it is supplied by the Licensor
|
||||||
|
with the Licensed Material:
|
||||||
|
|
||||||
|
i. identification of the creator(s) of the Licensed
|
||||||
|
Material and any others designated to receive
|
||||||
|
attribution, in any reasonable manner requested by
|
||||||
|
the Licensor (including by pseudonym if
|
||||||
|
designated);
|
||||||
|
|
||||||
|
ii. a copyright notice;
|
||||||
|
|
||||||
|
iii. a notice that refers to this Public License;
|
||||||
|
|
||||||
|
iv. a notice that refers to the disclaimer of
|
||||||
|
warranties;
|
||||||
|
|
||||||
|
v. a URI or hyperlink to the Licensed Material to the
|
||||||
|
extent reasonably practicable;
|
||||||
|
|
||||||
|
b. indicate if You modified the Licensed Material and
|
||||||
|
retain an indication of any previous modifications; and
|
||||||
|
|
||||||
|
c. indicate the Licensed Material is licensed under this
|
||||||
|
Public License, and include the text of, or the URI or
|
||||||
|
hyperlink to, this Public License.
|
||||||
|
|
||||||
|
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||||
|
reasonable manner based on the medium, means, and context in
|
||||||
|
which You Share the Licensed Material. For example, it may be
|
||||||
|
reasonable to satisfy the conditions by providing a URI or
|
||||||
|
hyperlink to a resource that includes the required
|
||||||
|
information.
|
||||||
|
|
||||||
|
3. If requested by the Licensor, You must remove any of the
|
||||||
|
information required by Section 3(a)(1)(A) to the extent
|
||||||
|
reasonably practicable.
|
||||||
|
|
||||||
|
b. ShareAlike.
|
||||||
|
|
||||||
|
In addition to the conditions in Section 3(a), if You Share
|
||||||
|
Adapted Material You produce, the following conditions also apply.
|
||||||
|
|
||||||
|
1. The Adapter's License You apply must be a Creative Commons
|
||||||
|
license with the same License Elements, this version or
|
||||||
|
later, or a BY-SA Compatible License.
|
||||||
|
|
||||||
|
2. You must include the text of, or the URI or hyperlink to, the
|
||||||
|
Adapter's License You apply. You may satisfy this condition
|
||||||
|
in any reasonable manner based on the medium, means, and
|
||||||
|
context in which You Share Adapted Material.
|
||||||
|
|
||||||
|
3. You may not offer or impose any additional or different terms
|
||||||
|
or conditions on, or apply any Effective Technological
|
||||||
|
Measures to, Adapted Material that restrict exercise of the
|
||||||
|
rights granted under the Adapter's License You apply.
|
||||||
|
|
||||||
|
|
||||||
|
Section 4 -- Sui Generis Database Rights.
|
||||||
|
|
||||||
|
Where the Licensed Rights include Sui Generis Database Rights that
|
||||||
|
apply to Your use of the Licensed Material:
|
||||||
|
|
||||||
|
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||||
|
to extract, reuse, reproduce, and Share all or a substantial
|
||||||
|
portion of the contents of the database;
|
||||||
|
|
||||||
|
b. if You include all or a substantial portion of the database
|
||||||
|
contents in a database in which You have Sui Generis Database
|
||||||
|
Rights, then the database in which You have Sui Generis Database
|
||||||
|
Rights (but not its individual contents) is Adapted Material,
|
||||||
|
including for purposes of Section 3(b); and
|
||||||
|
|
||||||
|
c. You must comply with the conditions in Section 3(a) if You Share
|
||||||
|
all or a substantial portion of the contents of the database.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 4 supplements and does not
|
||||||
|
replace Your obligations under this Public License where the Licensed
|
||||||
|
Rights include other Copyright and Similar Rights.
|
||||||
|
|
||||||
|
|
||||||
|
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||||
|
|
||||||
|
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||||
|
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||||
|
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||||
|
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||||
|
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||||
|
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||||
|
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||||
|
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||||
|
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||||
|
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||||
|
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||||
|
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||||
|
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||||
|
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||||
|
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||||
|
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
c. The disclaimer of warranties and limitation of liability provided
|
||||||
|
above shall be interpreted in a manner that, to the extent
|
||||||
|
possible, most closely approximates an absolute disclaimer and
|
||||||
|
waiver of all liability.
|
||||||
|
|
||||||
|
|
||||||
|
Section 6 -- Term and Termination.
|
||||||
|
|
||||||
|
a. This Public License applies for the term of the Copyright and
|
||||||
|
Similar Rights licensed here. However, if You fail to comply with
|
||||||
|
this Public License, then Your rights under this Public License
|
||||||
|
terminate automatically.
|
||||||
|
|
||||||
|
b. Where Your right to use the Licensed Material has terminated under
|
||||||
|
Section 6(a), it reinstates:
|
||||||
|
|
||||||
|
1. automatically as of the date the violation is cured, provided
|
||||||
|
it is cured within 30 days of Your discovery of the
|
||||||
|
violation; or
|
||||||
|
|
||||||
|
2. upon express reinstatement by the Licensor.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||||
|
right the Licensor may have to seek remedies for Your violations
|
||||||
|
of this Public License.
|
||||||
|
|
||||||
|
c. For the avoidance of doubt, the Licensor may also offer the
|
||||||
|
Licensed Material under separate terms or conditions or stop
|
||||||
|
distributing the Licensed Material at any time; however, doing so
|
||||||
|
will not terminate this Public License.
|
||||||
|
|
||||||
|
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 7 -- Other Terms and Conditions.
|
||||||
|
|
||||||
|
a. The Licensor shall not be bound by any additional or different
|
||||||
|
terms or conditions communicated by You unless expressly agreed.
|
||||||
|
|
||||||
|
b. Any arrangements, understandings, or agreements regarding the
|
||||||
|
Licensed Material not stated herein are separate from and
|
||||||
|
independent of the terms and conditions of this Public License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 8 -- Interpretation.
|
||||||
|
|
||||||
|
a. For the avoidance of doubt, this Public License does not, and
|
||||||
|
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||||
|
conditions on any use of the Licensed Material that could lawfully
|
||||||
|
be made without permission under this Public License.
|
||||||
|
|
||||||
|
b. To the extent possible, if any provision of this Public License is
|
||||||
|
deemed unenforceable, it shall be automatically reformed to the
|
||||||
|
minimum extent necessary to make it enforceable. If the provision
|
||||||
|
cannot be reformed, it shall be severed from this Public License
|
||||||
|
without affecting the enforceability of the remaining terms and
|
||||||
|
conditions.
|
||||||
|
|
||||||
|
c. No term or condition of this Public License will be waived and no
|
||||||
|
failure to comply consented to unless expressly agreed to by the
|
||||||
|
Licensor.
|
||||||
|
|
||||||
|
d. Nothing in this Public License constitutes or may be interpreted
|
||||||
|
as a limitation upon, or waiver of, any privileges and immunities
|
||||||
|
that apply to the Licensor or You, including from the legal
|
||||||
|
processes of any jurisdiction or authority.
|
||||||
|
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons is not a party to its public
|
||||||
|
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||||
|
its public licenses to material it publishes and in those instances
|
||||||
|
will be considered the “Licensor.” The text of the Creative Commons
|
||||||
|
public licenses is dedicated to the public domain under the CC0 Public
|
||||||
|
Domain Dedication. Except for the limited purpose of indicating that
|
||||||
|
material is shared under a Creative Commons public license or as
|
||||||
|
otherwise permitted by the Creative Commons policies published at
|
||||||
|
creativecommons.org/policies, Creative Commons does not authorize the
|
||||||
|
use of the trademark "Creative Commons" or any other trademark or logo
|
||||||
|
of Creative Commons without its prior written consent including,
|
||||||
|
without limitation, in connection with any unauthorized modifications
|
||||||
|
to any of its public licenses or any other arrangements,
|
||||||
|
understandings, or agreements concerning use of licensed material. For
|
||||||
|
the avoidance of doubt, this paragraph does not form part of the
|
||||||
|
public licenses.
|
||||||
|
|
||||||
|
Creative Commons may be contacted at creativecommons.org.
|
48
COPYING
Normal file
48
COPYING
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
Unless otherwise stated this repository is copyright © 2017-2019
|
||||||
|
Pleroma Authors <https://pleroma.social/>, and is distributed under
|
||||||
|
The GNU Affero General Public License Version 3, you should have received a
|
||||||
|
copy of the license file as AGPL-3.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The following files are copyright © 2019 shitposter.club, and are distributed
|
||||||
|
under the Creative Commons Attribution-ShareAlike 4.0 International license,
|
||||||
|
you should have received a copy of the license file as CC-BY-SA-4.0.
|
||||||
|
|
||||||
|
priv/static/images/pleroma-fox-tan.png
|
||||||
|
priv/static/images/pleroma-fox-tan-smol.png
|
||||||
|
priv/static/images/pleroma-tan.png
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The following files are copyright © 2017-2019 Pleroma Authors
|
||||||
|
<https://pleroma.social/>, and are distributed under the Creative Commons
|
||||||
|
Attribution-ShareAlike 4.0 International license, you should have received
|
||||||
|
a copy of the license file as CC-BY-SA-4.0.
|
||||||
|
|
||||||
|
priv/static/images/avi.png
|
||||||
|
priv/static/images/banner.png
|
||||||
|
priv/static/instance/thumbnail.jpeg
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
All photos published on Unsplash can be used for free. You can use them for
|
||||||
|
commercial and noncommercial purposes. You do not need to ask permission from
|
||||||
|
or provide credit to the photographer or Unsplash, although it is appreciated
|
||||||
|
when possible.
|
||||||
|
|
||||||
|
More precisely, Unsplash grants you an irrevocable, nonexclusive, worldwide
|
||||||
|
copyright license to download, copy, modify, distribute, perform, and use
|
||||||
|
photos from Unsplash for free, including for commercial purposes, without
|
||||||
|
permission from or attributing the photographer or Unsplash. This license
|
||||||
|
does not include the right to compile photos from Unsplash to replicate
|
||||||
|
a similar or competing service.
|
||||||
|
|
||||||
|
priv/static/images/city.jpg
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The files present under the priv/static/finmoji directory are copyright
|
||||||
|
Finland <https://finland.fi/emoji/>, and are distributed under the Creative
|
||||||
|
Commons Attribution-NonCommercial-NoDerivatives 4.0 International license, you
|
||||||
|
should have received a copy of the license file as CC-BY-NC-ND-4.0.
|
10
README.md
10
README.md
@ -1,14 +1,16 @@
|
|||||||
# Pleroma
|
# Pleroma
|
||||||
|
|
||||||
|
**Note**: This readme as well as complete documentation is also availible at <https://docs-develop.pleroma.social>
|
||||||
|
|
||||||
## About Pleroma
|
## About Pleroma
|
||||||
|
|
||||||
Pleroma is a microblogging server software that can federate (= exchange messages with) other servers that support the same federation standards (OStatus and ActivityPub). What that means is that you can host a server for yourself or your friends and stay in control of your online identity, but still exchange messages with people on larger servers. Pleroma will federate with all servers that implement either OStatus or ActivityPub, like Friendica, GNU Social, Hubzilla, Mastodon, Misskey, Peertube, and Pixelfed.
|
Pleroma is a microblogging server software that can federate (= exchange messages with) other servers that support the same federation standards (OStatus and ActivityPub). What that means is that you can host a server for yourself or your friends and stay in control of your online identity, but still exchange messages with people on larger servers. Pleroma will federate with all servers that implement either OStatus or ActivityPub, like Friendica, GNU Social, Hubzilla, Mastodon, Misskey, Peertube, and Pixelfed.
|
||||||
|
|
||||||
Pleroma is written in Elixir, high-performance and can run on small devices like a Raspberry Pi.
|
Pleroma is written in Elixir, high-performance and can run on small devices like a Raspberry Pi.
|
||||||
|
|
||||||
For clients it supports both the [GNU Social API with Qvitter extensions](https://twitter-api.readthedocs.io/en/latest/index.html) and the [Mastodon client API](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md).
|
For clients it supports both the [GNU Social API with Qvitter extensions](https://twitter-api.readthedocs.io/en/latest/index.html) and the [Mastodon client API](https://docs.joinmastodon.org/api/guidelines/).
|
||||||
|
|
||||||
- [Client Applications for Pleroma](docs/Clients.md)
|
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/clients.html)
|
||||||
|
|
||||||
No release has been made yet, but several servers have been online for months already. If you want to run your own server, feel free to contact us at @lain@pleroma.soykaf.com or in our dev chat at #pleroma on freenode or via matrix at <https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org>.
|
No release has been made yet, but several servers have been online for months already. If you want to run your own server, feel free to contact us at @lain@pleroma.soykaf.com or in our dev chat at #pleroma on freenode or via matrix at <https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org>.
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ While we don’t provide docker files, other people have written very good ones.
|
|||||||
|
|
||||||
* Run `mix deps.get` to install elixir dependencies.
|
* Run `mix deps.get` to install elixir dependencies.
|
||||||
* Run `mix pleroma.instance gen`. This will ask you questions about your instance and generate a configuration file in `config/generated_config.exs`. Check that and copy it to either `config/dev.secret.exs` or `config/prod.secret.exs`. It will also create a `config/setup_db.psql`, which you should run as the PostgreSQL superuser (i.e., `sudo -u postgres psql -f config/setup_db.psql`). It will create the database, user, and password you gave `mix pleroma.gen.instance` earlier, as well as set up the necessary extensions in the database. PostgreSQL superuser privileges are only needed for this step.
|
* Run `mix pleroma.instance gen`. This will ask you questions about your instance and generate a configuration file in `config/generated_config.exs`. Check that and copy it to either `config/dev.secret.exs` or `config/prod.secret.exs`. It will also create a `config/setup_db.psql`, which you should run as the PostgreSQL superuser (i.e., `sudo -u postgres psql -f config/setup_db.psql`). It will create the database, user, and password you gave `mix pleroma.gen.instance` earlier, as well as set up the necessary extensions in the database. PostgreSQL superuser privileges are only needed for this step.
|
||||||
* For these next steps, the default will be to run pleroma using the dev configuration file, `config/dev.secret.exs`. To run them using the prod config file, prefix each command at the shell with `MIX_ENV=prod`. For example: `MIX_ENV=prod mix phx.server`. Documentation for the config can be found at [`docs/config.md`](docs/config.md)
|
* For these next steps, the default will be to run pleroma using the dev configuration file, `config/dev.secret.exs`. To run them using the prod config file, prefix each command at the shell with `MIX_ENV=prod`. For example: `MIX_ENV=prod mix phx.server`. Documentation for the config can be found at [`docs/config.md`](docs/config.md) in the repository, or at the "Configuration" page on <https://docs-develop.pleroma.social/config.html>
|
||||||
* Run `mix ecto.migrate` to run the database migrations. You will have to do this again after certain updates.
|
* Run `mix ecto.migrate` to run the database migrations. You will have to do this again after certain updates.
|
||||||
* You can check if your instance is configured correctly by running it with `mix phx.server` and checking the instance info endpoint at `/api/v1/instance`. If it shows your uri, name and email correctly, you are configured correctly. If it shows something like `localhost:4000`, your configuration is probably wrong, unless you are running a local development setup.
|
* You can check if your instance is configured correctly by running it with `mix phx.server` and checking the instance info endpoint at `/api/v1/instance`. If it shows your uri, name and email correctly, you are configured correctly. If it shows something like `localhost:4000`, your configuration is probably wrong, unless you are running a local development setup.
|
||||||
* The common and convenient way for adding HTTPS is by using Nginx as a reverse proxy. You can look at example Nginx configuration in `installation/pleroma.nginx`. If you need TLS/SSL certificates for HTTPS, you can look get some for free with letsencrypt: <https://letsencrypt.org/>. The simplest way to obtain and install a certificate is to use [Certbot.](https://certbot.eff.org) Depending on your specific setup, certbot may be able to get a certificate and configure your web server automatically.
|
* The common and convenient way for adding HTTPS is by using Nginx as a reverse proxy. You can look at example Nginx configuration in `installation/pleroma.nginx`. If you need TLS/SSL certificates for HTTPS, you can look get some for free with letsencrypt: <https://letsencrypt.org/>. The simplest way to obtain and install a certificate is to use [Certbot.](https://certbot.eff.org) Depending on your specific setup, certbot may be able to get a certificate and configure your web server automatically.
|
||||||
@ -66,7 +68,7 @@ This is useful for running Pleroma inside Tor or I2P.
|
|||||||
|
|
||||||
## Customization and contribution
|
## Customization and contribution
|
||||||
|
|
||||||
The [Pleroma Wiki](https://git.pleroma.social/pleroma/pleroma/wikis/home) offers manuals and guides on how to further customize your instance to your liking and how you can contribute to the project.
|
The [Pleroma Documentation](https://docs-develop.pleroma.social/readme.html) offers manuals and guides on how to further customize your instance to your liking and how you can contribute to the project.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ use Mix.Config
|
|||||||
# General application configuration
|
# General application configuration
|
||||||
config :pleroma, ecto_repos: [Pleroma.Repo]
|
config :pleroma, ecto_repos: [Pleroma.Repo]
|
||||||
|
|
||||||
config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
|
config :pleroma, Pleroma.Repo,
|
||||||
|
types: Pleroma.PostgresTypes,
|
||||||
|
telemetry_event: [Pleroma.Repo.Instrumenter]
|
||||||
|
|
||||||
config :pleroma, Pleroma.Captcha,
|
config :pleroma, Pleroma.Captcha,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@ -34,7 +36,8 @@ config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.
|
|||||||
# Upload configuration
|
# Upload configuration
|
||||||
config :pleroma, Pleroma.Upload,
|
config :pleroma, Pleroma.Upload,
|
||||||
uploader: Pleroma.Uploaders.Local,
|
uploader: Pleroma.Uploaders.Local,
|
||||||
filters: [],
|
filters: [Pleroma.Upload.Filter.Dedupe],
|
||||||
|
link_name: true,
|
||||||
proxy_remote: false,
|
proxy_remote: false,
|
||||||
proxy_opts: [
|
proxy_opts: [
|
||||||
redirect_on_failure: false,
|
redirect_on_failure: false,
|
||||||
@ -55,7 +58,13 @@ config :pleroma, Pleroma.Uploaders.MDII,
|
|||||||
cgi: "https://mdii.sakura.ne.jp/mdii-post.cgi",
|
cgi: "https://mdii.sakura.ne.jp/mdii-post.cgi",
|
||||||
files: "https://mdii.sakura.ne.jp"
|
files: "https://mdii.sakura.ne.jp"
|
||||||
|
|
||||||
config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]
|
config :pleroma, :emoji,
|
||||||
|
shortcode_globs: ["/emoji/custom/**/*.png"],
|
||||||
|
groups: [
|
||||||
|
# Put groups that have higher priority than defaults here. Example in `docs/config/custom_emoji.md`
|
||||||
|
Finmoji: "/finmoji/128px/*-128.png",
|
||||||
|
Custom: ["/emoji/*.png", "/emoji/custom/*.png"]
|
||||||
|
]
|
||||||
|
|
||||||
config :pleroma, :uri_schemes,
|
config :pleroma, :uri_schemes,
|
||||||
valid_schemes: [
|
valid_schemes: [
|
||||||
@ -88,6 +97,7 @@ websocket_config = [
|
|||||||
|
|
||||||
# Configures the endpoint
|
# Configures the endpoint
|
||||||
config :pleroma, Pleroma.Web.Endpoint,
|
config :pleroma, Pleroma.Web.Endpoint,
|
||||||
|
instrumenters: [Pleroma.Web.Endpoint.Instrumenter],
|
||||||
url: [host: "localhost"],
|
url: [host: "localhost"],
|
||||||
http: [
|
http: [
|
||||||
dispatch: [
|
dispatch: [
|
||||||
@ -119,6 +129,11 @@ config :logger, :ex_syslogger,
|
|||||||
format: "$metadata[$level] $message",
|
format: "$metadata[$level] $message",
|
||||||
metadata: [:request_id]
|
metadata: [:request_id]
|
||||||
|
|
||||||
|
config :quack,
|
||||||
|
level: :warn,
|
||||||
|
meta: [:all],
|
||||||
|
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||||
|
|
||||||
config :mime, :types, %{
|
config :mime, :types, %{
|
||||||
"application/xml" => ["xml"],
|
"application/xml" => ["xml"],
|
||||||
"application/xrd+xml" => ["xrd+xml"],
|
"application/xrd+xml" => ["xrd+xml"],
|
||||||
@ -133,7 +148,14 @@ config :pleroma, :httpoison, Pleroma.HTTP
|
|||||||
config :tesla, adapter: Tesla.Adapter.Hackney
|
config :tesla, adapter: Tesla.Adapter.Hackney
|
||||||
|
|
||||||
# Configures http settings, upstream proxy etc.
|
# Configures http settings, upstream proxy etc.
|
||||||
config :pleroma, :http, proxy_url: nil
|
config :pleroma, :http,
|
||||||
|
proxy_url: nil,
|
||||||
|
adapter: [
|
||||||
|
ssl_options: [
|
||||||
|
# We don't support TLS v1.3 yet
|
||||||
|
versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
config :pleroma, :instance,
|
config :pleroma, :instance,
|
||||||
name: "Pleroma",
|
name: "Pleroma",
|
||||||
@ -166,7 +188,8 @@ config :pleroma, :instance,
|
|||||||
no_attachment_links: false,
|
no_attachment_links: false,
|
||||||
welcome_user_nickname: nil,
|
welcome_user_nickname: nil,
|
||||||
welcome_message: nil,
|
welcome_message: nil,
|
||||||
max_report_comment_size: 1000
|
max_report_comment_size: 1000,
|
||||||
|
safe_dm_mentions: false
|
||||||
|
|
||||||
config :pleroma, :markup,
|
config :pleroma, :markup,
|
||||||
# XXX - unfortunately, inline images must be enabled by default right now, because
|
# XXX - unfortunately, inline images must be enabled by default right now, because
|
||||||
@ -215,6 +238,9 @@ config :pleroma, :frontend_configurations,
|
|||||||
scopeCopy: true,
|
scopeCopy: true,
|
||||||
subjectLineBehavior: "email",
|
subjectLineBehavior: "email",
|
||||||
alwaysShowSubjectInput: true
|
alwaysShowSubjectInput: true
|
||||||
|
},
|
||||||
|
masto_fe: %{
|
||||||
|
showInstanceSpecificPanel: true
|
||||||
}
|
}
|
||||||
|
|
||||||
config :pleroma, :activitypub,
|
config :pleroma, :activitypub,
|
||||||
@ -262,8 +288,6 @@ config :pleroma, :media_proxy,
|
|||||||
|
|
||||||
config :pleroma, :chat, enabled: true
|
config :pleroma, :chat, enabled: true
|
||||||
|
|
||||||
config :ecto, json_library: Jason
|
|
||||||
|
|
||||||
config :phoenix, :format_encoders, json: Jason
|
config :phoenix, :format_encoders, json: Jason
|
||||||
|
|
||||||
config :pleroma, :gopher,
|
config :pleroma, :gopher,
|
||||||
@ -340,11 +364,18 @@ config :pleroma, Pleroma.Web.Federator.RetryQueue,
|
|||||||
initial_timeout: 30,
|
initial_timeout: 30,
|
||||||
max_retries: 5
|
max_retries: 5
|
||||||
|
|
||||||
config :pleroma, Pleroma.Jobs,
|
config :pleroma_job_queue, :queues,
|
||||||
federator_incoming: [max_jobs: 50],
|
federator_incoming: 50,
|
||||||
federator_outgoing: [max_jobs: 50],
|
federator_outgoing: 50,
|
||||||
mailer: [max_jobs: 10],
|
web_push: 50,
|
||||||
user: [max_jobs: 10]
|
mailer: 10,
|
||||||
|
transmogrifier: 20,
|
||||||
|
scheduled_activities: 10,
|
||||||
|
user: 10
|
||||||
|
|
||||||
|
config :pleroma, :fetch_initial_posts,
|
||||||
|
enabled: false,
|
||||||
|
pages: 5
|
||||||
|
|
||||||
config :auto_linker,
|
config :auto_linker,
|
||||||
opts: [
|
opts: [
|
||||||
@ -356,6 +387,42 @@ config :auto_linker,
|
|||||||
rel: false
|
rel: false
|
||||||
]
|
]
|
||||||
|
|
||||||
|
config :pleroma, :ldap,
|
||||||
|
enabled: System.get_env("LDAP_ENABLED") == "true",
|
||||||
|
host: System.get_env("LDAP_HOST") || "localhost",
|
||||||
|
port: String.to_integer(System.get_env("LDAP_PORT") || "389"),
|
||||||
|
ssl: System.get_env("LDAP_SSL") == "true",
|
||||||
|
sslopts: [],
|
||||||
|
tls: System.get_env("LDAP_TLS") == "true",
|
||||||
|
tlsopts: [],
|
||||||
|
base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
|
||||||
|
uid: System.get_env("LDAP_UID") || "cn"
|
||||||
|
|
||||||
|
oauth_consumer_strategies = String.split(System.get_env("OAUTH_CONSUMER_STRATEGIES") || "")
|
||||||
|
|
||||||
|
ueberauth_providers =
|
||||||
|
for strategy <- oauth_consumer_strategies do
|
||||||
|
strategy_module_name = "Elixir.Ueberauth.Strategy.#{String.capitalize(strategy)}"
|
||||||
|
strategy_module = String.to_atom(strategy_module_name)
|
||||||
|
{String.to_atom(strategy), {strategy_module, [callback_params: ["state"]]}}
|
||||||
|
end
|
||||||
|
|
||||||
|
config :ueberauth,
|
||||||
|
Ueberauth,
|
||||||
|
base_path: "/oauth",
|
||||||
|
providers: ueberauth_providers
|
||||||
|
|
||||||
|
config :pleroma, :auth, oauth_consumer_strategies: oauth_consumer_strategies
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Sendmail
|
||||||
|
|
||||||
|
config :prometheus, Pleroma.Web.Endpoint.MetricsExporter, path: "/api/pleroma/app_metrics"
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.ScheduledActivity,
|
||||||
|
daily_user_limit: 25,
|
||||||
|
total_user_limit: 300,
|
||||||
|
enabled: true
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
@ -12,7 +12,6 @@ config :pleroma, Pleroma.Web.Endpoint,
|
|||||||
protocol_options: [max_request_line_length: 8192, max_header_value_length: 8192]
|
protocol_options: [max_request_line_length: 8192, max_header_value_length: 8192]
|
||||||
],
|
],
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
secure_cookie_flag: false,
|
|
||||||
debug_errors: true,
|
debug_errors: true,
|
||||||
code_reloader: true,
|
code_reloader: true,
|
||||||
check_origin: false,
|
check_origin: false,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
firefox, /emoji/Firefox.gif
|
firefox, /emoji/Firefox.gif, Gif,Fun
|
||||||
blank, /emoji/blank.png
|
blank, /emoji/blank.png, Fun
|
||||||
f_00b, /emoji/f_00b.png
|
f_00b, /emoji/f_00b.png
|
||||||
f_00b11b, /emoji/f_00b11b.png
|
f_00b11b, /emoji/f_00b11b.png
|
||||||
f_00b33b, /emoji/f_00b33b.png
|
f_00b33b, /emoji/f_00b33b.png
|
||||||
@ -28,4 +28,3 @@ f_33b00b, /emoji/f_33b00b.png
|
|||||||
f_33b22b, /emoji/f_33b22b.png
|
f_33b22b, /emoji/f_33b22b.png
|
||||||
f_33h, /emoji/f_33h.png
|
f_33h, /emoji/f_33h.png
|
||||||
f_33t, /emoji/f_33t.png
|
f_33t, /emoji/f_33t.png
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ config :pleroma, Pleroma.Captcha,
|
|||||||
# Print only warnings and errors during test
|
# Print only warnings and errors during test
|
||||||
config :logger, level: :warn
|
config :logger, level: :warn
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Upload, filters: [], link_name: false
|
||||||
|
|
||||||
config :pleroma, Pleroma.Uploaders.Local, uploads: "test/uploads"
|
config :pleroma, Pleroma.Uploaders.Local, uploads: "test/uploads"
|
||||||
|
|
||||||
config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Test
|
config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Test
|
||||||
@ -44,7 +46,14 @@ config :web_push_encryption, :vapid_details,
|
|||||||
"BLH1qVhJItRGCfxgTtONfsOKDc9VRAraXw-3NsmjMngWSh7NxOizN6bkuRA7iLTMPS82PjwJAr3UoK9EC1IFrz4",
|
"BLH1qVhJItRGCfxgTtONfsOKDc9VRAraXw-3NsmjMngWSh7NxOizN6bkuRA7iLTMPS82PjwJAr3UoK9EC1IFrz4",
|
||||||
private_key: "_-XZ0iebPrRfZ_o0-IatTdszYa8VCH1yLN-JauK7HHA"
|
private_key: "_-XZ0iebPrRfZ_o0-IatTdszYa8VCH1yLN-JauK7HHA"
|
||||||
|
|
||||||
config :pleroma, Pleroma.Jobs, testing: [max_jobs: 2]
|
config :web_push_encryption, :http_client, Pleroma.Web.WebPushHttpClientMock
|
||||||
|
|
||||||
|
config :pleroma_job_queue, disabled: true
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.ScheduledActivity,
|
||||||
|
daily_user_limit: 2,
|
||||||
|
total_user_limit: 3,
|
||||||
|
enabled: false
|
||||||
|
|
||||||
try do
|
try do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
# Differences in Mastodon API responses from vanilla Mastodon
|
|
||||||
|
|
||||||
A Pleroma instance can be identified by "<Mastodon version> (compatible; Pleroma <version>)" present in `version` field in response from `/api/v1/instance`
|
|
||||||
|
|
||||||
## Flake IDs
|
|
||||||
|
|
||||||
Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mastodon's ids they are sortable strings
|
|
||||||
|
|
||||||
## Attachment cap
|
|
||||||
|
|
||||||
Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.
|
|
||||||
|
|
||||||
## Timelines
|
|
||||||
|
|
||||||
Adding the parameter `with_muted=true` to the timeline queries will also return activities by muted (not by blocked!) users.
|
|
17
docs/admin/backup.md
Normal file
17
docs/admin/backup.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Backup/Restore your instance
|
||||||
|
|
||||||
|
## Backup
|
||||||
|
|
||||||
|
1. Stop the Pleroma service.
|
||||||
|
2. Go to the working directory of Pleroma (default is `/opt/pleroma`)
|
||||||
|
3. Run `sudo -Hu postgres pg_dump -d <pleroma_db> --format=custom -f </path/to/backup_location/pleroma.pgdump>`
|
||||||
|
4. Copy `pleroma.pgdump`, `config/prod.secret.exs` and the `uploads` folder to your backup destination. If you have other modifications, copy those changes too.
|
||||||
|
5. Restart the Pleroma service.
|
||||||
|
|
||||||
|
## Restore
|
||||||
|
|
||||||
|
1. Stop the Pleroma service.
|
||||||
|
2. Go to the working directory of Pleroma (default is `/opt/pleroma`)
|
||||||
|
3. Copy the above mentioned files back to their original position.
|
||||||
|
4. Run `sudo -Hu postgres pg_restore -d <pleroma_db> -v -1 </path/to/backup_location/pleroma.pgdump>`
|
||||||
|
5. Restart the Pleroma service.
|
9
docs/admin/updating.md
Normal file
9
docs/admin/updating.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Updating your instance
|
||||||
|
1. Go to the working directory of Pleroma (default is `/opt/pleroma`)
|
||||||
|
2. Run `git pull`. This pulls the latest changes from upstream.
|
||||||
|
3. Run `mix deps.get`. This pulls in any new dependencies.
|
||||||
|
4. Stop the Pleroma service.
|
||||||
|
5. Run `mix ecto.migrate`[^1]. This task performs database migrations, if there were any.
|
||||||
|
6. Start the Pleroma service.
|
||||||
|
|
||||||
|
[^1]: Prefix with `MIX_ENV=prod` to run it using the production config file.
|
@ -7,9 +7,16 @@ Authentication is required and the user must be an admin.
|
|||||||
### List users
|
### List users
|
||||||
|
|
||||||
- Method `GET`
|
- Method `GET`
|
||||||
- Params:
|
- Query Params:
|
||||||
- `page`: **integer** page number
|
- *optional* `query`: **string** search term
|
||||||
- `page_size`: **integer** number of users per page (default is `50`)
|
- *optional* `filters`: **string** comma-separated string of filters:
|
||||||
|
- `local`: only local users
|
||||||
|
- `external`: only external users
|
||||||
|
- `active`: only active users
|
||||||
|
- `deactivated`: only deactivated users
|
||||||
|
- *optional* `page`: **integer** page number
|
||||||
|
- *optional* `page_size`: **integer** number of users per page (default is `50`)
|
||||||
|
- Example: `https://mypleroma.org/api/pleroma/admin/users?query=john&filters=local,active&page=1&page_size=10`
|
||||||
- Response:
|
- Response:
|
||||||
|
|
||||||
```JSON
|
```JSON
|
||||||
@ -20,34 +27,13 @@ Authentication is required and the user must be an admin.
|
|||||||
{
|
{
|
||||||
"deactivated": bool,
|
"deactivated": bool,
|
||||||
"id": integer,
|
"id": integer,
|
||||||
"nickname": string
|
"nickname": string,
|
||||||
},
|
"roles": {
|
||||||
...
|
"admin": bool,
|
||||||
]
|
"moderator": bool
|
||||||
}
|
},
|
||||||
```
|
"local": bool,
|
||||||
|
"tags": array
|
||||||
## `/api/pleroma/admin/users/search?query={query}&local={local}&page={page}&page_size={page_size}`
|
|
||||||
|
|
||||||
### Search users by name or nickname
|
|
||||||
|
|
||||||
- Method `GET`
|
|
||||||
- Params:
|
|
||||||
- `query`: **string** search term
|
|
||||||
- `local`: **bool** whether to return only local users
|
|
||||||
- `page`: **integer** page number
|
|
||||||
- `page_size`: **integer** number of users per page (default is `50`)
|
|
||||||
- Response:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"page_size": integer,
|
|
||||||
"count": integer,
|
|
||||||
"users": [
|
|
||||||
{
|
|
||||||
"deactivated": bool,
|
|
||||||
"id": integer,
|
|
||||||
"nickname": string
|
|
||||||
},
|
},
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
@ -72,6 +58,26 @@ Authentication is required and the user must be an admin.
|
|||||||
- `password`
|
- `password`
|
||||||
- Response: User’s nickname
|
- Response: User’s nickname
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/user/follow`
|
||||||
|
### Make a user follow another user
|
||||||
|
|
||||||
|
- Methods: `POST`
|
||||||
|
- Params:
|
||||||
|
- `follower`: The nickname of the follower
|
||||||
|
- `followed`: The nickname of the followed
|
||||||
|
- Response:
|
||||||
|
- "ok"
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/user/unfollow`
|
||||||
|
### Make a user unfollow another user
|
||||||
|
|
||||||
|
- Methods: `POST`
|
||||||
|
- Params:
|
||||||
|
- `follower`: The nickname of the follower
|
||||||
|
- `followed`: The nickname of the followed
|
||||||
|
- Response:
|
||||||
|
- "ok"
|
||||||
|
|
||||||
## `/api/pleroma/admin/users/:nickname/toggle_activation`
|
## `/api/pleroma/admin/users/:nickname/toggle_activation`
|
||||||
|
|
||||||
### Toggle user activation
|
### Toggle user activation
|
||||||
@ -124,7 +130,7 @@ Authentication is required and the user must be an admin.
|
|||||||
|
|
||||||
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
|
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
|
||||||
|
|
||||||
### Get user user permission groups membership
|
### Get user user permission groups membership per permission group
|
||||||
|
|
||||||
- Method: `GET`
|
- Method: `GET`
|
||||||
- Params: none
|
- Params: none
|
||||||
@ -163,6 +169,17 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||||||
- `nickname`
|
- `nickname`
|
||||||
- `status` BOOLEAN field, false value means deactivation.
|
- `status` BOOLEAN field, false value means deactivation.
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/users/:nickname`
|
||||||
|
|
||||||
|
### Retrive the details of a user
|
||||||
|
|
||||||
|
- Method: `GET`
|
||||||
|
- Params:
|
||||||
|
- `nickname`
|
||||||
|
- Response:
|
||||||
|
- On failure: `Not found`
|
||||||
|
- On success: JSON of the user
|
||||||
|
|
||||||
## `/api/pleroma/admin/relay`
|
## `/api/pleroma/admin/relay`
|
||||||
|
|
||||||
### Follow a Relay
|
### Follow a Relay
|
||||||
@ -183,11 +200,64 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||||||
|
|
||||||
## `/api/pleroma/admin/invite_token`
|
## `/api/pleroma/admin/invite_token`
|
||||||
|
|
||||||
### Get a account registeration invite token
|
### Get an account registration invite token
|
||||||
|
|
||||||
|
- Methods: `GET`
|
||||||
|
- Params:
|
||||||
|
- *optional* `invite` => [
|
||||||
|
- *optional* `max_use` (integer)
|
||||||
|
- *optional* `expires_at` (date string e.g. "2019-04-07")
|
||||||
|
]
|
||||||
|
- Response: invite token (base64 string)
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/invites`
|
||||||
|
|
||||||
|
### Get a list of generated invites
|
||||||
|
|
||||||
- Methods: `GET`
|
- Methods: `GET`
|
||||||
- Params: none
|
- Params: none
|
||||||
- Response: invite token (base64 string)
|
- Response:
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
|
||||||
|
"invites": [
|
||||||
|
{
|
||||||
|
"id": integer,
|
||||||
|
"token": string,
|
||||||
|
"used": boolean,
|
||||||
|
"expires_at": date,
|
||||||
|
"uses": integer,
|
||||||
|
"max_use": integer,
|
||||||
|
"invite_type": string (possible values: `one_time`, `reusable`, `date_limited`, `reusable_date_limited`)
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/revoke_invite`
|
||||||
|
|
||||||
|
### Revoke invite by token
|
||||||
|
|
||||||
|
- Methods: `POST`
|
||||||
|
- Params:
|
||||||
|
- `token`
|
||||||
|
- Response:
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"id": integer,
|
||||||
|
"token": string,
|
||||||
|
"used": boolean,
|
||||||
|
"expires_at": date,
|
||||||
|
"uses": integer,
|
||||||
|
"max_use": integer,
|
||||||
|
"invite_type": string (possible values: `one_time`, `reusable`, `date_limited`, `reusable_date_limited`)
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## `/api/pleroma/admin/email_invite`
|
## `/api/pleroma/admin/email_invite`
|
||||||
|
|
||||||
@ -196,7 +266,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||||||
- Methods: `POST`
|
- Methods: `POST`
|
||||||
- Params:
|
- Params:
|
||||||
- `email`
|
- `email`
|
||||||
- `name`, optionnal
|
- `name`, optional
|
||||||
|
|
||||||
## `/api/pleroma/admin/password_reset`
|
## `/api/pleroma/admin/password_reset`
|
||||||
|
|
54
docs/api/differences_in_mastoapi_responses.md
Normal file
54
docs/api/differences_in_mastoapi_responses.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Differences in Mastodon API responses from vanilla Mastodon
|
||||||
|
|
||||||
|
A Pleroma instance can be identified by "<Mastodon version> (compatible; Pleroma <version>)" present in `version` field in response from `/api/v1/instance`
|
||||||
|
|
||||||
|
## Flake IDs
|
||||||
|
|
||||||
|
Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mastodon's ids they are sortable strings
|
||||||
|
|
||||||
|
## Attachment cap
|
||||||
|
|
||||||
|
Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.
|
||||||
|
|
||||||
|
## Timelines
|
||||||
|
|
||||||
|
Adding the parameter `with_muted=true` to the timeline queries will also return activities by muted (not by blocked!) users.
|
||||||
|
|
||||||
|
## Statuses
|
||||||
|
|
||||||
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
- `local`: true if the post was made on the local instance.
|
||||||
|
- `conversation_id`: the ID of the conversation the status is associated with (if any)
|
||||||
|
- `content`: a map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
|
- `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
|
|
||||||
|
## Attachments
|
||||||
|
|
||||||
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
- `mime_type`: mime type of the attachment.
|
||||||
|
|
||||||
|
## Accounts
|
||||||
|
|
||||||
|
- `/api/v1/accounts/:id`: The `id` parameter can also be the `nickname` of the user. This only works in this endpoint, not the deeper nested ones for following etc.
|
||||||
|
|
||||||
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
- `tags`: Lists an array of tags for the user
|
||||||
|
- `relationship{}`: Includes fields as documented for Mastodon API https://docs.joinmastodon.org/api/entities/#relationship
|
||||||
|
- `is_moderator`: boolean, true if user is a moderator
|
||||||
|
- `is_admin`: boolean, true if user is an admin
|
||||||
|
- `confirmation_pending`: boolean, true if a new user account is waiting on email confirmation to be activated
|
||||||
|
|
||||||
|
## Notifications
|
||||||
|
|
||||||
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
- `is_seen`: true if the notification was read by the user
|
||||||
|
|
||||||
|
## POST `/api/v1/statuses`
|
||||||
|
|
||||||
|
Additional parameters can be added to the JSON body/Form data:
|
||||||
|
|
||||||
|
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
|
@ -10,7 +10,29 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
|
|||||||
* Authentication: not required
|
* Authentication: not required
|
||||||
* Params: none
|
* Params: none
|
||||||
* Response: JSON
|
* Response: JSON
|
||||||
* Example response: `{"kalsarikannit_f":"/finmoji/128px/kalsarikannit_f-128.png","perkele":"/finmoji/128px/perkele-128.png","blobdab":"/emoji/blobdab.png","happiness":"/finmoji/128px/happiness-128.png"}`
|
* Example response:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"girlpower": {
|
||||||
|
"tags": [
|
||||||
|
"Finmoji"
|
||||||
|
],
|
||||||
|
"image_url": "/finmoji/128px/girlpower-128.png"
|
||||||
|
},
|
||||||
|
"education": {
|
||||||
|
"tags": [
|
||||||
|
"Finmoji"
|
||||||
|
],
|
||||||
|
"image_url": "/finmoji/128px/education-128.png"
|
||||||
|
},
|
||||||
|
"finnishlove": {
|
||||||
|
"tags": [
|
||||||
|
"Finmoji"
|
||||||
|
],
|
||||||
|
"image_url": "/finmoji/128px/finnishlove-128.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
* Note: Same data as Mastodon API’s `/api/v1/custom_emojis` but in a different format
|
* Note: Same data as Mastodon API’s `/api/v1/custom_emojis` but in a different format
|
||||||
|
|
||||||
## `/api/pleroma/follow_import`
|
## `/api/pleroma/follow_import`
|
||||||
@ -27,14 +49,14 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
|
|||||||
* Method: `GET`
|
* Method: `GET`
|
||||||
* Authentication: not required
|
* Authentication: not required
|
||||||
* Params: none
|
* Params: none
|
||||||
* Response: Provider specific JSON, the only guaranteed parameter is `type`
|
* Response: Provider specific JSON, the only guaranteed parameter is `type`
|
||||||
* Example response: `{"type": "kocaptcha", "token": "whatever", "url": "https://captcha.kotobank.ch/endpoint"}`
|
* Example response: `{"type": "kocaptcha", "token": "whatever", "url": "https://captcha.kotobank.ch/endpoint"}`
|
||||||
|
|
||||||
## `/api/pleroma/delete_account`
|
## `/api/pleroma/delete_account`
|
||||||
### Delete an account
|
### Delete an account
|
||||||
* Method `POST`
|
* Method `POST`
|
||||||
* Authentication: required
|
* Authentication: required
|
||||||
* Params:
|
* Params:
|
||||||
* `password`: user's password
|
* `password`: user's password
|
||||||
* Response: JSON. Returns `{"status": "success"}` if the deletion was successful, `{"error": "[error message]"}` otherwise
|
* Response: JSON. Returns `{"status": "success"}` if the deletion was successful, `{"error": "[error message]"}` otherwise
|
||||||
* Example response: `{"error": "Invalid password."}`
|
* Example response: `{"error": "Invalid password."}`
|
||||||
@ -52,7 +74,7 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
|
|||||||
* `confirm`
|
* `confirm`
|
||||||
* `captcha_solution`: optional, contains provider-specific captcha solution,
|
* `captcha_solution`: optional, contains provider-specific captcha solution,
|
||||||
* `captcha_token`: optional, contains provider-specific captcha token
|
* `captcha_token`: optional, contains provider-specific captcha token
|
||||||
* `token`: invite token required when the registerations aren't public.
|
* `token`: invite token required when the registrations aren't public.
|
||||||
* Response: JSON. Returns a user object on success, otherwise returns `{"error": "error_msg"}`
|
* Response: JSON. Returns a user object on success, otherwise returns `{"error": "error_msg"}`
|
||||||
* Example response:
|
* Example response:
|
||||||
```
|
```
|
||||||
@ -108,3 +130,70 @@ See [Admin-API](Admin-API.md)
|
|||||||
* Response: JSON string. Returns the user flavour or the default one.
|
* Response: JSON string. Returns the user flavour or the default one.
|
||||||
* Example response: "glitch"
|
* Example response: "glitch"
|
||||||
* Note: This is intended to be used only by mastofe
|
* Note: This is intended to be used only by mastofe
|
||||||
|
|
||||||
|
## `/api/pleroma/notifications/read`
|
||||||
|
### Mark a single notification as read
|
||||||
|
* Method `POST`
|
||||||
|
* Authentication: required
|
||||||
|
* Params:
|
||||||
|
* `id`: notification's id
|
||||||
|
* Response: JSON. Returns `{"status": "success"}` if the reading was successful, otherwise returns `{"error": "error_msg"}`
|
||||||
|
|
||||||
|
## `/api/v1/pleroma/accounts/:id/subscribe`
|
||||||
|
### Subscribe to receive notifications for all statuses posted by a user
|
||||||
|
* Method `POST`
|
||||||
|
* Authentication: required
|
||||||
|
* Params:
|
||||||
|
* `id`: account id to subscribe to
|
||||||
|
* Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}`
|
||||||
|
* Example response:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "abcdefg",
|
||||||
|
"following": true,
|
||||||
|
"followed_by": false,
|
||||||
|
"blocking": false,
|
||||||
|
"muting": false,
|
||||||
|
"muting_notifications": false,
|
||||||
|
"subscribing": true,
|
||||||
|
"requested": false,
|
||||||
|
"domain_blocking": false,
|
||||||
|
"showing_reblogs": true,
|
||||||
|
"endorsed": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## `/api/v1/pleroma/accounts/:id/unsubscribe`
|
||||||
|
### Unsubscribe to stop receiving notifications from user statuses
|
||||||
|
* Method `POST`
|
||||||
|
* Authentication: required
|
||||||
|
* Params:
|
||||||
|
* `id`: account id to unsubscribe from
|
||||||
|
* Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}`
|
||||||
|
* Example response:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "abcdefg",
|
||||||
|
"following": true,
|
||||||
|
"followed_by": false,
|
||||||
|
"blocking": false,
|
||||||
|
"muting": false,
|
||||||
|
"muting_notifications": false,
|
||||||
|
"subscribing": false,
|
||||||
|
"requested": false,
|
||||||
|
"domain_blocking": false,
|
||||||
|
"showing_reblogs": true,
|
||||||
|
"endorsed": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## `/api/pleroma/notification_settings`
|
||||||
|
### Updates user notification settings
|
||||||
|
* Method `PUT`
|
||||||
|
* Authentication: required
|
||||||
|
* Params:
|
||||||
|
* `followers`: BOOLEAN field, receives notifications from followers
|
||||||
|
* `follows`: BOOLEAN field, receives notifications from people the user follows
|
||||||
|
* `remote`: BOOLEAN field, receives notifications from people on remote instances
|
||||||
|
* `local`: BOOLEAN field, receives notifications from people on the local instance
|
||||||
|
* Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
|
22
docs/api/prometheus.md
Normal file
22
docs/api/prometheus.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Prometheus Metrics
|
||||||
|
|
||||||
|
Pleroma includes support for exporting metrics via the [prometheus_ex](https://github.com/deadtrickster/prometheus.ex) library.
|
||||||
|
|
||||||
|
## `/api/pleroma/app_metrics`
|
||||||
|
### Exports Prometheus application metrics
|
||||||
|
* Method: `GET`
|
||||||
|
* Authentication: not required
|
||||||
|
* Params: none
|
||||||
|
* Response: JSON
|
||||||
|
|
||||||
|
## Grafana
|
||||||
|
### Config example
|
||||||
|
The following is a config example to use with [Grafana](https://grafana.com)
|
||||||
|
|
||||||
|
```
|
||||||
|
- job_name: 'beam'
|
||||||
|
metrics_path: /api/pleroma/app_metrics
|
||||||
|
scheme: https
|
||||||
|
static_configs:
|
||||||
|
- targets: ['pleroma.soykaf.com']
|
||||||
|
```
|
@ -4,8 +4,8 @@ Feel free to contact us to be added to this list!
|
|||||||
|
|
||||||
## Desktop
|
## Desktop
|
||||||
### Roma for Desktop
|
### Roma for Desktop
|
||||||
- Homepage: <http://www.pleroma.com/desktop-app/>
|
- Homepage: <https://www.pleroma.com/#desktopApp>
|
||||||
- Source Code: ???
|
- Source Code: <https://github.com/roma-apps/roma-desktop>
|
||||||
- Platforms: Windows, Mac, (Linux?)
|
- Platforms: Windows, Mac, (Linux?)
|
||||||
- Features: Streaming Ready
|
- Features: Streaming Ready
|
||||||
|
|
||||||
@ -30,6 +30,12 @@ Feel free to contact us to be added to this list!
|
|||||||
- Platforms: iOS
|
- Platforms: iOS
|
||||||
- Features: No Streaming
|
- Features: No Streaming
|
||||||
|
|
||||||
|
### Fedilab
|
||||||
|
- Source Code: <https://gitlab.com/tom79/mastalab/>
|
||||||
|
- Contact: [@tom79@mastodon.social](https://mastodon.social/users/tom79)
|
||||||
|
- Platforms: Android
|
||||||
|
- Features: Streaming Ready
|
||||||
|
|
||||||
### Nekonium
|
### Nekonium
|
||||||
- Homepage: [F-Droid Repository](https://repo.gdgd.jp.net/), [Google Play](https://play.google.com/store/apps/details?id=com.apps.nekonium), [Amazon](https://www.amazon.co.jp/dp/B076FXPRBC/)
|
- Homepage: [F-Droid Repository](https://repo.gdgd.jp.net/), [Google Play](https://play.google.com/store/apps/details?id=com.apps.nekonium), [Amazon](https://www.amazon.co.jp/dp/B076FXPRBC/)
|
||||||
- Source: <https://git.gdgd.jp.net/lin/nekonium/>
|
- Source: <https://git.gdgd.jp.net/lin/nekonium/>
|
||||||
@ -37,15 +43,9 @@ Feel free to contact us to be added to this list!
|
|||||||
- Platforms: Android
|
- Platforms: Android
|
||||||
- Features: Streaming Ready
|
- Features: Streaming Ready
|
||||||
|
|
||||||
### Mastalab
|
|
||||||
- Source Code: <https://gitlab.com/tom79/mastalab/>
|
|
||||||
- Contact: [@tom79@mastodon.social](https://mastodon.social/users/tom79)
|
|
||||||
- Platforms: Android
|
|
||||||
- Features: Streaming Ready
|
|
||||||
|
|
||||||
### Roma
|
### Roma
|
||||||
- Homepage: <http://www.pleroma.com/>
|
- Homepage: <https://www.pleroma.com/#mobileApps>
|
||||||
- Source Code: ???
|
- Source Code: [iOS](https://github.com/roma-apps/roma-ios), [Android](https://github.com/roma-apps/roma-android)
|
||||||
- Platforms: iOS, Android
|
- Platforms: iOS, Android
|
||||||
- Features: No Streaming
|
- Features: No Streaming
|
||||||
|
|
179
docs/config.md
179
docs/config.md
@ -6,6 +6,7 @@ If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherw
|
|||||||
## Pleroma.Upload
|
## Pleroma.Upload
|
||||||
* `uploader`: Select which `Pleroma.Uploaders` to use
|
* `uploader`: Select which `Pleroma.Uploaders` to use
|
||||||
* `filters`: List of `Pleroma.Upload.Filter` to use.
|
* `filters`: List of `Pleroma.Upload.Filter` to use.
|
||||||
|
* `link_name`: When enabled Pleroma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers when using filters like `Pleroma.Upload.Filter.Dedupe`
|
||||||
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host.
|
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host.
|
||||||
* `proxy_remote`: If you\'re using a remote uploader, Pleroma will proxy media requests instead of redirecting to it.
|
* `proxy_remote`: If you\'re using a remote uploader, Pleroma will proxy media requests instead of redirecting to it.
|
||||||
* `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation.
|
* `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation.
|
||||||
@ -100,10 +101,11 @@ config :pleroma, Pleroma.Mailer,
|
|||||||
* `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses
|
* `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses
|
||||||
* `welcome_message`: A message that will be send to a newly registered users as a direct message.
|
* `welcome_message`: A message that will be send to a newly registered users as a direct message.
|
||||||
* `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
|
* `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
|
||||||
* `max_report_size`: The maximum size of the report comment (Default: `1000`)
|
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`)
|
||||||
|
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). (Default: `false`)
|
||||||
|
|
||||||
## :logger
|
## :logger
|
||||||
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog
|
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
|
||||||
|
|
||||||
An example to enable ONLY ExSyslogger (f/ex in ``prod.secret.exs``) with info and debug suppressed:
|
An example to enable ONLY ExSyslogger (f/ex in ``prod.secret.exs``) with info and debug suppressed:
|
||||||
```
|
```
|
||||||
@ -126,10 +128,28 @@ config :logger, :ex_syslogger,
|
|||||||
|
|
||||||
See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/)
|
See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/)
|
||||||
|
|
||||||
|
An example of logging info to local syslog, but warn to a Slack channel:
|
||||||
|
```
|
||||||
|
config :logger,
|
||||||
|
backends: [ {ExSyslogger, :ex_syslogger}, Quack.Logger ],
|
||||||
|
level: :info
|
||||||
|
|
||||||
|
config :logger, :ex_syslogger,
|
||||||
|
level: :info,
|
||||||
|
ident: "pleroma",
|
||||||
|
format: "$metadata[$level] $message"
|
||||||
|
|
||||||
|
config :quack,
|
||||||
|
level: :warn,
|
||||||
|
meta: [:all],
|
||||||
|
webhook_url: "https://hooks.slack.com/services/YOUR-API-KEY-HERE"
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [Quack Github](https://github.com/azohra/quack) for more details
|
||||||
|
|
||||||
## :frontend_configurations
|
## :frontend_configurations
|
||||||
|
|
||||||
This can be used to configure a keyword list that keeps the configuration data for any kind of frontend. By default, settings for `pleroma_fe` are configured.
|
This can be used to configure a keyword list that keeps the configuration data for any kind of frontend. By default, settings for `pleroma_fe` and `masto_fe` are configured.
|
||||||
|
|
||||||
Frontends can access these settings at `/api/pleroma/frontend_configurations`
|
Frontends can access these settings at `/api/pleroma/frontend_configurations`
|
||||||
|
|
||||||
@ -189,6 +209,45 @@ This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:i
|
|||||||
* `enabled`: Enables the gopher interface
|
* `enabled`: Enables the gopher interface
|
||||||
* `ip`: IP address to bind to
|
* `ip`: IP address to bind to
|
||||||
* `port`: Port to bind to
|
* `port`: Port to bind to
|
||||||
|
* `dstport`: Port advertised in urls (optional, defaults to `port`)
|
||||||
|
|
||||||
|
## Pleroma.Web.Endpoint
|
||||||
|
`Phoenix` endpoint configuration, all configuration options can be viewed [here](https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#module-dynamic-configuration), only common options are listed here
|
||||||
|
* `http` - a list containing http protocol configuration, all configuration options can be viewed [here](https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html#module-options), only common options are listed here
|
||||||
|
- `ip` - a tuple consisting of 4 integers
|
||||||
|
- `port`
|
||||||
|
* `url` - a list containing the configuration for generating urls, accepts
|
||||||
|
- `host` - the host without the scheme and a post (e.g `example.com`, not `https://example.com:2020`)
|
||||||
|
- `scheme` - e.g `http`, `https`
|
||||||
|
- `port`
|
||||||
|
- `path`
|
||||||
|
|
||||||
|
|
||||||
|
**Important note**: if you modify anything inside these lists, default `config.exs` values will be overwritten, which may result in breakage, to make sure this does not happen please copy the default value for the list from `config.exs` and modify/add only what you need
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```elixir
|
||||||
|
config :pleroma, Pleroma.Web.Endpoint,
|
||||||
|
url: [host: "example.com", port: 2020, scheme: "https"],
|
||||||
|
http: [
|
||||||
|
# start copied from config.exs
|
||||||
|
dispatch: [
|
||||||
|
{:_,
|
||||||
|
[
|
||||||
|
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
||||||
|
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
||||||
|
{Phoenix.Transports.WebSocket,
|
||||||
|
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
|
||||||
|
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
||||||
|
]}
|
||||||
|
# end copied from config.exs
|
||||||
|
],
|
||||||
|
port: 8080,
|
||||||
|
ip: {127, 0, 0, 1}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
This will make Pleroma listen on `127.0.0.1` port `8080` and generate urls starting with `https://example.com:2020`
|
||||||
|
|
||||||
## :activitypub
|
## :activitypub
|
||||||
* ``accept_blocks``: Whether to accept incoming block activities from other instances
|
* ``accept_blocks``: Whether to accept incoming block activities from other instances
|
||||||
@ -250,25 +309,29 @@ You can then do
|
|||||||
curl "http://localhost:4000/api/pleroma/admin/invite_token?admin_token=somerandomtoken"
|
curl "http://localhost:4000/api/pleroma/admin/invite_token?admin_token=somerandomtoken"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Pleroma.Jobs
|
## :pleroma_job_queue
|
||||||
|
|
||||||
A list of job queues and their settings.
|
[Pleroma Job Queue](https://git.pleroma.social/pleroma/pleroma_job_queue) configuration: a list of queues with maximum concurrent jobs.
|
||||||
|
|
||||||
Job queue settings:
|
Pleroma has the following queues:
|
||||||
|
|
||||||
* `max_jobs`: The maximum amount of parallel jobs running at the same time.
|
* `federator_outgoing` - Outgoing federation
|
||||||
|
* `federator_incoming` - Incoming federation
|
||||||
|
* `mailer` - Email sender, see [`Pleroma.Mailer`](#pleroma-mailer)
|
||||||
|
* `transmogrifier` - Transmogrifier
|
||||||
|
* `web_push` - Web push notifications
|
||||||
|
* `scheduled_activities` - Scheduled activities, see [`Pleroma.ScheduledActivities`](#pleromascheduledactivity)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :pleroma, Pleroma.Jobs,
|
config :pleroma_job_queue, :queues,
|
||||||
federator_incoming: [max_jobs: 50],
|
federator_incoming: 50,
|
||||||
federator_outgoing: [max_jobs: 50]
|
federator_outgoing: 50
|
||||||
```
|
```
|
||||||
|
|
||||||
This config contains two queues: `federator_incoming` and `federator_outgoing`. Both have the `max_jobs` set to `50`.
|
This config contains two queues: `federator_incoming` and `federator_outgoing`. Both have the `max_jobs` set to `50`.
|
||||||
|
|
||||||
|
|
||||||
## Pleroma.Web.Federator.RetryQueue
|
## Pleroma.Web.Federator.RetryQueue
|
||||||
|
|
||||||
* `enabled`: If set to `true`, failed federation jobs will be retried
|
* `enabled`: If set to `true`, failed federation jobs will be retried
|
||||||
@ -285,6 +348,10 @@ This config contains two queues: `federator_incoming` and `federator_outgoing`.
|
|||||||
## :rich_media
|
## :rich_media
|
||||||
* `enabled`: if enabled the instance will parse metadata from attached links to generate link previews
|
* `enabled`: if enabled the instance will parse metadata from attached links to generate link previews
|
||||||
|
|
||||||
|
## :fetch_initial_posts
|
||||||
|
* `enabled`: if enabled, when a new user is federated with, fetch some of their latest posts
|
||||||
|
* `pages`: the amount of pages to fetch
|
||||||
|
|
||||||
## :hackney_pools
|
## :hackney_pools
|
||||||
|
|
||||||
Advanced. Tweaks Hackney (http client) connections pools.
|
Advanced. Tweaks Hackney (http client) connections pools.
|
||||||
@ -326,3 +393,91 @@ config :auto_linker,
|
|||||||
rel: false
|
rel: false
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Pleroma.ScheduledActivity
|
||||||
|
|
||||||
|
* `daily_user_limit`: the number of scheduled activities a user is allowed to create in a single day (Default: `25`)
|
||||||
|
* `total_user_limit`: the number of scheduled activities a user is allowed to create in total (Default: `300`)
|
||||||
|
* `enabled`: whether scheduled activities are sent to the job queue to be executed
|
||||||
|
|
||||||
|
## Pleroma.Web.Auth.Authenticator
|
||||||
|
|
||||||
|
* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
|
||||||
|
* `Pleroma.Web.Auth.LDAPAuthenticator`: LDAP authentication
|
||||||
|
|
||||||
|
## :ldap
|
||||||
|
|
||||||
|
Use LDAP for user authentication. When a user logs in to the Pleroma
|
||||||
|
instance, the name and password will be verified by trying to authenticate
|
||||||
|
(bind) to an LDAP server. If a user exists in the LDAP directory but there
|
||||||
|
is no account with the same name yet on the Pleroma instance then a new
|
||||||
|
Pleroma account will be created with the same name as the LDAP user name.
|
||||||
|
|
||||||
|
* `enabled`: enables LDAP authentication
|
||||||
|
* `host`: LDAP server hostname
|
||||||
|
* `port`: LDAP port, e.g. 389 or 636
|
||||||
|
* `ssl`: true to use SSL, usually implies the port 636
|
||||||
|
* `sslopts`: additional SSL options
|
||||||
|
* `tls`: true to start TLS, usually implies the port 389
|
||||||
|
* `tlsopts`: additional TLS options
|
||||||
|
* `base`: LDAP base, e.g. "dc=example,dc=com"
|
||||||
|
* `uid`: LDAP attribute name to authenticate the user, e.g. when "cn", the filter will be "cn=username,base"
|
||||||
|
|
||||||
|
## :auth
|
||||||
|
|
||||||
|
Authentication / authorization settings.
|
||||||
|
|
||||||
|
* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`.
|
||||||
|
* `oauth_consumer_template`: OAuth consumer mode authentication form template. By default it's `consumer.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/consumer.html.eex`.
|
||||||
|
* `oauth_consumer_strategies`: the list of enabled OAuth consumer strategies; by default it's set by OAUTH_CONSUMER_STRATEGIES environment variable.
|
||||||
|
|
||||||
|
# OAuth consumer mode
|
||||||
|
|
||||||
|
OAuth consumer mode allows sign in / sign up via external OAuth providers (e.g. Twitter, Facebook, Google, Microsoft, etc.).
|
||||||
|
Implementation is based on Ueberauth; see the list of [available strategies](https://github.com/ueberauth/ueberauth/wiki/List-of-Strategies).
|
||||||
|
|
||||||
|
Note: each strategy is shipped as a separate dependency; in order to get the strategies, run `OAUTH_CONSUMER_STRATEGIES="..." mix deps.get`,
|
||||||
|
e.g. `OAUTH_CONSUMER_STRATEGIES="twitter facebook google microsoft" mix deps.get`.
|
||||||
|
The server should also be started with `OAUTH_CONSUMER_STRATEGIES="..." mix phx.server` in case you enable any strategies.
|
||||||
|
|
||||||
|
Note: each strategy requires separate setup (on external provider side and Pleroma side). Below are the guidelines on setting up most popular strategies.
|
||||||
|
|
||||||
|
* For Twitter, [register an app](https://developer.twitter.com/en/apps), configure callback URL to https://<your_host>/oauth/twitter/callback
|
||||||
|
|
||||||
|
* For Facebook, [register an app](https://developers.facebook.com/apps), configure callback URL to https://<your_host>/oauth/facebook/callback, enable Facebook Login service at https://developers.facebook.com/apps/<app_id>/fb-login/settings/
|
||||||
|
|
||||||
|
* For Google, [register an app](https://console.developers.google.com), configure callback URL to https://<your_host>/oauth/google/callback
|
||||||
|
|
||||||
|
* For Microsoft, [register an app](https://portal.azure.com), configure callback URL to https://<your_host>/oauth/microsoft/callback
|
||||||
|
|
||||||
|
Once the app is configured on external OAuth provider side, add app's credentials and strategy-specific settings (if any — e.g. see Microsoft below) to `config/prod.secret.exs`,
|
||||||
|
per strategy's documentation (e.g. [ueberauth_twitter](https://github.com/ueberauth/ueberauth_twitter)). Example config basing on environment variables:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Twitter
|
||||||
|
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
||||||
|
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
||||||
|
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET")
|
||||||
|
|
||||||
|
# Facebook
|
||||||
|
config :ueberauth, Ueberauth.Strategy.Facebook.OAuth,
|
||||||
|
client_id: System.get_env("FACEBOOK_APP_ID"),
|
||||||
|
client_secret: System.get_env("FACEBOOK_APP_SECRET"),
|
||||||
|
redirect_uri: System.get_env("FACEBOOK_REDIRECT_URI")
|
||||||
|
|
||||||
|
# Google
|
||||||
|
config :ueberauth, Ueberauth.Strategy.Google.OAuth,
|
||||||
|
client_id: System.get_env("GOOGLE_CLIENT_ID"),
|
||||||
|
client_secret: System.get_env("GOOGLE_CLIENT_SECRET"),
|
||||||
|
redirect_uri: System.get_env("GOOGLE_REDIRECT_URI")
|
||||||
|
|
||||||
|
# Microsoft
|
||||||
|
config :ueberauth, Ueberauth.Strategy.Microsoft.OAuth,
|
||||||
|
client_id: System.get_env("MICROSOFT_CLIENT_ID"),
|
||||||
|
client_secret: System.get_env("MICROSOFT_CLIENT_SECRET")
|
||||||
|
|
||||||
|
config :ueberauth, Ueberauth,
|
||||||
|
providers: [
|
||||||
|
microsoft: {Ueberauth.Strategy.Microsoft, [callback_params: []]}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
17
docs/config/General-tips-for-customizing-Pleroma-FE.md
Normal file
17
docs/config/General-tips-for-customizing-Pleroma-FE.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# General tips for customizing Pleroma FE
|
||||||
|
There are some configuration scripts for Pleroma BE and FE:
|
||||||
|
|
||||||
|
1. `config/prod.secret.exs`
|
||||||
|
1. `config/config.exs`
|
||||||
|
1. `priv/static/static/config.json`
|
||||||
|
|
||||||
|
The `prod.secret.exs` affects first. `config.exs` is for fallback or default. `config.json` is for GNU-social-BE-Pleroma-FE instances.
|
||||||
|
|
||||||
|
Usually all you have to do is:
|
||||||
|
|
||||||
|
1. Copy the section in the `config/config.exs` which you want to activate.
|
||||||
|
1. Paste into `config/prod.secret.exs`.
|
||||||
|
1. Edit `config/prod.secret.exs`.
|
||||||
|
1. Restart the Pleroma daemon.
|
||||||
|
|
||||||
|
`prod.secret.exs` is for the `MIX_ENV=prod` environment. `dev.secret.exs` is for the `MIX_ENV=dev` environment respectively.
|
53
docs/config/custom_emoji.md
Normal file
53
docs/config/custom_emoji.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Custom Emoji
|
||||||
|
|
||||||
|
To add custom emoji:
|
||||||
|
* Add the image file(s) to `priv/static/emoji/custom`
|
||||||
|
* In case of conflicts: add the desired shortcode with the path to `config/custom_emoji.txt`, comma-separated and one per line
|
||||||
|
* Force recompilation (``mix clean && mix compile``)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
image files (in `/priv/static/emoji/custom`): `happy.png` and `sad.png`
|
||||||
|
|
||||||
|
content of `config/custom_emoji.txt`:
|
||||||
|
```
|
||||||
|
happy, /emoji/custom/happy.png, Tag1,Tag2
|
||||||
|
sad, /emoji/custom/sad.png, Tag1
|
||||||
|
foo, /emoji/custom/foo.png
|
||||||
|
```
|
||||||
|
|
||||||
|
The files should be PNG (APNG is okay with `.png` for `image/png` Content-type) and under 50kb for compatibility with mastodon.
|
||||||
|
|
||||||
|
## Emoji tags (groups)
|
||||||
|
|
||||||
|
Default tags are set in `config.exs`.
|
||||||
|
```elixir
|
||||||
|
config :pleroma, :emoji,
|
||||||
|
shortcode_globs: ["/emoji/custom/**/*.png"],
|
||||||
|
groups: [
|
||||||
|
Finmoji: "/finmoji/128px/*-128.png",
|
||||||
|
Custom: ["/emoji/*.png", "/emoji/custom/*.png"]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Order of the `groups` matters, so to override default tags just put your group on top of the list. E.g:
|
||||||
|
```elixir
|
||||||
|
config :pleroma, :emoji,
|
||||||
|
shortcode_globs: ["/emoji/custom/**/*.png"],
|
||||||
|
groups: [
|
||||||
|
"Finmoji special": "/finmoji/128px/a_trusted_friend-128.png", # special file
|
||||||
|
"Cirno": "/emoji/custom/cirno*.png", # png files in /emoji/custom/ which start with `cirno`
|
||||||
|
"Special group": "/emoji/custom/special_folder/*.png", # png files in /emoji/custom/special_folder/
|
||||||
|
"Another group": "/emoji/custom/special_folder/*/.png", # png files in /emoji/custom/special_folder/ subfolders
|
||||||
|
Finmoji: "/finmoji/128px/*-128.png",
|
||||||
|
Custom: ["/emoji/*.png", "/emoji/custom/*.png"]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Priority of tags assigns in emoji.txt and custom.txt:
|
||||||
|
|
||||||
|
`tag in file > special group setting in config.exs > default setting in config.exs`
|
||||||
|
|
||||||
|
Priority for globs:
|
||||||
|
|
||||||
|
`special group setting in config.exs > default setting in config.exs`
|
103
docs/config/hardening.md
Normal file
103
docs/config/hardening.md
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# Hardening your instance
|
||||||
|
Here are some suggestions which improve the security of parts of your Pleroma instance.
|
||||||
|
|
||||||
|
## Configuration file
|
||||||
|
|
||||||
|
These changes should go into `prod.secret.exs` or `dev.secret.exs`, depending on your `MIX_ENV` value.
|
||||||
|
|
||||||
|
### `http`
|
||||||
|
|
||||||
|
> Recommended value: `[ip: {127, 0, 0, 1}]`
|
||||||
|
|
||||||
|
This sets the Pleroma application server to only listen to the localhost interface. This way, you can only reach your server over the Internet by going through the reverse proxy. By default, Pleroma listens on all interfaces.
|
||||||
|
|
||||||
|
### `secure_cookie_flag`
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
This sets the `secure` flag on Pleroma’s session cookie. This makes sure, that the cookie is only accepted over encrypted HTTPs connections. This implicitly renames the cookie from `pleroma_key` to `__Host-pleroma-key` which enforces some restrictions. (see [cookie prefixes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Cookie_prefixes))
|
||||||
|
|
||||||
|
### `:http_security`
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
This will send additional HTTP security headers to the clients, including:
|
||||||
|
|
||||||
|
* `X-XSS-Protection: "1; mode=block"`
|
||||||
|
* `X-Permitted-Cross-Domain-Policies: "none"`
|
||||||
|
* `X-Frame-Options: "DENY"`
|
||||||
|
* `X-Content-Type-Options: "nosniff"`
|
||||||
|
* `X-Download-Options: "noopen"`
|
||||||
|
|
||||||
|
A content security policy (CSP) will also be set:
|
||||||
|
|
||||||
|
```csp
|
||||||
|
content-security-policy:
|
||||||
|
default-src 'none';
|
||||||
|
base-uri 'self';
|
||||||
|
frame-ancestors 'none';
|
||||||
|
img-src 'self' data: https:;
|
||||||
|
media-src 'self' https:;
|
||||||
|
style-src 'self' 'unsafe-inline';
|
||||||
|
font-src 'self';
|
||||||
|
script-src 'self';
|
||||||
|
connect-src 'self' wss://example.tld;
|
||||||
|
manifest-src 'self';
|
||||||
|
upgrade-insecure-requests;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `sts`
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
An additional “Strict transport security” header will be sent with the configured `sts_max_age` parameter. This tells the browser, that the domain should only be accessed over a secure HTTPs connection.
|
||||||
|
|
||||||
|
#### `ct_max_age`
|
||||||
|
|
||||||
|
An additional “Expect-CT” header will be sent with the configured `ct_max_age` parameter. This enforces the use of TLS certificates that are published in the certificate transparency log. (see [Expect-CT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT))
|
||||||
|
|
||||||
|
#### `referrer_policy`
|
||||||
|
|
||||||
|
> Recommended value: `same-origin`
|
||||||
|
|
||||||
|
If you click on a link, your browser’s request to the other site will include from where it is coming from. The “Referrer policy” header tells the browser how and if it should send this information. (see [Referrer policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy))
|
||||||
|
|
||||||
|
## systemd
|
||||||
|
|
||||||
|
A systemd unit example is provided at `installation/pleroma.service`.
|
||||||
|
|
||||||
|
### PrivateTmp
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
Use private `/tmp` and `/var/tmp` folders inside a new file system namespace, which are discarded after the process stops.
|
||||||
|
|
||||||
|
### ProtectHome
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
The `/home`, `/root`, and `/run/user` folders can not be accessed by this service anymore. If your Pleroma user has its home folder in one of the restricted places, or use one of these folders as its working directory, you have to set this to `false`.
|
||||||
|
|
||||||
|
### ProtectSystem
|
||||||
|
|
||||||
|
> Recommended value: `full`
|
||||||
|
|
||||||
|
Mount `/usr`, `/boot`, and `/etc` as read-only for processes invoked by this service.
|
||||||
|
|
||||||
|
### PrivateDevices
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
Sets up a new `/dev` mount for the process and only adds API pseudo devices like `/dev/null`, `/dev/zero` or `/dev/random` but not physical devices. This may not work on devices like the Raspberry Pi, where you need to set this to `false`.
|
||||||
|
|
||||||
|
### NoNewPrivileges
|
||||||
|
|
||||||
|
> Recommended value: `true`
|
||||||
|
|
||||||
|
Ensures that the service process and all its children can never gain new privileges through `execve()`.
|
||||||
|
|
||||||
|
### CapabilityBoundingSet
|
||||||
|
|
||||||
|
> Recommended value: `~CAP_SYS_ADMIN`
|
||||||
|
|
||||||
|
Drops the sysadmin capability from the daemon.
|
32
docs/config/howto_mediaproxy.md
Normal file
32
docs/config/howto_mediaproxy.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# How to activate mediaproxy
|
||||||
|
## Explanation
|
||||||
|
|
||||||
|
Without the `mediaproxy` function, Pleroma don't store any remote content like pictures, video etc. locally. So every time you open Pleroma, the content is loaded from the source server, from where the post is coming. This can result in slowly loading content or/and increased bandwidth usage on the source server.
|
||||||
|
With the `mediaproxy` function you can use the cache ability of nginx, to cache these content, so user can access it faster, cause it's loaded from your server.
|
||||||
|
|
||||||
|
## Activate it
|
||||||
|
|
||||||
|
* Edit your nginx config and add the following location:
|
||||||
|
```
|
||||||
|
location /proxy {
|
||||||
|
proxy_cache pleroma_media_cache;
|
||||||
|
proxy_cache_lock on;
|
||||||
|
proxy_pass http://localhost:4000;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Also add the following on top of the configuration, outside of the `server` block:
|
||||||
|
```
|
||||||
|
proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g inactive=720m use_temp_path=off;
|
||||||
|
```
|
||||||
|
If you came here from one of the installation guides, take a look at the example configuration `/installation/pleroma.nginx`, where this part is already included.
|
||||||
|
|
||||||
|
* Append the following to your `prod.secret.exs` or `dev.secret.exs` (depends on which mode your instance is running):
|
||||||
|
```
|
||||||
|
config :pleroma, :media_proxy,
|
||||||
|
enabled: true,
|
||||||
|
redirect_on_failure: true
|
||||||
|
#base_url: "https://cache.pleroma.social"
|
||||||
|
```
|
||||||
|
If you want to use a subdomain to serve the files, uncomment `base_url`, change the url and add a comma after `true` in the previous line.
|
||||||
|
|
||||||
|
* Restart nginx and Pleroma
|
12
docs/config/howto_proxy.md
Normal file
12
docs/config/howto_proxy.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# How to configure upstream proxy for federation
|
||||||
|
If you want to proxify all http requests (e.g. for TOR) that pleroma makes to an upstream proxy server, edit you config file (`dev.secret.exs` or `prod.secret.exs`) and add the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
config :pleroma, :http,
|
||||||
|
proxy_url: "127.0.0.1:8123"
|
||||||
|
```
|
||||||
|
|
||||||
|
The other way to do it, for example, with Tor you would most likely add something like this:
|
||||||
|
```
|
||||||
|
config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}
|
||||||
|
```
|
31
docs/config/howto_user_recomendation.md
Normal file
31
docs/config/howto_user_recomendation.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# How to activate user recommendation (Who to follow panel)
|
||||||
|
![who-to-follow-panel-small](/uploads/9de1b1300436c32461d272945f1bc23e/who-to-follow-panel-small.png)
|
||||||
|
|
||||||
|
To show the *who to follow* panel, edit `config/prod.secret.exs` in the Pleroma backend. Following code activates the *who to follow* panel:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
config :pleroma, :suggestions,
|
||||||
|
enabled: true,
|
||||||
|
third_party_engine:
|
||||||
|
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
|
||||||
|
timeout: 300_000,
|
||||||
|
limit: 23,
|
||||||
|
web: "https://vinayaka.distsn.org/?{{host}}+{{user}}"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
`config/config.exs` already includes this code, but `enabled:` is `false`.
|
||||||
|
|
||||||
|
`/api/v1/suggestions` is also provided when *who to follow* panel is enabled.
|
||||||
|
|
||||||
|
For advanced customization, following code shows the newcomers of the fediverse at the *who to follow* panel:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
config :pleroma, :suggestions,
|
||||||
|
enabled: true,
|
||||||
|
third_party_engine:
|
||||||
|
"http://vinayaka.distsn.org/cgi-bin/vinayaka-user-new-suggestions-api.cgi?{{host}}+{{user}}",
|
||||||
|
timeout: 60_000,
|
||||||
|
limit: 23,
|
||||||
|
web: "https://vinayaka.distsn.org/user-new.html"
|
||||||
|
```
|
196
docs/config/i2p.md
Normal file
196
docs/config/i2p.md
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
# I2P Federation and Accessability
|
||||||
|
|
||||||
|
This guide is going to focus on the Pleroma federation aspect. The actual installation is neatly explained in the official documentation, and more likely to remain up-to-date.
|
||||||
|
It might be added to this guide if there will be a need for that.
|
||||||
|
|
||||||
|
We're going to use I2PD for its lightweightness over the official client.
|
||||||
|
Follow the documentation according to your distro: https://i2pd.readthedocs.io/en/latest/user-guide/install/#installing
|
||||||
|
|
||||||
|
How to run it: https://i2pd.readthedocs.io/en/latest/user-guide/run/
|
||||||
|
|
||||||
|
## I2P Federation
|
||||||
|
|
||||||
|
There are 2 ways to go about this.
|
||||||
|
One using the config, and one using external software (fedproxy). The external software works better so far.
|
||||||
|
|
||||||
|
### Using the Config
|
||||||
|
|
||||||
|
**Warning:** So far, everytime I followed this way of federating using I2P, the rest of my federation stopped working. I'm leaving this here in case it will help with making it work.
|
||||||
|
|
||||||
|
Assuming you're running in prod, cd to your Pleroma folder and append the following to `config/prod.secret.exs`:
|
||||||
|
```
|
||||||
|
config :pleroma, :http, proxy_url: {:socks5, :localhost, 4447}
|
||||||
|
```
|
||||||
|
And then run the following:
|
||||||
|
```
|
||||||
|
su pleroma
|
||||||
|
MIX_ENV=prod mix deps.get
|
||||||
|
MIX_ENV=prod mix ecto.migrate
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
You can restart I2PD here and finish if you don't wish to make your instance viewable or accessible over I2P.
|
||||||
|
```
|
||||||
|
systemctl stop i2pd.service --no-block
|
||||||
|
systemctl start i2pd.service
|
||||||
|
```
|
||||||
|
*Notice:* The stop command initiates a graceful shutdown process, i2pd stops after finishing to route transit tunnels (maximum 10 minutes).
|
||||||
|
|
||||||
|
You can change the socks proxy port in `/etc/i2pd/i2pd.conf`.
|
||||||
|
|
||||||
|
### Using Fedproxy
|
||||||
|
|
||||||
|
Fedproxy passes through clearnet requests direct to where they are going. It doesn't force anything over Tor.
|
||||||
|
|
||||||
|
To use [fedproxy](https://github.com/majestrate/fedproxy) you'll need to install Golang.
|
||||||
|
```
|
||||||
|
apt install golang
|
||||||
|
```
|
||||||
|
Use a different user than pleroma or root. Run the following to add the Gopath to your ~/.bashrc.
|
||||||
|
```
|
||||||
|
echo "export GOPATH=/home/ren/.go" >> ~/.bashrc
|
||||||
|
```
|
||||||
|
Restart that bash session (you can exit and log back in).
|
||||||
|
Run the following to get fedproxy.
|
||||||
|
```
|
||||||
|
go get -u github.com/majestrate/fedproxy$
|
||||||
|
cp $(GOPATH)/bin/fedproxy /usr/local/bin/fedproxy
|
||||||
|
```
|
||||||
|
And then the following to start it for I2P only.
|
||||||
|
```
|
||||||
|
fedproxy 127.0.0.1:2000 127.0.0.1:4447
|
||||||
|
```
|
||||||
|
If you want to also use it for Tor, add `127.0.0.1:9050` to that command.
|
||||||
|
You'll also need to modify your Pleroma config.
|
||||||
|
|
||||||
|
Assuming you're running in prod, cd to your Pleroma folder and append the following to `config/prod.secret.exs`:
|
||||||
|
```
|
||||||
|
config :pleroma, :http, proxy_url: {:socks5, :localhost, 2000}
|
||||||
|
```
|
||||||
|
And then run the following:
|
||||||
|
```
|
||||||
|
su pleroma
|
||||||
|
MIX_ENV=prod mix deps.get
|
||||||
|
MIX_ENV=prod mix ecto.migrate
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
You can restart I2PD here and finish if you don't wish to make your instance viewable or accessible over I2P.
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl stop i2pd.service --no-block
|
||||||
|
systemctl start i2pd.service
|
||||||
|
```
|
||||||
|
*Notice:* The stop command initiates a graceful shutdown process, i2pd stops after finishing to route transit tunnels (maximum 10 minutes).
|
||||||
|
|
||||||
|
You can change the socks proxy port in `/etc/i2pd/i2pd.conf`.
|
||||||
|
|
||||||
|
## I2P Instance Access
|
||||||
|
|
||||||
|
Make your instance accessible using I2P.
|
||||||
|
|
||||||
|
Add the following to your I2PD config `/etc/i2pd/tunnels.conf`:
|
||||||
|
```
|
||||||
|
[pleroma]
|
||||||
|
type = http
|
||||||
|
host = 127.0.0.1
|
||||||
|
port = 14447
|
||||||
|
keys = pleroma.dat
|
||||||
|
```
|
||||||
|
Restart I2PD:
|
||||||
|
```
|
||||||
|
systemctl stop i2pd.service --no-block
|
||||||
|
systemctl start i2pd.service
|
||||||
|
```
|
||||||
|
*Notice:* The stop command initiates a graceful shutdown process, i2pd stops after finishing to route transit tunnels (maximum 10 minutes).
|
||||||
|
|
||||||
|
Now you'll have to find your address.
|
||||||
|
To do that you can download and use I2PD tools.[^1]
|
||||||
|
Or you'll need to access your web-console on localhost:7070.
|
||||||
|
If you don't have a GUI, you'll have to SSH tunnel into it like this:
|
||||||
|
`ssh -L 7070:127.0.0.1:7070 user@ip -p port`.
|
||||||
|
Now you can access it at localhost:7070.
|
||||||
|
Go to I2P tunnels page. Look for Server tunnels and you will see an address that ends with `.b32.i2p` next to "pleroma".
|
||||||
|
This is your site's address.
|
||||||
|
|
||||||
|
### I2P-only Instance
|
||||||
|
|
||||||
|
If creating an I2P-only instance, open `config/prod.secret.exs` and under "config :pleroma, Pleroma.Web.Endpoint," edit "https" and "port: 443" to the following:
|
||||||
|
```
|
||||||
|
url: [host: "i2paddress", scheme: "http", port: 80],
|
||||||
|
```
|
||||||
|
In addition to that, replace the existing nginx config's contents with the example below.
|
||||||
|
|
||||||
|
### Existing Instance (Clearnet Instance)
|
||||||
|
|
||||||
|
If not an I2P-only instance, add the nginx config below to your existing config at `/etc/nginx/sites-enabled/pleroma.nginx`.
|
||||||
|
|
||||||
|
And for both cases, disable CSP in Pleroma's config (STS is disabled by default) so you can define those yourself seperately from the clearnet (if your instance is also on the clearnet).
|
||||||
|
Copy the following into the `config/prod.secret.exs` in your Pleroma folder (/home/pleroma/pleroma/):
|
||||||
|
```
|
||||||
|
config :pleroma, :http_security,
|
||||||
|
enabled: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Use this as the Nginx config:
|
||||||
|
```
|
||||||
|
proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g inactive=720m use_temp_path=off;
|
||||||
|
# The above already exists in a clearnet instance's config.
|
||||||
|
# If not, add it.
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 127.0.0.1:14447;
|
||||||
|
server_name youri2paddress;
|
||||||
|
|
||||||
|
# Comment to enable logs
|
||||||
|
access_log /dev/null;
|
||||||
|
error_log /dev/null;
|
||||||
|
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_buffers 16 8k;
|
||||||
|
gzip_http_version 1.1;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
|
||||||
|
|
||||||
|
client_max_body_size 16m;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header X-Permitted-Cross-Domain-Policies none;
|
||||||
|
add_header X-Frame-Options DENY;
|
||||||
|
add_header X-Content-Type-Options nosniff;
|
||||||
|
add_header Referrer-Policy same-origin;
|
||||||
|
add_header X-Download-Options noopen;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
|
||||||
|
proxy_pass http://localhost:4000;
|
||||||
|
|
||||||
|
client_max_body_size 16m;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /proxy {
|
||||||
|
proxy_cache pleroma_media_cache;
|
||||||
|
proxy_cache_lock on;
|
||||||
|
proxy_ignore_client_abort on;
|
||||||
|
proxy_pass http://localhost:4000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
reload Nginx:
|
||||||
|
```
|
||||||
|
systemctl stop i2pd.service --no-block
|
||||||
|
systemctl start i2pd.service
|
||||||
|
```
|
||||||
|
*Notice:* The stop command initiates a graceful shutdown process, i2pd stops after finishing to route transit tunnels (maximum 10 minutes).
|
||||||
|
|
||||||
|
You should now be able to both access your instance using I2P and federate with other I2P instances!
|
||||||
|
|
||||||
|
[^1]: [I2PD tools](https://github.com/purplei2p/i2pd-tools) to print information about a router info file or an I2P private key, generate an I2P private key, and generate vanity addresses.
|
||||||
|
|
||||||
|
### Possible Issues
|
||||||
|
|
||||||
|
Will be added when encountered.
|
119
docs/config/mrf.md
Normal file
119
docs/config/mrf.md
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
# Message Rewrite Facility
|
||||||
|
The Message Rewrite Facility (MRF) is a subsystem that is implemented as a series of hooks that allows the administrator to rewrite or discard messages.
|
||||||
|
|
||||||
|
Possible uses include:
|
||||||
|
|
||||||
|
* marking incoming messages with media from a given account or instance as sensitive
|
||||||
|
* rejecting messages from a specific instance
|
||||||
|
* removing/unlisting messages from the public timelines
|
||||||
|
* removing media from messages
|
||||||
|
* sending only public messages to a specific instance
|
||||||
|
|
||||||
|
The MRF provides user-configurable policies. The default policy is `NoOpPolicy`, which disables the MRF functionality. Pleroma also includes an easy to use policy called `SimplePolicy` which maps messages matching certain pre-defined criterion to actions built into the policy module.
|
||||||
|
It is possible to use multiple, active MRF policies at the same time.
|
||||||
|
|
||||||
|
## Quarantine Instances
|
||||||
|
|
||||||
|
You have the ability to prevent from private / followers-only messages from federating with specific instances. Which means they will only get the public or unlisted messages from your instance.
|
||||||
|
|
||||||
|
If, for example, you're using `MIX_ENV=prod` aka using production mode, you would open your configuration file located in `config/prod.secret.exs` and edit or add the option under your `:instance` config object. Then you would specify the instance within quotes.
|
||||||
|
```
|
||||||
|
config :pleroma, :instance,
|
||||||
|
[...]
|
||||||
|
quarantined_instances: ["instance.example", "other.example"]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using `SimplePolicy`
|
||||||
|
|
||||||
|
`SimplePolicy` is capable of handling most common admin tasks.
|
||||||
|
|
||||||
|
To use `SimplePolicy`, you must enable it. Do so by adding the following to your `:instance` config object, so that it looks like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
config :pleroma, :instance,
|
||||||
|
[...]
|
||||||
|
rewrite_policy: Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||||
|
```
|
||||||
|
|
||||||
|
Once `SimplePolicy` is enabled, you can configure various groups in the `:mrf_simple` config object. These groups are:
|
||||||
|
|
||||||
|
* `media_removal`: Servers in this group will have media stripped from incoming messages.
|
||||||
|
* `media_nsfw`: Servers in this group will have the #nsfw tag and sensitive setting injected into incoming messages which contain media.
|
||||||
|
* `reject`: Servers in this group will have their messages rejected.
|
||||||
|
* `federated_timeline_removal`: Servers in this group will have their messages unlisted from the public timelines by flipping the `to` and `cc` fields.
|
||||||
|
|
||||||
|
Servers should be configured as lists.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
This example will enable `SimplePolicy`, block media from `illegalporn.biz`, mark media as NSFW from `porn.biz` and `porn.business`, reject messages from `spam.com` and remove messages from `spam.university` from the federated timeline:
|
||||||
|
|
||||||
|
```
|
||||||
|
config :pleroma, :instance,
|
||||||
|
rewrite_policy: [Pleroma.Web.ActivityPub.MRF.SimplePolicy]
|
||||||
|
|
||||||
|
config :pleroma, :mrf_simple,
|
||||||
|
media_removal: ["illegalporn.biz"],
|
||||||
|
media_nsfw: ["porn.biz", "porn.business"],
|
||||||
|
reject: ["spam.com"],
|
||||||
|
federated_timeline_removal: ["spam.university"]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use with Care
|
||||||
|
|
||||||
|
The effects of MRF policies can be very drastic. It is important to use this functionality carefully. Always try to talk to an admin before writing an MRF policy concerning their instance.
|
||||||
|
|
||||||
|
## Writing your own MRF Policy
|
||||||
|
|
||||||
|
As discussed above, the MRF system is a modular system that supports pluggable policies. This means that an admin may write a custom MRF policy in Elixir or any other language that runs on the Erlang VM, by specifying the module name in the `rewrite_policy` config setting.
|
||||||
|
|
||||||
|
For example, here is a sample policy module which rewrites all messages to "new message content":
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# This is a sample MRF policy which rewrites all Notes to have "new message
|
||||||
|
# content."
|
||||||
|
defmodule Site.RewritePolicy do
|
||||||
|
@behavior Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
|
# Catch messages which contain Note objects with actual data to filter.
|
||||||
|
# Capture the object as `object`, the message content as `content` and the
|
||||||
|
# message itself as `message`.
|
||||||
|
@impl true
|
||||||
|
def filter(%{"type" => Create", "object" => {"type" => "Note", "content" => content} = object} = message)
|
||||||
|
when is_binary(content) do
|
||||||
|
# Subject / CW is stored as summary instead of `name` like other AS2 objects
|
||||||
|
# because of Mastodon doing it that way.
|
||||||
|
summary = object["summary"]
|
||||||
|
|
||||||
|
# Message edits go here.
|
||||||
|
content = "new message content"
|
||||||
|
|
||||||
|
# Assemble the mutated object.
|
||||||
|
object =
|
||||||
|
object
|
||||||
|
|> Map.put("content", content)
|
||||||
|
|> Map.put("summary", summary)
|
||||||
|
|
||||||
|
# Assemble the mutated message.
|
||||||
|
message = Map.put(message, "object", object)
|
||||||
|
{:ok, message}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Let all other messages through without modifying them.
|
||||||
|
@impl true
|
||||||
|
def filter(message), do: {:ok, message}
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you save this file as `lib/site/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
config :pleroma, :instance,
|
||||||
|
rewrite_policy: [
|
||||||
|
Pleroma.Web.ActivityPub.MRF.SimplePolicy,
|
||||||
|
Site.RewritePolicy
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Please note that the Pleroma developers consider custom MRF policy modules to fall under the purview of the AGPL. As such, you are obligated to release the sources to your custom MRF policy modules upon request.
|
159
docs/config/onion_federation.md
Normal file
159
docs/config/onion_federation.md
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
# Easy Onion Federation (Tor)
|
||||||
|
Tor can free people from the necessity of a domain, in addition to helping protect their privacy. As Pleroma's goal is to empower the people and let as many as possible host an instance with as little resources as possible, the ability to host an instance with a small, cheap computer like a RaspberryPi along with Tor, would be a great way to achieve that.
|
||||||
|
In addition, federating with such instances will also help furthering that goal.
|
||||||
|
|
||||||
|
This is a guide to show you how it can be easily done.
|
||||||
|
|
||||||
|
This guide assumes you already got Pleroma working, and that it's running on the default port 4000.
|
||||||
|
Currently only has an Nginx example.
|
||||||
|
|
||||||
|
To install Tor on Debian / Ubuntu:
|
||||||
|
```
|
||||||
|
apt -yq install tor
|
||||||
|
```
|
||||||
|
If using an old server version (older than Debian Stretch or Ubuntu 18.04), install from backports or PPA.
|
||||||
|
I recommend using a newer server version instead.
|
||||||
|
|
||||||
|
To have the newest, V3 onion addresses (which I recommend) in Debian, install Tor from backports.
|
||||||
|
If you do not have backports, uncomment the stretch-backports links at the end of `/etc/apt/sources.list`.
|
||||||
|
Then install:
|
||||||
|
```
|
||||||
|
apt update
|
||||||
|
apt -t stretch-backports -yq install tor
|
||||||
|
```
|
||||||
|
**WARNING:** Onion instances not using a Tor version supporting V3 addresses will not be able to federate with you.
|
||||||
|
|
||||||
|
Create the hidden service for your Pleroma instance in `/etc/tor/torrc`:
|
||||||
|
```
|
||||||
|
HiddenServiceDir /var/lib/tor/pleroma_hidden_service/
|
||||||
|
HiddenServicePort 80 127.0.0.1:8099
|
||||||
|
HiddenServiceVersion 3 # Remove if Tor version is below 0.3 ( tor --version )
|
||||||
|
```
|
||||||
|
Restart Tor to generate an adress:
|
||||||
|
```
|
||||||
|
systemctl restart tor@default.service
|
||||||
|
```
|
||||||
|
Get the address:
|
||||||
|
```
|
||||||
|
cat /var/lib/tor/pleroma_hidden_service/hostname
|
||||||
|
```
|
||||||
|
|
||||||
|
# Federation
|
||||||
|
|
||||||
|
Next, edit your Pleroma config.
|
||||||
|
If running in prod, cd to your Pleroma directory, edit `config/prod.secret.exs`
|
||||||
|
and append this line:
|
||||||
|
```
|
||||||
|
config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}
|
||||||
|
```
|
||||||
|
In your Pleroma directory, assuming you're running prod,
|
||||||
|
run the following:
|
||||||
|
```
|
||||||
|
su pleroma
|
||||||
|
MIX_ENV=prod mix deps.get
|
||||||
|
MIX_ENV=prod mix ecto.migrate
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
restart Pleroma (if using systemd):
|
||||||
|
```
|
||||||
|
systemctl restart pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
# Tor Instance Access
|
||||||
|
|
||||||
|
Make your instance accessible using Tor.
|
||||||
|
|
||||||
|
## Tor-only Instance
|
||||||
|
If creating a Tor-only instance, open `config/prod.secret.exs` and under "config :pleroma, Pleroma.Web.Endpoint," edit "https" and "port: 443" to the following:
|
||||||
|
```
|
||||||
|
url: [host: "onionaddress", scheme: "http", port: 80],
|
||||||
|
```
|
||||||
|
In addition to that, replace the existing nginx config's contents with the example below.
|
||||||
|
|
||||||
|
## Existing Instance (Clearnet Instance)
|
||||||
|
If not a Tor-only instance,
|
||||||
|
add the nginx config below to your existing config at `/etc/nginx/sites-enabled/pleroma.nginx`.
|
||||||
|
|
||||||
|
---
|
||||||
|
For both cases, disable CSP in Pleroma's config (STS is disabled by default) so you can define those yourself seperately from the clearnet (if your instance is also on the clearnet).
|
||||||
|
Copy the following into the `config/prod.secret.exs` in your Pleroma folder (/home/pleroma/pleroma/):
|
||||||
|
```
|
||||||
|
config :pleroma, :http_security,
|
||||||
|
enabled: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Use this as the Nginx config:
|
||||||
|
```
|
||||||
|
proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g inactive=720m use_temp_path=off;
|
||||||
|
# The above already exists in a clearnet instance's config.
|
||||||
|
# If not, add it.
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 127.0.0.1:8099;
|
||||||
|
server_name youronionaddress;
|
||||||
|
|
||||||
|
# Comment to enable logs
|
||||||
|
access_log /dev/null;
|
||||||
|
error_log /dev/null;
|
||||||
|
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_buffers 16 8k;
|
||||||
|
gzip_http_version 1.1;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
|
||||||
|
|
||||||
|
client_max_body_size 16m;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header X-Permitted-Cross-Domain-Policies none;
|
||||||
|
add_header X-Frame-Options DENY;
|
||||||
|
add_header X-Content-Type-Options nosniff;
|
||||||
|
add_header Referrer-Policy same-origin;
|
||||||
|
add_header X-Download-Options noopen;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
|
||||||
|
proxy_pass http://localhost:4000;
|
||||||
|
|
||||||
|
client_max_body_size 16m;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /proxy {
|
||||||
|
proxy_cache pleroma_media_cache;
|
||||||
|
proxy_cache_lock on;
|
||||||
|
proxy_ignore_client_abort on;
|
||||||
|
proxy_pass http://localhost:4000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
reload Nginx:
|
||||||
|
```
|
||||||
|
systemctl reload nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
You should now be able to both access your instance using Tor and federate with other Tor instances!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Possible Issues
|
||||||
|
|
||||||
|
* In Debian, make sure your hidden service folder `/var/lib/tor/pleroma_hidden_service/` and its contents, has debian-tor as both owner and group by using
|
||||||
|
```
|
||||||
|
ls -la /var/lib/tor/
|
||||||
|
```
|
||||||
|
If it's not, run:
|
||||||
|
```
|
||||||
|
chown -R debian-tor:debian-tor /var/lib/tor/pleroma_hidden_service/
|
||||||
|
```
|
||||||
|
* Make sure *only* the owner has *only* read and write permissions.
|
||||||
|
If not, run:
|
||||||
|
```
|
||||||
|
chmod -R 600 /var/lib/tor/pleroma_hidden_service/
|
||||||
|
```
|
||||||
|
* If you have trouble logging in to the Mastodon Frontend when using Tor, use the Tor Browser Bundle.
|
35
docs/config/small_customizations.md
Normal file
35
docs/config/small_customizations.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Small customizations
|
||||||
|
Replace `dev.secret.exs` with `prod.secret.exs` according to your setup.
|
||||||
|
|
||||||
|
# Thumbnail
|
||||||
|
|
||||||
|
Replace `priv/static/instance/thumbnail.jpeg` with your selfie or other neat picture. It will appear in [Pleroma Instances](http://distsn.org/pleroma-instances.html).
|
||||||
|
|
||||||
|
# Instance-specific panel
|
||||||
|
|
||||||
|
![instance-specific panel demo](/uploads/296b19ec806b130e0b49b16bfe29ce8a/image.png)
|
||||||
|
|
||||||
|
To show the instance specific panel, set `show_instance_panel` to `true` in `config/dev.secret.exs`. You can modify its content by editing `priv/static/instance/panel.html`.
|
||||||
|
|
||||||
|
# Background
|
||||||
|
|
||||||
|
You can change the background of your Pleroma instance by uploading it to `priv/static/static`, and then changing `"background"` in `config/dev.secret.exs` accordingly.
|
||||||
|
|
||||||
|
# Logo
|
||||||
|
|
||||||
|
![logo modification demo](/uploads/c70b14de60fa74245e7f0dcfa695ebff/image.png)
|
||||||
|
|
||||||
|
If you want to give a brand to your instance, look no further. You can change the logo of your instance by uploading it to `priv/static/static`, and then changing `logo` in `config/dev.secret.exs` accordingly.
|
||||||
|
|
||||||
|
# Theme
|
||||||
|
|
||||||
|
All users of your instance will be able to change the theme they use by going to the settings (the cog in the top-right hand corner). However, if you wish to change the default theme, you can do so by editing `theme` in `config/dev.secret.exs` accordingly.
|
||||||
|
|
||||||
|
# Terms of Service
|
||||||
|
|
||||||
|
Terms of Service will be shown to all users on the registration page. It's the best place where to write down the rules for your instance. You can modify the rules by changing `priv/static/static/terms-of-service.html`.
|
||||||
|
|
||||||
|
# Message Visibility
|
||||||
|
|
||||||
|
To enable message visibility options when posting like in the Mastodon frontend, set
|
||||||
|
`scope_options_enabled` to `true` in `config/dev.secret.exs`.
|
20
docs/config/static_dir.md
Normal file
20
docs/config/static_dir.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Static Directory
|
||||||
|
|
||||||
|
Static frontend files are shipped in `priv/static/` and tracked by version control in this repository. If you want to overwrite or update these without the possibility of merge conflicts, you can write your custom versions to `instance/static/`.
|
||||||
|
|
||||||
|
```
|
||||||
|
config :pleroma, :instance,
|
||||||
|
static_dir: "instance/static/",
|
||||||
|
```
|
||||||
|
|
||||||
|
You can overwrite this value in your configuration to use a different static instance directory.
|
||||||
|
|
||||||
|
## robots.txt
|
||||||
|
|
||||||
|
By default, the `robots.txt` that ships in `priv/static/` is permissive. It allows well-behaved search engines to index all of your instance's URIs.
|
||||||
|
|
||||||
|
If you want to generate a restrictive `robots.txt`, you can run the following mix task. The generated `robots.txt` will be written in your instance static directory.
|
||||||
|
|
||||||
|
```
|
||||||
|
mix pleroma.robots_txt disallow_all
|
||||||
|
```
|
215
docs/installation/alpine_linux_en.md
Normal file
215
docs/installation/alpine_linux_en.md
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
# Installing on Alpine Linux
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
This guide is a step-by-step installation guide for Alpine Linux. It also assumes that you have administrative rights, either as root or a user with [sudo permissions](https://www.linode.com/docs/tools-reference/custom-kernels-distros/install-alpine-linux-on-your-linode/#configuration). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su -l <username> -s $SHELL -c 'command'` instead.
|
||||||
|
|
||||||
|
### Required packages
|
||||||
|
|
||||||
|
* `postgresql`
|
||||||
|
* `elixir`
|
||||||
|
* `erlang`
|
||||||
|
* `erlang-parsetools`
|
||||||
|
* `erlang-xmerl`
|
||||||
|
* `git`
|
||||||
|
* Development Tools
|
||||||
|
|
||||||
|
#### Optional packages used in this guide
|
||||||
|
|
||||||
|
* `nginx` (preferred, example configs for other reverse proxies can be found in the repo)
|
||||||
|
* `certbot` (or any other ACME client for Let’s Encrypt certificates)
|
||||||
|
|
||||||
|
### Prepare the system
|
||||||
|
|
||||||
|
* First make sure to have the community repository enabled:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
echo "https://nl.alpinelinux.org/alpine/latest-stable/community" | sudo tee -a /etc/apk/repository
|
||||||
|
```
|
||||||
|
|
||||||
|
* Then update the system, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk update
|
||||||
|
sudo apk upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install some tools, which are needed later:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add git build-base
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install Elixir and Erlang
|
||||||
|
|
||||||
|
* Install Erlang and Elixir:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add erlang erlang-runtime-tools erlang-xmerl elixir
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install `erlang-eldap` if you want to enable ldap authenticator
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add erlang-eldap
|
||||||
|
```
|
||||||
|
### Install PostgreSQL
|
||||||
|
|
||||||
|
* Install Postgresql server:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add postgresql postgresql-contrib
|
||||||
|
```
|
||||||
|
|
||||||
|
* Initialize database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo /etc/init.d/postgresql start
|
||||||
|
```
|
||||||
|
|
||||||
|
* Enable and start postgresql server:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo rc-update add postgresql
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PleromaBE
|
||||||
|
|
||||||
|
* Add a new system user for the Pleroma service:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo adduser -S -s /bin/false -h /opt/pleroma -H pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l pleroma -s $SHELL -c 'command'` and `su -l pleroma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
|
* Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /opt/pleroma
|
||||||
|
sudo chown -R pleroma:pleroma /opt/pleroma
|
||||||
|
sudo -Hu pleroma git clone https://git.pleroma.social/pleroma/pleroma /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Change to the new directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma mix deps.get
|
||||||
|
```
|
||||||
|
|
||||||
|
* Generate the configuration: `sudo -Hu pleroma mix pleroma.instance gen`
|
||||||
|
* Answer with `yes` if it asks you to install `rebar3`.
|
||||||
|
* This may take some time, because parts of pleroma get compiled first.
|
||||||
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
|
* Check the configuration and if all looks right, rename it, so Pleroma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
```
|
||||||
|
|
||||||
|
* The previous command creates also the file `config/setup_db.psql`, with which you can create the database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu postgres psql -f config/setup_db.psql
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now run the database migration:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now you can start Pleroma already
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finalize installation
|
||||||
|
|
||||||
|
If you want to open your newly installed instance to the world, you should run nginx or some other webserver/proxy in front of Pleroma and you should consider to create an OpenRC service file for Pleroma.
|
||||||
|
|
||||||
|
#### Nginx
|
||||||
|
|
||||||
|
* Install nginx, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Setup your SSL cert, using your method of choice or certbot. If using certbot, first install it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apk add certbot
|
||||||
|
```
|
||||||
|
|
||||||
|
and then set it up:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /var/lib/letsencrypt/
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again).
|
||||||
|
|
||||||
|
* Copy the example nginx configuration to the nginx folder
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/conf.d/pleroma.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
* Before starting nginx edit the configuration and change it to your needs (e.g. change servername, change cert paths)
|
||||||
|
* Enable and start nginx:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo rc-update add nginx
|
||||||
|
sudo service nginx start
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need to renew the certificate in the future, uncomment the relevant location block in the nginx config and run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --webroot -w /var/lib/letsencrypt/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### OpenRC service
|
||||||
|
|
||||||
|
* Copy example service file:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/init.d/pleroma /etc/init.d/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Make sure to start it during the boot
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo rc-update add pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create your first user
|
||||||
|
|
||||||
|
If your instance is up and running, you can create your first user with administrative rights with the following task:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Further reading
|
||||||
|
|
||||||
|
* [Admin tasks](Admin tasks)
|
||||||
|
* [Backup your instance](Backup-your-instance)
|
||||||
|
* [Configuration tips](General tips for customizing pleroma fe)
|
||||||
|
* [Hardening your instance](Hardening-your-instance)
|
||||||
|
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||||
|
* [Small Pleroma-FE customizations](Small customizations)
|
||||||
|
* [Updating your instance](Updating-your-instance)
|
||||||
|
|
||||||
|
## Questions
|
||||||
|
|
||||||
|
Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.
|
214
docs/installation/arch_linux_en.md
Normal file
214
docs/installation/arch_linux_en.md
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
# Installing on Arch Linux
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
This guide will assume that you have administrative rights, either as root or a user with [sudo permissions](https://wiki.archlinux.org/index.php/Sudo). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su <username> -s $SHELL -c 'command'` instead.
|
||||||
|
|
||||||
|
### Required packages
|
||||||
|
|
||||||
|
* `postgresql`
|
||||||
|
* `elixir`
|
||||||
|
* `erlang-unixodbc`
|
||||||
|
* `git`
|
||||||
|
* `base-devel`
|
||||||
|
|
||||||
|
#### Optional packages used in this guide
|
||||||
|
|
||||||
|
* `nginx` (preferred, example configs for other reverse proxies can be found in the repo)
|
||||||
|
* `certbot` (or any other ACME client for Let’s Encrypt certificates)
|
||||||
|
|
||||||
|
### Prepare the system
|
||||||
|
|
||||||
|
* First update the system, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo pacman -Syu
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install some of the above mentioned programs:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo pacman -S git base-devel elixir erlang-unixodbc
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PostgreSQL
|
||||||
|
|
||||||
|
[Arch Wiki article](https://wiki.archlinux.org/index.php/PostgreSQL)
|
||||||
|
|
||||||
|
* Install the `postgresql` package:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo pacman -S postgresql
|
||||||
|
```
|
||||||
|
|
||||||
|
* Initialize the database cluster:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -iu postgres initdb -D /var/lib/postgres/data
|
||||||
|
```
|
||||||
|
|
||||||
|
* Start and enable the `postgresql.service`
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now postgresql.service
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PleromaBE
|
||||||
|
|
||||||
|
* Add a new system user for the Pleroma service:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo useradd -r -s /bin/false -m -d /var/lib/pleroma -U pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l pleroma -s $SHELL -c 'command'` and `su -l pleroma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
|
* Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /opt/pleroma
|
||||||
|
sudo chown -R pleroma:pleroma /opt/pleroma
|
||||||
|
sudo -Hu pleroma git clone https://git.pleroma.social/pleroma/pleroma /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Change to the new directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma mix deps.get
|
||||||
|
```
|
||||||
|
|
||||||
|
* Generate the configuration: `sudo -Hu pleroma mix pleroma.instance gen`
|
||||||
|
* Answer with `yes` if it asks you to install `rebar3`.
|
||||||
|
* This may take some time, because parts of pleroma get compiled first.
|
||||||
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
|
* Check the configuration and if all looks right, rename it, so Pleroma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
```
|
||||||
|
|
||||||
|
* The previous command creates also the file `config/setup_db.psql`, with which you can create the database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu postgres psql -f config/setup_db.psql
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now run the database migration:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now you can start Pleroma already
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finalize installation
|
||||||
|
|
||||||
|
If you want to open your newly installed instance to the world, you should run nginx or some other webserver/proxy in front of Pleroma and you should consider to create a systemd service file for Pleroma.
|
||||||
|
|
||||||
|
#### Nginx
|
||||||
|
|
||||||
|
* Install nginx, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo pacman -S nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create directories for available and enabled sites:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /etc/nginx/sites-{available,enabled}
|
||||||
|
```
|
||||||
|
|
||||||
|
* Append the following line at the end of the `http` block in `/etc/nginx/nginx.conf`:
|
||||||
|
|
||||||
|
```Nginx
|
||||||
|
include sites-enabled/*;
|
||||||
|
```
|
||||||
|
|
||||||
|
* Setup your SSL cert, using your method of choice or certbot. If using certbot, first install it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo pacman -S certbot certbot-nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
and then set it up:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /var/lib/letsencrypt/
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* Copy the example nginx configuration and activate it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.nginx
|
||||||
|
sudo ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Before starting nginx edit the configuration and change it to your needs (e.g. change servername, change cert paths)
|
||||||
|
* Enable and start nginx:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now nginx.service
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need to renew the certificate in the future, uncomment the relevant location block in the nginx config and run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --webroot -w /var/lib/letsencrypt/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Other webserver/proxies
|
||||||
|
|
||||||
|
You can find example configurations for them in `/opt/pleroma/installation/`.
|
||||||
|
|
||||||
|
#### Systemd service
|
||||||
|
|
||||||
|
* Copy example service file
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
* Edit the service file and make sure that all paths fit your installation
|
||||||
|
* Enable and start `pleroma.service`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create your first user
|
||||||
|
|
||||||
|
If your instance is up and running, you can create your first user with administrative rights with the following task:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Further reading
|
||||||
|
|
||||||
|
* [Admin tasks](Admin tasks)
|
||||||
|
* [Backup your instance](Backup-your-instance)
|
||||||
|
* [Configuration tips](General tips for customizing pleroma fe)
|
||||||
|
* [Hardening your instance](Hardening-your-instance)
|
||||||
|
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||||
|
* [Small Pleroma-FE customizations](Small customizations)
|
||||||
|
* [Updating your instance](Updating-your-instance)
|
||||||
|
|
||||||
|
## Questions
|
||||||
|
|
||||||
|
Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.
|
277
docs/installation/centos7_en.md
Normal file
277
docs/installation/centos7_en.md
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
# Installing on CentOS 7
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
This guide is a step-by-step installation guide for CentOS 7. It also assumes that you have administrative rights, either as root or a user with [sudo permissions](https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su <username> -s $SHELL -c 'command'` instead.
|
||||||
|
|
||||||
|
### Required packages
|
||||||
|
|
||||||
|
* `postgresql` (9,6+, CentOS 7 comes with 9.2, we will install version 11 in this guide)
|
||||||
|
* `elixir` (1.5+)
|
||||||
|
* `erlang`
|
||||||
|
* `erlang-parsetools`
|
||||||
|
* `erlang-xmerl`
|
||||||
|
* `git`
|
||||||
|
* Development Tools
|
||||||
|
|
||||||
|
#### Optional packages used in this guide
|
||||||
|
|
||||||
|
* `nginx` (preferred, example configs for other reverse proxies can be found in the repo)
|
||||||
|
* `certbot` (or any other ACME client for Let’s Encrypt certificates)
|
||||||
|
|
||||||
|
### Prepare the system
|
||||||
|
|
||||||
|
* First update the system, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum update
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install some of the above mentioned programs:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install wget git unzip
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install development tools:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum group install "Development Tools"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install Elixir and Erlang
|
||||||
|
|
||||||
|
* Add the EPEL repo:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install epel-release
|
||||||
|
sudo yum -y update
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install Erlang repository:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
wget -P /tmp/ https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
|
||||||
|
sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install Erlang:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install erlang erlang-parsetools erlang-xmerl
|
||||||
|
```
|
||||||
|
|
||||||
|
* Download [latest Elixir release from Github](https://github.com/elixir-lang/elixir/releases/tag/v1.8.1) (Example for the newest version at the time when this manual was written)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
wget -P /tmp/ https://github.com/elixir-lang/elixir/releases/download/v1.8.1/Precompiled.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create folder where you want to install Elixir, we’ll use:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /opt/elixir
|
||||||
|
```
|
||||||
|
|
||||||
|
* Unzip downloaded file there:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo unzip /tmp/Precompiled.zip -d /opt/elixir
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create symlinks for the pre-compiled binaries:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
for e in elixir elixirc iex mix; do sudo ln -s /opt/elixir/bin/${e} /usr/local/bin/${e}; done
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PostgreSQL
|
||||||
|
|
||||||
|
* Add the Postgresql repository:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install the Postgresql server:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install postgresql11-server postgresql11-contrib
|
||||||
|
```
|
||||||
|
|
||||||
|
* Initialize database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
|
||||||
|
```
|
||||||
|
|
||||||
|
* Open configuration file `/var/lib/pgsql/11/data/pg_hba.conf` and change the following lines from:
|
||||||
|
|
||||||
|
```plain
|
||||||
|
# IPv4 local connections:
|
||||||
|
host all all 127.0.0.1/32 ident
|
||||||
|
# IPv6 local connections:
|
||||||
|
host all all ::1/128 ident
|
||||||
|
```
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
```plain
|
||||||
|
# IPv4 local connections:
|
||||||
|
host all all 127.0.0.1/32 md5
|
||||||
|
# IPv6 local connections:
|
||||||
|
host all all ::1/128 md5
|
||||||
|
```
|
||||||
|
|
||||||
|
* Enable and start postgresql server:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now postgresql-11.service
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PleromaBE
|
||||||
|
|
||||||
|
* Add a new system user for the Pleroma service:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo useradd -r -s /bin/false -m -d /var/lib/pleroma -U pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l pleroma -s $SHELL -c 'command'` and `su -l pleroma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
|
* Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /opt/pleroma
|
||||||
|
sudo chown -R pleroma:pleroma /opt/pleroma
|
||||||
|
sudo -Hu pleroma git clone https://git.pleroma.social/pleroma/pleroma /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Change to the new directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma mix deps.get
|
||||||
|
```
|
||||||
|
|
||||||
|
* Generate the configuration: `sudo -Hu pleroma mix pleroma.instance gen`
|
||||||
|
* Answer with `yes` if it asks you to install `rebar3`.
|
||||||
|
* This may take some time, because parts of pleroma get compiled first.
|
||||||
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
|
* Check the configuration and if all looks right, rename it, so Pleroma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
```
|
||||||
|
|
||||||
|
* The previous command creates also the file `config/setup_db.psql`, with which you can create the database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu postgres psql -f config/setup_db.psql
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now run the database migration:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now you can start Pleroma already
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finalize installation
|
||||||
|
|
||||||
|
If you want to open your newly installed instance to the world, you should run nginx or some other webserver/proxy in front of Pleroma and you should consider to create a systemd service file for Pleroma.
|
||||||
|
|
||||||
|
#### Nginx
|
||||||
|
|
||||||
|
* Install nginx, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Setup your SSL cert, using your method of choice or certbot. If using certbot, first install it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo yum install certbot-nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
and then set it up:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /var/lib/letsencrypt/
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* Copy the example nginx configuration to the nginx folder
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/conf.d/pleroma.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
* Before starting nginx edit the configuration and change it to your needs (e.g. change servername, change cert paths)
|
||||||
|
* Enable and start nginx:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need to renew the certificate in the future, uncomment the relevant location block in the nginx config and run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --webroot -w /var/lib/letsencrypt/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Other webserver/proxies
|
||||||
|
|
||||||
|
You can find example configurations for them in `/opt/pleroma/installation/`.
|
||||||
|
|
||||||
|
#### Systemd service
|
||||||
|
|
||||||
|
* Copy example service file
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
* Edit the service file and make sure that all paths fit your installation
|
||||||
|
* Enable and start `pleroma.service`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create your first user
|
||||||
|
|
||||||
|
If your instance is up and running, you can create your first user with administrative rights with the following task:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Further reading
|
||||||
|
|
||||||
|
* [Admin tasks](Admin tasks)
|
||||||
|
* [Backup your instance](Backup-your-instance)
|
||||||
|
* [Configuration tips](General tips for customizing pleroma fe)
|
||||||
|
* [Hardening your instance](Hardening-your-instance)
|
||||||
|
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||||
|
* [Small Pleroma-FE customizations](Small customizations)
|
||||||
|
* [Updating your instance](Updating-your-instance)
|
||||||
|
|
||||||
|
## Questions
|
||||||
|
|
||||||
|
Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.
|
202
docs/installation/debian_based_en.md
Normal file
202
docs/installation/debian_based_en.md
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
# Installing on Debian Based Distributions
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
This guide will assume you are on Debian Stretch. This guide should also work with Ubuntu 16.04 and 18.04. It also assumes that you have administrative rights, either as root or a user with [sudo permissions](https://www.digitalocean.com/community/tutorials/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su <username> -s $SHELL -c 'command'` instead.
|
||||||
|
|
||||||
|
### Required packages
|
||||||
|
|
||||||
|
* `postgresql` (9.6+, Ubuntu 16.04 comes with 9.5, you can get a newer version from [here](https://www.postgresql.org/download/linux/ubuntu/))
|
||||||
|
* `postgresql-contrib` (9.6+, same situtation as above)
|
||||||
|
* `elixir` (1.5+, [install from here, Debian and Ubuntu ship older versions](https://elixir-lang.org/install.html#unix-and-unix-like) or use [asdf](https://github.com/asdf-vm/asdf) as the pleroma user)
|
||||||
|
* `erlang-dev`
|
||||||
|
* `erlang-tools`
|
||||||
|
* `erlang-parsetools`
|
||||||
|
* `erlang-eldap`, if you want to enable ldap authenticator
|
||||||
|
* `erlang-xmerl`
|
||||||
|
* `git`
|
||||||
|
* `build-essential`
|
||||||
|
|
||||||
|
#### Optional packages used in this guide
|
||||||
|
|
||||||
|
* `nginx` (preferred, example configs for other reverse proxies can be found in the repo)
|
||||||
|
* `certbot` (or any other ACME client for Let’s Encrypt certificates)
|
||||||
|
|
||||||
|
### Prepare the system
|
||||||
|
|
||||||
|
* First update the system, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt update
|
||||||
|
sudo apt full-upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install some of the above mentioned programs:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install git build-essential postgresql postgresql-contrib
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install Elixir and Erlang
|
||||||
|
|
||||||
|
* Download and add the Erlang repository:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
wget -P /tmp/ https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
|
||||||
|
sudo dpkg -i /tmp/erlang-solutions_1.0_all.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install Elixir and Erlang:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PleromaBE
|
||||||
|
|
||||||
|
* Add a new system user for the Pleroma service:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo useradd -r -s /bin/false -m -d /var/lib/pleroma -U pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l pleroma -s $SHELL -c 'command'` and `su -l pleroma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
|
* Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /opt/pleroma
|
||||||
|
sudo chown -R pleroma:pleroma /opt/pleroma
|
||||||
|
sudo -Hu pleroma git clone https://git.pleroma.social/pleroma/pleroma /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Change to the new directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd /opt/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma mix deps.get
|
||||||
|
```
|
||||||
|
|
||||||
|
* Generate the configuration: `sudo -Hu pleroma mix pleroma.instance gen`
|
||||||
|
* Answer with `yes` if it asks you to install `rebar3`.
|
||||||
|
* This may take some time, because parts of pleroma get compiled first.
|
||||||
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
|
* Check the configuration and if all looks right, rename it, so Pleroma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
```
|
||||||
|
|
||||||
|
* The previous command creates also the file `config/setup_db.psql`, with which you can create the database:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu postgres psql -f config/setup_db.psql
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now run the database migration:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
* Now you can start Pleroma already
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finalize installation
|
||||||
|
|
||||||
|
If you want to open your newly installed instance to the world, you should run nginx or some other webserver/proxy in front of Pleroma and you should consider to create a systemd service file for Pleroma.
|
||||||
|
|
||||||
|
#### Nginx
|
||||||
|
|
||||||
|
* Install nginx, if not already done:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Setup your SSL cert, using your method of choice or certbot. If using certbot, first install it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install certbot
|
||||||
|
```
|
||||||
|
|
||||||
|
and then set it up:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo mkdir -p /var/lib/letsencrypt/
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
|
||||||
|
```
|
||||||
|
|
||||||
|
If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* Copy the example nginx configuration and activate it:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.nginx
|
||||||
|
sudo ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Before starting nginx edit the configuration and change it to your needs (e.g. change servername, change cert paths)
|
||||||
|
* Enable and start nginx:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now nginx.service
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need to renew the certificate in the future, uncomment the relevant location block in the nginx config and run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --webroot -w /var/lib/letsencrypt/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Other webserver/proxies
|
||||||
|
|
||||||
|
You can find example configurations for them in `/opt/pleroma/installation/`.
|
||||||
|
|
||||||
|
#### Systemd service
|
||||||
|
|
||||||
|
* Copy example service file
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
* Edit the service file and make sure that all paths fit your installation
|
||||||
|
* Enable and start `pleroma.service`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo systemctl enable --now pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create your first user
|
||||||
|
|
||||||
|
If your instance is up and running, you can create your first user with administrative rights with the following task:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Further reading
|
||||||
|
|
||||||
|
* [Admin tasks](Admin tasks)
|
||||||
|
* [Backup your instance](Backup-your-instance)
|
||||||
|
* [Configuration tips](General tips for customizing pleroma fe)
|
||||||
|
* [Hardening your instance](Hardening-your-instance)
|
||||||
|
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||||
|
* [Small Pleroma-FE customizations](Small customizations)
|
||||||
|
* [Updating your instance](Updating-your-instance)
|
||||||
|
|
||||||
|
## Questions
|
||||||
|
|
||||||
|
Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.
|
191
docs/installation/debian_based_jp.md
Normal file
191
docs/installation/debian_based_jp.md
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
# Pleromaの入れ方
|
||||||
|
## 日本語訳について
|
||||||
|
|
||||||
|
この記事は [Installing on Debian based distributions](Installing on Debian based distributions) の日本語訳です。何かがおかしいと思ったら、原文を見てください。
|
||||||
|
|
||||||
|
## インストール
|
||||||
|
|
||||||
|
このガイドはDebian Stretchを仮定しています。Ubuntu 16.04でも可能です。
|
||||||
|
|
||||||
|
### 必要なソフトウェア
|
||||||
|
|
||||||
|
- PostgreSQL 9.6+ (postgresql-contrib-9.6 または他のバージョンの PSQL をインストールしてください)
|
||||||
|
- Elixir 1.5 以上 ([Debianのリポジトリからインストールしないこと!!! ここからインストールすること!](https://elixir-lang.org/install.html#unix-and-unix-like))。または [asdf](https://github.com/asdf-vm/asdf) を pleroma ユーザーでインストール。
|
||||||
|
- erlang-dev
|
||||||
|
- erlang-tools
|
||||||
|
- erlang-parsetools
|
||||||
|
- erlang-xmerl (Jessieではバックポートからインストールすること!)
|
||||||
|
- git
|
||||||
|
- build-essential
|
||||||
|
- openssh
|
||||||
|
- openssl
|
||||||
|
- nginx prefered (Apacheも動くかもしれませんが、誰もテストしていません!)
|
||||||
|
- certbot (または何らかのACME Let's encryptクライアント)
|
||||||
|
|
||||||
|
### システムを準備する
|
||||||
|
|
||||||
|
* まずシステムをアップデートしてください。
|
||||||
|
```
|
||||||
|
apt update && apt dist-upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
* 複数のツールとpostgresqlをインストールします。あとで必要になるので。
|
||||||
|
```
|
||||||
|
apt install git build-essential openssl ssh sudo postgresql-9.6 postgresql-contrib-9.6
|
||||||
|
```
|
||||||
|
(postgresqlのバージョンは、あなたのディストロにあわせて変えてください。または、バージョン番号がいらないかもしれません。)
|
||||||
|
|
||||||
|
### ElixirとErlangをインストールします
|
||||||
|
|
||||||
|
* Erlangのリポジトリをダウンロードおよびインストールします。
|
||||||
|
```
|
||||||
|
wget -P /tmp/ https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i /tmp/erlang-solutions_1.0_all.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
* ElixirとErlangをインストールします、
|
||||||
|
```
|
||||||
|
apt update && apt install elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pleroma BE (バックエンド) をインストールします
|
||||||
|
|
||||||
|
* 新しいユーザーを作ります。
|
||||||
|
```
|
||||||
|
adduser pleroma
|
||||||
|
```
|
||||||
|
(Give it any password you want, make it STRONG)
|
||||||
|
|
||||||
|
* 新しいユーザーをsudoグループに入れます。
|
||||||
|
```
|
||||||
|
usermod -aG sudo pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* 新しいユーザーに変身し、ホームディレクトリに移動します。
|
||||||
|
```
|
||||||
|
su pleroma
|
||||||
|
cd ~
|
||||||
|
```
|
||||||
|
|
||||||
|
* Gitリポジトリをクローンします。
|
||||||
|
```
|
||||||
|
git clone https://git.pleroma.social/pleroma/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
* 新しいディレクトリに移動します。
|
||||||
|
```
|
||||||
|
cd pleroma/
|
||||||
|
```
|
||||||
|
|
||||||
|
* Pleromaが依存するパッケージをインストールします。Hexをインストールしてもよいか聞かれたら、yesを入力してください。
|
||||||
|
```
|
||||||
|
mix deps.get
|
||||||
|
```
|
||||||
|
|
||||||
|
* コンフィギュレーションを生成します。
|
||||||
|
```
|
||||||
|
mix pleroma.instance gen
|
||||||
|
```
|
||||||
|
* rebar3をインストールしてもよいか聞かれたら、yesを入力してください。
|
||||||
|
* この処理には時間がかかります。私もよく分かりませんが、何らかのコンパイルが行われているようです。
|
||||||
|
* あなたのインスタンスについて、いくつかの質問があります。その回答は `config/generated_config.exs` というコンフィギュレーションファイルに保存されます。
|
||||||
|
|
||||||
|
**注意**: メディアプロクシを有効にすると回答して、なおかつ、キャッシュのURLは空欄のままにしている場合は、`generated_config.exs` を編集して、`base_url` で始まる行をコメントアウトまたは削除してください。そして、上にある行の `true` の後にあるコンマを消してください。
|
||||||
|
|
||||||
|
* コンフィギュレーションを確認して、もし問題なければ、ファイル名を変更してください。
|
||||||
|
```
|
||||||
|
mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
```
|
||||||
|
|
||||||
|
* これまでのコマンドで、すでに `config/setup_db.psql` というファイルが作られています。このファイルをもとに、データベースを作成します。
|
||||||
|
```
|
||||||
|
sudo su postgres -c 'psql -f config/setup_db.psql'
|
||||||
|
```
|
||||||
|
|
||||||
|
* そして、データベースのミグレーションを実行します。
|
||||||
|
```
|
||||||
|
MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
* Pleromaを起動できるようになりました。
|
||||||
|
```
|
||||||
|
MIX_ENV=prod mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
### インストールを終わらせる
|
||||||
|
|
||||||
|
あなたの新しいインスタンスを世界に向けて公開するには、nginxまたは何らかのウェブサーバー (プロクシ) を使用する必要があります。また、Pleroma のためにシステムサービスファイルを作成する必要があります。
|
||||||
|
|
||||||
|
#### Nginx
|
||||||
|
|
||||||
|
* まだインストールしていないなら、nginxをインストールします。
|
||||||
|
```
|
||||||
|
apt install nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* SSLをセットアップします。他の方法でもよいですが、ここではcertbotを説明します。
|
||||||
|
certbotを使うならば、まずそれをインストールします。
|
||||||
|
```
|
||||||
|
apt install certbot
|
||||||
|
```
|
||||||
|
そしてセットアップします。
|
||||||
|
```
|
||||||
|
mkdir -p /var/lib/letsencrypt/.well-known
|
||||||
|
% certbot certonly --email your@emailaddress --webroot -w /var/lib/letsencrypt/ -d yourdomain
|
||||||
|
```
|
||||||
|
もしうまくいかないときは、先にnginxを設定してください。ssl "on" を "off" に変えてから再試行してください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* nginxコンフィギュレーションの例をnginxフォルダーにコピーします。
|
||||||
|
```
|
||||||
|
cp /home/pleroma/pleroma/installation/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
* nginxを起動する前に、コンフィギュレーションを編集してください。例えば、サーバー名、証明書のパスなどを変更する必要があります。
|
||||||
|
* nginxを再起動します。
|
||||||
|
```
|
||||||
|
systemctl reload nginx.service
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Systemd サービス
|
||||||
|
|
||||||
|
* サービスファイルの例をコピーします。
|
||||||
|
```
|
||||||
|
cp /home/pleroma/pleroma/installation/pleroma.service /usr/lib/systemd/system/pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
* サービスファイルを変更します。すべてのパスが正しいことを確認してください。また、`[Service]` セクションに以下の行があることを確認してください。
|
||||||
|
```
|
||||||
|
Environment="MIX_ENV=prod"
|
||||||
|
```
|
||||||
|
|
||||||
|
* `pleroma.service` を enable および start してください。
|
||||||
|
```
|
||||||
|
systemctl enable --now pleroma.service
|
||||||
|
```
|
||||||
|
|
||||||
|
#### モデレーターを作る
|
||||||
|
|
||||||
|
新たにユーザーを作ったら、モデレーター権限を与えたいかもしれません。以下のタスクで可能です。
|
||||||
|
```
|
||||||
|
mix set_moderator username [true|false]
|
||||||
|
```
|
||||||
|
|
||||||
|
モデレーターはすべてのポストを消すことができます。将来的には他のことも可能になるかもしれません。
|
||||||
|
|
||||||
|
#### メディアプロクシを有効にする
|
||||||
|
|
||||||
|
`generate_config` でメディアプロクシを有効にしているなら、すでにメディアプロクシが動作しています。あとから設定を変更したいなら、[How to activate mediaproxy](How-to-activate-mediaproxy) を見てください。
|
||||||
|
|
||||||
|
#### コンフィギュレーションとカスタマイズ
|
||||||
|
|
||||||
|
* [Configuration tips](General tips for customizing pleroma fe)
|
||||||
|
* [Small Pleroma-FE customizations](Small customizations)
|
||||||
|
* [Admin tasks](Admin tasks)
|
||||||
|
|
||||||
|
## 質問ある?
|
||||||
|
|
||||||
|
インストールについて質問がある、もしくは、うまくいかないときは、以下のところで質問できます。
|
||||||
|
|
||||||
|
* [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org)
|
||||||
|
* **Freenode** の **#pleroma** IRCチャンネル
|
198
docs/installation/netbsd_en.md
Normal file
198
docs/installation/netbsd_en.md
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
# Installing on NetBSD
|
||||||
|
|
||||||
|
## Required software
|
||||||
|
|
||||||
|
pkgin should have been installed by the NetBSD installer if you selected
|
||||||
|
the right options. If it isn't installed, install it using pkg_add.
|
||||||
|
|
||||||
|
Note that `postgresql11-contrib` is needed for the Postgres extensions
|
||||||
|
Pleroma uses.
|
||||||
|
|
||||||
|
The `mksh` shell is needed to run the Elixir `mix` script.
|
||||||
|
|
||||||
|
`# pkgin install acmesh elixir git-base git-docs mksh nginx postgresql11-server postgresql11-client postgresql11-contrib sudo`
|
||||||
|
|
||||||
|
You can also build these packages using pkgsrc:
|
||||||
|
```
|
||||||
|
databases/postgresql11-contrib
|
||||||
|
databases/postgresql11-client
|
||||||
|
databases/postgresql11-server
|
||||||
|
devel/git-base
|
||||||
|
devel/git-docs
|
||||||
|
lang/elixir
|
||||||
|
security/acmesh
|
||||||
|
security/sudo
|
||||||
|
shells/mksh
|
||||||
|
www/nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy the rc.d scripts to the right directory:
|
||||||
|
|
||||||
|
```
|
||||||
|
# cp /usr/pkg/share/examples/rc.d/nginx /usr/pkg/share/examples/rc.d/pgsql /etc/rc.d
|
||||||
|
```
|
||||||
|
|
||||||
|
Add nginx and Postgres to `/etc/rc.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
nginx=YES
|
||||||
|
pgsql=YES
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuring postgres
|
||||||
|
|
||||||
|
First, run `# /etc/rc.d/pgsql start`. Then, `$ sudo -Hu pgsql -g pgsql createdb`.
|
||||||
|
|
||||||
|
## Configuring Pleroma
|
||||||
|
|
||||||
|
Create a user for Pleroma:
|
||||||
|
|
||||||
|
```
|
||||||
|
# groupadd pleroma
|
||||||
|
# useradd -d /home/pleroma -m -g pleroma -s /usr/pkg/bin/mksh pleroma
|
||||||
|
# echo 'export LC_ALL="en_GB.UTF-8"' >> /home/pleroma/.profile
|
||||||
|
# su -l pleroma -c $SHELL
|
||||||
|
```
|
||||||
|
|
||||||
|
Clone the repository:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd /home/pleroma
|
||||||
|
$ git clone https://git.pleroma.social/pleroma/pleroma.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure Pleroma. Note that you need a domain name at this point:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd /home/pleroma/pleroma
|
||||||
|
$ mix deps.get
|
||||||
|
$ mix pleroma.instance gen # You will be asked a few questions here.
|
||||||
|
```
|
||||||
|
|
||||||
|
Since Postgres is configured, we can now initialize the database. There should
|
||||||
|
now be a file in `config/setup_db.psql` that makes this easier. Edit it, and
|
||||||
|
*change the password* to a password of your choice. Make sure it is secure, since
|
||||||
|
it'll be protecting your database. Now initialize the database:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo -Hu pgsql -g pgsql psql -f config/setup_db.psql
|
||||||
|
```
|
||||||
|
|
||||||
|
Postgres allows connections from all users without a password by default. To
|
||||||
|
fix this, edit `/usr/pkg/pgsql/data/pg_hba.conf`. Change every `trust` to
|
||||||
|
`password`.
|
||||||
|
|
||||||
|
Once this is done, restart Postgres with `# /etc/rc.d/pgsql restart`.
|
||||||
|
|
||||||
|
Run the database migrations.
|
||||||
|
You will need to do this whenever you update with `git pull`:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ MIX_ENV=prod mix ecto.migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuring nginx
|
||||||
|
|
||||||
|
Install the example configuration file
|
||||||
|
`/home/pleroma/pleroma/installation/pleroma.nginx` to
|
||||||
|
`/usr/pkg/etc/nginx.conf`.
|
||||||
|
|
||||||
|
Note that it will need to be wrapped in a `http {}` block. You should add
|
||||||
|
settings for the nginx daemon outside of the http block, for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
user nginx nginx;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
worker_processes 4;
|
||||||
|
|
||||||
|
events {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit the defaults:
|
||||||
|
|
||||||
|
* Change `ssl_certificate` and `ssl_trusted_certificate` to
|
||||||
|
`/etc/nginx/tls/fullchain`.
|
||||||
|
* Change `ssl_certificate_key` to `/etc/nginx/tls/key`.
|
||||||
|
* Change `example.tld` to your instance's domain name.
|
||||||
|
|
||||||
|
## Configuring acme.sh
|
||||||
|
|
||||||
|
We'll be using acme.sh in Stateless Mode for TLS certificate renewal.
|
||||||
|
|
||||||
|
First, get your account fingerprint:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo -Hu nginx -g nginx acme.sh --register-account
|
||||||
|
```
|
||||||
|
|
||||||
|
You need to add the following to your nginx configuration for the server
|
||||||
|
running on port 80:
|
||||||
|
|
||||||
|
```
|
||||||
|
location ~ ^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$ {
|
||||||
|
default_type text/plain;
|
||||||
|
return 200 "$1.6fXAG9VyG0IahirPEU2ZerUtItW2DHzDzD9wZaEKpqd";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace the string after after `$1.` with your fingerprint.
|
||||||
|
|
||||||
|
Start nginx:
|
||||||
|
|
||||||
|
```
|
||||||
|
# /etc/rc.d/nginx start
|
||||||
|
```
|
||||||
|
|
||||||
|
It should now be possible to issue a cert (replace `example.com`
|
||||||
|
with your domain name):
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo -Hu nginx -g nginx acme.sh --issue -d example.com --stateless
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's add auto-renewal to `/etc/daily.local`
|
||||||
|
(replace `example.com` with your domain):
|
||||||
|
|
||||||
|
```
|
||||||
|
/usr/pkg/bin/sudo -Hu nginx -g nginx \
|
||||||
|
/usr/pkg/sbin/acme.sh -r \
|
||||||
|
-d example.com \
|
||||||
|
--cert-file /etc/nginx/tls/cert \
|
||||||
|
--key-file /etc/nginx/tls/key \
|
||||||
|
--ca-file /etc/nginx/tls/ca \
|
||||||
|
--fullchain-file /etc/nginx/tls/fullchain \
|
||||||
|
--stateless
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating a startup script for Pleroma
|
||||||
|
|
||||||
|
Copy the startup script to the correct location and make sure it's executable:
|
||||||
|
|
||||||
|
```
|
||||||
|
# cp /home/pleroma/pleroma/installation/netbsd/rc.d/pleroma /etc/rc.d/pleroma
|
||||||
|
# chmod +x /etc/rc.d/pleroma
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the following to `/etc/rc.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
pleroma=YES
|
||||||
|
pleroma_home="/home/pleroma"
|
||||||
|
pleroma_user="pleroma"
|
||||||
|
```
|
||||||
|
|
||||||
|
Run `# /etc/rc.d/pleroma start` to start Pleroma.
|
||||||
|
|
||||||
|
## Conclusion
|
||||||
|
|
||||||
|
Restart nginx with `# /etc/rc.d/nginx restart` and you should be up and running.
|
||||||
|
|
||||||
|
If you need further help, contact niaa on freenode.
|
||||||
|
|
||||||
|
Make sure your time is in sync, or other instances will receive your posts with
|
||||||
|
incorrect timestamps. You should have ntpd running.
|
||||||
|
|
||||||
|
## Instances running NetBSD
|
||||||
|
|
||||||
|
* <https://catgirl.science>
|
222
docs/installation/openbsd_en.md
Normal file
222
docs/installation/openbsd_en.md
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
# Installing on OpenBSD
|
||||||
|
This guide describes the installation and configuration of pleroma (and the required software to run it) on a single OpenBSD 6.4 server.
|
||||||
|
For any additional information regarding commands and configuration files mentioned here, check the man pages [online](https://man.openbsd.org/) or directly on your server with the man command.
|
||||||
|
|
||||||
|
#### Required software
|
||||||
|
The following packages need to be installed:
|
||||||
|
* elixir
|
||||||
|
* gmake
|
||||||
|
* ImageMagick
|
||||||
|
* git
|
||||||
|
* postgresql-server
|
||||||
|
* postgresql-contrib
|
||||||
|
|
||||||
|
To install them, run the following command (with doas or as root):
|
||||||
|
`pkg_add elixir gmake ImageMagick git postgresql-server postgresql-contrib`
|
||||||
|
|
||||||
|
Pleroma requires a reverse proxy, OpenBSD has relayd in base (and is used in this guide) and packages/ports are available for nginx (www/nginx) and apache (www/apache-httpd). Independently of the reverse proxy, [acme-client(1)](https://man.openbsd.org/acme-client) can be used to get a certificate from Let's Encrypt.
|
||||||
|
|
||||||
|
#### Creating the pleroma user
|
||||||
|
Pleroma will be run by a dedicated user, \_pleroma. Before creating it, insert the following lines in login.conf:
|
||||||
|
```
|
||||||
|
pleroma:\
|
||||||
|
:datasize-max=1536M:\
|
||||||
|
:datasize-cur=1536M:\
|
||||||
|
:openfiles-max=4096
|
||||||
|
```
|
||||||
|
This creates a "pleroma" login class and sets higher values than default for datasize and openfiles (see [login.conf(5)](https://man.openbsd.org/login.conf)), this is required to avoid having pleroma crash some time after starting.
|
||||||
|
|
||||||
|
Create the \_pleroma user, assign it the pleroma login class and create its home directory (/home/\_pleroma/): `useradd -m -L pleroma _pleroma`
|
||||||
|
|
||||||
|
#### Clone pleroma's directory
|
||||||
|
Enter a shell as the \_pleroma user. As root, run `su _pleroma -;cd`. Then clone the repository with `git clone https://git.pleroma.social/pleroma/pleroma.git`. Pleroma is now installed in /home/\_pleroma/pleroma/, it will be configured and started at the end of this guide.
|
||||||
|
|
||||||
|
#### Postgresql
|
||||||
|
Start a shell as the \_postgresql user (as root run `su _postgresql -` then run the `initdb` command to initialize postgresql:
|
||||||
|
If you wish to not use the default location for postgresql's data (/var/postgresql/data), add the following switch at the end of the command: `-D <path>` and modify the `datadir` variable in the /etc/rc.d/postgresql script.
|
||||||
|
|
||||||
|
When this is done, enable postgresql so that it starts on boot and start it. As root, run:
|
||||||
|
```
|
||||||
|
rcctl enable postgresql
|
||||||
|
rcctl start postgresql
|
||||||
|
```
|
||||||
|
To check that it started properly and didn't fail right after starting, you can run `ps aux | grep postgres`, there should be multiple lines of output.
|
||||||
|
|
||||||
|
#### httpd
|
||||||
|
httpd will have three fuctions:
|
||||||
|
* redirect requests trying to reach the instance over http to the https URL
|
||||||
|
* serve a robots.txt file
|
||||||
|
* get Let's Encrypt certificates, with acme-client
|
||||||
|
|
||||||
|
Insert the following config in httpd.conf:
|
||||||
|
```
|
||||||
|
# $OpenBSD: httpd.conf,v 1.17 2017/04/16 08:50:49 ajacoutot Exp $
|
||||||
|
|
||||||
|
ext_inet="<IPv4 address>"
|
||||||
|
ext_inet6="<IPv6 address>"
|
||||||
|
|
||||||
|
server "default" {
|
||||||
|
listen on $ext_inet port 80 # Comment to disable listening on IPv4
|
||||||
|
listen on $ext_inet6 port 80 # Comment to disable listening on IPv6
|
||||||
|
listen on 127.0.0.1 port 80 # Do NOT comment this line
|
||||||
|
|
||||||
|
log syslog
|
||||||
|
directory no index
|
||||||
|
|
||||||
|
location "/.well-known/acme-challenge/*" {
|
||||||
|
root "/acme"
|
||||||
|
request strip 2
|
||||||
|
}
|
||||||
|
|
||||||
|
location "/robots.txt" { root "/htdocs/local/" }
|
||||||
|
location "/*" { block return 302 "https://$HTTP_HOST$REQUEST_URI" }
|
||||||
|
}
|
||||||
|
|
||||||
|
types {
|
||||||
|
include "/usr/share/misc/mime.types"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Do not forget to change *\<IPv4/6 address\>* to your server's address(es). If httpd should only listen on one protocol family, comment one of the two first *listen* options.
|
||||||
|
|
||||||
|
Create the /var/www/htdocs/local/ folder and write the content of your robots.txt in /var/www/htdocs/local/robots.txt.
|
||||||
|
Check the configuration with `httpd -n`, if it is OK enable and start httpd (as root):
|
||||||
|
```
|
||||||
|
rcctl enable httpd
|
||||||
|
rcctl start httpd
|
||||||
|
```
|
||||||
|
|
||||||
|
#### acme-client
|
||||||
|
acme-client is used to get SSL/TLS certificates from Let's Encrypt.
|
||||||
|
Insert the following configuration in /etc/acme-client.conf:
|
||||||
|
```
|
||||||
|
#
|
||||||
|
# $OpenBSD: acme-client.conf,v 1.4 2017/03/22 11:14:14 benno Exp $
|
||||||
|
#
|
||||||
|
|
||||||
|
authority letsencrypt-<domain name> {
|
||||||
|
#agreement url "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf"
|
||||||
|
api url "https://acme-v01.api.letsencrypt.org/directory"
|
||||||
|
account key "/etc/acme/letsencrypt-privkey-<domain name>.pem"
|
||||||
|
}
|
||||||
|
|
||||||
|
domain <domain name> {
|
||||||
|
domain key "/etc/ssl/private/<domain name>.key"
|
||||||
|
domain certificate "/etc/ssl/<domain name>.crt"
|
||||||
|
domain full chain certificate "/etc/ssl/<domain name>.fullchain.pem"
|
||||||
|
sign with letsencrypt-<domain name>
|
||||||
|
challengedir "/var/www/acme/"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Replace *\<domain name\>* by the domain name you'll use for your instance. As root, run `acme-client -n` to check the config, then `acme-client -ADv <domain name>` to create account and domain keys, and request a certificate for the first time.
|
||||||
|
Make acme-client run everyday by adding it in /etc/daily.local. As root, run the following command: `echo "acme-client <domain name>" >> /etc/daily.local`.
|
||||||
|
|
||||||
|
Relayd will look for certificates and keys based on the address it listens on (see next part), the easiest way to make them available to relayd is to create a link, as root run:
|
||||||
|
```
|
||||||
|
ln -s /etc/ssl/<domain name>.fullchain.pem /etc/ssl/<IP address>.crt
|
||||||
|
ln -s /etc/ssl/private/<domain name>.key /etc/ssl/private/<IP address>.key
|
||||||
|
```
|
||||||
|
This will have to be done for each IPv4 and IPv6 address relayd listens on.
|
||||||
|
|
||||||
|
#### relayd
|
||||||
|
relayd will be used as the reverse proxy sitting in front of pleroma.
|
||||||
|
Insert the following configuration in /etc/relayd.conf:
|
||||||
|
```
|
||||||
|
# $OpenBSD: relayd.conf,v 1.4 2018/03/23 09:55:06 claudio Exp $
|
||||||
|
|
||||||
|
ext_inet="<IPv4 address>"
|
||||||
|
ext_inet6="<IPv6 address>"
|
||||||
|
|
||||||
|
table <pleroma_server> { 127.0.0.1 }
|
||||||
|
table <httpd_server> { 127.0.0.1 }
|
||||||
|
|
||||||
|
http protocol plerup { # Protocol for upstream pleroma server
|
||||||
|
#tcp { nodelay, sack, socket buffer 65536, backlog 128 } # Uncomment and adjust as you see fit
|
||||||
|
tls ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305"
|
||||||
|
tls ecdhe secp384r1
|
||||||
|
|
||||||
|
# Forward some paths to the local server (as pleroma won't respond to them as you might want)
|
||||||
|
pass request quick path "/robots.txt" forward to <httpd_server>
|
||||||
|
|
||||||
|
# Append a bunch of headers
|
||||||
|
match request header append "X-Forwarded-For" value "$REMOTE_ADDR" # This two header and the next one are not strictly required by pleroma but adding them won't hurt
|
||||||
|
match request header append "X-Forwarded-By" value "$SERVER_ADDR:$SERVER_PORT"
|
||||||
|
|
||||||
|
match response header append "X-XSS-Protection" value "1; mode=block"
|
||||||
|
match response header append "X-Permitted-Cross-Domain-Policies" value "none"
|
||||||
|
match response header append "X-Frame-Options" value "DENY"
|
||||||
|
match response header append "X-Content-Type-Options" value "nosniff"
|
||||||
|
match response header append "Referrer-Policy" value "same-origin"
|
||||||
|
match response header append "X-Download-Options" value "noopen"
|
||||||
|
match response header append "Content-Security-Policy" value "default-src 'none'; base-uri 'self'; form-action 'self'; img-src 'self' data: https:; media-src 'self' https:; style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'; connect-src 'self' wss://CHANGEME.tld; upgrade-insecure-requests;" # Modify "CHANGEME.tld" and set your instance's domain here
|
||||||
|
match request header append "Connection" value "upgrade"
|
||||||
|
#match response header append "Strict-Transport-Security" value "max-age=31536000; includeSubDomains" # Uncomment this only after you get HTTPS working.
|
||||||
|
|
||||||
|
# If you do not want remote frontends to be able to access your Pleroma backend server, comment these lines
|
||||||
|
match response header append "Access-Control-Allow-Origin" value "*"
|
||||||
|
match response header append "Access-Control-Allow-Methods" value "POST, PUT, DELETE, GET, PATCH, OPTIONS"
|
||||||
|
match response header append "Access-Control-Allow-Headers" value "Authorization, Content-Type, Idempotency-Key"
|
||||||
|
match response header append "Access-Control-Expose-Headers" value "Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id"
|
||||||
|
# Stop commenting lines here
|
||||||
|
}
|
||||||
|
|
||||||
|
relay wwwtls {
|
||||||
|
listen on $ext_inet port https tls # Comment to disable listening on IPv4
|
||||||
|
listen on $ext_inet6 port https tls # Comment to disable listening on IPv6
|
||||||
|
|
||||||
|
protocol plerup
|
||||||
|
|
||||||
|
forward to <pleroma_server> port 4000 check http "/" code 200
|
||||||
|
forward to <httpd_server> port 80 check http "/robots.txt" code 200
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Again, change *\<IPv4/6 address\>* to your server's address(es) and comment one of the two *listen* options if needed. Also change *wss://CHANGEME.tld* to *wss://\<your instance's domain name\>*.
|
||||||
|
Check the configuration with `relayd -n`, if it is OK enable and start relayd (as root):
|
||||||
|
```
|
||||||
|
rcctl enable relayd
|
||||||
|
rcctl start relayd
|
||||||
|
```
|
||||||
|
|
||||||
|
#### pf
|
||||||
|
Enabling and configuring pf is highly recommended.
|
||||||
|
In /etc/pf.conf, insert the following configuration:
|
||||||
|
```
|
||||||
|
# Macros
|
||||||
|
if="<network interface>"
|
||||||
|
authorized_ssh_clients="any"
|
||||||
|
|
||||||
|
# Skip traffic on loopback interface
|
||||||
|
set skip on lo
|
||||||
|
|
||||||
|
# Default behavior
|
||||||
|
set block-policy drop
|
||||||
|
block in log all
|
||||||
|
pass out quick
|
||||||
|
|
||||||
|
# Security features
|
||||||
|
match in all scrub (no-df random-id)
|
||||||
|
block in log from urpf-failed
|
||||||
|
|
||||||
|
# Rules
|
||||||
|
pass in quick on $if inet proto icmp to ($if) icmp-type { echoreq unreach paramprob trace } # ICMP
|
||||||
|
pass in quick on $if inet6 proto icmp6 to ($if) icmp6-type { echoreq unreach paramprob timex toobig } # ICMPv6
|
||||||
|
pass in quick on $if proto tcp to ($if) port { http https } # relayd/httpd
|
||||||
|
pass in quick on $if proto tcp from $authorized_ssh_clients to ($if) port ssh
|
||||||
|
```
|
||||||
|
Replace *\<network interface\>* by your server's network interface name (which you can get with ifconfig). Consider replacing the content of the authorized\_ssh\_clients macro by, for exemple, your home IP address, to avoid SSH connection attempts from bots.
|
||||||
|
|
||||||
|
Check pf's configuration by running `pfctl -nf /etc/pf.conf`, load it with `pfctl -f /etc/pf.conf` and enable pf at boot with `rcctl enable pf`.
|
||||||
|
|
||||||
|
#### Configure and start pleroma
|
||||||
|
Enter a shell as \_pleroma (as root `su _pleroma -`) and enter pleroma's installation directory (`cd ~/pleroma/`).
|
||||||
|
Then follow the main installation guide:
|
||||||
|
* run `mix deps.get`
|
||||||
|
* run `mix pleroma.instance gen` and enter your instance's information when asked
|
||||||
|
* copy config/generated\_config.exs to config/prod.secret.exs. The default values should be sufficient but you should edit it and check that everything seems OK.
|
||||||
|
* exit your current shell back to a root one and run `psql -U postgres -f /home/_pleroma/config/setup_db.psql` to setup the database.
|
||||||
|
* return to a \_pleroma shell into pleroma's installation directory (`su _pleroma -;cd ~/pleroma`) and run `MIX_ENV=prod mix ecto.migrate`
|
||||||
|
|
||||||
|
As \_pleroma in /home/\_pleroma/pleroma, you can now run `LC_ALL=en_US.UTF-8 MIX_ENV=prod mix phx.server` to start your instance.
|
||||||
|
In another SSH session/tmux window, check that it is working properly by running `ftp -MVo - http://127.0.0.1:4000/api/v1/instance`, you should get json output. Double-check that *uri*'s value is your instance's domain name.
|
||||||
|
|
||||||
|
##### Starting pleroma at boot
|
||||||
|
An rc script to automatically start pleroma at boot hasn't been written yet, it can be run in a tmux session (tmux is in base).
|
110
docs/installation/openbsd_fi.md
Normal file
110
docs/installation/openbsd_fi.md
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
# Pleroman asennus OpenBSD:llä
|
||||||
|
|
||||||
|
Tarvitset:
|
||||||
|
* Oman domainin
|
||||||
|
* OpenBSD 6.3 -serverin
|
||||||
|
* Auttavan ymmärryksen unix-järjestelmistä
|
||||||
|
|
||||||
|
Komennot, joiden edessä on '#', tulee ajaa käyttäjänä `root`. Tämä on
|
||||||
|
suositeltavaa tehdä komennon `doas` avulla, katso `doas (1)` ja `doas.conf (5)`.
|
||||||
|
Tästä eteenpäin oletuksena on, että domain "esimerkki.com" osoittaa
|
||||||
|
serverin IP-osoitteeseen.
|
||||||
|
|
||||||
|
Jos asennuksen kanssa on ongelmia, IRC-kanava #pleroma Freenodessa tai
|
||||||
|
Matrix-kanava #freenode_#pleroma:matrix.org ovat hyviä paikkoja löytää apua
|
||||||
|
(englanniksi), `/msg eal kukkuu` jos haluat välttämättä puhua härmää.
|
||||||
|
|
||||||
|
Asenna tarvittava ohjelmisto:
|
||||||
|
|
||||||
|
`# pkg_add git elixir gmake postgresql-server-10.3 postgresql-contrib-10.3`
|
||||||
|
|
||||||
|
Luo postgresql-tietokanta:
|
||||||
|
|
||||||
|
`# su - _postgresql`
|
||||||
|
|
||||||
|
`$ mkdir /var/postgresql/data`
|
||||||
|
|
||||||
|
`$ initdb -D /var/postgresql/data -E UTF8`
|
||||||
|
|
||||||
|
`$ createdb`
|
||||||
|
|
||||||
|
Käynnistä tietokanta ja aseta se käynnistymään automaattisesti.
|
||||||
|
|
||||||
|
`# rcctl start postgresql`
|
||||||
|
|
||||||
|
`# rcctl enable postgresql`
|
||||||
|
|
||||||
|
Luo käyttäjä pleromaa varten (kysyy muutaman kysymyksen):
|
||||||
|
|
||||||
|
`# adduser pleroma`
|
||||||
|
|
||||||
|
Vaihda pleroma-käyttäjään ja mene kotihakemistoosi:
|
||||||
|
|
||||||
|
`# su - pleroma`
|
||||||
|
|
||||||
|
Lataa pleroman lähdekoodi:
|
||||||
|
|
||||||
|
`$ git clone https://git.pleroma.social/pleroma/pleroma.git`
|
||||||
|
|
||||||
|
`$ cd pleroma`
|
||||||
|
|
||||||
|
Asenna tarvittavat elixir-kirjastot:
|
||||||
|
|
||||||
|
`$ mix deps.get`
|
||||||
|
|
||||||
|
`$ mix deps.compile`
|
||||||
|
|
||||||
|
Luo tarvittava konfiguraatio:
|
||||||
|
|
||||||
|
`$ mix generate_config`
|
||||||
|
|
||||||
|
`$ cp config/generated_config.exs config/prod.secret.exs`
|
||||||
|
|
||||||
|
Aja luodut tietokantakomennot:
|
||||||
|
|
||||||
|
`# su _postgres -c 'psql -f config/setup_db.psql'`
|
||||||
|
|
||||||
|
`$ MIX_ENV=prod mix ecto.migrate`
|
||||||
|
|
||||||
|
Käynnistä pleroma-prosessi:
|
||||||
|
|
||||||
|
`$ MIX_ENV=prod mix compile`
|
||||||
|
|
||||||
|
`$ MIX_ENV=prod mix phx.server`
|
||||||
|
|
||||||
|
Tässä vaiheessa on hyvä tarkistaa että asetukset ovat oikein. Avaa selaimella,
|
||||||
|
curlilla tai vastaavalla työkalulla `esimerkki.com:4000/api/v1/instance` ja katso
|
||||||
|
että kohta "uri" on "https://esimerkki.com".
|
||||||
|
|
||||||
|
Huom! Muista varmistaa että muuttuja MIX_ENV on "prod" mix-komentoja ajaessasi.
|
||||||
|
Mix lukee oikean konfiguraatiotiedoston sen mukaisesti.
|
||||||
|
|
||||||
|
Ohessa enimmäkseen toimivaksi todettu rc.d-skripti pleroman käynnistämiseen.
|
||||||
|
Kirjoita se tiedostoon /etc/rc.d/pleroma. Tämän jälkeen aja
|
||||||
|
`# chmod +x /etc/rc.d/pleroma`, ja voit käynnistää pleroman komennolla
|
||||||
|
`# /etc/rc.d/pleroma start`.
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/ksh
|
||||||
|
#/etc/rc.d/pleroma
|
||||||
|
|
||||||
|
daemon="cd /home/pleroma/pleroma;MIX_ENV=prod /usr/local/bin/elixir"
|
||||||
|
daemon_flags="--detached /usr/local/bin/mix phx.server"
|
||||||
|
daemon_user="pleroma"
|
||||||
|
rc_reload="NO"
|
||||||
|
rc_bg="YES"
|
||||||
|
|
||||||
|
pexp="beam"
|
||||||
|
|
||||||
|
. /etc/rc.d/rc.subr
|
||||||
|
|
||||||
|
rc_cmd $1
|
||||||
|
```
|
||||||
|
|
||||||
|
Tämän jälkeen tarvitset enää HTTP-serverin välittämään kutsut pleroma-prosessille.
|
||||||
|
Tiedostosta `install/pleroma.nginx` löytyy esimerkkikonfiguraatio, ja TLS-sertifikaatit
|
||||||
|
saat ilmaiseksi esimerkiksi [letsencryptiltä](https://certbot.eff.org/lets-encrypt/opbsd-nginx.html).
|
||||||
|
Nginx asentuu yksinkertaisesti komennolla `# pkg_add nginx`.
|
||||||
|
|
||||||
|
Kun olet valmis, avaa https://esimerkki.com selaimessasi. Luo käyttäjä ja seuraa kiinnostavia
|
||||||
|
tyyppejä muilla palvelimilla!
|
55
docs/introduction.md
Normal file
55
docs/introduction.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Introduction to Pleroma
|
||||||
|
## What is Pleroma?
|
||||||
|
Pleroma is a federated social networking platform, compatible with GNU social, Mastodon and other OStatus and ActivityPub implementations. It is free software licensed under the AGPLv3.
|
||||||
|
It actually consists of two components: a backend, named simply Pleroma, and a user-facing frontend, named Pleroma-FE. It also includes the Mastodon frontend, if that's your thing.
|
||||||
|
It's part of what we call the fediverse, a federated network of instances which speak common protocols and can communicate with each other.
|
||||||
|
One account on a instance is enough to talk to the entire fediverse!
|
||||||
|
|
||||||
|
## How can I use it?
|
||||||
|
|
||||||
|
Pleroma instances are already widely deployed, a list can be found here:
|
||||||
|
http://distsn.org/pleroma-instances.html
|
||||||
|
|
||||||
|
If you don't feel like joining an existing instance, but instead prefer to deploy your own instance, that's easy too!
|
||||||
|
Installation instructions can be found here:
|
||||||
|
[main Pleroma wiki](/)
|
||||||
|
|
||||||
|
## I got an account, now what?
|
||||||
|
Great! Now you can explore the fediverse!
|
||||||
|
- Open the login page for your Pleroma instance (for ex. https://pleroma.soykaf.com) and login with your username and password.
|
||||||
|
(If you don't have one yet, click on Register) :slightly_smiling_face:
|
||||||
|
|
||||||
|
At this point you will have two columns in front of you.
|
||||||
|
|
||||||
|
### Left column
|
||||||
|
- first block: here you can see your avatar, your nickname a bio, and statistics (Statuses, Following, Followers).
|
||||||
|
Under that you have a text form which allows you to post new statuses. The icon on the left is for uploading media files and attach them to your post. The number under the text form is a character counter, every instance can have a different character limit (the default is 5000).
|
||||||
|
If you want to mention someone, type @ + name of the person. A drop-down menu will help you in finding the right person. :slight_smile:
|
||||||
|
To post your status, simply press Submit.
|
||||||
|
|
||||||
|
- second block: Here you can switch between the different timelines:
|
||||||
|
- Timeline: all the people that you follow
|
||||||
|
- Mentions: all the statutes where you are mentioned
|
||||||
|
- Public Timeline: all the statutes from the local instance
|
||||||
|
- The Whole Known Network: everything, local and remote!
|
||||||
|
|
||||||
|
- third block: this is the Chat block, where you communicate with people on the same instance in realtime. It is local-only, for now, but we're planning to make it extendable to the entire fediverse! :sweat_smile:
|
||||||
|
|
||||||
|
- fourth block: This is the Notifications block, here you will get notified whenever somebody mentions you, follows you, repeats or favorites one of your statuses.
|
||||||
|
|
||||||
|
### Right column
|
||||||
|
This is where the interesting stuff happens! :slight_smile:
|
||||||
|
Depending on the timeline you will see different statuses, but each status has a standard structure:
|
||||||
|
- Icon + name + link to profile. An optional left-arrow if it's a reply to another status (hovering will reveal the replied-to status).
|
||||||
|
- A + button on the right allows you to Expand/Collapse an entire discussion thread. It also updates in realtime!
|
||||||
|
- A binocular icon allows you to open the status on the instance where it's originating from.
|
||||||
|
- The text of the status, including mentions. If you click on a mention, it will automatically open the profile page of that person.
|
||||||
|
- Four buttons (left to right): Reply, Repeat, Favorite, Delete.
|
||||||
|
|
||||||
|
## Mastodon interface
|
||||||
|
If the Pleroma interface isn't your thing, or you're just trying something new but you want to keep using the familiar Mastodon interface, we got that too! :smile:
|
||||||
|
Just add a "/web" after your instance url (for ex. https://pleroma.soycaf.com/web) and you'll end on the Mastodon web interface, but with a Pleroma backend! MAGIC! :fireworks:
|
||||||
|
For more information on the Mastodon interface, please look here:
|
||||||
|
https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/User-guide.md
|
||||||
|
|
||||||
|
Remember, what you see is only the frontend part of Mastodon, the backend is still Pleroma.
|
@ -81,6 +81,14 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||||||
|
|
||||||
email = Common.get_option(options, :admin_email, "What is your admin email address?")
|
email = Common.get_option(options, :admin_email, "What is your admin email address?")
|
||||||
|
|
||||||
|
indexable =
|
||||||
|
Common.get_option(
|
||||||
|
options,
|
||||||
|
:indexable,
|
||||||
|
"Do you want search engines to index your site? (y/n)",
|
||||||
|
"y"
|
||||||
|
) === "y"
|
||||||
|
|
||||||
dbhost =
|
dbhost =
|
||||||
Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
||||||
|
|
||||||
@ -142,6 +150,8 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||||||
Mix.shell().info("Writing #{psql_path}.")
|
Mix.shell().info("Writing #{psql_path}.")
|
||||||
File.write(psql_path, result_psql)
|
File.write(psql_path, result_psql)
|
||||||
|
|
||||||
|
write_robots_txt(indexable)
|
||||||
|
|
||||||
Mix.shell().info(
|
Mix.shell().info(
|
||||||
"\n" <>
|
"\n" <>
|
||||||
"""
|
"""
|
||||||
@ -163,4 +173,28 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp write_robots_txt(indexable) do
|
||||||
|
robots_txt =
|
||||||
|
EEx.eval_file(
|
||||||
|
Path.expand("robots_txt.eex", __DIR__),
|
||||||
|
indexable: indexable
|
||||||
|
)
|
||||||
|
|
||||||
|
static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
|
||||||
|
|
||||||
|
unless File.exists?(static_dir) do
|
||||||
|
File.mkdir_p!(static_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
robots_txt_path = Path.join(static_dir, "robots.txt")
|
||||||
|
|
||||||
|
if File.exists?(robots_txt_path) do
|
||||||
|
File.cp!(robots_txt_path, "#{robots_txt_path}.bak")
|
||||||
|
Mix.shell().info("Backing up existing robots.txt to #{robots_txt_path}.bak")
|
||||||
|
end
|
||||||
|
|
||||||
|
File.write(robots_txt_path, robots_txt)
|
||||||
|
Mix.shell().info("Writing #{robots_txt_path}.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
defmodule Mix.Tasks.Pleroma.Relay do
|
defmodule Mix.Tasks.Pleroma.Relay do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
alias Pleroma.Web.ActivityPub.Relay
|
|
||||||
alias Mix.Tasks.Pleroma.Common
|
alias Mix.Tasks.Pleroma.Common
|
||||||
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
|
|
||||||
@shortdoc "Manages remote relays"
|
@shortdoc "Manages remote relays"
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
|
2
lib/mix/tasks/pleroma/robots_txt.eex
Normal file
2
lib/mix/tasks/pleroma/robots_txt.eex
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-Agent: *
|
||||||
|
Disallow: <%= if indexable, do: "", else: "/" %>
|
32
lib/mix/tasks/pleroma/robotstxt.ex
Normal file
32
lib/mix/tasks/pleroma/robotstxt.ex
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Mix.Tasks.Pleroma.RobotsTxt do
|
||||||
|
use Mix.Task
|
||||||
|
|
||||||
|
@shortdoc "Generate robots.txt"
|
||||||
|
@moduledoc """
|
||||||
|
Generates robots.txt
|
||||||
|
|
||||||
|
## Overwrite robots.txt to disallow all
|
||||||
|
|
||||||
|
mix pleroma.robots_txt disallow_all
|
||||||
|
|
||||||
|
This will write a robots.txt that will hide all paths on your instance
|
||||||
|
from search engines and other robots that obey robots.txt
|
||||||
|
|
||||||
|
"""
|
||||||
|
def run(["disallow_all"]) do
|
||||||
|
static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
|
||||||
|
|
||||||
|
if !File.exists?(static_dir) do
|
||||||
|
File.mkdir_p!(static_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
robots_txt_path = Path.join(static_dir, "robots.txt")
|
||||||
|
robots_txt_content = "User-Agent: *\nDisallow: /\n"
|
||||||
|
|
||||||
|
File.write!(robots_txt_path, robots_txt_content, [:write])
|
||||||
|
end
|
||||||
|
end
|
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
defmodule Mix.Tasks.Pleroma.Uploads do
|
defmodule Mix.Tasks.Pleroma.Uploads do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
alias Mix.Tasks.Pleroma.Common
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
alias Pleroma.Uploaders.Local
|
alias Pleroma.Uploaders.Local
|
||||||
alias Mix.Tasks.Pleroma.Common
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@log_every 50
|
@log_every 50
|
||||||
@ -20,7 +20,6 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||||||
Options:
|
Options:
|
||||||
- `--delete` - delete local uploads after migrating them to the target uploader
|
- `--delete` - delete local uploads after migrating them to the target uploader
|
||||||
|
|
||||||
|
|
||||||
A list of available uploaders can be seen in config.exs
|
A list of available uploaders can be seen in config.exs
|
||||||
"""
|
"""
|
||||||
def run(["migrate_local", target_uploader | args]) do
|
def run(["migrate_local", target_uploader | args]) do
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
defmodule Mix.Tasks.Pleroma.User do
|
defmodule Mix.Tasks.Pleroma.User do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Mix.Tasks.Pleroma.Common
|
alias Mix.Tasks.Pleroma.Common
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.UserInviteToken
|
||||||
|
|
||||||
@shortdoc "Manages Pleroma users"
|
@shortdoc "Manages Pleroma users"
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
@ -27,12 +27,28 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||||||
|
|
||||||
## Generate an invite link.
|
## Generate an invite link.
|
||||||
|
|
||||||
mix pleroma.user invite
|
mix pleroma.user invite [OPTION...]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
- `--expires_at DATE` - last day on which token is active (e.g. "2019-04-05")
|
||||||
|
- `--max_use NUMBER` - maximum numbers of token uses
|
||||||
|
|
||||||
|
## List generated invites
|
||||||
|
|
||||||
|
mix pleroma.user invites
|
||||||
|
|
||||||
|
## Revoke invite
|
||||||
|
|
||||||
|
mix pleroma.user revoke_invite TOKEN OR TOKEN_ID
|
||||||
|
|
||||||
## Delete the user's account.
|
## Delete the user's account.
|
||||||
|
|
||||||
mix pleroma.user rm NICKNAME
|
mix pleroma.user rm NICKNAME
|
||||||
|
|
||||||
|
## Delete the user's activities.
|
||||||
|
|
||||||
|
mix pleroma.user delete_activities NICKNAME
|
||||||
|
|
||||||
## Deactivate or activate the user's account.
|
## Deactivate or activate the user's account.
|
||||||
|
|
||||||
mix pleroma.user toggle_activated NICKNAME
|
mix pleroma.user toggle_activated NICKNAME
|
||||||
@ -220,7 +236,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||||||
{:ok, friends} = User.get_friends(user)
|
{:ok, friends} = User.get_friends(user)
|
||||||
|
|
||||||
Enum.each(friends, fn friend ->
|
Enum.each(friends, fn friend ->
|
||||||
user = Repo.get(User, user.id)
|
user = User.get_by_id(user.id)
|
||||||
|
|
||||||
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
|
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
|
||||||
User.unfollow(user, friend)
|
User.unfollow(user, friend)
|
||||||
@ -228,7 +244,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||||||
|
|
||||||
:timer.sleep(500)
|
:timer.sleep(500)
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
user = User.get_by_id(user.id)
|
||||||
|
|
||||||
if Enum.empty?(user.following) do
|
if Enum.empty?(user.following) do
|
||||||
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
|
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
|
||||||
@ -302,23 +318,91 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["invite"]) do
|
def run(["invite" | rest]) do
|
||||||
|
{options, [], []} =
|
||||||
|
OptionParser.parse(rest,
|
||||||
|
strict: [
|
||||||
|
expires_at: :string,
|
||||||
|
max_use: :integer
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
options =
|
||||||
|
options
|
||||||
|
|> Keyword.update(:expires_at, {:ok, nil}, fn
|
||||||
|
nil -> {:ok, nil}
|
||||||
|
val -> Date.from_iso8601(val)
|
||||||
|
end)
|
||||||
|
|> Enum.into(%{})
|
||||||
|
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
|
with {:ok, val} <- options[:expires_at],
|
||||||
Mix.shell().info("Generated user invite token")
|
options = Map.put(options, :expires_at, val),
|
||||||
|
{:ok, invite} <- UserInviteToken.create_invite(options) do
|
||||||
|
Mix.shell().info(
|
||||||
|
"Generated user invite token " <> String.replace(invite.invite_type, "_", " ")
|
||||||
|
)
|
||||||
|
|
||||||
url =
|
url =
|
||||||
Pleroma.Web.Router.Helpers.redirect_url(
|
Pleroma.Web.Router.Helpers.redirect_url(
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint,
|
||||||
:registration_page,
|
:registration_page,
|
||||||
token.token
|
invite.token
|
||||||
)
|
)
|
||||||
|
|
||||||
IO.puts(url)
|
IO.puts(url)
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
Mix.shell().error("Could not create invite token: #{inspect(error)}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["invites"]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
Mix.shell().info("Invites list:")
|
||||||
|
|
||||||
|
UserInviteToken.list_invites()
|
||||||
|
|> Enum.each(fn invite ->
|
||||||
|
expire_info =
|
||||||
|
with expires_at when not is_nil(expires_at) <- invite.expires_at do
|
||||||
|
" | Expires at: #{Date.to_string(expires_at)}"
|
||||||
|
end
|
||||||
|
|
||||||
|
using_info =
|
||||||
|
with max_use when not is_nil(max_use) <- invite.max_use do
|
||||||
|
" | Max use: #{max_use} Left use: #{max_use - invite.uses}"
|
||||||
|
end
|
||||||
|
|
||||||
|
Mix.shell().info(
|
||||||
|
"ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{
|
||||||
|
invite.used
|
||||||
|
}#{expire_info}#{using_info}"
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["revoke_invite", token]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
with {:ok, invite} <- UserInviteToken.find_by_token(token),
|
||||||
|
{:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
|
||||||
|
Mix.shell().info("Invite for token #{token} was revoked.")
|
||||||
|
else
|
||||||
|
_ -> Mix.shell().error("No invite found with token #{token}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["delete_activities", nickname]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
|
User.delete_user_activities(user)
|
||||||
|
Mix.shell().info("User #{nickname} statuses deleted.")
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
Mix.shell().error("Could not create invite token.")
|
Mix.shell().error("No local user #{nickname}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ defmodule Pleroma.PasswordResetToken do
|
|||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.PasswordResetToken
|
alias Pleroma.PasswordResetToken
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
schema "password_reset_tokens" do
|
schema "password_reset_tokens" do
|
||||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||||
@ -39,7 +39,7 @@ defmodule Pleroma.PasswordResetToken do
|
|||||||
|
|
||||||
def reset_password(token, data) do
|
def reset_password(token, data) do
|
||||||
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
||||||
%User{} = user <- Repo.get(User, token.user_id),
|
%User{} = user <- User.get_by_id(token.user_id),
|
||||||
{:ok, _user} <- User.reset_password(user, data),
|
{:ok, _user} <- User.reset_password(user, data),
|
||||||
{:ok, token} <- Repo.update(used_changeset(token)) do
|
{:ok, token} <- Repo.update(used_changeset(token)) do
|
||||||
{:ok, token}
|
{:ok, token}
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
defmodule Pleroma.Activity do
|
defmodule Pleroma.Activity do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@ -22,16 +23,53 @@ defmodule Pleroma.Activity do
|
|||||||
"Like" => "favourite"
|
"Like" => "favourite"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mastodon_to_ap_notification_types for {k, v} <- @mastodon_notification_types,
|
||||||
|
into: %{},
|
||||||
|
do: {v, k}
|
||||||
|
|
||||||
schema "activities" do
|
schema "activities" do
|
||||||
field(:data, :map)
|
field(:data, :map)
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
field(:actor, :string)
|
field(:actor, :string)
|
||||||
field(:recipients, {:array, :string})
|
field(:recipients, {:array, :string}, default: [])
|
||||||
has_many(:notifications, Notification, on_delete: :delete_all)
|
has_many(:notifications, Notification, on_delete: :delete_all)
|
||||||
|
|
||||||
|
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
|
||||||
|
# The foreign key is embedded in a jsonb field.
|
||||||
|
#
|
||||||
|
# To use it, you probably want to do an inner join and a preload:
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# |> join(:inner, [activity], o in Object,
|
||||||
|
# on: fragment("(?->>'id') = COALESCE((?)->'object'->> 'id', (?)->>'object')",
|
||||||
|
# o.data, activity.data, activity.data))
|
||||||
|
# |> preload([activity, object], [object: object])
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# As a convenience, Activity.with_preloaded_object() sets up an inner join and preload for the
|
||||||
|
# typical case.
|
||||||
|
has_one(:object, Object, on_delete: :nothing, foreign_key: :id)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_preloaded_object(query) do
|
||||||
|
query
|
||||||
|
|> join(
|
||||||
|
:inner,
|
||||||
|
[activity],
|
||||||
|
o in Object,
|
||||||
|
on:
|
||||||
|
fragment(
|
||||||
|
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||||
|
o.data,
|
||||||
|
activity.data,
|
||||||
|
activity.data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|> preload([activity, object], object: object)
|
||||||
|
end
|
||||||
|
|
||||||
def get_by_ap_id(ap_id) do
|
def get_by_ap_id(ap_id) do
|
||||||
Repo.one(
|
Repo.one(
|
||||||
from(
|
from(
|
||||||
@ -41,6 +79,24 @@ defmodule Pleroma.Activity do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_by_ap_id_with_object(ap_id) do
|
||||||
|
Repo.one(
|
||||||
|
from(
|
||||||
|
activity in Activity,
|
||||||
|
where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)),
|
||||||
|
left_join: o in Object,
|
||||||
|
on:
|
||||||
|
fragment(
|
||||||
|
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||||
|
o.data,
|
||||||
|
activity.data,
|
||||||
|
activity.data
|
||||||
|
),
|
||||||
|
preload: [object: o]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def get_by_id(id) do
|
def get_by_id(id) do
|
||||||
Activity
|
Activity
|
||||||
|> where([a], a.id == ^id)
|
|> where([a], a.id == ^id)
|
||||||
@ -48,6 +104,22 @@ defmodule Pleroma.Activity do
|
|||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_by_id_with_object(id) do
|
||||||
|
from(activity in Activity,
|
||||||
|
where: activity.id == ^id,
|
||||||
|
inner_join: o in Object,
|
||||||
|
on:
|
||||||
|
fragment(
|
||||||
|
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||||
|
o.data,
|
||||||
|
activity.data,
|
||||||
|
activity.data
|
||||||
|
),
|
||||||
|
preload: [object: o]
|
||||||
|
)
|
||||||
|
|> Repo.one()
|
||||||
|
end
|
||||||
|
|
||||||
def by_object_ap_id(ap_id) do
|
def by_object_ap_id(ap_id) do
|
||||||
from(
|
from(
|
||||||
activity in Activity,
|
activity in Activity,
|
||||||
@ -75,7 +147,7 @@ defmodule Pleroma.Activity do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_by_object_ap_id(ap_id) do
|
def create_by_object_ap_id(ap_id) when is_binary(ap_id) do
|
||||||
from(
|
from(
|
||||||
activity in Activity,
|
activity in Activity,
|
||||||
where:
|
where:
|
||||||
@ -89,6 +161,8 @@ defmodule Pleroma.Activity do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_by_object_ap_id(_), do: nil
|
||||||
|
|
||||||
def get_all_create_by_object_ap_id(ap_id) do
|
def get_all_create_by_object_ap_id(ap_id) do
|
||||||
Repo.all(create_by_object_ap_id(ap_id))
|
Repo.all(create_by_object_ap_id(ap_id))
|
||||||
end
|
end
|
||||||
@ -101,8 +175,39 @@ defmodule Pleroma.Activity do
|
|||||||
|
|
||||||
def get_create_by_object_ap_id(_), do: nil
|
def get_create_by_object_ap_id(_), do: nil
|
||||||
|
|
||||||
def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"])
|
def create_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) do
|
||||||
def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id)
|
from(
|
||||||
|
activity in Activity,
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||||
|
activity.data,
|
||||||
|
activity.data,
|
||||||
|
^to_string(ap_id)
|
||||||
|
),
|
||||||
|
where: fragment("(?)->>'type' = 'Create'", activity.data),
|
||||||
|
inner_join: o in Object,
|
||||||
|
on:
|
||||||
|
fragment(
|
||||||
|
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||||
|
o.data,
|
||||||
|
activity.data,
|
||||||
|
activity.data
|
||||||
|
),
|
||||||
|
preload: [object: o]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_by_object_ap_id_with_object(_), do: nil
|
||||||
|
|
||||||
|
def get_create_by_object_ap_id_with_object(ap_id) do
|
||||||
|
ap_id
|
||||||
|
|> create_by_object_ap_id_with_object()
|
||||||
|
|> Repo.one()
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"])
|
||||||
|
def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id)
|
||||||
def normalize(_), do: nil
|
def normalize(_), do: nil
|
||||||
|
|
||||||
def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do
|
def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do
|
||||||
@ -111,6 +216,19 @@ defmodule Pleroma.Activity do
|
|||||||
|
|
||||||
def get_in_reply_to_activity(_), do: nil
|
def get_in_reply_to_activity(_), do: nil
|
||||||
|
|
||||||
|
def delete_by_ap_id(id) when is_binary(id) do
|
||||||
|
by_object_ap_id(id)
|
||||||
|
|> select([u], u)
|
||||||
|
|> Repo.delete_all()
|
||||||
|
|> elem(1)
|
||||||
|
|> Enum.find(fn
|
||||||
|
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
|
||||||
|
_ -> nil
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_by_ap_id(_), do: nil
|
||||||
|
|
||||||
for {ap_type, type} <- @mastodon_notification_types do
|
for {ap_type, type} <- @mastodon_notification_types do
|
||||||
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
|
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
|
||||||
do: unquote(type)
|
do: unquote(type)
|
||||||
@ -118,6 +236,10 @@ defmodule Pleroma.Activity do
|
|||||||
|
|
||||||
def mastodon_notification_type(%Activity{}), do: nil
|
def mastodon_notification_type(%Activity{}), do: nil
|
||||||
|
|
||||||
|
def from_mastodon_notification_type(type) do
|
||||||
|
Map.get(@mastodon_to_ap_notification_types, type)
|
||||||
|
end
|
||||||
|
|
||||||
def all_by_actor_and_id(actor, status_ids \\ [])
|
def all_by_actor_and_id(actor, status_ids \\ [])
|
||||||
def all_by_actor_and_id(_actor, []), do: []
|
def all_by_actor_and_id(_actor, []), do: []
|
||||||
|
|
||||||
@ -128,6 +250,52 @@ defmodule Pleroma.Activity do
|
|||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def increase_replies_count(id) do
|
||||||
|
Activity
|
||||||
|
|> where(id: ^id)
|
||||||
|
|> update([a],
|
||||||
|
set: [
|
||||||
|
data:
|
||||||
|
fragment(
|
||||||
|
"""
|
||||||
|
jsonb_set(?, '{object, repliesCount}',
|
||||||
|
(coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
|
||||||
|
""",
|
||||||
|
a.data,
|
||||||
|
a.data
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|> Repo.update_all([])
|
||||||
|
|> case do
|
||||||
|
{1, [activity]} -> activity
|
||||||
|
_ -> {:error, "Not found"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrease_replies_count(id) do
|
||||||
|
Activity
|
||||||
|
|> where(id: ^id)
|
||||||
|
|> update([a],
|
||||||
|
set: [
|
||||||
|
data:
|
||||||
|
fragment(
|
||||||
|
"""
|
||||||
|
jsonb_set(?, '{object, repliesCount}',
|
||||||
|
(greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
|
||||||
|
""",
|
||||||
|
a.data,
|
||||||
|
a.data
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|> Repo.update_all([])
|
||||||
|
|> case do
|
||||||
|
{1, [activity]} -> activity
|
||||||
|
_ -> {:error, "Not found"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def restrict_disabled_users(query) do
|
def restrict_disabled_users(query) do
|
||||||
from(activity in query,
|
from(activity in query,
|
||||||
where:
|
where:
|
||||||
|
@ -11,10 +11,10 @@ defmodule Pleroma.Application do
|
|||||||
@repository Mix.Project.config()[:source_url]
|
@repository Mix.Project.config()[:source_url]
|
||||||
def name, do: @name
|
def name, do: @name
|
||||||
def version, do: @version
|
def version, do: @version
|
||||||
def named_version(), do: @name <> " " <> @version
|
def named_version, do: @name <> " " <> @version
|
||||||
def repository, do: @repository
|
def repository, do: @repository
|
||||||
|
|
||||||
def user_agent() do
|
def user_agent do
|
||||||
info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
|
info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
|
||||||
named_version() <> "; " <> info
|
named_version() <> "; " <> info
|
||||||
end
|
end
|
||||||
@ -25,6 +25,7 @@ defmodule Pleroma.Application do
|
|||||||
import Cachex.Spec
|
import Cachex.Spec
|
||||||
|
|
||||||
Pleroma.Config.DeprecationWarnings.warn()
|
Pleroma.Config.DeprecationWarnings.warn()
|
||||||
|
setup_instrumenters()
|
||||||
|
|
||||||
# Define workers and child supervisors to be supervised
|
# Define workers and child supervisors to be supervised
|
||||||
children =
|
children =
|
||||||
@ -48,7 +49,7 @@ defmodule Pleroma.Application do
|
|||||||
[
|
[
|
||||||
:user_cache,
|
:user_cache,
|
||||||
[
|
[
|
||||||
default_ttl: 25000,
|
default_ttl: 25_000,
|
||||||
ttl_interval: 1000,
|
ttl_interval: 1000,
|
||||||
limit: 2500
|
limit: 2500
|
||||||
]
|
]
|
||||||
@ -60,7 +61,7 @@ defmodule Pleroma.Application do
|
|||||||
[
|
[
|
||||||
:object_cache,
|
:object_cache,
|
||||||
[
|
[
|
||||||
default_ttl: 25000,
|
default_ttl: 25_000,
|
||||||
ttl_interval: 1000,
|
ttl_interval: 1000,
|
||||||
limit: 2500
|
limit: 2500
|
||||||
]
|
]
|
||||||
@ -103,15 +104,15 @@ defmodule Pleroma.Application do
|
|||||||
],
|
],
|
||||||
id: :cachex_idem
|
id: :cachex_idem
|
||||||
),
|
),
|
||||||
worker(Pleroma.FlakeId, [])
|
worker(Pleroma.FlakeId, []),
|
||||||
|
worker(Pleroma.ScheduledActivityWorker, [])
|
||||||
] ++
|
] ++
|
||||||
hackney_pool_children() ++
|
hackney_pool_children() ++
|
||||||
[
|
[
|
||||||
worker(Pleroma.Web.Federator.RetryQueue, []),
|
worker(Pleroma.Web.Federator.RetryQueue, []),
|
||||||
worker(Pleroma.Stats, []),
|
worker(Pleroma.Stats, []),
|
||||||
worker(Pleroma.Web.Push, []),
|
worker(Task, [&Pleroma.Web.Push.init/0], restart: :temporary, id: :web_push_init),
|
||||||
worker(Pleroma.Jobs, []),
|
worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary, id: :federator_init)
|
||||||
worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary)
|
|
||||||
] ++
|
] ++
|
||||||
streamer_child() ++
|
streamer_child() ++
|
||||||
chat_child() ++
|
chat_child() ++
|
||||||
@ -127,7 +128,25 @@ defmodule Pleroma.Application do
|
|||||||
Supervisor.start_link(children, opts)
|
Supervisor.start_link(children, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_hackney_pools() do
|
defp setup_instrumenters do
|
||||||
|
require Prometheus.Registry
|
||||||
|
|
||||||
|
:ok =
|
||||||
|
:telemetry.attach(
|
||||||
|
"prometheus-ecto",
|
||||||
|
[:pleroma, :repo, :query],
|
||||||
|
&Pleroma.Repo.Instrumenter.handle_event/4,
|
||||||
|
%{}
|
||||||
|
)
|
||||||
|
|
||||||
|
Prometheus.Registry.register_collector(:prometheus_process_collector)
|
||||||
|
Pleroma.Web.Endpoint.MetricsExporter.setup()
|
||||||
|
Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
|
||||||
|
Pleroma.Web.Endpoint.Instrumenter.setup()
|
||||||
|
Pleroma.Repo.Instrumenter.setup()
|
||||||
|
end
|
||||||
|
|
||||||
|
def enabled_hackney_pools do
|
||||||
[:media] ++
|
[:media] ++
|
||||||
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
|
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do
|
||||||
[:federation]
|
[:federation]
|
||||||
@ -142,14 +161,14 @@ defmodule Pleroma.Application do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Mix.env() == :test do
|
if Mix.env() == :test do
|
||||||
defp streamer_child(), do: []
|
defp streamer_child, do: []
|
||||||
defp chat_child(), do: []
|
defp chat_child, do: []
|
||||||
else
|
else
|
||||||
defp streamer_child() do
|
defp streamer_child do
|
||||||
[worker(Pleroma.Web.Streamer, [])]
|
[worker(Pleroma.Web.Streamer, [])]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp chat_child() do
|
defp chat_child do
|
||||||
if Pleroma.Config.get([:chat, :enabled]) do
|
if Pleroma.Config.get([:chat, :enabled]) do
|
||||||
[worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
|
[worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
|
||||||
else
|
else
|
||||||
@ -158,7 +177,7 @@ defmodule Pleroma.Application do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp hackney_pool_children() do
|
defp hackney_pool_children do
|
||||||
for pool <- enabled_hackney_pools() do
|
for pool <- enabled_hackney_pools() do
|
||||||
options = Pleroma.Config.get([:hackney_pools, pool])
|
options = Pleroma.Config.get([:hackney_pools, pool])
|
||||||
:hackney_pool.child_spec(pool, options)
|
:hackney_pool.child_spec(pool, options)
|
||||||
|
@ -10,7 +10,7 @@ defmodule Pleroma.Captcha do
|
|||||||
use GenServer
|
use GenServer
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def start_link() do
|
def start_link do
|
||||||
GenServer.start_link(__MODULE__, [], name: __MODULE__)
|
GenServer.start_link(__MODULE__, [], name: __MODULE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ defmodule Pleroma.Captcha do
|
|||||||
@doc """
|
@doc """
|
||||||
Ask the configured captcha service for a new captcha
|
Ask the configured captcha service for a new captcha
|
||||||
"""
|
"""
|
||||||
def new() do
|
def new do
|
||||||
GenServer.call(__MODULE__, :new)
|
GenServer.call(__MODULE__, :new)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ defmodule Pleroma.Captcha do
|
|||||||
secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt")
|
secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt")
|
||||||
sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign")
|
sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign")
|
||||||
|
|
||||||
# If the time found is less than (current_time - seconds_valid), then the time has already passed.
|
# If the time found is less than (current_time-seconds_valid) then the time has already passed
|
||||||
# Later we check that the time found is more than the presumed invalidatation time, that means
|
# Later we check that the time found is more than the presumed invalidatation time, that means
|
||||||
# that the data is still valid and the captcha can be checked
|
# that the data is still valid and the captcha can be checked
|
||||||
seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid])
|
seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid])
|
||||||
|
@ -7,7 +7,7 @@ defmodule Pleroma.Captcha.Kocaptcha do
|
|||||||
@behaviour Service
|
@behaviour Service
|
||||||
|
|
||||||
@impl Service
|
@impl Service
|
||||||
def new() do
|
def new do
|
||||||
endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
|
endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
|
||||||
|
|
||||||
case Tesla.get(endpoint <> "/new") do
|
case Tesla.get(endpoint <> "/new") do
|
||||||
|
@ -7,13 +7,13 @@ defmodule Pleroma.Clippy do
|
|||||||
# No software is complete until they have a Clippy implementation.
|
# No software is complete until they have a Clippy implementation.
|
||||||
# A ballmer peak _may_ be required to change this module.
|
# A ballmer peak _may_ be required to change this module.
|
||||||
|
|
||||||
def tip() do
|
def tip do
|
||||||
tips()
|
tips()
|
||||||
|> Enum.random()
|
|> Enum.random()
|
||||||
|> puts()
|
|> puts()
|
||||||
end
|
end
|
||||||
|
|
||||||
def tips() do
|
def tips do
|
||||||
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||||
|
|
||||||
[
|
[
|
||||||
@ -92,8 +92,8 @@ defmodule Pleroma.Clippy do
|
|||||||
|
|
||||||
# surrond one/five line clippy with blank lines around to not fuck up the layout
|
# surrond one/five line clippy with blank lines around to not fuck up the layout
|
||||||
#
|
#
|
||||||
# yes this fix sucks but it's good enough, have you ever seen a release of windows wihtout some butched
|
# yes this fix sucks but it's good enough, have you ever seen a release of windows
|
||||||
# features anyway?
|
# without some butched features anyway?
|
||||||
lines =
|
lines =
|
||||||
if length(lines) == 1 or length(lines) == 5 do
|
if length(lines) == 1 or length(lines) == 5 do
|
||||||
[""] ++ lines ++ [""]
|
[""] ++ lines ++ [""]
|
||||||
|
@ -57,4 +57,8 @@ defmodule Pleroma.Config do
|
|||||||
def delete(key) do
|
def delete(key) do
|
||||||
Application.delete_env(:pleroma, key)
|
Application.delete_env(:pleroma, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], [])
|
||||||
|
|
||||||
|
def oauth_consumer_enabled?, do: oauth_consumer_strategies() != []
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
defmodule Pleroma.Config.DeprecationWarnings do
|
defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def check_frontend_config_mechanism() do
|
def check_frontend_config_mechanism do
|
||||||
if Pleroma.Config.get(:fe) do
|
if Pleroma.Config.get(:fe) do
|
||||||
Logger.warn("""
|
Logger.warn("""
|
||||||
!!!DEPRECATION WARNING!!!
|
!!!DEPRECATION WARNING!!!
|
||||||
|
@ -29,9 +29,13 @@ defmodule Pleroma.AdminEmail do
|
|||||||
if length(statuses) > 0 do
|
if length(statuses) > 0 do
|
||||||
statuses_list_html =
|
statuses_list_html =
|
||||||
statuses
|
statuses
|
||||||
|> Enum.map(fn %{id: id} ->
|
|> Enum.map(fn
|
||||||
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
|
%{id: id} ->
|
||||||
"<li><a href=\"#{status_url}\">#{status_url}</li>"
|
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
|
||||||
|
"<li><a href=\"#{status_url}\">#{status_url}</li>"
|
||||||
|
|
||||||
|
id when is_binary(id) ->
|
||||||
|
"<li><a href=\"#{id}\">#{id}</li>"
|
||||||
end)
|
end)
|
||||||
|> Enum.join("\n")
|
|> Enum.join("\n")
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ defmodule Pleroma.Mailer do
|
|||||||
use Swoosh.Mailer, otp_app: :pleroma
|
use Swoosh.Mailer, otp_app: :pleroma
|
||||||
|
|
||||||
def deliver_async(email, config \\ []) do
|
def deliver_async(email, config \\ []) do
|
||||||
Pleroma.Jobs.enqueue(:mailer, __MODULE__, [:deliver_async, email, config])
|
PleromaJobQueue.enqueue(:mailer, __MODULE__, [:deliver_async, email, config])
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(:deliver_async, email, config), do: deliver(email, config)
|
def perform(:deliver_async, email, config), do: deliver(email, config)
|
||||||
|
@ -8,22 +8,28 @@ defmodule Pleroma.Emoji do
|
|||||||
|
|
||||||
* the built-in Finmojis (if enabled in configuration),
|
* the built-in Finmojis (if enabled in configuration),
|
||||||
* the files: `config/emoji.txt` and `config/custom_emoji.txt`
|
* the files: `config/emoji.txt` and `config/custom_emoji.txt`
|
||||||
* glob paths
|
* glob paths, nested folder is used as tag name for grouping e.g. priv/static/emoji/custom/nested_folder
|
||||||
|
|
||||||
This GenServer stores in an ETS table the list of the loaded emojis, and also allows to reload the list at runtime.
|
This GenServer stores in an ETS table the list of the loaded emojis, and also allows to reload the list at runtime.
|
||||||
"""
|
"""
|
||||||
use GenServer
|
use GenServer
|
||||||
|
|
||||||
|
@type pattern :: Regex.t() | module() | String.t()
|
||||||
|
@type patterns :: pattern() | [pattern()]
|
||||||
|
@type group_patterns :: keyword(patterns())
|
||||||
|
|
||||||
@ets __MODULE__.Ets
|
@ets __MODULE__.Ets
|
||||||
@ets_options [:ordered_set, :protected, :named_table, {:read_concurrency, true}]
|
@ets_options [:ordered_set, :protected, :named_table, {:read_concurrency, true}]
|
||||||
|
@groups Application.get_env(:pleroma, :emoji)[:groups]
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def start_link() do
|
def start_link do
|
||||||
GenServer.start_link(__MODULE__, [], name: __MODULE__)
|
GenServer.start_link(__MODULE__, [], name: __MODULE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Reloads the emojis from disk."
|
@doc "Reloads the emojis from disk."
|
||||||
@spec reload() :: :ok
|
@spec reload() :: :ok
|
||||||
def reload() do
|
def reload do
|
||||||
GenServer.call(__MODULE__, :reload)
|
GenServer.call(__MODULE__, :reload)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -38,7 +44,7 @@ defmodule Pleroma.Emoji do
|
|||||||
|
|
||||||
@doc "Returns all the emojos!!"
|
@doc "Returns all the emojos!!"
|
||||||
@spec get_all() :: [{String.t(), String.t()}, ...]
|
@spec get_all() :: [{String.t(), String.t()}, ...]
|
||||||
def get_all() do
|
def get_all do
|
||||||
:ets.tab2list(@ets)
|
:ets.tab2list(@ets)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -72,14 +78,15 @@ defmodule Pleroma.Emoji do
|
|||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp load() do
|
defp load do
|
||||||
|
finmoji_enabled = Keyword.get(Application.get_env(:pleroma, :instance), :finmoji_enabled)
|
||||||
|
shortcode_globs = Application.get_env(:pleroma, :emoji)[:shortcode_globs] || []
|
||||||
|
|
||||||
emojis =
|
emojis =
|
||||||
(load_finmoji(Keyword.get(Application.get_env(:pleroma, :instance), :finmoji_enabled)) ++
|
(load_finmoji(finmoji_enabled) ++
|
||||||
load_from_file("config/emoji.txt") ++
|
load_from_file("config/emoji.txt") ++
|
||||||
load_from_file("config/custom_emoji.txt") ++
|
load_from_file("config/custom_emoji.txt") ++
|
||||||
load_from_globs(
|
load_from_globs(shortcode_globs))
|
||||||
Keyword.get(Application.get_env(:pleroma, :emoji, []), :shortcode_globs, [])
|
|
||||||
))
|
|
||||||
|> Enum.reject(fn value -> value == nil end)
|
|> Enum.reject(fn value -> value == nil end)
|
||||||
|
|
||||||
true = :ets.insert(@ets, emojis)
|
true = :ets.insert(@ets, emojis)
|
||||||
@ -151,9 +158,12 @@ defmodule Pleroma.Emoji do
|
|||||||
"white_nights",
|
"white_nights",
|
||||||
"woollysocks"
|
"woollysocks"
|
||||||
]
|
]
|
||||||
|
|
||||||
defp load_finmoji(true) do
|
defp load_finmoji(true) do
|
||||||
Enum.map(@finmoji, fn finmoji ->
|
Enum.map(@finmoji, fn finmoji ->
|
||||||
{finmoji, "/finmoji/128px/#{finmoji}-128.png"}
|
file_name = "/finmoji/128px/#{finmoji}-128.png"
|
||||||
|
group = match_extra(@groups, file_name)
|
||||||
|
{finmoji, file_name, to_string(group)}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -172,8 +182,14 @@ defmodule Pleroma.Emoji do
|
|||||||
|> Stream.map(&String.trim/1)
|
|> Stream.map(&String.trim/1)
|
||||||
|> Stream.map(fn line ->
|
|> Stream.map(fn line ->
|
||||||
case String.split(line, ~r/,\s*/) do
|
case String.split(line, ~r/,\s*/) do
|
||||||
[name, file] -> {name, file}
|
[name, file, tags] ->
|
||||||
_ -> nil
|
{name, file, tags}
|
||||||
|
|
||||||
|
[name, file] ->
|
||||||
|
{name, file, to_string(match_extra(@groups, file))}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> Enum.to_list()
|
|> Enum.to_list()
|
||||||
@ -190,9 +206,40 @@ defmodule Pleroma.Emoji do
|
|||||||
|> Enum.concat()
|
|> Enum.concat()
|
||||||
|
|
||||||
Enum.map(paths, fn path ->
|
Enum.map(paths, fn path ->
|
||||||
|
tag = match_extra(@groups, Path.join("/", Path.relative_to(path, static_path)))
|
||||||
shortcode = Path.basename(path, Path.extname(path))
|
shortcode = Path.basename(path, Path.extname(path))
|
||||||
external_path = Path.join("/", Path.relative_to(path, static_path))
|
external_path = Path.join("/", Path.relative_to(path, static_path))
|
||||||
{shortcode, external_path}
|
{shortcode, external_path, to_string(tag)}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Finds a matching group for the given emoji filename
|
||||||
|
"""
|
||||||
|
@spec match_extra(group_patterns(), String.t()) :: atom() | nil
|
||||||
|
def match_extra(group_patterns, filename) do
|
||||||
|
match_group_patterns(group_patterns, fn pattern ->
|
||||||
|
case pattern do
|
||||||
|
%Regex{} = regex -> Regex.match?(regex, filename)
|
||||||
|
string when is_binary(string) -> filename == string
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp match_group_patterns(group_patterns, matcher) do
|
||||||
|
Enum.find_value(group_patterns, fn {group, patterns} ->
|
||||||
|
patterns =
|
||||||
|
patterns
|
||||||
|
|> List.wrap()
|
||||||
|
|> Enum.map(fn pattern ->
|
||||||
|
if String.contains?(pattern, "*") do
|
||||||
|
~r(#{String.replace(pattern, "*", ".*")})
|
||||||
|
else
|
||||||
|
pattern
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Enum.any?(patterns, matcher) && group
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,8 @@ defmodule Pleroma.Filter do
|
|||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
schema "filters" do
|
schema "filters" do
|
||||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||||
|
@ -46,7 +46,7 @@ defmodule Pleroma.FlakeId do
|
|||||||
|
|
||||||
def from_string(string) when is_binary(string) and byte_size(string) < 18 do
|
def from_string(string) when is_binary(string) and byte_size(string) < 18 do
|
||||||
case Integer.parse(string) do
|
case Integer.parse(string) do
|
||||||
{id, _} -> <<0::integer-size(64), id::integer-size(64)>>
|
{id, ""} -> <<0::integer-size(64), id::integer-size(64)>>
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -85,7 +85,7 @@ defmodule Pleroma.FlakeId do
|
|||||||
{:ok, FlakeId.from_string(value)}
|
{:ok, FlakeId.from_string(value)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def autogenerate(), do: get()
|
def autogenerate, do: get()
|
||||||
|
|
||||||
# -- GenServer API
|
# -- GenServer API
|
||||||
def start_link do
|
def start_link do
|
||||||
@ -165,7 +165,7 @@ defmodule Pleroma.FlakeId do
|
|||||||
1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000)
|
1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp worker_id() do
|
defp worker_id do
|
||||||
<<worker::integer-size(48)>> = :crypto.strong_rand_bytes(6)
|
<<worker::integer-size(48)>> = :crypto.strong_rand_bytes(6)
|
||||||
worker
|
worker
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,10 @@ defmodule Pleroma.Formatter do
|
|||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
|
@safe_mention_regex ~r/^(\s*(?<mentions>@.+?\s+)+)(?<rest>.*)/
|
||||||
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
||||||
@link_regex ~r{((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+}ui
|
@link_regex ~r{((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+}ui
|
||||||
|
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
||||||
|
|
||||||
@auto_linker_config hashtag: true,
|
@auto_linker_config hashtag: true,
|
||||||
hashtag_handler: &Pleroma.Formatter.hashtag_handler/4,
|
hashtag_handler: &Pleroma.Formatter.hashtag_handler/4,
|
||||||
@ -44,15 +46,28 @@ defmodule Pleroma.Formatter do
|
|||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Parses a text and replace plain text links with HTML. Returns a tuple with a result text, mentions, and hashtags.
|
Parses a text and replace plain text links with HTML. Returns a tuple with a result text, mentions, and hashtags.
|
||||||
|
|
||||||
|
If the 'safe_mention' option is given, only consecutive mentions at the start the post are actually mentioned.
|
||||||
"""
|
"""
|
||||||
@spec linkify(String.t(), keyword()) ::
|
@spec linkify(String.t(), keyword()) ::
|
||||||
{String.t(), [{String.t(), User.t()}], [{String.t(), String.t()}]}
|
{String.t(), [{String.t(), User.t()}], [{String.t(), String.t()}]}
|
||||||
def linkify(text, options \\ []) do
|
def linkify(text, options \\ []) do
|
||||||
options = options ++ @auto_linker_config
|
options = options ++ @auto_linker_config
|
||||||
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
|
|
||||||
{text, %{mentions: mentions, tags: tags}} = AutoLinker.link_map(text, acc, options)
|
|
||||||
|
|
||||||
{text, MapSet.to_list(mentions), MapSet.to_list(tags)}
|
if options[:safe_mention] && Regex.named_captures(@safe_mention_regex, text) do
|
||||||
|
%{"mentions" => mentions, "rest" => rest} = Regex.named_captures(@safe_mention_regex, text)
|
||||||
|
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
|
||||||
|
|
||||||
|
{text_mentions, %{mentions: mentions}} = AutoLinker.link_map(mentions, acc, options)
|
||||||
|
{text_rest, %{tags: tags}} = AutoLinker.link_map(rest, acc, options)
|
||||||
|
|
||||||
|
{text_mentions <> text_rest, MapSet.to_list(mentions), MapSet.to_list(tags)}
|
||||||
|
else
|
||||||
|
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
|
||||||
|
{text, %{mentions: mentions, tags: tags}} = AutoLinker.link_map(text, acc, options)
|
||||||
|
|
||||||
|
{text, MapSet.to_list(mentions), MapSet.to_list(tags)}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def emojify(text) do
|
def emojify(text) do
|
||||||
@ -62,9 +77,9 @@ defmodule Pleroma.Formatter do
|
|||||||
def emojify(text, nil), do: text
|
def emojify(text, nil), do: text
|
||||||
|
|
||||||
def emojify(text, emoji, strip \\ false) do
|
def emojify(text, emoji, strip \\ false) do
|
||||||
Enum.reduce(emoji, text, fn {emoji, file}, text ->
|
Enum.reduce(emoji, text, fn emoji_data, text ->
|
||||||
emoji = HTML.strip_tags(emoji)
|
emoji = HTML.strip_tags(elem(emoji_data, 0))
|
||||||
file = HTML.strip_tags(file)
|
file = HTML.strip_tags(elem(emoji_data, 1))
|
||||||
|
|
||||||
html =
|
html =
|
||||||
if not strip do
|
if not strip do
|
||||||
@ -86,7 +101,7 @@ defmodule Pleroma.Formatter do
|
|||||||
def demojify(text, nil), do: text
|
def demojify(text, nil), do: text
|
||||||
|
|
||||||
def get_emoji(text) when is_binary(text) do
|
def get_emoji(text) when is_binary(text) do
|
||||||
Enum.filter(Emoji.get_all(), fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end)
|
Enum.filter(Emoji.get_all(), fn {emoji, _, _} -> String.contains?(text, ":#{emoji}:") end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_emoji(_), do: []
|
def get_emoji(_), do: []
|
||||||
|
@ -6,7 +6,7 @@ defmodule Pleroma.Gopher.Server do
|
|||||||
use GenServer
|
use GenServer
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def start_link() do
|
def start_link do
|
||||||
config = Pleroma.Config.get(:gopher, [])
|
config = Pleroma.Config.get(:gopher, [])
|
||||||
ip = Keyword.get(config, :ip, {0, 0, 0, 0})
|
ip = Keyword.get(config, :ip, {0, 0, 0, 0})
|
||||||
port = Keyword.get(config, :port, 1234)
|
port = Keyword.get(config, :port, 1234)
|
||||||
@ -36,11 +36,11 @@ defmodule Pleroma.Gopher.Server do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
|
||||||
def start_link(ref, socket, transport, opts) do
|
def start_link(ref, socket, transport, opts) do
|
||||||
pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts])
|
pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts])
|
||||||
@ -65,7 +65,8 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
|||||||
def link(name, selector, type \\ 1) do
|
def link(name, selector, type \\ 1) do
|
||||||
address = Pleroma.Web.Endpoint.host()
|
address = Pleroma.Web.Endpoint.host()
|
||||||
port = Pleroma.Config.get([:gopher, :port], 1234)
|
port = Pleroma.Config.get([:gopher, :port], 1234)
|
||||||
"#{type}#{name}\t#{selector}\t#{address}\t#{port}\r\n"
|
dstport = Pleroma.Config.get([:gopher, :dstport], port)
|
||||||
|
"#{type}#{name}\t#{selector}\t#{address}\t#{dstport}\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_activities(activities) do
|
def render_activities(activities) do
|
||||||
|
@ -9,7 +9,7 @@ defmodule Pleroma.HTML do
|
|||||||
defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers
|
defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers
|
||||||
defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default]
|
defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default]
|
||||||
|
|
||||||
def get_scrubbers() do
|
def get_scrubbers do
|
||||||
Pleroma.Config.get([:markup, :scrub_policy])
|
Pleroma.Config.get([:markup, :scrub_policy])
|
||||||
|> get_scrubbers
|
|> get_scrubbers
|
||||||
end
|
end
|
||||||
@ -28,27 +28,39 @@ defmodule Pleroma.HTML do
|
|||||||
def filter_tags(html), do: filter_tags(html, nil)
|
def filter_tags(html), do: filter_tags(html, nil)
|
||||||
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
|
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
|
||||||
|
|
||||||
def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do
|
def get_cached_scrubbed_html_for_activity(content, scrubbers, activity, key \\ "") do
|
||||||
key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}"
|
key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
|
||||||
Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end)
|
|
||||||
|
Cachex.fetch!(:scrubber_cache, key, fn _key ->
|
||||||
|
ensure_scrubbed_html(content, scrubbers, activity.data["object"]["fake"] || false)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cached_stripped_html_for_object(content, object, module) do
|
def get_cached_stripped_html_for_activity(content, activity, key) do
|
||||||
get_cached_scrubbed_html_for_object(
|
get_cached_scrubbed_html_for_activity(
|
||||||
content,
|
content,
|
||||||
HtmlSanitizeEx.Scrubber.StripTags,
|
HtmlSanitizeEx.Scrubber.StripTags,
|
||||||
object,
|
activity,
|
||||||
module
|
key
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_scrubbed_html(
|
def ensure_scrubbed_html(
|
||||||
content,
|
content,
|
||||||
scrubbers
|
scrubbers,
|
||||||
|
false = _fake
|
||||||
) do
|
) do
|
||||||
{:commit, filter_tags(content, scrubbers)}
|
{:commit, filter_tags(content, scrubbers)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_scrubbed_html(
|
||||||
|
content,
|
||||||
|
scrubbers,
|
||||||
|
true = _fake
|
||||||
|
) do
|
||||||
|
{:ignore, filter_tags(content, scrubbers)}
|
||||||
|
end
|
||||||
|
|
||||||
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
|
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
|
||||||
generate_scrubber_signature([scrubber])
|
generate_scrubber_signature([scrubber])
|
||||||
end
|
end
|
||||||
@ -95,6 +107,13 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do
|
|||||||
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
||||||
Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"])
|
Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"])
|
||||||
|
|
||||||
|
Meta.allow_tag_with_this_attribute_values("a", "rel", [
|
||||||
|
"tag",
|
||||||
|
"nofollow",
|
||||||
|
"noopener",
|
||||||
|
"noreferrer"
|
||||||
|
])
|
||||||
|
|
||||||
# paragraphs and linebreaks
|
# paragraphs and linebreaks
|
||||||
Meta.allow_tag_with_these_attributes("br", [])
|
Meta.allow_tag_with_these_attributes("br", [])
|
||||||
Meta.allow_tag_with_these_attributes("p", [])
|
Meta.allow_tag_with_these_attributes("p", [])
|
||||||
@ -137,6 +156,13 @@ defmodule Pleroma.HTML.Scrubber.Default do
|
|||||||
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
||||||
Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"])
|
Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"])
|
||||||
|
|
||||||
|
Meta.allow_tag_with_this_attribute_values("a", "rel", [
|
||||||
|
"tag",
|
||||||
|
"nofollow",
|
||||||
|
"noopener",
|
||||||
|
"noreferrer"
|
||||||
|
])
|
||||||
|
|
||||||
Meta.allow_tag_with_these_attributes("abbr", ["title"])
|
Meta.allow_tag_with_these_attributes("abbr", ["title"])
|
||||||
|
|
||||||
Meta.allow_tag_with_these_attributes("b", [])
|
Meta.allow_tag_with_these_attributes("b", [])
|
||||||
|
@ -8,8 +8,8 @@ defmodule Pleroma.HTTP.Connection do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@hackney_options [
|
@hackney_options [
|
||||||
timeout: 10000,
|
connect_timeout: 2_000,
|
||||||
recv_timeout: 20000,
|
recv_timeout: 20_000,
|
||||||
follow_redirect: true,
|
follow_redirect: true,
|
||||||
pool: :federation
|
pool: :federation
|
||||||
]
|
]
|
||||||
@ -31,6 +31,10 @@ defmodule Pleroma.HTTP.Connection do
|
|||||||
#
|
#
|
||||||
defp hackney_options(opts) do
|
defp hackney_options(opts) do
|
||||||
options = Keyword.get(opts, :adapter, [])
|
options = Keyword.get(opts, :adapter, [])
|
||||||
@hackney_options ++ options
|
adapter_options = Pleroma.Config.get([:http, :adapter], [])
|
||||||
|
|
||||||
|
@hackney_options
|
||||||
|
|> Keyword.merge(adapter_options)
|
||||||
|
|> Keyword.merge(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,21 +27,29 @@ defmodule Pleroma.HTTP do
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
def request(method, url, body \\ "", headers \\ [], options \\ []) do
|
def request(method, url, body \\ "", headers \\ [], options \\ []) do
|
||||||
options =
|
try do
|
||||||
process_request_options(options)
|
options =
|
||||||
|> process_sni_options(url)
|
process_request_options(options)
|
||||||
|
|> process_sni_options(url)
|
||||||
|
|
||||||
params = Keyword.get(options, :params, [])
|
params = Keyword.get(options, :params, [])
|
||||||
|
|
||||||
%{}
|
%{}
|
||||||
|> Builder.method(method)
|
|> Builder.method(method)
|
||||||
|> Builder.headers(headers)
|
|> Builder.headers(headers)
|
||||||
|> Builder.opts(options)
|
|> Builder.opts(options)
|
||||||
|> Builder.url(url)
|
|> Builder.url(url)
|
||||||
|> Builder.add_param(:body, :body, body)
|
|> Builder.add_param(:body, :body, body)
|
||||||
|> Builder.add_param(:query, :query, params)
|
|> Builder.add_param(:query, :query, params)
|
||||||
|> Enum.into([])
|
|> Enum.into([])
|
||||||
|> (&Tesla.request(Connection.new(), &1)).()
|
|> (&Tesla.request(Connection.new(options), &1)).()
|
||||||
|
rescue
|
||||||
|
e ->
|
||||||
|
{:error, e}
|
||||||
|
catch
|
||||||
|
:exit, e ->
|
||||||
|
{:error, e}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_sni_options(options, nil), do: options
|
defp process_sni_options(options, nil), do: options
|
||||||
|
@ -2,8 +2,8 @@ defmodule Pleroma.Instances.Instance do
|
|||||||
@moduledoc "Instance."
|
@moduledoc "Instance."
|
||||||
|
|
||||||
alias Pleroma.Instances
|
alias Pleroma.Instances
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.Instances.Instance
|
alias Pleroma.Instances.Instance
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ defmodule Pleroma.Instances.Instance do
|
|||||||
|
|
||||||
schema "instances" do
|
schema "instances" do
|
||||||
field(:host, :string)
|
field(:host, :string)
|
||||||
field(:unreachable_since, :naive_datetime)
|
field(:unreachable_since, :naive_datetime_usec)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
@ -1,152 +0,0 @@
|
|||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Jobs do
|
|
||||||
@moduledoc """
|
|
||||||
A basic job queue
|
|
||||||
"""
|
|
||||||
use GenServer
|
|
||||||
|
|
||||||
require Logger
|
|
||||||
|
|
||||||
def init(args) do
|
|
||||||
{:ok, args}
|
|
||||||
end
|
|
||||||
|
|
||||||
def start_link do
|
|
||||||
queues =
|
|
||||||
Pleroma.Config.get(Pleroma.Jobs)
|
|
||||||
|> Enum.map(fn {name, _} -> create_queue(name) end)
|
|
||||||
|> Enum.into(%{})
|
|
||||||
|
|
||||||
state = %{
|
|
||||||
queues: queues,
|
|
||||||
refs: %{}
|
|
||||||
}
|
|
||||||
|
|
||||||
GenServer.start_link(__MODULE__, state, name: __MODULE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_queue(name) do
|
|
||||||
{name, {:sets.new(), []}}
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Enqueues a job.
|
|
||||||
|
|
||||||
Returns `:ok`.
|
|
||||||
|
|
||||||
## Arguments
|
|
||||||
|
|
||||||
- `queue_name` - a queue name(must be specified in the config).
|
|
||||||
- `mod` - a worker module (must have `perform` function).
|
|
||||||
- `args` - a list of arguments for the `perform` function of the worker module.
|
|
||||||
- `priority` - a job priority (`0` by default).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
Enqueue `Module.perform/0` with `priority=1`:
|
|
||||||
|
|
||||||
iex> Pleroma.Jobs.enqueue(:example_queue, Module, [])
|
|
||||||
:ok
|
|
||||||
|
|
||||||
Enqueue `Module.perform(:job_name)` with `priority=5`:
|
|
||||||
|
|
||||||
iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:job_name], 5)
|
|
||||||
:ok
|
|
||||||
|
|
||||||
Enqueue `Module.perform(:another_job, data)` with `priority=1`:
|
|
||||||
|
|
||||||
iex> data = "foobar"
|
|
||||||
iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:another_job, data])
|
|
||||||
:ok
|
|
||||||
|
|
||||||
Enqueue `Module.perform(:foobar_job, :foo, :bar, 42)` with `priority=1`:
|
|
||||||
|
|
||||||
iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:foobar_job, :foo, :bar, 42])
|
|
||||||
:ok
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def enqueue(queue_name, mod, args, priority \\ 1)
|
|
||||||
|
|
||||||
if Mix.env() == :test do
|
|
||||||
def enqueue(_queue_name, mod, args, _priority) do
|
|
||||||
apply(mod, :perform, args)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@spec enqueue(atom(), atom(), [any()], integer()) :: :ok
|
|
||||||
def enqueue(queue_name, mod, args, priority) do
|
|
||||||
GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_cast({:enqueue, queue_name, mod, args, priority}, state) do
|
|
||||||
{running_jobs, queue} = state[:queues][queue_name]
|
|
||||||
|
|
||||||
queue = enqueue_sorted(queue, {mod, args}, priority)
|
|
||||||
|
|
||||||
state =
|
|
||||||
state
|
|
||||||
|> update_queue(queue_name, {running_jobs, queue})
|
|
||||||
|> maybe_start_job(queue_name, running_jobs, queue)
|
|
||||||
|
|
||||||
{:noreply, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do
|
|
||||||
queue_name = state.refs[ref]
|
|
||||||
|
|
||||||
{running_jobs, queue} = state[:queues][queue_name]
|
|
||||||
|
|
||||||
running_jobs = :sets.del_element(ref, running_jobs)
|
|
||||||
|
|
||||||
state =
|
|
||||||
state
|
|
||||||
|> remove_ref(ref)
|
|
||||||
|> update_queue(queue_name, {running_jobs, queue})
|
|
||||||
|> maybe_start_job(queue_name, running_jobs, queue)
|
|
||||||
|
|
||||||
{:noreply, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_start_job(state, queue_name, running_jobs, queue) do
|
|
||||||
if :sets.size(running_jobs) < Pleroma.Config.get([__MODULE__, queue_name, :max_jobs]) &&
|
|
||||||
queue != [] do
|
|
||||||
{{mod, args}, queue} = queue_pop(queue)
|
|
||||||
{:ok, pid} = Task.start(fn -> apply(mod, :perform, args) end)
|
|
||||||
mref = Process.monitor(pid)
|
|
||||||
|
|
||||||
state
|
|
||||||
|> add_ref(queue_name, mref)
|
|
||||||
|> update_queue(queue_name, {:sets.add_element(mref, running_jobs), queue})
|
|
||||||
else
|
|
||||||
state
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def enqueue_sorted(queue, element, priority) do
|
|
||||||
[%{item: element, priority: priority} | queue]
|
|
||||||
|> Enum.sort_by(fn %{priority: priority} -> priority end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def queue_pop([%{item: element} | queue]) do
|
|
||||||
{element, queue}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp add_ref(state, queue_name, ref) do
|
|
||||||
refs = Map.put(state[:refs], ref, queue_name)
|
|
||||||
Map.put(state, :refs, refs)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp remove_ref(state, ref) do
|
|
||||||
refs = Map.delete(state[:refs], ref)
|
|
||||||
Map.put(state, :refs, refs)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp update_queue(state, queue_name, data) do
|
|
||||||
queues = Map.put(state[:queues], queue_name, data)
|
|
||||||
Map.put(state, :queues, queues)
|
|
||||||
end
|
|
||||||
end
|
|
@ -80,7 +80,7 @@ defmodule Pleroma.List do
|
|||||||
|
|
||||||
# Get lists to which the account belongs.
|
# Get lists to which the account belongs.
|
||||||
def get_lists_account_belongs(%User{} = owner, account_id) do
|
def get_lists_account_belongs(%User{} = owner, account_id) do
|
||||||
user = Repo.get(User, account_id)
|
user = User.get_by_id(account_id)
|
||||||
|
|
||||||
query =
|
query =
|
||||||
from(
|
from(
|
||||||
|
@ -5,14 +5,17 @@
|
|||||||
defmodule Pleroma.Notification do
|
defmodule Pleroma.Notification do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Pagination
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
schema "notifications" do
|
schema "notifications" do
|
||||||
field(:seen, :boolean, default: false)
|
field(:seen, :boolean, default: false)
|
||||||
@ -22,36 +25,37 @@ defmodule Pleroma.Notification do
|
|||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Make generic and unify (see activity_pub.ex)
|
def changeset(%Notification{} = notification, attrs) do
|
||||||
defp restrict_max(query, %{"max_id" => max_id}) do
|
notification
|
||||||
from(activity in query, where: activity.id < ^max_id)
|
|> cast(attrs, [:seen])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_max(query, _), do: query
|
def for_user_query(user) do
|
||||||
|
Notification
|
||||||
defp restrict_since(query, %{"since_id" => since_id}) do
|
|> where(user_id: ^user.id)
|
||||||
from(activity in query, where: activity.id > ^since_id)
|
|> where(
|
||||||
end
|
[n, a],
|
||||||
|
fragment(
|
||||||
defp restrict_since(query, _), do: query
|
"? not in (SELECT ap_id FROM users WHERE info->'disabled' @> 'true')",
|
||||||
|
a.actor
|
||||||
def for_user(user, opts \\ %{}) do
|
)
|
||||||
from(
|
)
|
||||||
n in Notification,
|
|> join(:inner, [n], activity in assoc(n, :activity))
|
||||||
where: n.user_id == ^user.id,
|
|> join(:left, [n, a], object in Object,
|
||||||
order_by: [desc: n.id],
|
on:
|
||||||
join: activity in assoc(n, :activity),
|
|
||||||
preload: [activity: activity],
|
|
||||||
limit: 20,
|
|
||||||
where:
|
|
||||||
fragment(
|
fragment(
|
||||||
"? not in (SELECT ap_id FROM users WHERE info->'disabled' @> 'true')",
|
"(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
|
||||||
activity.actor
|
object.data,
|
||||||
|
a.data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> restrict_since(opts)
|
|> preload([n, a, o], activity: {a, object: o})
|
||||||
|> restrict_max(opts)
|
end
|
||||||
|> Repo.all()
|
|
||||||
|
def for_user(user, opts \\ %{}) do
|
||||||
|
user
|
||||||
|
|> for_user_query()
|
||||||
|
|> Pagination.fetch_paginated(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_read_up_to(%{id: user_id} = _user, id) do
|
def set_read_up_to(%{id: user_id} = _user, id) do
|
||||||
@ -68,6 +72,14 @@ defmodule Pleroma.Notification do
|
|||||||
Repo.update_all(query, [])
|
Repo.update_all(query, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_one(%User{} = user, notification_id) do
|
||||||
|
with {:ok, %Notification{} = notification} <- get(user, notification_id) do
|
||||||
|
notification
|
||||||
|
|> changeset(%{seen: true})
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get(%{id: user_id} = _user, id) do
|
def get(%{id: user_id} = _user, id) do
|
||||||
query =
|
query =
|
||||||
from(
|
from(
|
||||||
@ -117,13 +129,7 @@ defmodule Pleroma.Notification do
|
|||||||
|
|
||||||
# TODO move to sql, too.
|
# TODO move to sql, too.
|
||||||
def create_notification(%Activity{} = activity, %User{} = user) do
|
def create_notification(%Activity{} = activity, %User{} = user) do
|
||||||
unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or
|
unless skip?(activity, user) do
|
||||||
CommonAPI.thread_muted?(user, activity) or user.ap_id == activity.data["actor"] or
|
|
||||||
(activity.data["type"] == "Follow" and
|
|
||||||
Enum.any?(Notification.for_user(user), fn notif ->
|
|
||||||
notif.activity.data["type"] == "Follow" and
|
|
||||||
notif.activity.data["actor"] == activity.data["actor"]
|
|
||||||
end)) do
|
|
||||||
notification = %Notification{user_id: user.id, activity: activity}
|
notification = %Notification{user_id: user.id, activity: activity}
|
||||||
{:ok, notification} = Repo.insert(notification)
|
{:ok, notification} = Repo.insert(notification)
|
||||||
Pleroma.Web.Streamer.stream("user", notification)
|
Pleroma.Web.Streamer.stream("user", notification)
|
||||||
@ -143,10 +149,66 @@ defmodule Pleroma.Notification do
|
|||||||
[]
|
[]
|
||||||
|> Utils.maybe_notify_to_recipients(activity)
|
|> Utils.maybe_notify_to_recipients(activity)
|
||||||
|> Utils.maybe_notify_mentioned_recipients(activity)
|
|> Utils.maybe_notify_mentioned_recipients(activity)
|
||||||
|
|> Utils.maybe_notify_subscribers(activity)
|
||||||
|> Enum.uniq()
|
|> Enum.uniq()
|
||||||
|
|
||||||
User.get_users_from_set(recipients, local_only)
|
User.get_users_from_set(recipients, local_only)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_notified_from_activity(_, _local_only), do: []
|
def get_notified_from_activity(_, _local_only), do: []
|
||||||
|
|
||||||
|
def skip?(activity, user) do
|
||||||
|
[:self, :blocked, :local, :muted, :followers, :follows, :recently_followed]
|
||||||
|
|> Enum.any?(&skip?(&1, activity, user))
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(:self, activity, user) do
|
||||||
|
activity.data["actor"] == user.ap_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(:blocked, activity, user) do
|
||||||
|
actor = activity.data["actor"]
|
||||||
|
User.blocks?(user, %{ap_id: actor})
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(:local, %{local: true}, %{info: %{notification_settings: %{"local" => false}}}),
|
||||||
|
do: true
|
||||||
|
|
||||||
|
def skip?(:local, %{local: false}, %{info: %{notification_settings: %{"remote" => false}}}),
|
||||||
|
do: true
|
||||||
|
|
||||||
|
def skip?(:muted, activity, user) do
|
||||||
|
actor = activity.data["actor"]
|
||||||
|
|
||||||
|
User.mutes?(user, %{ap_id: actor}) or
|
||||||
|
CommonAPI.thread_muted?(user, activity)
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(
|
||||||
|
:followers,
|
||||||
|
activity,
|
||||||
|
%{info: %{notification_settings: %{"followers" => false}}} = user
|
||||||
|
) do
|
||||||
|
actor = activity.data["actor"]
|
||||||
|
follower = User.get_cached_by_ap_id(actor)
|
||||||
|
User.following?(follower, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do
|
||||||
|
actor = activity.data["actor"]
|
||||||
|
followed = User.get_by_ap_id(actor)
|
||||||
|
User.following?(user, followed)
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do
|
||||||
|
actor = activity.data["actor"]
|
||||||
|
|
||||||
|
Notification.for_user(user)
|
||||||
|
|> Enum.any?(fn
|
||||||
|
%{activity: %{data: %{"type" => "Follow", "actor" => ^actor}}} -> true
|
||||||
|
_ -> false
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(_, _, _), do: false
|
||||||
end
|
end
|
||||||
|
@ -5,15 +5,17 @@
|
|||||||
defmodule Pleroma.Object do
|
defmodule Pleroma.Object do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Object
|
||||||
alias Pleroma.ObjectTombstone
|
alias Pleroma.ObjectTombstone
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
schema "objects" do
|
schema "objects" do
|
||||||
field(:data, :map)
|
field(:data, :map)
|
||||||
|
|
||||||
@ -38,6 +40,38 @@ defmodule Pleroma.Object do
|
|||||||
Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
|
Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If we pass an Activity to Object.normalize(), we can try to use the preloaded object.
|
||||||
|
# Use this whenever possible, especially when walking graphs in an O(N) loop!
|
||||||
|
def normalize(%Activity{object: %Object{} = object}), do: object
|
||||||
|
|
||||||
|
# A hack for fake activities
|
||||||
|
def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}) do
|
||||||
|
%Object{id: "pleroma:fake_object_id", data: data}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Catch and log Object.normalize() calls where the Activity's child object is not
|
||||||
|
# preloaded.
|
||||||
|
def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}) do
|
||||||
|
Logger.debug(
|
||||||
|
"Object.normalize() called without preloaded object (#{ap_id}). Consider preloading the object!"
|
||||||
|
)
|
||||||
|
|
||||||
|
Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}")
|
||||||
|
|
||||||
|
normalize(ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize(%Activity{data: %{"object" => ap_id}}) do
|
||||||
|
Logger.debug(
|
||||||
|
"Object.normalize() called without preloaded object (#{ap_id}). Consider preloading the object!"
|
||||||
|
)
|
||||||
|
|
||||||
|
Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}")
|
||||||
|
|
||||||
|
normalize(ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Old way, try fetching the object through cache.
|
||||||
def normalize(%{"id" => ap_id}), do: normalize(ap_id)
|
def normalize(%{"id" => ap_id}), do: normalize(ap_id)
|
||||||
def normalize(ap_id) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id)
|
def normalize(ap_id) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id)
|
||||||
def normalize(_), do: nil
|
def normalize(_), do: nil
|
||||||
@ -86,9 +120,9 @@ defmodule Pleroma.Object do
|
|||||||
|
|
||||||
def delete(%Object{data: %{"id" => id}} = object) do
|
def delete(%Object{data: %{"id" => id}} = object) do
|
||||||
with {:ok, _obj} = swap_object_with_tombstone(object),
|
with {:ok, _obj} = swap_object_with_tombstone(object),
|
||||||
Repo.delete_all(Activity.by_object_ap_id(id)),
|
deleted_activity = Activity.delete_by_ap_id(id),
|
||||||
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
||||||
{:ok, object}
|
{:ok, object, deleted_activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,4 +138,50 @@ defmodule Pleroma.Object do
|
|||||||
e -> e
|
e -> e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def increase_replies_count(ap_id) do
|
||||||
|
Object
|
||||||
|
|> where([o], fragment("?->>'id' = ?::text", o.data, ^to_string(ap_id)))
|
||||||
|
|> update([o],
|
||||||
|
set: [
|
||||||
|
data:
|
||||||
|
fragment(
|
||||||
|
"""
|
||||||
|
jsonb_set(?, '{repliesCount}',
|
||||||
|
(coalesce((?->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
|
||||||
|
""",
|
||||||
|
o.data,
|
||||||
|
o.data
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|> Repo.update_all([])
|
||||||
|
|> case do
|
||||||
|
{1, [object]} -> set_cache(object)
|
||||||
|
_ -> {:error, "Not found"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrease_replies_count(ap_id) do
|
||||||
|
Object
|
||||||
|
|> where([o], fragment("?->>'id' = ?::text", o.data, ^to_string(ap_id)))
|
||||||
|
|> update([o],
|
||||||
|
set: [
|
||||||
|
data:
|
||||||
|
fragment(
|
||||||
|
"""
|
||||||
|
jsonb_set(?, '{repliesCount}',
|
||||||
|
(greatest(0, (?->>'repliesCount')::int - 1))::varchar::jsonb, true)
|
||||||
|
""",
|
||||||
|
o.data,
|
||||||
|
o.data
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|> Repo.update_all([])
|
||||||
|
|> case do
|
||||||
|
{1, [object]} -> set_cache(object)
|
||||||
|
_ -> {:error, "Not found"}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
78
lib/pleroma/pagination.ex
Normal file
78
lib/pleroma/pagination.ex
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
defmodule Pleroma.Pagination do
|
||||||
|
@moduledoc """
|
||||||
|
Implements Mastodon-compatible pagination.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
|
@default_limit 20
|
||||||
|
|
||||||
|
def fetch_paginated(query, params) do
|
||||||
|
options = cast_params(params)
|
||||||
|
|
||||||
|
query
|
||||||
|
|> paginate(options)
|
||||||
|
|> Repo.all()
|
||||||
|
|> enforce_order(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def paginate(query, options) do
|
||||||
|
query
|
||||||
|
|> restrict(:min_id, options)
|
||||||
|
|> restrict(:since_id, options)
|
||||||
|
|> restrict(:max_id, options)
|
||||||
|
|> restrict(:order, options)
|
||||||
|
|> restrict(:limit, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp cast_params(params) do
|
||||||
|
param_types = %{
|
||||||
|
min_id: :string,
|
||||||
|
since_id: :string,
|
||||||
|
max_id: :string,
|
||||||
|
limit: :integer
|
||||||
|
}
|
||||||
|
|
||||||
|
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
|
||||||
|
changeset.changes
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :min_id, %{min_id: min_id}) do
|
||||||
|
where(query, [q], q.id > ^min_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :since_id, %{since_id: since_id}) do
|
||||||
|
where(query, [q], q.id > ^since_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :max_id, %{max_id: max_id}) do
|
||||||
|
where(query, [q], q.id < ^max_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :order, %{min_id: _}) do
|
||||||
|
order_by(query, [u], fragment("? asc nulls last", u.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :order, _options) do
|
||||||
|
order_by(query, [u], fragment("? desc nulls last", u.id))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, :limit, options) do
|
||||||
|
limit = Map.get(options, :limit, @default_limit)
|
||||||
|
|
||||||
|
query
|
||||||
|
|> limit(^limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict(query, _, _), do: query
|
||||||
|
|
||||||
|
defp enforce_order(result, %{min_id: _}) do
|
||||||
|
result
|
||||||
|
|> Enum.reverse()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp enforce_order(result, _), do: result
|
||||||
|
end
|
@ -34,13 +34,16 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
|
|||||||
|
|
||||||
defp csp_string do
|
defp csp_string do
|
||||||
scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
|
scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
|
||||||
websocket_url = String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws")
|
static_url = Pleroma.Web.Endpoint.static_url()
|
||||||
|
websocket_url = String.replace(static_url, "http", "ws")
|
||||||
|
|
||||||
|
connect_src = "connect-src 'self' #{static_url} #{websocket_url}"
|
||||||
|
|
||||||
connect_src =
|
connect_src =
|
||||||
if Mix.env() == :dev do
|
if Mix.env() == :dev do
|
||||||
"connect-src 'self' http://localhost:3035/ " <> websocket_url
|
connect_src <> " http://localhost:3035/"
|
||||||
else
|
else
|
||||||
"connect-src 'self' " <> websocket_url
|
connect_src
|
||||||
end
|
end
|
||||||
|
|
||||||
script_src =
|
script_src =
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
|
defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
|
||||||
alias Pleroma.Web.HTTPSignatures
|
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
alias Pleroma.Web.HTTPSignatures
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ defmodule Pleroma.Plugs.InstanceStatic do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@only ~w(index.html static emoji packs sounds images instance favicon.png sw.js sw-pleroma.js)
|
@only ~w(index.html robots.txt static emoji packs sounds images instance favicon.png sw.js
|
||||||
|
sw-pleroma.js)
|
||||||
|
|
||||||
def init(opts) do
|
def init(opts) do
|
||||||
opts
|
opts
|
||||||
|
@ -6,8 +6,8 @@ defmodule Pleroma.Plugs.OAuthPlug do
|
|||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
@realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i")
|
@realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i")
|
||||||
@ -38,6 +38,7 @@ defmodule Pleroma.Plugs.OAuthPlug do
|
|||||||
preload: [user: user]
|
preload: [user: user]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
||||||
with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do
|
with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do
|
||||||
{:ok, user, token_record}
|
{:ok, user, token_record}
|
||||||
end
|
end
|
||||||
|
@ -24,6 +24,18 @@ defmodule Pleroma.Plugs.UploadedMedia do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
|
def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
|
||||||
|
conn =
|
||||||
|
case fetch_query_params(conn) do
|
||||||
|
%{query_params: %{"name" => name}} = conn ->
|
||||||
|
name = String.replace(name, "\"", "\\\"")
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_resp_header("content-disposition", "filename=\"#{name}\"")
|
||||||
|
|
||||||
|
conn ->
|
||||||
|
conn
|
||||||
|
end
|
||||||
|
|
||||||
config = Pleroma.Config.get([Pleroma.Upload])
|
config = Pleroma.Config.get([Pleroma.Upload])
|
||||||
|
|
||||||
with uploader <- Keyword.fetch!(config, :uploader),
|
with uploader <- Keyword.fetch!(config, :uploader),
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Plugs.UserFetcherPlug do
|
defmodule Pleroma.Plugs.UserFetcherPlug do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Repo
|
|
||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|
||||||
def init(options) do
|
def init(options) do
|
||||||
@ -14,26 +12,10 @@ defmodule Pleroma.Plugs.UserFetcherPlug do
|
|||||||
|
|
||||||
def call(conn, _options) do
|
def call(conn, _options) do
|
||||||
with %{auth_credentials: %{username: username}} <- conn.assigns,
|
with %{auth_credentials: %{username: username}} <- conn.assigns,
|
||||||
{:ok, %User{} = user} <- user_fetcher(username) do
|
%User{} = user <- User.get_by_nickname_or_email(username) do
|
||||||
conn
|
assign(conn, :auth_user, user)
|
||||||
|> assign(:auth_user, user)
|
|
||||||
else
|
else
|
||||||
_ -> conn
|
_ -> conn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp user_fetcher(username_or_email) do
|
|
||||||
{
|
|
||||||
:ok,
|
|
||||||
cond do
|
|
||||||
# First, try logging in as if it was a name
|
|
||||||
user = Repo.get_by(User, %{nickname: username_or_email}) ->
|
|
||||||
user
|
|
||||||
|
|
||||||
# If we get nil, we try using it as an email
|
|
||||||
user = Repo.get_by(User, %{email: username_or_email}) ->
|
|
||||||
user
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
57
lib/pleroma/registration.ex
Normal file
57
lib/pleroma/registration.ex
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Registration do
|
||||||
|
use Ecto.Schema
|
||||||
|
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
alias Pleroma.Registration
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
|
||||||
|
|
||||||
|
schema "registrations" do
|
||||||
|
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||||
|
field(:provider, :string)
|
||||||
|
field(:uid, :string)
|
||||||
|
field(:info, :map, default: %{})
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def nickname(registration, default \\ nil),
|
||||||
|
do: Map.get(registration.info, "nickname", default)
|
||||||
|
|
||||||
|
def email(registration, default \\ nil),
|
||||||
|
do: Map.get(registration.info, "email", default)
|
||||||
|
|
||||||
|
def name(registration, default \\ nil),
|
||||||
|
do: Map.get(registration.info, "name", default)
|
||||||
|
|
||||||
|
def description(registration, default \\ nil),
|
||||||
|
do: Map.get(registration.info, "description", default)
|
||||||
|
|
||||||
|
def changeset(registration, params \\ %{}) do
|
||||||
|
registration
|
||||||
|
|> cast(params, [:user_id, :provider, :uid, :info])
|
||||||
|
|> validate_required([:provider, :uid])
|
||||||
|
|> foreign_key_constraint(:user_id)
|
||||||
|
|> unique_constraint(:uid, name: :registrations_provider_uid_index)
|
||||||
|
end
|
||||||
|
|
||||||
|
def bind_to_user(registration, user) do
|
||||||
|
registration
|
||||||
|
|> changeset(%{user_id: (user && user.id) || nil})
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_by_provider_uid(provider, uid) do
|
||||||
|
Repo.get_by(Registration,
|
||||||
|
provider: to_string(provider),
|
||||||
|
uid: to_string(uid)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
@ -3,7 +3,14 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Repo do
|
defmodule Pleroma.Repo do
|
||||||
use Ecto.Repo, otp_app: :pleroma
|
use Ecto.Repo,
|
||||||
|
otp_app: :pleroma,
|
||||||
|
adapter: Ecto.Adapters.Postgres,
|
||||||
|
migration_timestamps: [type: :naive_datetime_usec]
|
||||||
|
|
||||||
|
defmodule Instrumenter do
|
||||||
|
use Prometheus.EctoInstrumenter
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Dynamically loads the repository url from the
|
Dynamically loads the repository url from the
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.ReverseProxy do
|
defmodule Pleroma.ReverseProxy do
|
||||||
@keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range)
|
@keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since) ++
|
||||||
|
~w(if-unmodified-since if-none-match if-range range)
|
||||||
@resp_cache_headers ~w(etag date last-modified cache-control)
|
@resp_cache_headers ~w(etag date last-modified cache-control)
|
||||||
@keep_resp_headers @resp_cache_headers ++
|
@keep_resp_headers @resp_cache_headers ++
|
||||||
~w(content-type content-disposition content-encoding content-range accept-ranges vary)
|
~w(content-type content-disposition content-encoding content-range) ++
|
||||||
|
~w(accept-ranges vary)
|
||||||
@default_cache_control_header "public, max-age=1209600"
|
@default_cache_control_header "public, max-age=1209600"
|
||||||
@valid_resp_codes [200, 206, 304]
|
@valid_resp_codes [200, 206, 304]
|
||||||
@max_read_duration :timer.seconds(30)
|
@max_read_duration :timer.seconds(30)
|
||||||
@ -282,8 +284,8 @@ defmodule Pleroma.ReverseProxy do
|
|||||||
headers
|
headers
|
||||||
|
|
||||||
has_cache? ->
|
has_cache? ->
|
||||||
# There's caching header present but no cache-control -- we need to explicitely override it to public
|
# There's caching header present but no cache-control -- we need to explicitely override it
|
||||||
# as Plug defaults to "max-age=0, private, must-revalidate"
|
# to public as Plug defaults to "max-age=0, private, must-revalidate"
|
||||||
List.keystore(headers, "cache-control", 0, {"cache-control", "public"})
|
List.keystore(headers, "cache-control", 0, {"cache-control", "public"})
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
@ -309,7 +311,25 @@ defmodule Pleroma.ReverseProxy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if attachment? do
|
if attachment? do
|
||||||
disposition = "attachment; filename=" <> Keyword.get(opts, :attachment_name, "attachment")
|
name =
|
||||||
|
try do
|
||||||
|
{{"content-disposition", content_disposition_string}, _} =
|
||||||
|
List.keytake(headers, "content-disposition", 0)
|
||||||
|
|
||||||
|
[name | _] =
|
||||||
|
Regex.run(
|
||||||
|
~r/filename="((?:[^"\\]|\\.)*)"/u,
|
||||||
|
content_disposition_string || "",
|
||||||
|
capture: :all_but_first
|
||||||
|
)
|
||||||
|
|
||||||
|
name
|
||||||
|
rescue
|
||||||
|
MatchError -> Keyword.get(opts, :attachment_name, "attachment")
|
||||||
|
end
|
||||||
|
|
||||||
|
disposition = "attachment; filename=\"#{name}\""
|
||||||
|
|
||||||
List.keystore(headers, "content-disposition", 0, {"content-disposition", disposition})
|
List.keystore(headers, "content-disposition", 0, {"content-disposition", disposition})
|
||||||
else
|
else
|
||||||
headers
|
headers
|
||||||
|
161
lib/pleroma/scheduled_activity.ex
Normal file
161
lib/pleroma/scheduled_activity.ex
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.ScheduledActivity do
|
||||||
|
use Ecto.Schema
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@min_offset :timer.minutes(5)
|
||||||
|
|
||||||
|
schema "scheduled_activities" do
|
||||||
|
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||||
|
field(:scheduled_at, :naive_datetime)
|
||||||
|
field(:params, :map)
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(%ScheduledActivity{} = scheduled_activity, attrs) do
|
||||||
|
scheduled_activity
|
||||||
|
|> cast(attrs, [:scheduled_at, :params])
|
||||||
|
|> validate_required([:scheduled_at, :params])
|
||||||
|
|> validate_scheduled_at()
|
||||||
|
|> with_media_attachments()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp with_media_attachments(
|
||||||
|
%{changes: %{params: %{"media_ids" => media_ids} = params}} = changeset
|
||||||
|
)
|
||||||
|
when is_list(media_ids) do
|
||||||
|
media_attachments = Utils.attachments_from_ids(%{"media_ids" => media_ids})
|
||||||
|
|
||||||
|
params =
|
||||||
|
params
|
||||||
|
|> Map.put("media_attachments", media_attachments)
|
||||||
|
|> Map.put("media_ids", media_ids)
|
||||||
|
|
||||||
|
put_change(changeset, :params, params)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp with_media_attachments(changeset), do: changeset
|
||||||
|
|
||||||
|
def update_changeset(%ScheduledActivity{} = scheduled_activity, attrs) do
|
||||||
|
scheduled_activity
|
||||||
|
|> cast(attrs, [:scheduled_at])
|
||||||
|
|> validate_required([:scheduled_at])
|
||||||
|
|> validate_scheduled_at()
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_scheduled_at(changeset) do
|
||||||
|
validate_change(changeset, :scheduled_at, fn _, scheduled_at ->
|
||||||
|
cond do
|
||||||
|
not far_enough?(scheduled_at) ->
|
||||||
|
[scheduled_at: "must be at least 5 minutes from now"]
|
||||||
|
|
||||||
|
exceeds_daily_user_limit?(changeset.data.user_id, scheduled_at) ->
|
||||||
|
[scheduled_at: "daily limit exceeded"]
|
||||||
|
|
||||||
|
exceeds_total_user_limit?(changeset.data.user_id) ->
|
||||||
|
[scheduled_at: "total limit exceeded"]
|
||||||
|
|
||||||
|
true ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def exceeds_daily_user_limit?(user_id, scheduled_at) do
|
||||||
|
ScheduledActivity
|
||||||
|
|> where(user_id: ^user_id)
|
||||||
|
|> where([sa], type(sa.scheduled_at, :date) == type(^scheduled_at, :date))
|
||||||
|
|> select([sa], count(sa.id))
|
||||||
|
|> Repo.one()
|
||||||
|
|> Kernel.>=(Config.get([ScheduledActivity, :daily_user_limit]))
|
||||||
|
end
|
||||||
|
|
||||||
|
def exceeds_total_user_limit?(user_id) do
|
||||||
|
ScheduledActivity
|
||||||
|
|> where(user_id: ^user_id)
|
||||||
|
|> select([sa], count(sa.id))
|
||||||
|
|> Repo.one()
|
||||||
|
|> Kernel.>=(Config.get([ScheduledActivity, :total_user_limit]))
|
||||||
|
end
|
||||||
|
|
||||||
|
def far_enough?(scheduled_at) when is_binary(scheduled_at) do
|
||||||
|
with {:ok, scheduled_at} <- Ecto.Type.cast(:naive_datetime, scheduled_at) do
|
||||||
|
far_enough?(scheduled_at)
|
||||||
|
else
|
||||||
|
_ -> false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def far_enough?(scheduled_at) do
|
||||||
|
now = NaiveDateTime.utc_now()
|
||||||
|
diff = NaiveDateTime.diff(scheduled_at, now, :millisecond)
|
||||||
|
diff > @min_offset
|
||||||
|
end
|
||||||
|
|
||||||
|
def new(%User{} = user, attrs) do
|
||||||
|
%ScheduledActivity{user_id: user.id}
|
||||||
|
|> changeset(attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(%User{} = user, attrs) do
|
||||||
|
user
|
||||||
|
|> new(attrs)
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(%User{} = user, scheduled_activity_id) do
|
||||||
|
ScheduledActivity
|
||||||
|
|> where(user_id: ^user.id)
|
||||||
|
|> where(id: ^scheduled_activity_id)
|
||||||
|
|> Repo.one()
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(%ScheduledActivity{} = scheduled_activity, attrs) do
|
||||||
|
scheduled_activity
|
||||||
|
|> update_changeset(attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(%ScheduledActivity{} = scheduled_activity) do
|
||||||
|
scheduled_activity
|
||||||
|
|> Repo.delete()
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(id) when is_binary(id) or is_integer(id) do
|
||||||
|
ScheduledActivity
|
||||||
|
|> where(id: ^id)
|
||||||
|
|> select([sa], sa)
|
||||||
|
|> Repo.delete_all()
|
||||||
|
|> case do
|
||||||
|
{1, [scheduled_activity]} -> {:ok, scheduled_activity}
|
||||||
|
_ -> :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_user_query(%User{} = user) do
|
||||||
|
ScheduledActivity
|
||||||
|
|> where(user_id: ^user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def due_activities(offset \\ 0) do
|
||||||
|
naive_datetime =
|
||||||
|
NaiveDateTime.utc_now()
|
||||||
|
|> NaiveDateTime.add(offset, :millisecond)
|
||||||
|
|
||||||
|
ScheduledActivity
|
||||||
|
|> where([sa], sa.scheduled_at < ^naive_datetime)
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
end
|
58
lib/pleroma/scheduled_activity_worker.ex
Normal file
58
lib/pleroma/scheduled_activity_worker.ex
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.ScheduledActivityWorker do
|
||||||
|
@moduledoc """
|
||||||
|
Sends scheduled activities to the job queue.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
|
use GenServer
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
@schedule_interval :timer.minutes(1)
|
||||||
|
|
||||||
|
def start_link do
|
||||||
|
GenServer.start_link(__MODULE__, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
def init(_) do
|
||||||
|
if Config.get([ScheduledActivity, :enabled]) do
|
||||||
|
schedule_next()
|
||||||
|
{:ok, nil}
|
||||||
|
else
|
||||||
|
:ignore
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform(:execute, scheduled_activity_id) do
|
||||||
|
try do
|
||||||
|
{:ok, scheduled_activity} = ScheduledActivity.delete(scheduled_activity_id)
|
||||||
|
%User{} = user = User.get_cached_by_id(scheduled_activity.user_id)
|
||||||
|
{:ok, _result} = CommonAPI.post(user, scheduled_activity.params)
|
||||||
|
rescue
|
||||||
|
error ->
|
||||||
|
Logger.error(
|
||||||
|
"#{__MODULE__} Couldn't create a status from the scheduled activity: #{inspect(error)}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_info(:perform, state) do
|
||||||
|
ScheduledActivity.due_activities(@schedule_interval)
|
||||||
|
|> Enum.each(fn scheduled_activity ->
|
||||||
|
PleromaJobQueue.enqueue(:scheduled_activities, __MODULE__, [:execute, scheduled_activity.id])
|
||||||
|
end)
|
||||||
|
|
||||||
|
schedule_next()
|
||||||
|
{:noreply, state}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp schedule_next do
|
||||||
|
Process.send_after(self(), :perform, @schedule_interval)
|
||||||
|
end
|
||||||
|
end
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Stats do
|
defmodule Pleroma.Stats do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
def start_link do
|
def start_link do
|
||||||
agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
|
agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
defmodule Pleroma.ThreadMute do
|
defmodule Pleroma.ThreadMute do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
alias Pleroma.{Repo, User, ThreadMute}
|
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.ThreadMute
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
require Ecto.Query
|
require Ecto.Query
|
||||||
|
|
||||||
schema "thread_mutes" do
|
schema "thread_mutes" do
|
||||||
|
@ -70,7 +70,7 @@ defmodule Pleroma.Upload do
|
|||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"mediaType" => upload.content_type,
|
"mediaType" => upload.content_type,
|
||||||
"href" => url_from_spec(opts.base_url, url_spec)
|
"href" => url_from_spec(upload, opts.base_url, url_spec)
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name" => Map.get(opts, :description) || upload.name
|
"name" => Map.get(opts, :description) || upload.name
|
||||||
@ -85,6 +85,10 @@ defmodule Pleroma.Upload do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def char_unescaped?(char) do
|
||||||
|
URI.char_unreserved?(char) or char == ?/
|
||||||
|
end
|
||||||
|
|
||||||
defp get_opts(opts) do
|
defp get_opts(opts) do
|
||||||
{size_limit, activity_type} =
|
{size_limit, activity_type} =
|
||||||
case Keyword.get(opts, :type) do
|
case Keyword.get(opts, :type) do
|
||||||
@ -215,16 +219,18 @@ defmodule Pleroma.Upload do
|
|||||||
tmp_path
|
tmp_path
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_from_spec(base_url, {:file, path}) do
|
defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) do
|
||||||
path =
|
path =
|
||||||
path
|
URI.encode(path, &char_unescaped?/1) <>
|
||||||
|> URI.encode()
|
if Pleroma.Config.get([__MODULE__, :link_name], false) do
|
||||||
|> String.replace("?", "%3F")
|
"?name=#{URI.encode(name, &char_unescaped?/1)}"
|
||||||
|> String.replace(":", "%3A")
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
[base_url, "media", path]
|
[base_url, "media", path]
|
||||||
|> Path.join()
|
|> Path.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_from_spec(_base_url, {:url, url}), do: url
|
defp url_from_spec(_upload, _base_url, {:url, url}), do: url
|
||||||
end
|
end
|
||||||
|
@ -6,16 +6,22 @@ defmodule Pleroma.Uploaders.S3 do
|
|||||||
@behaviour Pleroma.Uploaders.Uploader
|
@behaviour Pleroma.Uploaders.Uploader
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
# The file name is re-encoded with S3's constraints here to comply with previous links with less strict filenames
|
# The file name is re-encoded with S3's constraints here to comply with previous
|
||||||
|
# links with less strict filenames
|
||||||
def get_file(file) do
|
def get_file(file) do
|
||||||
config = Pleroma.Config.get([__MODULE__])
|
config = Pleroma.Config.get([__MODULE__])
|
||||||
bucket = Keyword.fetch!(config, :bucket)
|
bucket = Keyword.fetch!(config, :bucket)
|
||||||
|
|
||||||
bucket_with_namespace =
|
bucket_with_namespace =
|
||||||
if namespace = Keyword.get(config, :bucket_namespace) do
|
cond do
|
||||||
namespace <> ":" <> bucket
|
truncated_namespace = Keyword.get(config, :truncated_namespace) ->
|
||||||
else
|
truncated_namespace
|
||||||
bucket
|
|
||||||
|
namespace = Keyword.get(config, :bucket_namespace) ->
|
||||||
|
namespace <> ":" <> bucket
|
||||||
|
|
||||||
|
true ->
|
||||||
|
bucket
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
|
@ -17,7 +17,7 @@ defmodule Pleroma.Uploaders.Swift.Keystone do
|
|||||||
|> Poison.decode!()
|
|> Poison.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_token() do
|
def get_token do
|
||||||
settings = Pleroma.Config.get(Pleroma.Uploaders.Swift)
|
settings = Pleroma.Config.get(Pleroma.Uploaders.Swift)
|
||||||
username = Keyword.fetch!(settings, :username)
|
username = Keyword.fetch!(settings, :username)
|
||||||
password = Keyword.fetch!(settings, :password)
|
password = Keyword.fetch!(settings, :password)
|
||||||
|
@ -29,7 +29,6 @@ defmodule Pleroma.Uploaders.Uploader do
|
|||||||
* `{:error, String.t}` error information if the file failed to be saved to the backend.
|
* `{:error, String.t}` error information if the file failed to be saved to the backend.
|
||||||
* `:wait_callback` will wait for an http post request at `/api/pleroma/upload_callback/:upload_path` and call the uploader's `http_callback/3` method.
|
* `:wait_callback` will wait for an http post request at `/api/pleroma/upload_callback/:upload_path` and call the uploader's `http_callback/3` method.
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@type file_spec :: {:file | :url, String.t()}
|
@type file_spec :: {:file | :url, String.t()}
|
||||||
@callback put_file(Pleroma.Upload.t()) ::
|
@callback put_file(Pleroma.Upload.t()) ::
|
||||||
|
@ -8,21 +8,22 @@ defmodule Pleroma.User do
|
|||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias Comeonin.Pbkdf2
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Formatter
|
||||||
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Registration
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Comeonin.Pbkdf2
|
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
|
|
||||||
alias Pleroma.Web.OStatus
|
|
||||||
alias Pleroma.Web.Websub
|
|
||||||
alias Pleroma.Web.OAuth
|
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
|
||||||
|
alias Pleroma.Web.OAuth
|
||||||
|
alias Pleroma.Web.OStatus
|
||||||
alias Pleroma.Web.RelMe
|
alias Pleroma.Web.RelMe
|
||||||
|
alias Pleroma.Web.Websub
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ defmodule Pleroma.User do
|
|||||||
|
|
||||||
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
|
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
|
||||||
|
|
||||||
|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
||||||
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
|
||||||
|
|
||||||
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
|
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
|
||||||
@ -49,23 +51,21 @@ defmodule Pleroma.User do
|
|||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
field(:follower_address, :string)
|
field(:follower_address, :string)
|
||||||
field(:search_rank, :float, virtual: true)
|
field(:search_rank, :float, virtual: true)
|
||||||
|
field(:search_type, :integer, virtual: true)
|
||||||
field(:tags, {:array, :string}, default: [])
|
field(:tags, {:array, :string}, default: [])
|
||||||
field(:bookmarks, {:array, :string}, default: [])
|
field(:bookmarks, {:array, :string}, default: [])
|
||||||
field(:last_refreshed_at, :naive_datetime)
|
field(:last_refreshed_at, :naive_datetime_usec)
|
||||||
has_many(:notifications, Notification)
|
has_many(:notifications, Notification)
|
||||||
|
has_many(:registrations, Registration)
|
||||||
embeds_one(:info, Pleroma.User.Info)
|
embeds_one(:info, Pleroma.User.Info)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def auth_active?(%User{local: false}), do: true
|
|
||||||
|
|
||||||
def auth_active?(%User{info: %User.Info{confirmation_pending: false}}), do: true
|
|
||||||
|
|
||||||
def auth_active?(%User{info: %User.Info{confirmation_pending: true}}),
|
def auth_active?(%User{info: %User.Info{confirmation_pending: true}}),
|
||||||
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
|
|
||||||
def auth_active?(_), do: false
|
def auth_active?(%User{}), do: true
|
||||||
|
|
||||||
def visible_for?(user, for_user \\ nil)
|
def visible_for?(user, for_user \\ nil)
|
||||||
|
|
||||||
@ -81,17 +81,17 @@ defmodule Pleroma.User do
|
|||||||
def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true
|
def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true
|
||||||
def superuser?(_), do: false
|
def superuser?(_), do: false
|
||||||
|
|
||||||
def avatar_url(user) do
|
def avatar_url(user, options \\ []) do
|
||||||
case user.avatar do
|
case user.avatar do
|
||||||
%{"url" => [%{"href" => href} | _]} -> href
|
%{"url" => [%{"href" => href} | _]} -> href
|
||||||
_ -> "#{Web.base_url()}/images/avi.png"
|
_ -> !options[:no_default] && "#{Web.base_url()}/images/avi.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def banner_url(user) do
|
def banner_url(user, options \\ []) do
|
||||||
case user.info.banner do
|
case user.info.banner do
|
||||||
%{"url" => [%{"href" => href} | _]} -> href
|
%{"url" => [%{"href" => href} | _]} -> href
|
||||||
_ -> "#{Web.base_url()}/images/banner.png"
|
_ -> !options[:no_default] && "#{Web.base_url()}/images/banner.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,9 +103,8 @@ defmodule Pleroma.User do
|
|||||||
"#{Web.base_url()}/users/#{nickname}"
|
"#{Web.base_url()}/users/#{nickname}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ap_followers(%User{} = user) do
|
def ap_followers(%User{follower_address: fa}) when is_binary(fa), do: fa
|
||||||
"#{ap_id(user)}/followers"
|
def ap_followers(%User{} = user), do: "#{ap_id(user)}/followers"
|
||||||
end
|
|
||||||
|
|
||||||
def user_info(%User{} = user) do
|
def user_info(%User{} = user) do
|
||||||
%{
|
%{
|
||||||
@ -234,7 +233,7 @@ defmodule Pleroma.User do
|
|||||||
changeset =
|
changeset =
|
||||||
struct
|
struct
|
||||||
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_required([:email, :name, :nickname, :password, :password_confirmation])
|
|> validate_required([:name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_confirmation(:password)
|
|> validate_confirmation(:password)
|
||||||
|> unique_constraint(:email)
|
|> unique_constraint(:email)
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
@ -245,6 +244,13 @@ defmodule Pleroma.User do
|
|||||||
|> validate_length(:name, min: 1, max: 100)
|
|> validate_length(:name, min: 1, max: 100)
|
||||||
|> put_change(:info, info_change)
|
|> put_change(:info, info_change)
|
||||||
|
|
||||||
|
changeset =
|
||||||
|
if opts[:external] do
|
||||||
|
changeset
|
||||||
|
else
|
||||||
|
validate_required(changeset, [:email])
|
||||||
|
end
|
||||||
|
|
||||||
if changeset.valid? do
|
if changeset.valid? do
|
||||||
hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
|
hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
|
||||||
ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
|
ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
|
||||||
@ -300,7 +306,7 @@ defmodule Pleroma.User do
|
|||||||
def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true
|
def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true
|
||||||
|
|
||||||
def needs_update?(%User{local: false} = user) do
|
def needs_update?(%User{local: false} = user) do
|
||||||
NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86400
|
NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86_400
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_update?(_), do: true
|
def needs_update?(_), do: true
|
||||||
@ -349,10 +355,11 @@ defmodule Pleroma.User do
|
|||||||
^followed_addresses
|
^followed_addresses
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
select: u
|
||||||
)
|
)
|
||||||
|
|
||||||
{1, [follower]} = Repo.update_all(q, [], returning: true)
|
{1, [follower]} = Repo.update_all(q, [])
|
||||||
|
|
||||||
Enum.each(followeds, fn followed ->
|
Enum.each(followeds, fn followed ->
|
||||||
update_follower_count(followed)
|
update_follower_count(followed)
|
||||||
@ -382,10 +389,11 @@ defmodule Pleroma.User do
|
|||||||
q =
|
q =
|
||||||
from(u in User,
|
from(u in User,
|
||||||
where: u.id == ^follower.id,
|
where: u.id == ^follower.id,
|
||||||
update: [push: [following: ^ap_followers]]
|
update: [push: [following: ^ap_followers]],
|
||||||
|
select: u
|
||||||
)
|
)
|
||||||
|
|
||||||
{1, [follower]} = Repo.update_all(q, [], returning: true)
|
{1, [follower]} = Repo.update_all(q, [])
|
||||||
|
|
||||||
{:ok, _} = update_follower_count(followed)
|
{:ok, _} = update_follower_count(followed)
|
||||||
|
|
||||||
@ -400,10 +408,11 @@ defmodule Pleroma.User do
|
|||||||
q =
|
q =
|
||||||
from(u in User,
|
from(u in User,
|
||||||
where: u.id == ^follower.id,
|
where: u.id == ^follower.id,
|
||||||
update: [pull: [following: ^ap_followers]]
|
update: [pull: [following: ^ap_followers]],
|
||||||
|
select: u
|
||||||
)
|
)
|
||||||
|
|
||||||
{1, [follower]} = Repo.update_all(q, [], returning: true)
|
{1, [follower]} = Repo.update_all(q, [])
|
||||||
|
|
||||||
{:ok, followed} = update_follower_count(followed)
|
{:ok, followed} = update_follower_count(followed)
|
||||||
|
|
||||||
@ -450,7 +459,8 @@ defmodule Pleroma.User do
|
|||||||
Repo.get_by(User, ap_id: ap_id)
|
Repo.get_by(User, ap_id: ap_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user
|
# This is mostly an SPC migration fix. This guesses the user nickname by taking the last part
|
||||||
|
# of the ap_id and the domain and tries to get that user
|
||||||
def get_by_guessed_nickname(ap_id) do
|
def get_by_guessed_nickname(ap_id) do
|
||||||
domain = URI.parse(ap_id).host
|
domain = URI.parse(ap_id).host
|
||||||
name = List.last(String.split(ap_id, "/"))
|
name = List.last(String.split(ap_id, "/"))
|
||||||
@ -519,11 +529,10 @@ defmodule Pleroma.User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_by_email(email), do: Repo.get_by(User, email: email)
|
||||||
|
|
||||||
def get_by_nickname_or_email(nickname_or_email) do
|
def get_by_nickname_or_email(nickname_or_email) do
|
||||||
case user = Repo.get_by(User, nickname: nickname_or_email) do
|
get_by_nickname(nickname_or_email) || get_by_email(nickname_or_email)
|
||||||
%User{} -> user
|
|
||||||
nil -> Repo.get_by(User, email: nickname_or_email)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cached_user_info(user) do
|
def get_cached_user_info(user) do
|
||||||
@ -547,6 +556,10 @@ defmodule Pleroma.User do
|
|||||||
_e ->
|
_e ->
|
||||||
with [_nick, _domain] <- String.split(nickname, "@"),
|
with [_nick, _domain] <- String.split(nickname, "@"),
|
||||||
{:ok, user} <- fetch_by_nickname(nickname) do
|
{:ok, user} <- fetch_by_nickname(nickname) do
|
||||||
|
if Pleroma.Config.get([:fetch_initial_posts, :enabled]) do
|
||||||
|
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
||||||
|
end
|
||||||
|
|
||||||
user
|
user
|
||||||
else
|
else
|
||||||
_e -> nil
|
_e -> nil
|
||||||
@ -554,6 +567,17 @@ defmodule Pleroma.User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Fetch some posts when the user has just been federated with"
|
||||||
|
def fetch_initial_posts(user) do
|
||||||
|
pages = Pleroma.Config.get!([:fetch_initial_posts, :pages])
|
||||||
|
|
||||||
|
Enum.each(
|
||||||
|
# Insert all the posts in reverse order, so they're in the right order on the timeline
|
||||||
|
Enum.reverse(Utils.fetch_ordered_collection(user.info.source_data["outbox"], pages)),
|
||||||
|
&Pleroma.Web.Federator.incoming_ap_doc/1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def get_followers_query(%User{id: id, follower_address: follower_address}, nil) do
|
def get_followers_query(%User{id: id, follower_address: follower_address}, nil) do
|
||||||
from(
|
from(
|
||||||
u in User,
|
u in User,
|
||||||
@ -637,7 +661,7 @@ defmodule Pleroma.User do
|
|||||||
users =
|
users =
|
||||||
user
|
user
|
||||||
|> User.get_follow_requests_query()
|
|> User.get_follow_requests_query()
|
||||||
|> join(:inner, [a], u in User, a.actor == u.ap_id)
|
|> join(:inner, [a], u in User, on: a.actor == u.ap_id)
|
||||||
|> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
|
|> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
|
||||||
|> group_by([a, u], u.id)
|
|> group_by([a, u], u.id)
|
||||||
|> select([a, u], u)
|
|> select([a, u], u)
|
||||||
@ -659,7 +683,8 @@ defmodule Pleroma.User do
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> Repo.update_all([], returning: true)
|
|> select([u], u)
|
||||||
|
|> Repo.update_all([])
|
||||||
|> case do
|
|> case do
|
||||||
{1, [user]} -> set_cache(user)
|
{1, [user]} -> set_cache(user)
|
||||||
_ -> {:error, user}
|
_ -> {:error, user}
|
||||||
@ -679,7 +704,8 @@ defmodule Pleroma.User do
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> Repo.update_all([], returning: true)
|
|> select([u], u)
|
||||||
|
|> Repo.update_all([])
|
||||||
|> case do
|
|> case do
|
||||||
{1, [user]} -> set_cache(user)
|
{1, [user]} -> set_cache(user)
|
||||||
_ -> {:error, user}
|
_ -> {:error, user}
|
||||||
@ -725,7 +751,8 @@ defmodule Pleroma.User do
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|> Repo.update_all([], returning: true)
|
|> select([u], u)
|
||||||
|
|> Repo.update_all([])
|
||||||
|> case do
|
|> case do
|
||||||
{1, [user]} -> set_cache(user)
|
{1, [user]} -> set_cache(user)
|
||||||
_ -> {:error, user}
|
_ -> {:error, user}
|
||||||
@ -766,77 +793,59 @@ defmodule Pleroma.User do
|
|||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec search_for_admin(binary(), %{
|
|
||||||
admin: Pleroma.User.t(),
|
|
||||||
local: boolean(),
|
|
||||||
page: number(),
|
|
||||||
page_size: number()
|
|
||||||
}) :: {:ok, [Pleroma.User.t()], number()}
|
|
||||||
def search_for_admin(term, %{admin: admin, local: local, page: page, page_size: page_size}) do
|
|
||||||
term = String.trim_leading(term, "@")
|
|
||||||
|
|
||||||
local_paginated_query =
|
|
||||||
User
|
|
||||||
|> maybe_local_user_query(local)
|
|
||||||
|> paginate(page, page_size)
|
|
||||||
|
|
||||||
search_query = fts_search_subquery(term, local_paginated_query)
|
|
||||||
|
|
||||||
count =
|
|
||||||
term
|
|
||||||
|> fts_search_subquery()
|
|
||||||
|> maybe_local_user_query(local)
|
|
||||||
|> Repo.aggregate(:count, :id)
|
|
||||||
|
|
||||||
{:ok, do_search(search_query, admin), count}
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec all_for_admin(number(), number()) :: {:ok, [Pleroma.User.t()], number()}
|
|
||||||
def all_for_admin(page, page_size) do
|
|
||||||
query = from(u in User, order_by: u.id)
|
|
||||||
|
|
||||||
paginated_query =
|
|
||||||
query
|
|
||||||
|> paginate(page, page_size)
|
|
||||||
|
|
||||||
count =
|
|
||||||
query
|
|
||||||
|> Repo.aggregate(:count, :id)
|
|
||||||
|
|
||||||
{:ok, Repo.all(paginated_query), count}
|
|
||||||
end
|
|
||||||
|
|
||||||
def search(query, resolve \\ false, for_user \\ nil) do
|
def search(query, resolve \\ false, for_user \\ nil) do
|
||||||
# Strip the beginning @ off if there is a query
|
# Strip the beginning @ off if there is a query
|
||||||
query = String.trim_leading(query, "@")
|
query = String.trim_leading(query, "@")
|
||||||
|
|
||||||
if resolve, do: get_or_fetch(query)
|
if resolve, do: get_or_fetch(query)
|
||||||
|
|
||||||
fts_results = do_search(fts_search_subquery(query), for_user)
|
{:ok, results} =
|
||||||
|
|
||||||
{:ok, trigram_results} =
|
|
||||||
Repo.transaction(fn ->
|
Repo.transaction(fn ->
|
||||||
Ecto.Adapters.SQL.query(Repo, "select set_limit(0.25)", [])
|
Ecto.Adapters.SQL.query(Repo, "select set_limit(0.25)", [])
|
||||||
do_search(trigram_search_subquery(query), for_user)
|
Repo.all(search_query(query, for_user))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Enum.uniq_by(fts_results ++ trigram_results, & &1.id)
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_search(subquery, for_user, options \\ []) do
|
def search_query(query, for_user) do
|
||||||
q =
|
fts_subquery = fts_search_subquery(query)
|
||||||
from(
|
trigram_subquery = trigram_search_subquery(query)
|
||||||
s in subquery(subquery),
|
union_query = from(s in trigram_subquery, union_all: ^fts_subquery)
|
||||||
order_by: [desc: s.search_rank],
|
distinct_query = from(s in subquery(union_query), order_by: s.search_type, distinct: s.id)
|
||||||
limit: ^(options[:limit] || 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
results =
|
from(s in subquery(boost_search_rank_query(distinct_query, for_user)),
|
||||||
q
|
order_by: [desc: s.search_rank],
|
||||||
|> Repo.all()
|
limit: 20
|
||||||
|> Enum.filter(&(&1.search_rank > 0))
|
)
|
||||||
|
end
|
||||||
|
|
||||||
boost_search_results(results, for_user)
|
defp boost_search_rank_query(query, nil), do: query
|
||||||
|
|
||||||
|
defp boost_search_rank_query(query, for_user) do
|
||||||
|
friends_ids = get_friends_ids(for_user)
|
||||||
|
followers_ids = get_followers_ids(for_user)
|
||||||
|
|
||||||
|
from(u in subquery(query),
|
||||||
|
select_merge: %{
|
||||||
|
search_rank:
|
||||||
|
fragment(
|
||||||
|
"""
|
||||||
|
CASE WHEN (?) THEN (?) * 1.3
|
||||||
|
WHEN (?) THEN (?) * 1.2
|
||||||
|
WHEN (?) THEN (?) * 1.1
|
||||||
|
ELSE (?) END
|
||||||
|
""",
|
||||||
|
u.id in ^friends_ids and u.id in ^followers_ids,
|
||||||
|
u.search_rank,
|
||||||
|
u.id in ^friends_ids,
|
||||||
|
u.search_rank,
|
||||||
|
u.id in ^followers_ids,
|
||||||
|
u.search_rank,
|
||||||
|
u.search_rank
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fts_search_subquery(term, query \\ User) do
|
defp fts_search_subquery(term, query \\ User) do
|
||||||
@ -851,6 +860,7 @@ defmodule Pleroma.User do
|
|||||||
from(
|
from(
|
||||||
u in query,
|
u in query,
|
||||||
select_merge: %{
|
select_merge: %{
|
||||||
|
search_type: ^0,
|
||||||
search_rank:
|
search_rank:
|
||||||
fragment(
|
fragment(
|
||||||
"""
|
"""
|
||||||
@ -884,6 +894,8 @@ defmodule Pleroma.User do
|
|||||||
from(
|
from(
|
||||||
u in User,
|
u in User,
|
||||||
select_merge: %{
|
select_merge: %{
|
||||||
|
# ^1 gives 'Postgrex expected a binary, got 1' for some weird reason
|
||||||
|
search_type: fragment("?", 1),
|
||||||
search_rank:
|
search_rank:
|
||||||
fragment(
|
fragment(
|
||||||
"similarity(?, trim(? || ' ' || coalesce(?, '')))",
|
"similarity(?, trim(? || ' ' || coalesce(?, '')))",
|
||||||
@ -897,33 +909,6 @@ defmodule Pleroma.User do
|
|||||||
|> restrict_disabled()
|
|> restrict_disabled()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp boost_search_results(results, nil), do: results
|
|
||||||
|
|
||||||
defp boost_search_results(results, for_user) do
|
|
||||||
friends_ids = get_friends_ids(for_user)
|
|
||||||
followers_ids = get_followers_ids(for_user)
|
|
||||||
|
|
||||||
Enum.map(
|
|
||||||
results,
|
|
||||||
fn u ->
|
|
||||||
search_rank_coef =
|
|
||||||
cond do
|
|
||||||
u.id in friends_ids ->
|
|
||||||
1.2
|
|
||||||
|
|
||||||
u.id in followers_ids ->
|
|
||||||
1.1
|
|
||||||
|
|
||||||
true ->
|
|
||||||
1
|
|
||||||
end
|
|
||||||
|
|
||||||
Map.put(u, :search_rank, u.search_rank * search_rank_coef)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|> Enum.sort_by(&(-&1.search_rank))
|
|
||||||
end
|
|
||||||
|
|
||||||
def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do
|
def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do
|
||||||
Enum.map(
|
Enum.map(
|
||||||
blocked_identifiers,
|
blocked_identifiers,
|
||||||
@ -965,6 +950,38 @@ defmodule Pleroma.User do
|
|||||||
update_and_set_cache(cng)
|
update_and_set_cache(cng)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscribe(subscriber, %{ap_id: ap_id}) do
|
||||||
|
deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
|
||||||
|
|
||||||
|
with %User{} = subscribed <- get_cached_by_ap_id(ap_id) do
|
||||||
|
blocked = blocks?(subscribed, subscriber) and deny_follow_blocked
|
||||||
|
|
||||||
|
if blocked do
|
||||||
|
{:error, "Could not subscribe: #{subscribed.nickname} is blocking you"}
|
||||||
|
else
|
||||||
|
info_cng =
|
||||||
|
subscribed.info
|
||||||
|
|> User.Info.add_to_subscribers(subscriber.ap_id)
|
||||||
|
|
||||||
|
change(subscribed)
|
||||||
|
|> put_embed(:info, info_cng)
|
||||||
|
|> update_and_set_cache()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsubscribe(unsubscriber, %{ap_id: ap_id}) do
|
||||||
|
with %User{} = user <- get_cached_by_ap_id(ap_id) do
|
||||||
|
info_cng =
|
||||||
|
user.info
|
||||||
|
|> User.Info.remove_from_subscribers(unsubscriber.ap_id)
|
||||||
|
|
||||||
|
change(user)
|
||||||
|
|> put_embed(:info, info_cng)
|
||||||
|
|> update_and_set_cache()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def block(blocker, %User{ap_id: ap_id} = blocked) do
|
def block(blocker, %User{ap_id: ap_id} = blocked) do
|
||||||
# sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213)
|
# sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213)
|
||||||
blocker =
|
blocker =
|
||||||
@ -975,10 +992,20 @@ defmodule Pleroma.User do
|
|||||||
blocker
|
blocker
|
||||||
end
|
end
|
||||||
|
|
||||||
|
blocker =
|
||||||
|
if subscribed_to?(blocked, blocker) do
|
||||||
|
{:ok, blocker} = unsubscribe(blocked, blocker)
|
||||||
|
blocker
|
||||||
|
else
|
||||||
|
blocker
|
||||||
|
end
|
||||||
|
|
||||||
if following?(blocked, blocker) do
|
if following?(blocked, blocker) do
|
||||||
unfollow(blocked, blocker)
|
unfollow(blocked, blocker)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
{:ok, blocker} = update_follower_count(blocker)
|
||||||
|
|
||||||
info_cng =
|
info_cng =
|
||||||
blocker.info
|
blocker.info
|
||||||
|> User.Info.add_to_block(ap_id)
|
|> User.Info.add_to_block(ap_id)
|
||||||
@ -1021,12 +1048,21 @@ defmodule Pleroma.User do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscribed_to?(user, %{ap_id: ap_id}) do
|
||||||
|
with %User{} = target <- User.get_by_ap_id(ap_id) do
|
||||||
|
Enum.member?(target.info.subscribers, user.ap_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def muted_users(user),
|
def muted_users(user),
|
||||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.mutes))
|
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.mutes))
|
||||||
|
|
||||||
def blocked_users(user),
|
def blocked_users(user),
|
||||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks))
|
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks))
|
||||||
|
|
||||||
|
def subscribers(user),
|
||||||
|
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.subscribers))
|
||||||
|
|
||||||
def block_domain(user, domain) do
|
def block_domain(user, domain) do
|
||||||
info_cng =
|
info_cng =
|
||||||
user.info
|
user.info
|
||||||
@ -1063,6 +1099,42 @@ defmodule Pleroma.User do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def maybe_external_user_query(query, external) do
|
||||||
|
if external, do: external_user_query(query), else: query
|
||||||
|
end
|
||||||
|
|
||||||
|
def external_user_query(query \\ User) do
|
||||||
|
from(
|
||||||
|
u in query,
|
||||||
|
where: u.local == false,
|
||||||
|
where: not is_nil(u.nickname)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_active_user_query(query, active) do
|
||||||
|
if active, do: active_user_query(query), else: query
|
||||||
|
end
|
||||||
|
|
||||||
|
def active_user_query(query \\ User) do
|
||||||
|
from(
|
||||||
|
u in query,
|
||||||
|
where: fragment("not (?->'deactivated' @> 'true')", u.info),
|
||||||
|
where: not is_nil(u.nickname)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_deactivated_user_query(query, deactivated) do
|
||||||
|
if deactivated, do: deactivated_user_query(query), else: query
|
||||||
|
end
|
||||||
|
|
||||||
|
def deactivated_user_query(query \\ User) do
|
||||||
|
from(
|
||||||
|
u in query,
|
||||||
|
where: fragment("(?->'deactivated' @> 'true')", u.info),
|
||||||
|
where: not is_nil(u.nickname)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def active_local_user_query do
|
def active_local_user_query do
|
||||||
from(
|
from(
|
||||||
u in local_user_query(),
|
u in local_user_query(),
|
||||||
@ -1087,39 +1159,48 @@ defmodule Pleroma.User do
|
|||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_notification_settings(%User{} = user, settings \\ %{}) do
|
||||||
|
info_changeset = User.Info.update_notification_settings(user.info, settings)
|
||||||
|
|
||||||
|
change(user)
|
||||||
|
|> put_embed(:info, info_changeset)
|
||||||
|
|> update_and_set_cache()
|
||||||
|
end
|
||||||
|
|
||||||
def delete(%User{} = user) do
|
def delete(%User{} = user) do
|
||||||
{:ok, user} = User.deactivate(user)
|
{:ok, user} = User.deactivate(user)
|
||||||
|
|
||||||
# Remove all relationships
|
# Remove all relationships
|
||||||
{:ok, followers} = User.get_followers(user)
|
{:ok, followers} = User.get_followers(user)
|
||||||
|
|
||||||
followers
|
Enum.each(followers, fn follower -> User.unfollow(follower, user) end)
|
||||||
|> Enum.each(fn follower -> User.unfollow(follower, user) end)
|
|
||||||
|
|
||||||
{:ok, friends} = User.get_friends(user)
|
{:ok, friends} = User.get_friends(user)
|
||||||
|
|
||||||
friends
|
Enum.each(friends, fn followed -> User.unfollow(user, followed) end)
|
||||||
|> Enum.each(fn followed -> User.unfollow(user, followed) end)
|
|
||||||
|
|
||||||
query = from(a in Activity, where: a.actor == ^user.ap_id)
|
delete_user_activities(user)
|
||||||
|
end
|
||||||
|
|
||||||
Repo.all(query)
|
def delete_user_activities(%User{ap_id: ap_id} = user) do
|
||||||
|> Enum.each(fn activity ->
|
Activity
|
||||||
case activity.data["type"] do
|
|> where(actor: ^ap_id)
|
||||||
"Create" ->
|
|> Activity.with_preloaded_object()
|
||||||
ActivityPub.delete(Object.normalize(activity.data["object"]))
|
|> Repo.all()
|
||||||
|
|> Enum.each(fn
|
||||||
|
%{data: %{"type" => "Create"}} = activity ->
|
||||||
|
activity |> Object.normalize() |> ActivityPub.delete()
|
||||||
|
|
||||||
# TODO: Do something with likes, follows, repeats.
|
# TODO: Do something with likes, follows, repeats.
|
||||||
_ ->
|
_ ->
|
||||||
"Doing nothing"
|
"Doing nothing"
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_async(user, status \\ true) do
|
def disable_async(user, status \\ true) do
|
||||||
Pleroma.Jobs.enqueue(:user, __MODULE__, [:disable_async, user, status])
|
PleromaJobQueue.enqueue(:user, __MODULE__, [:disable_async, user, status])
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable(%User{} = user, status \\ true) do
|
def disable(%User{} = user, status \\ true) do
|
||||||
@ -1146,24 +1227,39 @@ defmodule Pleroma.User do
|
|||||||
|
|
||||||
def html_filter_policy(_), do: @default_scrubbers
|
def html_filter_policy(_), do: @default_scrubbers
|
||||||
|
|
||||||
|
def fetch_by_ap_id(ap_id) do
|
||||||
|
ap_try = ActivityPub.make_user_from_ap_id(ap_id)
|
||||||
|
|
||||||
|
case ap_try do
|
||||||
|
{:ok, user} ->
|
||||||
|
user
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
case OStatus.make_user(ap_id) do
|
||||||
|
{:ok, user} -> user
|
||||||
|
_ -> {:error, "Could not fetch by AP id"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_or_fetch_by_ap_id(ap_id) do
|
def get_or_fetch_by_ap_id(ap_id) do
|
||||||
user = get_by_ap_id(ap_id)
|
user = get_by_ap_id(ap_id)
|
||||||
|
|
||||||
if !is_nil(user) and !User.needs_update?(user) do
|
if !is_nil(user) and !User.needs_update?(user) do
|
||||||
user
|
user
|
||||||
else
|
else
|
||||||
ap_try = ActivityPub.make_user_from_ap_id(ap_id)
|
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
|
||||||
|
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
|
||||||
|
|
||||||
case ap_try do
|
user = fetch_by_ap_id(ap_id)
|
||||||
{:ok, user} ->
|
|
||||||
user
|
|
||||||
|
|
||||||
_ ->
|
if should_fetch_initial do
|
||||||
case OStatus.make_user(ap_id) do
|
with %User{} = user do
|
||||||
{:ok, user} -> user
|
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
||||||
_ -> {:error, "Could not fetch by AP id"}
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1239,8 +1335,8 @@ defmodule Pleroma.User do
|
|||||||
# this is because we have synchronous follow APIs and need to simulate them
|
# this is because we have synchronous follow APIs and need to simulate them
|
||||||
# with an async handshake
|
# with an async handshake
|
||||||
def wait_and_refresh(_, %User{local: true} = a, %User{local: true} = b) do
|
def wait_and_refresh(_, %User{local: true} = a, %User{local: true} = b) do
|
||||||
with %User{} = a <- Repo.get(User, a.id),
|
with %User{} = a <- User.get_by_id(a.id),
|
||||||
%User{} = b <- Repo.get(User, b.id) do
|
%User{} = b <- User.get_by_id(b.id) do
|
||||||
{:ok, a, b}
|
{:ok, a, b}
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
@ -1250,8 +1346,8 @@ defmodule Pleroma.User do
|
|||||||
|
|
||||||
def wait_and_refresh(timeout, %User{} = a, %User{} = b) do
|
def wait_and_refresh(timeout, %User{} = a, %User{} = b) do
|
||||||
with :ok <- :timer.sleep(timeout),
|
with :ok <- :timer.sleep(timeout),
|
||||||
%User{} = a <- Repo.get(User, a.id),
|
%User{} = a <- User.get_by_id(a.id),
|
||||||
%User{} = b <- Repo.get(User, b.id) do
|
%User{} = b <- User.get_by_id(b.id) do
|
||||||
{:ok, a, b}
|
{:ok, a, b}
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
@ -1338,7 +1434,7 @@ defmodule Pleroma.User do
|
|||||||
|> Enum.map(&String.downcase(&1))
|
|> Enum.map(&String.downcase(&1))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp local_nickname_regex() do
|
defp local_nickname_regex do
|
||||||
if Pleroma.Config.get([:instance, :extended_nickname_format]) do
|
if Pleroma.Config.get([:instance, :extended_nickname_format]) do
|
||||||
@extended_local_nickname_regex
|
@extended_local_nickname_regex
|
||||||
else
|
else
|
||||||
@ -1381,4 +1477,8 @@ defmodule Pleroma.User do
|
|||||||
offset: ^((page - 1) * page_size)
|
offset: ^((page - 1) * page_size)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def showing_reblogs?(%User{} = user, %User{} = target) do
|
||||||
|
target.ap_id not in user.info.muted_reblogs
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,8 @@ defmodule Pleroma.User.Info do
|
|||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
alias Pleroma.User.Info
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:banner, :map, default: %{})
|
field(:banner, :map, default: %{})
|
||||||
field(:background, :map, default: %{})
|
field(:background, :map, default: %{})
|
||||||
@ -19,6 +21,8 @@ defmodule Pleroma.User.Info do
|
|||||||
field(:blocks, {:array, :string}, default: [])
|
field(:blocks, {:array, :string}, default: [])
|
||||||
field(:domain_blocks, {:array, :string}, default: [])
|
field(:domain_blocks, {:array, :string}, default: [])
|
||||||
field(:mutes, {:array, :string}, default: [])
|
field(:mutes, {:array, :string}, default: [])
|
||||||
|
field(:muted_reblogs, {:array, :string}, default: [])
|
||||||
|
field(:subscribers, {:array, :string}, default: [])
|
||||||
field(:deactivated, :boolean, default: false)
|
field(:deactivated, :boolean, default: false)
|
||||||
field(:no_rich_text, :boolean, default: false)
|
field(:no_rich_text, :boolean, default: false)
|
||||||
field(:ap_enabled, :boolean, default: false)
|
field(:ap_enabled, :boolean, default: false)
|
||||||
@ -38,6 +42,10 @@ defmodule Pleroma.User.Info do
|
|||||||
field(:flavour, :string, default: nil)
|
field(:flavour, :string, default: nil)
|
||||||
field(:disabled, :boolean, default: false)
|
field(:disabled, :boolean, default: false)
|
||||||
|
|
||||||
|
field(:notification_settings, :map,
|
||||||
|
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
|
||||||
|
)
|
||||||
|
|
||||||
# Found in the wild
|
# Found in the wild
|
||||||
# ap_id -> Where is this used?
|
# ap_id -> Where is this used?
|
||||||
# bio -> Where is this used?
|
# bio -> Where is this used?
|
||||||
@ -55,6 +63,19 @@ defmodule Pleroma.User.Info do
|
|||||||
|> validate_required([:deactivated])
|
|> validate_required([:deactivated])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_notification_settings(info, settings) do
|
||||||
|
notification_settings =
|
||||||
|
info.notification_settings
|
||||||
|
|> Map.merge(settings)
|
||||||
|
|> Map.take(["remote", "local", "followers", "follows"])
|
||||||
|
|
||||||
|
params = %{notification_settings: notification_settings}
|
||||||
|
|
||||||
|
info
|
||||||
|
|> cast(params, [:notification_settings])
|
||||||
|
|> validate_required([:notification_settings])
|
||||||
|
end
|
||||||
|
|
||||||
def set_disabled_status(info, disabled) do
|
def set_disabled_status(info, disabled) do
|
||||||
params = %{disabled: disabled}
|
params = %{disabled: disabled}
|
||||||
|
|
||||||
@ -99,6 +120,14 @@ defmodule Pleroma.User.Info do
|
|||||||
|> validate_required([:blocks])
|
|> validate_required([:blocks])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_subscribers(info, subscribers) do
|
||||||
|
params = %{subscribers: subscribers}
|
||||||
|
|
||||||
|
info
|
||||||
|
|> cast(params, [:subscribers])
|
||||||
|
|> validate_required([:subscribers])
|
||||||
|
end
|
||||||
|
|
||||||
def add_to_mutes(info, muted) do
|
def add_to_mutes(info, muted) do
|
||||||
set_mutes(info, Enum.uniq([muted | info.mutes]))
|
set_mutes(info, Enum.uniq([muted | info.mutes]))
|
||||||
end
|
end
|
||||||
@ -115,6 +144,14 @@ defmodule Pleroma.User.Info do
|
|||||||
set_blocks(info, List.delete(info.blocks, blocked))
|
set_blocks(info, List.delete(info.blocks, blocked))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_to_subscribers(info, subscribed) do
|
||||||
|
set_subscribers(info, Enum.uniq([subscribed | info.subscribers]))
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_from_subscribers(info, subscribed) do
|
||||||
|
set_subscribers(info, List.delete(info.subscribers, subscribed))
|
||||||
|
end
|
||||||
|
|
||||||
def set_domain_blocks(info, domain_blocks) do
|
def set_domain_blocks(info, domain_blocks) do
|
||||||
params = %{domain_blocks: domain_blocks}
|
params = %{domain_blocks: domain_blocks}
|
||||||
|
|
||||||
@ -259,4 +296,23 @@ defmodule Pleroma.User.Info do
|
|||||||
|
|
||||||
cast(info, params, [:pinned_activities])
|
cast(info, params, [:pinned_activities])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def roles(%Info{is_moderator: is_moderator, is_admin: is_admin}) do
|
||||||
|
%{
|
||||||
|
admin: is_admin,
|
||||||
|
moderator: is_moderator
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_reblog_mute(info, ap_id) do
|
||||||
|
params = %{muted_reblogs: info.muted_reblogs ++ [ap_id]}
|
||||||
|
|
||||||
|
cast(info, params, [:muted_reblogs])
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_reblog_mute(info, ap_id) do
|
||||||
|
params = %{muted_reblogs: List.delete(info.muted_reblogs, ap_id)}
|
||||||
|
|
||||||
|
cast(info, params, [:muted_reblogs])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ defmodule Pleroma.User.WelcomeMessage do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp welcome_user() do
|
defp welcome_user do
|
||||||
with nickname when is_binary(nickname) <-
|
with nickname when is_binary(nickname) <-
|
||||||
Pleroma.Config.get([:instance, :welcome_user_nickname]),
|
Pleroma.Config.get([:instance, :welcome_user_nickname]),
|
||||||
%User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
%User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
@ -24,7 +24,7 @@ defmodule Pleroma.User.WelcomeMessage do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp welcome_message() do
|
defp welcome_message do
|
||||||
Pleroma.Config.get([:instance, :welcome_message])
|
Pleroma.Config.get([:instance, :welcome_message])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,40 +6,119 @@ defmodule Pleroma.UserInviteToken do
|
|||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
import Ecto.Query
|
||||||
alias Pleroma.UserInviteToken
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.UserInviteToken
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
@type token :: String.t()
|
||||||
|
|
||||||
schema "user_invite_tokens" do
|
schema "user_invite_tokens" do
|
||||||
field(:token, :string)
|
field(:token, :string)
|
||||||
field(:used, :boolean, default: false)
|
field(:used, :boolean, default: false)
|
||||||
|
field(:max_use, :integer)
|
||||||
|
field(:expires_at, :date)
|
||||||
|
field(:uses, :integer, default: 0)
|
||||||
|
field(:invite_type, :string)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_token do
|
@spec create_invite(map()) :: UserInviteToken.t()
|
||||||
|
def create_invite(params \\ %{}) do
|
||||||
|
%UserInviteToken{}
|
||||||
|
|> cast(params, [:max_use, :expires_at])
|
||||||
|
|> add_token()
|
||||||
|
|> assign_type()
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_token(changeset) do
|
||||||
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64()
|
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64()
|
||||||
|
put_change(changeset, :token, token)
|
||||||
token = %UserInviteToken{
|
|
||||||
used: false,
|
|
||||||
token: token
|
|
||||||
}
|
|
||||||
|
|
||||||
Repo.insert(token)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def used_changeset(struct) do
|
defp assign_type(%{changes: %{max_use: _max_use, expires_at: _expires_at}} = changeset) do
|
||||||
struct
|
put_change(changeset, :invite_type, "reusable_date_limited")
|
||||||
|> cast(%{}, [])
|
|
||||||
|> put_change(:used, true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_as_used(token) do
|
defp assign_type(%{changes: %{expires_at: _expires_at}} = changeset) do
|
||||||
with %{used: false} = token <- Repo.get_by(UserInviteToken, %{token: token}),
|
put_change(changeset, :invite_type, "date_limited")
|
||||||
{:ok, token} <- Repo.update(used_changeset(token)) do
|
end
|
||||||
{:ok, token}
|
|
||||||
else
|
defp assign_type(%{changes: %{max_use: _max_use}} = changeset) do
|
||||||
_e -> {:error, token}
|
put_change(changeset, :invite_type, "reusable")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp assign_type(changeset), do: put_change(changeset, :invite_type, "one_time")
|
||||||
|
|
||||||
|
@spec list_invites() :: [UserInviteToken.t()]
|
||||||
|
def list_invites do
|
||||||
|
query = from(u in UserInviteToken, order_by: u.id)
|
||||||
|
Repo.all(query)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec update_invite!(UserInviteToken.t(), map()) :: UserInviteToken.t() | no_return()
|
||||||
|
def update_invite!(invite, changes) do
|
||||||
|
change(invite, changes) |> Repo.update!()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec update_invite(UserInviteToken.t(), map()) ::
|
||||||
|
{:ok, UserInviteToken.t()} | {:error, Changeset.t()}
|
||||||
|
def update_invite(invite, changes) do
|
||||||
|
change(invite, changes) |> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec find_by_token!(token()) :: UserInviteToken.t() | no_return()
|
||||||
|
def find_by_token!(token), do: Repo.get_by!(UserInviteToken, token: token)
|
||||||
|
|
||||||
|
@spec find_by_token(token()) :: {:ok, UserInviteToken.t()} | nil
|
||||||
|
def find_by_token(token) do
|
||||||
|
with invite <- Repo.get_by(UserInviteToken, token: token) do
|
||||||
|
{:ok, invite}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec valid_invite?(UserInviteToken.t()) :: boolean()
|
||||||
|
def valid_invite?(%{invite_type: "one_time"} = invite) do
|
||||||
|
not invite.used
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_invite?(%{invite_type: "date_limited"} = invite) do
|
||||||
|
not_overdue_date?(invite) and not invite.used
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_invite?(%{invite_type: "reusable"} = invite) do
|
||||||
|
invite.uses < invite.max_use and not invite.used
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_invite?(%{invite_type: "reusable_date_limited"} = invite) do
|
||||||
|
not_overdue_date?(invite) and invite.uses < invite.max_use and not invite.used
|
||||||
|
end
|
||||||
|
|
||||||
|
defp not_overdue_date?(%{expires_at: expires_at}) do
|
||||||
|
Date.compare(Date.utc_today(), expires_at) in [:lt, :eq]
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec update_usage!(UserInviteToken.t()) :: nil | UserInviteToken.t() | no_return()
|
||||||
|
def update_usage!(%{invite_type: "date_limited"}), do: nil
|
||||||
|
|
||||||
|
def update_usage!(%{invite_type: "one_time"} = invite),
|
||||||
|
do: update_invite!(invite, %{used: true})
|
||||||
|
|
||||||
|
def update_usage!(%{invite_type: invite_type} = invite)
|
||||||
|
when invite_type == "reusable" or invite_type == "reusable_date_limited" do
|
||||||
|
changes = %{
|
||||||
|
uses: invite.uses + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
changes =
|
||||||
|
if changes.uses >= invite.max_use do
|
||||||
|
Map.put(changes, :used, true)
|
||||||
|
else
|
||||||
|
changes
|
||||||
|
end
|
||||||
|
|
||||||
|
update_invite!(invite, changes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Instances
|
||||||
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Instances
|
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.OStatus
|
||||||
|
alias Pleroma.Web.WebFinger
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Pleroma.Web.ActivityPub.Utils
|
import Pleroma.Web.ActivityPub.Utils
|
||||||
@ -89,15 +89,39 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
|
if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert(map, local \\ true) when is_map(map) do
|
def increase_replies_count_if_reply(%{
|
||||||
|
"object" =>
|
||||||
|
%{"inReplyTo" => reply_ap_id, "inReplyToStatusId" => reply_status_id} = object,
|
||||||
|
"type" => "Create"
|
||||||
|
}) do
|
||||||
|
if is_public?(object) do
|
||||||
|
Activity.increase_replies_count(reply_status_id)
|
||||||
|
Object.increase_replies_count(reply_ap_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def increase_replies_count_if_reply(_create_data), do: :noop
|
||||||
|
|
||||||
|
def decrease_replies_count_if_reply(%Object{
|
||||||
|
data: %{"inReplyTo" => reply_ap_id, "inReplyToStatusId" => reply_status_id} = object
|
||||||
|
}) do
|
||||||
|
if is_public?(object) do
|
||||||
|
Activity.decrease_replies_count(reply_status_id)
|
||||||
|
Object.decrease_replies_count(reply_ap_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrease_replies_count_if_reply(_object), do: :noop
|
||||||
|
|
||||||
|
def insert(map, local \\ true, fake \\ false) when is_map(map) do
|
||||||
with nil <- Activity.normalize(map),
|
with nil <- Activity.normalize(map),
|
||||||
map <- lazy_put_activity_defaults(map),
|
map <- lazy_put_activity_defaults(map, fake),
|
||||||
:ok <- check_actor_is_active(map["actor"]),
|
:ok <- check_actor_is_active(map["actor"]),
|
||||||
{_, true} <- {:remote_limit_error, check_remote_limit(map)},
|
{_, true} <- {:remote_limit_error, check_remote_limit(map)},
|
||||||
{:ok, map} <- MRF.filter(map),
|
{:ok, map} <- MRF.filter(map),
|
||||||
:ok <- insert_full_object(map) do
|
{recipients, _, _} = get_recipients(map),
|
||||||
{recipients, _, _} = get_recipients(map)
|
{:fake, false, map, recipients} <- {:fake, fake, map, recipients},
|
||||||
|
{:ok, object} <- insert_full_object(map) do
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
Repo.insert(%Activity{
|
Repo.insert(%Activity{
|
||||||
data: map,
|
data: map,
|
||||||
@ -106,6 +130,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
recipients: recipients
|
recipients: recipients
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Splice in the child object if we have one.
|
||||||
|
activity =
|
||||||
|
if !is_nil(object) do
|
||||||
|
Map.put(activity, :object, object)
|
||||||
|
else
|
||||||
|
activity
|
||||||
|
end
|
||||||
|
|
||||||
Task.start(fn ->
|
Task.start(fn ->
|
||||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
end)
|
end)
|
||||||
@ -114,8 +146,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
stream_out(activity)
|
stream_out(activity)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
%Activity{} = activity -> {:ok, activity}
|
%Activity{} = activity ->
|
||||||
error -> {:error, error}
|
{:ok, activity}
|
||||||
|
|
||||||
|
{:fake, true, map, recipients} ->
|
||||||
|
activity = %Activity{
|
||||||
|
data: map,
|
||||||
|
local: local,
|
||||||
|
actor: map["actor"],
|
||||||
|
recipients: recipients,
|
||||||
|
id: "pleroma:fakeid"
|
||||||
|
}
|
||||||
|
|
||||||
|
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
{:ok, activity}
|
||||||
|
|
||||||
|
error ->
|
||||||
|
{:error, error}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,7 +205,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(%{to: to, actor: actor, context: context, object: object} = params) do
|
def create(%{to: to, actor: actor, context: context, object: object} = params, fake \\ false) do
|
||||||
additional = params[:additional] || %{}
|
additional = params[:additional] || %{}
|
||||||
# only accept false as false value
|
# only accept false as false value
|
||||||
local = !(params[:local] == false)
|
local = !(params[:local] == false)
|
||||||
@ -169,11 +216,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
%{to: to, actor: actor, published: published, context: context, object: object},
|
%{to: to, actor: actor, published: published, context: context, object: object},
|
||||||
additional
|
additional
|
||||||
),
|
),
|
||||||
{:ok, activity} <- insert(create_data, local),
|
{:ok, activity} <- insert(create_data, local, fake),
|
||||||
# Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info
|
{:fake, false, activity} <- {:fake, fake, activity},
|
||||||
|
_ <- increase_replies_count_if_reply(create_data),
|
||||||
|
# Changing note count prior to enqueuing federation task in order to avoid
|
||||||
|
# race conditions on updating user.info
|
||||||
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
|
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
else
|
||||||
|
{:fake, true, activity} ->
|
||||||
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -309,17 +362,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|
|
||||||
def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
|
def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
|
||||||
user = User.get_cached_by_ap_id(actor)
|
user = User.get_cached_by_ap_id(actor)
|
||||||
|
to = (object.data["to"] || []) ++ (object.data["cc"] || [])
|
||||||
|
|
||||||
data = %{
|
with {:ok, object, activity} <- Object.delete(object),
|
||||||
"type" => "Delete",
|
data <- %{
|
||||||
"actor" => actor,
|
"type" => "Delete",
|
||||||
"object" => id,
|
"actor" => actor,
|
||||||
"to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
|
"object" => id,
|
||||||
}
|
"to" => to,
|
||||||
|
"deleted_activity_id" => activity && activity.id
|
||||||
with {:ok, _} <- Object.delete(object),
|
},
|
||||||
{:ok, activity} <- insert(data, local),
|
{:ok, activity} <- insert(data, local),
|
||||||
# Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info
|
_ <- decrease_replies_count_if_reply(object),
|
||||||
|
# Changing note count prior to enqueuing federation task in order to avoid
|
||||||
|
# race conditions on updating user.info
|
||||||
{:ok, _actor} <- decrease_note_count_if_public(user, object),
|
{:ok, _actor} <- decrease_note_count_if_public(user, object),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
@ -367,20 +423,38 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
content: content
|
content: content
|
||||||
} = params
|
} = params
|
||||||
) do
|
) do
|
||||||
additional = params[:additional] || %{}
|
|
||||||
|
|
||||||
# only accept false as false value
|
# only accept false as false value
|
||||||
local = !(params[:local] == false)
|
local = !(params[:local] == false)
|
||||||
|
forward = !(params[:forward] == false)
|
||||||
|
|
||||||
%{
|
additional = params[:additional] || %{}
|
||||||
|
|
||||||
|
params = %{
|
||||||
actor: actor,
|
actor: actor,
|
||||||
context: context,
|
context: context,
|
||||||
account: account,
|
account: account,
|
||||||
statuses: statuses,
|
statuses: statuses,
|
||||||
content: content
|
content: content
|
||||||
}
|
}
|
||||||
|> make_flag_data(additional)
|
|
||||||
|> insert(local)
|
additional =
|
||||||
|
if forward do
|
||||||
|
Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]})
|
||||||
|
else
|
||||||
|
Map.merge(additional, %{"to" => [], "cc" => []})
|
||||||
|
end
|
||||||
|
|
||||||
|
with flag_data <- make_flag_data(params, additional),
|
||||||
|
{:ok, activity} <- insert(flag_data, local),
|
||||||
|
:ok <- maybe_federate(activity) do
|
||||||
|
Enum.each(User.all_superusers(), fn superuser ->
|
||||||
|
superuser
|
||||||
|
|> Pleroma.AdminEmail.report(actor, account, statuses, content)
|
||||||
|
|> Pleroma.Mailer.deliver_async()
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, activity}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activities_for_context(context, opts \\ %{}) do
|
def fetch_activities_for_context(context, opts \\ %{}) do
|
||||||
@ -409,6 +483,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
),
|
),
|
||||||
order_by: [desc: :id]
|
order_by: [desc: :id]
|
||||||
)
|
)
|
||||||
|
|> Activity.with_preloaded_object()
|
||||||
|
|
||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
@ -501,7 +576,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
when is_list(tag_reject) and tag_reject != [] do
|
when is_list(tag_reject) and tag_reject != [] do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("(not (? #> '{\"object\",\"tag\"}') \\?| ?)", activity.data, ^tag_reject)
|
where: fragment(~s(\(not \(? #> '{"object","tag"}'\) \\?| ?\)), activity.data, ^tag_reject)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -511,7 +586,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
when is_list(tag_all) and tag_all != [] do
|
when is_list(tag_all) and tag_all != [] do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("(? #> '{\"object\",\"tag\"}') \\?& ?", activity.data, ^tag_all)
|
where: fragment(~s(\(? #> '{"object","tag"}'\) \\?& ?), activity.data, ^tag_all)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -520,14 +595,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
|
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag)
|
where: fragment(~s(\(? #> '{"object","tag"}'\) \\?| ?), activity.data, ^tag)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
|
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data)
|
where: fragment(~s(? <@ (? #> '{"object","tag"}'\)), ^tag, activity.data)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -600,7 +675,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
|
defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("? <@ (? #> '{\"object\",\"likes\"}')", ^ap_id, activity.data)
|
where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -609,7 +684,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
|
defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("not (? #> '{\"object\",\"attachment\"}' = ?)", activity.data, ^[])
|
where: fragment(~s(not (? #> '{"object","attachment"}' = ?\)), activity.data, ^[])
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -676,6 +751,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|
|
||||||
defp restrict_pinned(query, _), do: query
|
defp restrict_pinned(query, _), do: query
|
||||||
|
|
||||||
|
defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
|
||||||
|
muted_reblogs = info.muted_reblogs || []
|
||||||
|
|
||||||
|
from(
|
||||||
|
activity in query,
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"not ( ?->>'type' = 'Announce' and ? = ANY(?))",
|
||||||
|
activity.data,
|
||||||
|
activity.actor,
|
||||||
|
^muted_reblogs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_muted_reblogs(query, _), do: query
|
||||||
|
|
||||||
|
defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
|
||||||
|
|
||||||
|
defp maybe_preload_objects(query, _) do
|
||||||
|
query
|
||||||
|
|> Activity.with_preloaded_object()
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_activities_query(recipients, opts \\ %{}) do
|
def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
base_query =
|
base_query =
|
||||||
from(
|
from(
|
||||||
@ -685,6 +784,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
)
|
)
|
||||||
|
|
||||||
base_query
|
base_query
|
||||||
|
|> maybe_preload_objects(opts)
|
||||||
|> restrict_recipients(recipients, opts["user"])
|
|> restrict_recipients(recipients, opts["user"])
|
||||||
|> restrict_tag(opts)
|
|> restrict_tag(opts)
|
||||||
|> restrict_tag_reject(opts)
|
|> restrict_tag_reject(opts)
|
||||||
@ -703,6 +803,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|> restrict_replies(opts)
|
|> restrict_replies(opts)
|
||||||
|> restrict_reblogs(opts)
|
|> restrict_reblogs(opts)
|
||||||
|> restrict_pinned(opts)
|
|> restrict_pinned(opts)
|
||||||
|
|> restrict_muted_reblogs(opts)
|
||||||
|> Activity.restrict_disabled_users()
|
|> Activity.restrict_disabled_users()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -907,7 +1008,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
},
|
},
|
||||||
:ok <- Transmogrifier.contain_origin(id, params),
|
:ok <- Transmogrifier.contain_origin(id, params),
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
{:ok, Object.normalize(activity.data["object"])}
|
{:ok, Object.normalize(activity)}
|
||||||
else
|
else
|
||||||
{:error, {:reject, nil}} ->
|
{:error, {:reject, nil}} ->
|
||||||
{:reject, nil}
|
{:reject, nil}
|
||||||
@ -919,7 +1020,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
|
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
|
||||||
|
|
||||||
case OStatus.fetch_activity_from_url(id) do
|
case OStatus.fetch_activity_from_url(id) do
|
||||||
{:ok, [activity | _]} -> {:ok, Object.normalize(activity.data["object"])}
|
{:ok, [activity | _]} -> {:ok, Object.normalize(activity)}
|
||||||
e -> e
|
e -> e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,15 +6,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
|||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.ActivityPub.ObjectView
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.UserView
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.ObjectView
|
||||||
alias Pleroma.Web.ActivityPub.Relay
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
alias Pleroma.Web.ActivityPub.UserView
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_policies() do
|
def get_policies do
|
||||||
Application.get_env(:pleroma, :instance, [])
|
Application.get_env(:pleroma, :instance, [])
|
||||||
|> Keyword.get(:rewrite_policy, [])
|
|> Keyword.get(:rewrite_policy, [])
|
||||||
|> get_policies()
|
|> get_policies()
|
||||||
|
@ -23,15 +23,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
|||||||
defp score_displayname(_), do: 0.0
|
defp score_displayname(_), do: 0.0
|
||||||
|
|
||||||
defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
|
defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
|
||||||
|
# nickname will always be a binary string because it's generated by Pleroma.
|
||||||
nick_score =
|
nick_score =
|
||||||
nickname
|
nickname
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|> score_nickname()
|
|> score_nickname()
|
||||||
|
|
||||||
|
# displayname will either be a binary string or nil, if a displayname isn't set.
|
||||||
name_score =
|
name_score =
|
||||||
displayname
|
if is_binary(displayname) do
|
||||||
|> String.downcase()
|
displayname
|
||||||
|> score_displayname()
|
|> String.downcase()
|
||||||
|
|> score_displayname()
|
||||||
|
else
|
||||||
|
0.0
|
||||||
|
end
|
||||||
|
|
||||||
nick_score + name_score
|
nick_score + name_score
|
||||||
end
|
end
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
defp string_matches?(string, _) when not is_binary(string) do
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
defp string_matches?(string, pattern) when is_binary(pattern) do
|
defp string_matches?(string, pattern) when is_binary(pattern) do
|
||||||
String.contains?(string, pattern)
|
String.contains?(string, pattern)
|
||||||
end
|
end
|
||||||
@ -44,14 +48,29 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp check_replace(%{"object" => %{"content" => content, "summary" => summary}} = message) do
|
defp check_replace(%{"object" => %{"content" => content, "summary" => summary}} = message) do
|
||||||
|
content =
|
||||||
|
if is_binary(content) do
|
||||||
|
content
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
|
summary =
|
||||||
|
if is_binary(summary) do
|
||||||
|
summary
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
{content, summary} =
|
{content, summary} =
|
||||||
Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), {content, summary}, fn {pattern,
|
Enum.reduce(
|
||||||
replacement},
|
Pleroma.Config.get([:mrf_keyword, :replace]),
|
||||||
{content_acc,
|
{content, summary},
|
||||||
summary_acc} ->
|
fn {pattern, replacement}, {content_acc, summary_acc} ->
|
||||||
{String.replace(content_acc, pattern, replacement),
|
{String.replace(content_acc, pattern, replacement),
|
||||||
String.replace(summary_acc, pattern, replacement)}
|
String.replace(summary_acc, pattern, replacement)}
|
||||||
end)
|
end
|
||||||
|
)
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
message
|
message
|
||||||
@ -59,11 +78,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
|||||||
|> put_in(["object", "summary"], summary)}
|
|> put_in(["object", "summary"], summary)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def filter(%{"object" => %{"content" => nil}} = message) do
|
|
||||||
{:ok, message}
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"type" => "Create", "object" => %{"content" => _content}} = message) do
|
def filter(%{"type" => "Create", "object" => %{"content" => _content}} = message) do
|
||||||
with {:ok, message} <- check_reject(message),
|
with {:ok, message} <- check_reject(message),
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.Relay do
|
defmodule Pleroma.Web.ActivityPub.Relay do
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do
|
|||||||
|
|
||||||
def publish(%Activity{data: %{"type" => "Create"}} = activity) do
|
def publish(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||||
with %User{} = user <- get_actor(),
|
with %User{} = user <- get_actor(),
|
||||||
%Object{} = object <- Object.normalize(activity.data["object"]["id"]) do
|
%Object{} = object <- Object.normalize(activity) do
|
||||||
ActivityPub.announce(user, object, nil, true, false)
|
ActivityPub.announce(user, object, nil, true, false)
|
||||||
else
|
else
|
||||||
e -> Logger.error("error: #{inspect(e)}")
|
e -> Logger.error("error: #{inspect(e)}")
|
||||||
|
@ -7,9 +7,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
A module to handle coding from internal to wire ActivityPub and back.
|
A module to handle coding from internal to wire ActivityPub and back.
|
||||||
"""
|
"""
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
@ -83,14 +83,34 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|> fix_content_map
|
|> fix_content_map
|
||||||
|> fix_likes
|
|> fix_likes
|
||||||
|> fix_addressing
|
|> fix_addressing
|
||||||
|
|> fix_summary
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_summary(%{"summary" => nil} = object) do
|
||||||
|
object
|
||||||
|
|> Map.put("summary", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_summary(%{"summary" => _} = object) do
|
||||||
|
# summary is present, nothing to do
|
||||||
|
object
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_summary(object) do
|
||||||
|
object
|
||||||
|
|> Map.put("summary", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_addressing_list(map, field) do
|
def fix_addressing_list(map, field) do
|
||||||
if is_binary(map[field]) do
|
cond do
|
||||||
map
|
is_binary(map[field]) ->
|
||||||
|> Map.put(field, [map[field]])
|
Map.put(map, field, [map[field]])
|
||||||
else
|
|
||||||
map
|
is_nil(map[field]) ->
|
||||||
|
Map.put(map, field, [])
|
||||||
|
|
||||||
|
true ->
|
||||||
|
map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -128,13 +148,42 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|> fix_explicit_addressing(explicit_mentions)
|
|> fix_explicit_addressing(explicit_mentions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# if as:Public is addressed, then make sure the followers collection is also addressed
|
||||||
|
# so that the activities will be delivered to local users.
|
||||||
|
def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collection) do
|
||||||
|
recipients = to ++ cc
|
||||||
|
|
||||||
|
if followers_collection not in recipients do
|
||||||
|
cond do
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public" in cc ->
|
||||||
|
to = to ++ [followers_collection]
|
||||||
|
Map.put(object, "to", to)
|
||||||
|
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public" in to ->
|
||||||
|
cc = cc ++ [followers_collection]
|
||||||
|
Map.put(object, "cc", cc)
|
||||||
|
|
||||||
|
true ->
|
||||||
|
object
|
||||||
|
end
|
||||||
|
else
|
||||||
|
object
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_implicit_addressing(object, _), do: object
|
||||||
|
|
||||||
def fix_addressing(object) do
|
def fix_addressing(object) do
|
||||||
|
%User{} = user = User.get_or_fetch_by_ap_id(object["actor"])
|
||||||
|
followers_collection = User.ap_followers(user)
|
||||||
|
|
||||||
object
|
object
|
||||||
|> fix_addressing_list("to")
|
|> fix_addressing_list("to")
|
||||||
|> fix_addressing_list("cc")
|
|> fix_addressing_list("cc")
|
||||||
|> fix_addressing_list("bto")
|
|> fix_addressing_list("bto")
|
||||||
|> fix_addressing_list("bcc")
|
|> fix_addressing_list("bcc")
|
||||||
|> fix_explicit_addressing
|
|> fix_explicit_addressing
|
||||||
|
|> fix_implicit_addressing(followers_collection)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_actor(%{"attributedTo" => actor} = object) do
|
def fix_actor(%{"attributedTo" => actor} = object) do
|
||||||
@ -355,6 +404,40 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Flag objects are placed ahead of the ID check because Mastodon 2.8 and earlier send them
|
||||||
|
# with nil ID.
|
||||||
|
def handle_incoming(%{"type" => "Flag", "object" => objects, "actor" => actor} = data) do
|
||||||
|
with context <- data["context"] || Utils.generate_context_id(),
|
||||||
|
content <- data["content"] || "",
|
||||||
|
%User{} = actor <- User.get_cached_by_ap_id(actor),
|
||||||
|
|
||||||
|
# Reduce the object list to find the reported user.
|
||||||
|
%User{} = account <-
|
||||||
|
Enum.reduce_while(objects, nil, fn ap_id, _ ->
|
||||||
|
with %User{} = user <- User.get_cached_by_ap_id(ap_id) do
|
||||||
|
{:halt, user}
|
||||||
|
else
|
||||||
|
_ -> {:cont, nil}
|
||||||
|
end
|
||||||
|
end),
|
||||||
|
|
||||||
|
# Remove the reported user from the object list.
|
||||||
|
statuses <- Enum.filter(objects, fn ap_id -> ap_id != account.ap_id end) do
|
||||||
|
params = %{
|
||||||
|
actor: actor,
|
||||||
|
context: context,
|
||||||
|
account: account,
|
||||||
|
statuses: statuses,
|
||||||
|
content: content,
|
||||||
|
additional: %{
|
||||||
|
"cc" => [account.ap_id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivityPub.flag(params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# disallow objects with bogus IDs
|
# disallow objects with bogus IDs
|
||||||
def handle_incoming(%{"id" => nil}), do: :error
|
def handle_incoming(%{"id" => nil}), do: :error
|
||||||
def handle_incoming(%{"id" => ""}), do: :error
|
def handle_incoming(%{"id" => ""}), do: :error
|
||||||
@ -650,10 +733,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
if object = Object.normalize(id), do: {:ok, object}, else: nil
|
if object = Object.normalize(id), do: {:ok, object}, else: nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do
|
def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
|
||||||
with false <- String.starts_with?(inReplyTo, "http"),
|
with false <- String.starts_with?(in_reply_to, "http"),
|
||||||
{:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
|
{:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
|
||||||
Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
|
Map.put(object, "inReplyTo", replied_to_object["external_url"] || in_reply_to)
|
||||||
else
|
else
|
||||||
_e -> object
|
_e -> object
|
||||||
end
|
end
|
||||||
@ -736,6 +819,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
def prepare_outgoing(%{"type" => _type} = data) do
|
def prepare_outgoing(%{"type" => _type} = data) do
|
||||||
data =
|
data =
|
||||||
data
|
data
|
||||||
|
|> strip_internal_fields
|
||||||
|> maybe_fix_object_url
|
|> maybe_fix_object_url
|
||||||
|> Map.merge(Utils.make_json_ld_header())
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
|
|
||||||
@ -829,10 +913,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_attributed_to(object) do
|
def add_attributed_to(object) do
|
||||||
attributedTo = object["attributedTo"] || object["actor"]
|
attributed_to = object["attributedTo"] || object["actor"]
|
||||||
|
|
||||||
object
|
object
|
||||||
|> Map.put("attributedTo", attributedTo)
|
|> Map.put("attributedTo", attributed_to)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_likes(%{"id" => id, "like_count" => likes} = object) do
|
def add_likes(%{"id" => id, "like_count" => likes} = object) do
|
||||||
@ -870,7 +954,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
"announcements",
|
"announcements",
|
||||||
"announcement_count",
|
"announcement_count",
|
||||||
"emoji",
|
"emoji",
|
||||||
"context_id"
|
"context_id",
|
||||||
|
"deleted_activity_id"
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -885,8 +970,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|
|
||||||
defp strip_internal_tags(object), do: object
|
defp strip_internal_tags(object), do: object
|
||||||
|
|
||||||
defp user_upgrade_task(user) do
|
def perform(:user_upgrade, user) do
|
||||||
old_follower_address = User.ap_followers(user)
|
# we pass a fake user so that the followers collection is stripped away
|
||||||
|
old_follower_address = User.ap_followers(%User{nickname: user.nickname})
|
||||||
|
|
||||||
q =
|
q =
|
||||||
from(
|
from(
|
||||||
@ -929,28 +1015,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
Repo.update_all(q, [])
|
Repo.update_all(q, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_user_from_ap_id(ap_id, async \\ true) do
|
def upgrade_user_from_ap_id(ap_id) do
|
||||||
with %User{local: false} = user <- User.get_by_ap_id(ap_id),
|
with %User{local: false} = user <- User.get_by_ap_id(ap_id),
|
||||||
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
|
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id),
|
||||||
already_ap = User.ap_enabled?(user)
|
already_ap <- User.ap_enabled?(user),
|
||||||
|
{:ok, user} <- user |> User.upgrade_changeset(data) |> User.update_and_set_cache() do
|
||||||
{:ok, user} =
|
unless already_ap do
|
||||||
User.upgrade_changeset(user, data)
|
PleromaJobQueue.enqueue(:transmogrifier, __MODULE__, [:user_upgrade, user])
|
||||||
|> Repo.update()
|
|
||||||
|
|
||||||
if !already_ap do
|
|
||||||
# This could potentially take a long time, do it in the background
|
|
||||||
if async do
|
|
||||||
Task.start(fn ->
|
|
||||||
user_upgrade_task(user)
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
user_upgrade_task(user)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
|
%User{} = user -> {:ok, user}
|
||||||
e -> e
|
e -> e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,16 +3,17 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.Utils do
|
defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.Web
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Web.Router.Helpers
|
|
||||||
alias Pleroma.Web.Endpoint
|
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
alias Ecto.UUID
|
alias Ecto.UUID
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
alias Pleroma.Web.Endpoint
|
||||||
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@ -98,7 +99,10 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
%{
|
%{
|
||||||
"@context" => [
|
"@context" => [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
"#{Web.base_url()}/schemas/litepub-0.1.jsonld"
|
"#{Web.base_url()}/schemas/litepub-0.1.jsonld",
|
||||||
|
%{
|
||||||
|
"@language" => "und"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -174,18 +178,26 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
Adds an id and a published data if they aren't there,
|
Adds an id and a published data if they aren't there,
|
||||||
also adds it to an included object
|
also adds it to an included object
|
||||||
"""
|
"""
|
||||||
def lazy_put_activity_defaults(map) do
|
def lazy_put_activity_defaults(map, fake \\ false) do
|
||||||
%{data: %{"id" => context}, id: context_id} = create_context(map["context"])
|
|
||||||
|
|
||||||
map =
|
map =
|
||||||
map
|
unless fake do
|
||||||
|> Map.put_new_lazy("id", &generate_activity_id/0)
|
%{data: %{"id" => context}, id: context_id} = create_context(map["context"])
|
||||||
|> Map.put_new_lazy("published", &make_date/0)
|
|
||||||
|> Map.put_new("context", context)
|
map
|
||||||
|> Map.put_new("context_id", context_id)
|
|> Map.put_new_lazy("id", &generate_activity_id/0)
|
||||||
|
|> Map.put_new_lazy("published", &make_date/0)
|
||||||
|
|> Map.put_new("context", context)
|
||||||
|
|> Map.put_new("context_id", context_id)
|
||||||
|
else
|
||||||
|
map
|
||||||
|
|> Map.put_new("id", "pleroma:fakeid")
|
||||||
|
|> Map.put_new_lazy("published", &make_date/0)
|
||||||
|
|> Map.put_new("context", "pleroma:fakecontext")
|
||||||
|
|> Map.put_new("context_id", -1)
|
||||||
|
end
|
||||||
|
|
||||||
if is_map(map["object"]) do
|
if is_map(map["object"]) do
|
||||||
object = lazy_put_object_defaults(map["object"], map)
|
object = lazy_put_object_defaults(map["object"], map, fake)
|
||||||
%{map | "object" => object}
|
%{map | "object" => object}
|
||||||
else
|
else
|
||||||
map
|
map
|
||||||
@ -195,7 +207,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
@doc """
|
@doc """
|
||||||
Adds an id and published date if they aren't there.
|
Adds an id and published date if they aren't there.
|
||||||
"""
|
"""
|
||||||
def lazy_put_object_defaults(map, activity \\ %{}) do
|
def lazy_put_object_defaults(map, activity \\ %{}, fake)
|
||||||
|
|
||||||
|
def lazy_put_object_defaults(map, activity, true = _fake) do
|
||||||
|
map
|
||||||
|
|> Map.put_new_lazy("published", &make_date/0)
|
||||||
|
|> Map.put_new("id", "pleroma:fake_object_id")
|
||||||
|
|> Map.put_new("context", activity["context"])
|
||||||
|
|> Map.put_new("fake", true)
|
||||||
|
|> Map.put_new("context_id", activity["context_id"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def lazy_put_object_defaults(map, activity, _fake) do
|
||||||
map
|
map
|
||||||
|> Map.put_new_lazy("id", &generate_object_id/0)
|
|> Map.put_new_lazy("id", &generate_object_id/0)
|
||||||
|> Map.put_new_lazy("published", &make_date/0)
|
|> Map.put_new_lazy("published", &make_date/0)
|
||||||
@ -208,12 +231,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
"""
|
"""
|
||||||
def insert_full_object(%{"object" => %{"type" => type} = object_data})
|
def insert_full_object(%{"object" => %{"type" => type} = object_data})
|
||||||
when is_map(object_data) and type in @supported_object_types do
|
when is_map(object_data) and type in @supported_object_types do
|
||||||
with {:ok, _} <- Object.create(object_data) do
|
with {:ok, object} <- Object.create(object_data) do
|
||||||
:ok
|
{:ok, object}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert_full_object(_), do: :ok
|
def insert_full_object(_), do: {:ok, nil}
|
||||||
|
|
||||||
def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
||||||
# TODO
|
# TODO
|
||||||
@ -274,13 +297,31 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_like_data(%User{ap_id: ap_id} = actor, %{data: %{"id" => id}} = object, activity_id) do
|
def make_like_data(
|
||||||
|
%User{ap_id: ap_id} = actor,
|
||||||
|
%{data: %{"actor" => object_actor_id, "id" => id}} = object,
|
||||||
|
activity_id
|
||||||
|
) do
|
||||||
|
object_actor = User.get_cached_by_ap_id(object_actor_id)
|
||||||
|
|
||||||
|
to =
|
||||||
|
if Visibility.is_public?(object) do
|
||||||
|
[actor.follower_address, object.data["actor"]]
|
||||||
|
else
|
||||||
|
[object.data["actor"]]
|
||||||
|
end
|
||||||
|
|
||||||
|
cc =
|
||||||
|
(object.data["to"] ++ (object.data["cc"] || []))
|
||||||
|
|> List.delete(actor.ap_id)
|
||||||
|
|> List.delete(object_actor.follower_address)
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
"type" => "Like",
|
"type" => "Like",
|
||||||
"actor" => ap_id,
|
"actor" => ap_id,
|
||||||
"object" => id,
|
"object" => id,
|
||||||
"to" => [actor.follower_address, object.data["actor"]],
|
"to" => to,
|
||||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
"cc" => cc,
|
||||||
"context" => object.data["context"]
|
"context" => object.data["context"]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +376,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
[state, actor, object]
|
[state, actor, object]
|
||||||
)
|
)
|
||||||
|
|
||||||
activity = Repo.get(Activity, activity.id)
|
activity = Activity.get_by_id(activity.id)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
@ -385,13 +426,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
activity.data
|
activity.data
|
||||||
),
|
),
|
||||||
where: activity.actor == ^follower_id,
|
where: activity.actor == ^follower_id,
|
||||||
|
# this is to use the index
|
||||||
where:
|
where:
|
||||||
fragment(
|
fragment(
|
||||||
"? @> ?",
|
"coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||||
activity.data,
|
activity.data,
|
||||||
^%{object: followed_id}
|
activity.data,
|
||||||
|
^followed_id
|
||||||
),
|
),
|
||||||
order_by: [desc: :id],
|
order_by: [fragment("? desc nulls last", activity.id)],
|
||||||
limit: 1
|
limit: 1
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -548,13 +591,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
activity.data
|
activity.data
|
||||||
),
|
),
|
||||||
where: activity.actor == ^blocker_id,
|
where: activity.actor == ^blocker_id,
|
||||||
|
# this is to use the index
|
||||||
where:
|
where:
|
||||||
fragment(
|
fragment(
|
||||||
"? @> ?",
|
"coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||||
activity.data,
|
activity.data,
|
||||||
^%{object: blocked_id}
|
activity.data,
|
||||||
|
^blocked_id
|
||||||
),
|
),
|
||||||
order_by: [desc: :id],
|
order_by: [fragment("? desc nulls last", activity.id)],
|
||||||
limit: 1
|
limit: 1
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -602,7 +647,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
#### Flag-related helpers
|
#### Flag-related helpers
|
||||||
|
|
||||||
def make_flag_data(params, additional) do
|
def make_flag_data(params, additional) do
|
||||||
status_ap_ids = Enum.map(params.statuses || [], & &1.data["id"])
|
status_ap_ids =
|
||||||
|
Enum.map(params.statuses || [], fn
|
||||||
|
%Activity{} = act -> act.data["id"]
|
||||||
|
act when is_map(act) -> act["id"]
|
||||||
|
act when is_binary(act) -> act
|
||||||
|
end)
|
||||||
|
|
||||||
object = [params.account.ap_id] ++ status_ap_ids
|
object = [params.account.ap_id] ++ status_ap_ids
|
||||||
|
|
||||||
%{
|
%{
|
||||||
@ -614,4 +665,43 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
}
|
}
|
||||||
|> Map.merge(additional)
|
|> Map.merge(additional)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Fetches the OrderedCollection/OrderedCollectionPage from `from`, limiting the amount of pages fetched after
|
||||||
|
the first one to `pages_left` pages.
|
||||||
|
If the amount of pages is higher than the collection has, it returns whatever was there.
|
||||||
|
"""
|
||||||
|
def fetch_ordered_collection(from, pages_left, acc \\ []) do
|
||||||
|
with {:ok, response} <- Tesla.get(from),
|
||||||
|
{:ok, collection} <- Poison.decode(response.body) do
|
||||||
|
case collection["type"] do
|
||||||
|
"OrderedCollection" ->
|
||||||
|
# If we've encountered the OrderedCollection and not the page,
|
||||||
|
# just call the same function on the page address
|
||||||
|
fetch_ordered_collection(collection["first"], pages_left)
|
||||||
|
|
||||||
|
"OrderedCollectionPage" ->
|
||||||
|
if pages_left > 0 do
|
||||||
|
# There are still more pages
|
||||||
|
if Map.has_key?(collection, "next") do
|
||||||
|
# There are still more pages, go deeper saving what we have into the accumulator
|
||||||
|
fetch_ordered_collection(
|
||||||
|
collection["next"],
|
||||||
|
pages_left - 1,
|
||||||
|
acc ++ collection["orderedItems"]
|
||||||
|
)
|
||||||
|
else
|
||||||
|
# No more pages left, just return whatever we already have
|
||||||
|
acc ++ collection["orderedItems"]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Got the amount of pages needed, add them all to the accumulator
|
||||||
|
acc ++ collection["orderedItems"]
|
||||||
|
end
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, "Not an OrderedCollection or OrderedCollectionPage"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user