added base URL to getCallingURL()

This commit is contained in:
Roland Gruber 2019-03-09 11:10:42 +01:00
parent 19ea7dd3dd
commit 4f04dcb48e
2 changed files with 47 additions and 3 deletions

View File

@ -1465,11 +1465,15 @@ function getDefaultLDAPErrorString($server) {
* Returns the URL under which the page was loaded.
* This includes any GET parameters set.
*
* @param $baseUrl base URL (e.g. http://www.example.com)
* @return String URL
*/
function getCallingURL() {
function getCallingURL($baseUrl = '') {
$url = null;
if (!empty($_SERVER['HTTP_HOST']) && !empty($_SERVER['REQUEST_URI'])) {
if (!empty($baseUrl) && !empty($_SERVER['REQUEST_URI'])) {
$url = $baseUrl . $_SERVER['REQUEST_URI'];
}
elseif (!empty($_SERVER['REQUEST_URI']) && !empty($_SERVER['HTTP_HOST'])) {
$proto = 'http://';
if (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) {
$proto = 'https://';

View File

@ -19,7 +19,8 @@
*/
include_once 'lam/lib/account.inc';
include_once __DIR__ . '/../../lib/account.inc';
include_once __DIR__ . '/../../lib/security.inc';
/**
* LAMConfig test case.
@ -88,4 +89,43 @@ class AccountTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('', formatSecondsToShortFormat(''));
}
/**
* Tests getCallingURL().
*/
function testGetCallingURL_noBaseUrl_noHost() {
$_SERVER['REQUEST_URI'] = '/test.php';
$_SERVER['HTTP_HOST'] = null;
$_SERVER['HTTP_REFERER'] = 'http://referrer/test.php';
$_SERVER['HTTPS'] = 'on';
$this->assertEquals('http://referrer/test.php', getCallingURL());
$_SERVER['HTTP_REFERER'] = null;
$this->assertNull(getCallingURL());
}
/**
* Tests getCallingURL().
*/
function testGetCallingURL_noBaseUrl_host() {
$_SERVER['REQUEST_URI'] = '/test.php';
$_SERVER['HTTP_HOST'] = 'host';
$_SERVER['HTTP_REFERER'] = 'http://referrer/test.php';
$_SERVER['HTTPS'] = 'on';
$this->assertEquals('https://host/test.php', getCallingURL());
$_SERVER['HTTP_REFERER'] = null;
$this->assertEquals('https://host/test.php', getCallingURL());
}
/**
* Tests getCallingURL().
*/
function testGetCallingURL_baseUrl_host() {
$_SERVER['REQUEST_URI'] = '/test.php';
$_SERVER['HTTP_HOST'] = 'host';
$_SERVER['HTTP_REFERER'] = 'http://referrer/test.php';
$_SERVER['HTTPS'] = 'on';
$this->assertEquals('http://base/test.php', getCallingURL('http://base'));
$_SERVER['HTTP_REFERER'] = null;
$this->assertEquals('http://base/test.php', getCallingURL('http://base'));
}
}