1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-13 19:44:02 +02:00

Fix directory checks, use initial working directory as root_dir by default.

Signed-off-by: Marco Dickert <marco@misterunknown.de>
This commit is contained in:
Marco Dickert
2022-06-10 02:22:33 +02:00
parent a1de29df96
commit bf0b6a737e

View File

@@ -77,6 +77,9 @@ class IFM {
public $mode = "standalone"; public $mode = "standalone";
public function __construct($config=[]) { public function __construct($config=[]) {
// store initial working directory
$this->initialWD = getcwd();
// load the default config // load the default config
$this->config = $this->defaultconfig; $this->config = $this->defaultconfig;
@@ -322,7 +325,7 @@ f00bar;
if ($handle = opendir(".")) { if ($handle = opendir(".")) {
while (false !== ($result = readdir($handle))) { while (false !== ($result = readdir($handle))) {
if ($result == basename($_SERVER['SCRIPT_NAME']) && $this->getScriptRoot() == getcwd()) if ($result == basename($_SERVER['SCRIPT_NAME']) && getcwd() == $this->initialWD)
continue; continue;
elseif (($result == ".htaccess" || $result==".htpasswd") && $this->config['showhtdocs'] != 1) elseif (($result == ".htaccess" || $result==".htpasswd") && $this->config['showhtdocs'] != 1)
continue; continue;
@@ -409,7 +412,7 @@ f00bar;
private function getConfig() { private function getConfig() {
$ret = $this->config; $ret = $this->config;
$ret['inline'] = ($this->mode == "inline") ? true : false; $ret['inline'] = ($this->mode == "inline") ? true : false;
$ret['isDocroot'] = ($this->getRootDir() == $this->getScriptRoot()); $ret['isDocroot'] = ($this->getRootDir() == $this->initialWD);
foreach (["auth_source", "root_dir"] as $field) foreach (["auth_source", "root_dir"] as $field)
unset($ret[$field]); unset($ret[$field]);
@@ -433,7 +436,7 @@ f00bar;
]); ]);
} }
sort($ret); sort($ret);
if ($this->getScriptRoot() == realpath($d['dir'])) if (realpath($d['dir']) == $this->initialWD)
$ret = array_merge( $ret = array_merge(
[ [
0 => [ 0 => [
@@ -687,7 +690,7 @@ f00bar;
if (!is_dir($d['targetdir']) && !mkdir($d['targetdir'], 0777, true)) if (!is_dir($d['targetdir']) && !mkdir($d['targetdir'], 0777, true))
throw new IFMException($this->l('folder_create_error')); throw new IFMException($this->l('folder_create_error'));
if (realpath($d['targetdir']) == substr($this->getScriptRoot(), 0, strlen(realpath($d['targetdir'])))) { if (realpath($d['targetdir']) == substr($this->initialWD, 0, strlen(realpath($d['targetdir'])))) {
$tmpSelfContent = tmpfile(); $tmpSelfContent = tmpfile();
fwrite($tmpSelfContent, file_get_contents(__FILE__)); fwrite($tmpSelfContent, file_get_contents(__FILE__));
$tmpSelfChecksum = hash_file("sha256", __FILE__); $tmpSelfChecksum = hash_file("sha256", __FILE__);
@@ -809,12 +812,12 @@ f00bar;
if ($this->isAbsolutePath($this->config['tmp_dir'])) if ($this->isAbsolutePath($this->config['tmp_dir']))
$dfile = $this->pathCombine($this->config['tmp_dir'], uniqid("ifm-tmp-") . ".zip"); // temporary filename $dfile = $this->pathCombine($this->config['tmp_dir'], uniqid("ifm-tmp-") . ".zip"); // temporary filename
else else
$dfile = $this->pathCombine(__DIR__, $this->config['tmp_dir'], uniqid("ifm-tmp-") . ".zip"); // temporary filename $dfile = $this->pathCombine($this->initialWD, $this->config['tmp_dir'], uniqid("ifm-tmp-") . ".zip"); // temporary filename
try { try {
IFMArchive::createZip(realpath($d['filename']), $dfile, [$this, 'isFilenameValid']); IFMArchive::createZip(realpath($d['filename']), $dfile, [$this, 'isFilenameValid']);
if ($d['filename'] == ".") { if ($d['filename'] == ".") {
if (getcwd() == $this->getScriptRoot()) if (getcwd() == $this->getRootDir())
$d['filename'] = "root"; $d['filename'] = "root";
else else
$d['filename'] = basename(getcwd()); $d['filename'] = basename(getcwd());
@@ -1103,15 +1106,11 @@ f00bar;
private function getRootDir() { private function getRootDir() {
if ($this->config['root_dir'] == "") if ($this->config['root_dir'] == "")
return realpath($this->getScriptRoot()); return $this->initialWD;
elseif ($this->isAbsolutePath($this->config['root_dir'])) elseif ($this->isAbsolutePath($this->config['root_dir']))
return realpath($this->config['root_dir']); return realpath($this->config['root_dir']);
else else
return realpath($this->pathCombine($this->getScriptRoot(), $this->config['root_dir'])); return realpath($this->pathCombine($this->initialWD, $this->config['root_dir']));
}
private function getScriptRoot() {
return dirname(__FILE__);
} }
private function getValidDir($dir) { private function getValidDir($dir) {
@@ -1279,7 +1278,7 @@ f00bar;
return false; return false;
elseif ($this->config['showhiddenfiles'] != 1 && substr($f, 0, 1) == ".") elseif ($this->config['showhiddenfiles'] != 1 && substr($f, 0, 1) == ".")
return false; return false;
elseif ($this->config['selfoverwrite'] != 1 && getcwd() == $this->getScriptRoot() && $f == basename(__FILE__)) elseif ($this->config['selfoverwrite'] != 1 && getcwd() == $this->initialWD && $f == basename(__FILE__))
return false; return false;
else else
return true; return true;