public.php 4.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
<?php

// Public http service , as in non-encrypted and listening on a port.
class Provision_Service_http_public extends Provision_Service_http {
  protected $has_port = TRUE;
   
  function default_port() {
    return 80;
  }

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

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

    // We assign this generic catch all for standard http.
    // The SSL based services will override this with the
    // correct ip address.
    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'] = '*';
    }

    // TODO: move away from drush_get_context entirely.
    if ($config == 'site') {

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

      $data = array_merge($data, drush_get_context('site'));
    }

    return $data;
  }

  function init_server() {
    parent::init_server();
    // System account
    if ($this->server->name == '@server_master') {
      $this->server->setProperty('web_group', _provision_default_web_group());
    }
    else {
      $this->server->web_group = d('@server_master')->web_group;
    }


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


    if (!is_null($this->application_name)) {
      $app_dir = "{$this->server->config_path}/{$this->application_name}";
      $this->server->http_pred_path = "{$app_dir}/pre.d";
      $this->server->http_postd_path = "{$app_dir}/post.d";
      $this->server->http_platformd_path = "{$app_dir}/platform.d";
      $this->server->http_vhostd_path = "{$app_dir}/vhost.d";
      $this->server->http_platforms_path = "{$this->server->aegir_root}/platforms";
    }
  }


  static function option_documentation() {
    return array(
76 77 78
      'web_group' => 'server with http: OS group for permissions; working default will be attempted',
      'web_disable_url' => 'server with http: URL disabled sites are redirected to; default {master_url}/hosting/disabled',
      'web_maintenance_url' => 'server with http: URL maintenance sites are redirected to; default {master_url}/hosting/maintenance',
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    );
  }


  function verify_server_cmd() {
    if (!is_null($this->application_name)) {
      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);

      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
      )); 

      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
      ));
    } 

    parent::verify_server_cmd();
  }

  /**
   * Ask the web server to check for and load configuration changes.
   */
  function parse_configs() {
    return TRUE;
  }

  /**
   * Return a list of servers that will need database access.
   */
  function grant_server_list() {
    return array(
      $this->server,
      $this->context->platform->server,
    );
  }
}