Skip to content

Instantly share code, notes, and snippets.

@chadhutchins
Last active December 6, 2019 18:00
Show Gist options
  • Save chadhutchins/db4e4c84340badc29c36 to your computer and use it in GitHub Desktop.
Save chadhutchins/db4e4c84340badc29c36 to your computer and use it in GitHub Desktop.
Proxy Script to allow Sugar to Receive MailChimp Webhooks using SugarChimp
<?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