implementing #20

This commit is contained in:
systopia 2018-03-01 11:08:44 +01:00
parent 2346076e72
commit a23f0cfb05
3 changed files with 20 additions and 10 deletions

View File

@ -36,10 +36,10 @@ $target_mail_view = $target_civicrm . '/civicrm/mailing/view';
** GENERAL OPTIONS ** ** GENERAL OPTIONS **
****************************************************************/ ****************************************************************/
// if you enable this, the system will also try to // This logo is shown if the proxy server is address with a web browser
// parse a parameter called 'json' as a JSON file // add your own logo here
// when looking for a certain parameter $civiproxy_logo = "<img src='{$proxy_base}/static/images/proxy-logo.png' alt='SYSTOPIA Organisationsberatung'></img>";
$evaluate_json_parameter = FALSE;
// Set api-key for mail subscribe/unsubscribe user // Set api-key for mail subscribe/unsubscribe user
// Set to NULL/FALSE to disable the feature // Set to NULL/FALSE to disable the feature
@ -86,6 +86,12 @@ $file_cache_include = array(
/**************************************************************** /****************************************************************
** REST API OPTIONS ** ** REST API OPTIONS **
****************************************************************/ ****************************************************************/
// if you enable this, the system will also try to
// parse the 'json' parameter, which holds additional
// input data according to the CiviCRM REST API specs
$rest_evaluate_json_parameter = FALSE;
// whitelisting is done per IP address ($_SERVER['REMOTE_ADDR']) with a 'all' for the generic stuff that applies to all IP addresses // whitelisting is done per IP address ($_SERVER['REMOTE_ADDR']) with a 'all' for the generic stuff that applies to all IP addresses
// - if a request comes in and the IP is not a key in the array, the whitelisted in 'all' are used // - if a request comes in and the IP is not a key in the array, the whitelisted in 'all' are used
// - if a request comes in and the IP is indeed a key in the array, the whitelisted in the IP are checked first. If nothing is // - if a request comes in and the IP is indeed a key in the array, the whitelisted in the IP are checked first. If nothing is

View File

@ -8,8 +8,7 @@
+---------------------------------------------------------*/ +---------------------------------------------------------*/
require_once "config.php"; require_once "config.php";
$civiproxy_version = '0.5.beta1+dev20'; $civiproxy_version = '0.6.dev1';
$civiproxy_logo = "<img src='{$proxy_base}/static/images/proxy-logo.png' alt='SYSTOPIA Organisationsberatung'></img>";
/** /**
* this will redirect the request to another URL, * this will redirect the request to another URL,
@ -228,12 +227,17 @@ function civiproxy_sanitise($value, $type) {
} }
} elseif ($type == 'json') { } elseif ($type == 'json') {
// valid json // valid json
$json_data = json_decode($value); $json_data = json_decode($value, true);
if ($json_data === NULL) { if ($json_data === NULL) {
$value = ''; $value = '';
} else { } else {
$value = json_encode($value); $value = json_encode($value);
} }
} elseif ($type == 'array') {
// this should only happen _inside_ the json field
if (!is_array($value)) {
$value = '';
}
} elseif (is_array($type)) { } elseif (is_array($type)) {
// this is a list of valid options // this is a list of valid options
$requested_value = $value; $requested_value = $value;

View File

@ -76,10 +76,10 @@ foreach ($action as $key => $value) {
} }
// evaluate the JSON parameter // evaluate the JSON parameter
global $evaluate_json_parameter; global $rest_evaluate_json_parameter;
if ($evaluate_json_parameter) { if ($rest_evaluate_json_parameter) {
if (isset($_REQUEST['json'])) { if (isset($_REQUEST['json'])) {
$json_data = json_decode($_REQUEST['json']); $json_data = json_decode($_REQUEST['json'], true);
if (!empty($json_data)) { if (!empty($json_data)) {
$json_parameters = civiproxy_get_parameters($valid_parameters, $json_data); $json_parameters = civiproxy_get_parameters($valid_parameters, $json_data);
$parameters['json'] = json_encode($json_parameters); $parameters['json'] = json_encode($json_parameters);