2019-05-10 15:41:24 +02:00
|
|
|
#!/usr/bin/env bash
|
2017-10-09 20:30:45 +02:00
|
|
|
[[ -f mailcow.conf ]] && source mailcow.conf
|
|
|
|
[[ -f ../mailcow.conf ]] && source ../mailcow.conf
|
|
|
|
|
|
|
|
if [[ -z ${DBUSER} ]] || [[ -z ${DBPASS} ]] || [[ -z ${DBNAME} ]]; then
|
|
|
|
echo "Cannot find mailcow.conf, make sure this script is run from within the mailcow folder."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "Checking MySQL service... "
|
|
|
|
if [[ -z $(docker ps -qf name=mysql-mailcow) ]]; then
|
|
|
|
echo "failed"
|
|
|
|
echo "MySQL (mysql-mailcow) is not up and running, exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "OK"
|
|
|
|
read -r -p "Are you sure you want to reset the mailcow administrator account? [y/N] " response
|
|
|
|
response=${response,,} # tolower
|
|
|
|
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
|
|
|
echo -e "\nWorking, please wait..."
|
2023-03-28 11:17:59 +02:00
|
|
|
random=$(</dev/urandom tr -dc _A-Z-a-z-0-9 2> /dev/null | head -c${1:-16})
|
2021-07-04 15:12:50 +02:00
|
|
|
password=$(docker exec -it $(docker ps -qf name=dovecot-mailcow) doveadm pw -s SSHA256 -p ${random} | tr -d '\r')
|
2018-10-11 12:01:06 +02:00
|
|
|
docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM admin WHERE username='admin';"
|
|
|
|
docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM domain_admins WHERE username='admin';"
|
2021-07-04 15:12:50 +02:00
|
|
|
docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "INSERT INTO admin (username, password, superadmin, active) VALUES ('admin', '${password}', 1, 1);"
|
2017-10-09 20:30:45 +02:00
|
|
|
docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM tfa WHERE username='admin';"
|
|
|
|
echo "
|
|
|
|
Reset credentials:
|
|
|
|
---
|
|
|
|
Username: admin
|
2021-07-04 15:12:50 +02:00
|
|
|
Password: ${random}
|
2017-10-09 20:30:45 +02:00
|
|
|
TFA: none
|
|
|
|
"
|
|
|
|
else
|
|
|
|
echo "Operation canceled."
|
|
|
|
fi
|