Skip to content

Commit

Permalink
Extract some common checks from common.inc.php
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Jul 6, 2021
1 parent 1a2d780 commit 17f4e09
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 63 deletions.
24 changes: 24 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@
// phpcs:enable
}

if (PHP_VERSION_ID < 70205) {
die('<p>PHP 7.2.5+ is required.</p><p>Currently installed version is: ' . PHP_VERSION . '</p>');
}

// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require_once ROOT_PATH . 'libraries/vendor_config.php';

/**
* Activate autoloader
*/
if (! @is_readable(AUTOLOAD_FILE)) {
die(
'<p>File <samp>' . AUTOLOAD_FILE . '</samp> missing or not readable.</p>'
. '<p>Most likely you did not run Composer to '
. '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">'
. 'install library files</a>.</p>'
);
}

require AUTOLOAD_FILE;

global $route, $containerBuilder, $request;

require_once ROOT_PATH . 'libraries/common.inc.php';
Expand Down
24 changes: 24 additions & 0 deletions js/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
// phpcs:enable
}

if (PHP_VERSION_ID < 70205) {
die('<p>PHP 7.2.5+ is required.</p><p>Currently installed version is: ' . PHP_VERSION . '</p>');
}

// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require_once ROOT_PATH . 'libraries/vendor_config.php';

/**
* Activate autoloader
*/
if (! @is_readable(AUTOLOAD_FILE)) {
die(
'<p>File <samp>' . AUTOLOAD_FILE . '</samp> missing or not readable.</p>'
. '<p>Most likely you did not run Composer to '
. '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">'
. 'install library files</a>.</p>'
);
}

require AUTOLOAD_FILE;

chdir('..');

// Send correct type.
Expand Down
61 changes: 4 additions & 57 deletions libraries/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,68 +47,15 @@
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Tracker;

if (! defined('PHPMYADMIN')) {
exit;
}

/** @psalm-suppress InvalidGlobal */
global $containerBuilder, $errorHandler, $config, $server, $dbi, $request,
$lang, $cfg, $isConfigLoading, $auth_plugin, $route, $theme,
$urlParams, $goto, $back, $db, $table, $sql_query, $token_mismatch;

/**
* block attempts to directly run this script
*/
if (getcwd() == __DIR__) {
die('Attack stopped');
}

/**
* Minimum PHP version; can't call Core::fatalError() which uses a
* PHP 5 function, so cannot easily localize this message.
*/
if (PHP_VERSION_ID < 70205) {
die(
'<p>PHP 7.2.5+ is required.</p>'
. '<p>Currently installed version is: ' . PHP_VERSION . '</p>'
);
}

// phpcs:disable PSR1.Files.SideEffects
/**
* for verification in all procedural scripts under libraries
*/
define('PHPMYADMIN', true);
// phpcs:enable

/**
* Load vendor configuration.
*/
require_once ROOT_PATH . 'libraries/vendor_config.php';

/**
* Activate autoloader
*/
if (! @is_readable(AUTOLOAD_FILE)) {
die(
'<p>File <samp>' . AUTOLOAD_FILE . '</samp> missing or not readable.</p>'
. '<p>Most likely you did not run Composer to '
. '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">'
. 'install library files</a>.</p>'
);
}

require_once AUTOLOAD_FILE;

/**
* (TCPDF workaround)
* Avoid referring to nonexistent files (causes warnings when open_basedir is used)
* This is defined to avoid the tcpdf code to search for a directory outside of open_basedir
* See: https://github.com/phpmyadmin/phpmyadmin/issues/16709
* This value if not used but is usefull, no header logic is used for PDF exports
*/
if (! defined('K_PATH_IMAGES')) {
// phpcs:disable PSR1.Files.SideEffects
define('K_PATH_IMAGES', ROOT_PATH);
// phpcs:enable
}

$request = ServerRequestFactory::createFromGlobals();

$route = Routing::getCurrentRoute();
Expand Down
9 changes: 9 additions & 0 deletions libraries/vendor_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@
* Suffix to add to the phpMyAdmin version
*/
define('VERSION_SUFFIX', '');

/**
* TCPDF workaround. Avoid referring to nonexistent files (causes warnings when open_basedir is used).
* This is defined to avoid the TCPDF code to search for a directory outside of open_basedir.
* This value if not used but is useful, no header logic is used for PDF exports.
*
* @see https://github.com/phpmyadmin/phpmyadmin/issues/16709
*/
define('K_PATH_IMAGES', ROOT_PATH);
7 changes: 4 additions & 3 deletions setup/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
// phpcs:enable
}

/**
* Core libraries.
*/
// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require ROOT_PATH . 'setup/lib/common.inc.php';

$form_display = new ConfigForm($GLOBALS['ConfigFile']);
Expand Down
4 changes: 4 additions & 0 deletions setup/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
/** @psalm-suppress InvalidGlobal */
global $cfg;

// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require ROOT_PATH . 'setup/lib/common.inc.php';

if (@file_exists(CONFIG_FILE) && ! $cfg['DBG']['demo']) {
Expand Down
24 changes: 24 additions & 0 deletions setup/lib/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@
use PhpMyAdmin\Config\ConfigFile;
use PhpMyAdmin\DatabaseInterface;

if (PHP_VERSION_ID < 70205) {
die('<p>PHP 7.2.5+ is required.</p><p>Currently installed version is: ' . PHP_VERSION . '</p>');
}

if (! defined('PHPMYADMIN')) {
exit;
}

require_once ROOT_PATH . 'libraries/vendor_config.php';

/**
* Activate autoloader
*/
if (! @is_readable(AUTOLOAD_FILE)) {
die(
'<p>File <samp>' . AUTOLOAD_FILE . '</samp> missing or not readable.</p>'
. '<p>Most likely you did not run Composer to '
. '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">'
. 'install library files</a>.</p>'
);
}

require AUTOLOAD_FILE;

chdir('..');

if (! file_exists(ROOT_PATH . 'libraries/common.inc.php')) {
Expand Down
7 changes: 4 additions & 3 deletions setup/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
// phpcs:enable
}

/**
* Core libraries.
*/
// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require ROOT_PATH . 'setup/lib/common.inc.php';

$validators = [];
Expand Down
24 changes: 24 additions & 0 deletions url.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
// phpcs:enable
}

if (PHP_VERSION_ID < 70205) {
die('<p>PHP 7.2.5+ is required.</p><p>Currently installed version is: ' . PHP_VERSION . '</p>');
}

// phpcs:disable PSR1.Files.SideEffects
define('PHPMYADMIN', true);
// phpcs:enable

require_once ROOT_PATH . 'libraries/vendor_config.php';

/**
* Activate autoloader
*/
if (! @is_readable(AUTOLOAD_FILE)) {
die(
'<p>File <samp>' . AUTOLOAD_FILE . '</samp> missing or not readable.</p>'
. '<p>Most likely you did not run Composer to '
. '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">'
. 'install library files</a>.</p>'
);
}

require AUTOLOAD_FILE;

global $containerBuilder, $dbi;

$isMinimumCommon = true;
Expand Down

0 comments on commit 17f4e09

Please sign in to comment.