WebMail Lite 8 Documentation

Exporting list of user accounts with passwords

The following sample demonstrates exporting user data from WebMail Lite 8 database.

The idea of this sample is to create .SQL file, containing structure and content of the database table. Each record holds user's ID, email address and password.

function dump_add($str, $add=TRUE) {
    file_put_contents("./exportusers.sql", $str."\r\n", $add?FILE_APPEND:0);
}
    
include __DIR__.'./system/autoload.php';
\Aurora\System\Api::Init(true);
$oHelper = new Aurora\System\Db\Pdo\MySql\Helper();
 
$oCoreModule = \Aurora\System\Api::GetModule("Core");
$ul = $oCoreModule->getUserList();
$ulItems = $ul["Items"];
 
dump_add("DROP TABLE IF EXISTS `exportusers`;", false);
dump_add("CREATE TABLE `exportusers` (`user` int(11) NOT NULL, `mail` varchar(255) NOT NULL, `pass` varchar(255) NOT NULL);");
 
foreach ($ulItems as $key=>$item) {
    $sEmail = $item["PublicId"];
    $oUser = $oCoreModule->GetUserByPublicId($sEmail);
    $iUserId = $oUser->EntityId;
    $oAccount = $oCoreModule->GetAccountUsedToAuthorize($sEmail);
    $sPass = $oAccount->getPassword();
    dump_add("INSERT INTO `exported` (`user`, `mail`, `pass`) VALUES (".$oHelper->EscapeString($iUserId).", ".$oHelper->EscapeString($sEmail).", ".$oHelper->EscapeString($sPass).");");    
}

As you can see, we've added a helper function dump_add() which places a line into SQL file. By default, both the script and the dump file are located in root directory of WebMail Lite 8 installation.

The main code part is rather straightforward: we get a list of all the user ID's, for each user we retrieve their email account, get that account's password and add a line to .SQL file.

NB: Please bear in mind that passwords will be stored in .SQL file in clear text.