You are here

function seckit_init in Security Kit 7

Same name and namespace in other branches
  1. 6 seckit.module \seckit_init()

Implements hook_init().

File

./seckit.module, line 81
Allows administrators to improve security of the website.

Code

function seckit_init() {

  // Do nothing for command-line requests.
  if (drupal_is_cli()) {
    return;
  }

  // get default/set options
  $options = _seckit_get_options();
  if ($options['seckit_advanced']['disable_seckit']) {
    return;
  }

  // execute necessary functions
  if ($options['seckit_csrf']['origin']) {
    _seckit_origin();
  }
  if ($options['seckit_xss']['csp']['checkbox']) {
    _seckit_csp();
  }
  if ($options['seckit_xss']['x_xss']['select']) {
    _seckit_x_xss($options['seckit_xss']['x_xss']['select']);
  }

  // Always call this (regardless of the setting) since if it's disabled it may
  // be necessary to actively disable the Drupal core clickjacking defense.
  _seckit_x_frame($options['seckit_clickjacking']['x_frame']);
  if ($options['seckit_clickjacking']['js_css_noscript']) {
    _seckit_js_css_noscript();
  }
  if ($options['seckit_ssl']['hsts']) {
    _seckit_hsts();
  }
  if ($options['seckit_ct']['expect_ct']) {
    _seckit_expect_ct();
  }
  if ($options['seckit_various']['from_origin']) {
    _seckit_from_origin();
  }
  if ($options['seckit_various']['referrer_policy']) {
    _seckit_referrer_policy();
  }
  if ($options['seckit_fp']['feature_policy']) {
    _seckit_fp();
  }

  // load jQuery listener
  if ($_GET['q'] == 'admin/config/system/seckit') {
    $path = drupal_get_path('module', 'seckit');
    $listener = "{$path}/js/seckit.listener.js";
    drupal_add_js($listener);
  }
}