mirror of
https://codeberg.org/Windfluechter/cleanup-friendica.git
synced 2025-03-03 05:21:01 +01:00
Update cleanup_friendica.sh
Some changes: - moved mail texts to subroutines - fixed issue that older lastlogin dates were ignored. Before only 7-9 months old lastlogins were considered for deletion, now lastlogins with >7 months and "year(s) ago" are considered as well - removed BCC for admin, added comment how to enable BCC mail again
This commit is contained in:
parent
7aa79992f2
commit
04b2a140c6
1 changed files with 65 additions and 46 deletions
|
@ -18,6 +18,44 @@ set -f
|
||||||
|
|
||||||
cd ${friendicapath} || exit 0
|
cd ${friendicapath} || exit 0
|
||||||
|
|
||||||
|
# notify the user that s/he needs to re-login after 6 months to prevent account deletion
|
||||||
|
notifyUser () {
|
||||||
|
( cat <<EOF
|
||||||
|
Dear ${dispname},
|
||||||
|
|
||||||
|
you have registered on ${siteurl} ${registered} and last time you logged in was ${lastlogin}.
|
||||||
|
Your latest post - if any - was ${lastpost}.
|
||||||
|
|
||||||
|
If you want to continue to keep your account on Nerdica then please log in at least every 6 months to keep your account alive. Otherwise we assume that you don't want to use it anymore and will cancel your account 7 months after your last login.
|
||||||
|
|
||||||
|
You can access your profile at ${profileurl} or you can cancel your account on your own when logged in at ${siteurl}removeme - however we would like to see you become an active user again and contribute to the Fediverse, but of course it's up to you.
|
||||||
|
|
||||||
|
Sincerely,
|
||||||
|
your ${site} admins
|
||||||
|
|
||||||
|
EOF
|
||||||
|
) | sed 's/_/\ /g' | /usr/bin/mail -s "The Fediverse misses you, ${username}!" -r "${sitefrom}" -- "${usermail}"
|
||||||
|
# add '-b "$siteadmin"' before the "--" above to receive BCC mails
|
||||||
|
}
|
||||||
|
|
||||||
|
# notify user that the account has been deleted because of inactivity
|
||||||
|
notifyUserDeletion () {
|
||||||
|
( cat <<EOF
|
||||||
|
Dear ${dispname},
|
||||||
|
|
||||||
|
you have registered on ${siteurl} ${registered} and last time you logged in was ${lastlogin}.
|
||||||
|
Your latest post - if any - was ${lastpost}.
|
||||||
|
|
||||||
|
Since you haven't reacted to the previous mails and didn't login again, your account including all your data has now been deleted.
|
||||||
|
|
||||||
|
Sincerely,
|
||||||
|
your ${site} admins
|
||||||
|
|
||||||
|
EOF
|
||||||
|
) | sed 's/_/\ /g' | /usr/bin/mail -s "Your account ${username} on ${site} has been be deleted!" -r "${sitefrom}" -- "${usermail}"
|
||||||
|
# add '-b "$siteadmin"' before the "--" above to receive BCC mails
|
||||||
|
}
|
||||||
|
|
||||||
# delete users that never logged in and never posted content
|
# delete users that never logged in and never posted content
|
||||||
# filtering for "weeks" will result in accounts with 2 weeks old accounts,
|
# filtering for "weeks" will result in accounts with 2 weeks old accounts,
|
||||||
# filter for just "week" will do the same after 1 week.
|
# filter for just "week" will do the same after 1 week.
|
||||||
|
@ -32,7 +70,7 @@ for username in $( ${friendicapath}/bin/console user list active -c 10000 | grep
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ ${pcheck} -eq 0 ]; then
|
if [ ${pcheck} -eq 0 ]; then
|
||||||
#echo "Delete user ${username}"
|
echo "Delete unconfirmed user ${username}"
|
||||||
${friendicapath}/bin/console user delete "${username}" -q
|
${friendicapath}/bin/console user delete "${username}" -q
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -47,58 +85,39 @@ for u in $( ${friendicapath}/bin/console user list active -c 10000 | grep -v '.*
|
||||||
registered=$(echo "${u}" | awk -F ";" '{print $5}')
|
registered=$(echo "${u}" | awk -F ";" '{print $5}')
|
||||||
lastlogin=$(echo "${u}" | awk -F ";" '{print $6}')
|
lastlogin=$(echo "${u}" | awk -F ";" '{print $6}')
|
||||||
lastpost=$(echo "${u}" | awk -F ";" '{print $7}')
|
lastpost=$(echo "${u}" | awk -F ";" '{print $7}')
|
||||||
#echo "Userinfo: ${username},${dispname},${profileurl},${usermail},${registered},${lastlogin},${lastpost}"
|
res=$(echo "${lastlogin}" | grep -e'[6-9]\ months.*' -e '1[012]\ months.*' -e 'year')
|
||||||
res=$(echo "${lastlogin}" | grep '[6-9]_months.*')
|
|
||||||
if [ -n "${res}" ]; then
|
if [ -n "${res}" ]; then
|
||||||
num_months=$(echo "${res}" | awk -F "_" '{ print $1}')
|
num_months=$(echo "${res}" | awk -F "_" '{ print $1}')
|
||||||
#echo "months: ${num_months}"
|
monthyear=$(echo "${res}" | awk -F "_" '{ print $2}' | sed -e 's/s//g') # remove the "s" in months and years
|
||||||
if [ ${num_months} -ge 7 ]; then
|
if [ "${monthyear}" = "month" ] ; then
|
||||||
|
if [ ${num_months} -ge 7 ] ; then
|
||||||
|
DELUSER=true
|
||||||
|
elif [ ${num_months} -eq 6 ]; then
|
||||||
|
# mail the user and ask to re-login
|
||||||
|
DELUSER=false
|
||||||
|
notifyUser
|
||||||
|
fi
|
||||||
|
elif [ "${monthyear}" = "year" ]; then
|
||||||
|
DELUSER=true
|
||||||
|
fi
|
||||||
|
if [ "${DELUSER}" = "true" ]; then
|
||||||
# delete account when last login is older than 7 months and send mail about deletion
|
# delete account when last login is older than 7 months and send mail about deletion
|
||||||
# you should copy & paste the text from 6 months for the first runs of this script
|
# you should copy & paste the text from 6 months for the first runs of this script
|
||||||
# and later change the text to a notification that the account has been deleted.
|
# and later change the text to a notification that the account has been deleted.
|
||||||
( cat <<EOF
|
# if username is a protected user do nothing, else delete user
|
||||||
Dear ${dispname},
|
if [ -n "${protectedusers}" ]; then
|
||||||
|
pcheck=0
|
||||||
you have registered on ${siteurl} ${registered} and last time you logged in was ${lastlogin}.
|
for s in $(echo ${protectedusers}) ; do
|
||||||
Your latest post - if any - was ${lastpost}.
|
if [ "${s}" = "${username}" ]; then
|
||||||
|
pcheck=1
|
||||||
Since you haven't reacted to the previous mails and didn't login again, your account including all your data has now been deleted.
|
fi
|
||||||
|
done
|
||||||
Sincerely,
|
if [ ${pcheck} -eq 0 ]; then
|
||||||
your ${site} admins
|
echo "Delete user ${username}"
|
||||||
|
${friendicapath}/bin/console user delete "${username}" -q
|
||||||
EOF
|
notifyUserDeletion
|
||||||
) | sed 's/_/\ /g' | /usr/bin/mail -s "Your account ${username} on ${site} has been deleted!" -r "${sitefrom}" -b "$siteadmin" -- "${usermail}"
|
|
||||||
# if username is a protected user do nothing, else delete user
|
|
||||||
if [ -n "${protectedusers}" ]; then
|
|
||||||
pcheck=0
|
|
||||||
for s in $(echo ${protectedusers}) ; do
|
|
||||||
if [ "${s}" = "${username}" ]; then
|
|
||||||
pcheck=1
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
if [ ${pcheck} -eq 0 ]; then
|
|
||||||
echo "Delete user ${username}"
|
|
||||||
${friendicapath}/bin/console user delete "${username}" -q
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ ${num_months} -eq 6 ]; then
|
|
||||||
# mail the user and ask to re-login
|
|
||||||
( cat <<EOF
|
|
||||||
Dear ${dispname},
|
|
||||||
|
|
||||||
you have registered on ${siteurl} ${registered} and last time you logged in was ${lastlogin}.
|
|
||||||
Your latest post - if any - was ${lastpost}.
|
|
||||||
|
|
||||||
If you want to continue to keep your account on Nerdica then please log in at least every 6 months to keep your account alive. Otherwise we assume that you don't want to use it anymore and will cancel your account 7 months after your last login.
|
|
||||||
|
|
||||||
You can access your profile at ${profileurl} or you can cancel your account on your own when logged in at ${siteurl}/removeme - however we would like to see you become an active user again and contribute to the Fediverse, but of course it's up to you.
|
|
||||||
|
|
||||||
Sincerely,
|
|
||||||
your ${site} admins
|
|
||||||
|
|
||||||
EOF
|
|
||||||
) | sed 's/_/\ /g' | /usr/bin/mail -s "The Fediverse misses you, ${username}!" -r "${sitefrom}" -b "$siteadmin" -- "${usermail}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue