Commit 83d20ee4 authored by Adrian Rossouw's avatar Adrian Rossouw

this is a test of http server stuff. don't expect anything useful to come out of this

parent 304c5b5e
......@@ -3,14 +3,42 @@
class provisionService_http_apache extends provisionService {
function templates() {
$this->configs['vhost'] = 'vhost.tpl.php';
$this->configs['vhost_redirect'] = 'vhost_redirect.tpl.php';
$this->configs['vhost_disabled'] = 'vhost_disabled.tpl.php';
$this->configs['platform'] = 'platform.tpl.php';
$this->configs['server'] = 'server.tpl.php';
$this->templates['vhost'] = 'vhost.tpl.php';
$this->templates['vhost_disabled'] = 'vhost_disabled.tpl.php';
$this->templates['platform'] = 'platform.tpl.php';
$this->templates['server'] = 'server.tpl.php';
}
function create_site_config($url) {
$file = drush_get_option('vhost_path') . '/' . $url . '_' . drush_get_option('site_port');
drush_log(dt("Generating apache host configuration file %file.", array('%file' => basename($file))));
return $this->write_config($file, 'vhost', drush_get_merged_options());
}
function delete_site_config($url) {
$file = drush_get_option('vhost_path') . '/' . $url . '_' . drush_get_option('site_port');
provision_path("unlink", $file, TRUE, dt("Removed apache virtual host configuration"));
}
function create_platform_config() {
$file = drush_get_option('platform_conf_path') . '/platform_' . drush_get_option('platform') . '.conf';
drush_log(dt("Generating apache host configuration file %file.", array('%file' => basename($file))));
return $this->write_config($file, 'platform', drush_get_merged_options());
}
function delete_site_config($url) {
$file = drush_get_option('platform_conf_path') . '/platform_' . drush_get_option('platform');
provision_path("unlink", $file, TRUE, dt("Removed apache platform configuration"));
}
function create_server_config() {
$file = drush_get_option('conf_path') . '/apache.conf';
drush_log(dt("Generating apache host configuration file %file.", array('%file' => basename($file))));
return $this->write_config($file, 'server', drush_get_merged_options());
}
function verify($url) {
if (PROVISION_CONTEXT_PLATFORM) {
......@@ -52,4 +80,7 @@ class provisionService_http_apache extends provisionService {
function delete_server_config() {
}
}
......@@ -3,46 +3,98 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function http_drush_init() {
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
// Set up defines for platform
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
$path = drush_set_default('docroot_path', rtrim(($docroot) ? $docroot : $_SERVER['DOCUMENT_ROOT'], '/'));
drush_set_default('sites_path', $path . '/sites');
drush_set_default('publish_path', realpath(drush_get_option('docroot_path')));
$parts = explode("/", $path);
array_pop($parts);
$parent_path = drush_set_default('parent_path', implode("/" , $parts));
drush_set_default('backup_path', $parent_path . '/backups');
drush_set_default('config_path', $parent_path . '/config');
$config_path = drush_get_option('config_path');
drush_set_default('vhost_path', $config_path . '/vhost.d');
drush_set_default('platform_conf_path', $config_path . '/platform.d');
// Commands
drush_set_default('restart_cmd', _provision_default_restart_cmd());
// System account
drush_set_default('web_group', _provision_default_web_group());
drush_set_default('script_user', get_current_user());
// Redirection urls
drush_set_default('master_url', $GLOBALS['base_url']);
$master_url = drush_get_option('master_url');
drush_set_default('web_disable_url', $master_url .'/hosting/disabled');
drush_set_default('web_maintenence_url', $master_url .'/hosting/maintenance');
drush_set_default('web_ip', '127.0.0.1');
drush_set_default('web_port', 80);
drush_set_default('site_port', 80);
}
}
class provisionService_http extends provisionService {
/**
* Ask the web server to check for and load configuration changes.
*/
function parse_configs() {
return TRUE
}
/**
* Generate a site specific configuration file
*/
function create_site_config($url) {
return TRUE;
}
/**
* Remove an existing site configuration file.
*/
function delete_site_config($url) {
return TRUE;
}
/**
* Add a new platform specific configuration file.
*/
function create_platform_config($url) {
return TRUE;
}
/**
* Remove an existing platform configuration file.
*/
function delete_platform_config() {
return TRUE;
}
/**
* Create a new server specific configuration file.
*/
function create_server_config() {
return TRUE;
}
/**
* Remove an existing server specific configuration file
*/
function delete_server_config() {
return TRUE;
}
}
<?php
class provisionService {
protected $configs = array();
protected $templates = array();
function verify() {
return TRUE;
}
function templates() {
$this->configs = array();
$this->templates = array();
}
function render_config($template, $variables) {
drush_errors_off();
extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
ob_start(); // Start output buffering
eval('?>'. $template); // Generate content
$contents = ob_get_contents(); // Get the contents of the buffer
ob_end_clean(); // End buffering and discard
drush_errors_on();
return $contents; // Return the contents
}
function write_config($file, $key, $extra_data = array()) {
$data = drush_get_merged_options();
if (is_writeable($file)) {
if ($template = $this->load_template($key)) {
$file = fopen($file, "w");
$text = $this->render_config($template, $data);
fwrite($file, $text);
fclose($file);
}
}
}
}
class provisionConfig {
public $template = null;
function __construct() {
if (is_null($this->template)) {
throw(exception);
}
}
function filename() {
return false;
}
function load() {
$reflect = new reflectionObject($this);
$base_dir = $reflect->getFilename();
if (isset($this->templates[$key])) {
$file = $base_dir . '/' . $this->templates[$key];
if (file_exists($file) && is_readable($file)) {
return file_get_contents($file);
}
}
return false;
}
function render($template, $variables) {
}
function write_config($extra_data) {
}
}
class provisionService_null extends provisionService {
function __get($name) {
......
......@@ -57,33 +57,6 @@ function provision_apache_drush_init() {
}
}
/**
* The default template provided for the virtual host configuration
*/
function _provision_apache_default_template() {
return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost.tpl.php");
}
/**
* The template for site redirection
*/
function _provision_apache_redirect_template() {
return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost_redirect.tpl.php");
}
/**
* The default template for disabled sites
*/
function _provision_apache_disabled_template() {
return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost_disabled.tpl.php");
}
/**
* The template for platform configuration settings
*/
function _provision_apache_platform_template() {
return file_get_contents(dirname(__FILE__) ."/provision_apache_platform.tpl.php");
}
/**
* Delete virtual host file
......@@ -233,14 +206,7 @@ function _provision_apache_create_server_config($url) {
}
}
/**
* default template for server-wide configurations
*
* @see _provision_apache_create_server_config()
*/
function _provision_apache_default_server_template() {
return file_get_contents(dirname(__FILE__) ."/provision_apache_server.tpl.php");
}
function _provision_apache_delete_platform_config($file) {
provision_path("unlink", drush_get_option('platform_conf_path') ."/" . $file, TRUE, dt("Removed apache platform vhost configuration"));
......
<Directory <?php print $publish_path; ?>>
Order allow,deny
Allow from all
<?php print $extra_config; ?>
</Directory>
# Aegir web server configuration file
<?php if (is_array($web_ports)) :
foreach ($web_ports as $web_port) :?>
NameVirtualHost *:<?php print $web_port; ?>
<VirtualHost *:<?php print $web_port; ?>>
ServerName default
Redirect 404 /
</VirtualHost>
<?php
endforeach;
endif;
?>
<IfModule !env_module>
LoadModule env_module modules/mod_env.so
</IfModule>
<IfModule !rewrite_module>
LoadModule rewrite_module modules/mod_rewrite.so
</IfModule>
Include <?php print $config_path ?>/vhost.d/
Include <?php print $config_path ?>/platform.d/
<?php print $extra_config; ?>
<VirtualHost *:<?php print $site_port; ?>>
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
ServerName <?php print $site_url; ?>
SetEnv db_type <?php print urlencode($db_type); ?>
SetEnv db_name <?php print urlencode($db_name); ?>
SetEnv db_user <?php print urlencode($db_user); ?>
SetEnv db_passwd <?php print urlencode($db_passwd); ?>
SetEnv db_host <?php print urlencode($db_host); ?>
<?php if (!$redirection && is_array($aliases)) :
foreach ($aliases as $alias_url) :
if (trim($alias_url)) : ?>
ServerAlias <?php print $alias_url; ?>
<?php
endif;
endforeach;
endif; ?>
<?php print $extra_config; ?>
# Error handler for Drupal > 4.6.7
<Directory "<?php print $publish_path; ?>/sites/<?php print trim($site_url, '/'); ?>/files">
SetHandler This_is_a_Drupal_security_line_do_not_remove
</Directory>
# @todo make this configurable and more intelligent
# php_admin_value open_basedir /tmp:<?php print rtrim($publish_path, '/') ?>/:<?php print rtrim($config_path, '/') ?>/includes/:/usr/share/php/
</VirtualHost>
<VirtualHost *:80>
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
DocumentRoot <?php print $publish_path; ?>
ServerName <?php print $site_url; ?>
<?php if (is_array($aliases)) :
foreach ($aliases as $alias) : ?>
ServerAlias <?php print $alias; ?>
<?php
endforeach;
endif; ?>
RewriteEngine on
# the ? at the end is to remove any query string in the original url
RewriteRule ^(.*)$ <?php print $redirect_url . '/' . $site_url ?>?
</VirtualHost>
<VirtualHost *:<?php print $site_port; ?>>
<?php if ($site_mail) : ?>
ServerAdmin <?php print $site_mail; ?>
<?php endif;?>
<?php if (is_array($aliases) && count($aliases)): ?>
ServerName <?php print array_pop($aliases); ?>
<?php if (count($aliases)): ?>
ServerAlias <?php print join(" ", $aliases); ?>
<?php endif; ?>
<?php else:
# this should never happen and has the potential of creating an infinite redirection loop
?>
ServerName <?php print $site_url ?>
<?php endif; ?>
<?php if ($ssl_redirect): ?>
RedirectMatch permanent ^(.*) https://<?php print $site_url ?>$1
<?php else: ?>
RedirectMatch permanent ^(.*) http://<?php print $site_url ?>$1
<?php endif; ?>
</VirtualHost>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment