48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Exclusion Matcher — determines if a file path matches any exclusion glob pattern.
|
|
*
|
|
* @author Ball Studios <https://git.balls.studio>
|
|
* @license MIT
|
|
*/
|
|
|
|
namespace Pterodactyl\Addons\AdvancedAdmin\Services\Revisions;
|
|
|
|
class ExclusionMatcher
|
|
{
|
|
/** @var string[] */
|
|
private array $patterns;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->patterns = config('advanced-admin.revisions.excluded_patterns', []);
|
|
}
|
|
|
|
/**
|
|
* Returns true if the file should be excluded from tracking.
|
|
*/
|
|
public function isExcluded(string $filePath): bool
|
|
{
|
|
$basename = basename($filePath);
|
|
|
|
foreach ($this->patterns as $pattern) {
|
|
// Match against both full path and basename
|
|
if (fnmatch($pattern, $basename, FNM_CASEFOLD)) {
|
|
return true;
|
|
}
|
|
if (fnmatch($pattern, $filePath, FNM_CASEFOLD | FNM_PATHNAME)) {
|
|
return true;
|
|
}
|
|
// Also check for case-insensitive substring matches on sensitive keywords
|
|
if (str_contains(strtolower($basename), 'secret') ||
|
|
str_contains(strtolower($basename), 'password') ||
|
|
str_contains(strtolower($basename), 'token') && str_ends_with($basename, '.json')
|
|
) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|