Skip to content

Instantly share code, notes, and snippets.

@rallisf1
Last active April 1, 2024 06:17
Show Gist options
  • Save rallisf1/b8c78ce8bc465c39cbccfe5c0a27d429 to your computer and use it in GitHub Desktop.
Save rallisf1/b8c78ce8bc465c39cbccfe5c0a27d429 to your computer and use it in GitHub Desktop.
get all emails and their password hashes from a cPanel server
#!/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"
@rallisf1
Copy link
Author

rallisf1 commented May 3, 2023

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).

@brycelarge
Copy link

When you format this in a csv file do you remove the {CRYPT} prefix before importing into mailcow?

@rallisf1
Copy link
Author

rallisf1 commented Apr 1, 2024

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.

@brycelarge
Copy link

Have you found a new way of importing cpanel mails into mailcow?

@rallisf1
Copy link
Author

rallisf1 commented Apr 1, 2024

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.

@brycelarge
Copy link

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