Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Option 2 Find/Replace) Fix error log spam PHP message: PHP Warning: is_dir(): open_basedir restriction in effect. File ... is not within the allowed path(s) #21592

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CRM/Admin/Page/APIExplorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function run() {
$paths = self::uniquePaths();
foreach ($paths as $path) {
$dir = \CRM_Utils_File::addTrailingSlash($path) . 'api' . DIRECTORY_SEPARATOR . 'v3' . DIRECTORY_SEPARATOR . 'examples';
if (is_dir($dir)) {
if (@is_dir($dir)) {
foreach (scandir($dir) as $item) {
if ($item && strpos($item, '.') === FALSE && array_search($item, $examples) === FALSE) {
$examples[] = $item;
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function getExampleFile() {
$paths = self::uniquePaths();
foreach ($paths as $path) {
$dir = \CRM_Utils_File::addTrailingSlash($path) . 'api' . DIRECTORY_SEPARATOR . 'v3' . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $_GET['entity'];
if (is_dir($dir)) {
if (@is_dir($dir)) {
foreach (scandir($dir) as $item) {
$item = str_replace('.ex.php', '', $item);
if ($item && strpos($item, '.') === FALSE) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Api4/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function loadServices($namespace, $tag, $container) {
);
foreach ($locations as $location) {
$path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
if (!file_exists($path) || !is_dir($path)) {
if (!file_exists($path) || !@is_dir($path)) {
$resource = new \Symfony\Component\Config\Resource\FileExistenceResource($path);
$container->addResource($resource);
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Import/Form/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private function _getDataSources() {
global $civicrm_root;
$dataSourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'DataSource' . DIRECTORY_SEPARATOR;
$dataSources = [];
if (!is_dir($dataSourceDir)) {
if (!@is_dir($dataSourceDir)) {
$this->invalidConfig("Import DataSource directory $dataSourceDir does not exist");
}
if (!$dataSourceHandle = opendir($dataSourceDir)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/CodeGen/Util/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CRM_Core_CodeGen_Util_File {
* @param int $perm
*/
public static function createDir($dir, $perm = 0755) {
if (!is_dir($dir)) {
if (!@is_dir($dir)) {
mkdir($dir, $perm, TRUE);
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static function tableNames(&$tables) {
public static function getComponentsFromFile($crmFolderDir) {
$components = [];
//traverse CRM folder and check for Info file
if (is_dir($crmFolderDir) && $dir = opendir($crmFolderDir)) {
if (@is_dir($crmFolderDir) && $dir = opendir($crmFolderDir)) {
while ($subDir = readdir($dir)) {
// skip the extensions diretory since it has an Info.php file also
if ($subDir == 'Extension') {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function cleanup($value, $rmdir = TRUE) {
$this->configAndLogDir,
$this->customFileUploadDir,
] as $dir) {
if ($dir && is_dir($dir)) {
if ($dir && @is_dir($dir)) {
CRM_Utils_File::restrictAccess($dir);
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Config/MagicMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function __get($k) {
if ($value) {
$value = CRM_Utils_File::addTrailingSlash($value);
if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) {
if (!is_dir($value) && !CRM_Utils_File::createDir($value, FALSE)) {
if (!@is_dir($value) && !CRM_Utils_File::createDir($value, FALSE)) {
CRM_Core_Session::setStatus(ts('Failed to make directory (%1) at "%2". Please update the settings or file permissions.', [
1 => $k,
2 => $value,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function languages($justEnabled = FALSE) {

// check which ones are available; add them to $all if not there already
$codes = [];
if (is_dir(CRM_Core_I18n::getResourceDir()) && $dir = opendir(CRM_Core_I18n::getResourceDir())) {
if (@is_dir(CRM_Core_I18n::getResourceDir()) && $dir = opendir(CRM_Core_I18n::getResourceDir())) {
while ($filename = readdir($dir)) {
if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
$codes[] = $filename;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Page/QUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function run() {
}

$path = CRM_Extension_System::singleton()->getMapper()->keyToBasePath($ext);
if (!is_dir("$path/tests/qunit/$suite")) {
if (!@is_dir("$path/tests/qunit/$suite")) {
throw new CRM_Core_Exception("Failed to locate test suite");
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Extension/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($repoUrl, $indexPath, $cacheDir) {
$this->repoUrl = $repoUrl;
$this->cacheDir = $cacheDir;
$this->indexPath = empty($indexPath) ? self::SINGLE_FILE_PATH : $indexPath;
if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) {
if ($cacheDir && !file_exists($cacheDir) && @is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) {
CRM_Utils_File::createDir($cacheDir, FALSE);
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function checkRequirements() {

$errors = [];

if (!$this->cacheDir || !is_dir($this->cacheDir) || !is_writable($this->cacheDir)) {
if (!$this->cacheDir || !@is_dir($this->cacheDir) || !is_writable($this->cacheDir)) {
$civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
$url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}");
$errors[] = array(
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extension/Container/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache
public function checkRequirements() {
$errors = [];

if (empty($this->baseDir) || !is_dir($this->baseDir)) {
if (empty($this->baseDir) || !@is_dir($this->baseDir)) {
$errors[] = [
'title' => ts('Invalid Base Directory'),
'message' => ts('An extension container has been defined with a blank directory.'),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extension/Container/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function checkRequirements() {

// In current configuration, we don't construct the default container
// unless baseDir is set, so this error condition is more theoretical.
if (empty($this->baseDir) || !is_dir($this->baseDir)) {
if (empty($this->baseDir) || !@is_dir($this->baseDir)) {
$civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
$url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}");
$errors[] = array(
Expand Down
4 changes: 2 additions & 2 deletions CRM/Extension/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(CRM_Extension_Manager $manager, $containerDir, $tmpD
public function checkRequirements($extensionInfo = NULL) {
$errors = [];

if (!$this->containerDir || !is_dir($this->containerDir) || !is_writable($this->containerDir)) {
if (!$this->containerDir || !@is_dir($this->containerDir) || !is_writable($this->containerDir)) {
$civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
$url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}");
$errors[] = array(
Expand Down Expand Up @@ -166,7 +166,7 @@ public function extractFiles($key, $zipFile) {
return FALSE;
}
$extractedZipPath = $this->tmpDir . DIRECTORY_SEPARATOR . $zipSubDir;
if (is_dir($extractedZipPath)) {
if (@is_dir($extractedZipPath)) {
if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
CRM_Core_Session::setStatus(ts('Unable to extract the extension: %1 cannot be cleared', array(1 => $extractedZipPath)), ts('Installation Error'), 'error');
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extension/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function getStatuses() {
while ($dao->fetch()) {
try {
$path = $this->fullContainer->getPath($dao->full_name);
$codeExists = !empty($path) && is_dir($path);
$codeExists = !empty($path) && @is_dir($path);
}
catch (CRM_Extension_Exception $e) {
$codeExists = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extension/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getFullContainer() {
// At time of writing, D6, D7, and WP support cmsRootPath() but J does not
if (NULL !== $this->parameters['cmsRootPath']) {
$vendorPath = $this->parameters['cmsRootPath'] . DIRECTORY_SEPARATOR . 'vendor';
if (is_dir($vendorPath)) {
if (@is_dir($vendorPath)) {
$containers['cmsvendor'] = new CRM_Extension_Container_Basic(
$vendorPath,
CRM_Utils_File::addTrailingSlash($this->parameters['userFrameworkBaseURL'], '/') . 'vendor',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Upgrade/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public static function doFileCleanup(CRM_Queue_TaskContext $ctx, $postUpgradeMes
$files = $source->findOrphanedFiles();
$errors = [];
foreach ($files as $file) {
if (is_dir($file['path'])) {
if (@is_dir($file['path'])) {
@rmdir($file['path']);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Check/Component/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public function checkExtensions() {
return $messages;
}

if (!is_dir($basedir)) {
if (!@is_dir($basedir)) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__,
ts('Your extensions directory path points to %1, which is not a directory. Please check your file system.',
Expand Down
4 changes: 2 additions & 2 deletions CRM/Utils/Check/Component/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function checkCxnOverrides() {
* @return bool
*/
public function isBrowsable($dir, $url) {
if (empty($dir) || empty($url) || !is_dir($dir)) {
if (empty($dir) || empty($url) || !@is_dir($dir)) {
return FALSE;
}

Expand Down Expand Up @@ -337,7 +337,7 @@ public function isBrowsable($dir, $url) {
*/
public function isDirAccessible($dir, $url) {
$url = rtrim($url, '/');
if (empty($dir) || empty($url) || !is_dir($dir)) {
if (empty($dir) || empty($url) || !@is_dir($dir)) {
return FALSE;
}

Expand Down
20 changes: 10 additions & 10 deletions CRM/Utils/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function isHtml($name) {
* FALSE: Creation failed.
*/
public static function createDir($path, $abort = TRUE) {
if (is_dir($path) || empty($path)) {
if (@is_dir($path) || empty($path)) {
return NULL;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE) {
if (!in_array($sibling, $exceptions)) {
$object = $target . DIRECTORY_SEPARATOR . $sibling;

if (is_dir($object)) {
if (@is_dir($object)) {
CRM_Utils_File::cleanDir($object, $rmdir, $verbose);
}
elseif (is_file($object)) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public static function copyDir($source, $destination) {
@mkdir($destination);
while (FALSE !== ($file = readdir($dh))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
if (@is_dir($source . DIRECTORY_SEPARATOR . $file)) {
CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
}
else {
Expand Down Expand Up @@ -528,7 +528,7 @@ public static function restrictAccess($dir, $overwrite = FALSE) {
// note: empty value for $dir can play havoc, since that might result in putting '.htaccess' to root dir
// of site, causing site to stop functioning.
// FIXME: we should do more checks here -
if (!empty($dir) && is_dir($dir)) {
if (!empty($dir) && @is_dir($dir)) {
$htaccess = <<<HTACCESS
<Files "*">
# Apache 2.2
Expand Down Expand Up @@ -559,7 +559,7 @@ public static function restrictAccess($dir, $overwrite = FALSE) {
* @param $publicDir
*/
public static function restrictBrowsing($publicDir) {
if (!is_dir($publicDir) || !is_writable($publicDir)) {
if (!@is_dir($publicDir) || !is_writable($publicDir)) {
return;
}

Expand All @@ -572,7 +572,7 @@ public static function restrictBrowsing($publicDir) {
// child dirs
$dir = new RecursiveDirectoryIterator($publicDir);
foreach ($dir as $name => $object) {
if (is_dir($name) && $name != '..') {
if (@is_dir($name) && $name != '..') {
$nobrowse = realpath($name) . '/index.html';
if (!file_exists($nobrowse)) {
@file_put_contents($nobrowse, '');
Expand Down Expand Up @@ -742,7 +742,7 @@ public static function tempdir($prefix = 'tmp-') {
* @return array(string)
*/
public static function findFiles($dir, $pattern, $relative = FALSE) {
if (!is_dir($dir) || !is_readable($dir)) {
if (!@is_dir($dir) || !is_readable($dir)) {
return [];
}
// Which dirs should we exclude from our searches?
Expand All @@ -760,7 +760,7 @@ public static function findFiles($dir, $pattern, $relative = FALSE) {
$matches = glob("$subdir/$pattern");
if (is_array($matches)) {
foreach ($matches as $match) {
if (!is_dir($match)) {
if (!@is_dir($match)) {
$result[] = $relative ? CRM_Utils_File::relativize($match, "$dir/") : $match;
}
}
Expand All @@ -777,7 +777,7 @@ public static function findFiles($dir, $pattern, $relative = FALSE) {
$entry !== '.'
&& $entry !== '..'
&& (empty($excludeDirsPattern) || !preg_match($excludeDirsPattern, $path))
&& is_dir($path)
&& @is_dir($path)
&& is_readable($path)
) {
$todos[] = $path;
Expand Down Expand Up @@ -834,7 +834,7 @@ public static function isChildPath($parent, $child, $checkRealPath = TRUE) {
* TRUE on success
*/
public static function replaceDir($fromDir, $toDir, $verbose = FALSE) {
if (is_dir($toDir)) {
if (@is_dir($toDir)) {
if (!self::cleanDir($toDir, TRUE, $verbose)) {
return FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Utils/Mail/EmailProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function processBounces($is_create_activities) {
*/
public static function cleanupDir($dir, $age = 5184000) {
// return early if we can’t read/write the dir
if (!is_writable($dir) or !is_readable($dir) or !is_dir($dir)) {
if (!is_writable($dir) or !is_readable($dir) or !@is_dir($dir)) {
return;
}

Expand All @@ -69,7 +69,7 @@ public static function cleanupDir($dir, $age = 5184000) {
}

// it’s an old file/dir, so delete/recurse
is_dir("$dir/$file") ? self::cleanupDir("$dir/$file", $age) : unlink("$dir/$file");
@is_dir("$dir/$file") ? self::cleanupDir("$dir/$file", $age) : unlink("$dir/$file");
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public static function fileExists($path) {
* @return bool
*/
public static function settingPath($path) {
return is_dir(Civi::paths()->getPath($path));
return @is_dir(Civi::paths()->getPath($path));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ public static function listIncludeFiles($relpath) {
$inc_dirs = explode(PATH_SEPARATOR, get_include_path());
foreach ($inc_dirs as $inc_dir) {
$target_dir = $inc_dir . DIRECTORY_SEPARATOR . $relpath;
if (is_dir($target_dir)) {
if (@is_dir($target_dir)) {
$cur_list = scandir($target_dir);
foreach ($cur_list as $fname) {
if ($fname != '.' && $fname != '..') {
Expand Down
6 changes: 3 additions & 3 deletions Civi/API/Provider/MagicFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getEntityNames($version) {
foreach ($include_dirs as $include_dir) {
$api_dir = implode(DIRECTORY_SEPARATOR,
[$include_dir, 'api', 'v' . $version]);
if (!is_dir($api_dir)) {
if (!@is_dir($api_dir)) {
continue;
}
$iterator = new \DirectoryIterator($api_dir);
Expand All @@ -119,7 +119,7 @@ public function getEntityNames($version) {

// Check for entities with standalone action files (eg "api/v3/MyEntity/MyAction.php").
$action_dir = $api_dir . DIRECTORY_SEPARATOR . $file;
if (preg_match('/^[A-Z][A-Za-z0-9]*$/', $file) && is_dir($action_dir)) {
if (preg_match('/^[A-Z][A-Za-z0-9]*$/', $file) && @is_dir($action_dir)) {
if (count(glob("$action_dir/[A-Z]*.php")) > 0) {
$entities[] = $file;
}
Expand Down Expand Up @@ -281,7 +281,7 @@ protected function loadEntity($entity, $version) {
foreach ([$camelName, 'Generic'] as $name) {
$action_dir = implode(DIRECTORY_SEPARATOR,
[$include_dir, 'api', "v${version}", $name]);
if (!is_dir($action_dir)) {
if (!@is_dir($action_dir)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Action/Entity/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function getAllApiClasses() {
);
foreach ($locations as $location) {
$dir = \CRM_Utils_File::addTrailingSlash(dirname($location)) . 'Civi/Api4';
if (is_dir($dir)) {
if (@is_dir($dir)) {
foreach (glob("$dir/*.php") as $file) {
$className = 'Civi\Api4\\' . basename($file, '.php');
if (is_a($className, 'Civi\Api4\Generic\AbstractEntity', TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Action/GetActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function getRecords() {
*/
private function scanDir($dir, $nameSpace) {
$dir .= str_replace('\\', '/', $nameSpace);
if (is_dir($dir)) {
if (@is_dir($dir)) {
foreach (glob("$dir/*.php") as $file) {
$actionName = basename($file, '.php');
$actionClass = new \ReflectionClass($nameSpace . '\\' . $actionName);
Expand Down
2 changes: 1 addition & 1 deletion Civi/CiUtil/PHPUnitScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function findTestClasses($paths) {
$finder = new Finder();

foreach ($paths as $path) {
if (is_dir($path)) {
if (@is_dir($path)) {
foreach ($finder->files()->in($paths)->name('*Test.php') as $file) {
$testClass = self::_findTestClasses((string) $file);
if (count($testClass) == 1) {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Core/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct() {
->register('civicrm.l10n', function () {
$dir = defined('CIVICRM_L10N_BASEDIR') ? CIVICRM_L10N_BASEDIR : \Civi::paths()->getPath('[civicrm.private]/l10n');
return [
'path' => is_dir($dir) ? $dir : \Civi::paths()->getPath('[civicrm.root]/l10n'),
'path' => @is_dir($dir) ? $dir : \Civi::paths()->getPath('[civicrm.root]/l10n'),
];
})
->register('cms', function () {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Core/SettingsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected static function loadSettingsMetaDataFolders($metaDataFolders) {
$loadedFolders = [];
foreach ($metaDataFolders as $metaDataFolder) {
$realFolder = realpath($metaDataFolder);
if (is_dir($realFolder) && !isset($loadedFolders[$realFolder])) {
if (@is_dir($realFolder) && !isset($loadedFolders[$realFolder])) {
$loadedFolders[$realFolder] = TRUE;
$settingsMetadata = $settingsMetadata + self::loadSettingsMetadata($metaDataFolder);
}
Expand Down
Loading