Commit d6ef6b71 authored by Adrian Rossouw's avatar Adrian Rossouw

Committed drumm's cleanup patch that takes care of permission checks inside...

Committed drumm's cleanup patch that takes care of permission checks inside the config writing code,
and some other fixes to get install etc. working again
parent faba286a
......@@ -212,7 +212,7 @@ class provisionService_db extends provisionService {
// todo - SORT THIS SHIT OUT!
function dump_site_database($url) {
return $this->dump_database($url);
return $this->generate_dump($url);
}
......
......@@ -14,6 +14,6 @@ function drush_db_provision_delete_validate($url = null) {
*/
function drush_db_provision_delete($url = NULL) {
if (PROVISION_CONTEXT_SITE) {
provision_service('db')->destroy_site_db($url);
provision_service('db')->destroy_site_database($url);
}
}
......@@ -379,6 +379,29 @@ class provisionService_file extends provisionService {
return $exists;
}
/**
* Write $data to $path.
*
* Sets @path token for ->succeed and ->fail.
*
* @param $path
* The path you want to perform this operation on.
* @param $data
* The data to write.
* @param $flags
* The file_put_contents() flags to use.
*
* @see file_put_contents()
*/
function file_put_contents($path, $data, $flags) {
$this->_clear_state();
$this->tokens = array('@path' => $path);
$this->last_status = file_put_contents($path, $data, $flags) !== FALSE;
return $this;
}
/**
* Walk the given tree recursively (depth first), calling a function on each file
*
......
......@@ -87,7 +87,7 @@ function drush_provision_drupal_provision_deploy($url) {
function drush_provision_drupal_post_provision_deploy($url) {
provision_prepare_environment();
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
provision_save_site_data($url);
// call the drush updatedb command.
drush_backend_invoke("updatedb", array('uri' => "http://$url"));
......
......@@ -40,7 +40,7 @@ function drush_provision_drupal_pre_provision_install($url) {
function drush_provision_drupal_provision_install($url) {
// Requires at least the database settings to complete.
provision_prepare_environment();
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
drush_include_engine('drupal', 'install');
......@@ -69,8 +69,6 @@ function drush_provision_drupal_provision_install_rollback($url) {
function drush_provision_drupal_post_provision_install($url) {
drush_set_option('aliases', drush_get_option('aliases'), 'site');
drush_set_option('installed', TRUE, 'site');
provision_service('file')->chmod('./sites/' . $url . '/settings.php', 0440)
->succeed('Secured settings.php with safe permissions');
_provision_drupal_rebuild_caches($url);
drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
}
......
......@@ -36,7 +36,7 @@ function drush_provision_drupal_pre_provision_migrate($url, $platform = null) {
*/
drush_log(dt("Putting site under maintenance"));
drush_set_option('site_offline', 1);
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
drush_invoke('provision-backup', $url);
}
......@@ -48,7 +48,7 @@ function drush_provision_drupal_pre_provision_migrate_rollback($url, $platform =
// Set site_offline to false and regenerate the config
drush_log(dt("Bringing site out of maintenance"));
drush_set_option('site_offline', 0);
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
$success = provision_service('file')->unlink(drush_get_option('backup_file'))
->succeed('Removed unused migration site package')
->fail('Could not remove unused migration site package');
......
......@@ -89,7 +89,27 @@ function provision_drupal_drush_exit($url = NULL) {
else {
// Generate a drushrc.php for the platform unless it's being deleted
if (!preg_match("/^provision-delete/", $command[0])) {
_provision_generate_config();
$exists = provision_service('file')->exists(drush_get_option('docroot_path') . '/drushrc.php')
->succeed('Found existing drushrc.php file')
->fail('Generating drushrc.php file')
->status();
if ($exists) {
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0600)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
}
drush_set_option('context-path', drush_get_option('context-path', null, 'drupal'));
drush_unset_option('context-path', 'drupal');
drush_set_option('config-file', drush_get_option('config-file', null, 'drupal'));
drush_unset_option('config-file', 'drupal');
drush_save_config('drupal');
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0400)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
}
}
}
......@@ -172,29 +192,15 @@ function _provision_drupal_site_installed($url) {
* A reference to the associated array containing the data for the site. This needs to be a reference,
* because the modules might provide additional information about the site.
*/
function _provision_drupal_create_settings_file($url = NULL) {
if (provision_service('file')->exists('sites/' . $url . '/settings.php')->status()) {
provision_service('file')->chmod('sites/' . $url . '/settings.php', 0640)
->succeed('Changed permissions of settings.php to @perm')
->fail('Could not change permissions of settings.php to @perm');
}
function _provision_drupal_create_settings_file() {
$config = new provisionConfig_drupal_settings(drush_get_merged_options());
$config->write();
# Change the permissions of the file
provision_service('file')->chmod('sites/' . $url . '/settings.php', 0440)
->succeed('Changed permissions of settings.php to @perm')
->fail('Could not change permissions of settings.php to @perm');
provision_service('file')->chgrp('sites/' . $url . '/settings.php', drush_get_option('web_group'))
->succeed('Change group ownership of settings.php to @gid')
->fail('Could not change group ownership of settings.php to @gid');
}
class provisionConfig_drupal_settings extends provisionConfig {
public $template = 'provision_drupal_settings.tpl.php';
public $description = 'Drupal settings.php file';
protected $mode = 0440;
function filename() {
return $this->data['sites_path'] . '/' . $this->data['site_url'] . '/settings.php';
......@@ -207,6 +213,8 @@ class provisionConfig_drupal_settings extends provisionConfig {
$this->data['extra_config'] = "# Extra configuration from modules:\n";
$this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_drupal_config', $this->data['site_url'], $this->data));
$this->group = drush_get_option('web_group');
}
}
......
......@@ -63,7 +63,7 @@ function drush_provision_drupal_provision_restore($url) {
->succeed('Swapping out the @path1 and @path2 directories was successful.')
->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');
// make sure it has the latest site data available
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
provision_save_site_data($url);
}
......@@ -79,7 +79,7 @@ function drush_provision_drupal_post_provision_restore($url) {
_provision_recursive_delete(drush_get_option('sites_path') ."/$url.restore");
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories($url);
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
}
......@@ -10,7 +10,7 @@ function drush_provision_drupal_provision_verify_validate($url = null) {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
provision_prepare_environment();
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
drush_errors_on();
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
}
......@@ -49,7 +49,7 @@ function drush_provision_drupal_provision_verify($url = null) {
_provision_drupal_create_directories($url);
_provision_drupal_maintain_aliases($url);
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($url);
_provision_drupal_create_settings_file();
}
}
......
......@@ -10,7 +10,9 @@ class provisionConfig {
public $template = null;
public $data = array();
public $description = null;
protected $mode = 'w';
protected $append = FALSE;
protected $mode = NULL;
protected $group = NULL;
function __construct($data = array()) {
if (is_null($this->template)) {
......@@ -57,7 +59,6 @@ class provisionConfig {
return $contents; // Return the contents
}
function write() {
$filename = $this->filename();
if ($filename && is_writeable(dirname($filename))) {
......@@ -65,13 +66,26 @@ class provisionConfig {
$this->process();
if ($template = $this->load_template()) {
#todo - convert to file_service
$file = fopen($filename, $this->mode);
$text = $this->render_template($template, $this->data);
fwrite($file, $text);
fclose($file);
if ($this->description) {
drush_log("Generated config : " . $this->description, 'success');
// Make sure we can write to the file
if (!is_null($this->mode) && !($this->mode & 0200) && provision_service('file')->exists($filename)->status()) {
provision_service('file')->chmod($filename, $this->mode | 0200)
->succeed('Changed permissions of @path to @perm')
->fail('Could not change permissions of @path to @perm');
}
provision_service('file')->file_put_contents($filename, $this->render_template($template, $this->data), $this->append ? FILE_APPEND : 0)
->succeed('Generated config ' . (empty($this->description) ? $filename : $this->description), 'success');
// Change the permissions of the file if needed
if (!is_null($this->mode)) {
provision_service('file')->chmod($filename, $this->mode)
->succeed('Changed permissions of @path to @perm')
->fail('Could not change permissions of @path to @perm');
}
if (!is_null($this->group)) {
provision_service('file')->chgrp($filename, $this->group)
->succeed('Change group ownership of @path to @gid')
->fail('Could not change group ownership of @path to @gid');
}
}
}
......
......@@ -197,29 +197,6 @@ function drush_provision_hostmaster_make($platform) {
drush_backend_invoke('make', array(dirname(__FILE__) . '/aegir.make', $platform));
}
/**
* Generate a provision.settings.php file to configure provision
*/
function _provision_generate_config() {
$exists = provision_service('file')->exists(drush_get_option('docroot_path') . '/drushrc.php')->status();
if ($exists) {
drush_log(dt("Found existing drushrc.php file"));
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0600)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
}
else {
drush_log(dt("Generating drushrc.php file"));
}
provision_save_platform_data();
provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0400)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
return TRUE;
}
function _provision_default_restart_cmd() {
$command = '/usr/sbin/apachectl'; # a proper default for most of the world
foreach (explode(':', $_SERVER['PATH']) as $path) {
......
......@@ -87,29 +87,26 @@ function provision_save_site_data() {
drush_set_option('config-file', drush_get_option('config-file', null, 'site'));
drush_unset_option('config-file', 'site');
drush_save_config($context);
drush_set_option('config-file', _drush_config_file('site'));
if (!drush_get_error()) {
$config = new provisionConfig_drushrc(drush_get_merged_options());
$config->write();
}
provision_service('file')->chmod(_drush_config_file($context), 0600)
->succeed('Changed permissions of drushrc.php to @perm')
->fail('Could not change permissions of drushrc.php to @perm');
}
class provisionConfig_drushrc extends provisionConfig {
public $template = 'provision_drushrc.tpl.php';
public $description = 'Drush configuration file';
protected $append = TRUE;
protected $mode = 0600;
function filename() {
return $this->data['config-file'];
}
function process() {
$this->mode = 'a+';
}
}
......@@ -117,25 +114,6 @@ class provisionConfig_drushrc extends provisionConfig {
* @} End of "defgroup sitedata".
*/
/**
* Save the options for the platform to the drushrc.php in the root of
* the platform.
*
* @return
* Boolean. The value returned by drush_save_config().
*/
function provision_save_platform_data() {
drush_set_option('context-path', drush_get_option('context-path', null, 'drupal'));
drush_unset_option('context-path', 'drupal');
drush_set_option('config-file', drush_get_option('config-file', null, 'drupal'));
drush_unset_option('config-file', 'drupal');
return drush_save_config('drupal');
}
/**
* Remove files or directories, recursively
*
......
# Aegir additions
<?php foreach (array('db_type', 'db_host', 'db_user', 'db_passwd', 'db_name') as $key) { ?>
$_SERVER['<?php print $key; ?>'] = $options['<?php print $key; ?>'];
<?php } ?>
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