http.config.inc 3.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
 // $Id$

/**
 * @file
 *    Configuration classes for the HTTP service.
 */


/**
 * Base class for HTTP config files.
 *
 * This class will publish the config files to remote
 * servers automatically.
 */
16
class provisionConfig_http extends Provision_Config {
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
  function write() {
    parent::write();
    $this->data['server']->sync($this->filename());
  }

  function unlink() {
    parent::unlink();
    $this->data['server']->sync($this->filename());
  }
}

/**
 * Base configuration class for server level http configs.
 *
 * This class uses the service defined application_name, to generate
 * a top level $app_name.conf for the service.
 *
 * Each server has it's own configuration, and this class will
 * automatically generate a symlink to the correct file for each
 * server.
 */
class provisionConfig_http_server extends provisionConfig_http {
  public $template = 'server.tpl.php';
  public $description = 'web server configuration file';

  function write() {
    parent::write();

    if (isset($this->data['application_name'])) {
      $file = $this->data['application_name'] . '.conf';
      // We link the app_name.conf file on the remote server to the right version.
      $cmd = sprintf('ln -sf %s %s', 
        escapeshellarg($this->data['server']->config_path . '/' . $file), 
        escapeshellarg($this->data['server']->aegir_root . '/config/' . $file)
      );
52 53 54 55 56 57 58 59
      
      if ($this->data['server']->shell_exec($cmd)) {
        drush_log(dt("Created symlink for %file on %server", array(
          '%file' => $file,
          '%server' => $this->data['server']->remote_host,
        )));  
       
      };
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    }
  }

  function filename() {
    if (isset($this->data['application_name'])) {
      $file = $this->data['application_name'] . '.conf';
      return $this->data['server']->config_path . '/' . $file;
    }
    else {
      return FALSE;
    }
  }


}


/**
 * Base class for platform configuration files.
 */
class provisionConfig_http_platform extends provisionConfig_http {
  public $template = 'platform.tpl.php';
  public $description = 'platform configuration file';

  function filename() {
85
    return $this->data['http_platformd_path'] . '/' . ltrim($this->context->name, '@') . '.conf';
86 87 88 89 90 91 92 93 94
  }
}


/**
 * Base class for virtual host configuration files.
 */
class provisionConfig_http_site extends provisionConfig_http {
  public $template = 'vhost.tpl.php';
95 96
  // The template file to use when the site has been disabled.
  public $disabled_template = 'vhost_disabled.tpl.php';
97 98 99 100 101 102 103
  public $description = 'virtual host configuration file';


  function filename() {
    return $this->data['http_vhostd_path'] . '/' . $this->uri;
  }

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  function write() {
    parent::write();

    // We also leave a record of this IP in the site's drushrc.php
    // This way we can pass the info back to the front end.
    $ip_addresses = drush_get_option('site_ip_addresses', array(), 'site');

    if ($this->data['ip_address'] != '*') {
      $ip_addresses[$this->data['server']->name] = $this->data['ip_address'];
    }
    elseif (isset($context['site_ip_addresses'][$this->data['server']->name])) {
      unset($ip_addresses[$this->data['server']->name]);
    }
    drush_set_option('site_ip_addresses', $ip_addresses, 'site');
  }

  function unlink() {
    parent::unlink();

    // We also remove the record of this IP in the site's drushrc.php
    // This way we can pass the info back to the front end.
    $ip_addresses = drush_get_option('site_ip_addresses', array(), 'site');
    unset($ip_addresses[$this->data['server']->name]);
    drush_set_option('site_ip_addresses', $ip_addresses, 'site');
  }

130 131 132 133 134 135 136
  function process() {
    parent::process();

    if ($this->aliases && !is_array($this->aliases)) {
      $this->aliases = explode(",", $this->aliases);
    }

137 138
    $this->aliases = array_filter($this->aliases, 'trim');

139
    if (!$this->site_enabled) {
140
      $this->template = $this->disabled_template;
141 142 143 144
    }

  }
}