http.drush.inc 5.61 KB
Newer Older
1 2 3 4
<?php

include_once(dirname(__FILE__) . '/../provision.service.inc');

5
function http_provision_services() {
drumm's avatar
drumm committed
6
  return array('http' => NULL);
7
}
8

9 10

// Base http service class. 
11
class provisionService_http extends provisionService {
12
  public $service = 'http';
13
  protected $ssl_enabled = FALSE;
14 15 16 17 18 19 20 21 22


  /**
   * Support the ability to cloak the database credentials using environment variables.
   */
  function cloaked_db_creds() {
    return FALSE;
  }

23

24 25 26 27 28 29 30 31 32
  function verify_server_cmd() {
    $this->create_config($this->context->type);
    $this->parse_configs();
  }

  function verify_platform_cmd() {
    $this->create_config($this->context->type);
    $this->parse_configs();
  }
33

34
  function verify_site_cmd() {
35 36 37 38
    $this->create_config($this->context->type);
    $this->parse_configs();
  }

39

40 41 42 43 44 45 46 47 48
  /**
   * Register the http handler for platforms, based on the web_server option.
   */
  static function subscribe_platform($context) {
    $context->setProperty('web_server', '@server_master');
    $context->is_oid('web_server');
    $context->service_subscribe('http', $context->web_server->name);
  }

49
}
50

51
// Public http service , as in non-encrypted and listening on a port.
52
class provisionService_http_public extends provisionService_http {
53
  protected $has_port = TRUE;
54 55 56 57 58 59 60 61
   
  function default_port() {
    return 80;
  }

  function config_data($config = null, $class = null) {
    $data = parent::config_data($config, $class);
    if (!is_null($this->application_name)) {
62 63
      $data['http_pred_path'] = $this->server->http_pred_path;
      $data['http_postd_path'] = $this->server->http_postd_path;
64 65 66 67
      $data['http_platformd_path'] = $this->server->http_platformd_path;
      $data['http_vhostd_path'] = $this->server->http_vhostd_path;
    }

68 69
    $data['http_port'] = $this->server->http_port;

70 71 72
    // We assign this generic catch all for standard http.
    // The SSL based services will override this with the
    // correct ip address.
73 74 75 76 77 78 79 80 81
    if (sizeof($this->server->ip_addresses)) {
      // Use the first IP address for all standard virtual hosts.
      $data['ip_address'] = $this->server->ip_addresses[0];
    }
    else {
      // If no external ip addresses are defined, we fall back on *:port
      // There will be no SSL , so that's fine.
      $data['ip_address'] = '*';
    }
82

83 84
    // TODO: move away from drush_get_context entirely.
    if ($config == 'site') {
85 86 87 88

      // DO not create it with the port here. Protocol only is enough.
      $data['redirect_url'] = "http://{$this->context->uri}";

89
      $data = array_merge($data, drush_get_context('site'));
90 91 92 93
    }

    return $data;
  }
drumm's avatar
drumm committed
94

95 96
  function init_server() {
    parent::init_server();
97
    // System account
98
    if ($this->server->name == '@server_master') {
99 100 101
      $this->server->setProperty('web_group', _provision_default_web_group());
    }
    else {
102
      $this->server->web_group = d('@server_master')->web_group;
103
    }
104

105

106
    // Redirection urls
107 108
    $this->server->web_disable_url = rtrim($this->server->master_url, '/') .'/hosting/disabled';
    $this->server->web_maintenance_url = rtrim($this->server->master_url, '/') .'/hosting/maintenance';
109

110

111 112
    if (!is_null($this->application_name)) {
      $app_dir = "{$this->server->config_path}/{$this->application_name}";
113 114
      $this->server->http_pred_path = "{$app_dir}/pre.d";
      $this->server->http_postd_path = "{$app_dir}/post.d";
115 116
      $this->server->http_platformd_path = "{$app_dir}/platform.d";
      $this->server->http_vhostd_path = "{$app_dir}/vhost.d";
117
      $this->server->http_platforms_path = "{$this->server->aegir_root}/platforms";
118
    }
119 120
  }

121

122 123
  static function option_documentation() {
    return array(
124
      '--web_group' => 'server with http: OS group for permissions; working default will be attempted',
125
      '--web_disable_url' => 'server with http: URL disabled sites are redirected to; default {master_url}/hosting/disabled',
126
      '--web_maintenance_url' => 'server with http: URL maintenance sites are redirected to; default {master_url}/hosting/maintenance',
127 128 129 130
    );
  }


131 132
  function verify_server_cmd() {
    if (!is_null($this->application_name)) {
133 134 135 136
      provision_file()->create_dir($this->server->http_pred_path, dt("Webserver custom pre-configuration"), 0700);
      $this->sync($this->server->http_pred_path);
      provision_file()->create_dir($this->server->http_postd_path, dt("Webserver custom post-configuration"), 0700);
      $this->sync($this->server->http_postd_path);
137

138 139 140 141
      provision_file()->create_dir($this->server->http_platformd_path, dt("Webserver platform configuration"), 0700);
      $this->sync($this->server->http_platformd_path, array(
        'exclude' => $this->server->http_platformd_path . '/*',  // Make sure remote directory is created
      )); 
142

143 144 145
      provision_file()->create_dir($this->server->http_vhostd_path , dt("Webserver virtual host configuration"), 0700);
      $this->sync($this->server->http_vhostd_path, array(
        'exclude' => $this->server->http_vhostd_path . '/*',  // Make sure remote directory is created
146 147
      ));

anarcat's avatar
anarcat committed
148
      provision_file()->create_dir($this->server->http_platforms_path, dt("Platforms"), 0755);
149 150 151
      $this->sync($this->server->http_platforms_path, array(
        'exclude' => $this->server->http_platforms_path . '/*',  // Make sure remote directory is created
      ));
152
    } 
153

154
    parent::verify_server_cmd();
155 156
  }

157 158 159
  /**
   * Ask the web server to check for and load configuration changes.
   */
160
  function parse_configs() {
161
    return TRUE;
162 163
  }

164 165 166 167 168 169
  /**
   * Return a list of servers that will need database access.
   */
  function grant_server_list() {
    return array(
      $this->server,
170
      $this->context->platform->server,
171 172
    );
  }
173
}
174 175 176 177


include_once('http.config.inc');
include_once('http.ssl.inc');