-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.php
More file actions
108 lines (91 loc) · 4.4 KB
/
boot.php
File metadata and controls
108 lines (91 loc) · 4.4 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
105
106
107
108
<?php
declare(strict_types=1);
use FriendsOfREDAXO\YFormEncryption\EventHandler;
use FriendsOfREDAXO\YFormEncryption\FieldMapper;
use FriendsOfREDAXO\YFormEncryption\SessionGuard;
// Lokalen PhpSpreadsheet-Vendor einbinden
$vendorAutoload = __DIR__ . '/vendor/autoload.php';
if (file_exists($vendorAutoload)) {
require_once $vendorAutoload;
}
/**
* YForm Encryption AddOn - Boot.
*
* @var rex_addon $this
* @psalm-scope-this rex_addon
*/
// EP-Handler nur registrieren wenn YForm verfügbar ist
if (rex_addon::get('yform')->isAvailable()) {
EventHandler::register();
}
// Berechtigung registrieren – erscheint in Rollenverwaltung
if (rex::isBackend()) {
rex_perm::register('yform_encryption[export]', rex_i18n::msg('perm_yform_encryption_export'));
}
if (rex::isBackend() && rex::getUser()) {
rex_view::addCssFile($this->getAssetsUrl('css/yform-encryption.css'));
rex_view::addJsFile($this->getAssetsUrl('js/yform-encryption.js'));
// Auf YForm-Manager-Seiten: Lock/Unlock-Bar einblenden
rex_extension::register('PAGE_CHECKED', function () {
$page = rex_be_controller::getCurrentPage();
// Nur auf yform/manager-Seiten aktiv
if (!str_starts_with($page, 'yform/manager/data')) {
return;
}
// Prüfen ob die aktuelle Tabelle verschlüsselte Felder hat
$tableName = rex_request('table_name', 'string', '');
if ($tableName === '') {
return;
}
$mapper = FieldMapper::getInstance();
if (!$mapper->hasEncryptedFields($tableName)) {
return;
}
$guard = SessionGuard::getInstance();
$isUnlocked = $guard->isUnlocked();
$remaining = $guard->getRemainingTime();
$timeout = $guard->getTimeout();
// Daten als data-Attribute für JS bereitstellen
rex_extension::register('OUTPUT_FILTER', static function (rex_extension_point $ep) use ($isUnlocked, $remaining, $timeout, $tableName) {
$content = $ep->getSubject();
$statusBar = '<div id="yform-enc-status-bar" '
. 'data-unlocked="' . ($isUnlocked ? '1' : '0') . '" '
. 'data-remaining="' . $remaining . '" '
. 'data-timeout="' . $timeout . '" '
. 'data-table="' . rex_escape($tableName) . '" '
. 'class="yform-enc-bar' . ($isUnlocked ? ' yform-enc-bar-unlocked' : ' yform-enc-bar-locked') . '">'
. '</div>';
// Auth-Modal
$modal = '<div id="yform-enc-auth-modal" class="yform-enc-modal" style="display:none">'
. '<div class="yform-enc-modal-backdrop"></div>'
. '<div class="yform-enc-modal-dialog">'
. '<div class="yform-enc-modal-header">'
. '<h4><i class="rex-icon fa-lock"></i> ' . rex_i18n::msg('yform_encryption_auth_title') . '</h4>'
. '</div>'
. '<div class="yform-enc-modal-body">'
. '<p>' . rex_i18n::msg('yform_encryption_auth_desc') . '</p>'
. '<div class="form-group">'
. '<label for="yform-enc-login">' . rex_i18n::msg('yform_encryption_auth_login') . '</label>'
. '<input type="text" class="form-control" id="yform-enc-login" autocomplete="username">'
. '</div>'
. '<div class="form-group">'
. '<label for="yform-enc-password">' . rex_i18n::msg('yform_encryption_auth_password') . '</label>'
. '<input type="password" class="form-control" id="yform-enc-password" autocomplete="current-password">'
. '</div>'
. '<div id="yform-enc-auth-error" class="alert alert-danger" style="display:none"></div>'
. '</div>'
. '<div class="yform-enc-modal-footer">'
. '<button type="button" class="btn btn-default" id="yform-enc-cancel">'
. rex_i18n::msg('yform_encryption_auth_cancel') . '</button> '
. '<button type="button" class="btn btn-primary" id="yform-enc-submit">'
. '<i class="rex-icon fa-unlock"></i> '
. rex_i18n::msg('yform_encryption_auth_submit') . '</button>'
. '</div>'
. '</div>'
. '</div>';
// Vor </body> einfügen
$content = str_replace('</body>', $statusBar . $modal . '</body>', $content);
return $content;
});
});
}