-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathdebug.php
122 lines (110 loc) · 3.79 KB
/
debug.php
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
<?php
/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2025 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/
use Glpi\Exception\Http\AccessDeniedHttpException;
use Glpi\Exception\Http\BadRequestHttpException;
use Glpi\Exception\Http\NotFoundHttpException;
Html::header_nocache();
if ($_SESSION['glpi_use_mode'] !== Session::DEBUG_MODE) {
throw new AccessDeniedHttpException();
}
\Glpi\Debug\Profiler::getInstance()->disable();
if (isset($_GET['ajax_id'])) {
// Get debug data for a specific ajax call
$ajax_id = $_GET['ajax_id'];
$profile = \Glpi\Debug\Profile::pull($ajax_id);
// Close session ASAP to not block other requests.
// DO NOT do it before call to `\Glpi\Debug\Profile::pull()`,
// as we have to delete profile from `$_SESSION` during the pull operation.
session_write_close();
header('Content-Type: application/json');
if ($profile) {
$data = $profile->getDebugInfo();
if ($data) {
echo json_encode($data);
}
}
return;
}
if (isset($_GET['action'])) {
$action = $_GET['action'];
if ($action === 'get_itemtypes') {
$loaded = get_declared_classes();
$glpi_classes = array_filter($loaded, static function ($class) {
if (!is_subclass_of($class, 'CommonDBTM')) {
return false;
}
$reflection_class = new ReflectionClass($class);
if ($reflection_class->isAbstract()) {
return false;
}
return true;
});
sort($glpi_classes);
header('Content-Type: application/json');
echo json_encode($glpi_classes);
return;
}
if ($action === 'get_search_options' && isset($_GET['itemtype'])) {
header('Content-Type: application/json');
$class = $_GET['itemtype'];
if (!class_exists($class) || !is_subclass_of($class, 'CommonDBTM')) {
echo '[]';
return;
}
$reflection_class = new ReflectionClass($class);
if ($reflection_class->isAbstract()) {
echo '[]';
return;
}
try {
/** @var CommonGLPI $item */
$item = new $_GET['itemtype']();
$options = Search::getOptions($item::getType());
} catch (Throwable $e) {
$options = [];
}
$options = array_filter($options, static function ($k) {
return is_numeric($k);
}, ARRAY_FILTER_USE_KEY);
echo json_encode($options);
return;
}
if ($action === 'get_themes') {
header('Content-Type: application/json');
$themes = \Glpi\UI\ThemeManager::getInstance()->getAllThemes();
echo json_encode($themes);
return;
}
}
throw new BadRequestHttpException();