Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | [[ -f mailcow.conf ]] && source mailcow.conf |
| 3 | [[ -f ../mailcow.conf ]] && source ../mailcow.conf |
| 4 | |
| 5 | if [[ -z ${DBUSER} ]] || [[ -z ${DBPASS} ]] || [[ -z ${DBNAME} ]]; then |
| 6 | echo "Cannot find mailcow.conf, make sure this script is run from within the mailcow folder." |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | echo -n "Checking MySQL service... " |
| 11 | if [[ -z $(docker ps -qf name=mysql-mailcow) ]]; then |
| 12 | echo "failed" |
| 13 | echo "MySQL (mysql-mailcow) is not up and running, exiting..." |
| 14 | exit 1 |
| 15 | fi |
| 16 | |
| 17 | echo "OK" |
| 18 | read -r -p "Are you sure you want to reset the mailcow administrator account? [y/N] " response |
| 19 | response=${response,,} # tolower |
| 20 | if [[ "$response" =~ ^(yes|y)$ ]]; then |
| 21 | echo -e "\nWorking, please wait..." |
| 22 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM admin WHERE username='admin';" |
| 23 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM domain_admins WHERE username='admin';" |
| 24 | 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', '{SSHA256}K8eVJ6YsZbQCfuJvSUbaQRLr0HPLz5rC9IAp0PAFl0tmNDBkMDc0NDAyOTAxN2Rk', 1, 1);" |
| 25 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM tfa WHERE username='admin';" |
| 26 | echo " |
| 27 | Reset credentials: |
| 28 | --- |
| 29 | Username: admin |
| 30 | Password: moohoo |
| 31 | TFA: none |
| 32 | " |
| 33 | else |
| 34 | echo "Operation canceled." |
| 35 | fi |