From 7381cb74d099589d93e0af4cfa3fc3db9564f07e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 3 Jul 2003 17:11:23 +0000 Subject: [PATCH] improved version of in_docroot, allows for pathnames starting like the docroot --- infolog/inc/class.vfs.inc.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/infolog/inc/class.vfs.inc.php b/infolog/inc/class.vfs.inc.php index 70e66fc87e..00fe60af4e 100644 --- a/infolog/inc/class.vfs.inc.php +++ b/infolog/inc/class.vfs.inc.php @@ -102,7 +102,7 @@ // test if the files-dir is inside the document-root, and refuse working if so // - if (strstr($this->basedir,PHPGW_SERVER_ROOT) || strstr($this->basedir,$GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])) + if ($this->in_docroot($this->basedir)) { $GLOBALS['phpgw']->common->phpgw_header(); if ($GLOBALS['phpgw_info']['flags']['noheader']) @@ -157,6 +157,31 @@ } } + /*! + @function in_docroot + @abstract test if $path lies within the webservers document-root + */ + function in_docroot($path) + { + $docroots = array(PHPGW_SERVER_ROOT,$GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']); + + foreach ($docroots as $docroot) + { + $len = strlen($docroot); + + if ($docroot == substr($path,0,$len)) + { + $rest = substr($path,$len); + + if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR) + { + return True; + } + } + } + return False; + } + /*! @function set_relative @abstract Set path relativity