<?php
/*
 * --------------------------------------------------------
 * ENLARGE PASSWORD FIELD
 * --------------------------------------------------------
 */
$queryAlter = "ALTER TABLE `domains` CHANGE `password` `password` VARCHAR(100) NOT NULL DEFAULT ''";
mysql_query($queryAlter);

if (extension_loaded('mcrypt')) {
    require_once 'encrypted/Clientexec.php';

    /*
     * --------------------------------------------------------
     * ADDED A SETTING TO ENCRYPT DOMAIN PASSWORDS
     * --------------------------------------------------------
     */
    $queryInsert = "INSERT INTO `setting` VALUES (NULL, 'Domain Passwords are Encrypted', 1, 'This setting allows to encrypt Domain Passwords. When the encryption is done, this setting is set to true.', 1, 0, 1, 0, 0, 0, 0, 0, 0, 1)";
    mysql_query($queryInsert);

    $query = "SELECT `id`, `password` FROM `domains`";
    $result = mysql_query($query) or die("ERROR in query: $query");
    while (list($id, $password) = mysql_fetch_row($result)) {
        $encryptedPassword = NE_Lib::encryptData($password, Clientexec::getDomainPwdEncryptionKey());

        $update = "UPDATE `domains` SET `password` = '".mysql_real_escape_string($encryptedPassword)."' WHERE `id` = $id";
        mysql_query($update) or die("ERROR in query: $update");
    }
}else{
    $queryInsert = "INSERT INTO `setting` VALUES (NULL, 'Domain Passwords are Encrypted', 0, 'This setting allows to encrypt Domain Passwords. When the encryption is done, this setting is set to true.', 1, 0, 1, 0, 0, 0, 0, 0, 0, 1)";
    mysql_query($queryInsert);
}
?>
