ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilFileServicesSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
29  private ilDBInterface $db;
30  private array $white_list_default = [];
31  private array $white_list_negative = [];
32  private array $white_list_positive = [];
33  private array $white_list_overall = [];
34  private array $black_list_prohibited = [];
35  private array $black_list_overall = [];
36  private bool $convert_to_ascii = true;
37  private ?bool $bypass = null;
38  protected int $file_admin_ref_id;
39 
40  public function __construct(
41  ilSetting $settings,
42  ilIniFile $client_ini,
43  ilDBInterface $db
44  ) {
45  $this->db = $db;
46 
47  $general_settings = new General();
48  $this->convert_to_ascii = $general_settings->isDownloadWithAsciiFileName();
49  $this->settings = $settings;
51  $this->white_list_default = include __DIR__ . "/../defaults/default_whitelist.php";
52  $this->file_admin_ref_id = $this->determineFileAdminRefId();
53  $this->read();
54  }
55 
56  private function determineFileAdminRefId(): int
57  {
58  $r = $this->db->query(
59  "SELECT ref_id FROM object_reference JOIN object_data ON object_reference.obj_id = object_data.obj_id WHERE object_data.type = 'facs';"
60  );
61  $r = $this->db->fetchObject($r);
62  return (int) ($r->ref_id ?? 0);
63  }
64 
65  private function determineByPass(): bool
66  {
67  global $DIC;
68  return $DIC->isDependencyAvailable('rbac')
69  && isset($DIC["rbacsystem"])
70  && $DIC->rbac()->system()->checkAccess(
71  'upload_blacklisted_files',
72  $this->file_admin_ref_id
73  );
74  }
75 
76  public function isByPassAllowedForCurrentUser(): bool
77  {
78  if ($this->bypass !== null) {
79  return $this->bypass;
80  }
81  return $this->bypass = $this->determineByPass();
82  }
83 
84  private function read(): void
85  {
86  $this->readBlackList();
87  $this->readWhiteList();
88  }
89 
90  public function isASCIIConvertionEnabled(): bool
91  {
93  }
94 
95  private function readWhiteList(): void
96  {
97  $cleaner = $this->getCleaner();
98 
99  $this->white_list_negative = array_map(
100  $cleaner,
101  explode(",", $this->settings->get("suffix_repl_additional") ?? '')
102  );
103 
104  $this->white_list_positive = array_map(
105  $cleaner,
106  explode(",", $this->settings->get("suffix_custom_white_list") ?? '')
107  );
108 
109  $this->white_list_overall = array_merge($this->white_list_default, $this->white_list_positive);
110  $this->white_list_overall = array_diff($this->white_list_overall, $this->white_list_negative);
111  $this->white_list_overall = array_diff($this->white_list_overall, $this->black_list_overall);
112  $this->white_list_overall[] = '';
113  $this->white_list_overall = array_unique($this->white_list_overall);
114  $this->white_list_overall = array_diff($this->white_list_overall, $this->black_list_prohibited);
115  }
116 
117  private function readBlackList(): void
118  {
119  $cleaner = $this->getCleaner();
120 
121  $this->black_list_prohibited = array_map(
122  $cleaner,
123  explode(",", $this->settings->get("suffix_custom_expl_black") ?? '')
124  );
125 
126  $this->black_list_prohibited = array_filter($this->black_list_prohibited, fn($item): bool => $item !== '');
127  $this->black_list_overall = $this->black_list_prohibited;
128  }
129 
130  private function getCleaner(): Closure
131  {
132  return function (string $suffix): string {
133  return trim(strtolower($suffix));
134  };
135  }
136 
137  public function getWhiteListedSuffixes(): array
138  {
140  }
141 
142  public function getBlackListedSuffixes(): array
143  {
145  }
146 
150  public function getDefaultWhitelist()
151  {
153  }
154 
158  public function getWhiteListNegative(): array
159  {
161  }
162 
166  public function getWhiteListPositive(): array
167  {
169  }
170 
174  public function getProhibited(): array
175  {
177  }
178 }
__construct(ilSetting $settings, ilIniFile $client_ini, ilDBInterface $db)
global $DIC
Definition: shib_login.php:25
$r