You are here

cronkeychange.module in Cron key change 7

Same filename and directory in other branches
  1. 8 cronkeychange.module
  2. 2.x cronkeychange.module

Cron Key Change

File

cronkeychange.module
View source
<?php

/**
 * @file
 * Cron Key Change
 */

/**
 * Implements hook_help().
 *
 * Displays help and module information.
 *
 * @param path
 *   Which path of the site we are using to display help
 * @param arg
 *   Array that holds the current path as returned from arg() function
 */
function cronkeychange_help($path, $arg) {
  switch ($path) {
    case "admin/help#cronkeychange":
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Cron key change is a module that adds various utility functions for the Drupal cron system. This module helps to generate a new cron key. This might be a useful utility module for anyone who has reason to believe their cron key has been accidentally disclosed. Drush command <strong><em>drush cronkeychange</strong></em> is available to display the newly generated cron key.') . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dt>' . t('Configuring Cron key change') . '</dt>';
      $output .= '<dd>' . t('On the Cron page, you can <a href="@cron-keygen#edit-cronkeychange">generate the new cron key</a>', array(
        '@cron-keygen' => url('admin/config/system/cron'),
      )) . '</dd>';

      // Add a link to the Drupal.org project.
      $output .= '<p>';
      $output .= t('Visit the <a href="@project_link">Cron key change project page</a> on Drupal.org for more information.', array(
        '@project_link' => url('https://www.drupal.org/project/cronkeychange'),
      ));
      $output .= '</p>';
      return $output;
      break;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cronkeychange_form_system_cron_settings_alter(&$form, &$form_state, $form_id) {
  $form['cronkeychange'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
    '#title' => t('Change cron key'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['cronkeychange']['current'] = array(
    '#type' => 'item',
    '#title' => t('Current cron key'),
    '#markup' => variable_get('cron_key', 'drupal'),
  );
  $form['cronkeychange']['generate'] = array(
    '#type' => 'submit',
    '#value' => t('Generate new key'),
    '#submit' => array(
      'cronkeychange_generate_submit',
    ),
  );
}

/**
 * Generate new cron key.
 */
function cronkeychange_generate_submit(&$form = array(), &$form_state = array()) {
  $cron_key = drupal_random_key();
  variable_set('cron_key', $cron_key);
  if (!drupal_is_cli()) {
    drupal_set_message(t('New cron key generated.'));
  }
  watchdog('Cron key change', 'New cron key generated.');
}