Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
148 lines (133 loc) · 5.18 KB
/
Copy pathsetup.php
File metadata and controls
148 lines (133 loc) · 5.18 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* -------------------------------------------------------------------------
* LogByMail plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2026 LORENTZ Johan
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/lorentzjohan
* -------------------------------------------------------------------------
*/
use Glpi\Plugin\Hooks;
use GlpiPlugin\Logbymail\LoginPageCustomizer;
use GlpiPlugin\Logbymail\LoginRequestHandler;
use GlpiPlugin\Logbymail\UserLists;
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_LOGBYMAIL_VERSION', '1.2.1');
// Minimal GLPI version, inclusive: GLPI 11.x
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_LOGBYMAIL_MIN_GLPI_VERSION', '11.0.0');
// Maximum GLPI version, exclusive: every GLPI 12.x release is accepted
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_LOGBYMAIL_MAX_GLPI_VERSION', '13.0.0');
// Minimal PHP version, inclusive (same as GLPI 11; GLPI 12 itself requires PHP 8.3)
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_LOGBYMAIL_MIN_PHP_VERSION', '8.2.0');
/**
* Init hooks of the plugin.
* REQUIRED
*
* Called on every request, so it must stay cheap:
* - the e-mail resolution only runs on a POST to /front/login.php;
* - the login page customization is only registered for unauthenticated sessions.
*/
function plugin_init_logbymail(): void
{
/** @var array<string, array<string, mixed>> $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS[Hooks::CONFIG_PAGE]['logbymail'] = 'config';
// Keep the included / excluded users lists clean when a user is purged.
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['logbymail'] = [User::class => UserLists::onUserPurge(...)];
// Translate an e-mail address typed in the login form into the matching GLPI login,
// before GLPI's own authentication process (and 2FA) runs.
LoginRequestHandler::handleCurrentRequest();
// "Login or e-mail" label on the login page. Registered on POST_INIT, once the
// plugin translations are loaded.
if (LoginPageCustomizer::isNeededForCurrentRequest()) {
$PLUGIN_HOOKS[Hooks::POST_INIT]['logbymail'] = LoginPageCustomizer::registerHooks(...);
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array{
* name: string,
* version: string,
* author: string,
* license: string,
* homepage: string,
* requirements: array{
* glpi: array{
* min: string,
* max: string,
* },
* php: array{
* min: string,
* }
* }
* }
*/
function plugin_version_logbymail(): array
{
return [
'name' => 'LogByMail',
'version' => PLUGIN_LOGBYMAIL_VERSION,
'author' => 'LORENTZ Johan',
'license' => 'MIT',
'homepage' => 'https://github.com/lorentzjohan/logbymail',
'requirements' => [
'glpi' => [
'min' => PLUGIN_LOGBYMAIL_MIN_GLPI_VERSION,
'max' => PLUGIN_LOGBYMAIL_MAX_GLPI_VERSION,
],
'php' => [
'min' => PLUGIN_LOGBYMAIL_MIN_PHP_VERSION,
],
],
];
}
/**
* Check pre-requisites before install
* OPTIONAL
*/
function plugin_logbymail_check_prerequisites(): bool
{
if (!extension_loaded('filter')) {
echo 'The PHP "filter" extension is required by the LogByMail plugin.';
return false;
}
return true;
}
/**
* Check configuration process
* OPTIONAL
*
* @param bool $verbose Whether to display message on failure. Defaults to false.
*/
function plugin_logbymail_check_config(bool $verbose = false): bool
{
// Default settings are written on install and the plugin works out of the box.
return true;
}