/var/www/*/ssl symlinks not removed after migration

Enhancement #6301 (closed) in 3.2.9 needs an enhancement of its own. I'm running 3.2.12, migrated from another system with 3.1 and updated. The migration brought over all of the old /ssl files but the /etc/letsencrypt folder doesn't existing on this system. In commit 6ef85318, removal of symlinks is done with if(@is_link($key_file)) unlink($key_file); But if the target folder doesn't exist, is_link returns false, so the file isn't unlinked. As a result, my ssl folders are still full of those old symlinks.

Try something in server/lib/classes/letsencrypt.inc.php like

if (file_exists($key_file) && readlink($key_file) !== false) {
    unlink($key_file);
}

For anyone who still has the files and wants to delete them:

Get a backup of the ssl folders:

sudo tar -czvf /root/www_ssl_backup_$(date +%F).tar.gz /var/www/*/ssl/

Verify the targets:

cd /var/www && find . -path "./*/ssl/*" -type l | while read -r link; do
   target=$(readlink "$link")
   [[ "$target" == /etc/letsencrypt/* ]] && echo "$link -> $target"
done

Delete the symlinks:

cd /var/www && find . -path "./*/ssl/*" -type l | while read -r link; do
   target=$(readlink "$link")
   [[ "$target" == /etc/letsencrypt/* ]] && rm -v "$link"
done