You are here

login_security.install in Login Security 6

Login Security installation routines

File

login_security.install
View source
<?php

/**
 * @file
 * Login Security installation routines
 */

/**
 * Implementation of hook_schema().
 */
function login_security_schema() {
  $schema['login_security_track'] = array(
    'description' => t('Keeps track of failed login attempts, as a pair of the IP address and user name.'),
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => t("ID of each login event."),
      ),
      'host' => array(
        'type' => 'varchar',
        'length' => 39,
        'not null' => TRUE,
        'default' => '',
        'description' => t("The IP address of the request."),
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => t("Clean username, submitted using the login form."),
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => t("Timestamp of the event."),
      ),
    ),
    'indexes' => array(
      'name' => array(
        'name',
      ),
      'host' => array(
        'host',
      ),
      'timestamp' => array(
        'timestamp',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function login_security_install() {
  drupal_install_schema('login_security');
}

/**
 * Implementation of hook_uninstall().
 */
function login_security_uninstall() {
  variable_del('login_security_track_time');
  variable_del('login_security_user_wrong_count');
  variable_del('login_security_host_wrong_count');
  variable_del('login_security_host_wrong_count_hard');
  variable_del('login_security_disable_core_login_error');
  variable_del('login_security_notice_attempts_available');
  variable_del('login_security_notice_attempts_message');
  variable_del('login_security_host_soft_banned');
  variable_del('login_security_host_hard_banned');
  variable_del('login_security_user_blocked');
  variable_del('login_security_user_blocked_email_user');
  variable_del('login_security_user_blocked_email_subject');
  variable_del('login_security_user_blocked_email_body');
  variable_del('login_security_last_login_timestamp');
  variable_del('login_security_last_access_timestamp');
  variable_del('login_security_activity_threshold');
  variable_del('login_security_login_activity_email_user');
  variable_del('login_security_login_activity_subject');
  variable_del('login_security_login_activity_body');
  variable_del('login_security_threshold_notified');
  drupal_uninstall_schema('login_security');
}

/**
 * Support IPv6 length addresses in 6.x because the original 6.x
 * didn't have this update function. Since it's redundant from the
 * previous update function, it's mostly just helping support PostgreSQL.
 * Because update_5000() was the same, without schema, it was removed.
 *
 * @return array
 */
function login_security_update_6000() {
  $ret = array();

  // Change current primary key
  db_add_index($ret, 'login_security_track', 'id', array(
    'id',
  ));
  db_drop_primary_key($ret, 'login_security_track');
  db_add_primary_key($ret, 'login_security_track', array(
    'id',
  ));
  db_change_field($ret, 'login_security_track', 'host', 'host', array(
    'type' => 'varchar',
    'length' => 39,
    'not null' => TRUE,
    'default' => '',
    'description' => t("The IP address of the request."),
  ));
  db_add_index($ret, 'login_security_track', 'host', array(
    'host',
  ));
  db_add_index($ret, 'login_security_track', 'name', array(
    'name',
  ));
  db_drop_index($ret, 'login_security_track', 'timestamp');
  return $ret;
}

/**
 * Database clean up update as for #399390
 * http://drupal.org/node/399390
 *
 * Change current primary key to 'id' and add timestamp index
 *
 * @return array
 */
function login_security_update_6001() {
  $ret = array();

  // Change current primary key
  db_drop_primary_key($ret, 'login_security_track');
  db_add_primary_key($ret, 'login_security_track', array(
    'id',
  ));

  // Drop indexes
  db_drop_index($ret, 'login_security_track', 'name');
  db_drop_index($ret, 'login_security_track', 'id');
  db_change_field($ret, 'login_security_track', 'name', 'name', array(
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
    'description' => t("Clean username, after submitted using the login form."),
  ));
  db_change_field($ret, 'login_security_track', 'timestamp', 'timestamp', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => t("Timestamp of the event."),
  ));

  // Re-create indexes
  db_add_index($ret, 'login_security_track', 'name', array(
    'name',
  ));
  db_add_index($ret, 'login_security_track', 'timestamp', array(
    'timestamp',
  ));
  return $ret;
}

/**
 * Variable clean up update as for #866068
 * http://drupal.org/node/866068
 *
 * Allows to change email recipient
 *
 * @return array
 */
function login_security_update_6002() {
  $ret = array();
  $admin_name = db_result(db_query('SELECT name FROM {users} WHERE uid = 1'));

  // Adjust the 'blocked user' email notification variables
  $blocked_email = variable_get('login_security_user_blocked_email', LOGIN_SECURITY_USER_BLOCKED_EMAIL);
  $blocked_email_user = variable_get('login_security_user_blocked_email_user', LOGIN_SECURITY_USER_BLOCKED_EMAIL_USER);
  if ($blocked_email && $blocked_email_user === '') {
    variable_set('login_security_user_blocked_email_user', $admin_name);
  }

  // Adjust the 'suspect activity' email notification variables
  $activity_email = variable_get('login_security_login_activity_email', LOGIN_SECURITY_LOGIN_ACTIVITY_EMAIL);
  $activity_email_user = variable_get('login_security_login_activity_email_user', LOGIN_SECURITY_LOGIN_ACTIVITY_EMAIL_USER);
  if ($activity_email && $activity_email_user === '') {
    variable_set('login_security_login_activity_email_user', $admin_name);
  }

  // Clean up the now obsolete boolean variables
  variable_del('login_security_user_blocked_email');
  variable_del('login_security_login_activity_email');
  return $ret;
}

/**
 * Remove the option to have a login punishment for login failures for DoS.
 */
function login_security_update_6003() {
  variable_del('login_security_delay_base_time');
  variable_del('login_security_delay_increase');
}

Functions

Namesort descending Description
login_security_install Implementation of hook_install().
login_security_schema Implementation of hook_schema().
login_security_uninstall Implementation of hook_uninstall().
login_security_update_6000 Support IPv6 length addresses in 6.x because the original 6.x didn't have this update function. Since it's redundant from the previous update function, it's mostly just helping support PostgreSQL. Because update_5000() was the same,…
login_security_update_6001 Database clean up update as for #399390 http://drupal.org/node/399390
login_security_update_6002 Variable clean up update as for #866068 http://drupal.org/node/866068
login_security_update_6003 Remove the option to have a login punishment for login failures for DoS.