Commit 11d12e65 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

More work towards restore functionality. Moved the mysql utility functions to...

More work towards restore functionality. Moved the mysql utility functions to provision_mysql.inc, and the help stuff to it's own include too.

Made more constants to replace the various helper functions, still need to document them.

Replaced all references to db_username with db_user, which is consistent with everywhere else in the system.
parent 3872c8a5
This diff is collapsed.
......@@ -128,7 +128,7 @@ function _provision_drupal_create_settings_file($url, &$data) {
# Change the permissions of the file
provision_path("chmod", "sites/$url/settings.php", 0550);
provision_path("chgrp", "sites/$url/settings.php", provision_get_group_name());
provision_path("chgrp", "sites/$url/settings.php", PROVISION_WEB_GROUP);
}
/**
......@@ -154,11 +154,11 @@ function _provision_drupal_create_directories($url, $profile = null) {
t("Could not create <code>@path</code>"),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
}
provision_path("chown", $path, provision_get_script_owner(),
provision_path("chown", $path, PROVISION_SCRIPT_USER,
t("Changed ownership of <code>@path</code>"),
t("Could not change ownership <code>@path</code>"),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
provision_path("chgrp", $path, provision_get_group_name(),
provision_path("chgrp", $path, PROVISION_WEB_GROUP,
t("Changed group ownership of <code>@path</code>"),
t("Could not change group ownership <code>@path</code>"));
......
$db_url = '<?php print "$site_db_type://$site_db_username:$site_db_passwd@$site_db_host/$site_db_name"; ?>';
$db_url = '<?php print "$site_db_type://$site_db_user:$site_db_passwd@$site_db_host/$site_db_name"; ?>';
$profile = "<?php print $site_profile ?>";
# Additional host wide configuration settings. Useful for safely specifying configuration settings.
......
<?php
/**
* @file ProvisionHelp contains the bulk of the provision help system
*/
/**
* Implementation of hook_help()
*/
function provision_help($section) {
switch ($section) {
case 'admin/help#provision':
$output .= t('<p>The Provision framework is a powerful set of modules that lets you to accomplish a lot of maintenance tasks through the unix command line such as installing new sites, backing them up, rolling back to previous backups and facilitating upgrades.</p>');
$output .= t('<p>Additionally, the Provision framework is one component of the distributed hosting infrastructure provided by the <code>hostmaster</code> install profile.
The Hostmaster profile is capable of driving several provision backends, in a distributed manner, and provides an interface for the functionality of provision.</p>');
$output .= t('<p>It is not required to run the hosting front end to use the Provision framework, but the system does not provide much in the way of a web accessible front end, by design.</p>');
$output .= '<a name=\'requirements\'><h3>' . t('Requirements') . '</h3></a>';
$output .= t('<p>For a more detailed breakdown of steps that need to be taken to configure Provisioning to run with your system, please read the <a href="@url">in depth requirement documentation</a></p>',
array('@url' => url('admin/help/provision/requirements')));
$output .= '<a name=\'commands\'><h3>' . t('Commands') . '</h3></a>';
$commands = module_invoke_all('drush_command');
$output .= "<dl>";
foreach ($commands as $command => $info) {
if (preg_match('/^provision/', $command)) {
if (sizeof($info['arguments'])) {
$command .= ' ' . implode(' ', (array) key($info['arguments']));
}
if (sizeof($info['optional arguments'])) {
$command .= ' [' . implode('] [', (array) key($info['optional arguments'])) . ']';
}
$output .= '<dt>' . "<code>drush.php $command</code>" . '</dt>';
$output .= '<dd>' . $info["description"] . '</dd>';
}
}
$output .= "</dl>";
$output .= '<a name=\'options\'><h3>' . t('Options') . '</h3></a>';
$options = module_invoke_all('value_list');
$output .= "<dl>";
foreach ($options as $option => $description) {
$output .= '<dt>' . "<code>--$option</code>" . '</dt>';
$output .= '<dd>' . $description . '</dd>';
}
$output .= "</dl>";
return $output;
case 'admin/help/provision#requirements' :
$username = PROVISION_SCRIPT_USER;
$group = PROVISION_WEB_GROUP;
$backup_path = PROVISION_BACKUP_PATH;
$mkdir_cmd['@backup_path'] = $backup_path;
$mkdir_cmd['@provision_link'] = url('admin/settings/provision');
$mkdir_cmd['@mkdir_cmd'] = <<<EOF
[$username@hm2 ~]$ mkdir $backup_path
[$username@hm2 ~]$ chown $username:$username $backup_path
[$username@hm2 ~]$ chmod 0700 $backup_path
EOF;
$output .= "<ol>";
$output .= '<li>' . t('<p><strong>The user account running the script, and the group of the httpd daemon.</strong>
The provision framework takes special care to make sure that the file permissions of the
hosted sites are always as safe as can be, especially to make sure that the web server does
not have the ability to modify the code of the site, therefor this information is required
to assure that safety while keeping the sites accessible.</p>
<p>Based on your server configuration we have determined that you should set the
username to "<code>@username</code>" and the group to "<code>@group</code>",
but you can change these in the <a href="@provision_link">provisioning section</a>.</p>', array("@username" => $username, "@group" => $group, "@provision_link" => url('admin/settings/provision'))) . '</li>';
$output .= '<li>' . t('<p><strong>Write access to a directory to store backups.</strong>
The drush user needs to be able to maintain the backups repository to ensure that your site is backed up successfully.
It is incredibly important that this path is not accessible via the web server, so that no undesirables can get their
hands on your database. The recommended path is directly above your platform path, but it can be anywhere.</p>
<p>Based on your server configuration we have determined that your path should be <code>@backup_path</code>,
but you can change this in the <a href="@provision_link">provisioning section</a>.</p>
<strong>To configure: </strong> Please enter the following commands :
<pre>@mkdir_cmd</pre>',$mkdir_cmd) . '</li>';
$output .= "</ol>";
return $output;
}
}
/**
* Page callback with in depth requirement documentation
*/
function provision_help_requirements() {
$output .= t('<p>Unfortunately, due to the requirements of some of the functionality, significantly more access than is usually allowed on a shared hosting solution is required,
and as such, a virtual server or dedicated hosting system will be required to run this system.</p>');
$output .= t('<p>Some of the features of the system also require the ability to create symlinks, which means that it needs to run on a unix-like operating system. There are no plans currently to add windows support.</p>');
$modules = module_implements('provision_service');
foreach ($modules as $module) {
$service = module_invoke($module, 'provision_service');
$name = current($service);
$help = module_invoke($module, 'help', 'admin/help/provision#requirements');
if ($name && $help) {
$output .= '<a href="requirements-$module"></a><h3>' . t($name) . '</h3>';
$output .= $help;
}
}
return $output;
}
......@@ -316,13 +316,12 @@ function provision_save_site_data($url, $data) {
provision_set_error(PROVISION_PERM_ERROR);
}
else {
fwrite($fp, "\n\n#" . format_date(mktime(), "large"));
if ($data['action_id']) {
$action = array('id' => $data['action_id'],
'timestamp' => mktime(),
'action' => $data['site_action_type'],
'status' => provision_get_error());
$line = "\n\$actions[] = " . str_replace(array(" ", "\n"), "", var_export($action, TRUE)) . ";";
$timestamp = mktime();
$aid = $data['action_id'];
fwrite($fp, "\n\n#" . format_date($timestamp, "large"));
if ($aid) {
$action = array('action' => $data['site_action_type'], 'status' => provision_get_error());
$line = "\n\$actions[$aid][$timestamp] = " . str_replace(array(" ", "\n"), "", var_export($action, TRUE)) . ";";
fwrite($fp, $line);
}
foreach ($data as $key => $value) {
......@@ -385,31 +384,6 @@ function provision_render_config($template, $variables) {
* @} End of "defgroup provisionvalues".
*/
/**
* Provide defines for all the major paths.
* Avoids duplication and possible errors in duplication
*/
function provision_init_paths() {
if (function_exists('drush_get_option')) {
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
}
else {
$docroot = $_SERVER['pwd'];
}
$path = ($docroot) ? $docroot : $_SERVER['DOCUMENT_ROOT'];
define('PROVISION_DOCROOT_PATH', rtrim($path, '/'));
define('PROVISION_SITES_PATH', rtrim($path, '/'));
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
define('PROVISION_BACKUP_PATH', rtrim(variable_get('provision_backup_path', implode("/" , $parts) . '/backups'), '/'));
define('PROVISION_CONFIG_PATH', rtrim(variable_get('provision_config_path', implode("/" , $parts) . '/config'), '/')) ;
define('PROVISION_VHOST_PATH', PROVISION_CONFIG_PATH . '/vhost.d');
define('PROVISION_DRUSHRC_PATH', PROVISION_CONFIG_PATH . '/drushrc.d');
}
/**
* Remove files or directories, recursively
......@@ -487,26 +461,6 @@ function provision_set_active_db($new_db_url = null) {
db_set_active('default');
}
}
/**
* Return the user who owns this script.
*
* Used to generate permissions. Can be overridden by variable_set().
*/
function provision_get_script_owner() {
return variable_get('provision_script_user', get_current_user());
}
/**
* Return the group who runs the httpd daemin.
*
* Used to generate permissions. Can be overridden by variable_set().
*/
function provision_get_group_name() {
$info = posix_getgrgid(posix_getgid());
return variable_get('provision_web_group', $info['name']);
}
/**
* Check whether a user is a member of a group.
*
......
This diff is collapsed.
......@@ -172,15 +172,14 @@ function provision_path_chown($path, &$owner, &$reason) {
}
function provision_path_chgrp($path, &$group, &$reason) {
$user = provision_get_script_owner();
if ($group = provision_posix_groupname($group)) {
if (provision_user_in_group($user, $group)) {
if (provision_user_in_group(PROVISION_SCRIPT_USER, $group)) {
if (chgrp($path, $group)) {
$reason = t("chgrp failed");
}
}
else {
$reason = t("@user is not in @group group", array("@user" => $user, "@group" => $group));
$reason = t("@user is not in @group group", array("@user" => PROVISION_SCRIPT_USER, "@group" => $group));
}
}
else {
......
......@@ -20,8 +20,8 @@ function provision_apache_provision_service() {
function provision_apache_help($section) {
switch ($section) {
case 'admin/help/provision#requirements':
$username = provision_get_script_owner();
$group = provision_get_group_name();
$username = PROVISION_SCRIPT_USER;
$group = PROVISION_WEB_GROUP;
$vhost_path = PROVISION_VHOST_PATH;
$mkdir_cmd['@vhost_path'] = $vhost_path;
$mkdir_cmd['@provision_link'] = url('admin/settings/provision');
......@@ -98,7 +98,7 @@ function provision_apache_provision_configure($node = null) {
'#title' => t('System account'),
'#required' => TRUE,
'#description' => t('The system account that the hosted files will belong to, for security reasons.<br />This should be a different to the account the web server is running as.'),
'#default_value' => ($node->script_user) ? $node->script_user : provision_get_script_owner(),
'#default_value' => ($node->script_user) ? $node->script_user : PROVISION_SCRIPT_USER,
'#size' => 20,
'#maxlength' => 255,
);
......@@ -108,7 +108,7 @@ function provision_apache_provision_configure($node = null) {
'#title' => t('Web server group'),
'#required' => TRUE,
'#description' => t('The group that the hosted files will belong to.<br />This should be the group the web server is running as.'),
'#default_value' => ($node->web_group) ? $node->web_group : provision_get_group_name(),
'#default_value' => ($node->web_group) ? $node->web_group : PROVISION_WEB_GROUP,
'#size' => 20,
'#maxlength' => 75,
'#validate' => array('provision_apache_validate_web_group' => array()),
......@@ -228,9 +228,8 @@ function _provision_apache_create_vhost_config($url, $data, $template = null) {
$template = variable_get('provision_apache_vhost_template', _provision_apache_default_template());
}
provision_log("Notice", t("Generate virtual host configuration file."));
$writable = provision_path("writable", PROVISION_VHOST_PATH, true ,
t("Virtual host configuration path is writable."),
t("Virtual host configuration path is not writable."),
$writable = provision_path("writable", PROVISION_VHOST_PATH, true , '',
t("Virtual host configuration path @path is not writable."),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
if ($writable) {
$file = fopen(PROVISION_VHOST_PATH . '/' . $url, "w");
......@@ -271,7 +270,7 @@ function provision_apache_provision_verify() {
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
if (!$writable) {
provision_path("chown", PROVISION_VHOST_PATH, provision_get_script_owner(),
provision_path("chown", PROVISION_VHOST_PATH, PROVISION_SCRIPT_USER,
t("Changed ownership of <code>@path</code>"),
t("Could not change ownership <code>@path</code>"),
PROVISION_PERM_ERROR);
......
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