You are here

function hosting_ssl_site_form in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 web_server/ssl/hosting_ssl.nodeapi.inc \hosting_ssl_site_form()
  2. 7.3 web_server/ssl/hosting_ssl.nodeapi.inc \hosting_ssl_site_form()

Form API code to extend the site form with SSL fields.

1 call to hosting_ssl_site_form()
hosting_ssl_form_alter in web_server/ssl/hosting_ssl.module
Implements hook_form_alter().

File

web_server/ssl/hosting_ssl.nodeapi.inc, line 15
NodeAPI functions for the Hosting SSL module.

Code

function hosting_ssl_site_form(&$form, &$form_state, $form_id) {
  $node = $form['#node'];
  $new_site = TRUE;
  $ssl_available = FALSE;

  // Only allow the user to modify these values when the platform is SSL enabled.
  if (isset($node->nid)) {
    $new_site = FALSE;
    $platform = node_load($node->platform);
    $server = node_load($platform->web_server);
    if ($server->services['http']->ssl_enabled) {
      $ssl_available = TRUE;
    }
  }
  elseif (count(hosting_ssl_get_servers('http')) > 0) {
    $ssl_available = TRUE;
  }
  if (!$ssl_available) {
    return;
  }
  _hosting_site_field($form, $node, 'hosting_ssl_wrapper', array(
    '#type' => 'fieldset',
    '#title' => t('SSL Settings'),
    '#default_value' => NULL,
  ), 'filter_xss', $ssl_available);
  _hosting_site_field($form['hosting_ssl_wrapper'], $node, 'ssl_enabled', array(
    '#type' => 'radios',
    '#title' => t('Encryption'),
    '#options' => hosting_ssl_status_options(),
    '#description' => t('Enabling encryption will publish your site on both HTTP and HTTPS ports, allowing you to redirect users to the more secure version for certain pages that require the additional security. Requiring encryption will automatically redirect all unencrypted traffic to your HTTPS site.'),
    '#required' => TRUE,
    '#default_value' => isset($node->ssl_enabled) ? $node->ssl_enabled : HOSTING_SSL_DISABLED,
    '#access' => user_access('create ssl certificate'),
  ), 'hosting_ssl_status_options', $ssl_available);
  _hosting_site_field($form['hosting_ssl_wrapper'], $node, 'ssl_key', array(
    '#type' => 'radios',
    '#title' => t('Encryption key'),
    '#description' => t("Choose an existing SSL certificate. If you do not wish to use any of your existing certificates, you may choose to generate a new one."),
    '#options' => hosting_ssl_get_keys(NULL, TRUE),
    '#required' => TRUE,
    '#default_value' => isset($node->ssl_key) && $node->ssl_key > 0 ? $node->ssl_key : HOSTING_SSL_CUSTOM_KEY,
    '#access' => user_access('create ssl certificate'),
    '#states' => array(
      'visible' => array(
        ':input[name="ssl_enabled"]' => array(
          '!value' => 0,
        ),
      ),
    ),
  ), 'hosting_ssl_output_key', $ssl_available, !$new_site);
  _hosting_site_field($form['hosting_ssl_wrapper'], $node, 'ssl_key_new', array(
    '#type' => 'textfield',
    '#title' => t('New encryption key'),
    '#description' => t("A name for the certificate, often relating to the domain name. This field should only contain lower case alpha-numeric and '_', '-' or '.' characters. If the SSL certificate is not found in config/ssl.d, Aegir will automatically generate a self-signed certificate for you. You can replace the generated with a properly signed version later. Any required intermediate certificates can be added in a file called config/ssl.d/<name>/openssl_chain.crt"),
    '#default_value' => '',
    '#access' => user_access('create ssl certificate'),
    '#states' => array(
      'visible' => array(
        ':input[name="ssl_enabled"]' => array(
          '!value' => 0,
        ),
        ':input[name="ssl_key"]' => array(
          'value' => HOSTING_SSL_CUSTOM_KEY,
        ),
      ),
    ),
  ), 'filter_xss', $ssl_available, FALSE);
}