Merge #2566
2566: Make it clear that we don't delete users r=mergify[bot] a=nextgens ## What type of PR? bug-fix ## What does this PR do? Make it clear that we don't delete users. Users can and should be disabled when not in use anymore. ### Related issue(s) - closes #1820 ## Prerequisites Before we can consider review and merge, please make sure the following list is done and checked. If an entry in not applicable, you can check it or remove it from the list. - [x] In case of feature or enhancement: documentation updated accordingly - [ ] Unless it's docs or a minor change: add [changelog](https://mailu.io/master/contributors/workflow.html#changelog) entry file. Co-authored-by: Florent Daigniere <nextgens@freenetproject.org> Co-authored-by: Alexander Graf <ghostwheel42@users.noreply.github.com> Co-authored-by: Dimitri Huisman <diman@huisman.xyz> Co-authored-by: Dimitri Huisman <52963853+Diman0@users.noreply.github.com>main
commit
5fbfb3cb1c
@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get id of running admin container
|
||||||
|
admin="$(docker compose ps admin --format=json | jq -r '.[].ID')"
|
||||||
|
if [[ -z "${admin}" ]]; then
|
||||||
|
echo "Sorry, can't find running mailu admin container."
|
||||||
|
echo "You need to start this in the path containing your docker-compose.yml."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get storage path
|
||||||
|
storage="$(
|
||||||
|
docker inspect "${admin}" \
|
||||||
|
| jq -r '.[].Mounts[] | select(.Destination == "/data") | .Source'
|
||||||
|
)/.."
|
||||||
|
storage="$(realpath "${storage}")"
|
||||||
|
if [[ ! -d "${storage}" ]]; then
|
||||||
|
echo "Sorry, can't find mailu storage path."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# fetch list of users from admin
|
||||||
|
declare -A users=()
|
||||||
|
while read line; do
|
||||||
|
users[${line#* }]="${line/ *}"
|
||||||
|
done < <(
|
||||||
|
docker compose exec -T admin \
|
||||||
|
flask mailu config-export -j user.email user.enabled \
|
||||||
|
2>/dev/null | jq -r '.user[] | "\(.enabled) \(.email)"'
|
||||||
|
)
|
||||||
|
if [[ ${#users[@]} -eq 0 ]]; then
|
||||||
|
echo "mailu config-export returned no users. Aborted."
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# diff list of users <> storage
|
||||||
|
unknown=false
|
||||||
|
disabled=false
|
||||||
|
for maildir in "${storage}"/mail/*; do
|
||||||
|
[[ -d "${maildir}" ]] || continue
|
||||||
|
email="${maildir/*\/}"
|
||||||
|
enabled="${users[${email}]:-}"
|
||||||
|
if [[ -z "${enabled}" ]]; then
|
||||||
|
unknown=true
|
||||||
|
users[${email}]="unknown"
|
||||||
|
elif ${enabled}; then
|
||||||
|
unset users[${email}]
|
||||||
|
else
|
||||||
|
disabled=true
|
||||||
|
users[${email}]="disabled"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#users[@]} -eq 0 ]]; then
|
||||||
|
echo "Nothing to clean up."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# is roundcube webmail in use?
|
||||||
|
webmail=false
|
||||||
|
docker compose exec webmail test -e /data/roundcube.db 2>/dev/null && webmail=true
|
||||||
|
|
||||||
|
# output actions
|
||||||
|
if ${unknown}; then
|
||||||
|
echo "# To delete maildirs unknown to mailu, run:"
|
||||||
|
for email in "${!users[@]}"; do
|
||||||
|
[[ "${users[${email}]}" == "unknown" ]] || continue
|
||||||
|
echo -n "rm -rf '${storage}/mail/${email}'"
|
||||||
|
${webmail} && \
|
||||||
|
echo -n " && docker compose exec -T webmail su mailu -c \"/var/www/roundcube/bin/deluser.sh --host=front '${email}'\""
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
if ${disabled}; then
|
||||||
|
echo "# To purge disabled users, run:"
|
||||||
|
for email in "${!users[@]}"; do
|
||||||
|
[[ "${users[${email}]}" == "disabled" ]] || continue
|
||||||
|
echo -n "docker compose exec -T admin flask mailu user-delete -r '${email}' && rm -rf '${storage}/mail/${email}'"
|
||||||
|
${webmail} && \
|
||||||
|
echo -n " && docker compose exec -T webmail su mailu -c \"/var/www/roundcube/bin/deluser.sh --host=front '${email}'\""
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
fi
|
@ -0,0 +1,2 @@
|
|||||||
|
Remove the ability to delete users via the webui; Disable them instead.
|
||||||
|
For more information on deleting users see the entry "How to delete users" in the FAQ.
|
Loading…
Reference in New Issue