()
| 724 | } |
| 725 | |
| 726 | private static function getVirusScanExcludeRules(): array |
| 727 | { |
| 728 | static $rules = null; |
| 729 | if ($rules !== null) { |
| 730 | return $rules; |
| 731 | } |
| 732 | |
| 733 | $raw = ''; |
| 734 | $env = getenv('VIRUS_SCAN_EXCLUDE_DIRS'); |
| 735 | if ($env !== false && trim((string)$env) !== '') { |
| 736 | $raw = (string)$env; |
| 737 | } elseif (class_exists(AdminModel::class)) { |
| 738 | $cfg = AdminModel::getConfig(); |
| 739 | if (is_array($cfg) && !isset($cfg['error'])) { |
| 740 | $raw = (string)($cfg['clamav']['excludeDirs'] ?? ''); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | $rules = []; |
| 745 | if (trim($raw) !== '') { |
| 746 | $parts = preg_split('/[,\r\n]+/', $raw); |
| 747 | if (is_array($parts)) { |
| 748 | foreach ($parts as $entry) { |
| 749 | $entry = trim((string)$entry); |
| 750 | if ($entry === '') { |
| 751 | continue; |
| 752 | } |
| 753 | |
| 754 | $source = ''; |
| 755 | $path = $entry; |
| 756 | if (strpos($entry, ':') !== false) { |
| 757 | [$maybeSource, $rest] = explode(':', $entry, 2); |
| 758 | $maybeSource = trim($maybeSource); |
| 759 | if ($maybeSource !== '' && preg_match('/^[A-Za-z0-9_-]{1,64}$/', $maybeSource)) { |
| 760 | $source = $maybeSource; |
| 761 | $path = $rest; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | $path = self::normalizeVirusScanExcludePath($path); |
| 766 | if ($path === '') { |
| 767 | continue; |
| 768 | } |
| 769 | |
| 770 | $rules[] = [ |
| 771 | 'source' => $source, |
| 772 | 'path' => $path, |
| 773 | ]; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | return $rules; |
| 779 | } |
| 780 | |
| 781 | private static function normalizeVirusScanExcludePath(string $path): string |
| 782 | { |
no test coverage detected