-
Notifications
You must be signed in to change notification settings - Fork 98
/
redirect.php
92 lines (82 loc) · 2.19 KB
/
redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* EGroupware save redirect script
*
* idea by: Jason Wies
* doing and adding to cvs: Lars Kneschke
*
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/
use EGroupware\Api;
/*
Use this script when you want to link to a external url.
This way you don't send something like sessionid as referer
Use this in your app:
"<a href=\"$webserverURL/redirect.php?go=".htmlentities(urlencode('http://www.egroupware.org')).'">'
*/
if(!function_exists('html_entity_decode'))
{
function html_entity_decode($given_html, $quote_style = ENT_QUOTES)
{
$trans_table = array_flip(get_html_translation_table( HTML_SPECIALCHARS, $quote_style));
$trans_table['''] = "'";
return(strtr($given_html, $trans_table));
}
}
/* Only allow redirects with a valid session */
$GLOBALS['egw_info'] = array(
'flags' => array(
'noheader' => True,
'nonavbar' => True,
'currentapp' => 'home'
)
);
include('./header.inc.php');
/* Only allow redirects from inside this eGroupware installation. */
$valid_referer = array();
$path = preg_replace('/\/[^\/]*$/','',$_SERVER['PHP_SELF']) . '/';
array_push($valid_referer, $path);
array_push($valid_referer, Api\Header\Http::schema() . '//' . $_SERVER['SERVER_ADDR'] . $path);
array_push($valid_referer, Api\Framework::getUrl($path));
$referrer = trim($_SERVER['HTTP_REFERER']);
if ((!isset($_SERVER['HTTP_REFERER'])) || (empty($referrer)))
{
echo "Only usable from within eGroupware.\n";
}
else if($_GET['go'])
{
$allow = false;
foreach ($valid_referer as $urlRoot)
{
/* Check if the referrer begins with a valid URL. */
if (strncmp($urlRoot, $referrer, strlen($urlRoot)) == 0)
{
$allow = true;
break;
}
}
if ($allow)
{
$url= html_entity_decode(urldecode($_GET['go']));
unset($_GET['go']);
/* Only add "&" if there is something to append. */
if (!empty($_GET))
{
$url=$url."&".http_build_query($_GET);
}
Header('Location: ' . html_entity_decode(urldecode($url)));
exit;
}
else
{
echo "Redirect not allowed for referrer '".$_SERVER['HTTP_REFERER']."'.\n";
echo "<pre>";
print_r($valid_referer);
echo "<pre>\n";
}
}
else
{
echo "Error redirecting.";
}