mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/11215] Correct paths when path info is used for controller access
PHPBB3-11215
This commit is contained in:
parent
2d7a91ebd6
commit
c20f92ba1e
3 changed files with 52 additions and 14 deletions
|
@ -24,7 +24,6 @@ $user->session_begin();
|
||||||
$auth->acl($user->data);
|
$auth->acl($user->data);
|
||||||
$user->setup('app');
|
$user->setup('app');
|
||||||
|
|
||||||
$symfony_request = phpbb_create_symfony_request($request);
|
|
||||||
$http_kernel = $phpbb_container->get('http_kernel');
|
$http_kernel = $phpbb_container->get('http_kernel');
|
||||||
$response = $http_kernel->handle($symfony_request);
|
$response = $http_kernel->handle($symfony_request);
|
||||||
$response->send();
|
$response->send();
|
||||||
|
|
|
@ -109,6 +109,9 @@ $db = $phpbb_container->get('dbal.conn');
|
||||||
// make sure request_var uses this request instance
|
// make sure request_var uses this request instance
|
||||||
request_var('', 0, false, false, $request); // "dependency injection" for a function
|
request_var('', 0, false, false, $request); // "dependency injection" for a function
|
||||||
|
|
||||||
|
// Create a Symfony Request object from our phpbb_request object
|
||||||
|
$symfony_request = phpbb_create_symfony_request($request);
|
||||||
|
|
||||||
// Grab global variables, re-cache if necessary
|
// Grab global variables, re-cache if necessary
|
||||||
$config = $phpbb_container->get('config');
|
$config = $phpbb_container->get('config');
|
||||||
set_config(null, null, null, $config);
|
set_config(null, null, null, $config);
|
||||||
|
|
|
@ -2413,6 +2413,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
||||||
{
|
{
|
||||||
global $_SID, $_EXTRA_URL, $phpbb_hook;
|
global $_SID, $_EXTRA_URL, $phpbb_hook;
|
||||||
global $phpbb_dispatcher;
|
global $phpbb_dispatcher;
|
||||||
|
global $request;
|
||||||
|
|
||||||
if ($params === '' || (is_array($params) && empty($params)))
|
if ($params === '' || (is_array($params) && empty($params)))
|
||||||
{
|
{
|
||||||
|
@ -2420,6 +2421,12 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
||||||
$params = false;
|
$params = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$corrected_root = phpbb_get_web_root_path(phpbb_create_symfony_request($request));
|
||||||
|
if ($corrected_root)
|
||||||
|
{
|
||||||
|
$url = $corrected_root . substr($url, strlen($phpbb_root_path));
|
||||||
|
}
|
||||||
|
|
||||||
$append_sid_overwrite = false;
|
$append_sid_overwrite = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5209,7 +5216,11 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
||||||
|
|
||||||
// Determine board url - we may need it later
|
// Determine board url - we may need it later
|
||||||
$board_url = generate_board_url() . '/';
|
$board_url = generate_board_url() . '/';
|
||||||
$web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path;
|
// This path is sent with the base template paths in the assign_vars()
|
||||||
|
// call below. We need to correct it in case we are accessing from a
|
||||||
|
// controller because the web paths will be incorrect otherwise.
|
||||||
|
$corrected_path = phpbb_get_web_root_path(phpbb_create_symfony_request($request));
|
||||||
|
$web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path;
|
||||||
|
|
||||||
// Send a proper content-language to the output
|
// Send a proper content-language to the output
|
||||||
$user_lang = $user->lang['USER_LANG'];
|
$user_lang = $user->lang['USER_LANG'];
|
||||||
|
@ -5685,6 +5696,16 @@ function phpbb_convert_30_dbms_to_31($dbms)
|
||||||
*/
|
*/
|
||||||
function phpbb_create_symfony_request(phpbb_request $request)
|
function phpbb_create_symfony_request(phpbb_request $request)
|
||||||
{
|
{
|
||||||
|
// If we have already gotten it, don't go back through all the trouble of
|
||||||
|
// creating it again; instead, just return it. This allows multiple calls
|
||||||
|
// of this method so we don't have to globalize $symfony_request in other
|
||||||
|
// functions.
|
||||||
|
static $symfony_request;
|
||||||
|
if (null !== $symfony_request)
|
||||||
|
{
|
||||||
|
return $symfony_request;
|
||||||
|
}
|
||||||
|
|
||||||
// This function is meant to sanitize the global input arrays
|
// This function is meant to sanitize the global input arrays
|
||||||
$sanitizer = function(&$value, $key) {
|
$sanitizer = function(&$value, $key) {
|
||||||
$type_cast_helper = new phpbb_request_type_cast_helper();
|
$type_cast_helper = new phpbb_request_type_cast_helper();
|
||||||
|
@ -5704,21 +5725,36 @@ function phpbb_create_symfony_request(phpbb_request $request)
|
||||||
array_walk_recursive($get_parameters, $sanitizer);
|
array_walk_recursive($get_parameters, $sanitizer);
|
||||||
array_walk_recursive($post_parameters, $sanitizer);
|
array_walk_recursive($post_parameters, $sanitizer);
|
||||||
|
|
||||||
// Until we fix the issue with relative paths, we have to fake path info
|
$symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters);
|
||||||
// to allow urls like app.php?controller=foo/bar
|
return $symfony_request;
|
||||||
$controller = $request->variable('controller', '');
|
}
|
||||||
$path_info = '/' . $controller;
|
|
||||||
$request_uri = $server_parameters['REQUEST_URI'];
|
|
||||||
|
|
||||||
// Remove the query string from REQUEST_URI
|
/**
|
||||||
if ($pos = strpos($request_uri, '?'))
|
* Get a relative root path from the current URL
|
||||||
|
*
|
||||||
|
* @param Request $symfony_request Symfony Request object
|
||||||
|
*/
|
||||||
|
function phpbb_get_web_root_path(Request $symfony_request)
|
||||||
{
|
{
|
||||||
$request_uri = substr($request_uri, 0, $pos);
|
static $path;
|
||||||
|
if (null !== $path)
|
||||||
|
{
|
||||||
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the path info (i.e. controller route) to the REQUEST_URI
|
$path_info = $symfony_request->getPathInfo();
|
||||||
$server_parameters['REQUEST_URI'] = $request_uri . $path_info;
|
if ($path_info == '/')
|
||||||
$server_parameters['SCRIPT_NAME'] = '';
|
{
|
||||||
|
return '';
|
||||||
return new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters);
|
}
|
||||||
|
|
||||||
|
$corrections = substr_count($symfony_request->getPathInfo(), '/');
|
||||||
|
|
||||||
|
$path = '';
|
||||||
|
for ($i = 0; $i < $corrections; $i++)
|
||||||
|
{
|
||||||
|
$path .= '../';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue