moved check_dir to setup_detection, to have it available inside and outside of setup

This commit is contained in:
Ralf Becker 2007-12-11 01:15:02 +00:00
parent bfff821e18
commit ab3c470388
3 changed files with 450 additions and 450 deletions

View File

@ -337,14 +337,14 @@
} }
$config_errors =& $GLOBALS['egw_info']['setup']['config_errors']; $config_errors =& $GLOBALS['egw_info']['setup']['config_errors'];
$config_errors = array(); $config_errors = array();
if (!check_dir($config['temp_dir'],$error_msg)) if (!$this->check_dir($config['temp_dir'],$error_msg))
{ {
$config_errors[] = lang("Your temporary directory '%1' %2",$config['temp_dir'],$error_msg); $config_errors[] = lang("Your temporary directory '%1' %2",$config['temp_dir'],$error_msg);
} }
if ((!isset($config['file_repository']) || $config['file_repository'] == 'sql') && if ((!isset($config['file_repository']) || $config['file_repository'] == 'sql') &&
(!isset($config['file_store_contents']) || $config['file_store_contents'] == 'filesystem') && (!isset($config['file_store_contents']) || $config['file_store_contents'] == 'filesystem') &&
!check_dir($config['files_dir'],$error_msg,true)) !$this->check_dir($config['files_dir'],$error_msg,true))
{ {
$config_errors[] = lang("Your files directory '%1' %2",$config['files_dir'],$error_msg); $config_errors[] = lang("Your files directory '%1' %2",$config['files_dir'],$error_msg);
} }
@ -362,7 +362,7 @@
),__LINE__,__FILE__); ),__LINE__,__FILE__);
} }
} }
if (!check_dir($config['backup_dir'],$error_msg,true)) if (!$this->check_dir($config['backup_dir'],$error_msg,true))
{ {
$config_errors[] = lang("Your backup directory '%1' %2",$config['backup_dir'],$error_msg); $config_errors[] = lang("Your backup directory '%1' %2",$config['backup_dir'],$error_msg);
} }
@ -487,5 +487,48 @@
return True; return True;
} }
} }
/**
* Checks if a directory exists, is writable by the webserver and optionaly is in the docroot
*
* @param string $dir path
* @param string &$msg error-msg: 'does not exist', 'is not writeable by the webserver' or 'is in the webservers docroot' (run through lang)
* @param boolean $check_in_docroot=false run an optional in docroot check
* @return boolean
*/
static function check_dir($dir,&$msg,$check_in_docroot=false)
{
if (!@is_dir($dir) && !@mkdir($dir,0700,true))
{
$msg = lang('does not exist');
return false;
}
if (!@is_writeable($dir) && $_SERVER['HTTP_HOST']) // only do the check if we run by the webserver
{
$msg = lang('is not writeable by the webserver');
return false;
}
if ($check_in_docroot)
{
$docroots = array(realpath(EGW_SERVER_ROOT),realpath($_SERVER['DOCUMENT_ROOT']));
$dir = realpath($dir);
foreach ($docroots as $docroot)
{
$len = strlen($docroot);
if ($docroot == substr($dir,0,$len) && $len>0)
{
$rest = substr($dir,$len);
if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR)
{
$msg = lang('is in the webservers docroot');
return false;
}
}
}
}
return true;
}
} }
?>

View File

@ -54,50 +54,6 @@
define('SEP',filesystem_separator()); define('SEP',filesystem_separator());
/**
* Checks if a directory exists, is writable by the webserver and optionaly is in the docroot
*
* @param string $dir path
* @param string &$msg error-msg: 'does not exist', 'is not writeable by the webserver' or 'is in the webservers docroot' (run through lang)
* @param boolean $check_in_docroot=false run an optional in docroot check
* @return boolean
*/
function check_dir($dir,&$msg,$check_in_docroot=false)
{
if (!@is_dir($dir) && !@mkdir($dir,0700,true))
{
$msg = lang('does not exist');
return false;
}
if (!@is_writeable($dir) && $_SERVER['HTTP_HOST']) // only do the check if we run by the webserver
{
$msg = lang('is not writeable by the webserver');
return false;
}
if ($check_in_docroot)
{
$docroots = array(realpath(EGW_SERVER_ROOT),realpath($_SERVER['DOCUMENT_ROOT']));
$dir = realpath($dir);
foreach ($docroots as $docroot)
{
$len = strlen($docroot);
if ($docroot == substr($dir,0,$len) && $len>0)
{
$rest = substr($dir,$len);
if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR)
{
$msg = lang('is in the webservers docroot');
return false;
}
}
}
}
return true;
}
/** /**
* function to handle multilanguage support * function to handle multilanguage support
* *

View File

@ -36,7 +36,7 @@
function temp_dir($settings) function temp_dir($settings)
{ {
if (!check_dir($settings['temp_dir'],$error_msg)) if (!setup_detection::check_dir($settings['temp_dir'],$error_msg))
{ {
$GLOBALS['config_error'] = lang("Your temporary directory '%1' %2",$settings['temp_dir'],$error_msg); $GLOBALS['config_error'] = lang("Your temporary directory '%1' %2",$settings['temp_dir'],$error_msg);
} }
@ -44,7 +44,8 @@
function files_dir($settings) function files_dir($settings)
{ {
if ($settings['file_repository'] == 'sql' && $settings['file_store_contents'] == 'filesystem' && !check_dir($settings['files_dir'],$error_msg,true)) if ($settings['file_repository'] == 'sql' && $settings['file_store_contents'] == 'filesystem' &&
!setup_detection::check_dir($settings['files_dir'],$error_msg,true))
{ {
$GLOBALS['config_error'] = lang("Your files directory '%1' %2",$settings['files_dir'],$error_msg); $GLOBALS['config_error'] = lang("Your files directory '%1' %2",$settings['files_dir'],$error_msg);
} }
@ -56,7 +57,7 @@
{ {
$settings['backup_dir'] = $settings['files_dir'].'/db_backup'; $settings['backup_dir'] = $settings['files_dir'].'/db_backup';
} }
if (!check_dir($settings['backup_dir'],$error_msg,true)) if (!setup_detection::check_dir($settings['backup_dir'],$error_msg,true))
{ {
$GLOBALS['config_error'] = lang("Your backup directory '%1' %2",$settings['backup_dir'],$error_msg); $GLOBALS['config_error'] = lang("Your backup directory '%1' %2",$settings['backup_dir'],$error_msg);
} }