You are here

function hosting_ssl_nodeapi_site_validate in Hosting 7.4

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

Implements hook_nodeapi_TYPE_OP().

File

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

Code

function hosting_ssl_nodeapi_site_validate($node, &$form) {
  if (isset($node->ssl_enabled) && $node->ssl_enabled) {

    // TODO: find a way to avoid calling this function multiple times in hook_validate
    $valid_options = hosting_site_available_options($node);
    if ($node->ssl_key == HOSTING_SSL_CUSTOM_KEY) {
      if (!strlen($node->ssl_key_new)) {
        form_set_error('ssl_key_new', t("The encryption key field is required to enable us to generate a new SSL certificate for your site."));
      }
      else {
        $key = hosting_ssl_filter_key($node->ssl_key_new);
        if ($node->ssl_key_new != $key || !strlen($key)) {
          form_set_error('ssl_key_new', t("The encryption key field should only contain lower case alpha-numeric and '_', '-' or '.' characters."));
        }
        if (!ctype_alnum($key[0])) {
          form_set_error('ssl_key_new', t("The encryption key field must start with an alpha-numeric character."));
        }
        if ($key == HOSTING_SSL_CUSTOM_KEY) {
          form_set_error('ssl_key_new', t("This encryption key value is reserved for internal use, please choose another"));
        }
      }
    }
    else {
      if (!in_array($node->ssl_key, $valid_options['ssl_key'])) {
        form_set_error('ssl_key', t("You have chosen an invalid SSL key"));
      }
    }

    // TODO, check that the server to host this site has ssl enabled.
    // if (!empty($node->platform)) {
    // $platform = node_load($node->platform);
    // $server = node_load($platform->web_server);
    // $server->services['http']->type == 'apache_ssl' or nginx_ssl???
    // }
  }
}