You are here

status.inc in Lockr 7.2

Same filename and directory in other branches
  1. 7.3 include/status.inc

Status callback for Lockr admin page.

File

include/status.inc
View source
<?php

/**
 * @file
 * Status callback for Lockr admin page.
 */
function lockr_admin_status($status) {
  include_once DRUPAL_ROOT . '/includes/install.inc';
  $cert_valid = $status['cert_valid'];
  $exists = $status['exists'];
  $created = isset($status['created']) ? $status['created'] : FALSE;
  $cert_valid_text = <<<EOL
You're a certified Lockr user!
We've found your certificate and it validates with our system.
EOL;
  $cert_invalid_text = <<<EOL
Oops!
Looks like we need to know who you are before we give you the keys to the castle.
Your certificate is not valid, please register for one.
If you've already gotten a certificate, we are unable to find it.
Please check the advanced settings to ensure your path is correct
(or if you're on a hosting partner contact their support).
EOL;
  $reqs[] = [
    'title' => t('Certificate Valid'),
    'value' => $cert_valid ? t('Yes') : t('No'),
    'description' => $cert_valid ? $cert_valid_text : $cert_invalid_text,
    'severity' => $cert_valid ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  if ($cert_valid) {
    $reqs[] = [
      'title' => t('Environment'),
      'value' => $status['info']['env'],
      'severity' => REQUIREMENT_INFO,
    ];
  }
  else {
    $private_path = variable_get('file_private_path');
    $is_dir = is_dir($private_path);
    $req = [
      'title' => t('Private Directory'),
      'value' => $private_path ?: t('Unknown'),
      'description' => "Lockr stores certificates in Drupal's private directory. " . ($is_dir ? 'Looks good!' : format_string('Please <a href="@link">set the private directory</a>. ' . 'Make sure it is not available from the web.', array(
        '@link' => '/admin/config/media/file-system',
      ))),
      'severity' => $is_dir ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    ];
    array_unshift($reqs, $req);
  }
  $exists_text = <<<EOL
You're one of the family.
We've got your site registered and you're all good to go!
EOL;
  $not_exists_text = <<<EOL
Who are you again?
We don't have your site registered with Lockr.
Please use the form below to register your site.
EOL;
  $reqs[] = [
    'title' => t('Site Registered'),
    'value' => $exists ? t('Yes') : t('No'),
    'description' => $exists ? $exists_text : $not_exists_text,
    'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  if ($cert_valid) {
    $has_cc = $status['has_cc'];
    if ($created) {
      $expires = (new \DateTime())
        ->setTimestamp($created)
        ->add(new \DateInterval('P14D'));
      if ($expires > new \DateTime()) {
        $reqs[] = [
          'title' => t('Trial Expiration Date'),
          'value' => $expires
            ->format('M jS, Y'),
          'severity' => REQUIREMENT_INFO,
        ];
      }
      elseif (!$has_cc) {
        $reqs[] = [
          'title' => t('Trial Expiration Date'),
          'value' => $expires
            ->format('M jS, Y'),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
    }
    $partner = $status['info']['partner'];
    $is_custom = in_array($partner, [
      'custom',
      'lockr',
    ]);
    $default = $is_custom ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
    $is_custom_text = <<<EOL
Uh oh!
Without a credit card we cannot issue a production certificate.
Please add one before migrating to production.
EOL;
    $is_not_custom_text = "Since you're on a partnering host, a credit card is not necessary to move to production. However, please make sure you get a card on file ASAP. We will contact you if there is no card on file within 30 days of moving to production use.";
    $default_description = $is_custom ? $is_custom_text : $is_not_custom_text;
    $has_cc_text = <<<EOL
We've got your credit card safely on file and you'll be receiving regular
invoice for your key usage.
EOL;
    $reqs[] = [
      'title' => t('Credit Card on File'),
      'value' => $has_cc ? t('Yes') : t('No'),
      'description' => $has_cc ? $has_cc_text : $default_description,
      'severity' => $has_cc ? REQUIREMENT_OK : $default,
    ];
  }
  $migrate = FALSE;
  $keys = key_get_keys_by_provider('lockr');
  foreach ($keys as $key) {
    if (strpos($key['key_provider_settings']['encoded'], 'rijndael-256$cbc$') === 0) {
      $migrate = true;
      break;
    }
  }
  if ($migrate) {
    $reqs[] = [
      'title' => t('Legacy Keys'),
      'value' => t('Yes'),
      'description' => t('This site contains keys stored with legacy code. Please <a href="@link">migrate them</a> to using the latest encryption libraries.', [
        '@link' => url('admin/config/system/lockr/migrate', [
          'query' => [
            'destination' => 'admin/config/system/lockr',
          ],
        ]),
      ]),
      'severity' => REQUIREMENT_WARNING,
    ];
  }
  return theme('status_report', [
    'requirements' => $reqs,
  ]);
}

Functions

Namesort descending Description
lockr_admin_status @file Status callback for Lockr admin page.