diff --git a/server/hosting_server.service.inc b/server/hosting_server.service.inc index f63daac..fe4b0a6 100644 --- a/server/hosting_server.service.inc +++ b/server/hosting_server.service.inc @@ -160,7 +160,13 @@ class hostingService { } } - + + /** + * Implement this method to add form elements to site nodes that use this service. + */ + public function site_form(&$form, $node) { + } + public function view(&$render) { if ($this->has_restart_cmd) { $render['restart_cmd'] = array( diff --git a/site/hosting_site.form.inc b/site/hosting_site.form.inc index c1107b5..4b2b5c0 100644 --- a/site/hosting_site.form.inc +++ b/site/hosting_site.form.inc @@ -346,6 +346,49 @@ function hosting_site_form($node, &$form_state) { '#value' => isset($node->$extra_attribute) ? $node->$extra_attribute : NULL, ); } + + // Let services add form elements to the site node form. + // @TODO: This only works on site edit pages, because we don't yet know what + // platform the user wants (which determnines which web server the user wants.) + $form['server_tabs'] = array( + '#type' => 'vertical_tabs', + ); + $services_metadata = hosting_server_services(); + + // The servers that a site requires are loaded via hosting_site_load(). + // Show a fieldset for each one of them. + foreach ($node->servers as $server_type => $server) { + $form['servers'][$server_type] = array( + '#type' => 'fieldset', + '#group' => 'server_tabs', + '#title' => $services_metadata[$server_type]['title'], + ); + + // Show the chosen server + $form['servers'][$server_type]['server'] = array( + '#type' => 'item', + '#title' => t('Server'), + '#markup' => l($server->title, "node/{$server->nid}", array( + 'attributes' => array( + 'target' => '_blank', + ), + )), + ); + foreach ($server->services as $service_type => $service) { + if (method_exists($service, 'site_form')) { + $service->site_form($form['servers'][$server_type][$service_type], $node); + } + } + + // If there is more than one web server, and user has edit access, show a + // link to change the web server. + // Platform web server can be changed on the platform edit page. + + // If there is more than one db server, and user has edit access, show a + // link to change the db server. + // Site db server can be changed with a migrate task. + + } return $form; } diff --git a/site/hosting_site.nodeapi.inc b/site/hosting_site.nodeapi.inc index 01dbb27..7cd6866 100644 --- a/site/hosting_site.nodeapi.inc +++ b/site/hosting_site.nodeapi.inc @@ -400,9 +400,13 @@ function hosting_site_node_update($node) { */ function hosting_site_load($nodes) { foreach ($nodes as $nid => &$node) { - $additions = db_query('SELECT client, db_server, db_name, platform, profile, language as site_language, last_cron, cron_key, status AS site_status, verified FROM {hosting_site} WHERE vid = :vid', array(':vid' => $node->vid))->fetch(); + $additions = db_query('SELECT client, db_server, db_name, platform, profile, web_server, publish_path, language as site_language, last_cron, cron_key, s.status AS site_status, p.status AS platform_status, s.verified, p.verified as platform_verified FROM {hosting_site} s LEFT JOIN {hosting_platform} p ON s.platform = p.nid WHERE s.vid = :vid', array(':vid' => $node->vid))->fetch(); foreach ($additions as $property => &$value) { $node->$property = $value; } } + + // Create a "servers" array based on our two base servers. + $node->servers['http'] = node_load($node->web_server); + $node->servers['db'] = node_load($node->db_server); } diff --git a/web_server/ssl/hosting_ssl.module b/web_server/ssl/hosting_ssl.module index 71764bb..89fd062 100644 --- a/web_server/ssl/hosting_ssl.module +++ b/web_server/ssl/hosting_ssl.module @@ -89,14 +89,14 @@ function hosting_ssl_get_profiles() { return array_unique($ssl_profiles); } -/** - * Implements hook_form_alter(). - */ -function hosting_ssl_form_alter(&$form, &$form_state, $form_id) { - if ($form_id == 'site_node_form') { - hosting_ssl_site_form($form, $form_state, $form_id); - } -} +///** +// * Implements hook_form_alter(). +// */ +//function hosting_ssl_form_alter(&$form, &$form_state, $form_id) { +// if ($form_id == 'site_node_form') { +// hosting_ssl_site_form($form, $form_state, $form_id); +// } +//} /** * Per-server, per-ip certificate listing. diff --git a/web_server/ssl/hosting_ssl.nodeapi.inc b/web_server/ssl/hosting_ssl.nodeapi.inc index 6c527f3..c523cf0 100644 --- a/web_server/ssl/hosting_ssl.nodeapi.inc +++ b/web_server/ssl/hosting_ssl.nodeapi.inc @@ -9,78 +9,78 @@ */ define('HOSTING_SSL_CUSTOM_KEY', 'null'); -/** - * Form API code to extend the site form with SSL fields. - */ -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); -} +///** +// * Form API code to extend the site form with SSL fields. +// */ +//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); +//} /** * Implemensts hook_hosting_site_options_alter diff --git a/web_server/ssl/hosting_ssl.service.inc b/web_server/ssl/hosting_ssl.service.inc index b8cda1c..0475ac6 100644 --- a/web_server/ssl/hosting_ssl.service.inc +++ b/web_server/ssl/hosting_ssl.service.inc @@ -78,7 +78,83 @@ class hostingService_http_ssl extends hostingService_http_public { $this->ssl_port = $context->http_ssl_port; } - + + public function site_form(&$form, $node) { + parent::site_form($form, $node); + +// $new_site = TRUE; +// $ssl_available = FALSE; + // Only allow the user to modify these values when the platform is SSL enabled. + // @TODO: Remove this, we probably don't need it any more since this method is only invoked if the services are 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; +// } + + + // Assume SSL is available and this is not a new site, since our code doesn't support new sites yet. + $ssl_available = TRUE; + $new_site = FALSE; + + _hosting_site_field($form, $node, 'hosting_ssl_wrapper', array( + '#type' => 'fieldset', + '#title' => t('SSL Settings'), + '#default_value' => NULL, +// '#parents' => array('hosting_ssl_wrapper'), + ), '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); + } } class hostingService_http_apache_ssl extends hostingService_http_ssl {