Skip to content

Commit 5b1de5d

Browse files
authored
Update v-import-cpanel (hestiacp#4121)
Fix email account password restoration Add prefix SHA512 for the hash type before the password so that the doveadm can read it and not the expected md5 from the settings that cases failed login since the hash not the same
1 parent 79b8442 commit 5b1de5d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

bin/v-import-cpanel

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,26 @@ for folder in *; do
264264
mv $mail_account /home/$new_user/mail/$folder/
265265
chown -R $new_user:mail /home/$new_user/mail/$folder/
266266
find /home/$new_user/mail/$folder -type f -name 'dovecot*' -delete
267-
pass=$(grep "^$mail_account:" ../../etc/${folder}/shadow | awk -F ":" '{print $2}')
268-
USER_DATA=$HESTIA/data/users/$new_user/
269-
update_object_value "mail/$folder" 'ACCOUNT' "$mail_account" '$MD5' "$pass"
267+
268+
# Extract and update password from the shadow file
269+
password_file="../../etc/${folder}/shadow"
270+
if [ -f "$password_file" ]; then
271+
pass_line=$(grep "^$mail_account:" $password_file)
272+
if [ $? -eq 0 ]; then
273+
# Extract the hashed password from the shadow file
274+
pass=$(echo "$pass_line" | awk -F ":" '{print $2}')
275+
newline="${mail_account}:{SHA512-CRYPT}$pass:${new_user}:mail::/home/${new_user}:0"
276+
newline2="ACCOUNT='${mail_account}' ALIAS='' AUTOREPLY='no' FWD='' FWD_ONLY='' MD5='{SHA512-CRYPT}$pass' QUOTA='unlimited' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'"
277+
escaped=$(printf '%s\n' "$newline" | sed -e 's/[\/&]/\\&/g')
278+
escaped2=$(printf '%s\n' "$newline2" | sed -e 's/[\/&]/\\&/g')
279+
sed -i "s/^${mail_account}:.*/$escaped/g" /home/${new_user}/conf/mail/${folder}/passwd
280+
sed -i "s/^ACCOUNT='${mail_account}.*/$escaped2/g" /usr/local/hestia/data/users/${new_user}/mail/${folder}.conf
281+
else
282+
echo "Warning: Password for $mail_account@$folder not found in shadow file."
283+
fi
284+
else
285+
echo "Warning: Shadow file for $folder not found."
286+
fi
270287
done
271288
cd ..
272289
$BIN/v-rebuild-mail-domain $new_user $folder

0 commit comments

Comments
 (0)