diff --git a/alias/hosting_alias.module b/alias/hosting_alias.module index ce3a1f1..0211f20 100644 --- a/alias/hosting_alias.module +++ b/alias/hosting_alias.module @@ -493,7 +493,7 @@ function hosting_alias_settings($form, &$form_state) { * Validation handler for hosting_alias_settings form. */ function hosting_alias_settings_validate($form, $form_state) { - if (!empty($form_state['values']['hosting_alias_subdomain']) && !valid_url($form_state['values']['hosting_alias_subdomain'])) { + if (!valid_url($form_state['values']['hosting_alias_subdomain'])) { form_set_error('hosting_alias_subdomain', t('The provided domain is invalid.')); } } diff --git a/dns/hosting.feature.dns.inc b/dns/hosting.feature.dns.inc new file mode 100644 index 0000000..2295b76 --- /dev/null +++ b/dns/hosting.feature.dns.inc @@ -0,0 +1,19 @@ + t('DNS support'), + 'description' => t('Manage DNS records for your hosted sites.'), + 'status' => HOSTING_FEATURE_DISABLED, + 'module' => 'hosting_dns', + 'group' => 'experimental', + ); + return $features; +} diff --git a/dns/hosting_dns.info b/dns/hosting_dns.info new file mode 100644 index 0000000..d3bc2e2 --- /dev/null +++ b/dns/hosting_dns.info @@ -0,0 +1,8 @@ +name = DNS support +description = Manage DNS records for your hosted sites. +package = Hosting +dependencies[] = hosting + +core = 7.x + +files[] = hosting_dns.service.inc diff --git a/dns/hosting_dns.install b/dns/hosting_dns.install new file mode 100644 index 0000000..3e89ecf --- /dev/null +++ b/dns/hosting_dns.install @@ -0,0 +1,37 @@ + array( + 'fields' => array( + 'master_vid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'master_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'slave_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('master_vid', 'master_nid'), + ), + ); +} + diff --git a/dns/hosting_dns.module b/dns/hosting_dns.module new file mode 100644 index 0000000..9227ad8 --- /dev/null +++ b/dns/hosting_dns.module @@ -0,0 +1,25 @@ + array('title' => t('DNS service'))); +} + +/** + * Implements hook_hosting_service(). + */ +function hosting_dns_hosting_service() { + return array( + 'dnsmasq' => 'dns', + 'bind' => 'dns', + 'bind_slave' => 'dns', + ); +} + + diff --git a/dns/hosting_dns.service.inc b/dns/hosting_dns.service.inc new file mode 100644 index 0000000..0901dea --- /dev/null +++ b/dns/hosting_dns.service.inc @@ -0,0 +1,149 @@ +slave mapping + */ +class hostingService_dns_master extends hostingService_dns { + function view(&$render) { + parent::view($render); + + if (sizeof($this->slave_servers)) { + $render['slave_servers'] = array( + '#type' => 'item', + '#title' => t('Slave servers'), + '#value' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('dns'))))), + ); + } + } + + function form(&$form) { + parent::form($form); + + $servers = hosting_get_servers('dns'); + + // Exclude the current server from the list of possible slaves. + if (isset($this->server->nid)) { + unset($servers[$this->server->nid]); + } + + if (sizeof($servers)) { + $form['slave_servers'] = array( + '#title' => t('Slave DNS servers'), + '#type' => 'checkboxes', + '#options' => $servers, + '#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(), + ); + } + else { + $form['slave_server'] = array( + '#type' => 'value', + '#value' => array(), + ); + } + } + + function load() { + parent::load(); + + $slave_servers = array(); + $result = db_query('SELECT slave_nid FROM {hosting_dns_slaves} WHERE master_vid = :master_vid', array(':master_vid' => $this->server->vid)); + while ($slave_server = $result->fetch()) { + $slave_servers[] = $slave_server->slave_nid; + } + + $this->setValues(array('slave_servers' => drupal_map_assoc($slave_servers))); + } + + function insert() { + parent::insert(); + if (is_array($this->slave_servers)) { + foreach (array_filter($this->slave_servers) as $slave_server) { + $record = array( + 'master_nid' => $this->server->nid, + 'master_vid' => $this->server->vid, + 'slave_nid' => $slave_server, + ); + drupal_write_record('hosting_dns_slaves', $record); + } + } + } + + function delete() { + parent::delete(); + db_delete('hosting_dns_slaves') + ->condition('master_nid', $this->server->nid) + ->execute(); + } + + function delete_revision() { + parent::delete_revision(); + db_delete('hosting_dns_slaves') + ->condition('master_vid', $this->server->vid) + ->execute(); + } + + function context_options($task_type, $ref_type, &$task) { + parent::context_options($task_type, $ref_type, $task); + + if (is_array($this->slave_servers) && sizeof($this->slave_servers)) { + $task->context_options['slave_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('dns'))))); + } + } + +} + + +/** + * An implementation of the dns service type, registered with hook_hosting_service. + */ +class hostingService_dns_dnsmasq extends hostingService_dns_master { + public $type = 'dnsmasq'; + public $name = 'DNSMasq'; + + public $has_restart_cmd = TRUE; + + function default_restart_cmd() { + return "sudo /etc/init.d/dnsmasq restart"; + } +} + +/** + * An implementation of the dns service type, registered with hook_hosting_service. + */ +class hostingService_dns_bind extends hostingService_dns_master { + public $type = 'bind'; + public $name = 'Bind'; + + public $has_restart_cmd = TRUE; + + function default_restart_cmd() { + return "sudo /etc/init.d/bind restart"; + } +} + +/** + * Slave-specific servers + */ +class hostingService_dns_bind_slave extends hostingService_dns { + public $type = 'bind_slave'; + public $name = 'Bind Slave'; + + public $has_restart_cmd = TRUE; + + function default_restart_cmd() { + return "sudo /etc/init.d/bind restart"; + } +} diff --git a/server/hosting_server.drush.inc b/server/hosting_server.drush.inc index 94b2264..49bb527 100644 --- a/server/hosting_server.drush.inc +++ b/server/hosting_server.drush.inc @@ -23,15 +23,7 @@ function hosting_hosting_server_context_options(&$task) { } } else { - // If we're here, there is no enabled service of this type on this server. - // If such a service had previously been enabled, that fact, along with - // any subscribed properties would be recorded in the server context. - // Since we persist values in contexts, we cannot just leave this unset. - // Similarly, in Provision_Context::__get(), we filter out falsy values, - // so we cannot set this to NULL. 0 or the like. Therefore, we explicitely - // set it to value that we check for in - // Provision_Context_server::spawn_service(). - $task->context_options["{$type}_service_type"] = 'NONE'; + $task->context_options["{$type}_service_type"] = '0'; } } } diff --git a/server/hosting_server.module b/server/hosting_server.module index 9259e8e..cb88334 100644 --- a/server/hosting_server.module +++ b/server/hosting_server.module @@ -800,27 +800,21 @@ function hosting_server_entity_property_info() { * @param string $service * Service type string, like 'http' or 'db' * - * @param bool $node_access - * Apply node access filters, defaults to TRUE. - * * @return array * An array of enabled servers, keys are the nid's of the nodes representing * them, values are the titles of the servers. * * @see hook_hosting_servers_titles_alter() */ -function hosting_get_servers($service, $node_access = TRUE) { +function hosting_get_servers($service) { $return = array(); $query = db_select('node', 'n'); $query->join('hosting_service', 's', 'n.vid = s.vid'); $query ->fields('n', array('nid', 'title')) ->condition('s.available', '1') - ->condition('s.service', $service); - - if ($node_access) { - $query->addTag('node_access'); - } + ->condition('s.service', $service) + ->addTag('node_access'); $result = $query->execute(); diff --git a/site/hosting_site.drush.inc b/site/hosting_site.drush.inc index 88dc891..1faa0d5 100644 --- a/site/hosting_site.drush.inc +++ b/site/hosting_site.drush.inc @@ -24,6 +24,12 @@ function hosting_hosting_site_context_options(&$task) { $task->options['client_email'] = $user->mail; } $task->context_options['client_name'] = $client->uname; + + // Set "install_method" property, only if there is one present on the site node. + // "profile" is used by default, we don't have to set it here. + if (isset($task->ref->install_method) && !empty($task->ref->install_method)) { + $task->context_options['install_method'] = $task->ref->install_method; + } } /** diff --git a/site/hosting_site.form.inc b/site/hosting_site.form.inc index 763d328..fc383e9 100644 --- a/site/hosting_site.form.inc +++ b/site/hosting_site.form.inc @@ -267,10 +267,6 @@ function hosting_site_form($node, &$form_state) { // Load platforms for the selected profile $platforms = hosting_get_profile_platforms($selected_profile); - $available_options = hosting_site_available_options($node); - $available_platforms = array_flip($available_options['platform']); - $platforms = array_intersect_key($platforms, $available_platforms); - $q = drupal_get_query_parameters(); if (isset($q['platform']) && is_numeric($q['platform'])) { $default_platform = $q['platform']; diff --git a/task.hosting.inc b/task.hosting.inc index 2c393ce..65e7cc5 100644 --- a/task.hosting.inc +++ b/task.hosting.inc @@ -93,10 +93,7 @@ function drush_hosting_task_validate($id, $type = NULL) { } } else { - drush_set_error('HOSTING_INVALID_TASK', t("Could not find or create a '!type' task for hosting context '!context'.", array( - '!type' => $type, - '!context' => $id, - ))); + drush_set_error('HOSTING_INVALID_TASK', t("This task is not valid")); } } diff --git a/web_server/hosting_web_server.service.inc b/web_server/hosting_web_server.service.inc index 75aa443..fed9889 100644 --- a/web_server/hosting_web_server.service.inc +++ b/web_server/hosting_web_server.service.inc @@ -34,11 +34,9 @@ class hostingService_http_apache extends hostingService_http_public { function default_restart_cmd() { $command = '/usr/sbin/apache2ctl'; # a proper default for most of the world - if (isset($_SERVER['PATH'])) { - foreach (explode(':', $_SERVER['PATH']) as $path) { - $options[] = "$path/apache2ctl"; - $options[] = "$path/apachectl"; - } + foreach (explode(':', $_SERVER['PATH']) as $path) { + $options[] = "$path/apache2ctl"; + $options[] = "$path/apachectl"; } # try to detect the apache restart command $options[] = '/usr/local/sbin/apachectl'; # freebsd