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..." |
Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 22 | random=$(</dev/urandom tr -dc _A-Z-a-z-0-9 2> /dev/null | head -c${1:-16}) |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 23 | password=$(docker exec -it $(docker ps -qf name=dovecot-mailcow) doveadm pw -s SSHA256 -p ${random} | tr -d '\r') |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 24 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM admin WHERE username='admin';" |
| 25 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM domain_admins WHERE username='admin';" |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 26 | 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);" |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 27 | docker exec -it $(docker ps -qf name=mysql-mailcow) mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM tfa WHERE username='admin';" |
| 28 | echo " |
| 29 | Reset credentials: |
| 30 | --- |
| 31 | Username: admin |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 32 | Password: ${random} |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 33 | TFA: none |
| 34 | " |
| 35 | else |
| 36 | echo "Operation canceled." |
| 37 | fi |