You are here

function encrypt_requirements in Encrypt 6

Same name and namespace in other branches
  1. 7.3 encrypt.install \encrypt_requirements()
  2. 7 encrypt.install \encrypt_requirements()
  3. 7.2 encrypt.install \encrypt_requirements()

Implementation of hook_requirements().

2 calls to encrypt_requirements()
encrypt_admin_settings in includes/encrypt.admin.inc
Menu callback; displays the encrypt module settings page.
encrypt_admin_settings_validate in includes/encrypt.admin.inc
Validate form function for encrypt_admin_settings(). Checks if users really wants to change path, and whether key can be written.

File

./encrypt.install, line 40
This file holds the functions for the installing and enabling of the encrypt module.

Code

function encrypt_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();

  // We do not require key to be secure for module to work.
  if ($phase == 'runtime') {
    $error_message = '';
    $key_found = FALSE;
    $encrypt_key_path = rtrim(variable_get('encrypt_secure_key_path', ''), '/\\');
    $encrypt_key_file = $encrypt_key_path . '/' . ENCRYPT_SECURE_KEY_FILE;

    // Check if path is set
    if ($encrypt_key_path == '') {
      $error_message = $t('No path set for key.');
    }

    // Check if path is writable and a dir
    if (empty($error_message)) {
      if (!is_writable($encrypt_key_path) || !is_dir($encrypt_key_path)) {
        $error_message = $t('Path not writable.');
        $state = 1;
      }
    }

    // Check for file
    if (empty($error_message)) {
      if (!file_exists($encrypt_key_file) || !is_writable($encrypt_key_file) || !is_readable($encrypt_key_file)) {
        $error_message = $t('File not found or not writable.');
        $state = 2;
      }
    }

    // Check for contents of file
    if (empty($error_message)) {
      $key_contents = file_get_contents($encrypt_key_file);
      if (!$key_contents) {
        $error_message = $t('No key found in file.');
      }
    }

    // Check if keys found
    $requirements['encrypt_keys'] = array();
    $requirements['encrypt_keys']['title'] = $t('Encrypt Key Storage');
    if (empty($error_message)) {
      $requirements['encrypt_keys']['value'] = $t('OK');
      $requirements['encrypt_keys']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['encrypt_keys']['value'] = $error_message;
      $requirements['encrypt_keys']['severity'] = REQUIREMENT_ERROR;
      $requirements['encrypt_keys']['description'] = $t('Encrypt is really only secure if you store your key outside the webroot.  Read the %readme file or go to the <a href="@admin">admin settings</a> to find out more.', array(
        '%settings' => 'settings.php',
        '%readme' => 'README.txt',
        '@admin' => url('admin/settings/encrypt'),
      ));
    }
  }
  return $requirements;
}