Last active
April 1, 2024 06:17
-
-
Save rallisf1/b8c78ce8bc465c39cbccfe5c0a27d429 to your computer and use it in GitHub Desktop.
get all emails and their password hashes from a cPanel server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the path to the cPanel user file | |
USERS_FILE="/etc/trueuserdomains" | |
# Loop through each cPanel user | |
while read DOMAIN USER; do | |
# Remove the colon from the end of the DOMAIN variable | |
DOMAIN=$(echo "$DOMAIN" | sed 's/:$//') | |
# Get the user's email accounts | |
EMAIL_ACCOUNTS=$(whmapi1 list_pops_for user=$USER | grep ' - ' | cut -d "-" -f 2-99 | tr -d ' ') | |
for EMAIL_ACCOUNT in $EMAIL_ACCOUNTS; do | |
# Extract the user part from the email address | |
POP=$(echo $EMAIL_ACCOUNT | cut -d@ -f1) | |
# Get the password hash from the shadow file & remove any leading exclamation marks | |
PASSWORD=$(grep "^$POP:" /home/$USER/etc/$DOMAIN/shadow | cut -d: -f2 | sed 's/^!*\([^!].*\)/\1/') | |
echo "$EMAIL_ACCOUNT,{CRYPT}$PASSWORD" | |
done | |
done < "$USERS_FILE" |
When you format this in a csv file do you remove the {CRYPT} prefix before importing into mailcow?
When you format this in a csv file do you remove the {CRYPT} prefix before importing into mailcow?
No. It works as it is.
Frankly I have stopped using this as the messages get new ids upon encryption and email clients (e.g. Ms outlook) download them as duplicates.
Have you found a new way of importing cpanel mails into mailcow?
I reset the passwords on cPanel and use the embedded IMAP sync tool. Then ask clients to log in to mailcow and change their password.
thats a problem when you have hundreds of mail accounts :-(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work for addon domains. Emails of addon domain will have no OR wrong passwords (if the main domain has the same user names).