View source  
  <?php
define('DRD_AGENT_LIB_BASE_URI', 'https://git.drupalcode.org/project/drd_agent_lib/raw/master/');
if (!defined('DRUPAL_ROOT')) {
  define('DRUPAL_ROOT', getcwd());
}
if (!defined('REQUEST_TIME')) {
  define('REQUEST_TIME', time());
}
function drd_agent_menu() {
  $items['drd-agent'] = array(
    'title' => 'DRD Agent Callback',
    'page callback' => 'drd_agent',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['drd-agent-crypt'] = array(
    'title' => 'DRD Agent Callback',
    'page callback' => 'drd_agent_crypt',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['drd-agent-authorize-secret'] = array(
    'title' => 'Authorize Dashboard',
    'page callback' => 'drd_agent_authorize_secret',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['drd-agent-authorize'] = array(
    'title' => 'Authorize Dashboard',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'drd_agent_authorize',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'drd_agent.admin.inc',
    'type' => MENU_CALLBACK,
  );
  $items['admin/settings/drd'] = array(
    'title' => 'DRD',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'drd_agent_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'drd_agent.admin.inc',
  );
  return $items;
}
function _drd_get_lib($force = FALSE) {
  $archive = 'drd-' . $_SERVER['HTTP_X_DRD_VERSION'] . '.phar';
  $uri = file_directory_temp() . '/' . $archive;
  if ($force || !file_exists($uri)) {
    $response = drupal_http_request(DRD_AGENT_LIB_BASE_URI . $archive);
    if (empty($response->code) || $response->code != 200) {
      throw new Exception('DRD Library not available');
    }
    file_put_contents($uri, $response->data);
  }
  require_once $uri;
  if (!defined('DRD_BASE')) {
    
    ini_set('opcache.enable', 0);
    require $uri;
  }
}
function drd_agent() {
  _drd_get_lib();
  drd_agent_deliver(\Drupal\drd\Agent\Action\Base::run(6, variable_get('drd_agent_debug_mode', FALSE)));
}
function drd_agent_crypt() {
  _drd_get_lib();
  drd_agent_deliver(base64_encode(json_encode(\Drupal\drd\Crypt\Base::getMethods())));
}
function drd_agent_authorize_secret() {
  _drd_get_lib();
  drd_agent_deliver(\Drupal\drd\Agent\Action\Base::authorizeBySecret(6, variable_get('drd_agent_debug_mode', FALSE)));
}
function drd_agent_deliver($page_callback_result) {
  drupal_set_header('Content-Type: text/plain; charset=utf-8');
  drupal_set_header('X-DRD-Agent: ' . $_SERVER['HTTP_X_DRD_VERSION']);
  print $page_callback_result;
  drupal_page_footer();
  exit;
}