hosting_ssl.service.inc

Define Hosting service class for SSL.

Classes

File

web_server/ssl/hosting_ssl.service.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Define Hosting service class for SSL.
  5. */
  6. class hostingService_http_ssl extends hostingService_http_public {
  7. function load() {
  8. parent::load();
  9. $this->mergeData("SELECT ssl_port FROM {hosting_ssl_server} WHERE vid=:vid", array(':vid' => $this->server->vid));
  10. $this->ssl_enabled = TRUE;
  11. }
  12. function insert() {
  13. parent::insert();
  14. $id = db_insert('hosting_ssl_server')
  15. ->fields(array(
  16. 'vid' => $this->server->vid,
  17. 'nid' => $this->server->nid,
  18. 'ssl_port' => $this->ssl_port,
  19. ))
  20. ->execute();
  21. }
  22. function delete() {
  23. parent::delete();
  24. db_delete('hosting_ssl_server')
  25. ->condition('nid', $this->server->nid)
  26. ->execute();
  27. }
  28. function delete_revision() {
  29. parent::delete_revision();
  30. db_delete('hosting_ssl_server')
  31. ->condition('vid', $this->server->vid)
  32. ->execute();
  33. }
  34. function form(&$form) {
  35. parent::form($form);
  36. $form['ssl_port'] = array(
  37. '#type' => 'textfield',
  38. '#title' => t('SSL Port'),
  39. '#required' => !empty($this->available),
  40. '#size' => 40,
  41. '#default_value' => isset($this->ssl_port) ? $this->ssl_port : '443',
  42. '#description' => t("The port that this service will use for encrypted traffic."),
  43. '#maxlength' => 255,
  44. '#weight' => -7,
  45. );
  46. }
  47. function view(&$render) {
  48. parent::view($render);
  49. $render['ssl_port'] = array(
  50. '#type' => 'item',
  51. '#title' => t('SSL Port'),
  52. '#markup' => filter_xss($this->ssl_port),
  53. );
  54. }
  55. public function validate(&$node, &$form) {
  56. parent::validate($node, $form);
  57. if ((int) $this->ssl_port <= 0) {
  58. form_set_error('ssl_port', t("The port you specify must be a number."));
  59. }
  60. }
  61. public function context_options($task_type, $ref_type, &$task) {
  62. parent::context_options($task_type, $ref_type, $task);
  63. $task->context_options[$this->service . '_ssl_port'] = $this->ssl_port;
  64. }
  65. public function context_import($context) {
  66. parent::context_import($context);
  67. $this->ssl_port = $context->http_ssl_port;
  68. }
  69. }
  70. class hostingService_http_apache_ssl extends hostingService_http_ssl {
  71. public $type = 'apache_ssl';
  72. protected $has_restart_cmd = TRUE;
  73. function default_restart_cmd() {
  74. $command = '/usr/sbin/apachectl'; # a proper default for most of the world
  75. foreach (explode(':', $_SERVER['PATH']) as $path) {
  76. $options[] = "$path/apache2ctl";
  77. $options[] = "$path/apachectl";
  78. }
  79. # try to detect the apache restart command
  80. $options[] = '/usr/local/sbin/apachectl'; # freebsd
  81. $options[] = '/usr/sbin/apache2ctl'; # debian + apache2
  82. $options[] = $command;
  83. foreach ($options as $test) {
  84. if (is_executable($test)) {
  85. $command = $test;
  86. break;
  87. }
  88. }
  89. return "sudo $command graceful";
  90. }
  91. }