You are here

hsts.install in HTTP Strict Transport Security 7

Same filename and directory in other branches
  1. 6 hsts.install

Install file for hsts.

File

hsts.install
View source
<?php

// $Id$

/**
 * @file
 * Install file for hsts.
 */

/**
 * Implementation of hook_install().
 */
function hsts_install() {

  // Set the module weight to ensure it is the first module loaded
  db_query("UPDATE {system} SET weight = -999 WHERE name = 'hsts'");
  variable_set('hsts_max_age', 400);
  variable_set('hsts_enabled', FALSE);
  variable_set('hsts_subdomains', FALSE);
  variable_set('hsts_https_only', TRUE);

  // Notify the user that extra configuration is required.
  drupal_set_message(t('HSTS module enabled.'));
  drupal_set_message(t('HSTS headers are not enabled by default. To do so please use the !link page.', array(
    '!link' => l(t('HSTS Configuration'), 'admin/config/security/hsts'),
  )), 'info');
}

/**
 * Implementation of hook_uninstall().
 */
function hsts_uninstall() {
  variable_del('hsts_max_age');
  variable_del('hsts_enabled');
  variable_del('hsts_subdomains');
  variable_del('hsts_https_only');
}

/**
 * Implements hook_update_N().
 *
 * Only set HSTS headers on HTTPS connections.
 */
function hsts_update_7100(&$sandbox) {
  global $is_https;
  if (!$is_https) {
    drupal_set_message(t('HSTS was unable to detect if your site is running over HTTPS. Please check the HSTS configuration.'), 'warning');
  }

  // Safe default is to restrict to HTTPS only.
  variable_set('hsts_https_only', TRUE);
}

Functions

Namesort descending Description
hsts_install Implementation of hook_install().
hsts_uninstall Implementation of hook_uninstall().
hsts_update_7100 Implements hook_update_N().