blob: 4afd14c924fb26daf79d8a7ede00407c76f64f23 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001#!/usr/bin/env bash
2[[ -f mailcow.conf ]] && source mailcow.conf
3[[ -f ../mailcow.conf ]] && source ../mailcow.conf
4
5if [[ -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
8fi
9
10echo -n "Checking MySQL service... "
11if [[ -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
15fi
16
17echo "OK"
18read -r -p "Are you sure you want to reset the mailcow administrator account? [y/N] " response
19response=${response,,} # tolower
20if [[ "$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 "
27Reset credentials:
28---
29Username: admin
30Password: moohoo
31TFA: none
32"
33else
34 echo "Operation canceled."
35fi