= fediblock-backend :showtitle: :toc: preamble :project: fediblock-backend :uri-base: https://schlomp.space/FediBlock/backend :uri-branch-main: {uri-base}/src/branch/main :uri-gcc: https://gcc.gnu.org/ :uri-clang: https://clang.llvm.org/ :uri-cmake: https://cmake.org/ :uri-catch: https://github.com/catchorg/Catch2 :uri-dpkg: https://packages.qa.debian.org/dpkg :uri-rpm-build: http://www.rpm.org :uri-clang-tidy: https://clang.llvm.org/extra/clang-tidy/ :uri-cgicc: https://www.gnu.org/software/cgicc/ :uri-nlohmann-json: https://nlohmann.github.io/json/ :uri-libgit2: https://libgit2.org/ :uri-libcurl: https://curl.haxx.se/libcurl/ :uri-icu: http://site.icu-project.org/ :uri-fmt: https://github.com/fmtlib/fmt :uri-pugixml: https://pugixml.org/ *{project}* turns form data into JSON and opens a pull request on link:https://schlomp.space/FediBlock/data[FediBlock/data]. Also included are tools to generate a HTML list and an RSS generator. == Usage .nginx config [source,nginx] -------------------------------------------------------------------------------- # Use 100 MiB cache with a 1 MiB memory zone (enough for ~8,000 keys). # Delete data that has not been accessed for 10 minutes. fastcgi_cache_path /var/cache/nginx/fediblock levels=1:2 max_size=100m keys_zone=fediblock:1m inactive=10m use_temp_path=off; fastcgi_cache_key "$scheme$request_method$host$request_uri"; add_header X-Cache $upstream_cache_status; limit_req_zone $binary_remote_addr zone=fediblock_add:10m rate=1r/m; server { # […] expires 30m; location ~* "(png|jpe?g|webp|gif)$" { expires 6d; } location /add { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/cgi-fcgiwrap.socket-1; fastcgi_param SCRIPT_FILENAME /usr/bin/fediblock-backend; fastcgi_param HOME "/var/lib/nginx"; # When I didn't set it, HOME was /root. client_max_body_size 5M; limit_req zone=fediblock_add; } location /rss { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/cgi-fcgiwrap.socket-1; fastcgi_param SCRIPT_FILENAME /usr/bin/fediblock-backend-gen_rss; fastcgi_param HOME "/var/lib/nginx"; fastcgi_cache fediblock; fastcgi_cache_valid 200 15m; # Cache answers for up to 15 minutes. fastcgi_cache_lock on; # Relay only one identical request at a time. } location /api/v1/list { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/cgi-fcgiwrap.socket-1; fastcgi_param SCRIPT_FILENAME /usr/bin/fediblock-backend-json_api; fastcgi_param HOME "/var/lib/nginx"; fastcgi_cache fediblock; fastcgi_cache_valid 200 15m; # Cache answers for up to 15 minutes. fastcgi_cache_lock on; # Relay only one identical request at a time. } } -------------------------------------------------------------------------------- .Generate SSH key [source,shell] -------------------------------------------------------------------------------- sudo -u nginx ssh-keygen -t ed25519 -f ~nginx/.local/share/fediblock-backend/ssh_id -------------------------------------------------------------------------------- Don't forget to add the key to the data repo. Generate an access token and save it in `~nginx/.local/share/fediblock-backend/gitea_access_token`. [NOTE] On non-Linux systems the data path is `~nginx/.fediblock-backend` unless `XDG_DATA_HOME` is set. Make sure the user that runs the CGI programs can create lockfiles. In Linux, the locations are `/run/user/` or `/run/lock`, on UNIX the location is `/var/run`. If none of these locations exist, `/tmp` is used as a fallback. === Generate HTML blocklist After compiling, run `fediblock-backend-gen_html`. The screenshots will be copied into the target directory and the output will be the HTML file. .Example: Generate the HTML blocklist in `~/blocklist/` [source,shell] -------------------------------------------------------------------------------- fediblock-backend-gen_html ~/blocklist > ~/blocklist/index.html -------------------------------------------------------------------------------- Existing screenshots will not be overwritten. [NOTE] The RSS generator expects the blocklist to be in `http(s)://your-domain/blocklist/`. == Install === From source ==== Dependencies * Tested OS: Linux * C\++ compiler with C++17 support (tested: link:{uri-gcc}[GCC] 7/8/9/10, link:{uri-clang}[clang] 6/7/10) * link:{uri-cmake}[CMake] (at least: 3.10) * link:{uri-cgicc}[cgicc] (tested: 3.2) * link:{uri-nlohmann-json}[nlohmann-json] (tested: 3.7 / 2.1) * link:{uri-libgit2}[libgit2] with SSH support (tested: 1.0 / 0.26) * link:{uri-libcurl}[libcurl] (at least: 7.56) * link:{uri-icu}[ICU] (tested: 67.1 / 60.2) * link:{uri-fmt}[fmt] (tested: 7.0 / 4.0) * link:{uri-pugixml}[pugixml] (tested: 1.10 / 1.8) * Optional ** Tests: link:{uri-catch}[Catch] (tested: 2.5 / 1.10) ** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.19) ** RPM package: link:{uri-rpm-build}[rpm-build] (tested: 4.11) ==== Get sourcecode [source,shell] -------------------------------------------------------------------------------- git clone https://schlomp.space/FediBlock/backend.git -------------------------------------------------------------------------------- ==== Compile [source,shell] -------------------------------------------------------------------------------- mkdir -p build && cd build cmake .. cmake --build . -- --jobs=$(nproc --ignore=1) -------------------------------------------------------------------------------- .CMake options: * `-DCMAKE_BUILD_TYPE=Debug` for a debug build. * `-DWITH_TESTS=YES` if you want to compile the tests. * `-DWITH_CLANG-TIDY=YES` to check the sourcecode with link:{uri-clang-tidy}[clang-tidy] while compiling. * One of: ** `-DWITH_DEB=YES` if you want to be able to generate a deb-package. ** `-DWITH_RPM=YES` if you want to be able to generate an rpm-package. To create a deb or rpm package, run `make package` after compiling. include::{uri-base}/raw/branch/main/CONTRIBUTING.adoc[]