Created
January 11, 2023 11:51
-
-
Save solarisfire/858bb91f8287406b1094407e136e7bec to your computer and use it in GitHub Desktop.
Script to Firewall Defederated Servers from Local Instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################# | |
# | |
# Script to Firewall Defederated Servers from Local Instance | |
# Modified from original at: https://wiki.friendsofdesoto.social/en/Technical_Details#defederation-firewall | |
# | |
############################################################################# | |
#!/bin/bash | |
#Set the name of the Mastodon Database | |
DB=mastodon_production | |
ipset -L defederated >/dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
ipset create defederated hash:net | |
iptables -I INPUT -m set --match-set defederated src -j DROP | |
else | |
ipset flush defederated | |
fi | |
list=`sudo -u postgres psql -d $DB -t -c "select domain from domain_blocks where severity=1;"` | |
for i in $list | |
do | |
ips=`dig +short $i` | |
for p in $ips | |
do | |
ipset add defederated $p | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment