After spending over 40 hours trying to figure this out, I think I have a variation on this solution that might be useful for those in a hosted environment. I've tested it and it seems to work. If anyone can find any problems or security issues, please post them as I'm not an expert with this and figured it out only through significant research and trial-and-error.
Create an index.php file that you will put in a directory that is accessible to the public with the following (thanx to edub for this code):
Code:
<?php
$hidden_URL = "http://www.[location of your SugarCRM index.php file that is protected]/index.php?entryPoint=";
$usrpsswd = "username:password";
if ($_REQUEST['entryPoint'] == 'removeme' || $_REQUEST['entryPoint'] == 'campaign_trackerv2' || $_REQUEST['entryPoint'] == 'image') {
if (strlen($_REQUEST['identifier']) == 36) {
$ch = curl_init();
if (strlen($_REQUEST['track']) > 0) {
curl_setopt($ch, CURLOPT_URL, $hidden_URL . $_REQUEST['entryPoint'] . "&identifier=" . $_REQUEST['identifier'] . "&track=" . $_REQUEST['track']);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_USERPWD, $usrpsswd);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$headers = curl_exec($ch);
$headerArray = explode("\n",$headers);
foreach ($headerArray as $value) {
if (substr($value,0,8) == "Location") {
header($value);
}
}
} else {
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_URL, $hidden_URL . $_REQUEST['entryPoint'] . "&identifier=" . $_REQUEST['identifier']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERPWD, $usrpsswd);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_exec($ch);
}
curl_close($ch);
unset($ch);
}
}
?> Modify the .htaccess file that comes with SugarCRM by adding the following lines before what's ever already there (or put it in a root directory and specify the appropriate subdirectories in front of index.php?entryPoint below):
Code:
SetEnvIf Request_URI "(\index.php?entryPoint=campaign_trackerv2)$" allow
SetEnvIf Request_URI "(\index.php?entryPoint=removeme)$" allow
SetEnvIf Request_URI "(\index.php?entryPoint=image)$" allow
Order allow,deny
Allow from env=allow
<Files *.*>
Order deny,allow
Deny from all
Allow from [whatever your IP address is at your office/home]
</Files>
Satisfy any
# Disable directory browsing
Options -Indexes
AuthType Basic
AuthName "Authentication required"
require valid-user
AuthUserFile "[wherever your password files are]/passwd"
Effectively, the .htaccess file keeps the public out of your SugarCRM files but allows you to access them. Then edub's code with slight modifications for sending the username and password with curl allows the public to just use index.php, but only if it's one of the 3 entry points defined in the .htaccess file (i.e., they can't just bring up index.php because they'd be required to authenticate).
Hope that helps.
- B.
Edit: Just to clarify, you must go into the admin and choose the option "Campaign Email Settings: Configure." Then change "Location of campaign tracking files (like campaign_tracker.php) " to user-defined and enter the URL directory for the index.php that you created above.
Bookmarks