53 private $currentAction = null;
58 private static $access_levels = [
'public',
'logged_in',
'admin'];
68 $this->config = $config;
70 $this->crypto = $crypto;
94 'admin/plugins/disable',
99 if (!in_array(
$action, $exceptions)) {
107 $forwarder = str_replace($this->config->getSiteUrl(),
"", $forwarder);
108 $forwarder = str_replace(
"http://",
"", $forwarder);
109 $forwarder = str_replace(
"@",
"", $forwarder);
110 if (substr($forwarder, 0, 1) ==
"/") {
111 $forwarder = substr($forwarder, 1);
130 $response = new \Elgg\Http\ErrorResponse($msg, $status_code);
133 $response = new \Elgg\Http\OkResponse(
$content, $status_code);
136 $forwarder = empty($forwarder) ?
REFERER : $forwarder;
137 $response->setForwardURL($forwarder);
141 if (!isset($this->actions[
$action])) {
145 $user = $this->session->getLoggedInUser();
148 switch ($this->actions[$action][
'access']) {
166 if (!
_elgg_services()->hooks->trigger(
'action', $action, null,
true)) {
194 if (empty($filename)) {
195 $path = __DIR__ .
'/../../../actions';
196 $filename = realpath(
"$path/$action.php");
199 if (!in_array(
$access, self::$access_levels)) {
200 _elgg_services()->logger->error(
"Unrecognized value '$access' for \$access in " . __METHOD__);
204 $this->actions[
$action] = array(
216 if (isset($this->actions[
$action])) {
217 unset($this->actions[$action]);
237 $session_id = $this->session->getId();
239 if ((
$token) && (
$ts) && ($session_id)) {
240 if ($this->validateTokenOwnership(
$token,
$ts)) {
241 if ($this->validateTokenTimestamp(
$ts)) {
244 $returnval =
_elgg_services()->hooks->trigger(
'action_gatekeeper:permissions:check',
'all', array(
251 }
else if ($visible_errors) {
254 }
else if ($visible_errors) {
258 'js:security:token_refresh_failed',
259 array($this->config->getSiteUrl()
265 }
else if ($visible_errors) {
275 $length = $req->server->get(
'CONTENT_LENGTH');
276 $post_count = count($req->request);
277 if (
$length && $post_count < 1) {
279 $error_msg =
_elgg_services()->hooks->trigger(
'action_gatekeeper:upload_exceeded_msg',
'all', array(
281 'visible_errors' => $visible_errors,
282 ),
_elgg_services()->translator->translate(
'actiongatekeeper:uploadexceeded'));
284 $error_msg =
_elgg_services()->translator->translate(
'actiongatekeeper:missingfields');
286 if ($visible_errors) {
302 $timeout = $this->getActionTokenTimeout();
304 return ($timeout == 0 || (
$ts > $now - $timeout) && (
$ts < $now + $timeout));
314 if (($timeout = $this->config->get(
'action_token_timeout')) === null) {
319 return (
int)((float)$timeout * $hour);
329 if ($this->validateActionToken(
false)) {
335 if (
$token && $this->validateTokenTimestamp(
$ts)) {
344 if ($this->validateActionToken()) {
363 $required_token = $this->generateActionToken(
$timestamp, $session_token);
380 if (!$session_token) {
382 if (!$session_token) {
396 return (isset($this->actions[
$action]) && file_exists($this->actions[$action][
'file']));
412 if ($reason ==
'walled_garden' || $reason ==
'csrf') {
416 $status_code = (int) $reason;
417 if ($status_code < 100 || ($status_code > 299 && $status_code < 400) || $status_code > 599) {
426 $headers[
'Content-Type'] =
'application/json; charset=UTF-8';
466 $session_token =
get_input(
'session_token', null,
false);
467 $pairs = (array)
get_input(
'pairs', array(),
false);
468 $valid_tokens = (object)array();
469 foreach ($pairs as $pair) {
470 list(
$ts,
$token) = explode(
',', $pair, 2);
471 if ($this->validateTokenOwnership(
$token,
$ts, $session_token)) {
472 $valid_tokens->{
$token} =
true;
477 $token = $this->generateActionToken(
$ts);
482 'logged_in' => $this->session->isLoggedIn(),
484 'valid_tokens' => $valid_tokens,
485 'session_token' => $this->session->get(
'__elgg_session'),
486 'user_guid' => $this->session->getLoggedInUserGuid(),
const ELGG_HTTP_FORBIDDEN
const ELGG_HTTP_NOT_IMPLEMENTED
HTTP response builder interface.
elgg_is_xhr()
Checks whether the request was requested via ajax.
validateTokenOwnership($token, $timestamp, $session_token= '')
Was the given token generated for the session defined by session_token?
if(!$entity->delete()) $forward_url
if(!array_key_exists($filename, $text_files)) $file
elgg_set_http_header($header, $replace=true)
Set a response HTTP header.
execute($action, $forwarder="")
Executes an action If called from action() redirect will be issued by the response factory If called ...
elgg_get_session()
Gets Elgg's session object.
Access to configuration values.
getCurrentTime($modifier= '')
Get the (cloned) time.
getAllActions()
Get all actions.
ajaxForwardHook($hook, $reason, $forward_url, $params)
validateActionToken($visible_errors=true, $token=null, $ts=null)
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
validateTokenTimestamp($ts)
Is the token timestamp within acceptable range?
elgg register_error
Wrapper function for system_messages.
__construct(Config $config, ElggSession $session, ElggCrypto $crypto)
Constructor.
$content
Set robots.txt action.
handleTokenRefreshRequest()
Send an updated CSRF token, provided the page's current tokens were not fake.
trait TimeUsing
Adds methods for setting the current time (for testing)
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
gatekeeper()
Alias of elgg_gatekeeper()
generateActionToken($timestamp, $session_token= '')
Generate a token from a session token (specifying the user), the timestamp, and the site key...