-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathupdate.php
More file actions
104 lines (85 loc) · 4.25 KB
/
Copy pathupdate.php
File metadata and controls
104 lines (85 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
$addon = rex_addon::get('maintenance');
// Upgrade from 2.x to 3.x
if (rex_version::compare($addon->getVersion(), '3.0.0-dev', '<')) {
if ($addon->hasConfig('responsecode')) {
$addon->setConfig('http_response_code', $addon->getConfig('responsecode'));
}
if ($addon->hasConfig('ip')) {
$addon->setConfig('allowed_ips', $addon->getConfig('ip'));
}
if ($addon->hasConfig('frontend_aktiv')) {
$addon->setConfig('block_frontend', 'Deaktivieren' === $addon->getConfig('frontend_aktiv') ? 0 : 1);
}
if ($addon->hasConfig('redirect_frontend')) {
$addon->setConfig('redirect_frontend_to_url', $addon->getConfig('redirect_frontend'));
}
if ($addon->hasConfig('redirect_backend')) {
$addon->setConfig('redirect_backend_to_url', $addon->getConfig('redirect_backend'));
}
if ($addon->hasConfig('backend_aktiv')) {
$addon->setConfig('block_backend', '1' === $addon->getConfig('backend_aktiv') ? 1 : 0);
}
if ($addon->hasConfig('blockSession')) {
$addon->setConfig('block_frontend_rex_user', 'Inaktiv' === $addon->getConfig('blockSession') ? 0 : 1);
}
if ($addon->hasConfig('type')) {
$addon->setConfig('authentication_mode', 'Password' === $addon->getConfig('type') ? 'password' : 'URL');
}
if ($addon->hasConfig('secret')) {
$addon->setConfig('maintenance_secret', $addon->getConfig('secret'));
}
$addon->removeConfig('responsecode');
$addon->removeConfig('ip');
$addon->removeConfig('frontend_aktiv');
$addon->removeConfig('redirect_frontend');
$addon->removeConfig('redirect_backend');
$addon->removeConfig('backend_aktiv');
$addon->removeConfig('blockSession');
$addon->removeConfig('type');
$addon->removeConfig('secret');
}
// Migration von 'authentification_mode' zu 'authentication_mode' (Rechtschreibkorrektur)
// Prüfe zuerst, ob die alte falsche Schreibweise existiert
if ($addon->hasConfig('authentification_mode')) {
// Wenn die neue korrekte Schreibweise noch nicht existiert, übernehme den Wert
if (!$addon->hasConfig('authentication_mode')) {
$addon->setConfig('authentication_mode', $addon->getConfig('authentification_mode'));
}
// Entferne in jedem Fall die alte falsche Schreibweise
$addon->removeConfig('authentification_mode');
}
// Leerer String ('') und 'URL' werden beide als gültige URL-Authentifizierung betrachtet
$authentication_mode = $addon->getConfig('authentication_mode', '');
if (!in_array($authentication_mode, ['URL', 'password'], true)) {
// Wenn kein gültiger Modus gesetzt ist, standardmäßig auf URL setzen
$addon->setConfig('authentication_mode', 'URL');
}
// Überprüfen, ob ein maintenance_secret existiert
if (!$addon->hasConfig('maintenance_secret') || '' === $addon->getConfig('maintenance_secret')) {
// Falls kein Secret vorhanden, ein neues generieren
$addon->setConfig('maintenance_secret', bin2hex(random_bytes(16)));
}
// Migration der alten allowed_yrewrite_domains zu neuem domain_status System
if ($addon->hasConfig('allowed_yrewrite_domains') && !$addon->hasConfig('domain_status')) {
$oldAllowedDomains = (string) $addon->getConfig('allowed_yrewrite_domains', '');
if ('' !== $oldAllowedDomains && rex_addon::exists('yrewrite') && rex_addon::get('yrewrite')->isAvailable()) {
// Die alten allowed_yrewrite_domains waren eine Whitelist (erlaubte Domains)
// Im neuen System bedeutet: Domains die NICHT in der Whitelist sind, sollten gesperrt sein
$allowedDomainsArray = explode('|', $oldAllowedDomains);
$allowedDomainsArray = array_filter(array_map('trim', $allowedDomainsArray));
$domainStatus = [];
foreach (rex_yrewrite::getDomains() as $domain) {
$domainName = $domain->getName();
if ('default' !== $domainName) {
// Domain ist gesperrt, wenn sie NICHT in der Whitelist war
$domainStatus[$domainName] = !in_array($domain->getHost(), $allowedDomainsArray, true);
}
}
if (!empty($domainStatus)) {
$addon->setConfig('domain_status', $domainStatus);
}
}
// Alte Konfiguration kann entfernt werden (bleibt aber zur Kompatibilität)
// $addon->removeConfig('allowed_yrewrite_domains');
}