View source
<?php
define('ACQUIA_SPI_DATA_VERSION', 2.1);
define('ACQUIA_SPI_METHOD_CALLBACK', 'menu');
define('ACQUIA_SPI_METHOD_CRON', 'cron');
define('ACQUIA_SPI_METHOD_DRUSH', 'drush');
define('ACQUIA_SPI_METHOD_CREDS', 'creds');
define('ACQUIA_SPI_METHOD_INSIGHT', 'insight');
function acquia_spi_help($path, $arg) {
$welcome_nid = variable_get('acquia_welcome', 0);
if ($path == 'admin/help#acquia_spi' && $welcome_nid) {
if ($nid = db_query('SELECT nid FROM {node} where nid = :nid', array(
':nid' => $welcome_nid,
))
->fetchField()) {
$txt = 'The !acquia_welcome provides information about how to ' . 'quickly get your site up and running. Also there are instructions for ' . 'setting the site theme as well as many other configuration tasks.';
$link = l('Acquia Drupal welcome page', 'node/' . $nid);
return '<p>' . t($txt, array(
'!acquia_welcome' => $link,
)) . '<p>';
}
}
}
function acquia_spi_cron() {
$last = variable_get('acquia_spi_cron_last', 0);
$interval = variable_get('acquia_spi_cron_interval', 30);
if (variable_get('acquia_spi_cron_interval_override', FALSE)) {
$interval = variable_get('acquia_spi_cron_interval_override', 30);
}
$now = REQUEST_TIME;
if (variable_get('acquia_spi_use_cron', 1) && $now - $last > $interval * 60) {
$ret = acquia_spi_send_full_spi(ACQUIA_SPI_METHOD_CRON);
}
}
function acquia_spi_menu() {
$items['system/acquia-spi-send'] = array(
'title' => 'Acquia SPI Send',
'description' => 'Send SPI data to Acquia Insight.',
'page callback' => '_acquia_spi_send',
'access callback' => '_acquia_spi_send_access',
);
$items['system/acquia-spi-custom-test-validate'] = array(
'title' => 'Acquia SPI Custom Test Validation',
'description' => 'Perform a validation check on all Acquia SPI custom tests.',
'page callback' => 'acquia_spi_test_status',
'page arguments' => array(
TRUE,
),
'access arguments' => array(
'access site reports',
),
);
return $items;
}
function acquia_spi_boot() {
if (drupal_is_cli()) {
return;
}
$last = variable_get('acquia_spi_boot_last', 0);
$interval = variable_get('acquia_spi_cron_interval', 60);
$now = REQUEST_TIME;
if ($now - $last > $interval * 60 && lock_acquire(__FUNCTION__)) {
$platform = acquia_spi_get_platform();
acquia_spi_data_store_set(array(
'platform' => $platform,
));
variable_set('acquia_spi_boot_last', $now);
}
}
function acquia_spi_data_store_set($data, $expire = NULL) {
if (is_null($expire)) {
$expire = REQUEST_TIME + 60 * 60 * 24;
}
foreach ($data as $key => $value) {
cache_set('acquia.spi.' . $key, $value, 'cache', $expire);
}
}
function acquia_spi_data_store_get($keys) {
$store = array();
foreach ($keys as $key) {
$cache = cache_get('acquia.spi.' . $key, 'cache');
if ($cache && !empty($cache->data)) {
$store[$key] = $cache->data;
}
}
return $store;
}
function _acquia_spi_send_access() {
$acquia_key = acquia_agent_settings('acquia_key');
if (!empty($acquia_key) && isset($_GET['key'])) {
$key = sha1(drupal_get_private_key());
if ($key === $_GET['key']) {
return TRUE;
}
}
return FALSE;
}
function _acquia_spi_send() {
$method = ACQUIA_SPI_METHOD_CALLBACK;
if (isset($_GET['method']) && $_GET['method'] === ACQUIA_SPI_METHOD_INSIGHT) {
$method = ACQUIA_SPI_METHOD_INSIGHT;
}
$response = acquia_spi_send_full_spi($method);
if (isset($_GET['destination'])) {
if (!empty($response)) {
$message = array();
if (isset($response['spi_data_received']) && $response['spi_data_received'] === TRUE) {
$message[] = t('SPI data sent.');
}
if (!empty($response['nspi_messages'])) {
$message[] = t('Acquia Insight returned the following messages. Further information may be in the logs.');
foreach ($response['nspi_messages'] as $nspi_message) {
$message[] = check_plain($nspi_message);
}
}
drupal_set_message(implode('<br/>', $message));
}
else {
drupal_set_message(t('Error sending SPI data. Consult the logs for more information.'), 'error');
}
drupal_goto();
}
drupal_exit();
}
function acquia_spi_xmlrpc() {
return array(
array(
'acquia.nspi.send.module.data',
'acquia_spi_send_module_data',
array(
'string',
'array',
),
t('Send file data for the provided path.'),
),
);
}
function acquia_spi_valid_request($data, $message) {
$key = acquia_agent_settings('acquia_key');
if (!isset($data['authenticator']) || !isset($data['authenticator']['time']) || !isset($data['authenticator']['nonce'])) {
return FALSE;
}
$string = $data['authenticator']['time'] . ':' . $data['authenticator']['nonce'] . ':' . $message;
$hash = sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $string)));
if ($hash == $data['authenticator']['hash']) {
return TRUE;
}
else {
return FALSE;
}
}
function acquia_spi_send_module_data($data = array()) {
$via_ssl = isset($_SERVER['HTTPS']) ? TRUE : FALSE;
if (variable_get('acquia_spi_module_diff_data', 1) && $via_ssl && acquia_agent_has_credentials() && isset($data['body']['file']) && acquia_spi_valid_request($data, $data['body']['file'])) {
$file = $data['body']['file'];
$document_root = getcwd();
$file_path = realpath($document_root . '/' . $file);
if (is_file($file_path) && strpos($file_path, $document_root) === 0 && strpos($file_path, 'settings.php') === FALSE) {
$file_contents = file_get_contents($file_path);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type:text");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
return $file_contents;
}
}
return FALSE;
}
function acquia_spi_form_acquia_agent_settings_form_alter(&$form) {
$identifier = acquia_agent_settings('acquia_identifier');
$key = acquia_agent_settings('acquia_key');
if (empty($identifier) && empty($key)) {
return;
}
if (module_exists('help')) {
$help_url = url('admin/help/acquia_agent');
}
else {
$help_url = url('https://docs.acquia.com/network/install');
}
$ssl_available = in_array('ssl', stream_get_transports(), TRUE) && !defined('ACQUIA_DEVELOPMENT_NOSSL');
$form['connection']['#description'] = t('Allow collection and examination of the following items. <a href="!url">Learn more</a>.', array(
'!url' => $help_url,
));
$form['connection']['spi'] = array(
'#prefix' => '<div class="acquia-spi">',
'#suffix' => '</div>',
'#weight' => -1,
);
$form['connection']['spi']['admin_priv'] = array(
'#type' => 'checkbox',
'#title' => t('Admin privileges'),
'#default_value' => variable_get('acquia_spi_admin_priv', 1),
);
$form['connection']['spi']['send_node_user'] = array(
'#type' => 'checkbox',
'#title' => t('Nodes and users'),
'#default_value' => variable_get('acquia_spi_send_node_user', 1),
);
$form['connection']['spi']['send_watchdog'] = array(
'#type' => 'checkbox',
'#title' => t('Watchdog logs'),
'#default_value' => variable_get('acquia_spi_send_watchdog', 1),
);
$form['connection']['spi']['module_diff_data'] = array(
'#type' => 'checkbox',
'#title' => t('Source code'),
'#default_value' => (int) variable_get('acquia_spi_module_diff_data', 1) && $ssl_available,
'#description' => t('Source code analysis requires a SSL connection and for your site to be publicly accessible. <a href="!url">Learn more</a>.', array(
'!url' => $help_url,
)),
'#disabled' => !$ssl_available,
);
$form['connection']['alter_variables'] = array(
'#type' => 'checkbox',
'#title' => t('Allow Insight to update list of approved variables.'),
'#default_value' => (int) variable_get('acquia_spi_set_variables_override', 0),
'#description' => t('Insight can set variables on your site to recommended values at your approval, but only from a specific list of variables. Check this box to allow Insight to update the list of approved variables. <a href="!url">Learn more</a>.', array(
'!url' => $help_url,
)),
);
$use_cron = variable_get('acquia_spi_use_cron', 1);
$form['connection']['spi_use_cron'] = array(
'#type' => 'checkbox',
'#title' => t('Send via Drupal cron'),
'#default_value' => $use_cron,
);
$key = sha1(drupal_get_private_key());
$url = url('system/acquia-spi-send', array(
'query' => array(
'key' => $key,
),
'absolute' => TRUE,
));
$form['connection']['spi_use_cron_url'] = array(
'#type' => 'container',
'#children' => t('<p>Enter the following URL in your server\'s crontab to send SPI data:<br/><em>!url</em></p>', array(
'!url' => $url,
)),
'#states' => array(
'visible' => array(
':input[name="spi_use_cron"]' => array(
'checked' => FALSE,
),
),
),
);
if ($use_cron) {
$form['connection']['spi_use_cron_url']['#states'] = array(
'visible' => array(
':input[name="spi_use_cron"]' => array(
'checked' => FALSE,
),
),
);
}
$form['actions']['submit']['#submit'][] = 'acquia_agent_spi_set_submit';
}
function acquia_spi_agent_settings_submit($form, &$form_state) {
acquia_spi_send_full_spi(ACQUIA_SPI_METHOD_CREDS);
}
function acquia_agent_spi_set_submit($form, &$form_state) {
variable_set('acquia_spi_module_diff_data', $form_state['values']['module_diff_data']);
variable_set('acquia_spi_admin_priv', $form_state['values']['admin_priv']);
variable_set('acquia_spi_send_node_user', $form_state['values']['send_node_user']);
variable_set('acquia_spi_send_watchdog', $form_state['values']['send_watchdog']);
variable_set('acquia_spi_use_cron', $form_state['values']['spi_use_cron']);
variable_set('acquia_spi_set_variables_override', $form_state['values']['alter_variables']);
}
function acquia_spi_update_definition() {
$core_version = substr(VERSION, 0, 1);
$spi_def_end_point = variable_get('acquia_spi_server', 'https://nspi.acquia.com');
$spi_def_end_point .= '/spi_def/get/' . $core_version;
$options = array(
'method' => 'GET',
'headers' => array(
'Content-type' => 'application/json',
),
'data' => drupal_http_build_query(array(
'spi_data_version' => ACQUIA_SPI_DATA_VERSION,
)),
);
$response = drupal_http_request($spi_def_end_point, $options);
if ($response->code != 200 || !isset($response->data)) {
watchdog('acquia spi', 'Failed to obtain latest SPI data definition. HTTP response: @response', array(
'@response' => var_export($response, TRUE),
), WATCHDOG_ERROR);
return FALSE;
}
else {
$response_data = drupal_json_decode($response->data);
$expected_data_types = array(
'drupal_version' => 'string',
'timestamp' => 'string',
'acquia_spi_variables' => 'array',
);
foreach ($expected_data_types as $key => $values) {
if (!array_key_exists($key, $response_data) || gettype($response_data[$key]) != $expected_data_types[$key]) {
watchdog('acquia spi', 'Received SPI data definition does not match expected pattern while checking "@key". Received and expected data: @data', array(
'@key' => $key,
'@data' => var_export(array_merge(array(
'expected_data' => $expected_data_types,
), array(
'response_data' => $response_data,
)), 1),
TRUE,
), WATCHDOG_ERROR);
return FALSE;
}
}
if ($response_data['drupal_version'] != $core_version) {
watchdog('acquia spi', 'Received SPI data definition does not match with current version of your Drupal installation. Data received for Drupal @version', array(
'@version' => $response_data['drupal_version'],
), WATCHDOG_ERROR);
return FALSE;
}
}
if ((int) $response_data['timestamp'] > (int) variable_get('acquia_spi_def_timestamp', 0)) {
$old_vars = variable_get('acquia_spi_def_vars', array());
$new_vars = $response_data['acquia_spi_variables'];
$new_optional_vars = 0;
foreach ($new_vars as $new_var_name => $new_var) {
if ($new_var['optional'] && !array_key_exists($new_var_name, $old_vars) || $new_var['optional'] && isset($old_vars[$new_var_name]) && !$old_vars[$new_var_name]['optional']) {
$new_optional_vars++;
}
}
$waived_spi_def_vars = variable_get('acquia_spi_def_waived_vars', array());
$changed_bool = FALSE;
foreach ($waived_spi_def_vars as $key => $waived_var) {
if (!in_array($waived_var, $new_vars)) {
unset($waived_spi_def_vars[$key]);
$changed_bool = TRUE;
}
}
if ($changed_bool) {
variable_set('acquia_spi_def_waived_vars', $waived_spi_def_vars);
}
if ($new_optional_vars > 0) {
variable_set('acquia_spi_new_optional_data', 1);
}
variable_set('acquia_spi_def_timestamp', $response_data['timestamp']);
variable_set('acquia_spi_def_vars', $response_data['acquia_spi_variables']);
return TRUE;
}
return FALSE;
}
function acquia_spi_send_full_spi($method = '') {
$spi = acquia_spi_get();
if (!empty($method)) {
$spi['send_method'] = $method;
}
$result = acquia_spi_send_data($spi);
if ($result === FALSE) {
return FALSE;
}
acquia_spi_handle_server_response($result);
variable_set('acquia_spi_cron_last', REQUEST_TIME);
return $result;
}
function acquia_spi_handle_server_response($spi_response) {
$update = isset($spi_response['update_spi_definition']) ? $spi_response['update_spi_definition'] : FALSE;
if ($update === TRUE) {
acquia_spi_update_definition();
}
$set_variables = isset($spi_response['set_variables']) ? $spi_response['set_variables'] : FALSE;
if ($set_variables !== FALSE) {
acquia_spi_set_variables($set_variables);
}
$messages = isset($spi_response['nspi_messages']) ? $spi_response['nspi_messages'] : FALSE;
if ($messages !== FALSE) {
watchdog('acquia spi', 'SPI update server response messages: @messages', array(
'@messages' => implode(', ', $messages),
));
}
}
function acquia_spi_send_data($spi) {
if (!acquia_agent_has_credentials()) {
watchdog('acquia spi', 'Connect your site to a valid Acquia Subscription to send SPI data', array(), WATCHDOG_ERROR);
return FALSE;
}
$nspi_server = variable_get('acquia_spi_server', 'https://nspi.acquia.com');
$spi['rpc_version'] = 3;
$response = acquia_agent_call('acquia.nspi.update', $spi, NULL, NULL, $nspi_server);
if (!acquia_agent_valid_response($response, acquia_agent_settings('acquia_key'))) {
return FALSE;
}
return $response['result']['body'];
}
function acquia_spi_get() {
list($hashes, $fileinfo) = acquia_spi_file_hashes();
$hashes_string = serialize($hashes);
$drupal_version = acquia_spi_get_version_info();
$stored = acquia_spi_data_store_get(array(
'platform',
));
if (!empty($stored['platform'])) {
$platform = $stored['platform'];
}
else {
$platform = acquia_spi_get_platform();
}
$spi = array(
'spi_data_version' => ACQUIA_SPI_DATA_VERSION,
'site_key' => sha1(drupal_get_private_key()),
'modules' => acquia_spi_get_modules(),
'platform' => $platform,
'quantum' => acquia_spi_get_quantum(),
'system_status' => acquia_spi_get_system_status(),
'failed_logins' => variable_get('acquia_spi_send_watchdog', 1) ? acquia_spi_get_failed_logins() : array(),
'404s' => variable_get('acquia_spi_send_watchdog', 1) ? acquai_spi_get_404s() : array(),
'watchdog_size' => acquai_spi_get_watchdog_size(),
'watchdog_data' => variable_get('acquia_spi_send_watchdog', 1) ? acquia_spi_get_watchdog_data() : array(),
'last_nodes' => variable_get('acquia_spi_send_node_user', 1) ? acquai_spi_get_last_nodes() : array(),
'last_users' => variable_get('acquia_spi_send_node_user', 1) ? acquai_spi_get_last_users() : array(),
'extra_files' => acquia_spi_check_files_present(),
'ssl_login' => acquia_spi_check_login(),
'file_hashes' => $hashes,
'hashes_md5' => md5($hashes_string),
'hashes_sha1' => sha1($hashes_string),
'fileinfo' => $fileinfo,
'distribution' => isset($drupal_version['distribution']) ? $drupal_version['distribution'] : '',
'base_version' => $drupal_version['base_version'],
'build_data' => $drupal_version,
'roles' => drupal_json_encode(user_roles()),
'uid_0_present' => acquia_spi_uid_0_present(),
);
$scheme = parse_url(variable_get('acquia_spi_server', 'https://nspi.acquia.com'), PHP_URL_SCHEME);
$via_ssl = in_array('ssl', stream_get_transports(), TRUE) && $scheme == 'https' ? TRUE : FALSE;
if (variable_get('acquia_spi_ssl_override', FALSE)) {
$via_ssl = TRUE;
}
$additional_data = array();
$security_review_results = acquia_spi_run_security_review();
$additional_data['node_grants_modules'] = module_implements("node_grants", TRUE);
$additional_data['node_access_modules'] = module_implements("node_access", TRUE);
$additional_data['fast_404'] = acquia_spi_get_fast404();
if (!empty($security_review_results)) {
$additional_data['security_review'] = $security_review_results['security_review'];
}
$custom_tests_results = acquia_spi_test_collect();
if (!empty($custom_tests_results)) {
$additional_data['custom_tests'] = $custom_tests_results;
}
$spi_data = module_invoke_all('acquia_spi_get');
if (!empty($spi_data)) {
foreach ($spi_data as $name => $data) {
if (is_string($name) && is_array($data)) {
$additional_data[$name] = $data;
}
}
}
include_once DRUPAL_ROOT . '/includes/install.inc';
drupal_load_updates();
$additional_data['pending_updates'] = FALSE;
foreach (module_list() as $module) {
$updates = drupal_get_schema_versions($module);
if ($updates !== FALSE) {
$default = drupal_get_installed_schema_version($module);
if (max($updates) > $default) {
$additional_data['pending_updates'] = TRUE;
break;
}
}
}
if (!empty($additional_data)) {
$spi['additional_data'] = drupal_json_encode($additional_data);
}
if (!$via_ssl) {
return $spi;
}
else {
$spi_ssl = array(
'system_vars' => acquia_spi_get_variables_data(),
'settings_ra' => acquia_spi_get_settings_permissions(),
'admin_count' => variable_get('acquia_spi_admin_priv', 1) ? acquia_spi_get_admin_count() : '',
'admin_name' => variable_get('acquia_spi_admin_priv', 1) ? acquia_spi_get_super_name() : '',
);
return array_merge($spi, $spi_ssl);
}
}
function acquia_spi_get_fast404() {
global $base_url;
$path = sprintf('acquia-connector-fast-404-check-%s.css', uniqid());
$url = rtrim($base_url, DIRECTORY_SEPARATOR) . base_path() . $path;
$response = drupal_http_request($url);
$expected = variable_get('404_fast_html', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>');
$expected = strtr($expected, array(
'@path' => base_path() . $path,
));
if (isset($response->code) && $response->code != 404) {
watchdog('acquia spi', 'A fast 404 test to @url returned a non-404 result (@code): @error.', array(
'@url' => $url,
'@code' => $response->code,
'@error' => $response->error,
), WATCHDOG_WARNING);
return FALSE;
}
return array(
'enabled' => isset($response->data) && $response->data == $expected,
'base_url' => rtrim($base_url, DIRECTORY_SEPARATOR),
'response_code' => isset($response->code) ? $response->code : NULL,
);
}
function acquia_spi_run_security_review() {
if (!_acquia_spi_security_review_compatible()) {
return array();
}
module_load_include('inc', 'acquia_spi', 'security_review');
$checklist_results = array();
$skips = array();
$checklist = acquia_spi_security_review_get_checks();
$to_check = array(
'views_access',
'temporary_files',
'base_url_set',
'executable_php',
'input_formats',
'admin_permissions',
'untrusted_php',
'private_files',
'upload_extensions',
);
foreach ($checklist as $module => $checks) {
foreach ($checks as $check_name => $args) {
if (!in_array($check_name, $to_check)) {
unset($checklist[$module][$check_name]);
}
}
if (empty($checklist[$module])) {
unset($checklist[$module]);
}
}
$checklist_results = acquia_spi_security_review_run($checklist);
foreach ($checklist_results as $module => $checks) {
foreach ($checks as $check_name => $check) {
if (is_null($check['result'])) {
unset($checklist_results[$module][$check_name]);
}
else {
unset($check['success']);
unset($check['failure']);
$checklist_results[$module][$check_name] = $check;
}
}
if (empty($checklist_results[$module])) {
unset($checklist_results[$module]);
}
}
return $checklist_results;
}
function _acquia_spi_security_review_compatible() {
if (module_exists('security_review')) {
if (file_exists(drupal_get_path('module', 'security_review') . DIRECTORY_SEPARATOR . 'security_review.inc')) {
return TRUE;
}
else {
return FALSE;
}
}
return TRUE;
}
function acquia_spi_test_collect() {
$custom_data = array();
$collections = module_invoke_all('acquia_spi_test');
foreach ($collections as $test_name => $test_params) {
$result = acquia_spi_test_validate(array(
$test_name => $test_params,
));
if ($result['result']) {
$custom_data[$test_name] = $test_params;
}
}
return $custom_data;
}
function acquia_spi_test_enable() {
$modules = module_implements('acquia_spi_test');
foreach ($modules as $module) {
if (function_exists($module . '_acquia_spi_test')) {
drupal_set_message(t("An invokation of hook_acquia_spi_test() has been detected in @module.", array(
'@module' => $module,
)));
watchdog('acquia agent', "An invokation of hook_acquia_spi_test() has been detected in @module.", array(
'@module' => $module,
));
}
}
}
function acquia_spi_test_modules_enabled($modules) {
foreach ($modules as $module) {
if (function_exists($module . '_acquia_spi_test')) {
drupal_set_message(t("A new invokation of hook_acquia_spi_test() has been detected in @module.", array(
'@module' => $module,
)));
watchdog('acquia spi test', "A new invokation of hook_acquia_spi_test() has been detected in @module.", array(
'@module' => $module,
));
}
}
}
function acquia_spi_test_status($log = FALSE) {
$custom_data = array();
foreach (module_implements('acquia_spi_test') as $module) {
$function = $module . '_acquia_spi_test';
if (function_exists($function)) {
$result = acquia_spi_test_validate($function());
if (!$result['result']) {
$custom_data[$module] = $result;
foreach ($result['failure'] as $test_name => $test_failures) {
foreach ($test_failures as $test_param => $test_value) {
$variables = array(
'!module' => $module,
'@message' => $test_value['message'],
'!param_name' => $test_param,
'!test' => $test_name,
'!value' => $test_value['value'],
);
if ($log) {
drupal_set_message(t("Custom test validation failed for !test in !module and has been logged: @message for parameter '!param_name'; current value '!value'.", $variables), 'error');
watchdog('acquia spi test', "<em>Custom test validation failed</em>: @message for parameter '!param_name'; current value '!value'. (<em>Test '!test_name' in module '!module_name'</em>)", $variables, WATCHDOG_WARNING);
}
}
}
}
}
}
if ($log) {
drupal_goto('admin/reports/status');
}
return $custom_data;
}
function acquia_spi_test_validate($collection) {
$result = TRUE;
$check_result_value = array();
$categories = array(
'performance',
'security',
'best_practices',
);
$severities = array(
0,
1,
2,
4,
8,
16,
32,
64,
128,
);
foreach ($collection as $machine_name => $tests) {
foreach ($tests as $check_name => $check_value) {
$fail_value = '';
$message = '';
$check_name = strtolower($check_name);
$check_value = is_string($check_value) ? strtolower($check_value) : $check_value;
switch ($check_name) {
case 'category':
if (!is_string($check_value) || !in_array($check_value, $categories)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a string and one of ' . implode(', ', $categories);
}
break;
case 'solved':
if (!is_bool($check_value)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a boolean';
}
break;
case 'severity':
if (!is_int($check_value) || !in_array($check_value, $severities)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be an integer and set to one of ' . implode(', ', $severities);
}
break;
default:
if (!is_string($check_value) || strlen($check_value) > 1024) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a string and no more than 1024 characters';
}
break;
}
if (!empty($fail_value) && !empty($message)) {
$check_result_value['failed'][$machine_name][$check_name]['value'] = $fail_value;
$check_result_value['failed'][$machine_name][$check_name]['message'] = $message;
}
}
}
if (!empty($check_result_value)) {
$result = FALSE;
}
return array(
'result' => $result,
'failure' => isset($check_result_value['failed']) ? $check_result_value['failed'] : array(),
);
}
function acquia_spi_get_version_info() {
$store = acquia_spi_data_store_get(array(
'platform',
));
$server = !empty($store) && isset($store['platform']) ? $store['platform']['php_quantum']['SERVER'] : $_SERVER;
$ver = array();
$ver['base_version'] = VERSION;
$install_root = $server['DOCUMENT_ROOT'] . base_path();
$ver['distribution'] = '';
acquia_agent_load_versions();
if (IS_ACQUIA_DRUPAL) {
$ver['distribution'] = 'Acquia Drupal';
$ver['ad']['version'] = ACQUIA_DRUPAL_VERSION;
$ver['ad']['series'] = ACQUIA_DRUPAL_SERIES;
$ver['ad']['branch'] = ACQUIA_DRUPAL_BRANCH;
$ver['ad']['revision'] = ACQUIA_DRUPAL_REVISION;
}
if (defined('CACHE_EXTERNAL')) {
$ver['distribution'] = 'Pressflow';
$press_version_file = $install_root . './PRESSFLOW.txt';
if (is_file($press_version_file)) {
$ver['pr']['version'] = trim(file_get_contents($press_version_file));
}
}
elseif (is_dir($install_root . '/profiles/openatrium')) {
$ver['distribution'] = 'Open Atrium';
$version_file = $install_root . 'profiles/openatrium/VERSION.txt';
if (is_file($version_file)) {
$ver['oa']['version'] = trim(file_get_contents($version_file));
}
}
elseif (is_dir($install_root . '/profiles/commons')) {
$ver['distribution'] = 'Commons';
}
elseif (is_dir($install_root . '/profiles/cod')) {
$ver['distribution'] = 'COD';
}
return $ver;
}
function acquia_spi_check_login() {
$login_safe = 0;
if (module_exists('securepages')) {
if (drupal_match_path('user/login', variable_get('securepages_pages', ''))) {
$login_safe = 1;
}
if (drupal_match_path('user/login', variable_get('securepages_ignore', ''))) {
$login_safe = 0;
}
if (!variable_get('securepages_secure', FALSE) || !variable_get('securepages_enable', FALSE)) {
$login_safe = 0;
}
}
elseif (module_exists('securelogin')) {
$required_forms = array(
'securelogin_form_user_login',
'securelogin_form_user_login_block',
'securelogin_form_user_pass',
'securelogin_form_user_profile_form',
'securelogin_form_user_register_form',
);
$forms_safe = TRUE;
foreach ($required_forms as $form_variable) {
if (!variable_get($form_variable, TRUE)) {
$forms_safe = FALSE;
break;
}
}
if ($forms_safe && !variable_get('https', FALSE)) {
$login_safe = 1;
}
}
return $login_safe;
}
function acquia_spi_get_settings_permissions() {
$settings_permissions_read_only = TRUE;
$writes = array(
'2',
'3',
'6',
'7',
);
$settings_file = './' . conf_path(FALSE, TRUE) . '/settings.php';
$permissions = drupal_substr(sprintf('%o', fileperms($settings_file)), -4);
foreach ($writes as $bit) {
if (strpos($permissions, $bit)) {
$settings_permissions_read_only = FALSE;
break;
}
}
return $settings_permissions_read_only;
}
function acquia_spi_check_files_present() {
$store = acquia_spi_data_store_get(array(
'platform',
));
$server = !empty($store) && isset($store['platform']) ? $store['platform']['php_quantum']['SERVER'] : $_SERVER;
$files_exist = FALSE;
$url = url(NULL, array(
'absolute' => TRUE,
));
$files_to_remove = array(
'CHANGELOG.txt',
'COPYRIGHT.txt',
'INSTALL.mysql.txt',
'INSTALL.pgsql.txt',
'INSTALL.txt',
'LICENSE.txt',
'MAINTAINERS.txt',
'README.txt',
'UPGRADE.txt',
'PRESSFLOW.txt',
'install.php',
);
foreach ($files_to_remove as $file) {
$path = $server['DOCUMENT_ROOT'] . base_path() . $file;
if (file_exists($path)) {
$files_exist = TRUE;
}
}
return $files_exist ? 1 : 0;
}
function acquai_spi_get_last_users() {
$last_five_users = array();
$result = db_select('users', 'u')
->fields('u', array(
'uid',
'name',
'mail',
'created',
))
->condition('u.created', REQUEST_TIME - 3600, '>')
->orderBy('created', 'DESC')
->range(0, 15)
->execute();
$count = 0;
foreach ($result as $record) {
$last_five_users[$count]['uid'] = $record->uid;
$last_five_users[$count]['name'] = $record->name;
$last_five_users[$count]['email'] = $record->mail;
$last_five_users[$count]['created'] = $record->created;
$count++;
}
return $last_five_users;
}
function acquai_spi_get_last_nodes() {
$last_five_nodes = array();
$result = db_select('node', 'n')
->fields('n', array(
'title',
'type',
'nid',
'created',
))
->condition('n.created', REQUEST_TIME - 3600, '>')
->orderBy('n.created', 'DESC')
->range(0, 15)
->execute();
$count = 0;
foreach ($result as $record) {
$last_five_nodes[$count]['url'] = drupal_get_path_alias('node/' . $record->nid);
$last_five_nodes[$count]['title'] = $record->title;
$last_five_nodes[$count]['type'] = $record->type;
$last_five_nodes[$count]['created'] = $record->created;
$count++;
}
return $last_five_nodes;
}
function acquai_spi_get_watchdog_size() {
if (module_exists('dblog')) {
return db_select('watchdog', 'w')
->fields('w', array(
'wid',
))
->countQuery()
->execute()
->fetchField();
}
}
function acquia_spi_get_watchdog_data() {
$wd = array();
if (module_exists('dblog')) {
$result = db_select('watchdog', 'w')
->fields('w', array(
'wid',
'severity',
'type',
'message',
'timestamp',
))
->condition('w.severity', array(
WATCHDOG_EMERGENCY,
WATCHDOG_CRITICAL,
), 'IN')
->condition('w.timestamp', REQUEST_TIME - 3600, '>')
->execute();
while ($record = $result
->fetchAssoc()) {
$wd[$record['severity']] = $record;
}
}
return $wd;
}
function acquai_spi_get_404s() {
$data = array();
$row = 0;
if (module_exists('dblog')) {
$result = db_select('watchdog', 'w')
->fields('w', array(
'message',
'hostname',
'referer',
'timestamp',
))
->condition('w.type', 'page not found', '=')
->condition('w.timestamp', REQUEST_TIME - 3600, '>')
->condition('w.message', array(
"UPGRADE.txt",
"MAINTAINERS.txt",
"README.txt",
"INSTALL.pgsql.txt",
"INSTALL.txt",
"LICENSE.txt",
"INSTALL.mysql.txt",
"COPYRIGHT.txt",
"CHANGELOG.txt",
), 'NOT IN')
->orderBy('w.timestamp', 'DESC')
->range(0, 10)
->execute();
foreach ($result as $record) {
$data[$row]['message'] = $record->message;
$data[$row]['hostname'] = $record->hostname;
$data[$row]['referer'] = $record->referer;
$data[$row]['timestamp'] = $record->timestamp;
$row++;
}
}
return $data;
}
function acquia_spi_get_variables_data() {
global $conf;
$data = array();
$variables = array(
'acquia_spi_send_node_user',
'acquia_spi_admin_priv',
'acquia_spi_module_diff_data',
'acquia_spi_send_watchdog',
'acquia_spi_use_cron',
'cache_backends',
'cache_default_class',
'cache_inc',
'cron_safe_threshold',
'googleanalytics_cache',
'error_level',
'preprocess_js',
'page_cache_maximum_age',
'block_cache',
'preprocess_css',
'page_compression',
'cache',
'cache_lifetime',
'cron_last',
'clean_url',
'redirect_global_clean',
'theme_zen_settings',
'site_offline',
'site_name',
'user_register',
'user_signatures',
'user_admin_role',
'user_email_verification',
'user_cancel_method',
'filter_fallback_format',
'dblog_row_limit',
'date_default_timezone',
'file_default_scheme',
'install_profile',
'maintenance_mode',
'update_last_check',
'site_default_country',
'acquia_spi_saved_variables',
'acquia_spi_set_variables_automatic',
'acquia_spi_ignored_set_variables',
'acquia_spi_set_variables_override',
);
$spi_def_vars = variable_get('acquia_spi_def_vars', array());
$waived_spi_def_vars = variable_get('acquia_spi_def_waived_vars', array());
foreach ($spi_def_vars as $var_name => $var) {
if (!in_array($var_name, $waived_spi_def_vars) && !in_array($var_name, $variables)) {
$variables[] = $var_name;
}
}
$types = node_type_get_types();
if (!empty($types)) {
foreach ($types as $name => $type) {
$variables[] = 'comment_' . $name;
}
}
foreach ($variables as $name) {
if (isset($conf[$name])) {
$data[$name] = $conf[$name];
}
}
if (module_exists('globalredirect') && function_exists('_globalredirect_get_settings')) {
$data['globalredirect_settings'] = _globalredirect_get_settings();
}
if (drupal_is_cli()) {
$cron_safe_threshold = acquia_spi_get_db_variable('cron_safe_threshold');
$data['cron_safe_threshold'] = !is_null($cron_safe_threshold) ? $cron_safe_threshold : DRUPAL_CRON_DEFAULT_THRESHOLD;
}
foreach ($data as $var_name => $var) {
if (in_array($var_name, $waived_spi_def_vars)) {
unset($data[$var_name]);
}
}
return drupal_json_encode($data);
}
function acquia_spi_get_db_variable($name) {
$result = db_query("SELECT value FROM {variable} WHERE name = :name", array(
':name' => $name,
));
if ($result
->rowCount() == 1) {
return unserialize($result
->fetchField());
}
return NULL;
}
function acquia_spi_get_failed_logins() {
$last_logins = array();
$cron_interval = variable_get('acquia_spi_cron_interval', 8 * 60 * 60);
if (module_exists('dblog')) {
$result = db_select('watchdog', 'w')
->fields('w', array(
'message',
'variables',
))
->condition('w.message', 'login attempty failed%', 'LIKE')
->condition('w.timestamp', REQUEST_TIME - $cron_interval, '>')
->condition('w.message', array(
"UPGRADE.txt",
"MAINTAINERS.txt",
"README.txt",
"INSTALL.pgsql.txt",
"INSTALL.txt",
"LICENSE.txt",
"INSTALL.mysql.txt",
"COPYRIGHT.txt",
"CHANGELOG.txt",
), 'NOT IN')
->orderBy('w.timestamp', 'DESC')
->range(0, 10)
->execute();
foreach ($result as $record) {
$variables = unserialize($record->variables);
$last_logins['failed'][$record->timestamp] = check_plain($variables['%user']);
}
}
return $last_logins;
}
function acquia_spi_get_super_name() {
$result = db_query("SELECT name FROM {users} WHERE uid = 1 AND (name LIKE '%admin%' OR name LIKE '%root%')")
->fetch();
if ($result) {
return TRUE;
}
else {
return FALSE;
}
}
function acquia_spi_get_admin_count() {
$count = NULL;
$sql = "SELECT COUNT(DISTINCT u.uid) as count\n FROM {users} u, {users_roles} ur, {role_permission} p\n WHERE u.uid = ur.uid\n AND ur.rid = p.rid\n AND u.status = 1\n AND (p.permission = 'administer permissions' OR p.permission = 'administer users')";
$result = db_query($sql)
->fetchObject();
return isset($result->count) && is_numeric($result->count) ? $result->count : NULL;
}
function acquia_spi_get_platform() {
$server = $_SERVER;
$db_class = 'DatabaseTasks_' . Database::getConnection()
->driver();
$db_tasks = new $db_class();
preg_match('!^([^/]+)(/.+)?$!', $server['SERVER_SOFTWARE'], $webserver);
if (isset($webserver[1]) && stristr($webserver[1], 'Apache') && function_exists('apache_get_version')) {
$webserver[2] = apache_get_version();
$apache_modules = apache_get_modules();
}
else {
$apache_modules = '';
}
$php_quantum = array(
'memory_limit' => ini_get('memory_limit'),
'register_globals' => ini_get('register_globals'),
'post_max_size' => ini_get('post_max_size'),
'max_execution_time' => ini_get('max_execution_time'),
'upload_max_filesize' => ini_get('upload_max_filesize'),
'error_log' => ini_get('error_log'),
'error_reporting' => ini_get('error_reporting'),
'display_errors' => ini_get('display_errors'),
'log_errors' => ini_get('log_errors'),
'session.cookie_domain' => ini_get('session.cookie_domain'),
'session.cookie_lifetime' => ini_get('session.cookie_lifetime'),
'newrelic.appname' => ini_get('newrelic.appname'),
'SERVER' => $server,
'sapi' => php_sapi_name(),
);
$platform = array(
'php' => PHP_VERSION,
'webserver_type' => isset($webserver[1]) ? $webserver[1] : '',
'webserver_version' => isset($webserver[2]) ? $webserver[2] : '',
'apache_modules' => $apache_modules,
'php_extensions' => get_loaded_extensions(),
'php_quantum' => $php_quantum,
'database_type' => $db_tasks
->name(),
'database_version' => Database::getConnection()
->version(),
'system_type' => php_uname('s'),
'system_version' => php_uname('r') . ' ' . php_uname('v') . ' ' . php_uname('m') . ' ' . php_uname('n'),
'mysql' => Database::getConnection()
->driver() == 'mysql' ? acquia_spi_get_platform_mysql_data() : array(),
);
foreach ($platform as $key => $value) {
if (empty($platform[$key])) {
$platform[$key] = '';
}
}
return $platform;
}
function acquia_spi_get_platform_mysql_data() {
$connection = Database::getConnection('default');
$orig = $connection
->getAttribute(PDO::ATTR_CASE);
$connection
->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$result = $connection
->query("SHOW GLOBAL STATUS", array(), array());
$connection
->setAttribute(PDO::ATTR_CASE, $orig);
$ret = array();
if (empty($result)) {
return $ret;
}
foreach ($result as $record) {
if (!isset($record->variable_name)) {
continue;
}
switch ($record->variable_name) {
case 'Table_locks_waited':
$ret['Table_locks_waited'] = $record->value;
break;
case 'Slow_queries':
$ret['Slow_queries'] = $record->value;
break;
case 'Qcache_hits':
$ret['Qcache_hits'] = $record->value;
break;
case 'Qcache_inserts':
$ret['Qcache_inserts'] = $record->value;
break;
case 'Qcache_queries_in_cache':
$ret['Qcache_queries_in_cache'] = $record->value;
break;
case 'Qcache_lowmem_prunes':
$ret['Qcache_lowmem_prunes'] = $record->value;
break;
case 'Open_tables':
$ret['Open_tables'] = $record->value;
break;
case 'Opened_tables':
$ret['Opened_tables'] = $record->value;
break;
case 'Select_scan':
$ret['Select_scan'] = $record->value;
break;
case 'Select_full_join':
$ret['Select_full_join'] = $record->value;
break;
case 'Select_range_check':
$ret['Select_range_check'] = $record->value;
break;
case 'Created_tmp_disk_tables':
$ret['Created_tmp_disk_tables'] = $record->value;
break;
case 'Created_tmp_tables':
$ret['Created_tmp_tables'] = $record->value;
break;
case 'Handler_read_rnd_next':
$ret['Handler_read_rnd_next'] = $record->value;
break;
case 'Sort_merge_passes':
$ret['Sort_merge_passes'] = $record->value;
break;
case 'Qcache_not_cached':
$ret['Qcache_not_cached'] = $record->value;
break;
}
}
return $ret;
}
function acquia_spi_get_system_status() {
$data = array();
$profile = drupal_get_profile();
if ($profile != 'standard') {
$info = system_get_info('module', $profile);
$data['install_profile'] = array(
'title' => 'Install profile',
'value' => t('%profile_name (%profile-%version)', array(
'%profile_name' => $info['name'],
'%profile' => $profile,
'%version' => $info['version'],
)),
);
}
$data['php'] = array(
'title' => 'PHP',
'value' => phpversion(),
);
$conf_dir = TRUE;
$settings = TRUE;
$dir = conf_path();
if (is_writable($dir) || is_writable($dir . '/settings.php')) {
$value = 'Not protected';
if (is_writable($dir)) {
$conf_dir = FALSE;
}
elseif (is_writable($dir . '/settings.php')) {
$settings = FALSE;
}
}
else {
$value = 'Protected';
}
$data['settings.php'] = array(
'title' => 'Configuration file',
'value' => $value,
'conf_dir' => $conf_dir,
'settings' => $settings,
);
$cron_last = variable_get('cron_last', NULL);
if (!is_numeric($cron_last)) {
$cron_last = variable_get('install_time', 0);
}
$data['cron'] = array(
'title' => 'Cron maintenance tasks',
'value' => t('Last run !time ago', array(
'!time' => format_interval(REQUEST_TIME - $cron_last),
)),
'cron_last' => $cron_last,
);
if (!empty($GLOBALS['update_free_access'])) {
$data['update access'] = array(
'value' => 'Not protected',
'protected' => FALSE,
);
}
else {
$data['update access'] = array(
'value' => 'Protected',
'protected' => TRUE,
);
}
$data['update access']['title'] = 'Access to update.php';
if (!module_exists('update')) {
$data['update status'] = array(
'value' => 'Not enabled',
);
}
else {
$data['update status'] = array(
'value' => 'Enabled',
);
}
$data['update status']['title'] = 'Update notifications';
return $data;
}
function acquia_spi_get_modules() {
$last_build = variable_get('acquia_spi_module_rebuild', 0);
if ($last_build < REQUEST_TIME - 86400) {
$modules = system_rebuild_module_data();
variable_set('acquia_spi_module_rebuild', REQUEST_TIME);
}
else {
$result = db_query("SELECT filename, name, type, status, schema_version, info FROM {system} WHERE type = 'module'");
foreach ($result as $file) {
$file->info = unserialize($file->info);
$modules[$file->filename] = $file;
}
}
$result = array();
$keys_to_send = array(
'name',
'version',
'package',
'core',
'project',
);
foreach ($modules as $filename => $file) {
$info = array();
$info['status'] = $file->status;
foreach ($keys_to_send as $key) {
$info[$key] = isset($file->info[$key]) ? $file->info[$key] : '';
}
$info['filename'] = $file->filename;
$module_path = explode('/', $file->filename);
array_pop($module_path);
if ($module_path[0] == 'sites') {
$contrib_path = implode('/', $module_path);
list($info['module_data']['hashes'], $info['module_data']['fileinfo']) = _acquia_spi_generate_hashes($contrib_path);
}
else {
$info['module_data']['hashes'] = array();
$info['module_data']['fileinfo'] = array();
}
$result[] = $info;
}
return $result;
}
function acquia_spi_get_quantum() {
$quantum = array();
$quantum['nodes'] = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('n.status', NODE_PUBLISHED)
->countQuery()
->execute()
->fetchField();
$quantum['users'] = db_select('users', 'u')
->fields('u', array(
'uid',
))
->condition('u.status', 1)
->countQuery()
->execute()
->fetchField();
if (module_exists('comment')) {
$quantum['comments'] = db_select('comment', 'c')
->fields('c', array(
'cid',
))
->condition('c.status', COMMENT_PUBLISHED)
->countQuery()
->execute()
->fetchField();
}
return $quantum;
}
function acquia_spi_uid_0_present() {
$count = db_query("SELECT uid FROM {users} WHERE uid = 0")
->rowCount();
return $count == 1 ? TRUE : FALSE;
}
function acquia_spi_file_hashes($exclude_dirs = array()) {
list($hashes, $fileinfo) = _acquia_spi_generate_hashes('.', $exclude_dirs, array(
'modules',
'profiles',
'themes',
'includes',
'misc',
'scripts',
));
ksort($hashes);
$htaccess = DRUPAL_ROOT . DIRECTORY_SEPARATOR . '.htaccess';
if (is_file($htaccess)) {
$owner = fileowner($htaccess);
if (function_exists('posix_getpwuid')) {
$userinfo = posix_getpwuid($owner);
$owner = $userinfo['name'];
}
$fileinfo['.htaccess'] = 'mt:' . filemtime($htaccess) . '$p:' . substr(sprintf('%o', fileperms($htaccess)), -4) . '$o:' . $owner . '$s:' . filesize($htaccess);
}
return array(
$hashes,
$fileinfo,
);
}
function _acquia_spi_generate_hashes($dir, $exclude_dirs = array(), $limit_dirs = array(), $module_break = FALSE, $orig_dir = NULL) {
$hashes = array();
$fileinfo = array();
if ($dir != $orig_dir && $module_break) {
if (is_dir($dir) && ($handle = opendir($dir))) {
while ($file = readdir($handle)) {
if (stristr($file, '.module')) {
return;
}
}
}
}
if (isset($handle)) {
closedir($handle);
}
if (is_dir($dir) && ($handle = opendir($dir))) {
while ($file = readdir($handle)) {
if (!in_array($file, array(
'.',
'..',
'CVS',
'.svn',
))) {
$path = $dir == '.' ? $file : "{$dir}/{$file}";
if (is_dir($path) && !in_array($path, $exclude_dirs) && (empty($limit_dirs) || in_array($path, $limit_dirs)) && $file != 'translations') {
list($sub_hashes, $sub_fileinfo) = _acquia_spi_generate_hashes($path, $exclude_dirs);
$hashes = array_merge($sub_hashes, $hashes);
$fileinfo = array_merge($sub_fileinfo, $fileinfo);
$hashes[$path] = acquia_spi_hash_path($path);
}
elseif (acquia_spi_is_manifest_type($file)) {
$hashes[$path] = acquia_spi_hash_path($path);
$owner = fileowner($path);
if (function_exists('posix_getpwuid')) {
$userinfo = posix_getpwuid($owner);
$owner = $userinfo['name'];
}
$fileinfo[$path] = 'mt:' . filemtime($path) . '$p:' . substr(sprintf('%o', fileperms($path)), -4) . '$o:' . $owner . '$s:' . filesize($path);
}
}
}
closedir($handle);
}
return array(
$hashes,
$fileinfo,
);
}
function acquia_spi_is_manifest_type($path) {
$extensions = array(
'php' => 1,
'php4' => 1,
'php5' => 1,
'module' => 1,
'inc' => 1,
'install' => 1,
'test' => 1,
'theme' => 1,
'engine' => 1,
'profile' => 1,
'css' => 1,
'js' => 1,
'info' => 1,
'sh' => 1,
'pem' => 1,
'pl' => 1,
'pm' => 1,
);
$pathinfo = pathinfo($path);
return isset($pathinfo['extension']) && isset($extensions[$pathinfo['extension']]);
}
function acquia_spi_hash_path($path = '') {
$hash = '';
if (file_exists($path)) {
if (!is_dir($path)) {
$string = file_get_contents($path);
$string = rtrim($string);
$string = preg_replace('/\\$Id[^;<>{}\\(\\)\\$]*\\$/', 'x$' . 'Id$', $string);
$string = preg_replace('/\\r\\n|\\n|\\r/', ' ', $string);
$hash = base64_encode(pack("H*", sha1($string)));
}
}
return $hash;
}
function acquia_spi_set_variables($set_variables) {
if (empty($set_variables)) {
return;
}
$saved = array();
$ignored = variable_get('acquia_spi_ignored_set_variables', array());
if (!variable_get('acquia_spi_set_variables_override', 0)) {
$ignored[] = 'acquia_spi_set_variables_automatic';
}
$ignored = array_merge($ignored, array(
'drupal_private_key',
'site_mail',
'site_name',
'maintenance_mode',
'user_register',
));
$whitelist = acquia_spi_approved_set_variables();
foreach ($set_variables as $key => $value) {
if (in_array($key, $whitelist) && !in_array($key, $ignored)) {
$saved[] = $key;
variable_set($key, $value);
}
}
if (!empty($saved)) {
variable_set('acquia_spi_saved_variables', array(
'variables' => $saved,
'time' => time(),
));
watchdog('acquia spi', 'Saved variables from Acquia Insight: @variables', array(
'@variables' => implode(', ', $saved),
), WATCHDOG_INFO);
}
else {
watchdog('acquia spi', 'Did not save any variables from Acquia Insight.', array(), WATCHDOG_INFO);
}
}
function acquia_spi_approved_set_variables() {
return variable_get('acquia_spi_set_variables_automatic', array(
'acquia_spi_set_variables_automatic',
'error_level',
'preprocess_js',
'page_cache_maximum_age',
'block_cache',
'preprocess_css',
'page_compression',
'cache',
'cache_lifetime',
'image_allow_insecure_derivatives',
'googleanalytics_cache',
'acquia_spi_send_node_user',
'acquia_spi_admin_priv',
'acquia_spi_module_diff_data',
'acquia_spi_send_watchdog',
'acquia_spi_use_cron',
));
}