You are here

hosting_https.module in Aegir HTTPS 7.3

Hook implementations for the Hosting HTTPS module.

File

hosting_https.module
View source
<?php

/**
 * @file
 * Hook implementations for the Hosting HTTPS module.
 */

/**
 * HTTPS is either disabled, enabled or required for a site.
 */
define('HOSTING_HTTPS_DISABLED', 0);
define('HOSTING_HTTPS_ENABLED', 1);
define('HOSTING_HTTPS_REQUIRED', 2);

/**
 * Client authentication can also be enabled.
 */
define('HOSTING_HTTPS_CLIENT_AUTHENTICATION_DISABLED', 0);
define('HOSTING_HTTPS_CLIENT_AUTHENTICATION_ENABLED', 1);
include_once 'hosting_https.nodeapi.inc';

/**
 * Implements hook_permission().
 *
 * @todo Move this to the 'manual' certificate service implementation.
 */
function hosting_https_permission() {
  return array(
    'manage site HTTPS settings' => array(
      'title' => t('Manage site HTTPS settings.'),
    ),
  );
}

/**
 * Return a list of servers which have HTTPS enabled web services.
 */
function hosting_https_get_servers($access_check = TRUE) {
  $servers = hosting_get_servers('http', $access_check);
  $https_servers = array();
  foreach ($servers as $nid => $title) {
    $server = node_load($nid);
    $check_servers = array();
    if ($server->services['http']->type == 'cluster') {
      foreach ($server->services['http']->web_servers as $inner_nid) {
        $check_servers[] = node_load($inner_nid);
      }
    }
    elseif ($server->services['http']->type == 'pack') {
      foreach ($server->services['http']->master_servers as $inner_nid) {
        $check_servers[] = node_load($inner_nid);
      }
      foreach ($server->services['http']->slave_servers as $inner_nid) {
        $check_servers[] = node_load($inner_nid);
      }
    }
    else {
      $check_servers[] = $server;
    }
    $https_available = TRUE;
    foreach ($check_servers as $node) {

      // For clusters and packs, HTTPS is only available if *all* of its servers
      // have HTTPS enabled.
      $https_available = $https_available && $node->services['http']->https_enabled;
    }
    if ($https_available) {
      $https_servers[] = $nid;
    }
  }
  return $https_servers;
}

/**
 * Return a list of platforms on HTTPS enabled servers.
 */
function hosting_https_get_platforms() {
  $https_servers = hosting_https_get_servers();
  $https_platforms = array();
  $platforms = _hosting_get_platforms();
  foreach ($platforms as $nid => $title) {
    $platform = node_load($nid);
    if (in_array($platform->web_server, $https_servers)) {
      $https_platforms[] = $nid;
    }
  }
  return $https_platforms;
}

/**
 * Return a list of profiles with HTTPS enabled platforms.
 */
function hosting_https_get_profiles() {
  $https_platforms = hosting_https_get_platforms();
  $https_profiles = array();
  foreach ($https_platforms as $nid) {
    $platform = node_load($nid);
    $https_profiles = array_merge($https_profiles, array_keys($platform->profiles));
  }
  return array_unique($https_profiles);
}

/**
 * Implements hook_form_alter().
 */
function hosting_https_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'site_node_form') {
    hosting_https_site_form($form, $form_state, $form_id);
  }
}

/**
 * Callback function to execute on enabling this module's feature.
 *
 * @see: hosting_example_hosting_feature().
 */
function hosting_https_feature_enable_callback() {
  drupal_set_message(t("Please make sure you have enabled HTTPS support in your webserver, e.g. by enabling mod_ssl in Apache."));
  drupal_set_message(t("To start using HTTPS please edit the desired server node within Aegir to set it from e.g. 'apache' to 'apache_https'."));
}
function hosting_https_is_available($site, $check_server_access = TRUE) {
  $https_available = FALSE;
  if (isset($site->nid)) {
    $platform = node_load($site->platform);
    if (in_array($platform->web_server, hosting_https_get_servers($check_server_access))) {
      $https_available = TRUE;
    }
  }
  elseif (count(hosting_https_get_servers($check_server_access)) > 0) {
    $https_available = TRUE;
  }
  return $https_available;
}

Functions

Namesort descending Description
hosting_https_feature_enable_callback Callback function to execute on enabling this module's feature.
hosting_https_form_alter Implements hook_form_alter().
hosting_https_get_platforms Return a list of platforms on HTTPS enabled servers.
hosting_https_get_profiles Return a list of profiles with HTTPS enabled platforms.
hosting_https_get_servers Return a list of servers which have HTTPS enabled web services.
hosting_https_is_available
hosting_https_permission Implements hook_permission().

Constants

Namesort descending Description
HOSTING_HTTPS_CLIENT_AUTHENTICATION_DISABLED Client authentication can also be enabled.
HOSTING_HTTPS_CLIENT_AUTHENTICATION_ENABLED
HOSTING_HTTPS_DISABLED HTTPS is either disabled, enabled or required for a site.
HOSTING_HTTPS_ENABLED
HOSTING_HTTPS_REQUIRED