You are here

hsts.module in HTTP Strict Transport Security 6

Same filename and directory in other branches
  1. 8 hsts.module
  2. 7 hsts.module

Main module file for hsts.

File

hsts.module
View source
<?php

/**
 * @file
 * Main module file for hsts.
 */

/**
 * Implements hook_init().
 *
 * Sets the header in all requests to include the HSTS max-age value
 */
function hsts_init() {

  // Set the header to include the HSTS data
  if (variable_get('hsts_enabled', FALSE) == 1) {

    // Add the max age header
    $hsts_header = 'Strict-Transport-Security: max-age=' . check_plain(variable_get('hsts_max_age', 500));
    if (variable_get('hsts_subdomains', FALSE)) {

      // Include subdomains
      $hsts .= ';includeSubDomains';
    }

    // Add the header
    drupal_set_header($hsts_header);
  }
}

/**
 * Implements hook_perm().
 */
function hsts_perm() {
  return array(
    'administer strict transport security',
  );
}

/**
 * Implements hook_menu().
 */
function hsts_menu() {
  $items = array();
  $items['admin/settings/hsts'] = array(
    'title' => 'HTTP Strict Transport Security Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hsts_admin_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer strict transport security',
    ),
    'file' => 'hsts.admin.inc',
  );
  return $items;
}

Functions

Namesort descending Description
hsts_init Implements hook_init().
hsts_menu Implements hook_menu().
hsts_perm Implements hook_perm().