Created
April 12, 2016 11:10
-
-
Save Mark-H/5c08e830c3c1eb2170717d33f23cf038 to your computer and use it in GitHub Desktop.
Connector for MODX Revolution with whitelist of permitted actions accessible from the web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set context | |
$_REQUEST['ctx'] = 'web'; | |
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php'; | |
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; | |
require_once MODX_CONNECTORS_PATH . 'index.php'; | |
// define allowed actions | |
$webActions = array( | |
'one/allowed/action', | |
'two/allowed/action', | |
'three/allowed/action', | |
); | |
// authentication | |
if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $webActions)) { | |
$version = $modx->getVersionData(); | |
if (version_compare($version['full_version'],'2.1.1-pl') >= 0) { | |
if ($modx->user->hasSessionContext($modx->context->get('key'))) { | |
$_SERVER['HTTP_MODAUTH'] = $_SESSION["modx.{$modx->context->get('key')}.user.token"]; | |
} else { | |
$_SESSION["modx.{$modx->context->get('key')}.user.token"] = 0; | |
$_SERVER['HTTP_MODAUTH'] = 0; | |
} | |
} else { | |
$_SERVER['HTTP_MODAUTH'] = $modx->site_id; | |
} | |
$_REQUEST['HTTP_MODAUTH'] = $_SERVER['HTTP_MODAUTH']; | |
} | |
/* handle request */ | |
$corePath = $modx->getOption('my_extra.core_path', null, $modx->getOption('core_path') . 'components/my_extra/'); | |
$modx->request->handleRequest(array( | |
'processors_path' => $corePath . 'processors/', | |
'location' => '', | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment