?php ; n fixUrls_url($matches) { $uri = $matches[3]; $urlPrefix = $GLOBALS['urlPrefix']; if (preg_match("#http(s)?://users2.focalbeam.com#i", $uri)) { $uri = preg_replace("#^http://(.+\.)?focalbeam.com#i", rtrim($urlPrefix, '/'), $uri); return $matches[1] . $matches[2] . $uri . $matches[4]; } if (preg_match("#^(mailto|http[s]?://)#i", $uri)) return $matches[1] . $matches[2] . $uri . $matches[4]; if (! preg_match("#^/#", $uri)) { $requestUri = $_SERVER['REQUEST_URI']; if (! preg_match("#/$#", $requestUri)) $urlPrefix .= trim(preg_replace("#/[^/]+$#", '', $requestUri), '/') . '/'; } return $matches[1] . $matches[2] . $urlPrefix . ltrim($uri, '/') . $matches[4]; } //###################################################################### function fixUrls(&$str) { //Wrap or fix all the urls as appropriate. $arr = array('#(href=)([\"\'])(.+)(\\2)#siU', '#(action=)([\"\'])(.+)(\\2)#siU', '#(src=)([\"\'])(.+)(\\2)#siU', '#(window.location=)([\"\'])(.+)(\\2)#siU', ); $str = preg_replace_callback($arr, 'fixUrls_url', $str); } $passHeaders = array('expires', 'cache-control', 'pragma', 'last-modified', 'accept-ranges', 'content-disposition', 'connection', 'content-type', 'location', 'etag'); //###################################################################### function handleHeaders($str) { $arr = explode("\r\n", $str); array_shift($arr); foreach ($arr as $line) { $parts = preg_split("#:[ ]+#", $line); if ($parts[0] == 'x_AD_forceRedirect') { header('Location: ' . $parts[1]); exit; } if (in_array(strtolower($parts[0]), $GLOBALS['passHeaders'])) { header(rtrim($line)); } } } //###################################################################### function handleBody($str) { $contentType = NULL; foreach (headers_list() as $header) { $arr = preg_split("#:[ ]+#", $header); if (strcasecmp($arr[0], 'content-type') == 0) { $type = $arr[1]; $contentType = preg_replace("#[ ]*;.+$#", '', $type); break; } } if (($contentType == 'text/html') || (! $contentType)) { fixUrls($str); } header('Content-Length: ' . strlen($str)); echo $str; } //###################################################################### //###################################################################### $uri = ltrim($_SERVER['REQUEST_URI'], '/'); if (preg_match("#^fs/#", $uri)) { /* Do nothing, it's already an /fs/ url. 2012/11/10 -- After we convert to the obfuscated urls and wait a while, we can remove this. */ } else { //It's an obfuscated distribution url. Pass it on with the right prefix to have it deobfuscated. $uri = 'fs/d:obfuscated/' . $uri; } //Determine the master server to forward to. //If _s=2 is present, route to the new master; otherwise route to the original. if (isset($_GET['_s']) && $_GET['_s'] == '2') { $masterHost = 'sites2.focalbeam.com'; //Strip the _s param from the URI so the master doesn't see it. $uri = preg_replace('#([?&])_s=2(&|$)#', '$1', $uri); $uri = rtrim($uri, '?&'); } else { $masterHost = 'sites.focalbeam.com'; } $uri .= (strstr($uri, '?') ? '&' : '?') . 'AD_LEAF_TUNNEL=1&AD_LEAF_REMOTE_ADDR=' . urlencode($_SERVER['REMOTE_ADDR']) . '&AD_LEAF_HTTP_HOST=' . urlencode($_SERVER['HTTP_HOST']); $opts = array( CURLOPT_URL => 'http://' . $masterHost . '/' . $uri, CURLOPT_AUTOREFERER => true, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_FOLLOWLOCATION => true ); $ch = curl_init(); curl_setopt_array($ch, $opts); $str = curl_exec($ch); curl_close($ch); list($header, $str) = preg_split("#\r\n\r\n#", $str, 2); handleHeaders($header); handleBody($str); ?> $urlPrefix = '/'; //###################################################################### function fixUrls_url($matches) { $uri = $matches[3]; $urlPrefix = $GLOBALS['urlPrefix']; if (preg_match("#http(s)?://users.focalbeam.com#i", $uri)) { $uri = preg_replace("#^http://(.+\.)?focalbeam.com#i", rtrim($urlPrefix, '/'), $uri); return $matches[1] . $matches[2] . $uri . $matches[4]; } if (preg_match("#^(mailto|http[s]?://)#i", $uri)) return $matches[1] . $matches[2] . $uri . $matches[4]; if (! preg_match("#^/#", $uri)) { $requestUri = $_SERVER['REQUEST_URI']; if (! preg_match("#/$#", $requestUri)) $urlPrefix .= trim(preg_replace("#/[^/]+$#", '', $requestUri), '/') . '/'; } return $matches[1] . $matches[2] . $urlPrefix . ltrim($uri, '/') . $matches[4]; } //###################################################################### function fixUrls(&$str) { //Wrap or fix all the urls as appropriate. $arr = array('#(href=)([\"\'])(.+)(\\2)#siU', '#(action=)([\"\'])(.+)(\\2)#siU', '#(src=)([\"\'])(.+)(\\2)#siU', '#(window.location=)([\"\'])(.+)(\\2)#siU', ); $str = preg_replace_callback($arr, 'fixUrls_url', $str); } $passHeaders = array('expires', 'cache-control', 'pragma', 'last-modified', 'accept-ranges', 'content-disposition', 'connection', 'content-type', 'location', 'etag'); //###################################################################### function handleHeaders($str) { $arr = explode("\r\n", $str); array_shift($arr); foreach ($arr as $line) { $parts = preg_split("#:[ ]+#", $line); if ($parts[0] == 'x_AD_forceRedirect') { header('Location: ' . $parts[1]); exit; } if (in_array(strtolower($parts[0]), $GLOBALS['passHeaders'])) { header(rtrim($line)); } } } //###################################################################### function handleBody($str) { $contentType = NULL; foreach (headers_list() as $header) { $arr = preg_split("#:[ ]+#", $header); if (strcasecmp($arr[0], 'content-type') == 0) { $type = $arr[1]; $contentType = preg_replace("#[ ]*;.+$#", '', $type); break; } } if (($contentType == 'text/html') || (! $contentType)) { fixUrls($str); } header('Content-Length: ' . strlen($str)); echo $str; } //###################################################################### //###################################################################### $uri = ltrim($_SERVER['REQUEST_URI'], '/'); if (preg_match("#^fs/#", $uri)) { /* Do nothing, it's already an /fs/ url. 2012/11/10 -- After we convert to the obfuscated urls and wait a while, we can remove this. */ } else { //It's an obfuscated distribution url. Pass it on with the right prefix to have it deobfuscated. $uri = 'fs/d:obfuscated/' . $uri; } $uri .= (strstr($uri, '?') ? '&' : '?') . 'AD_LEAF_TUNNEL=1&AD_LEAF_REMOTE_ADDR=' . urlencode($_SERVER['REMOTE_ADDR']) . '&AD_LEAF_HTTP_HOST=' . urlencode($_SERVER['HTTP_HOST']); $opts = array( CURLOPT_URL => 'http://sites.focalbeam.com/' . $uri, CURLOPT_AUTOREFERER => true, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_BINARYTRANSFER => true, ); $ch = curl_init(); curl_setopt_array($ch, $opts); $str = curl_exec($ch); curl_close($ch); list($header, $str) = preg_split("#\r\n\r\n#", $str, 2); handleHeaders($header); handleBody($str); ?> l?php ; $urlPrefix = '/'; //###################################################################### function fixUrls_url($matches) { $uri = $matches[3]; $urlPrefix = $GLOBALS['urlPrefix']; if (preg_match("#http(s)?://users.focalbeam.com#i", $uri)) { $uri = preg_replace("#^http://(.+\.)?focalbeam.com#i", rtrim($urlPrefix, '/'), $uri); return $matches[1] . $matches[2] . $uri . $matches[4]; } if (preg_match("#^(mailto|http[s]?://)#i", $uri)) return $matches[1] . $matches[2] . $uri . $matches[4]; if (! preg_match("#^/#", $uri)) { $requestUri = $_SERVER['REQUEST_URI']; if (! preg_match("#/$#", $requestUri)) $urlPrefix .= trim(preg_replace("#/[^/]+$#", '', $requestUri), '/') . '/'; } return $matches[1] . $matches[2] . $urlPrefix . ltrim($uri, '/') . $matches[4]; } //###################################################################### function fixUrls(&$str) { //Wrap or fix all the urls as appropriate. $arr = array('#(href=)([\"\'])(.+)(\\2)#siU', '#(action=)([\"\'])(.+)(\\2)#siU', '#(src=)([\"\'])(.+)(\\2)#siU', '#(window.location=)([\"\'])(.+)(\\2)#siU', ); $str = preg_replace_callback($arr, 'fixUrls_url', $str); } $passHeaders = array('expires', 'cache-control', 'pragma', 'last-modified', 'accept-ranges', 'content-disposition', 'connection', 'content-type', 'location', 'etag'); //###################################################################### function handleHeaders($str) { $arr = explode("\r\n", $str); array_shift($arr); foreach ($arr as $line) { $parts = preg_split("#:[ ]+#", $line); if ($parts[0] == 'x_AD_forceRedirect') { header('Location: ' . $parts[1]); exit; } if (in_array(strtolower($parts[0]), $GLOBALS['passHeaders'])) { header(rtrim($line)); } } } //###################################################################### function handleBody($str) { $contentType = NULL; foreach (headers_list() as $header) { $arr = preg_split("#:[ ]+#", $header); if (strcasecmp($arr[0], 'content-type') == 0) { $type = $arr[1]; $contentType = preg_replace("#[ ]*;.+$#", '', $type); break; } } if (($contentType == 'text/html') || (! $contentType)) { fixUrls($str); } header('Content-Length: ' . strlen($str)); echo $str; } //###################################################################### //###################################################################### $uri = ltrim($_SERVER['REQUEST_URI'], '/'); if (preg_match("#^fs/#", $uri)) { /* Do nothing, it's already an /fs/ url. 2012/11/10 -- After we convert to the obfuscated urls and wait a while, we can remove this. */ } else { //It's an obfuscated distribution url. Pass it on with the right prefix to have it deobfuscated. $uri = 'fs/d:obfuscated/' . $uri; } $uri .= (strstr($uri, '?') ? '&' : '?') . 'AD_LEAF_TUNNEL=1&AD_LEAF_REMOTE_ADDR=' . urlencode($_SERVER['REMOTE_ADDR']) . '&AD_LEAF_HTTP_HOST=' . urlencode($_SERVER['HTTP_HOST']); $opts = array( CURLOPT_URL => 'http://sites.focalbeam.com/' . $uri, CURLOPT_AUTOREFERER => true, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_BINARYTRANSFER => true, ); $ch = curl_init(); curl_setopt_array($ch, $opts); $str = curl_exec($ch); curl_close($ch); list($header, $str) = preg_split("#\r\n\r\n#", $str, 2); handleHeaders($header); handleBody($str); ?>