Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
global:
- AEGIR_HOSTING_VERSION=7.x-3.x
- AEGIR_TESTS_VERSION=master
- AEGIR_PROVISION_VERSION=7.x-3.x
- AEGIR_PROVISION_VERSION=feature/quick-review

#env:
# - test: Ubuntu 14.04 Apache
Expand Down
5 changes: 2 additions & 3 deletions alias/hosting_alias.module
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function hosting_alias_form_site_node_form_alter(&$form, &$form_state) {
function hosting_alias_site_form_validate($form, &$form_state) {
$aliases = $form_state['values']['aliases'] = array_filter($form_state['values']['aliases']);
foreach ($aliases as $key => $alias) {
hosting_alias_validate_alias($form_state['node'], $alias, $key);
hosting_alias_validate_alias($form_state['values'], $alias, $key);
}
}

Expand Down Expand Up @@ -365,8 +365,7 @@ function hosting_alias_node_revision_delete($node) {
function hosting_alias_validate_alias($site, $alias, $key) {
if ($alias = strtolower(trim($alias))) {
$alias = strtolower(trim($alias));
$params = isset($site->nid) ? array('nid' => $site->nid) : array();
if (!hosting_domain_allowed($alias, $params) || $alias == $site->title) {
if (!hosting_domain_allowed($alias, (array) $site) || $alias == $site->title) {
form_set_error("aliases][$key", t('The domain name @alias is already in use', array('@alias' => $alias)));
}
if (!_hosting_valid_fqdn_wildcard($alias)) {
Expand Down
90 changes: 89 additions & 1 deletion client/hosting_client.module
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ function hosting_client_permission() {
'edit client uname' => array(
'title' => t('edit client uname'),
),
'bypass domain owner check' => array(
'title' => t('bypass domain owner check'),
'description' => t('Allows the client to register a subdomain, even when the above domain is owned by another client.'),
),
);
}

Expand Down Expand Up @@ -634,7 +638,7 @@ function hosting_client_view($node, $view_mode, $langcode = NULL) {
$header = array(t('Allowed users'));
$node->content['users_view'] = array(
'#type' => 'item',
'#value' => theme('table', array('header' => $header, 'rows' => $rows)),
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)),
'#class' => 'client',
'#prefix' => '<div id="hosting-site-list">',
'#suffix' => '</div>',
Expand Down Expand Up @@ -991,6 +995,12 @@ function hosting_client_configure($form, &$form_state) {
'#description' => t('If this setting is on, any new client nodes will automatically have a system user account generated for them, and associated with the new client node. Users going through the signup form module have a user created regardless of this setting.'),
'#default_value' => variable_get('hosting_client_register_user', FALSE),
);
$form['hosting_client_subdomain_owner_check'] = array(
'#type' => 'checkbox',
'#title' => t('Check owner upon creating subdomains.'),
'#description' => t("As a policy a hosting_client user is not allowed to create a site on a domain or subdomain thereof that is already in use by another client. (Unles the client has the 'bypass domain owner check' permission)"),
'#default_value' => variable_get('hosting_client_subdomain_owner_check', FALSE),
);

// User e-mail settings.
$form['email'] = array(
Expand Down Expand Up @@ -1175,3 +1185,81 @@ function hosting_client_views_api() {
'path' => drupal_get_path('module', 'hosting_client') . '/includes/views',
);
}

/**
* Implements hook_allow_domain().
*
* Disallow domains already used as any site's title/url, unless the site has
* been deleted.
*
* @see hosting_domain_allowed()
*/
function hosting_client_allow_domain($url, $params = array()) {
// If we do not have to be here, leave ASAP.
if (!variable_get('hosting_client_subdomain_owner_check', FALSE) || user_access('bypass domain owner check')) {
return TRUE;
}

// Get the client node from the client name.
$client = hosting_get_client($params['client']);

// Prepare array.
$subdomains = array();

// Break up url.
$url_array = explode('.', $url);
while ($url_array) {
$subdomains[] = implode('.', $url_array);
array_shift($url_array);
}

// Start query
$query = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'site');
$query->leftJoin('hosting_site', 'h', 'h.nid = n.nid');
$query->condition('h.status', HOSTING_SITE_DELETED, '<>');

// Check for either ...
$or = db_or();

$sites = db_or();
$aliases = db_or();

// Iterate over all subdomains and populate sites and aliases checks.
foreach ($subdomains as $domain) {
// Regular site names
$sites->condition('n.title', $domain);

// And aliases
$aliases->condition('a.alias', $domain);
}

// Any of the above domains that do not belong to this client.
$or->condition(
db_and()
->condition($sites)
->condition('h.client', $client->nid, '<>')
);

if (module_exists('hosting_alias')) {
$query->leftJoin('hosting_site_alias', 'a', 'n.vid = a.vid');

// Any of the above domain aliases that do not belong to this client.
$or->condition(
db_and()
->condition($aliases)
->condition('h.client', $client->nid, '<>')
);
}

// Add conditions to the query.
$query->condition($or);

// For existing sites, don't match the site's current url.
if (isset($params['nid'])) {
$query->condition('n.nid', $params['nid'], '<>');
}

return !$query->countQuery()->execute()->fetchField();
}
12 changes: 12 additions & 0 deletions hosting.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ td.hosting-actions .hosting-button-disabled {
text-transform: none;
}

.view-hosting-task-list .hosting-status time {
font-size:0.8em;
color: #555;
text-transform: uppercase;
padding: 0 1em 0 0;
white-space: nowrap;
}

.view-hosting-task-list .hosting-status time em.placeholder {
font-style: normal;
}

/**
* Status icons, colors.
*/
Expand Down
4 changes: 2 additions & 2 deletions migrate/hosting_migrate.module
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function hosting_migrate_hosting_tasks() {
$tasks = array();

$tasks['site']['migrate'] = array(
'title' => t('Migrate'),
'title' => t('Migrate Site'),
'description' => t('Move the site to a new platform.'),
'dialog' => TRUE,
);

$tasks['platform']['migrate'] = array(
'title' => t('Migrate'),
'title' => t('Migrate Sites'),
'description' => t('Migrate sites to a new platform.'),
'page arguments' => array('hosting_migrate_platform', 1),
'dialog' => TRUE,
Expand Down
14 changes: 7 additions & 7 deletions platform/hosting_platform.module
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ function hosting_platform_node_info() {
function hosting_platform_hosting_tasks() {
$tasks = array();
$tasks['platform']['verify'] = array(
'title' => t('Verify'),
'title' => t('Verify Platform'),
'description' => t('Verify that the platform is correctly installed and working.'),
'weight' => 10,
'provision_save' => TRUE,
);
$tasks['platform']['delete'] = array(
'title' => t('Delete'),
'title' => t('Delete Platform'),
'description' => t('Deleting this platform will completely remove it from the hosting system.
This process can not be undone. It can not be performed if you have sites currently
running on this platform.
Expand Down Expand Up @@ -332,8 +332,8 @@ function hosting_platform_form(&$node) {
'#maxlength' => 255,
);

// Allow edition if the node is in creation, or if wasn't verified correctly
// *and* we're not using a makefile. The reason while we don't allow editing
// Allow editing if the node is in creation, or if wasn't verified correctly
// *and* we're not using a makefile. The reason why we don't allow editing
// the path if the makefile was specified is that there's the possibility
// that the platform path was actually created when the node was saved the
// first time and we have cruft lying around to cleanup.
Expand Down Expand Up @@ -378,7 +378,7 @@ function hosting_platform_form(&$node) {
// Send it on form submission.
$form['publish_path'] = array(
'#type' => 'hidden',
'#value' => $node->publish_path,
'#value' => hosting_path_normalize($node->publish_path),
);
}

Expand Down Expand Up @@ -490,7 +490,7 @@ function hosting_platform_insert($node) {
->fields(array(
'vid' => $node->vid,
'nid' => $node->nid,
'publish_path' => $node->publish_path,
'publish_path' => hosting_path_normalize($node->publish_path),
'makefile' => isset($node->makefile) ? $node->makefile : (isset($node->frommakefile['makefile']) ? $node->frommakefile['makefile'] : ''),
'verified' => isset($node->verified) ? $node->verified : 0,
'web_server' => $node->web_server,
Expand Down Expand Up @@ -520,7 +520,7 @@ function hosting_platform_update($node) {
}
db_update('hosting_platform')
->fields(array(
'publish_path' => $node->publish_path,
'publish_path' => hosting_path_normalize($node->publish_path),
'makefile' => isset($node->makefile) ? $node->makefile : (isset($node->frommakefile['makefile']) ? $node->frommakefile['makefile'] : ''),
'web_server' => $node->web_server,
'verified' => $node->verified,
Expand Down
7 changes: 7 additions & 0 deletions queued/hosting_queued.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ function hosting_queued_settings_form($form, &$form_state) {
60 * 60,
), 'format_interval'),
);

$form['hosting_queued_paused'] = array(
'#type' => 'checkbox',
'#title' => t('Pause the Hosting Queue'),
'#description' => t('Temporarily pause the hosting queue from running tasks.'),
'#default_value' => variable_get('hosting_queued_paused', 0),
);

return system_settings_form($form);
// @ignore security_fapi_markup
Expand Down
42 changes: 40 additions & 2 deletions queued/hosting_queued.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,47 @@ function drush_hosting_queued() {
// frontend.
variable_set('hosting_queued_process_started', REQUEST_TIME);

watchdog('hosting_queued', 'Started Hosting queue daemon, waiting for new tasks');
drush_log('Started hosting queue daemon. Waiting for new tasks.', 'ok');
// Check if hosting queue is paused, show appropriate message.
$is_paused = variable_get('hosting_queued_paused', 0);
if ($is_paused) {
watchdog('hosting_queued', 'Started Hosting queue daemon, hosting queue is paused.');
drush_log('Started hosting queue daemon, hosting queue is paused.', 'ok');
}
else {
watchdog('hosting_queued', 'Started Hosting queue daemon, waiting for new tasks');
drush_log('Started hosting queue daemon. Waiting for new tasks.', 'ok');
}

global $conf;

while (TRUE) {

// Detect if the hosting queue is paused or not.
// Reload variables. Since this is still a single request, any variable changes are not available.
$conf = variable_initialize();
if (variable_get('hosting_queued_paused', 0)) {

// If was not paused on last cycle, announce that it has been paused.
if (!$is_paused) {
drush_log('Hosting Queued has been paused.', 'ok');
}
sleep(1);

// Save current state for next cycle.
$is_paused = variable_get('hosting_queued_paused', 0);

continue;
}
else {
// If was paused on last cycle, announce that it has been unpaused.
if ($is_paused) {
drush_log('Hosting Queued has been unpaused.', 'ok');
}

// Save current state for next cycle.
$is_paused = variable_get('hosting_queued_paused', 0);
}

try {
// Should we terminate.
if (time() > $end_time) {
Expand Down
4 changes: 2 additions & 2 deletions server/hosting_server.module
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ function hosting_server_menu() {
function hosting_server_hosting_tasks() {
$tasks = array();
$tasks['server']['verify'] = array(
'title' => t('Verify'),
'title' => t('Verify Server'),
'description' => t('Verify that the server is correctly installed and working.'),
'weight' => 10,
'provision_save' => TRUE,
);

$tasks['server']['delete'] = array(
'title' => t('Delete'),
'title' => t('Delete Server'),
'description' => t('Delete the server.'),
);

Expand Down
1 change: 1 addition & 0 deletions site/hosting_site.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function hosting_hosting_site_context_options(&$task) {
$task->options['client_email'] = $user->mail;
}
$task->context_options['client_name'] = $client->uname;
$task->options['site_install_method'] = $task->ref->install_method;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion site/hosting_site.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ function hosting_site_validate($node, &$form) {
}

// TODO: maybe we should allow creation of sites that conflict with HOSTING_SITE_DISABLED (which would then need to be renamed before being re-enabled)
// TODO: This error is also triggered when the user attempts to register a subdomain of a used site. Perhaps we should read the error code and split the errors?
if (!hosting_domain_allowed($url, (array) $node)) {
form_set_error('title', t("The domain name you have specified is already in use."));
form_set_error('title', t("The domain name you have specified is already in use, or does not belong to you."));
}

// If the quota module is loaded and this is a new node, check
Expand Down
24 changes: 13 additions & 11 deletions site/hosting_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function hosting_site_hosting_tasks() {
);

$tasks['site']['verify'] = array(
'title' => t('Verify'),
'title' => t('Verify Site'),
'description' => t('Confirm that the site has been correctly installed and regenerate all configuration files to match the hosting front end.'),
'provision_save' => TRUE,
);
Expand All @@ -311,7 +311,7 @@ function hosting_site_hosting_tasks() {
It may be disabled again if needed.'),
);
$tasks['site']['delete'] = array(
'title' => t('Delete'),
'title' => t('Delete Site'),
'description' => t('Deleting this site will completely remove it from the hosting system,
but will keep the last backup available. This process can not be undone.
Are you really sure you want to delete this site?'),
Expand Down Expand Up @@ -661,18 +661,20 @@ function hosting_site_status_codes($type = NULL) {
* @see hosting_domain_allowed()
*/
function hosting_site_allow_domain($url, $params = array()) {
$query = "SELECT COUNT(n.nid) FROM {node} n
JOIN {hosting_site} h ON n.nid = h.nid
WHERE type = 'site' AND n.title = :title AND h.status <> :status";
$args[':title'] = $url;
$args[':status'] = HOSTING_SITE_DELETED;
$query = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'site')
->condition('n.title', $url);

$query->leftJoin('hosting_site', 'h', 'h.nid = n.nid');
$query->condition('h.status', HOSTING_SITE_DELETED, '<>');

// For existing sites, don't match the site's current url.
if (isset($params['nid'])) {
$query .= " AND n.nid <> :nid";
$args[':nid'] = $params['nid'];
$query->condition('n.nid', $params['nid'], '<>');
}
$result = !db_query($query, $args)->fetchField();
return $result;

return !$query->countQuery()->execute()->fetchField();
}

/**
Expand Down
Loading