Skip to content

Commit

Permalink
Fix code using relative path
Browse files Browse the repository at this point in the history
if (chdir('/tmp') === false) {
    die('Could not change dir');
}

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jun 15, 2021
1 parent 7edfe93 commit f09ead5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/Table/ReplaceController.php
Expand Up @@ -260,7 +260,7 @@ public function index(): void
) {
$filename = 'libraries/classes/Plugins/Transformations/'
. $mime_map[$column_name]['input_transformation'];
if (is_file($filename)) {
if (is_file(ROOT_PATH . $filename)) {
$classname = $this->transformations->getClassName($filename);
if (class_exists($classname)) {
/** @var IOTransformationsPlugin $transformation_plugin */
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Display/Results.php
Expand Up @@ -2830,7 +2830,7 @@ private function getRowValues(
$file = $mime_map[$orgFullColName]['transformation'];
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;

if (@file_exists($include_file)) {
if (@file_exists(ROOT_PATH . $include_file)) {
$class_name = $this->transformations->getClassName($include_file);
if (class_exists($class_name)) {
// todo add $plugin_manager
Expand Down Expand Up @@ -2863,7 +2863,7 @@ private function getRowValues(
&& (trim($row[$i]) != '')
&& ! $_SESSION['tmpval']['hide_transformation']
) {
include_once $this->transformationInfo[$dbLower][$tblLower][$nameLower][0];
include_once ROOT_PATH . $this->transformationInfo[$dbLower][$tblLower][$nameLower][0];
$transformation_plugin = new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1](null);

$transform_options = $this->transformations->getOptions(
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/InsertEdit.php
Expand Up @@ -2602,7 +2602,7 @@ public function transformEditedValues(
$type
) {
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
if (is_file($include_file)) {
if (is_file(ROOT_PATH . $include_file)) {
// $cfg['SaveCellsAtOnce'] = true; JS code sends an array
$whereClause = is_array($_POST['where_clause']) ? $_POST['where_clause'][0] : $_POST['where_clause'];
$_url_params = [
Expand Down Expand Up @@ -3425,7 +3425,7 @@ private function getHtmlForInsertEditFormColumn(
if (! empty($column_mime['input_transformation'])) {
$file = $column_mime['input_transformation'];
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
if (is_file($include_file)) {
if (is_file(ROOT_PATH . $include_file)) {
$class_name = $this->transformations->getClassName($include_file);
if (class_exists($class_name)) {
$transformation_plugin = new $class_name();
Expand Down
16 changes: 11 additions & 5 deletions libraries/classes/Plugins.php
Expand Up @@ -48,6 +48,7 @@
use function strtolower;
use function ucfirst;
use function usort;
use const DIRECTORY_SEPARATOR;

/**
* PhpMyAdmin\Plugins class
Expand Down Expand Up @@ -77,8 +78,11 @@ public static function getPlugin(
. mb_strtoupper($plugin_format[0])
. mb_strtolower(mb_substr($plugin_format, 1));
$file = $class_name . '.php';
if (is_file($plugins_dir . $file)) {
//include_once $plugins_dir . $file;

$fullFsPathPluginDir = ROOT_PATH . DIRECTORY_SEPARATOR . $plugins_dir;

if (is_file($fullFsPathPluginDir . $file)) {
//include_once $fullFsPathPluginDir . $file;
$fqnClass = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)) . $class_name;
// check if class exists, could be caused by skip_import
if (class_exists($fqnClass)) {
Expand Down Expand Up @@ -136,7 +140,9 @@ private static function getPlugins(string $plugin_type, string $plugins_dir, $pl

$GLOBALS['plugin_param'] = $plugin_param;

$handle = @opendir($plugins_dir);
$fullFsPathPluginDir = ROOT_PATH . DIRECTORY_SEPARATOR . $plugins_dir;

$handle = @opendir($fullFsPathPluginDir);
if (! $handle) {
return [];
}
Expand All @@ -154,7 +160,7 @@ private static function getPlugins(string $plugin_type, string $plugins_dir, $pl
// (for example ._csv.php) so the following regexp
// matches a file which does not start with a dot but ends
// with ".php"
if (! is_file($plugins_dir . $file)
if (! is_file($fullFsPathPluginDir . $file)
|| ! preg_match(
'@^' . $class_type . '([^\.]+)\.php$@i',
$file,
Expand All @@ -167,7 +173,7 @@ private static function getPlugins(string $plugin_type, string $plugins_dir, $pl
/** @var bool $skip_import */
$skip_import = false;

include_once $plugins_dir . $file;
include_once $fullFsPathPluginDir . $file;

if ($skip_import) {
continue;
Expand Down
36 changes: 29 additions & 7 deletions libraries/classes/Theme.php
Expand Up @@ -18,6 +18,7 @@
use function trigger_error;
use function trim;
use function version_compare;
use const DIRECTORY_SEPARATOR;

/**
* handles theme
Expand Down Expand Up @@ -56,11 +57,17 @@ class Theme
private $fsPath = '';

/**
* @var string image path
* @var string image path as an URL
* @access protected
*/
public $imgPath = '';

/**
* @var string image path on the file-system
* @access protected
*/
public $imgPathFs = '';

/**
* @var int last modification time for info file
* @access protected
Expand Down Expand Up @@ -195,16 +202,21 @@ public static function load(string $folder, string $fsPath)
public function checkImgPath()
{
// try current theme first
if (is_dir($this->getFsPath() . 'img/')) {
if (is_dir($this->getFsPath() . 'img' . DIRECTORY_SEPARATOR)) {
$this->setImgPath($this->getPath() . '/img/');
$this->setImgPathFs($this->getFsPath() . 'img' . DIRECTORY_SEPARATOR);

return true;
}

// try fallback theme
$fallback = ThemeManager::getThemesDir() . ThemeManager::FALLBACK_THEME . '/img/';
if (is_dir(ThemeManager::getThemesFsDir() . ThemeManager::FALLBACK_THEME . '/img/')) {
$this->setImgPath($fallback);
$fallbackFsPathThemeDir = ThemeManager::getThemesFsDir() . ThemeManager::FALLBACK_THEME
. DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR;
if (is_dir($fallbackFsPathThemeDir)) {
$fallbackUrl = ThemeManager::getThemesDir() . ThemeManager::FALLBACK_THEME
. '/img/';
$this->setImgPath($fallbackUrl);
$this->setImgPathFs($fallbackFsPathThemeDir);

return true;
}
Expand Down Expand Up @@ -363,7 +375,7 @@ public function getId()
/**
* Sets path to images for the theme
*
* @param string $path path to images for this theme
* @param string $path path to images for this theme as an URL path
*
* @return void
*
Expand All @@ -374,6 +386,16 @@ public function setImgPath($path)
$this->imgPath = $path;
}

/**
* Sets path to images for the theme
*
* @param string $path file-system path to images for this theme
*/
public function setImgPathFs(string $path): void
{
$this->imgPathFs = $path;
}

/**
* Returns the path to image for the theme.
* If filename is given, it possibly fallbacks to fallback
Expand All @@ -392,7 +414,7 @@ public function getImgPath($file = null, $fallback = null)
return $this->imgPath;
}

if (is_readable($this->imgPath . $file)) {
if (is_readable($this->imgPathFs . $file)) {
return $this->imgPath . $file;
}

Expand Down
37 changes: 10 additions & 27 deletions libraries/classes/ThemeManager.php
Expand Up @@ -19,7 +19,6 @@
use function readdir;
use function sprintf;
use function trigger_error;
use function trim;

/**
* phpMyAdmin theme manager
Expand All @@ -36,10 +35,13 @@ class ThemeManager
private static $instance;

/**
* @var string path to theme folder
* @var string file-system path to the theme folder
* @access protected
*/
private $themesPath = './themes/';
private $themesPath;

/** @var string path to theme folder as an URL */
private $themesPathUrl = './themes/';

/** @var array available themes */
public $themes = [];
Expand Down Expand Up @@ -69,8 +71,9 @@ public function __construct()
$this->themes = [];
$this->themeDefault = self::FALLBACK_THEME;
$this->activeTheme = '';
$this->themesPath = self::getThemesFsDir();

if (! $this->setThemesPath('./themes/')) {
if (! $this->checkThemeFolder($this->themesPath)) {
return;
}

Expand Down Expand Up @@ -124,26 +127,6 @@ public static function getInstance(): ThemeManager
return self::$instance;
}

/**
* sets path to folder containing the themes
*
* @param string $path path to themes folder
*
* @return bool success
*
* @access public
*/
public function setThemesPath($path): bool
{
if (! $this->checkThemeFolder($path)) {
return false;
}

$this->themesPath = trim($path);

return true;
}

/**
* sets if there are different themes per server
*
Expand Down Expand Up @@ -295,16 +278,16 @@ public function loadThemes(): bool
// Skip non dirs, . and ..
if ($PMA_Theme === '.'
|| $PMA_Theme === '..'
|| ! @is_dir(ROOT_PATH . $this->themesPath . $PMA_Theme)
|| ! @is_dir($this->themesPath . $PMA_Theme)
) {
continue;
}
if (array_key_exists($PMA_Theme, $this->themes)) {
continue;
}
$new_theme = Theme::load(
$this->themesPath . $PMA_Theme,
ROOT_PATH . $this->themesPath . $PMA_Theme . '/'
$this->themesPathUrl . $PMA_Theme,
$this->themesPath . $PMA_Theme . DIRECTORY_SEPARATOR
);
if (! $new_theme) {
continue;
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Transformations.php
Expand Up @@ -108,7 +108,6 @@ public function getOptions($optionString)
* @return array array[mimetype], array[transformation]
*
* @access public
* @staticvar array mimetypes
*/
public function getAvailableMimeTypes()
{
Expand All @@ -126,7 +125,7 @@ public function getAvailableMimeTypes()
];

foreach ($sub_dirs as $sd => $prefix) {
$handle = opendir('libraries/classes/Plugins/Transformations/' . $sd);
$handle = opendir(ROOT_PATH . 'libraries/classes/Plugins/Transformations/' . $sd);

if (! $handle) {
$stack[$prefix . 'transformation'] = [];
Expand Down

0 comments on commit f09ead5

Please sign in to comment.