Afterlogic WebMail on CyberPanel – with password change

For some time now, we strive to make our webmail products better integrated with various hosting control panels. We provide automated installers for cPanel, DirectAdmin and Plesk – and popular features such as password change and user signup are available there. On other control panels, it should be possible to install webmail just like you install any other PHP applications – but even in such cases, features like signup or password change are worth implementing.

This week we’ve been exploring CyberPanel, free opensource control panel software. Installing WebMail Pro there was a breeze, simply unpacking the product package into a website directory, supplying credenials of a database we’ve just created, et voilĂ . We were going to research how it all works internally and create a password change module – just like we recently did for FastPanel – but it turned out there’s no need for that. Passwords are stored in database as hashes, and we already have a module which can be used for that: Password change in mail server database.

We’ve downloaded a module and unzipped it into modules directory, ChangePasswordInMailServerDatabasePlugin subdirectory, then edited Module.php file replacing these two lines:

$sPasshash = exec("doveadm pw -s 'ssha512' -p '" . $sPassword . "'");
$sql = "UPDATE mailbox SET password='" . $sPasshash . "' WHERE username='" . $oAccount->IncomingLogin . "'";

with the following code:

$sEmail = $oAccount->IncomingLogin;
[$sUsername, $sDomain] = explode("@", $sEmail);
$sPasshash = '{CRYPT}'.password_hash($sPassword, PASSWORD_BCRYPT, ['cost' => 12,]);
$sql = "UPDATE e_users SET password = '" . $sPasshash . "' WHERE emailOwner_id = '" . $sDomain . "' AND email = '" . $sEmail . "'";

To configure the module, the first thing to do is press “Update configuration” button in Database Settings screen of adminpanel. Once that’s done, ChangePasswordInMailServerDatabasePlugin.config.json file will appear under data/settings/modules directory.

In that file, we’ll need to specify credentials of the database used by CyberPanel, it’s called “cyberpanel”, username is “root”. As for the root password, you can find it in /etc/cyberpanel/mysqlPassword file; with newer versions of CyberPanel, you can also check /root/.my.cnf file.

One last thing to do is set Disabled to false in data/settings/modules/ChangePasswordWebclient.config.json configuration file. And there we go, now you have Afterlogic WebMail installed on CyberPanel, and your users can change their email account passwords.

One additional thing I’d mention is that CyberPanel run OpenLiteSpeed webserver, so data directory protection via .htaccess file won’t work there. The easiest solution is to move data directory out of public_html and create inc_settings_path.php file with the new location specified – check this documentation page for detailed info.