You are here

function _acquia_agent_call_provision_freetrial in Acquia Connector 7

Same name and namespace in other branches
  1. 6 acquia_agent/acquia_agent.pages.inc \_acquia_agent_call_provision_freetrial()

Helper function that creates a new AN subscription via xmlrpc call. It stores id/key if success and sets page error otherwise

1 call to _acquia_agent_call_provision_freetrial()
_acquia_agent_provision_freetrial in acquia_agent/acquia_agent.pages.inc

File

acquia_agent/acquia_agent.pages.inc, line 32
Acquia Agent configuration page.

Code

function _acquia_agent_call_provision_freetrial($body, $authenticator, $pass) {
  $md5_pass = md5($pass);
  $values = array(
    'body' => $body,
    'authenticator' => $authenticator,
  );
  $result = xmlrpc(acquia_agent_network_address(), array(
    'acquia.agent.provision.freetrial' => array(
      $values,
    ),
  ));
  if ($errno = xmlrpc_errno()) {
    drupal_set_message(t('Error getting free trial: @message (@errno)', array(
      '@message' => xmlrpc_error_msg(),
      '@errno' => xmlrpc_errno(),
    )), 'error');
    watchdog('acquia agent', '@message (@errno): %server - %method - <pre>@data</pre>', array(
      '@message' => xmlrpc_error_msg(),
      '@errno' => xmlrpc_errno(),
      '%server' => acquia_agent_network_address(),
      '%method' => 'acquia.agent.provision.freetrial',
      '@data' => print_r($values, TRUE),
    ), WATCHDOG_ERROR);
    $result = FALSE;
  }
  elseif (!empty($result['body']['nid'])) {
    if (!empty($result['body']['hashkey']) && !empty($md5_pass)) {

      // We have a key XOR'd with a hash.
      $hash = str_pad(_acquia_agent_hmac($md5_pass, $authenticator['time'], $authenticator['nonce'], $result['body']['identifier']), 64, chr(0x0));

      // Repeat the XOR and remove trailing NUL bytes.
      $key = rtrim(base64_decode($result['body']['hashkey']) ^ $hash);

      // Strip off the padding marker character.
      $key = substr($key, 0, -1);
    }
    else {
      $key = $result['body']['key'];
    }
    variable_set('acquia_key', $key);
    variable_set('acquia_identifier', $result['body']['identifier']);
    drupal_set_message(t('The Acquia configuration options have been saved.'));

    // Check subscription and send a heartbeat to Acquia Network via XML-RPC.
    // Our status gets updated locally via the return data.
    acquia_agent_check_subscription();
    cache_clear_all();
  }
  return $result;
}