--- aes.install 2011-01-26 13:34:59.000000000 +0100 +++ aes.install 2012-06-27 14:47:35.651281326 +0200 @@ -1,128 +1,168 @@ t('AES encryption implementation'), - 'description' => t('The AES encryption module requires at least one of two things to function: Either the PHP Mcrypt extension has to be installed on the web server. Or the PHP Secure Communications Library (phpseclib) needs to be installed in the AES directory. Check the README.txt for more information.'), - 'severity' => $requirement_severity, - ), - ); - + // Ensure translations don't break at install time. + $t = get_t(); + + $aes_implementations = aes_get_available_aes_implementations(); + $aes_implemented = $t('Not implemented'); + $implements = ''; + $description = ''; + + if ($aes_implementations['mcrypt'] === TRUE && $aes_implementations['phpseclib'] === TRUE) { + $requirement_severity = REQUIREMENT_ERROR; + $description = $t('The AES encryption module requires at least one of two things to function: Either the PHP Mcrypt extension has to be installed on the web server. Or the PHP Secure Communications Library (phpseclib) needs to be installed in the AES directory. Check the README.txt for more information.'); + } + else { + $requirement_severity = REQUIREMENT_OK; + foreach ($aes_implementations as $k => $v) { + if ($v == TRUE) { + $implements .= ucfirst($k) . ' '; + } + } + $aes_implemented = $t('@implements', array('@implements' => rtrim($implements))); + } + + $requirements = array( + array( + 'title' => $t('AES encryption implementation'), + 'description' => $description, + 'severity' => $requirement_severity, + 'value' => $aes_implemented + ), + ); + return $requirements; } +/** + * Helper function to check AES requirements. + * + * @see aes_requirements() + */ function aes_get_available_aes_implementations() { - - $phpsec_include_path = dirname(__FILE__)."/phpseclib"; - set_include_path(get_include_path() . PATH_SEPARATOR . $phpsec_include_path); - $phpsec_available = true; - if (file_exists($phpsec_include_path.'/Crypt/AES.php') === false) { - $phpsec_available = false; - } - else if (is_readable($phpsec_include_path.'/Crypt/AES.php') === false) { - $phpsec_available = false; - } - - - if (extension_loaded("mcrypt")) { - $mcrypt_available = true; - } - else { - $mcrypt_available = false; - } - - return array('mcrypt' => $mcrypt_available, 'phpseclib' => $phpsec_available); + $phpsec_include_path = dirname(__FILE__) . '/phpseclib'; + set_include_path(get_include_path() . PATH_SEPARATOR . $phpsec_include_path); + $phpsec_available = TRUE; + + if (file_exists($phpsec_include_path.'/Crypt/AES.php') === FALSE) { + $phpsec_available = FALSE; + } + elseif (is_readable($phpsec_include_path.'/Crypt/AES.php') === FALSE) { + $phpsec_available = FALSE; + } + + if (extension_loaded('mcrypt')) { + $mcrypt_available = TRUE; + } + else { + $mcrypt_available = FALSE; + } + + return array('mcrypt' => $mcrypt_available, 'phpseclib' => $phpsec_available); } +/** + * Implements hook_install(). + */ function aes_install() { - - variable_set("aes_key_storage_method", "Database"); - variable_set("aes_cipher", "rijndael-128"); - variable_set("aes_convert", "true"); - variable_set("aes_viewing_method", "collapsible"); - + // Ensure translations don't break at install time. + $t = get_t(); + + variable_set('aes_key_storage_method', 'Database'); + variable_set('aes_cipher', 'rijndael-128'); + variable_set('aes_convert', TRUE); + variable_set('aes_viewing_method', 'collapsible'); + $aes_implementations = aes_get_available_aes_implementations(); - + if ($aes_implementations['mcrypt']) { - variable_set("aes_implementation", "mcrypt"); - $install_msg = t("AES installed using the Mcrypt implementation."); + variable_set('aes_implementation', 'mcrypt'); + $install_msg = $t('AES installed using the Mcrypt implementation.'); } else if ($aes_implementations['phpseclib']) { - variable_set("aes_implementation", "phpseclib"); - $install_msg = t("AES installed using the phpseclib implementation."); + variable_set('aes_implementation', 'phpseclib'); + $install_msg = $t('AES installed using the phpseclib implementation.'); } else { - //this case shouldn't actually be possible since hook_requirements should stop the installation if there's no implementation - variable_set("aes_implementation", "missing"); - $install_msg = t("AES installed without any implementation!"); + // This case shouldn't actually be possible since hook_requirements + // should stop the installation if there's no implementation. + variable_set('aes_implementation', 'missing'); + $install_msg = $t('AES installed without any implementation!'); } - + drupal_set_message($install_msg); } +/** + * Implements hook_update_N(). + */ function aes_update_6100(&$sandbox = NULL) { $aes_implementations = aes_get_available_aes_implementations(); - + if ($aes_implementations['mcrypt']) { - variable_set("aes_implementation", "mcrypt"); + variable_set('aes_implementation', 'mcrypt'); } - else if ($aes_implementations['phpseclib']) { - variable_set("aes_implementation", "phpseclib"); + elseif ($aes_implementations['phpseclib']) { + variable_set('aes_implementation', 'phpseclib'); } else { - variable_set("aes_implementation", "missing"); + variable_set('aes_implementation', 'missing'); } - + return array(); } +/** + * Implements hook_update_N(). + */ function aes_update_7100(&$sandbox = NULL) { - if(file_exists("login_edit_dump.txt")) { - unlink("login_edit_dump.txt"); - } + if (file_exists('login_edit_dump.txt')) { + unlink('login_edit_dump.txt'); + } } +/** + * Implements hook_schema(). + */ function aes_schema() { - - $schema['aes_passwords'] = array( - 'fields' => array( - 'uid' => array('type' => 'int', 'unsigned' => true, 'not null' => true, 'default' => 0), - 'pass' => array('type' => 'varchar', 'length' => 128, 'not null' => true, 'default' => ''), - ), - 'primary key' => array('uid'), - ); - - return $schema; + $schema['aes_passwords'] = array( + 'fields' => array( + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'pass' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('uid') + ); + + return $schema; } +/** + * Implements hook_uninstall(). + */ function aes_uninstall() { - //delete keyfile - if (variable_get("aes_key_storage_method", "") == "File") { - unlink(variable_get("aes_key_path", "")); - } - - //delete variables - variable_del("aes_key"); - variable_del("aes_convert"); - variable_del("aes_key_storage_method"); - variable_del("aes_key_path"); - variable_del("aes_key"); - variable_del("aes_encryption_iv"); - variable_del("aes_cipher"); - variable_del("aes_viewing_method"); - variable_del("aes_implementation"); - - drupal_set_message(t("AES uninstalled.")); -} + // Delete keyfile. + if (variable_get('aes_key_storage_method', '') == 'File') { + unlink(variable_get('aes_key_path', '')); + } + + // Delete variables. + variable_del('aes_key'); + variable_del('aes_convert'); + variable_del('aes_key_storage_method'); + variable_del('aes_key_path'); + variable_del('aes_key'); + variable_del('aes_encryption_iv'); + variable_del('aes_cipher'); + variable_del('aes_viewing_method'); + variable_del('aes_implementation'); + drupal_set_message(t('AES uninstalled.')); +}