- JavaScript 28.9%
- PHP 28.5%
- CSS 24.2%
- Python 17.7%
- HTML 0.7%
|
|
||
|---|---|---|
| assets | sanity check update | |
| bot | vesioning | |
| de | initial commit | |
| en | fixed typos | |
| .gitignore | ignore userdata | |
| christmas150158151615.php | minor typo | |
| error.html | initial commit | |
| forbidden.html | initial commit | |
| index.php | removed strict mode | |
| LICENSE.md | initial commit | |
| README.md | removed strict mode | |
| wartungsarbeiten.html | initial commit | |
Fedimap
An independent map for the Fediverse · Eine unabhängige Karte für das Fediversum
English
Fedimap is a map based on Leaflet.js that enables people from the Fediverse to voluntarily locate themselves, creating a sense of closeness and visibility in a decentralized world.
With minimal data collection, no advertising, and without tracking.
Deutsch
Fedimap ist eine Karte auf Basis von Leaflet.js, die es Menschen aus dem Fediversum ermöglicht, sich ganz freiwillig zu verorten und so ein Stück Nähe und Sichtbarkeit in einer dezentralen Welt zu schaffen.
Datensparsam, werbefrei und ohne Tracking.
Installation
The following setup describes an installation on a Debian GNU/Linux based system and should work as well on Ubuntu.
If not otherwise stated, all of the follwing commands have to be executed with Root-Permissions.
Bot Requirenments
The bot requires python3-mastodon and python3-dotenv. On a Debian based system these can be installed with the following command:
apt install python3-dotenv python3-mastodon
NGINX
As a webserver we use NGINX with PHP support through php-fpm. Install the required packages as followed:
apt install nginx certbot python3-certbot-nginx php-fpm -y
Create and enable a basic Webserver configuration:
tee /etc/nginx/sites-available/fedimap.conf <<EOF
server {
listen 80;
listen [::]:80;
server_name fedimap.de www.fedimap.de;
}
EOF
Enable the configuration:
ln -s /etc/nginx/sites-available/fedimap.conf /etc/nginx/sites-enabled/
Request a SSL-Certificate
We use Certbot to request a SSL-Certificate:
certbot --nginx -d fedimap.de -d www.fedimap.de
Certbot will automatically include the required changes in the previously created NGINX configuration.
Enable the Certbot timer to automatically renew the certificate:
systemctl enable --now certbot.timer
Adjust NGINX configuration
Adjust the webserver configuration to include PHP support, redirects and status page definitions:
server {
server_name fedimap.de www.fedimap.de;
root /var/www/fedimap/app;
index index.php index.html index.htm;
charset utf-8;
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/fedimap.de/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/fedimap.de/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
try_files $uri $uri/ =404;
autoindex off;
}
location = /feed.rss {
return 301 social.linux.pizza/@fedimap.rss;
}
location ~* \.rss$ {
add_header Content-Type "application/rss+xml";
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 401 403 404 /error.html;
}
server {
if ($host = www.fedimap.de) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = fedimap.de) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name fedimap.de www.fedimap.de;
return 404; # managed by Certbot
}
You can test if the configuration is valid using the following command:
nginx -t
Add an useraccount and create the webserver root for the application
First add an useraccount for the application and adjust the permissions of the home directory:
useradd --system --create-home --home-dir /var/www/fedimap --shell /bin/bash --comment "fedimap service account" -U fedimap
chmod 775 /var/www/fedimap
Create the directory for the application and ensure that the webserver group has access to it:
install -o fedimap -g www-data -m 770 -d /var/www/fedimap/app
Set SGID Bit on the application directory to ensure that all files created within it, will receive the same group ownership (www-data in this case):
chmod g+x /var/www/fedimap/app
Switch to the application user account and clone the repository to the newly created app directory
su - fedimap
git clone https://codeberg.org/Lioh/Fedimap.git app
Copy the Bot to a dedicated directory
We copy the bot to a dedicated directory within the home of the application user and adjust the permissions:
cp -r app/bot bot
Please not that on any updates of the bot within the git directory, the changes have to be applied manually. Do not edit or use the bot within the webserver root.
Register the bot on the relevant fediverse account
The bot has to be registered to a specific fediverse account. It is not recommended to use this account for anything else than the bot activity.
For this example the bot will be connected to a Mastodon account, but other Fediverse applications might work as well.
Open the Settings in the Mastodon webinterface and click on Development. Register a new application and define a name and the URL of the website it is associated with.
Define the following permissions:
read read:accounts read:blocks read:bookmarks read:favourites read:filters read:follows read:lists read:mutes read:notifications read:search read:statuses profile write write:accounts write:blocks write:bookmarks write:conversations write:favourites write:filters write:follows write:lists write:media write:mutes write:notifications write:reports write:statuses follow push
Save the settings and click on the Application name in the overview.
There you will find an access token which is necessary in order for the bot to communicate with the Fediverse account.
Note: Treat the TOKEN as if it where a password. This is a secret which allows the control of the bots Fediverse account. Do not push any of this information to a publicly accessible Git Repository.
Adjust environment variables
Copy the example env file to .env within the bots working directory
cp env.example .env
Adjust the MASTODON_BASE_URL variable so it points to the URL of your instance.
Insert the previously noted token into the ACCESS_TOKEN variable.
Create an empty userdata.txt file
Userdata is populated in assets/data/userdata.txt within the app directory. In order for the bot to start correctly, an empty file has to be created:
touch /var/www/fedimap/app/assets/data/userdata.txt
Test if the bot starts correctly
At this point, the bot can be started manually using the following command:
./fedimapbot
The output should be like this:
Fedimapbot vX.X starting...
Prepare a directory for logging and create a systemd service
The following commands are executed as root user. To leave the context of the bot account, simply type exit.
Log Directory
install -o fedimap -g fedimap -m 770 -d /var/www/fedimap/logs
chmod g+s /var/www/fedimap/logs
The logfiles can be rotated using logrotate. In order to do so, crewate a logrotate definition /etc/logrotate.d/kartenbot:
/var/www/fedimap/logs/fedimapbot.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
su fedimap fedimap
create 660 fedimap fedimap
postrotate
systemctl reload fedimapbot >/dev/null 2>&1 || true
endscript
}
Systemd Service
Create a systemd service definition /etc/systemd/system/fedimapbot.service with the following content
[Unit]
Description=Fedimapbot Python Service
After=network.target
[Service]
Type=simple
User=fedimap
Group=fedimap
WorkingDirectory=/var/www/fedimap/bot
Environment=PYTHONUNBUFFERED=1
ExecStart=/usr/bin/python3 -u /var/www/fedimap/bot/fedimapbot
Restart=always
UMask=0007
StandardOutput=append:/var/www/fedimap/logs/fedimapbot.log
StandardError=append:/var/www/fedimap/logs/fedimapbot.log
[Install]
WantedBy=multi-user.target
Reload the systemd service
systemctl daemon-reload
Enable the service on boot and start it directly
systemctl enable --now fedimapbot.service
Updating
To update the installation simply change to the fedimap user context and enter the app directory. The update itself can be done with a simple git pull
su - fedimap
cd app
git pull
If a new version of the bot is available copy it to the bot directory:
cd ~/bot
cp ../app/bot/fedimapbot .
Afterwards restart the bot service as Root user. You can leave the fedimap user context using the exit command.
systemctl restart fedimapbot
Testing
To test the fedimap website without the bot, simply add one or more users to the assets/data/userdata.txt and start a PHP server, e.g., with
echo "lioh@social.linux.pizza|47.05126161,8.30730557|https://social.linux.pizza/@lioh" > assets/data/userdata.txt
php -S localhost:8087
Use the web server opening http://localhost:8087 for manual testing.