implementing REST
This commit is contained in:
parent
d9012e3d7b
commit
e9bf065bd8
|
|
@ -2,5 +2,5 @@ TODO
|
||||||
|
|
||||||
1) make index page nice (real html)
|
1) make index page nice (real html)
|
||||||
2) REST error -> set headers?
|
2) REST error -> set headers?
|
||||||
3) replace URLs
|
3) file cache => http://pear.php.net/manual/en/package.caching.cache-lite.cache-lite.cache-lite.php
|
||||||
4) file cache?
|
4) config page for extension
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,23 @@
|
||||||
|
|
||||||
|
|
||||||
// this is the primary variable that you would want to change
|
// this is the primary variable that you would want to change
|
||||||
//$target_civicrm = 'https://civicrm.muslimehelfen.org';
|
|
||||||
$target_civicrm = 'http://localhost:8888/mh';
|
$target_civicrm = 'http://localhost:8888/mh';
|
||||||
|
$proxy_base = 'http://localhost:8888/proxy';
|
||||||
|
|
||||||
|
// default paths, override if you want
|
||||||
|
$target_rest = $target_civicrm . '/sites/all/modules/civicrm/extern/rest.php';
|
||||||
|
$target_url = $target_civicrm . '/sites/all/modules/civicrm/extern/url.php';
|
||||||
|
$target_open = $target_civicrm . '/sites/all/modules/civicrm/extern/open.php';
|
||||||
|
|
||||||
// API and SITE keys
|
// API and SITE keys
|
||||||
$api_key_map = array();
|
$api_key_map = array();
|
||||||
$sys_key_map = array();
|
$sys_key_map = array();
|
||||||
|
|
||||||
if (file_exists("secrets.php")) {
|
if (file_exists("secrets.php")) {
|
||||||
// keys can also be stored in secrets php
|
// keys can also be stored in 'secrets.php'
|
||||||
require_once "secrets.php";
|
require_once "secrets.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// default paths, override if you want
|
|
||||||
$target_rest = $target_civicrm . '/sites/all/modules/civicrm/extern/rest.php';
|
|
||||||
$target_url = $target_civicrm . '/sites/all/modules/civicrm/extern/url.php';
|
|
||||||
$target_open = $target_civicrm . '/sites/all/modules/civicrm/extern/open.php';
|
|
||||||
|
|
||||||
// define the REST actions that will be allowed
|
// define the REST actions that will be allowed
|
||||||
$rest_allowed_actions = array(
|
$rest_allowed_actions = array(
|
||||||
'MhApi' => array(
|
'MhApi' => array(
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
$civiproxy_version = '0.1';
|
$civiproxy_version = '0.1';
|
||||||
require_once "config.php";
|
require_once "config.php";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this will redirect the request to another URL,
|
* this will redirect the request to another URL,
|
||||||
* i.e. will pass the reply on to this request
|
* i.e. will pass the reply on to this request
|
||||||
|
|
@ -21,8 +20,8 @@ require_once "config.php";
|
||||||
* where type can be 'int', 'string' (unchecked),
|
* where type can be 'int', 'string' (unchecked),
|
||||||
*/
|
*/
|
||||||
function civiproxy_redirect($url_requested, $parameters) {
|
function civiproxy_redirect($url_requested, $parameters) {
|
||||||
error_log('CALLING: '.$url_requested);
|
// error_log('CALLING: '.$url_requested);
|
||||||
error_log(print_r($parameters,1));
|
// error_log(print_r($parameters,1));
|
||||||
|
|
||||||
$url = $url_requested;
|
$url = $url_requested;
|
||||||
$curlSession = curl_init();
|
$curlSession = curl_init();
|
||||||
|
|
@ -70,18 +69,17 @@ function civiproxy_redirect($url_requested, $parameters) {
|
||||||
$body = $content[1];
|
$body = $content[1];
|
||||||
|
|
||||||
// handle headers - simply re-outputing them
|
// handle headers - simply re-outputing them
|
||||||
$header_ar = split(chr(10), $header);
|
$header_ar = explode(chr(10), $header);
|
||||||
foreach ($header_ar as $header_line){
|
foreach ($header_ar as $header_line){
|
||||||
if (!preg_match("/^Transfer-Encoding/", $header_line)){
|
if (!preg_match("/^Transfer-Encoding/", $header_line)){
|
||||||
// TODO: replace returned URLs
|
civiproxy_mend_URLs($header_line);
|
||||||
//$header_line = str_replace($url, "TODO://", $header_line);
|
|
||||||
header(trim($header_line));
|
header(trim($header_line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do we need this?
|
|
||||||
//rewrite all hard coded urls to ensure the links still work!
|
//rewrite all hard coded urls to ensure the links still work!
|
||||||
//$body = str_replace($base,$mydomain,$body);
|
civiproxy_mend_URLs($body);
|
||||||
|
|
||||||
print $body;
|
print $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,6 +87,16 @@ function civiproxy_redirect($url_requested, $parameters) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will mend all the URLs in the string that point to the target,
|
||||||
|
* so they will point to this proxy instead
|
||||||
|
*/
|
||||||
|
function civiproxy_mend_URLs(&$string) {
|
||||||
|
// TODO: this will become more complex with the file cache
|
||||||
|
global $target_civicrm, $proxy_base;
|
||||||
|
$string = preg_replace("#$target_civicrm#", $proxy_base, $string);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will check the incoming connection.
|
* Will check the incoming connection.
|
||||||
* This hook allowes for (future) checks for flooding, spoofing,
|
* This hook allowes for (future) checks for flooding, spoofing,
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,7 @@ if (!civiproxy_security_check('rest')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check credentials
|
// check credentials
|
||||||
error_log(print_r($_REQUEST,1));
|
|
||||||
$credentials = civiproxy_get_parameters(array('key' => 'string', 'api_key' => 'string'));
|
$credentials = civiproxy_get_parameters(array('key' => 'string', 'api_key' => 'string'));
|
||||||
error_log(print_r($credentials,1));
|
|
||||||
if (empty($credentials['key'])) {
|
if (empty($credentials['key'])) {
|
||||||
civiproxy_rest_error("No site key given");
|
civiproxy_rest_error("No site key given");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue