diff --git a/proxy/TODO.txt b/proxy/TODO.txt index 772309c..9a0bf0c 100644 --- a/proxy/TODO.txt +++ b/proxy/TODO.txt @@ -2,5 +2,5 @@ TODO 1) make index page nice (real html) 2) REST error -> set headers? -3) replace URLs -4) file cache? +3) file cache => http://pear.php.net/manual/en/package.caching.cache-lite.cache-lite.cache-lite.php +4) config page for extension diff --git a/proxy/config.php b/proxy/config.php index 0d7bd45..96f468f 100644 --- a/proxy/config.php +++ b/proxy/config.php @@ -9,24 +9,23 @@ // this is the primary variable that you would want to change -//$target_civicrm = 'https://civicrm.muslimehelfen.org'; $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_key_map = array(); $sys_key_map = array(); 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"; } - -// 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 $rest_allowed_actions = array( 'MhApi' => array( diff --git a/proxy/proxy.php b/proxy/proxy.php index 2e9994c..3d98efe 100644 --- a/proxy/proxy.php +++ b/proxy/proxy.php @@ -10,7 +10,6 @@ $civiproxy_version = '0.1'; require_once "config.php"; - /** * this will redirect the request to another URL, * 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), */ function civiproxy_redirect($url_requested, $parameters) { - error_log('CALLING: '.$url_requested); - error_log(print_r($parameters,1)); + // error_log('CALLING: '.$url_requested); + // error_log(print_r($parameters,1)); $url = $url_requested; $curlSession = curl_init(); @@ -70,18 +69,17 @@ function civiproxy_redirect($url_requested, $parameters) { $body = $content[1]; // handle headers - simply re-outputing them - $header_ar = split(chr(10), $header); + $header_ar = explode(chr(10), $header); foreach ($header_ar as $header_line){ if (!preg_match("/^Transfer-Encoding/", $header_line)){ - // TODO: replace returned URLs - //$header_line = str_replace($url, "TODO://", $header_line); + civiproxy_mend_URLs($header_line); header(trim($header_line)); } } - // TODO: do we need this? //rewrite all hard coded urls to ensure the links still work! - //$body = str_replace($base,$mydomain,$body); + civiproxy_mend_URLs($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. * This hook allowes for (future) checks for flooding, spoofing, diff --git a/proxy/rest.php b/proxy/rest.php index 669c135..2d588df 100644 --- a/proxy/rest.php +++ b/proxy/rest.php @@ -17,9 +17,7 @@ if (!civiproxy_security_check('rest')) { } // check credentials -error_log(print_r($_REQUEST,1)); $credentials = civiproxy_get_parameters(array('key' => 'string', 'api_key' => 'string')); -error_log(print_r($credentials,1)); if (empty($credentials['key'])) { civiproxy_rest_error("No site key given"); } else {