hosting_ssl.module

Hook implementations for the Hosting SSL module.

Functions

Namesort descending Description
hosting_ssl_cert_node_load Implements hook_load() from hook_menu().
hosting_ssl_feature_enable_callback Callback function to execute on enabling this module's feature.
hosting_ssl_form_alter Implements hook_form_alter().
hosting_ssl_get_platforms Return a list of platforms on SSL enabled servers.
hosting_ssl_get_profiles Return a list of profiles with SSL enabled platforms.
hosting_ssl_get_servers Return a list of servers which have SSL enabled web services.
hosting_ssl_hosting_service Implements hook_hosting_service().
hosting_ssl_menu Per-server, per-ip certificate listing.
hosting_ssl_permission Implements hook_permission().
hosting_ssl_server_cert_list List SSL certificates associated with the given server.

Constants

Namesort descending Description
HOSTING_SSL_DISABLED SSL is disabled for this site.
HOSTING_SSL_ENABLED SSL is enabled for this site.
HOSTING_SSL_REQUIRED SSL is required for this site.

File

web_server/ssl/hosting_ssl.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hook implementations for the Hosting SSL module.
  5. */
  6. /**
  7. * SSL is disabled for this site.
  8. */
  9. define('HOSTING_SSL_DISABLED', 0);
  10. /**
  11. * SSL is enabled for this site.
  12. */
  13. define('HOSTING_SSL_ENABLED', 1);
  14. /**
  15. * SSL is required for this site.
  16. */
  17. define('HOSTING_SSL_REQUIRED', 2);
  18. include_once 'hosting_ssl.nodeapi.inc';
  19. /**
  20. * Implements hook_hosting_service().
  21. */
  22. function hosting_ssl_hosting_service() {
  23. return array(
  24. 'apache_ssl' => 'http',
  25. );
  26. }
  27. /**
  28. * Implements hook_permission().
  29. */
  30. function hosting_ssl_permission() {
  31. return array(
  32. 'create ssl certificate' => array(
  33. 'title' => t('create ssl certificate'),
  34. ),
  35. );
  36. }
  37. /**
  38. * Return a list of servers which have SSL enabled web services.
  39. */
  40. function hosting_ssl_get_servers() {
  41. $servers = hosting_get_servers('http');
  42. $ssl_servers = array();
  43. foreach ($servers as $nid => $title) {
  44. $node = node_load($nid);
  45. if ($node->services['http']->ssl_enabled) {
  46. $ssl_servers[] = $nid;
  47. }
  48. }
  49. return $ssl_servers;
  50. }
  51. /**
  52. * Return a list of platforms on SSL enabled servers.
  53. */
  54. function hosting_ssl_get_platforms() {
  55. $servers = hosting_ssl_get_servers();
  56. $ssl_platforms = array();
  57. $platforms = _hosting_get_platforms();
  58. foreach ($platforms as $nid => $title) {
  59. $platform = node_load($nid);
  60. if (in_array($platform->web_server, $servers)) {
  61. $ssl_platforms[] = $nid;
  62. }
  63. }
  64. return $ssl_platforms;
  65. }
  66. /**
  67. * Return a list of profiles with SSL enabled platforms.
  68. */
  69. function hosting_ssl_get_profiles() {
  70. $platforms = hosting_ssl_get_platforms();
  71. $ssl_profiles = array();
  72. foreach ($platforms as $nid) {
  73. $platform = node_load($nid);
  74. $ssl_profiles = array_merge($ssl_profiles, array_keys($platform->profiles));
  75. }
  76. return array_unique($ssl_profiles);
  77. }
  78. /**
  79. * Implements hook_form_alter().
  80. */
  81. function hosting_ssl_form_alter(&$form, &$form_state, $form_id) {
  82. if ($form_id == 'site_node_form') {
  83. hosting_ssl_site_form($form, $form_state, $form_id);
  84. }
  85. }
  86. /**
  87. * Per-server, per-ip certificate listing.
  88. */
  89. function hosting_ssl_menu() {
  90. $items = array();
  91. $items['node/%hosting_ssl_cert_node/ssl'] = array(
  92. 'title' => 'Certificates',
  93. 'description' => 'SSL certificates deployed on this server',
  94. 'page callback' => 'hosting_ssl_server_cert_list',
  95. 'page arguments' => array(1),
  96. 'type' => MENU_LOCAL_TASK,
  97. 'access arguments' => array('view server'),
  98. );
  99. return $items;
  100. }
  101. /**
  102. * Implements hook_load() from hook_menu().
  103. *
  104. * This is a weird hook that is not well documented but allows loads from the
  105. * menu system. This is *not* the regular hook_load().
  106. *
  107. * @see hosting_ssl_menu()
  108. */
  109. function hosting_ssl_cert_node_load($arg) {
  110. if (!is_numeric($arg)) {
  111. return FALSE;
  112. }
  113. if ($node = node_load($arg)) {
  114. if ($node->type == 'server') {
  115. return $node;
  116. }
  117. }
  118. return FALSE;
  119. }
  120. /**
  121. * List SSL certificates associated with the given server.
  122. */
  123. function hosting_ssl_server_cert_list($node) {
  124. drupal_set_title(t('Certificates installed on server @server', array('@server' => $node->title)), PASS_THROUGH);
  125. $header = array(
  126. array(
  127. 'data' => t('Domain'),
  128. 'field' => 'domain',
  129. ),
  130. array(
  131. 'data' => t('IP address'),
  132. 'field' => 'ip_address',
  133. ),
  134. array(
  135. 'data' => t('Client'),
  136. 'field' => 'client',
  137. ),
  138. );
  139. $query = db_select('hosting_ip_addresses', 'ips');
  140. $query = $query->extend('PagerDefault');
  141. $query = $query->extend('TableSort');
  142. $query->join('hosting_ssl_cert_ips', 'cert_ip', 'cert_ip.ip_address = ips.id');
  143. $query->join('hosting_ssl_cert', 'cert', 'cert.cid = cert_ip.cid');
  144. $query->join('node', 'client', 'client.nid = cert.client');
  145. $query->element(2);
  146. $query->addField('ips', 'ip_address');
  147. $query->addField('cert', 'ssl_key', 'domain');
  148. $query->addField('cert', 'status');
  149. $query->addField('client', 'title', 'client');
  150. $query->condition('ips.nid', $node->nid)
  151. ->limit(25)
  152. ->orderByHeader($header)
  153. ->addTag('node_access');
  154. $result = $query->execute();
  155. $rows = array();
  156. foreach ($result as $cert) {
  157. $row = array();
  158. $row[] = $cert->domain;
  159. $row[] = $cert->ip_address;
  160. $row[] = filter_xss($cert->client);
  161. $rows[] = $row;
  162. }
  163. return theme('table',
  164. array(
  165. 'header' => $header,
  166. 'rows' => $rows,
  167. 'attributes' => array('class' => array('hosting-table')),
  168. ))
  169. . theme('pager', array('tags' => NULL, 'element' => 2));
  170. }
  171. /**
  172. * Callback function to execute on enabling this module's feature.
  173. *
  174. * @see: hosting_example_hosting_feature().
  175. */
  176. function hosting_ssl_feature_enable_callback() {
  177. drupal_set_message(t("Please make sure you have enabled SSL support in your webserver, e.g. by enabling mod_ssl in Apache."));
  178. drupal_set_message(t("To start using SSL please edit the desired server node within Aegir to set in from e.g. 'apache' to 'apache_ssl'."));
  179. }