You are here

hosting_https.install in Aegir HTTPS 7.3

Define the database schema and uninstall function for the hosting_https module.

File

hosting_https.install
View source
<?php

/**
 * @file
 * Define the database schema and uninstall function for the hosting_https module.
 *
 */

/**
 * Implements hook_schema().
 */
function hosting_https_schema() {
  $schema['hosting_https_server'] = array(
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'https_port' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'vid',
      'nid',
    ),
  );
  $schema['hosting_https_site'] = array(
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'https_enabled' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'client_authentication' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Whether client authentication is enabled (1) or not (0).',
      ),
      'client_authentication_path' => array(
        'description' => 'The client authentication path, if not global.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'vid',
      'nid',
    ),
  );
  return $schema;
}

/**
 * Remove HTTPS service records from hosting_service table.
 */
function hosting_https_uninstall() {
  db_delete('hosting_service')
    ->condition('service', 'http')
    ->condition('type', 'https_apache')
    ->execute();
  db_delete('hosting_service')
    ->condition('service', 'http')
    ->condition('type', 'https_nginx')
    ->execute();
}

/**
 * Add the client_authentication column with defaults to the database.
 */
function hosting_https_update_7001() {
  $schema = hosting_https_schema();
  $field = $schema['hosting_https_site']['fields']['client_authentication'];
  db_add_field('hosting_https_site', 'client_authentication', $field);
  db_update('hosting_https_site')
    ->fields(array(
    'client_authentication' => 0,
  ))
    ->execute();
}

/**
 * Add support for enabling client authentication only on a specific path.
 */
function hosting_https_update_7002() {
  $schema = hosting_https_schema();
  $field = $schema['hosting_https_site']['fields']['client_authentication_path'];
  db_add_field('hosting_https_site', 'client_authentication_path', $field);
  db_update('hosting_https_site')
    ->fields(array(
    'client_authentication_path' => '',
  ))
    ->execute();
}

/**
 * Force a re-verification of all enabled SSL sites.
 */
function hosting_https_update_7300() {

  // node_access_rebuild from the the update hook fails without the following defintion.
  if (!defined('HOSTING_ADMIN_CLIENT')) {
    define('HOSTING_ADMIN_CLIENT', variable_get('hosting_admin_client', 1));
  }
  $apache_nids = array();
  $http_servers = hosting_get_servers('http', FALSE);
  $servers = node_load_multiple(array_keys($http_servers));
  foreach ($servers as $server) {
    if (!empty($server->services['http'])) {
      if ($server->services['http']->type === 'https_apache') {
        $apache_nids[] = $server->nid;
      }
    }
  }
  if ($apache_nids) {
    $site_query = db_select('hosting_site', 'hs');
    $site_query
      ->innerJoin('hosting_platform', 'hp', 'hs.platform = hp.nid');
    $site_query
      ->addField('hs', 'nid');
    $site_query
      ->condition('hs.status', 1);
    $site_query
      ->condition('hp.status', 1);
    $site_query
      ->condition('hp.web_server', $apache_nids, 'IN');
    $result = $site_query
      ->execute();
    while ($site = $result
      ->fetch()) {
      hosting_add_task($site->nid, 'verify');
    }
  }
}

Functions

Namesort descending Description
hosting_https_schema Implements hook_schema().
hosting_https_uninstall Remove HTTPS service records from hosting_service table.
hosting_https_update_7001 Add the client_authentication column with defaults to the database.
hosting_https_update_7002 Add support for enabling client authentication only on a specific path.
hosting_https_update_7300 Force a re-verification of all enabled SSL sites.