1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-10 10:04:01 +02:00

use isPathValid function everywhere instead of manual checking

This commit is contained in:
Marco Dickert
2017-03-04 18:44:31 +01:00
parent 444b669882
commit 3cdeee6b7b
2 changed files with 8 additions and 14 deletions

11
ifm.php
View File

@@ -1832,10 +1832,10 @@ ifm.init();
}
private function getValidDir($dir) {
if( $this->getScriptRoot() != substr( realpath( $dir ), 0, strlen( $this->getScriptRoot() ) ) ) {
if( ! $this->isPathValid( $dir ) || ! is_dir( $dir ) ) {
return "";
} else {
return ( file_exists( realpath( $dir ) ) ) ? substr( realpath( $dir ), strlen( $this->getScriptRoot() ) + 1 ) : "";
return $dir;
}
}
@@ -1861,7 +1861,6 @@ ifm.init();
}
private function getScriptRoot() {
//return realpath( substr( $_SERVER["SCRIPT_FILENAME"], 0, strrpos( $_SERVER["SCRIPT_FILENAME"], "/" ) ) );
return dirname( $_SERVER["SCRIPT_FILENAME"] );
}
@@ -1887,12 +1886,10 @@ ifm.init();
}
private function getRealpath($dir) {
if( $this->getScriptRoot() != substr( realpath( $_POST["dir"] ), 0, strlen( $this->getScriptRoot() ) ) ) {
if( ! $this->isPathValid( $dir ) || ! is_dir( $dir ) ) {
echo json_encode( array( "realpath" => "" ) );
} else {
$rp = substr( realpath( $_POST["dir"] ), strlen( $this->getScriptRoot() ) + 1 );
if( $rp == false ) $rp = "";
echo json_encode( array( "realpath" => $rp ) );
echo json_encode( array( "realpath" => $dir ) );
}
}
private function rec_rmdir( $path ) {

View File

@@ -671,10 +671,10 @@ class IFM {
}
private function getValidDir($dir) {
if( $this->getScriptRoot() != substr( realpath( $dir ), 0, strlen( $this->getScriptRoot() ) ) ) {
if( ! $this->isPathValid( $dir ) || ! is_dir( $dir ) ) {
return "";
} else {
return ( file_exists( realpath( $dir ) ) ) ? substr( realpath( $dir ), strlen( $this->getScriptRoot() ) + 1 ) : "";
return $dir;
}
}
@@ -700,7 +700,6 @@ class IFM {
}
private function getScriptRoot() {
//return realpath( substr( $_SERVER["SCRIPT_FILENAME"], 0, strrpos( $_SERVER["SCRIPT_FILENAME"], "/" ) ) );
return dirname( $_SERVER["SCRIPT_FILENAME"] );
}
@@ -726,12 +725,10 @@ class IFM {
}
private function getRealpath($dir) {
if( $this->getScriptRoot() != substr( realpath( $_POST["dir"] ), 0, strlen( $this->getScriptRoot() ) ) ) {
if( ! $this->isPathValid( $dir ) || ! is_dir( $dir ) ) {
echo json_encode( array( "realpath" => "" ) );
} else {
$rp = substr( realpath( $_POST["dir"] ), strlen( $this->getScriptRoot() ) + 1 );
if( $rp == false ) $rp = "";
echo json_encode( array( "realpath" => $rp ) );
echo json_encode( array( "realpath" => $dir ) );
}
}
private function rec_rmdir( $path ) {