Skip to content

client部分 有些虚拟主机没权限 使用__DIR__替代 #2

@bailangvvk

Description

@bailangvvk

来自codeium
function scanDirectory($directory)
{
$currentPath = realpath(DIR);
$allowedPaths = array(
$currentPath,
);

$iterator = new RecursiveIteratorIterator(
	new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS),
	RecursiveIteratorIterator::SELF_FIRST
);
$files = array();

foreach ($iterator as $file) {
	if ($file->isFile()) {
		$filePath = $file->getPathname();
		$realPath = realpath($filePath);

		if ($realPath !== false && isAllowedPath($realPath, $allowedPaths)) {
			$files[] = $realPath;
		}
	}
}

return $files;

}

function isAllowedPath($path, $allowedPaths)
{
foreach ($allowedPaths as $allowedPath) {
if (strpos($path, $allowedPath) === 0) {
return true;
}
}

return false;

}

另外把同步的主机弄成参数 我现在的方案 管理20台机太难了

添加了白名单 但是strpos要消耗平方算力 虽然也不多 看看有没有优化空间

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions