implementing #20

This commit is contained in:
systopia 2018-03-01 10:15:59 +01:00
parent 9f1caed052
commit 2346076e72
2 changed files with 27 additions and 12 deletions

View File

@ -8,7 +8,7 @@
+---------------------------------------------------------*/
require_once "config.php";
$civiproxy_version = '0.5.beta1';
$civiproxy_version = '0.5.beta1+dev20';
$civiproxy_logo = "<img src='{$proxy_base}/static/images/proxy-logo.png' alt='SYSTOPIA Organisationsberatung'></img>";
/**
@ -165,17 +165,12 @@ function civiproxy_security_check($target, $quit=TRUE) {
*
* @param $valid_parameters array '<parameter name> => '<expected type>'
* where type can be 'int', 'string' (unchecked),
* @param $request provides the request data to use,
* defaults to $_REQUEST
*/
function civiproxy_get_parameters($valid_parameters) {
$request = $_REQUEST;
// explode civicrm's json parameter
global $evaluate_json_parameter;
if (!emtpy($evaluate_json_parameter) && isset($request['json'])) {
$json_data = json_decode($request['json']);
if (is_array($json_data)) {
$request = $request + $json_data;
}
function civiproxy_get_parameters($valid_parameters, $request = NULL) {
if ($request === NULL) {
$request = $_REQUEST;
}
$result = array();
@ -231,6 +226,14 @@ function civiproxy_sanitise($value, $type) {
error_log("CiviProxy: removed invalid email parameter: " . $value);
$value = '';
}
} elseif ($type == 'json') {
// valid json
$json_data = json_decode($value);
if ($json_data === NULL) {
$value = '';
} else {
$value = json_encode($value);
}
} elseif (is_array($type)) {
// this is a list of valid options
$requested_value = $value;

View File

@ -64,7 +64,7 @@ if (isset($rest_allowed_actions['all'])) {
} else {
civiproxy_rest_error("Invalid entity/action.");
}
}
}
// extract parameters and add credentials and action data
$parameters = civiproxy_get_parameters($valid_parameters);
@ -75,6 +75,18 @@ foreach ($action as $key => $value) {
$parameters[$key] = $value;
}
// evaluate the JSON parameter
global $evaluate_json_parameter;
if ($evaluate_json_parameter) {
if (isset($_REQUEST['json'])) {
$json_data = json_decode($_REQUEST['json']);
if (!empty($json_data)) {
$json_parameters = civiproxy_get_parameters($valid_parameters, $json_data);
$parameters['json'] = json_encode($json_parameters);
}
}
}
// finally execute query
civiproxy_redirect($target_rest, $parameters);