| 39 |
|
%% ||
|
| 40 |
|
|| **Purpose:** Initializes the Http object and sets up HTTP session handling. ||
|
| 41 |
|
|| **Parameters:** ||
|
| 42 |
|
|| - ##$db## - Database object reference ||
|
| 43 |
|
|| **Initialization Steps:** ||
|
| 44 |
|
|| 1. Stores database reference ||
|
| 45 |
|
|| 2. Extracts and normalizes REQUEST_URI ||
|
| 46 |
|
|| 3. Detects TLS/HTTPS session status ||
|
| 47 |
|
|| 4. Determines client's real IP address ||
|
| 48 |
|
|| 5. Sets up TLS mark cookie name ||
|
| 49 |
|
|| 6. Enforces TLS session upgrade if needed ||
|
| 50 |
|
|| **Example:** ||
|
| 51 |
|
|| %%php
|
| |
33 |
%%
|
| |
34 |
|
| |
35 |
**Purpose:** Initializes the Http object and sets up HTTP session handling.
|
| |
36 |
|
| |
37 |
**Parameters:**
|
| |
38 |
- ##$db## - Database object reference
|
| |
39 |
|
| |
40 |
**Initialization Steps:**
|
| |
41 |
1. Stores database reference
|
| |
42 |
2. Extracts and normalizes REQUEST_URI
|
| |
43 |
3. Detects TLS/HTTPS session status
|
| |
44 |
4. Determines client's real IP address
|
| |
45 |
5. Sets up TLS mark cookie name
|
| |
46 |
6. Enforces TLS session upgrade if needed
|
| |
47 |
|
| |
48 |
**Example:**
|
| |
49 |
%%php
|
| 53 |
|
%% ||
|
| 54 |
|
|| ---- ||
|
| 55 |
|
|| === Core Methods === ||
|
| 56 |
|
|| ==== Session Management ==== ||
|
| 57 |
|
|| ===== ##session($route): void## ===== ||
|
| 58 |
|
|| Initializes the session handler (file-based or database-based). ||
|
| 59 |
|
|| **Parameters:** ||
|
| 60 |
|
|| - ##$route## (int) - Routing flag: ||
|
| 61 |
|
|| - Bit 2 (##$route & 2##): Enable static mode for files/freecap (disables replay prevention and ID regeneration) ||
|
| 62 |
|
|| **Features:** ||
|
| 63 |
|
|| - Selects storage backend (file or database) ||
|
| 64 |
|
|| - Configures cookie settings (security, path, httponly) ||
|
| 65 |
|
|| - Binds IP and TLS validation ||
|
| 66 |
|
|| - Recovers diagnostic logs from previous session ||
|
| 67 |
|
|| **Example:** ||
|
| 68 |
|
|| %%php
|
| |
51 |
%%
|
| |
52 |
|
| |
53 |
----
|
| |
54 |
|
| |
55 |
=== Core Methods ===
|
| |
56 |
|
| |
57 |
==== Session Management ====
|
| |
58 |
|
| |
59 |
===== ##session($route): void## =====
|
| |
60 |
Initializes the session handler (file-based or database-based).
|
| |
61 |
|
| |
62 |
**Parameters:**
|
| |
63 |
- ##$route## (int) - Routing flag:
|
| |
64 |
- Bit 2 (##$route & 2##): Enable static mode for files/freecap (disables replay prevention and ID regeneration)
|
| |
65 |
|
| |
66 |
**Features:**
|
| |
67 |
- Selects storage backend (file or database)
|
| |
68 |
- Configures cookie settings (security, path, httponly)
|
| |
69 |
- Binds IP and TLS validation
|
| |
70 |
- Recovers diagnostic logs from previous session
|
| |
71 |
|
| |
72 |
**Example:**
|
| |
73 |
%%php
|
| 71 |
|
%% ||
|
| 72 |
|
|| ---- ||
|
| 73 |
|
|| ==== Caching System ==== ||
|
| 74 |
|
|| ===== ##check_cache($page, $method): void## ===== ||
|
| 75 |
|
|| Determines if a page can be cached and prepares the cache check. ||
|
| 76 |
|
|| **Parameters:** ||
|
| 77 |
|
|| - ##$page## (string) - Page name to cache ||
|
| 78 |
|
|| - ##$method## (string) - Request method/action (e.g., 'show', 'edit') ||
|
| 79 |
|
|| **Caching Rules:** ||
|
| 80 |
|
|| - ✅ Enabled for GET requests only ||
|
| 81 |
|
|| - ✅ Disabled for POST requests ||
|
| 82 |
|
|| - ❌ Never cached for 'edit' or 'watch' methods ||
|
| 83 |
|
|| - ✅ Only cached for anonymous users (no logged-in users) ||
|
| 84 |
|
|| **Example:** ||
|
| 85 |
|
|| %%php
|
| |
76 |
%%
|
| |
77 |
|
| |
78 |
----
|
| |
79 |
|
| |
80 |
==== Caching System ====
|
| |
81 |
|
| |
82 |
===== ##check_cache($page, $method): void## =====
|
| |
83 |
Determines if a page can be cached and prepares the cache check.
|
| |
84 |
|
| |
85 |
**Parameters:**
|
| |
86 |
- ##$page## (string) - Page name to cache
|
| |
87 |
- ##$method## (string) - Request method/action (e.g., 'show', 'edit')
|
| |
88 |
|
| |
89 |
**Caching Rules:**
|
| |
90 |
- ✅ Enabled for GET requests only
|
| |
91 |
- ✅ Disabled for POST requests
|
| |
92 |
- ❌ Never cached for 'edit' or 'watch' methods
|
| |
93 |
- ✅ Only cached for anonymous users (no logged-in users)
|
| |
94 |
|
| |
95 |
**Example:**
|
| |
96 |
%%php
|
| 100 |
|
%% ||
|
| 101 |
|
|| ---- ||
|
| 102 |
|
|| ===== ##invalidate_page($page): int## ===== ||
|
| 103 |
|
|| Invalidates all cached versions of a page. ||
|
| 104 |
|
|| **Parameters:** ||
|
| 105 |
|
|| - ##$page## (string) - Page name to invalidate ||
|
| 106 |
|
|| **Returns:** ||
|
| 107 |
|
|| - Number of cache entries invalidated ||
|
| 108 |
|
|| **Process:** ||
|
| 109 |
|
|| 1. Finds all cached versions (different methods/languages) ||
|
| 110 |
|
|| 2. Touches files to past timestamp (faster than deletion) ||
|
| 111 |
|
|| 3. Removes entries from cache metadata table ||
|
| 112 |
|
|| 4. Returns count of invalidated caches ||
|
| 113 |
|
|| **Example:** ||
|
| 114 |
|
|| %%php
|
| |
115 |
%%
|
| |
116 |
|
| |
117 |
----
|
| |
118 |
|
| |
119 |
===== ##invalidate_page($page): int## =====
|
| |
120 |
Invalidates all cached versions of a page.
|
| |
121 |
|
| |
122 |
**Parameters:**
|
| |
123 |
- ##$page## (string) - Page name to invalidate
|
| |
124 |
|
| |
125 |
**Returns:**
|
| |
126 |
- Number of cache entries invalidated
|
| |
127 |
|
| |
128 |
**Process:**
|
| |
129 |
1. Finds all cached versions (different methods/languages)
|
| |
130 |
2. Touches files to past timestamp (faster than deletion)
|
| |
131 |
3. Removes entries from cache metadata table
|
| |
132 |
4. Returns count of invalidated caches
|
| |
133 |
|
| |
134 |
**Example:**
|
| |
135 |
%%php
|
| 143 |
|
%% ||
|
| 144 |
|
|| ---- ||
|
| 145 |
|
|| ==== IP Address Detection ==== ||
|
| 146 |
|
|| ===== ##real_ip(): string## (Private) ===== ||
|
| 147 |
|
|| Detects client's real IP address accounting for proxies. ||
|
| 148 |
|
|| **Proxy Headers Checked (in order):** ||
|
| 149 |
|
|| 1. ##HTTP_X_CLUSTER_CLIENT_IP## ||
|
| 150 |
|
|| 2. ##HTTP_X_FORWARDED_FOR## (or custom header) ||
|
| 151 |
|
|| 3. ##HTTP_CLIENT_IP## ||
|
| 152 |
|
|| 4. ##HTTP_X_REMOTE_ADDR## ||
|
| 153 |
|
|| 5. ##REMOTE_ADDR## (fallback) ||
|
| 154 |
|
|| **Features:** ||
|
| 155 |
|
|| - Filters out private/reserved IP ranges ||
|
| 156 |
|
|| - Respects configured reverse proxy addresses ||
|
| 157 |
|
|| - Returns ##'0.0.0.0'## as fallback ||
|
| 158 |
|
|| **Configuration in Database:** ||
|
| 159 |
|
|| - ##reverse_proxy_addresses## - Comma/space-separated proxy IPs ||
|
| 160 |
|
|| - ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##) ||
|
| 161 |
|
|| **Example:** ||
|
| 162 |
|
|| %%php
|
| |
174 |
%%
|
| |
175 |
|
| |
176 |
----
|
| |
177 |
|
| |
178 |
==== IP Address Detection ====
|
| |
179 |
|
| |
180 |
===== ##real_ip(): string## (Private) =====
|
| |
181 |
Detects client's real IP address accounting for proxies.
|
| |
182 |
|
| |
183 |
**Proxy Headers Checked (in order):**
|
| |
184 |
1. ##HTTP_X_CLUSTER_CLIENT_IP##
|
| |
185 |
2. ##HTTP_X_FORWARDED_FOR## (or custom header)
|
| |
186 |
3. ##HTTP_CLIENT_IP##
|
| |
187 |
4. ##HTTP_X_REMOTE_ADDR##
|
| |
188 |
5. ##REMOTE_ADDR## (fallback)
|
| |
189 |
|
| |
190 |
**Features:**
|
| |
191 |
- Filters out private/reserved IP ranges
|
| |
192 |
- Respects configured reverse proxy addresses
|
| |
193 |
- Returns ##'0.0.0.0'## as fallback
|
| |
194 |
|
| |
195 |
**Configuration in Database:**
|
| |
196 |
- ##reverse_proxy_addresses## - Comma/space-separated proxy IPs
|
| |
197 |
- ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##)
|
| |
198 |
|
| |
199 |
**Example:**
|
| |
200 |
%%php
|
| 164 |
|
%% ||
|
| 165 |
|
|| ---- ||
|
| 166 |
|
|| ==== HTTPS Detection ==== ||
|
| 167 |
|
|| ===== ##tls_session(): bool## (Private) ===== ||
|
| 168 |
|
|| Detects if current connection uses HTTPS/TLS. ||
|
| 169 |
|
|| **Checks (any being true = HTTPS):** ||
|
| 170 |
|
|| - ##$_SERVER['HTTPS']## is 'on' ||
|
| 171 |
|
|| - ##$_SERVER['SERVER_PORT']## is 443 ||
|
| 172 |
|
|| - ##$_SERVER['HTTP_X_FORWARDED_PROTO']## is 'https' ||
|
| 173 |
|
|| - ##$_SERVER['HTTP_X_FORWARDED_SSL']## is 'on' ||
|
| 174 |
|
|| - ##$_SERVER['HTTP_X_FORWARDED_PORT']## is 443 ||
|
| 175 |
|
|| ---- ||
|
| 176 |
|
|| ==== Security Headers ==== ||
|
| 177 |
|
|| ===== ##http_security_headers(): void## ===== ||
|
| 178 |
|
|| Sets security-related HTTP headers. ||
|
| 179 |
|
|| **Headers Set:** ||
|
| 180 |
|
|| Header | Purpose | Config Key ||
|
| 181 |
|
|| -------- | --------- | ------------ ||
|
| 182 |
|
|| Content-Security-Policy | XSS/injection protection | ##csp## ||
|
| 183 |
|
|| Permissions-Policy | Control browser features | ##permissions_policy## ||
|
| 184 |
|
|| Referrer-Policy | Control referrer information | ##referrer_policy## ||
|
| 185 |
|
|| Strict-Transport-Security | Force HTTPS | Auto (TLS only) ||
|
| 186 |
|
|| X-Frame-Options | Clickjacking protection | Hardcoded: ##SAMEORIGIN## ||
|
| 187 |
|
|| X-Content-Type-Options | MIME sniffing prevention | Hardcoded: ##nosniff## ||
|
| 188 |
|
|| **CSP Configuration Options:** ||
|
| 189 |
|
|| - ##0## - Disabled ||
|
| 190 |
|
|| - ##1## - Default policy (from ##csp.conf##) ||
|
| 191 |
|
|| - ##2## - Custom policy (from ##csp_custom.conf##) ||
|
| 192 |
|
|| **Example:** ||
|
| 193 |
|
|| %%php
|
| 194 |
|
$http->http_security_headers();
|
| 195 |
|
%% ||
|
| 196 |
|
|| ---- ||
|
| 197 |
|
|| ==== HTTP Methods ==== ||
|
| 198 |
|
|| ===== ##redirect($url, $permanent = false): void## ===== ||
|
| 199 |
|
|| Performs an HTTP redirect. ||
|
| 200 |
|
|| **Parameters:** ||
|
| 201 |
|
|| - ##$url## (string) - Target URL ||
|
| 202 |
|
|| - ##$permanent## (bool) - Use 301 (permanent) vs 302 (temporary) ||
|
| 203 |
|
|| **Features:** ||
|
| 204 |
|
|| - Decodes ##&## entities to prevent broken redirects ||
|
| 205 |
|
|| - Only works if headers not yet sent ||
|
| 206 |
|
|| - Uses output buffering to work anywhere in page processing ||
|
| 207 |
|
|| **Example:** ||
|
| 208 |
|
|| %%php
|
| |
202 |
%%
|
| |
203 |
|
| |
204 |
----
|
| |
205 |
|
| |
206 |
==== HTTPS Detection ====
|
| |
207 |
|
| |
208 |
===== ##tls_session(): bool## (Private) =====
|
| |
209 |
Detects if current connection uses HTTPS/TLS.
|
| |
210 |
|
| |
211 |
**Checks (any being true = HTTPS):**
|
| |
212 |
- ##$_SERVER['HTTPS']## is 'on'
|
| |
213 |
- ##$_SERVER['SERVER_PORT']## is 443
|
| |
214 |
- ##$_SERVER['HTTP_X_FORWARDED_PROTO']## is 'https'
|
| |
215 |
- ##$_SERVER['HTTP_X_FORWARDED_SSL']## is 'on'
|
| |
216 |
- ##$_SERVER['HTTP_X_FORWARDED_PORT']## is 443
|
| |
217 |
|
| |
218 |
----
|
| |
219 |
|
| |
220 |
==== Security Headers ====
|
| |
221 |
|
| |
222 |
===== ##http_security_headers(): void## =====
|
| |
223 |
|
| |
224 |
|
| |
225 |
==== HTTP Methods ====
|
| |
226 |
|
| |
227 |
===== ##redirect($url, $permanent = false): void## =====
|
| |
228 |
Performs an HTTP redirect.
|
| |
229 |
|
| |
230 |
**Parameters:**
|
| |
231 |
- ##$url## (string) - Target URL
|
| |
232 |
- ##$permanent## (bool) - Use 301 (permanent) vs 302 (temporary)
|
| |
233 |
|
| |
234 |
**Features:**
|
| |
235 |
- Decodes ##&## entities to prevent broken redirects
|
| |
236 |
- Only works if headers not yet sent
|
| |
237 |
- Uses output buffering to work anywhere in page processing
|
| |
238 |
|
| |
239 |
**Example:**
|
| |
240 |
%%php
|
| 247 |
|
%% ||
|
| 248 |
|
|| ---- ||
|
| 249 |
|
|| ==== Caching Control ==== ||
|
| 250 |
|
|| ===== ##no_cache($client_only = true): void## ===== ||
|
| 251 |
|
|| Disables caching of the current page. ||
|
| 252 |
|
|| **Parameters:** ||
|
| 253 |
|
|| - ##$client_only## (bool, default: TRUE) ||
|
| 254 |
|
|| - ##TRUE##: Disable browser cache only ||
|
| 255 |
|
|| - ##FALSE##: Disable both browser and server cache ||
|
| 256 |
|
|| **Headers Set:** ||
|
| 257 |
|
|| - ##Last-Modified: <current-time>## (always fresh) ||
|
| 258 |
|
|| - ##Cache-Control: no-store## ||
|
| 259 |
|
|| **Example:** ||
|
| 260 |
|
|| %%php
|
| |
287 |
%%
|
| |
288 |
|
| |
289 |
----
|
| |
290 |
|
| |
291 |
==== Caching Control ====
|
| |
292 |
|
| |
293 |
===== ##no_cache($client_only = true): void## =====
|
| |
294 |
Disables caching of the current page.
|
| |
295 |
|
| |
296 |
**Parameters:**
|
| |
297 |
- ##$client_only## (bool, default: TRUE)
|
| |
298 |
- ##TRUE##: Disable browser cache only
|
| |
299 |
- ##FALSE##: Disable both browser and server cache
|
| |
300 |
|
| |
301 |
**Headers Set:**
|
| |
302 |
- ##Last-Modified: <current-time>## (always fresh)
|
| |
303 |
- ##Cache-Control: no-store##
|
| |
304 |
|
| |
305 |
**Example:**
|
| |
306 |
%%php
|
| 272 |
|
%% ||
|
| 273 |
|
|| ---- ||
|
| 274 |
|
|| ==== Language Negotiation ==== ||
|
| 275 |
|
|| ===== ##user_agent_language(): string## ===== ||
|
| 276 |
|
|| Determines best language based on browser preferences. ||
|
| 277 |
|
|| **Features:** ||
|
| 278 |
|
|| - Follows RFC 9110 section 12.5.4 (HTTP Accept-Language) ||
|
| 279 |
|
|| - Parses ##Accept-Language## header with quality factors ||
|
| 280 |
|
|| - Attempts exact match first, then language fallback ||
|
| 281 |
|
|| - Falls back to default system language ||
|
| 282 |
|
|| **Example Header:** ||
|
| 283 |
|
|| %%
|
| |
322 |
%%
|
| |
323 |
|
| |
324 |
----
|
| |
325 |
|
| |
326 |
==== Language Negotiation ====
|
| |
327 |
|
| |
328 |
===== ##user_agent_language(): string## =====
|
| |
329 |
Determines best language based on browser preferences.
|
| |
330 |
|
| |
331 |
**Features:**
|
| |
332 |
- Follows RFC 9110 section 12.5.4 (HTTP Accept-Language)
|
| |
333 |
- Parses ##Accept-Language## header with quality factors
|
| |
334 |
- Attempts exact match first, then language fallback
|
| |
335 |
- Falls back to default system language
|
| |
336 |
|
| |
337 |
**Example Header:**
|
| |
338 |
%%
|
| 285 |
|
%% ||
|
| 286 |
|
|| **Returns:** ||
|
| 287 |
|
|| - Language code (e.g., 'en', 'en-US', 'de') ||
|
| 288 |
|
|| ---- ||
|
| 289 |
|
|| ===== ##available_languages($subset = true): array## ===== ||
|
| 290 |
|
|| Returns list of available language translations. ||
|
| 291 |
|
|| **Parameters:** ||
|
| 292 |
|
|| - ##$subset## (bool, default: TRUE) ||
|
| 293 |
|
|| - ##TRUE##: Only allowed languages ||
|
| 294 |
|
|| - ##FALSE##: All available languages ||
|
| 295 |
|
|| **Features:** ||
|
| 296 |
|
|| - Scans ##LANG_DIR## for language files ||
|
| 297 |
|
|| - Filters by ##allowed_languages## config if set ||
|
| 298 |
|
|| - Caches result in session ||
|
| 299 |
|
|| - System language always included ||
|
| 300 |
|
|| **Returns:** ||
|
| 301 |
|
|| - Associative array: ##['en' => 'en', 'de' => 'de', ...]## ||
|
| 302 |
|
|| **Example:** ||
|
| 303 |
|
|| %%php
|
| |
340 |
%%
|
| |
341 |
|
| |
342 |
**Returns:**
|
| |
343 |
- Language code (e.g., 'en', 'en-US', 'de')
|
| |
344 |
|
| |
345 |
----
|
| |
346 |
|
| |
347 |
===== ##available_languages($subset = true): array## =====
|
| |
348 |
Returns list of available language translations.
|
| |
349 |
|
| |
350 |
**Parameters:**
|
| |
351 |
- ##$subset## (bool, default: TRUE)
|
| |
352 |
- ##TRUE##: Only allowed languages
|
| |
353 |
- ##FALSE##: All available languages
|
| |
354 |
|
| |
355 |
**Features:**
|
| |
356 |
- Scans ##LANG_DIR## for language files
|
| |
357 |
- Filters by ##allowed_languages## config if set
|
| |
358 |
- Caches result in session
|
| |
359 |
- System language always included
|
| |
360 |
|
| |
361 |
**Returns:**
|
| |
362 |
- Associative array: ##['en' => 'en', 'de' => 'de', ...]##
|
| |
363 |
|
| |
364 |
**Example:**
|
| |
365 |
%%php
|
| 306 |
|
%% ||
|
| 307 |
|
|| ---- ||
|
| 308 |
|
|| ==== File Serving ==== ||
|
| 309 |
|
|| ===== ##sendfile($path, $filename = null, $age = null): void## ===== ||
|
| 310 |
|
|| Serves files with proper HTTP headers and caching. ||
|
| 311 |
|
|| **Parameters:** ||
|
| 312 |
|
|| - ##$path## (string) - File path (or HTTP_XXX constant for error pages) ||
|
| 313 |
|
|| - ##$filename## (string, optional) - Custom download filename ||
|
| 314 |
|
|| - ##$age## (int, optional) - Cache age in days ||
|
| 315 |
|
|| **Features:** ||
|
| 316 |
|
|| - HTTP range request support (partial file downloads) ||
|
| 317 |
|
|| - ETag and Last-Modified conditional requests ||
|
| 318 |
|
|| - Proper MIME type detection ||
|
| 319 |
|
|| - Content-Security-Policy for special file types ||
|
| 320 |
|
|| - Streaming for large files ||
|
| 321 |
|
|| - GZip compression for text files ||
|
| 322 |
|
|| **Special Paths:** ||
|
| 323 |
|
|| %%php
|
| |
368 |
%%
|
| |
369 |
|
| |
370 |
----
|
| |
371 |
|
| |
372 |
==== File Serving ====
|
| |
373 |
|
| |
374 |
===== ##sendfile($path, $filename = null, $age = null): void## =====
|
| |
375 |
Serves files with proper HTTP headers and caching.
|
| |
376 |
|
| |
377 |
**Parameters:**
|
| |
378 |
- ##$path## (string) - File path (or HTTP_XXX constant for error pages)
|
| |
379 |
- ##$filename## (string, optional) - Custom download filename
|
| |
380 |
- ##$age## (int, optional) - Cache age in days
|
| |
381 |
|
| |
382 |
**Features:**
|
| |
383 |
- HTTP range request support (partial file downloads)
|
| |
384 |
- ETag and Last-Modified conditional requests
|
| |
385 |
- Proper MIME type detection
|
| |
386 |
- Content-Security-Policy for special file types
|
| |
387 |
- Streaming for large files
|
| |
388 |
- GZip compression for text files
|
| |
389 |
|
| |
390 |
**Special Paths:**
|
| |
391 |
%%php
|
| 340 |
|
%% ||
|
| 341 |
|
|| ---- ||
|
| 342 |
|
|| ===== ##mime_types(): array## (Private) ===== ||
|
| 343 |
|
|| Loads and caches MIME types from configuration. ||
|
| 344 |
|
|| **Features:** ||
|
| 345 |
|
|| - Reads from ##config/mime.types## ||
|
| 346 |
|
|| - Caches to ##cache/config/mime.types## ||
|
| 347 |
|
|| - Reloads if config is updated ||
|
| 348 |
|
|| ---- ||
|
| 349 |
|
|| ==== Compression ==== ||
|
| 350 |
|
|| ===== ##gzip(): void## ===== ||
|
| 351 |
|
|| Compresses HTTP response with gzip/x-gzip. ||
|
| 352 |
|
|| **Features:** ||
|
| 353 |
|
|| - Manually implements gzip (not relying on zlib.output_compression) ||
|
| 354 |
|
|| - Produces correct ##Content-Length## header ||
|
| 355 |
|
|| - Only compresses if: ||
|
| 356 |
|
|| - 860 bytes < content < 1 MB ||
|
| 357 |
|
|| - Client accepts compression ||
|
| 358 |
|
|| - Headers not already sent ||
|
| 359 |
|
|| **Example:** ||
|
| 360 |
|
|| %%php
|
| |
413 |
%%
|
| |
414 |
|
| |
415 |
----
|
| |
416 |
|
| |
417 |
===== ##mime_types(): array## (Private) =====
|
| |
418 |
Loads and caches MIME types from configuration.
|
| |
419 |
|
| |
420 |
**Features:**
|
| |
421 |
- Reads from ##config/mime.types##
|
| |
422 |
- Caches to ##cache/config/mime.types##
|
| |
423 |
- Reloads if config is updated
|
| |
424 |
|
| |
425 |
----
|
| |
426 |
|
| |
427 |
==== Compression ====
|
| |
428 |
|
| |
429 |
===== ##gzip(): void## =====
|
| |
430 |
Compresses HTTP response with gzip/x-gzip.
|
| |
431 |
|
| |
432 |
**Features:**
|
| |
433 |
- Manually implements gzip (not relying on zlib.output_compression)
|
| |
434 |
- Produces correct ##Content-Length## header
|
| |
435 |
- Only compresses if:
|
| |
436 |
- 860 bytes < content < 1 MB
|
| |
437 |
- Client accepts compression
|
| |
438 |
- Headers not already sent
|
| |
439 |
|
| |
440 |
**Example:**
|
| |
441 |
%%php
|
| 373 |
|
%% ||
|
| 374 |
|
|| ---- ||
|
| 375 |
|
|| ===== ##request_uri(): string## (Private) ===== ||
|
| 376 |
|
|| Extracts and normalizes REQUEST_URI from server. ||
|
| 377 |
|
|| **Normalization:** ||
|
| 378 |
|
|| - Removes base URL prefix ||
|
| 379 |
|
|| - Removes spaces ||
|
| 380 |
|
|| - Collapses multiple slashes ||
|
| 381 |
|
|| - Removes ##..## path traversal attempts ||
|
| 382 |
|
|| - Removes leading/trailing slashes ||
|
| 383 |
|
|| ---- ||
|
| 384 |
|
|| ===== ##cut_prefix($prefix, $path): string## (Private) ===== ||
|
| 385 |
|
|| Removes prefix from path (case-insensitive). ||
|
| 386 |
|
|| ---- ||
|
| 387 |
|
|| ===== ##get_header_conf($file_name): string## (Private) ===== ||
|
| 388 |
|
|| Loads security header configuration from files. ||
|
| 389 |
|
|| **Files Supported:** ||
|
| 390 |
|
|| - ##csp.conf## / ##csp_custom.conf## ||
|
| 391 |
|
|| - ##permissions_policy.conf## / ##permissions_policy_custom.conf## ||
|
| 392 |
|
|| ---- ||
|
| 393 |
|
|| === Configuration Dependencies === ||
|
| 394 |
|
|| The class relies on these database configuration settings: ||
|
| 395 |
|
|| Setting | Type | Purpose ||
|
| 396 |
|
|| --------- | ------ | --------- ||
|
| 397 |
|
|| ##base_url## | string | Wiki's base URL ||
|
| 398 |
|
|| ##tls## | bool | Enable HTTPS enforcement ||
|
| 399 |
|
|| ##cache## | bool | Enable page caching ||
|
| 400 |
|
|| ##cache_ttl## | int | Cache lifetime in seconds ||
|
| 401 |
|
|| ##session_store## | int | 1=File, 0=Database ||
|
| 402 |
|
|| ##system_seed_hash## | string | Session encryption seed ||
|
| 403 |
|
|| ##cookie_prefix## | string | Session cookie prefix ||
|
| 404 |
|
|| ##cookie_path## | string | Cookie path ||
|
| 405 |
|
|| ##allow_persistent_cookie## | bool | Allow persistent login ||
|
| 406 |
|
|| ##session_length## | int | Session lifetime in seconds ||
|
| 407 |
|
|| ##reverse_proxy_addresses## | string | Comma/space-separated proxy IPs ||
|
| 408 |
|
|| ##reverse_proxy_header## | string | Custom X-Forwarded header ||
|
| 409 |
|
|| ##language## | string | Default language code ||
|
| 410 |
|
|| ##multilanguage## | bool | Enable language negotiation ||
|
| 411 |
|
|| ##allowed_languages## | string | Comma/space-separated allowed langs ||
|
| 412 |
|
|| ##enable_security_headers## | bool | Send security headers ||
|
| 413 |
|
|| ##csp## | int | CSP setting (0/1/2) ||
|
| 414 |
|
|| ##permissions_policy## | int | Permissions-Policy setting (0/1/2) ||
|
| 415 |
|
|| ##referrer_policy## | int | Referrer-Policy setting (0-8) ||
|
| 416 |
|
|| ---- ||
|
| 417 |
|
|| === Constants Used === ||
|
| 418 |
|
|| Constant | Type | Purpose ||
|
| 419 |
|
|| ---------- | ------ | --------- ||
|
| 420 |
|
|| ##IN_WACKO## | bool | Security check (exit if not defined) ||
|
| 421 |
|
|| ##CHMOD_SAFE## | int | File permissions for cache files ||
|
| 422 |
|
|| ##CHMOD_FILE## | int | File permissions for config cache ||
|
| 423 |
|
|| ##CACHE_PAGE_DIR## | string | Page cache directory ||
|
| 424 |
|
|| ##CACHE_SESSION_DIR## | string | Session cache directory ||
|
| 425 |
|
|| ##CACHE_CONFIG_DIR## | string | Config cache directory ||
|
| 426 |
|
|| ##CONFIG_DIR## | string | Configuration directory ||
|
| 427 |
|
|| ##LANG_DIR## | string | Language files directory ||
|
| 428 |
|
|| ##DAYSECS## | int | Seconds in a day (86400) ||
|
| 429 |
|
|| ##HTTP_404## | string | Path to 404 error page ||
|
| 430 |
|
|| ##HTTP_403## | string | Path to 403 error page ||
|
| 431 |
|
|#
|
| 432 |
|
|
| 433 |
|
----
|
| |
459 |
%%
|
| |
460 |
|
| |
461 |
----
|
| |
462 |
|
| |
463 |
===== ##request_uri(): string## (Private) =====
|
| |
464 |
Extracts and normalizes REQUEST_URI from server.
|
| |
465 |
|
| |
466 |
**Normalization:**
|
| |
467 |
- Removes base URL prefix
|
| |
468 |
- Removes spaces
|
| |
469 |
- Collapses multiple slashes
|
| |
470 |
- Removes ##..## path traversal attempts
|
| |
471 |
- Removes leading/trailing slashes
|
| |
472 |
|
| |
473 |
----
|
| |
474 |
|
| |
475 |
===== ##cut_prefix($prefix, $path): string## (Private) =====
|
| |
476 |
Removes prefix from path (case-insensitive).
|
| |
477 |
|
| |
478 |
----
|
| |
479 |
|
| |
480 |
===== ##get_header_conf($file_name): string## (Private) =====
|
| |
481 |
Loads security header configuration from files.
|
| |
482 |
|
| |
483 |
**Files Supported:**
|
| |
484 |
- ##csp.conf## / ##csp_custom.conf##
|
| |
485 |
- ##permissions_policy.conf## / ##permissions_policy_custom.conf##
|
| |
486 |
|
| |
487 |
----
|
| |
488 |
|
| |
489 |
=== Configuration Dependencies ===
|
| |
490 |
|
| |
491 |
|
| |
492 |
|
| |
493 |
=== Constants Used ===
|
| |
494 |
|
| |
495 |
|