- <?php
-
- * @file
- * Acquia Agent securely sends information to Acquia Network.
- */
-
- * XML-RPC errors defined by the Acquia Network.
- */
- define('SUBSCRIPTION_NOT_FOUND' , 1000);
- define('SUBSCRIPTION_KEY_MISMATCH' , 1100);
- define('SUBSCRIPTION_EXPIRED' , 1200);
- define('SUBSCRIPTION_REPLAY_ATTACK' , 1300);
- define('SUBSCRIPTION_KEY_NOT_FOUND' , 1400);
- define('SUBSCRIPTION_MESSAGE_FUTURE' , 1500);
- define('SUBSCRIPTION_MESSAGE_EXPIRED' , 1600);
- define('SUBSCRIPTION_MESSAGE_INVALID' , 1700);
- define('SUBSCRIPTION_VALIDATION_ERROR', 1800);
- define('SUBSCRIPTION_PROVISION_ERROR' , 9000);
-
-
- * Subscription message lifetime defined by the Acquia Network.
- */
- define('SUBSCRIPTION_MESSAGE_LIFETIME', 15*60);
-
- * Implementation of hook_menu().
- */
- function acquia_agent_menu() {
- $items['admin/settings/acquia-agent'] = array(
- 'title' => 'Acquia Network settings',
- 'description' => 'Connect your site to the Acquia Network.',
- 'page callback' => 'acquia_agent_settings_page',
- 'file' => 'acquia_agent.pages.inc',
- 'access arguments' => array('administer site configuration'),
- );
- $items['admin/settings/acquia-agent/setup'] = array(
- 'title' => 'Acquia Network automatic setup',
- 'description' => 'Connect your site to the Acquia Network.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('acquia_agent_automatic_setup_form'),
- 'file' => 'acquia_agent.pages.inc',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/settings/acquia-agent/credentials'] = array(
- 'title' => 'Acquia Network credentials',
- 'description' => 'Connect your site to the Acquia Network.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('acquia_agent_settings_credentials'),
- 'file' => 'acquia_agent.pages.inc',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/settings/acquia-agent/migrate'] = array(
- 'title' => 'Acquia Cloud Upload',
- 'description' => 'Migrate your site to Acquia Cloud.',
- 'page callback' => 'acquia_agent_migrate_page',
- 'file' => 'acquia_agent.pages.inc',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK,
- );
- $items['system/acquia-migrate-check'] = array(
- 'title' => 'Migrate capable',
- 'description' => 'Check for Acquia Cloud migration capabilities',
- 'page callback' => 'acquia_agent_migrate_check',
- 'file' => 'acquia_agent.migrate.inc',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/settings/acquia-agent/refresh-status'] = array(
- 'title' => 'Manual update check',
- 'page callback' => 'acquia_agent_refresh_status',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
-
- * Implementation of hook_init().
- */
- function acquia_agent_init() {
- if (arg(2) != 'acquia-agent' && empty($_POST) &&
- user_access('administer site configuration') &&
- (!acquia_agent_has_credentials()) &&
- arg(0) !== 'filefield' && arg(1) != 'progress') {
- $text = 'Get a <a href="!acquia-free">free 30-day trial</a> of the Acquia Network which includes a <a href="!library" target="_blank">library</a> of expert knowledge, <a href="!services" target="_blank">tools and services</a> to make your site awesome, and <a href="!support" target="_blank">Drupal support</a> when you need it.<br/>If you have an Acquia Network subscription, <a href="!settings">connect now</a>. Otherwise, you can turn this message off by disabling the Acquia Network <a href="!admin-modules">modules</a>.';
- if (isset($_SERVER['AH_SITE_GROUP'])) {
- $text = '<a href="!settings">Connect your site to the Acquia Network now</a>.';
- }
- $message = t($text, array('!acquia-free' => url('admin/settings/acquia-agent'), '!library' => url('http://library.acquia.com'), '!settings' => url('admin/settings/acquia-agent/setup'), '!support' => url('http://www.acquia.com/drupal-support'), '!services' => url('http://www.acquia.com/products-services/acquia-network/cloud-services'), '!admin-modules' => url('admin/build/modules', array('fragment' => 'edit-modules-acquia-network-connector'))));
- drupal_set_message($message, 'warning', FALSE);
- }
- }
-
- * Implementation of hook_theme().
- */
- function acquia_agent_theme() {
- return array(
- 'acquia_agent_banner_form' => array(
- 'arguments' => array('form' => NULL),
- 'file' => 'acquia_agent.pages.inc',
- ),
- );
- }
-
- * Get subscription status from the Acquia Network, and store the result.
- *
- * This check also sends a heartbeat to the Acquia Network unless
- * $params['no_heartbeat'] == 1.
- */
- function acquia_agent_check_subscription($params = array()) {
-
- $subscription = FALSE;
- $response_error = FALSE;
- $active = FALSE;
- if (!acquia_agent_has_credentials()) {
-
- variable_del('acquia_subscription_data');
- }
- else {
- $subscription = acquia_agent_get_subscription($params);
- if (is_int($subscription)) {
- switch($subscription) {
- case SUBSCRIPTION_NOT_FOUND:
- case SUBSCRIPTION_EXPIRED:
- variable_del('acquia_subscription_data');
- break;
- }
- }
-
- variable_set('acquia_subscription_data', $subscription);
-
- if ($subscription) {
- $active = acquia_agent_subscription_is_active();
- }
- }
- module_invoke_all('acquia_subscription_status', $active, $subscription);
- return $subscription;
- }
-
- * Get subscription status from the Acquia Network
- *
- * This check also sends a heartbeat to the Acquia Network unless
- * $params['no_heartbeat'] == 1.
- */
- function acquia_agent_get_subscription($params = array(), $identifier = NULL, $key = NULL, $acquia_network_address = NULL) {
-
- $response_error = FALSE;
-
- $subscription = array();
- $subscription['timestamp'] = time();
-
-
- acquia_agent_load_versions();
- if (IS_ACQUIA_DRUPAL) {
- $params['version'] = ACQUIA_DRUPAL_VERSION;
- $params['series'] = ACQUIA_DRUPAL_SERIES;
- $params['branch'] = ACQUIA_DRUPAL_BRANCH;
- $params['revision'] = ACQUIA_DRUPAL_REVISION;
- }
-
- if (module_exists('acquia_search')) {
- if (defined('ACQUIA_SEARCH_VERSION')) {
- $params['search_version']['acquia_search'] = ACQUIA_SEARCH_VERSION;
- }
- else {
- $params['search_version']['acquia_search'] = variable_get('acquia_search_version', '6.x-3.x');
- }
- $info = db_result(db_query("SELECT info FROM {system} WHERE name = 'apachesolr'"));
- if ($info = unserialize($info)) {
-
- $params['search_version']['apachesolr'] = isset($info['version']) ? (string)$info['version'] : $info['core'];
- }
- }
-
-
- $data = acquia_agent_call('acquia.agent.subscription', $params, $identifier, $key, $acquia_network_address);
-
-
- if ($errno = xmlrpc_errno()) {
- return $errno;
- }
- elseif (acquia_agent_valid_response($data, $key)) {
-
- $subscription += $data['result']['body'];
- }
- else {
- watchdog('acquia agent', 'HMAC validation error: <pre>@data</pre>', array('@data' => print_r($data, TRUE)), WATCHDOG_ERROR);
- return FALSE;
- }
-
- return $subscription;
- }
-
- function acquia_agent_report_xmlrpc_error() {
- drupal_set_message(t('Error: @message (@errno)', array('@message' => xmlrpc_error_msg(), '@errno' => xmlrpc_errno())), 'error');
- }
-
- * Implementation of hook_update_status_alter().
- *
- * This compares the array of computed information about projects that are
- * missing available updates with the saved settings. If the settings specify
- * that a particular project or release should be ignored, the status for that
- * project is altered to indicate it is ignored because of settings.
- *
- * @param $projects
- * Reference to an array of information about available updates to each
- * project installed on the system.
- *
- * @see update_calculate_project_data()
- */
- function acquia_agent_update_status_alter(&$projects) {
-
- if (!$subscription = acquia_agent_has_update_service()) {
-
- return;
- }
-
- foreach ($projects as $project => $project_info) {
- if ($project == 'drupal') {
- if (isset($subscription['update'])) {
- $projects[$project]['status'] = $subscription['update']['status'];
- $projects[$project]['releases'] = $subscription['update']['releases'];
- $projects[$project]['recommended'] = $subscription['update']['recommended'];
- $projects[$project]['latest_version'] = $subscription['update']['latest_version'];
-
-
- unset($projects[$project]['security updates']);
- }
- else {
- $projects[$project]['status'] = UPDATE_NOT_CHECKED;
- $projects[$project]['reason'] = t('No information available from the Acquia Network');
- unset($projects[$project]['releases']);
- unset($projects[$project]['recommended']);
- }
- $projects[$project]['link'] = 'http://acquia.com/products-services/acquia-drupal';
- $projects[$project]['title'] = 'Acquia Drupal';
- $projects[$project]['existing_version'] = ACQUIA_DRUPAL_VERSION;
- $projects[$project]['install_type'] = 'official';
- unset($projects[$project]['extra']);
- }
- elseif ($project_info['datestamp'] == 'acquia drupal') {
- $projects['drupal']['includes'][$project] = $project_info['title'];
- unset($projects[$project]);
- }
- }
- }
-
- * Implementation of hook_system_info_alter()
- */
- function acquia_agent_system_info_alter(&$info) {
- if (!$subscription = acquia_agent_has_update_service()) {
-
- return;
- }
- if (isset($info['acquia'])) {
-
- $info['datestamp'] = 'acquia drupal';
- }
- }
-
- * Returns the stored subscription data if update service is enabled or FALSE otherwise.
- */
- function acquia_agent_has_update_service() {
-
- acquia_agent_load_versions();
-
- $subscription = acquia_agent_settings('acquia_subscription_data');
- if (!IS_ACQUIA_DRUPAL || !$subscription['active'] || (isset($subscription['update_service']) && empty($subscription['update_service']))) {
-
-
-
-
-
- return FALSE;
- }
-
- return $subscription;
- }
-
- * Implemetation of hook_menu_alter()
- */
- function acquia_agent_menu_alter(&$items) {
- if (isset($items['admin/reports/updates/check'])) {
- $items['admin/reports/updates/check']['page callback'] = 'acquia_agent_manual_status';
- }
- }
-
- function acquia_agent_help($path, $arg) {
- switch ($path) {
- case 'admin/help#acquia_agent':
- $output = '<h2>' . t('Acquia Network and Connector modules') . '</h2>';
- $output .= '<p>' . t("The Acquia Network Connector suite of modules allow you to connect your site to the Acquia Network and use its variety of services.") . '<p>';
- $output .= '<dl>';
- $output .= '<dt>Acquia Agent</dt>';
- $output .= '<dd>' . t('Enables secure communication between your Drupal sites and the Acquia Network.') . '</dt>';
- $output .= '<dt>Acquia SPI</dt>';
- $output .= '<dd>' . t('Automates the collection of site information. Required for use with the Acquia Insight service.') . '</dt>';
- $output .= '<dt>Acquia Search</dt>';
- $output .= '<dd>' . t('Provides authentication service to the Apache Solr Search Integration module to enable use of Acquia\'s hosted Solr search indexes.') . '</dt>';
- $output .= '</dl>';
- $output .= '<h3>' . t('Configuration settings') . '</h3>';
- $output .= '<dl>';
- $output .= '<dt>' . t('Data collection and examination') . '</dt>';
- $output .= '<dd>' . t('Upon cron (or if configured to run manually) information about your site will be sent and analyzed as part of the Acquia Insight service. You can optionally exclude information about admin privileges, content and user count, and watchdog logs.');
- $output .= '<dt>' . t('Source code analysis') . '</dt>';
- $output .= '<dd>' . t('If enhanced SSL security is enabled for your site and outside connections are allowed, Acquia Insight will examine the source code of your site to detect alterations and provide code diffs and update recommentations.');
- $output .= '<dt>' . t('Enhanced SSL security') . '</dt>';
- $output .= '<dd>' . t('The Acquia Connector will attempt to verify Acquia server identities before sending data if SSL is avaliable. May cause communication to fail, however, depending on your local configuration.');
- $ssl_available = (in_array('ssl', stream_get_transports(), TRUE) && !defined('ACQUIA_DEVELOPMENT_NOSSL'));
- if ($ssl_available) {
- $output .= ' <div class="ok">'. t('PHP has SSL support and may support this feature.') .'</div></dd>';
- }
- else {
- $output .= ' <div class="error">'. t('Your installation of PHP does not have SSL support. Please enable the SSL extension or compile PHP with SSL to use this feature, see: <a href="http://php.net/manual/en/book.openssl.php" target="_blank">http://php.net/manual/en/book.openssl.php</a>.') .'</div></dd>';
- }
- $output .= '<dt>' . t('Receive updates from Acquia Network') . '</dt>';
- $output .= '<dd>' . t('Receive dynamic updates on the Network Settings page from Acquia.com about your subscription and new features.') . '</dd>';
- $output .= '</dl>';
- return $output;
- }
- }
-
- * Menu callback for 'admin/settings/acquia-agent/refresh-status'.
- */
- function acquia_agent_refresh_status() {
-
-
-
- acquia_agent_check_subscription();
-
- drupal_goto('admin/settings/acquia-agent');
- }
-
- * Substituted menu callback for 'admin/reports/updates/check'.
- */
- function acquia_agent_manual_status() {
-
-
-
- acquia_agent_check_subscription();
-
- update_manual_status();
- }
-
- * Implementation of hook_cron().
- */
- function acquia_agent_cron() {
-
- acquia_agent_check_subscription();
- }
-
- * Implementation of hook_watchdog().
- */
- function acquia_agent_watchdog($log_entry) {
-
-
- $cron_failure_messages = array(
- 'Cron has been running for more than an hour and is most likely stuck.',
- 'Attempting to re-run cron while it is already running.',
- );
- if (in_array($log_entry['message'], $cron_failure_messages, TRUE)) {
- acquia_agent_check_subscription();
- }
- }
-
- * @defgroup acquia_admin_menu Alter or add to the administration menu.
- * @{
- * The admin_menu module is enabled by default - we alter it to add our icon and
- * subscription information.
- */
-
- * Implementation of hook_admin_menu().
- */
- function acquia_agent_admin_menu() {
-
- $links[] = array(
- 'title' => 'acquia_subscription_status',
- 'path' => 'http://acquia.com',
- 'weight' => -80,
- 'parent_path' => '<root>',
- 'options' => array('extra class' => 'admin-menu-action acquia-subscription-status', 'html' => TRUE),
- );
-
- return $links;
- }
-
- * Implementation of hook_translated_menu_link_alter().
- *
- * Here is where we make changes to links that need dynamic information such
- * as the current page path or the number of users.
- */
- function acquia_agent_translated_menu_link_alter(&$item, $map) {
- global $user;
-
- if (empty($user->uid) || ($item['module'] != 'admin_menu')) {
- return;
- }
- if ($item['title'] == 'acquia_subscription_status') {
- $subscription = acquia_agent_settings('acquia_subscription_data');
- if (empty($subscription['timestamp']) || (time() - $subscription['timestamp'] > 60*60*24)) {
- $subscription = acquia_agent_check_subscription(array('no_heartbeat' => 1));
- }
- if ($subscription['active']) {
- $icon = '<img src="'. base_path() . 'misc/watchdog-ok.png" height="10" alt="ok" />';
- $item['title'] = t("!icon Subscription active (expires @date)", array('!icon' => $icon, '@date' => format_date(strtotime($subscription['expiration_date']['value']), 'small')));
- $item['localized_options']['extra class'] .= " acquia-active-subscription";
- $item['localized_options']['attributes']['title'] = $subscription['product']['view'];
- $item['href'] = $subscription['href'];
- }
- else {
- $icon = '<img src="'. base_path() . 'misc/watchdog-error.png" height="10" alt="error" />';
- $item['title'] = t("!icon Subscription not active", array('!icon' => $icon));
- $item['localized_options']['extra class'] .= " acquia-inactive-subscription";
- $item['href'] = 'http://acquia.com/network';
- }
- }
- }
-
- * Implementation of hook_theme_registry_alter().
- */
- function acquia_agent_theme_registry_alter(&$theme_registry) {
- if (isset($theme_registry['admin_menu_icon'])) {
- $theme_registry['admin_menu_icon']['function'] = 'acquia_agent_menu_icon';
- }
- }
-
- * Render an icon to display in the Administration Menu.
- */
- function acquia_agent_menu_icon() {
- return '<img class="admin-menu-icon" src="'. base_path() . drupal_get_path('module', 'acquia_agent') . '/acquia.ico" height = "16" alt="" />';
- }
-
- * @} End of "acquia_admin_menu".
- */
-
- * Validate identifier/key pair via XML-RPC call to Acquia Network address.
- *
- * This is generaly only useful when actually entering the values in the form.
- * Normally, use acquia_agent_check_subscription() since it also validates
- * the response.
- */
- function acquia_agent_valid_credentials($identifier, $key, $acquia_network_address = NULL) {
- $data = acquia_agent_call('acquia.agent.validate', array(), $identifier, $key, $acquia_network_address);
- return (bool)$data['result'];
- }
-
- * Prepare and send a XML-RPC request to Acquia Network with an authenticator.
- *
- */
- function acquia_agent_call($method, $params, $identifier = NULL, $key = NULL, $acquia_network_address = NULL) {
- $path = drupal_get_path('module', 'acquia_agent');
- require_once $path .'/acquia_agent_streams.inc';
-
- $acquia_network_address = acquia_agent_network_address($acquia_network_address);
- $ip = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : '';
- $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : '';
- $ssl = isset($_SERVER["HTTPS"]) ? TRUE : FALSE;
- $data = array(
- 'authenticator' => _acquia_agent_authenticator($params, $identifier, $key),
- 'ip' => $ip,
- 'host' => $host,
- 'ssl' => $ssl,
- 'body' => $params,
- );
- $data['result'] = _acquia_agent_request($acquia_network_address, $method, $data);
- return $data;
- }
-
-
-
- * Returns an error message for the most recent (failed) attempt to connect
- * to the Acquia Network during the current page request. If there were no
- * failed attempts, returns FALSE.
- *
- * This function assumes that the most recent XML-RPC error came from the
- * Acquia Network; otherwise, it will not work correctly.
- */
- function acquia_agent_connection_error_message() {
- $errno = xmlrpc_errno();
- if ($errno) {
- switch ($errno) {
- case SUBSCRIPTION_NOT_FOUND:
- return t('The identifier you have provided does not exist in the Acquia Network or is expired. Please make sure you have used the correct value and try again.');
- break;
- case SUBSCRIPTION_EXPIRED:
- return t('Your Acquia Network subscription has expired. Please renew your subscription so that you can resume using Acquia Network services.');
- break;
- case SUBSCRIPTION_MESSAGE_FUTURE:
- return t('Your server is unable to communicate with the Acquia Network due to a problem with your clock settings. For security reasons, we reject messages that are more than @time ahead of the actual time recorded by our servers. Please fix the clock on your server and try again.', array('@time' => format_interval(SUBSCRIPTION_MESSAGE_LIFETIME)));
- break;
- case SUBSCRIPTION_MESSAGE_EXPIRED:
- return t('Your server is unable to communicate with the Acquia Network due to a problem with your clock settings. For security reasons, we reject messages that are more than @time older than the actual time recorded by our servers. Please fix the clock on your server and try again.', array('@time' => format_interval(SUBSCRIPTION_MESSAGE_LIFETIME)));
- break;
- case SUBSCRIPTION_VALIDATION_ERROR:
- return t('The identifier and key you have provided for the Acquia Network do not match. Please make sure you have used the correct values and try again.');
- break;
- default:
- return t('There is an error communicating with the Acquia Network at this time. Please check your identifier and key and try again.');
- break;
- }
- }
- return FALSE;
- }
-
- * Helper function to build the xmlrpc target address.
- */
- function acquia_agent_network_address($acquia_network_address = NULL) {
- if (empty($acquia_network_address)) {
- $acquia_network_address = acquia_agent_settings('acquia_network_address');
- }
-
- $uri = parse_url($acquia_network_address);
- if (isset($uri['host'])) {
- $acquia_network_address = $uri['host'];
- }
- $acquia_network_address .= isset($uri['port']) ? ':' . $uri['port'] : '';
- $acquia_network_address .= (isset($uri['path']) && isset($uri['host'])) ? $uri['path'] : '';
-
- if (in_array('ssl', stream_get_transports(), TRUE) && !defined('ACQUIA_DEVELOPMENT_NOSSL')) {
-
- $acquia_network_address = 'https://' . $acquia_network_address;
- }
- else {
- $acquia_network_address = 'http://' . $acquia_network_address;
- }
- $acquia_network_address .= '/xmlrpc.php';
- return $acquia_network_address;
- }
-
- * Helper function to check if an identifer and key exist.
- */
- function acquia_agent_has_credentials() {
- return (bool)(variable_get('acquia_identifier', '') && variable_get('acquia_key', ''));
- }
-
- * Helper function to check if the site has an active subscription.
- */
- function acquia_agent_subscription_is_active() {
- $active = FALSE;
-
- if (acquia_agent_has_credentials()) {
- $subscription = acquia_agent_settings('acquia_subscription_data');
- $active = !empty($subscription['active']);
- }
- return $active;
- }
-
- * Helper function so that we don't need to repeat defaults.
- */
- function acquia_agent_settings($variable_name) {
- switch ($variable_name) {
- case 'acquia_identifier':
- return variable_get('acquia_identifier', '');
- case 'acquia_key':
- return variable_get('acquia_key', '');
- case 'acquia_network_address':
- return variable_get('acquia_network_address', 'https://rpc.acquia.com');
- case 'acquia_subscription_data':
- return variable_get('acquia_subscription_data', array('active' => FALSE));
- case 'acquia_subscription_name':
- return variable_get('acquia_subscription_name', '');
- }
- }
-
- * Returns a string of highly randomized bytes (over the full 8-bit range).
- *
- * This function is better than simply calling mt_rand() or any other built-in
- * PHP function because it can return a long string of bytes (compared to < 4
- * bytes normally from mt_rand)) and uses the best available pseudo-random source.
- *
- * @param $count
- * The number of characters (bytes) to return in the string.
- */
- function acquia_agent_random_bytes($count) {
- static $random_state;
-
- if (empty($random_state)) {
- $random_state = getmypid();
- }
- $output = '';
-
-
- if ($fh = @fopen('/dev/urandom', 'rb')) {
- $output = fread($fh, $count);
- fclose($fh);
- }
-
-
- while (strlen($output) < $count) {
- $random_state = md5(microtime() . mt_rand() . $random_state);
- $output .= pack('H*', md5(mt_rand() . $random_state));
- }
- return substr($output, 0, $count);
- }
-
- * API function used by others to ensure version information is loaded.
- *
- * Saves us some cycles to not load it each time, when it is actually
- * not needed. We store this in a separate file, so that the Acquia
- * build process only needs to alter that file instead of the main
- * module file.
- */
- function acquia_agent_load_versions() {
-
- include_once 'acquia_agent_drupal_version.inc';
- }
-
- * Implementation of hook_form_[form_id]_alter()..
- */
- function acquia_agent_form_system_modules_alter(&$form, &$form_state) {
-
- if (isset($form['description']['acquia_search'])) {
- $subscription = acquia_agent_settings('acquia_subscription_data');
-
- if (!module_exists('acquia_search') && empty($subscription['active'])) {
- $form['status']['#disabled_modules'][] = 'acquia_search';
- $text = 'Acquia Search requires an <a href="@network-url">Acquia Network subscription</a>';
- $message = t($text, array('@network-url' => 'http://acquia.com/products-services/acquia-search'));
- $form['description']['acquia_search']['#value'] = '<div style="padding-left:5px; margin:8px 0px" class="messages warning" id="acquia-agent-no-search">' . $message . '</div>' . $form['description']['acquia_search']['#value'];
- }
- }
- }
-