diff --git a/httprl.async.inc b/httprl.async.inc index 423a6a7..986d967 100644 --- a/httprl.async.inc +++ b/httprl.async.inc @@ -17,7 +17,24 @@ function httprl_async_page() { if ( empty($_POST['master_key']) || empty($_POST['temp_key']) || strpos($_POST['temp_key'], 'httprl_') !== 0 - || $_POST['master_key'] != hash('sha512', drupal_get_private_key()) + ) { + httprl_fast403(); + } + + // See if a full bootstrap has been done given the Drupal version. + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { + $level = drupal_bootstrap(); + $full_bootstrap = ($level == DRUPAL_BOOTSTRAP_FULL) ? TRUE : FALSE; + } + else { + $full_bootstrap = isset($GLOBALS['multibyte']) ? TRUE : FALSE; + } + // Get the private key. + $private_key = $full_bootstrap ? drupal_get_private_key() : httprl_variable_get('drupal_private_key', 0); + + // Exit if the master_key does not match the md5 of $private_key. + if ( empty($private_key) + || $_POST['master_key'] != hash('sha512', $private_key) ) { httprl_fast403(); } diff --git a/httprl.module b/httprl.module index 29dd58d..ef95f3f 100644 --- a/httprl.module +++ b/httprl.module @@ -1632,3 +1632,104 @@ function _httprl_use_proxy($host) { $proxy_exceptions = variable_get('proxy_exceptions', array('localhost', '127.0.0.1')); return !in_array(strtolower($host), $proxy_exceptions, TRUE); } + +/** + * Returns a persistent variable. + * + * This version ignores the $conf global and reads directly from the database. + * + * Case-sensitivity of the variable_* functions depends on the database + * collation used. To avoid problems, always use lower case for persistent + * variable names. + * + * @param $name + * The name of the variable to return. + * @param $default + * The default value to use if this variable has never been set. + * @return + * The value of the variable. + * + * @see variable_del(), variable_set() + */ +function httprl_variable_get($name, $default = NULL) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { + $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable} WHERE name = :name', array(':name' => $name))->fetchAllKeyed()); + return isset($variables[$name]) ? $variables[$name] : $default; + } + else { + $result = db_query("SELECT value FROM {variable} WHERE name = '%s'", $name); + if (!empty($result)) { + $result = db_result($result); + if (!empty($result)) { + $value = unserialize($result); + } + } + return isset($value) ? $value : $default; + } +} + +/** + * + * + * @param $array + * + */ +function httprl_run_array(&$array) { + $last = NULL; + foreach ($array as &$data) { + // Set the last variable if so desired. + if (isset($data['last'])) { + $last = $data['last']; + } + + // Replace the last key with the last thing that has been returned. + if (array_key_exists('last', $data['args'])) { + $data['args']['last'] = $last; + $data['args'] = array_values($data['args']); + } + + // Capture output if requested. + if (array_key_exists('printed', $data)) { + ob_start(); + } + + // Pass by reference trick for call_user_func_array(). + $args = array(); + foreach ($data['args'] as &$arg) { + $args[] = &$arg; + } + + // Start to capture errors. + $track_errors = ini_set('track_errors', '1'); + $php_errormsg = ''; + + // Call a function or a method. + switch ($data['type']) { + case 'function': + $last = call_user_func_array($data['call'], $args); + break; + + case 'method': + $last = call_user_func_array(array($last, $data['call']), $args); + break; + + } + + // Set any errors if any where thrown. + if (!empty($php_errormsg)) { + $data['error'] = $php_errormsg; + ini_set('track_errors', $track_errors); + } + + // End capture. + if (array_key_exists('printed', $data)) { + $data['printed'] = ob_get_contents(); + ob_end_clean(); + } + + // Set what was returned from each call. + if (array_key_exists('return', $data)) { + $data['return'] = $last; + } + } +} diff --git a/httprl_caller.php b/httprl_caller.php new file mode 100644 index 0000000..cacdd25 --- /dev/null +++ b/httprl_caller.php @@ -0,0 +1,58 @@ += 7) { + $result = db_query('SELECT filename FROM {system} WHERE name = :name', array(':name' => 'httprl'))->fetchAssoc(); + if (!empty($result)) { + $filename = $result['filename']; + } +} +else { + $result = db_query("SELECT filename FROM {system} WHERE name = '%s'", 'httprl'); + if (!empty($result)) { + $result = db_fetch_array($result); + if (!empty($result['filename'])) { + $filename = $result['filename']; + } + } +} +if (!empty($filename)) { + require_once DRUPAL_ROOT . '/' . $result['filename']; +} +else { + httprl_fast403(); +} + + +// Require async code and run it. +require_once dirname($filename) . '/httprl.async.inc'; +httprl_async_page();