View source
<?php
define('DRD_AGENT_LIB_BASE_URI', 'https://git.drupalcode.org/project/drd_agent_lib/raw/master/');
function drd_agent_menu() {
$items['drd-agent'] = array(
'title' => 'DRD Agent Callback',
'page callback' => 'drd_agent',
'access callback' => TRUE,
'delivery callback' => 'drd_agent_deliver',
'type' => MENU_CALLBACK,
);
$items['drd-agent-crypt'] = array(
'title' => 'DRD Agent Callback',
'page callback' => 'drd_agent_crypt',
'access callback' => TRUE,
'delivery callback' => 'drd_agent_deliver',
'type' => MENU_CALLBACK,
);
$items['drd-agent-authorize-secret'] = array(
'title' => 'Authorize Dashboard',
'page callback' => 'drd_agent_authorize_secret',
'access callback' => TRUE,
'delivery callback' => 'drd_agent_deliver',
'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/config/system/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_agent_admin_paths() {
return array(
'drd-agent' => TRUE,
'drd-agent-crypt' => TRUE,
'drd-agent-authorize' => TRUE,
);
}
function _drd_get_lib($force = FALSE) {
$archive = 'drd-' . $_SERVER['HTTP_X_DRD_VERSION'] . '.phar';
$uri = 'temporary://' . $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();
return \Drupal\drd\Agent\Action\Base::run(7, variable_get('drd_agent_debug_mode', FALSE));
}
function drd_agent_crypt() {
_drd_get_lib();
return base64_encode(json_encode(\Drupal\drd\Crypt\Base::getMethods()));
}
function drd_agent_authorize_secret() {
_drd_get_lib();
return \Drupal\drd\Agent\Action\Base::authorizeBySecret(7, variable_get('drd_agent_debug_mode', FALSE));
}
function drd_agent_deliver($page_callback_result) {
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
drupal_add_http_header('X-DRD-Agent', $_SERVER['HTTP_X_DRD_VERSION']);
print $page_callback_result;
ajax_footer();
}