Blocking individual gnusocial/postactiv nicknames

This commit is contained in:
Bob Mottram 2017-04-21 18:40:45 +01:00
parent 4ca6024342
commit 8a34b22417
4 changed files with 89 additions and 9 deletions

View File

@ -360,6 +360,9 @@ function upgrade_gnusocial {
fi
fi
gnusocial_block_user_script
gnusocial_block_domain_script gnusocial
gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
@ -767,6 +770,7 @@ function install_gnusocial_main {
${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$GNUSOCIAL_DOMAIN_NAME" -g gnusocial --public no
${PROJECT_NAME}-pass -u $MY_USERNAME -a gnusocial -p "$GNUSOCIAL_ADMIN_PASSWORD"
gnusocial_block_user_script
gnusocial_block_domain_script gnusocial
set_completion_param "gnusocial domain" "$GNUSOCIAL_DOMAIN_NAME"

View File

@ -359,6 +359,9 @@ function upgrade_postactiv {
function_check postactiv_running_script
postactiv_running_script
gnusocial_block_user_script
gnusocial_block_domain_script postactiv
upgrade_pleroma "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
postactiv_customise_logo
install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
@ -764,6 +767,7 @@ function install_postactiv_main {
${PROJECT_NAME}-pass -u $MY_USERNAME -a postactiv -p "$POSTACTIV_ADMIN_PASSWORD"
gnusocial_block_user_script
gnusocial_block_domain_script postactiv
set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"

View File

@ -1859,16 +1859,21 @@ function domain_blocking_add {
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Block a domain name" \
--backtitle $"Freedombone Control Panel" \
--inputbox $"Enter the domain name that you wish to block" 8 60 "" 2>$data
--inputbox $"Enter the domain name or GNU Social/postActiv nick@domain that you wish to block" 8 60 "" 2>$data
sel=$?
case $sel in
0)
blocked_domain=$(<$data)
if [ ${#blocked_domain} -gt 2 ]; then
if [[ "${blocked_domain}" == *'.'* ]]; then
firewall_block_domain $blocked_domain
dialog --title $"Block a domain" \
--msgbox $"The domain $blocked_domain has been blocked" 6 40
if [[ "${blocked_domain}" != *'@'* ]]; then
firewall_block_domain $blocked_domain
dialog --title $"Block a domain" \
--msgbox $"The domain $blocked_domain has been blocked" 6 40
else
dialog --title $"Block a GNU Social/postActiv nickname" \
--msgbox $"$blocked_domain has been blocked" 6 40
fi
fi
fi
;;
@ -1880,16 +1885,21 @@ function domain_blocking_remove {
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Unblock a domain name" \
--backtitle $"Freedombone Control Panel" \
--inputbox $"Enter the domain name that you wish to unblock" 8 60 "" 2>$data
--inputbox $"Enter the domain name or GNU Social/postActiv nick@domain that you wish to unblock" 8 60 "" 2>$data
sel=$?
case $sel in
0)
unblocked_domain=$(<$data)
if [ ${#unblocked_domain} -gt 2 ]; then
if [[ "${unblocked_domain}" == *'.'* ]]; then
firewall_unblock_domain $unblocked_domain
dialog --title $"Unblock a domain" \
--msgbox $"The domain $unblocked_domain has been unblocked" 6 40
if [[ "${unblocked_domain}" != *'@'* ]]; then
firewall_unblock_domain $unblocked_domain
dialog --title $"Unblock a domain" \
--msgbox $"The domain $unblocked_domain has been unblocked" 6 40
else
dialog --title $"Unblock a GNU Social/postActiv nickname" \
--msgbox $"$unblocked_domain has been unblocked" 6 40
fi
fi
fi
;;

View File

@ -327,6 +327,64 @@ function gnusocial_hourly_script {
chmod +x /etc/cron.hourly/${gnusocial_type}-daemons
}
function gnusocial_block_user_script {
echo '#!/bin/bash' > /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'database_name=$1' >> /usr/bin/gnusocial-delete-user
echo 'remove_user=$2' >> /usr/bin/gnusocial-delete-user
echo 'MARIADB_PASSWORD=$(freedombone-pass -u root -a mariadb)' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'if [ ${#remove_user} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-user
echo ' echo $"No user was specified"' >> /usr/bin/gnusocial-delete-user
echo ' exit 1' >> /usr/bin/gnusocial-delete-user
echo 'fi' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'if [[ "$remove_user" != *"."* || "$remove_user" != *"@"* ]]; then' >> /usr/bin/gnusocial-delete-user
echo ' echo $"This doesnt look like a user"' >> /usr/bin/gnusocial-delete-user
echo ' exit 2' >> /usr/bin/gnusocial-delete-user
echo 'fi' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'if [ ${#database_name} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-user
echo ' echo $"No database was specified"' >> /usr/bin/gnusocial-delete-user
echo ' exit 3' >> /usr/bin/gnusocial-delete-user
echo 'fi' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo "nickname=\$(echo \"\$remove_user\" | awk -F '@' '{print \$1}')" >> /usr/bin/gnusocial-delete-user
echo "remove_domain=\$(echo "\$remove_user" | awk -F '@' '{print \$2}')" >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'database_query="select profile.id from profile where nickname = ${nickname} and profileurl like "%${remove_domain}%";"' >> /usr/bin/gnusocial-delete-user
echo 'declare -a ids=$(mysql -u root --password="$MARIADB_PASSWORD" << EOF' >> /usr/bin/gnusocial-delete-user
echo 'use $database_name;' >> /usr/bin/gnusocial-delete-user
echo '$database_query' >> /usr/bin/gnusocial-delete-user
echo 'EOF' >> /usr/bin/gnusocial-delete-user
echo ')' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo 'ctr=0' >> /usr/bin/gnusocial-delete-user
echo 'for id in $ids' >> /usr/bin/gnusocial-delete-user
echo 'do' >> /usr/bin/gnusocial-delete-user
echo ' if [ $ctr -gt 0 ]; then' >> /usr/bin/gnusocial-delete-user
echo ' #echo "Removing user ID $id on $remove_domain"' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo ' database_query="delete from conversation where uri like "%${remove_domain}%";"' >> /usr/bin/gnusocial-delete-user
echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo ' database_query="delete from reply where profile_id=${id};"' >> /usr/bin/gnusocial-delete-user
echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo ' database_query="delete from reply where replied_id=${id};"' >> /usr/bin/gnusocial-delete-user
echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo ' database_query="delete from notice where profile_id=${id};"' >> /usr/bin/gnusocial-delete-user
echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user
echo '' >> /usr/bin/gnusocial-delete-user
echo ' database_query="delete from profile where id=${id};"' >> /usr/bin/gnusocial-delete-user
echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user
echo ' fi' >> /usr/bin/gnusocial-delete-user
echo ' ctr=$((ctr + 1))' >> /usr/bin/gnusocial-delete-user
echo 'done' >> /usr/bin/gnusocial-delete-user
chmod +x /usr/bin/gnusocial-delete-user
}
function gnusocial_block_domain_script {
database_name=$1
@ -390,7 +448,11 @@ function gnusocial_block_domain_script {
echo 'FIREWALL_DOMAINS=$HOME/${PROJECT_NAME}-firewall-domains.cfg' >> /usr/bin/${database_name}-firewall
echo '' >> /usr/bin/${database_name}-firewall
echo 'while read block; do' >> /usr/bin/${database_name}-firewall
echo ' /usr/bin/gnusocial-delete-domain "$database_name" "$block"' >> /usr/bin/${database_name}-firewall
echo ' if [[ "$block" != *"@"* ]]; then' >> /usr/bin/${database_name}-firewall
echo ' /usr/bin/gnusocial-delete-domain "$database_name" "$block"' >> /usr/bin/${database_name}-firewall
echo ' else' >> /usr/bin/${database_name}-firewall
echo ' /usr/bin/gnusocial-delete-user "$database_name" "$block"' >> /usr/bin/${database_name}-firewall
echo ' fi' >> /usr/bin/${database_name}-firewall
echo 'done <$FIREWALL_DOMAINS' >> /usr/bin/${database_name}-firewall
chmod +x /usr/bin/${database_name}-firewall