Commit 10de8c75 authored by Arnau Vàzquez's avatar Arnau Vàzquez

Merge branch 'manual-delete-cleanup-details' into 'develop'

Manual delete cleanup details

Closes e/management#951

See merge request !60
parents bde18e7f c5710e4a
......@@ -6,6 +6,11 @@ source /mnt/repo-base/scripts/base.sh
echo "Enter the email address to be deleted:"
read ACCOUNT
# strip @ANDEVERYTHINGAFTER suffix to get mbox only
MBOX=${ACCOUNT%%@*}
# strip EVERYTHINGBEFOREAND@ prefix to get domain only
MAIL_DOMAIN=${ACCOUNT##*@}
if ! docker-compose exec -T -u www-data nextcloud php occ user:info "$ACCOUNT" | grep "$ACCOUNT" --quiet; then
echo "Error: The account $ACCOUNT does not exist"
exit
......@@ -20,5 +25,61 @@ if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Deleting email account"
docker-compose exec -T postfixadmin /postfixadmin/scripts/postfixadmin-cli mailbox delete "$ACCOUNT"
# remove user's maildir as postfixadmin-cli mailbox delete "$ACCOUNT" is not doing it
MAILDIR="/mnt/repo-base/volumes/mail/vhosts/$MAIL_DOMAIN/$MBOX"
if [[ -n "$MBOX" && -n "$MAIL_DOMAIN" ]]; then
# double check on $MBOX and $MAIL_DOMAIN not empty
# as we don't want to remove entire /mnt/repo-base/volumes/mail/vhosts/ !!
if [ -d $MAILDIR ]; then
echo "Deleting email folder in $MAILDIR for this account"
rm -rf $MAILDIR
else
echo "$MAILDIR does not exit"
fi
fi
# 2 files to update auth.file.done and auth.file
AUTH_FILE_DONE=/mnt/repo-base/volumes/accounts/auth.file.done
AUTH_FILE=/mnt/repo-base/volumes/accounts/auth.file
# delete line with $ACCOUNT : @ACCOUNT is a $MBOX@DOMAIN
# strip @ANDEVERYTHINGAFTER suffix to get mbox only, to be more generic
MBOX=${ACCOUNT%%@*}
echo "Updating system persistent info"
NB_LINES=$(grep -R "\:$MBOX$" $AUTH_FILE_DONE |wc -l)
# if ONLY one line found in auth.file.done, delete it
if [[ $NB_LINES = "1" ]]; then
# Grab mail used to register from the line (to be used for $AUTH_FILE update in #2)
MAIL_USED=$(grep -R "\:$MBOX$" $AUTH_FILE_DONE| cut -f1 -d":")
echo "#1 Removing $MBOX from file $AUTH_FILE_DONE"
# sed pattern : \:$MBOX$
# use $ after $MBOX to get line ending with $MBOX,
# ':' before $MBOX to prevent accidental deletion
# ex : if $MBOX = doe only delete line ending with ":doe"
# do NOT delete all lines ending with ":doe", ":johndoe" or ":john-doe"
sed -i "/\:$MBOX$/d" $AUTH_FILE_DONE
echo "#2 Deleting all lines with $MAIL_USED found in $AUTH_FILE"
# sed pattern : ^$MAIL_USED\:
# use ^ before $MAIL_USED to get only line STARTING WITH $MAIL_USED,
# ':' after $MAIL_USED to encapsulate it
sed -i "/^$MAIL_USED\:/d" $AUTH_FILE
elif [[ $NB_LINES = "0" ]]
then
echo "$MBOX not found in $AUTH_FILE_DONE"
else
echo "More than one line to be deleted for $MBOX, check $AUTH_FILE_DONE please"
fi
# TODO: delete onlyoffice account???
fi
......@@ -57,9 +57,12 @@ $CONFIG = array (
'user_exists' => 'SELECT EXISTS(SELECT 1 FROM mailbox WHERE username = :username)',
'get_users' => 'select username as fqda from mailbox where username like :search or name like :search',
'set_password_hash_for_user' => 'UPDATE mailbox SET password = CONCAT(\'{SHA512-CRYPT}\',:new_password_hash) WHERE username = BINARY :username',
'delete_user' => 'SELECT EXISTS(SELECT 1 FROM mailbox WHERE username = :username)',
'get_display_name' => 'SELECT name FROM mailbox where username = BINARY :username',
'set_display_name' => 'UPDATE mailbox SET name = :new_display_name WHERE username = BINARY :username',
'count_users' => 'SELECT COUNT(*) FROM mailbox',
//'get_home' => '',
//'create_user' => '',
),
'hash_algorithm_for_new_passwords' => 'sha512',
),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment