Last active
December 6, 2019 18:00
-
-
Save chadhutchins/db4e4c84340badc29c36 to your computer and use it in GitHub Desktop.
Proxy Script to allow Sugar to Receive MailChimp Webhooks using SugarChimp
This file contains 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 | |
/** | |
If you want to keep your SugarCRM server non-accessible from the outside web | |
But you still want to receive MailChimp updates with SugarChimp, this script will help you do so | |
You need to make this script accessible from the outside web and it will allow MailChimp to connect to Sugar through the SuagrChimpWebhook entrypoint | |
All other Sugar requests will get ignored | |
Be sure to change the $sugar_url variable to the path of your index.php script inside your Sugar folder | |
*/ | |
// CHANGE THIS LINE BELOW TO YOUR SUGAR INSTANCE URL | |
$sugar_url = "http://url-to-my-sugar-instance.com/index.php"; | |
if ($_REQUEST['module'] == 'SugarChimp') | |
{ | |
$ch = curl_init(); | |
if ($_REQUEST['entryPoint'] == 'SugarChimpWebhook') | |
{ | |
curl_setopt($ch, CURLOPT_URL, $sugar_url . "?module=SugarChimp&entryPoint=SugarChimpWebhook"); | |
$post_data_array = array( | |
'type' => $_REQUEST['type'], | |
'data' => $_REQUEST['data'], | |
); | |
$post_data_string = http_build_query($post_data_array); | |
curl_setopt($ch,CURLOPT_POST, 1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data_string); | |
} | |
else if ($_REQUEST['entryPoint'] == 'OAuthTokenCapture') | |
{ | |
$args = array( | |
'state' => $_REQUEST['state'], | |
'token' => $_REQUEST['token'], | |
'module' => 'SugarChimp', | |
'entryPoint' => 'OAuthTokenCapture', | |
); | |
$query = http_build_query($args); | |
curl_setopt($ch, CURLOPT_URL, $sugar_url . "?" . $query); | |
} | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); | |
curl_exec($ch); | |
curl_close($ch); | |
unset($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment