Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
PLEROMA_DOMAIN_NAME=
PLEROMA_CODE=
PLEROMA_PORT=4000
PLEROMA_ONION_PORT=8011
PLEROMA_REPO="https://git.pleroma.social/pleroma/pleroma.git"
PLEROMA_COMMIT='41b0ecef959df0a1cda71e56e256cacebe48d56f'
pleroma_secret=$PLEROMA_DIR/config/dev.secret.exs
PLEROMA_BACKGROUND_IMAGE_URL=
PLEROMA_TITLE='Pleroma Server'
# Number of months after which posts expire
PLEROMA_EXPIRE_MONTHS=3
pleroma_expire_posts_script=/usr/bin/pleroma-expire-posts
PLEROMA_SHORT_DESCRIPTION=$'Federated microblogging'
PLEROMA_DESCRIPTION=$'Federated microblogging'
PLEROMA_MOBILE_APP_URL='https://f-droid.org/packages/com.keylesspalace.tusky'
pleroma_variables=(ONION_ONLY
PLEROMA_DOMAIN_NAME
PLEROMA_CODE
PLEROMA_WELCOME_MESSAGE
PLEROMA_BACKGROUND_IMAGE_URL
DDNS_PROVIDER
PLEROMA_TITLE
PLEROMA_EXPIRE_MONTHS
MY_EMAIL_ADDRESS
MY_USERNAME)
function pleroma_enable_chat {
if [[ "$1" == 't'* || "$1" == 'y'* || "$1" == 'T'* || "$1" == 'Y'* ]]; then
sed -i 's|"chatDisabled":.*|"chatDisabled": false,|g' $PLEROMA_DIR/priv/static/static/config.json
sed -i 's|:chat, enabled:.*|:chat, enabled: true|g' $PLEROMA_DIR/config/config.exs
else
sed -i 's|"chatDisabled":.*|"chatDisabled": true,|g' $PLEROMA_DIR/priv/static/static/config.json
sed -i 's|:chat, enabled:.*|:chat, enabled: false|g' $PLEROMA_DIR/config/config.exs
fi
pleroma_recompile
}
{ echo '#!/bin/bash';
echo "if [ ! -f /root/${PROJECT_NAME}-firewall-domains.cfg ]; then";
echo ' exit 0';
echo 'fi';
echo 'if [ -f /tmp/pleroma-blocking.lock ]; then';
echo ' cd /tmp';
echo ' find ./pleroma*.lock -type f -mmin +5 -exec rm {} \;';
echo ' if [ -f /tmp/pleroma-blocking.lock ]; then';
echo ' exit 0';
echo ' fi';
echo 'fi';
echo 'touch /tmp/pleroma-blocking.lock';
echo 'objects_query="DELETE FROM objects WHERE"';
echo 'objects_updated=';
echo 'users_query="DELETE FROM users WHERE"';
echo 'websub_server_subscriptions_query="DELETE FROM websub_server_subscriptions WHERE"';
echo 'websub_server_subscriptions_updated=';
echo 'while read blocked; do';
echo " if [[ \"\$blocked\" == *\".\"* || \"\$blocked\" == *\"@\"* ]]; then";
echo " if [ \${#blocked} -gt 4 ]; then";
echo " if [ \$objects_updated ]; then";
echo " objects_query=\"\${objects_query} or\"";
echo " users_query=\"\${users_query} or\"";
echo ' fi';
echo " objects_query=\"\${objects_query} data->>'content' ilike '%\${blocked}%' or data->>'actor' ilike '%\${blocked}%' or data->>'to' ilike '%\${blocked}%' or data->>'id' ilike '%\${blocked}%' or data->>'external_url' ilike '%\${blocked}%'\"";
echo " users_query=\"\${users_query} nickname ilike '%\${blocked}%'\"";
echo ' objects_updated=1';
echo " if [[ \"\$blocked\" != *\"@\"* ]]; then";
echo ' # Create a filter string for the pleroma configuration';
echo " if [ \"\$filter_str\" ]; then";
echo " filter_str=\"\${filter_str}, \\\"\$blocked\\\"\"";
echo ' else';
echo " if ! grep -q \"127.0.0.1 \$blocked\" /etc/hosts; then";
echo " echo \"127.0.0.1 \$blocked\" >> /etc/hosts";
echo ' fi';
echo " if [ \$websub_server_subscriptions_updated ]; then";
echo " websub_server_subscriptions_query=\"\${websub_server_subscriptions_query} or\"";
echo ' fi';
echo " websub_server_subscriptions_query=\"\${websub_server_subscriptions_query} callback like '%\${blocked}%'\"";
echo ' websub_server_subscriptions_updated=1';
echo ' else';
echo " curr_user_query=\"SELECT nickname FROM users where nickname ilike '%\${blocked}%'\"";
echo " curr_user_present=\$(sudo -u postgres psql -d pleroma -c \"\$curr_user_query\")";
echo " if [[ \"\$curr_user_present\" != *'(0 '* ]]; then";
echo " cd $PLEROMA_DIR";
echo " sudo -u pleroma mix deactivate_user \${blocked}";
echo ' fi';
echo ' fi';
echo ' fi';
echo ' fi';
echo 'done </root/freedombone-firewall-domains.cfg';
echo '';
echo "if [ \"\$filter_str\" ]; then";
echo " if ! grep -q \" \$filter_str \" $pleroma_secret; then";
echo " sed -i \"s| media_removal:.*| media_removal: [ \$filter_str ],|g\" $pleroma_secret";
echo " sed -i \"s| federated_timeline_removal:.*| federated_timeline_removal: [ \$filter_str ],|g\" $pleroma_secret";
echo " sed -i \"s| reject:.*| reject: [ \$filter_str ]|g\" $pleroma_secret";
echo " chown -R pleroma:pleroma $PLEROMA_DIR";
echo ' sudo -u pleroma mix clean';
echo ' sudo -u pleroma mix deps.compile';
echo ' sudo -u pleroma mix compile';
echo ' systemctl restart pleroma';
echo ' fi';
echo 'fi';
echo '';
echo '#cd /etc/postgresql';
echo "#if [ \$objects_updated ]; then";
echo "# sudo -u postgres psql -d pleroma -c \"\$objects_query\"";
echo "# sudo -u postgres psql -d pleroma -c \"\$users_query\"";
echo '#fi';
echo "#if [ \$websub_server_subscriptions_updated ]; then";
echo "# sudo -u postgres psql -d pleroma -c \"\$websub_server_subscriptions_query\"";
echo '#fi';
chmod +x $blocking_script_file
if ! grep -q "$blocking_script_file" /etc/crontab; then
function expire_pleroma_posts {
domain_name=$1
expire_months=$3
# files are what take up most of the backup time, so don't keep them for very long
expire_days_files=7
# To prevent the database size from growing endlessly this script expires posts
# after a number of months
if [ ! -d /etc/pleroma ]; then
return
fi
{ echo '#!/bin/bash';
echo "plmonths=\"$PLEROMA_EXPIRE_MONTHS\"";
echo "if [ \${#plmonths} -eq 0 ]; then";
echo ' exit 1';
echo 'fi';
echo "if [[ \"\$plmonths\" == \"0\" ]]; then";
echo ' exit 2';
echo 'fi';
echo "oldate=\$(date +%Y-%m-%d --date=\"\$plmonths months ago\")";
echo 'cd /etc/postgresql';
echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM notifications WHERE inserted_at <= '\$oldate 01:01:01'\"";
echo "sudo -u postgres psql -d pleroma -c \"DELETE FROM objects WHERE inserted_at <= '\$oldate 01:01:01'\""; } > $pleroma_expire_posts_script
chmod +x $pleroma_expire_posts_script
pleroma_expire_script=/etc/cron.daily/pleroma-expire
expire_days_files_threshold=$((expire_days_files - 1))
{ echo '#!/bin/bash';
echo 'cd /etc/postgresql';
echo 'if [ -d /etc/pleroma/tempfiles ]; then';
echo ' rm -rf /etc/pleroma/tempfiles';
echo 'fi';
echo '';
echo '# make directory to temporarily store local avatars';
echo 'mkdir /etc/pleroma/tempfiles';
echo '';
echo '# get the local avatar files';
echo "avatars=\$(sudo -u postgres psql -d pleroma -c \"select avatar->>'url' from users where avatar->>'url' like '%${domain_name}%'\")";
echo '';
echo '# copy the avatar files to a temporary directory';
echo "arr=( \$avatars )";
echo " if [[ \"\$i\" == *'/media/'* ]]; then";
echo " imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');";
echo " if [ -f \$imagefile ]; then";
echo " imagedir=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}' | awk -F '/' '{print \$1}')";
echo " nowdate=\$(date +%s)";
echo " sinceepoch=\$(date +%s -r \$imagefile)";
echo " daysold=\$(((\$nowdate - \$sinceepoch) / 86400))";
echo " if [ \$daysold -ge ${expire_days_files_threshold} ]; then";
echo " if [ ! -d \$imagedir ]; then";
echo " mkdir \$imagedir";
echo ' fi';
echo " cp -rp \$imagefile \$imagedir";
echo ' fi';
echo ' fi';
echo ' fi';
echo 'done';
echo '';
echo '# get the local banner files';
echo "banners=\$(sudo -u postgres psql -d pleroma -c \"select avatar->>'banner' from users where avatar->>'url' like '%${domain_name}%'\")";
echo '';
echo '# copy the banner files to a temporary directory';
echo "arr=( \$banners )";
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
echo " if [[ \"\$i\" == *'/media/'* ]]; then";
echo " imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');";
echo " if [ -f \$imagefile ]; then";
echo " imagedir=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}' | awk -F '/' '{print \$1}')";
echo " nowdate=\$(date +%s)";
echo " sinceepoch=\$(date +%s -r \$imagefile)";
echo " daysold=\$(((\$nowdate - \$sinceepoch) / 86400))";
echo " if [ \$daysold -ge ${expire_days_files_threshold} ]; then";
echo " if [ ! -d \$imagedir ]; then";
echo " mkdir \$imagedir";
echo ' fi';
echo " cp -rp \$imagefile \$imagedir";
echo ' fi';
echo ' fi';
echo ' fi';
echo 'done';
echo '';
echo '# delete old files';
echo "find /etc/pleroma/uploads/* -mtime +${expire_days_files} -exec rm -rf {} +";
echo '';
echo '# move avatar files back to uploads';
echo 'chown -R pleroma:pleroma /etc/pleroma/tempfiles';
echo 'mv /etc/pleroma/tempfiles/* /etc/pleroma/uploads';
echo 'rm -rf /etc/pleroma/tempfiles';
echo '';
echo '/usr/bin/pleroma-expire-posts 2> /dev/null'; } > $pleroma_expire_script
chmod +x $pleroma_expire_script
# remove any old cron job
if grep -q "pleroma-expire" /etc/crontab; then
sed -i "/pleroma-expire/d" /etc/crontab
rm /usr/bin/pleroma-expire
fi
# remove old expire script
if [ -f /etc/cron.weekly/clear-pleroma-database ]; then
rm /etc/cron.weekly/clear-pleroma-database
fi
}
function pleroma_recompile {
# necessary after parameter changes
chown -R pleroma:pleroma $PLEROMA_DIR
sudo -u pleroma mix clean
sudo -u pleroma mix deps.compile
sudo -u pleroma mix compile
if [ -f /etc/systemd/system/pleroma.service ]; then
systemctl restart pleroma
fi
}
function logging_on_pleroma {
echo -n ''
}
function logging_off_pleroma {
echo -n ''
}
function remove_user_pleroma {
remove_username="$1"
cd $PLEROMA_DIR || exit 252498
mix rm_user "$remove_username"
}
function add_user_pleroma {
new_username="$1"
new_user_password="$2"
cd $PLEROMA_DIR || exit 348346
mix register_user "$new_username" "$new_username" "$new_username@$HOSTNAME" $"Your bio goes here" "$new_user_password"
"${PROJECT_NAME}-pass" -u "$new_username" -a pleroma -p "$new_user_password"
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
PLEROMA_DOMAIN_NAME='pleroma.local'
else
PLEROMA_DETAILS_COMPLETE=
while [ ! $PLEROMA_DETAILS_COMPLETE ]
do
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
dialog --backtitle $"Freedombone Configuration" \
--title $"Pleroma Configuration" \
--form $"\\nPlease enter your Pleroma details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
$"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
$"Title:" 2 1 "$(grep "$PLEROMA_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
$"Background image URL:" 3 1 "$(grep "$PLEROMA_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
$"Code:" 4 1 "$(grep 'PLEROMA_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
else
dialog --backtitle $"Freedombone Configuration" \
--title $"Pleroma Configuration" \
--form $"\\nPlease enter your Pleroma details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
$"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
$"Title:" 2 1 "$(grep "$PLEROMA_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
$"Background image URL:" 3 1 "$(grep "$PLEROMA_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
PLEROMA_DOMAIN_NAME=$(sed -n 1p < "$data")
title=$(sed -n 2p < "$data")
if [ ${#img_url} -gt 1 ]; then
PLEROMA_BACKGROUND_IMAGE_URL=$img_url
fi
if [[ $PLEROMA_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
PLEROMA_DOMAIN_NAME=""
fi
TEST_DOMAIN_NAME=$PLEROMA_DOMAIN_NAME
validate_domain_name
PLEROMA_DOMAIN_NAME=
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
PLEROMA_DOMAIN_NAME=
fi
fi
fi
fi
if [ $PLEROMA_DOMAIN_NAME ]; then
PLEROMA_DETAILS_COMPLETE="yes"
fi
done
# remove any invalid characters
if [ ${#PLEROMA_TITLE} -gt 0 ]; then
PLEROMA_TITLE="$new_title"
fi
# save the results in the config file
write_config_param "PLEROMA_CODE" "$PLEROMA_CODE"
write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
fi
write_config_param "PLEROMA_DOMAIN_NAME" "$PLEROMA_DOMAIN_NAME"
APP_INSTALLED=1
}
function change_password_pleroma {
new_user_password="$2"
#${PROJECT_NAME}-pass -u "$curr_username" -a pleroma -p "$new_user_password"
}
function pleroma_create_database_failed {
run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
}
function pleroma_create_config {
config_filename="$1"
domain=$PLEROMA_DOMAIN_NAME
domain_scheme='https'
domain_port=443
if [[ "$ONION_ONLY" != 'no' ]]; then
domain=$PLEROMA_ONION_HOSTNAME
domain_scheme='http'
domain_port=80
fi
{ echo 'use Mix.Config';
echo '';
echo 'config :pleroma, Pleroma.Web.Endpoint,';
echo ' pubsub: [name: Pleroma.Web.PubSub, adapter: Phoenix.PubSub.PG2],';
echo " secret_key_base: \"$PLEROMA_SECRET_KEY\",";
echo " http: [port: $PLEROMA_PORT],";
echo ' protocol: "http",';
echo ' debug_errors: true,';
echo ' code_reloader: true,';
echo ' check_origin: false,';
echo ' watchers: [],';
echo " url: [host: \"$domain\", scheme: \"$domain_scheme\", port: $domain_port]";
echo '';
echo "config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}";
echo '';
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# shellcheck disable=SC2028
echo "config :logger, :console, format: \"[\$level] \$message\\n\"";
echo '';
echo 'config :comeonin, :pbkdf2_rounds, 1';
echo '';
echo '# begin filtering';
echo 'config :pleroma, :mrf_simple,';
echo ' media_removal: [],';
echo ' media_nsfw: [],';
echo ' federated_timeline_removal: [],';
echo ' accept: [],';
echo ' reject: []';
echo '';
echo 'config :phoenix, :stacktrace_depth, 20';
echo '';
echo 'config :pleroma, Pleroma.Repo,';
echo ' adapter: Ecto.Adapters.Postgres,';
echo ' username: "pleroma",';
echo " password: \"$PLEROMA_ADMIN_PASSWORD\",";
echo ' database: "pleroma",';
echo ' hostname: "localhost",';
echo ' pool_size: 10';
echo '';
echo 'try do';
echo ' # import_config "dev.secret.exs"';
echo 'rescue';
# shellcheck disable=SC2028
echo ' _-> IO.puts("!!! RUNNING IN LOCALHOST DEV MODE! !!!\nFEDERATION WONT WORK UNTIL YOU CONFIGURE A dev.secret.exs")';
echo 'end'; } > "$config_filename"
}
if [ -f "$IMAGE_PASSWORD_FILE" ]; then
PLEROMA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
if [ ! "$PLEROMA_ADMIN_PASSWORD" ]; then
PLEROMA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
add_postgresql_user pleroma "$PLEROMA_ADMIN_PASSWORD" encrypted
run_system_query_postgresql "create database pleroma;"
# temporarily allow the user to create databases
run_system_query_postgresql "ALTER USER pleroma CREATEDB;"
run_system_query_postgresql "ALTER USER pleroma SUPERUSER;"
run_system_query_postgresql "GRANT ALL ON ALL tables IN SCHEMA public TO pleroma;"
run_system_query_postgresql "GRANT ALL ON ALL sequences IN SCHEMA public TO pleroma;"
run_system_query_postgresql "set statement_timeout to 40000;"
read_config_param "PLEROMA_SECRET_KEY"
if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
PLEROMA_SECRET_KEY="$(create_password 30)$(create_password 30)$(create_password 30)"
if [ ${#PLEROMA_SECRET_KEY} -lt 64 ]; then
echo $'Pleroma secret key not created'
exit 6782352
fi
write_config_param "PLEROMA_SECRET_KEY" "$PLEROMA_SECRET_KEY"
fi
if [ ! -d $PLEROMA_DIR/config ]; then
echo $"Missing directory $PLEROMA_DIR/config"
exit 7835393
fi
if [ ! -f $PLEROMA_DIR/config/dev.exs ]; then
echo $"Did not find $PLEROMA_DIR/config/dev.exs"
exit 78923528
fi
pleroma_create_config $pleroma_secret
sudo -u pleroma mix local.hex --force
sudo -u pleroma mix deps.compile mimerl
echo $'mix ecto.migrate failed'
exit 73752573
fi
# revoke the ability to create databases for this user
run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
}
function reconfigure_pleroma {
echo -n ''
}
function pleroma_set_background_image {
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
dialog --title $"Pleroma" \
--backtitle $"Freedombone Control Panel" \
if [ ${#temp_background} -gt 0 ]; then
PLEROMA_BACKGROUND_IMAGE_URL="$temp_background"
write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
if [[ $(pleroma_set_background_image_from_url $PLEROMA_DIR "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE" | tail -n 1) == "0" ]]; then
dialog --title $"Set Pleroma login background" \
--msgbox $"The background image has been set" 6 60
fi
fi
;;
esac
dialog --title $"Pleroma" \
--backtitle $"Freedombone Control Panel" \
if [ ${#new_title} -gt 0 ]; then
PLEROMA_TITLE="$new_title"
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/static/config.json
sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/priv/static/static/config.json
sed -i "s|name: .*|name: \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/config/config.exs
systemctl restart pleroma
dialog --title $"Set Pleroma title" \
--msgbox $"The title has been set" 6 60
fi
;;
esac
}
function pleroma_set_expire_months {
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
dialog --title $"Pleroma" \
--backtitle $"Freedombone Control Panel" \
--inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$PLEROMA_EXPIRE_MONTHS" 2>"$data"
if [ ${#new_expiry_months} -gt 0 ]; then
# should contain no spaces
if [[ "$new_expiry_months" == *" "* ]]; then
return
fi
# should be a number
re='^[0-9]+$'
if ! [[ $new_expiry_months =~ $re ]] ; then
return
fi
# set the new value
PLEROMA_EXPIRE_MONTHS=$new_expiry_months
write_config_param "PLEROMA_EXPIRE_MONTHS" "$PLEROMA_EXPIRE_MONTHS"
expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
dialog --title $"Set Pleroma post expiry period" \
--msgbox $"Expiry period set to $PLEROMA_EXPIRE_MONTHS months" 6 60
fi
;;
esac
function pleroma_disable_registrations {
dialog --title $"Disable new Pleroma user registrations" \
--backtitle $"Freedombone Control Panel" \
0) sed -i 's|registrations_open: true|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
sed -i 's|registrations_open: True|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
sed -i 's|"registrationOpen": true|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
sed -i 's|"registrationOpen": True|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
1) sed -i 's|registrations_open: false|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
sed -i 's|registrations_open: False|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
sed -i 's|"registrationOpen": false|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
sed -i 's|"registrationOpen": False|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
255) return;;
esac
pleroma_recompile
}
dialog --backtitle $"Freedombone Control Panel" \
--title $"Add Custom Emoji" \
$"Shortcode:" 1 1 "" 1 18 16 15 \
$"ImageURL:" 2 1 "" 2 18 512 10000 \
shortcode=$(sed -n 1p < "$data")
image_url=$(sed -n 2p < "$data")
rm -f "$data"
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
if [ ${#shortcode} -lt 2 ]; then
return
fi
if [ ${#image_url} -lt 2 ]; then
return
fi
if [[ "$image_url" != *'.'* ]]; then
return
fi
if [[ "$image_url" != *'.png' && "$image_url" != *'.jpg' && "$image_url" != *'.jpeg' && "$image_url" != *'.gif' ]]; then
dialog --title $"Add Custom Emoji" \
--msgbox $"The image must be png/jpg/gif format" 6 60
return
fi
if [[ "$shortcode" == *':'* || "$shortcode" == *' '* || "$shortcode" == *'.'* || "$shortcode" == *'!'* ]]; then
dialog --title $"Add Custom Emoji" \
--msgbox $"The shortcode contains invalid characters" 6 60
return
fi
image_extension='png'
if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' ]]; then
image_extension='jpg'
fi
if [[ "$image_url" == *'.gif' ]]; then
image_extension='gif'
fi
if [ ! -d $PLEROMA_DIR/priv/static/emoji ]; then
mkdir -p $PLEROMA_DIR/priv/static/emoji
image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
wget "$image_url" -O "$image_filename"
if [ ! -f "$image_filename" ]; then
dialog --title $"Add Custom Emoji" \
--msgbox $"Unable to download the image" 6 60
return
fi
if [[ "$image_url" == *'.jpg' || "$image_url" == *'.jpeg' || "$image_url" == *'.gif' ]]; then
convert "$image_filename" -resize "$emoji_resolution" "$PLEROMA_DIR/priv/static/emoji/${shortcode}.png"
if [ ! -f "$PLEROMA_DIR/priv/static/emoji/${shortcode}.png" ]; then
dialog --title $"Add Custom Emoji" \
--msgbox $"Unable to convert empji image to png format" 6 60
return
fi
image_filename=$PLEROMA_DIR/priv/static/emoji/${shortcode}.${image_extension}
convert "$image_filename" -resize "$emoji_resolution" "$image_filename"
echo "${shortcode}, /emoji/${shortcode}.${image_extension}" >> $PLEROMA_DIR/config/emoji.txt
sed -i "s|${shortcode},.*|${shortcode}, /emoji/${shortcode}.${image_extension}|g" $PLEROMA_DIR/config/emoji.txt
fi
chown -R pleroma:pleroma $PLEROMA_DIR
clear
echo ''
echo $'Recompiling Pleroma with the new emoji'
systemctl stop pleroma
pleroma_recompile
dialog --title $"Add Custom Emoji" \
--msgbox $"Custom emoji :${shortcode}: has been added" 6 70
}
read_config_param PLEROMA_EXPIRE_MONTHS
while true
do
chatenabled=
enablechatstr=$'Enable chat system'
if grep -q ':chat, enabled: true' $PLEROMA_DIR/config/config.exs; then
chatenabled=1
enablechatstr=$'Disable chat system'
fi
pleromatorstr=$'Enable routing through Tor for onion addresses'
if grep -q '9050' $pleroma_secret; then
pleromatorstr=$'Disable routing through Tor'
fi
W=(1 $"Set a background image"
2 $"Set the title"
3 $"Disable new account registrations"
4 $"Add a custom emoji"
5 $"Set post expiry period (currently $PLEROMA_EXPIRE_MONTHS months)"
6 "$enablechatstr"
7 "$pleromatorstr")
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Pleroma" --menu $"Choose an operation, or ESC to exit:" 14 60 7 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
1) pleroma_set_background_image;;
2) pleroma_set_title;;
3) pleroma_disable_registrations;;
4) pleroma_add_emoji;;
5) pleroma_set_expire_months;;
6) if [ $chatenabled ]; then
pleroma_enable_chat false
else
pleroma_enable_chat true
fi
;;
7) if grep -q '9050' $pleroma_secret; then
pleroma_disable_tor
else
pleroma_enable_tor
fi
;;
function pleroma_disable_tor {
if grep -q '9050' $pleroma_secret; then
sed -i '/9050/d' $pleroma_secret
sed -i 's|# config :pleroma, :http, proxy_url:|config :pleroma, :http, proxy_url:|g' $PLEROMA_DIR/config/config.exs
pleroma_recompile
fi
}
function pleroma_enable_tor {
if ! grep -q '{:socks5, :localhost, 9050}' $pleroma_secret; then
pleroma_tor_update=1
fi
if ! grep -q '# config :pleroma, :http, proxy_url:' $PLEROMA_DIR/config/config.exs; then
pleroma_tor_update=1
fi
if [ ! $pleroma_tor_update ]; then
return
fi
if ! grep -q '{:socks5, :localhost, 9050}' $pleroma_secret; then
sed -i '/9050/d' $pleroma_secret
sed -i '/url:/a config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}' $pleroma_secret
fi
if ! grep -q '# config :pleroma, :http, proxy_url:' $PLEROMA_DIR/config/config.exs; then
sed -i 's|config :pleroma, :http, proxy_url:|# config :pleroma, :http, proxy_url:|g' $PLEROMA_DIR/config/config.exs
fi
pleroma_recompile
}
if ! grep -q "/media/" /etc/cron.daily/pleroma-expire; then
rm $pleroma_expire_posts_script
fi
expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
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
return
fi
pleroma_registrations=open
if grep -q 'registrations_open: false' $PLEROMA_DIR/config/config.exs; then
pleroma_registrations=
fi
pleroma_chat_enabled=1
if grep -q ':chat, enabled: false' $PLEROMA_DIR/config/config.exs; then
pleroma_chat_enabled=
fi
# make a copy of the configuration
cp $PLEROMA_DIR/priv/static/static/config.json $PLEROMA_DIR/priv/static/static/config_prev.json
if [ -f $PLEROMA_DIR/config/emoji.txt ]; then
cp $PLEROMA_DIR/config/emoji.txt $PLEROMA_DIR/config/emoji_prev.txt
fi
$INSTALL_PACKAGES --only-upgrade esl-erlang
$INSTALL_PACKAGES --only-upgrade elixir erlang-xmerl erlang-dev erlang-parsetools
function_check set_repo_commit
set_repo_commit $PLEROMA_DIR "pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
chown -R pleroma:pleroma $PLEROMA_DIR
# restore the configuration
cp $PLEROMA_DIR/priv/static/static/config_prev.json $PLEROMA_DIR/priv/static/static/config.json
chown pleroma:pleroma $PLEROMA_DIR/priv/static/static/config.json
if [ -f $PLEROMA_DIR/config/emoji_prev.txt ]; then
cp $PLEROMA_DIR/config/emoji_prev.txt $PLEROMA_DIR/config/emoji.txt
chown pleroma:pleroma $PLEROMA_DIR/config/emoji.txt
rm cp $PLEROMA_DIR/config/emoji_prev.txt
if [ ! $pleroma_registrations ]; then
sed -i 's|registrations_open: true|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
sed -i 's|registrations_open: True|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
fi
if [ ! $pleroma_chat_enabled ]; then
sed -i 's|config :pleroma, :chat.*|config :pleroma, :chat, enabled: false|g' $PLEROMA_DIR/config/config.exs
else
sed -i 's|config :pleroma, :chat.*|config :pleroma, :chat, enabled: true|g' $PLEROMA_DIR/config/config.exs
fi
# migrate database
sudo -u pleroma mix deps.clean --build mime
expire_pleroma_posts "$PLEROMA_DOMAIN_NAME" "$PLEROMA_EXPIRE_MONTHS"
systemctl restart pleroma
function backup_local_pleroma {
PLEROMA_DOMAIN_NAME='pleroma'
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
fi
dest_directory=pleroma
backup_directory_to_usb $source_directory $dest_directory
USE_POSTGRESQL=1
function_check backup_database_to_usb
backup_database_to_usb pleroma
function_check restart_site
restart_site
systemctl restart pleroma
return
fi
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
echo $"Restoring pleroma"
temp_restore_dir=/root/temppleroma
PLEROMA_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_pleroma/hostname)
function_check pleroma_create_database
pleroma_create_database
USE_POSTGRESQL=1
restore_database pleroma
if [ -d $temp_restore_dir ]; then
rm -rf $temp_restore_dir
fi
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir pleroma
if [ -d $temp_restore_dir ]; then
echo $"Restore of pleroma complete"
fi
}
function backup_remote_pleroma {
PLEROMA_DOMAIN_NAME='pleroma'
PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
fi