pleroma blocking script

This commit is contained in:
Bob Mottram 2018-01-21 17:56:39 +00:00
parent 4cbd1cce34
commit ab2cba8075
1 changed files with 29 additions and 0 deletions

View File

@ -59,6 +59,7 @@ PLEROMA_TITLE='Pleroma Server'
# Number of months after which posts expire
PLEROMA_EXPIRE_MONTHS=3
pleroma_expire_posts_script=/usr/bin/pleroma-expire-posts
blocking_script_file=/usr/bin/pleroma-blocking
pleroma_variables=(ONION_ONLY
PLEROMA_DOMAIN_NAME
@ -71,6 +72,26 @@ pleroma_variables=(ONION_ONLY
MY_EMAIL_ADDRESS
MY_USERNAME)
function create_pleroma_blocklist {
echo '#!/bin/bash' > $blocking_script_file
echo "if [ ! -f ${PROJECT_NAME}-firewall-domains.cfg ]; then" >> $blocking_script_file
echo ' exit 0' >> $blocking_script_file
echo 'fi' >> $blocking_script_file
echo 'cd /etc/postgresql' >> $blocking_script_file
echo 'while read blocked; do' >> $blocking_script_file
echo ' if [[ "$blocked" == *"."* || "$blocked" == *"@"* ]]; then' >> $blocking_script_file
echo ' if [ ${#blocked} -gt 4 ]; then' >> $blocking_script_file
echo " sudo -u postgres psql -d pleroma -c \"DELETE FROM objects WHERE data->>'content' ilike '%\${blocked}%' or data->>'actor' ilike '%\${blocked}%'\"" >> $blocking_script_file
echo ' fi' >> $blocking_script_file
echo ' fi' >> $blocking_script_file
echo "done <${PROJECT_NAME}-firewall-domains.cfg" >> $blocking_script_file
chmod +x $blocking_script_file
if ! grep -q "$blocking_script_file" /etc/crontab; then
echo "#*/1 * * * * root $blocking_script_file > /dev/null" >> /etc/crontab
fi
}
function expire_pleroma_posts {
domain_name=$1
expire_months=$3
@ -433,6 +454,7 @@ function pleroma_set_expire_months {
write_config_param "PLEROMA_EXPIRE_MONTHS" "$PLEROMA_EXPIRE_MONTHS"
expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
create_pleroma_blocklist
dialog --title $"Set Pleroma post expiry period" \
--msgbox $"Expiry period set to $PLEROMA_EXPIRE_MONTHS months" 6 60
@ -592,6 +614,9 @@ function upgrade_pleroma {
if [ ! -f $pleroma_expire_posts_script ]; then
expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
fi
if [ ! -f $blocking_script_file ]; then
create_pleroma_blocklist
fi
CURR_PLEROMA_COMMIT=$(get_completion_param "pleroma commit")
if [[ "$CURR_PLEROMA_COMMIT" == "$PLEROMA_COMMIT" ]]; then
@ -606,6 +631,7 @@ function upgrade_pleroma {
pleroma_recompile
expire_pleroma_posts $PLEROMA_DOMAIN_NAME $PLEROMA_EXPIRE_MONTHS
create_pleroma_blocklist
}
function backup_local_pleroma {
@ -752,6 +778,7 @@ function remove_pleroma {
remove_completion_param install_pleroma
sed -i '/pleroma domain/d' $COMPLETION_FILE
sed -i '/pleroma commit/d' $COMPLETION_FILE
sed -i "/$blocking_script_file/d" /etc/crontab
function_check remove_ddns_domain
remove_ddns_domain $PLEROMA_DOMAIN_NAME
@ -964,6 +991,8 @@ function install_pleroma {
fi
fi
create_pleroma_blocklist
# daemon
echo '[Unit]' > /etc/systemd/system/pleroma.service
echo 'Description=Pleroma social network' >> /etc/systemd/system/pleroma.service