aes.install in AES encryption 7
Same filename and directory in other branches
Install/uninstall related functions.
File
aes.installView source
<?php
/**
* @file
*
* Install/uninstall related functions.
*/
/**
* Implements hook_requirements().
*/
function aes_requirements($phase) {
// Make sure translations won't break on install.
$t = get_t();
$aes_implementations = aes_get_available_aes_implementations();
if ($aes_implementations['mcrypt'] === FALSE && $aes_implementations['phpseclib'] === FALSE) {
$requirement_severity = REQUIREMENT_ERROR;
$value = $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;
if ($aes_implementations['mcrypt'] && $aes_implementations['phpseclib']) {
$value = t('Both MCrypt and PHP Secure Communications Library are available.');
}
else {
if ($aes_implementations['mcrypt']) {
$value = t('MCrypt is available.');
}
else {
$value = t('PHP Secure Communications Library is available.');
}
}
}
$requirements['aes'] = array(
'title' => $t('AES encryption implementation'),
'value' => $value,
'severity' => $requirement_severity,
);
return $requirements;
}
/**
* Retrieve information about available AES implementations.
*
* @return array
*/
function aes_get_available_aes_implementations() {
$phpsec_available = FALSE;
if (module_exists('libraries') && libraries_get_path('phpseclib')) {
$phpsec_include_path = libraries_get_path('phpseclib');
set_include_path(get_include_path() . PATH_SEPARATOR . $phpsec_include_path);
$phpsec_available = is_readable($phpsec_include_path . '/Crypt/AES.php');
}
$mcrypt_available = extension_loaded('mcrypt');
return array(
'mcrypt' => $mcrypt_available,
'phpseclib' => $phpsec_available,
);
}
/**
* Implements hook_enable().
*/
function aes_enable() {
if (variable_get("aes_implementation", FALSE)) {
// Implementation method is already set. We assume everything is already configured.
return;
}
$aes_implementations = aes_get_available_aes_implementations();
if ($aes_implementations['phpseclib']) {
variable_set("aes_implementation", "phpseclib");
$install_msg = t("AES enabled using the phpseclib implementation.");
}
else {
if ($aes_implementations['mcrypt']) {
variable_set("aes_implementation", "mcrypt");
$install_msg = t("AES enabled using the MCrypt 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 enabled but no AES implementation available. Please enable implementation before use!");
}
}
drupal_set_message($install_msg);
$iv = base64_decode(variable_get("aes_encryption_iv", FALSE));
if (empty($iv)) {
aes_make_iv(TRUE);
}
// This will create a new key if one doesn't exist.
aes_get_key();
}
/**
* 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;
}
/**
* Implements hook_uninstall().
*/
function aes_uninstall() {
// Delete keyfile.
if (variable_get("aes_key_storage_method", "Database") == "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_encryption_iv");
variable_del("aes_cipher");
variable_del("aes_viewing_method");
variable_del("aes_implementation");
drupal_set_message(t("AES uninstalled."));
}
/**
* Convert old setting for aes_convert from string to boolean.
*/
function aes_update_7100(&$sandbox) {
$old_value = variable_get("aes_convert", FALSE);
if (is_string($old_value)) {
$old_value = strtolower($old_value);
$new_value = $old_value === 'true';
}
else {
$new_value = (bool) $old_value;
}
variable_set("aes_convert", $new_value);
}
/**
* Convert old setting value for aes_viewing_method:collapsible.
*/
function aes_update_7101(&$sandbox) {
if (variable_get('aes_viewing_method') == 'collapsible') {
variable_set("aes_viewing_method", 'inplace');
}
}
Functions
Name | Description |
---|---|
aes_enable | Implements hook_enable(). |
aes_get_available_aes_implementations | Retrieve information about available AES implementations. |
aes_requirements | Implements hook_requirements(). |
aes_schema | Implements hook_schema(). |
aes_uninstall | Implements hook_uninstall(). |
aes_update_7100 | Convert old setting for aes_convert from string to boolean. |
aes_update_7101 | Convert old setting value for aes_viewing_method:collapsible. |