Debian Codegraph @

templates/schema/schema.php

raw
1 <?php
2 namespace LAM\SCHEMA;
3 use \htmlResponsiveRow;
4 use \htmlSpacer;
5 use \htmlLink;
6 use \htmlStatusMessage;
7 use \htmlResponsiveTable;
8 use \htmlOutputText;
9 use \htmlGroup;
10 use \htmlSelect;
11 use \htmlDiv;
12 use \htmlSubTitle;
13 use htmlTitle;
14
15 /*
16
17 Copyright (C) 2018 - 2025 Roland Gruber
18
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
33 */
34
35
36 /**
37 * Displays the LDAP schema of the server
38 *
39 * @package tools
40 * @author Roland Gruber
41 */
42
43
44 /** security functions */
45 include_once(__DIR__ . "/../../lib/security.inc");
46 /** access to LDAP server */
47 include_once(__DIR__ . "/../../lib/ldap.inc");
48 /** access to configuration options */
49 include_once(__DIR__ . "/../../lib/config.inc");
50 /** schema functions */
51 require_once(__DIR__ . "/../../lib/schema.inc");
52
53 // start session
54 startSecureSession();
55 enforceUserIsLoggedIn();
56
57 checkIfToolIsActive('toolSchemaBrowser');
58
59 setlanguage();
60
61 include __DIR__ . '/../../lib/adminHeader.inc';
62 echo "<div class=\"smallPaddingContent\">\n";
63
64 $availableViews = ['objectClass', 'attribute', 'syntax', 'rule'];
65 $selectedView = 'objectClass';
66 if (!empty($_GET['display']) && in_array($_GET['display'], $availableViews)) {
67 $selectedView = $_GET['display'];
68 }
69
70 $row = new htmlResponsiveRow();
71 $row->add(new htmlTitle(_('Schema browser')));
72 $row->addVerticalSpacer('2rem');
73 $row->add(new htmlSpacer('1rem', '1px'), 0, 2);
74 $row->add(new htmlLink(_('Object classes'), 'schema.php'), 12, 2, 2, 'font-big text-center');
75 $row->add(new htmlLink(_('Attribute types'), 'schema.php?display=attribute'), 12, 2, 2, 'font-big text-center');
76 $row->add(new htmlLink(_('Syntaxes'), 'schema.php?display=syntax'), 12, 2, 2, 'font-big text-center');
77 $row->add(new htmlLink(_('Matching rules'), 'schema.php?display=rule'), 12, 2, 2, 'font-big text-center');
78 $row->add(new htmlSpacer('1rem', '1px'), 0, 2);
79 $row->addVerticalSpacer('2rem');
80
81 if ($selectedView === 'syntax') {
82 displaySyntaxList($row);
83 }
84 elseif( $selectedView == 'attribute' ) {
85 displayAttributeList($row);
86 }
87 elseif ($selectedView === 'rule') {
88 displayRuleList($row);
89 }
90 elseif( $selectedView == 'objectClass' ) {
91 displayObjectClassList($row);
92 }
93
94 parseHtml(null, $row, [], false, 'user');
95
96 echo '</div>';
97 include __DIR__ . '/../../lib/adminFooter.inc';
98
99 /**
100 * Displays the syntax list.
101 *
102 * @param htmlResponsiveRow $row row
103 */
104 function displaySyntaxList(htmlResponsiveRow &$row): void {
105 $schema_syntaxes = get_schema_syntaxes(null);
106 if (!$schema_syntaxes) {
107 $row->add(new htmlStatusMessage("ERROR", _("Unable to retrieve schema!")), 12);
108 return;
109 }
110 $data = [];
111 $labels = [_('Syntax OID'), _('Description')];
112 $pos = 0;
113 $highlighted = [];
114 foreach( $schema_syntaxes as $syntax ) {
115 $oid = new htmlOutputText($syntax->getOID());
116 $description = new htmlOutputText($syntax->getDescription());
117 $data[] = [$oid, $description];
118 if (!empty($_GET['sel']) && ($syntax->getOID() === $_GET['sel'])) {
119 $highlighted[] = $pos;
120 }
121 $pos++;
122 }
123 $table = new htmlResponsiveTable($labels, $data, $highlighted);
124 $table->setCSSClasses(['colored--table']);
125 $row->add($table);
126 }
127
128 /**
129 * Displays the matching rule list.
130 *
131 * @param htmlResponsiveRow $row row
132 */
133 function displayRuleList(htmlResponsiveRow &$row): void {
134 $rules = get_schema_matching_rules(null);
135 if (!$rules) {
136 $row->add(new htmlStatusMessage("ERROR", _("Unable to retrieve schema!")), 12);
137 return;
138 }
139 $row->addLabel(new htmlOutputText(_('Jump to a matching rule')));
140 $availableRules = [''];
141 foreach ($rules as $rule) {
142 $availableRules[] = $rule->getName();
143 }
144 $selectedRule = [];
145 if (!empty($_GET['sel']) && in_array($_GET['sel'], $availableRules)) {
146 $selectedRule[] = $_GET['sel'];
147 }
148 $ruleSelect = new htmlSelect('lam-schema-select', $availableRules, $selectedRule);
149 $ruleSelect->addDataAttribute('display', 'rule');
150 $row->addField($ruleSelect);
151 $row->addVerticalSpacer('1rem');
152
153 $labels = [_('Matching rule OID'), _('Name'), _('Used by attributes')];
154 $data = [];
155 foreach ($rules as $rule) {
156 if (!empty($selectedRule) && !in_array($rule->getName(), $selectedRule)) {
157 continue;
158 }
159 $oid = new htmlOutputText($rule->getOID());
160 $name = $rule->getName();
161 if (!empty($rule->getDescription())) {
162 $name .= ' (' . $rule->getDescription() . ')';
163 }
164 if ($rule->getIsObsolete()) {
165 $name .= ' (' . _('Obsolete') . ')';
166 }
167 $nameText = new htmlOutputText($name);
168 $attributes = new htmlGroup();
169 foreach ($rule->getUsedByAttrs() as $attr) {
170 $attributes->addElement(new htmlDiv(null, new htmlLink($attr, 'schema.php?display=attribute&sel=' . $attr)));
171 }
172 $data[] = [$oid, $nameText, new htmlDiv(null, $attributes, ['smallScroll'])];
173 }
174 $table = new htmlResponsiveTable($labels, $data);
175 $table->setCSSClasses(['colored--table']);
176 $row->add($table);
177 }
178
179 /**
180 * Displays the object class list.
181 *
182 * @param htmlResponsiveRow $row row
183 */
184 function displayObjectClassList(htmlResponsiveRow &$row): void {
185 $objectClasses = get_schema_objectclasses();
186 if (empty($objectClasses)) {
187 $row->add(new htmlStatusMessage("ERROR", _("Unable to retrieve schema!")), 12);
188 return;
189 }
190 $row->addLabel(new htmlOutputText(_('Jump to an object class')));
191 $availableClasses = [_('all') => ''];
192 foreach ($objectClasses as $objectClass) {
193 $availableClasses[$objectClass->getName()] = $objectClass->getName();
194 }
195 $selectedClass = [];
196 if (isset($_GET['sel']) && (empty($_GET['sel']) || array_key_exists(strtolower($_GET['sel']), $objectClasses))) {
197 $selectedClass[0] = $_GET['sel'];
198 }
199 if (empty($selectedClass)) {
200 // select first class by default
201 $selectedClassNames = array_keys($objectClasses);
202 $selectedClass[0] = $selectedClassNames[0];
203 }
204 $classSelect = new htmlSelect('lam-schema-select', $availableClasses, $selectedClass);
205 $classSelect->addDataAttribute('display', 'objectClass');
206 $classSelect->setHasDescriptiveElements(true);
207 $classSelect->setSortElements(false);
208 $row->addField($classSelect);
209 $row->addVerticalSpacer('1rem');
210
211 // fill child object classes
212 foreach ($objectClasses as $name => $objectClass) {
213 foreach ($objectClass->getSupClasses() as $subClass) {
214 if (!isset($objectClasses[strtolower($subClass)])) {
215 continue;
216 }
217 $objectClasses[strtolower($subClass)]->addChildObjectClass($name);
218 }
219 }
220
221 foreach ($objectClasses as $name => $objectClass) {
222 if (!empty($selectedClass[0]) && ($name !== strtolower($selectedClass[0]))) {
223 continue;
224 }
225 $row->add(new htmlSubTitle($objectClass->getName()), 12);
226 $row->addLabel(new htmlOutputText(_('OID')), 'bold-mobile-only');
227 $row->addField(new htmlOutputText($objectClass->getOID()));
228 if (!empty($objectClass->getDescription())) {
229 $row->addLabel(new htmlOutputText(_('Description')), 'bold-mobile-only');
230 $row->addField(new htmlOutputText($objectClass->getDescription()));
231 }
232 $row->addLabel(new htmlOutputText(_('Type')), 'bold-mobile-only');
233 $row->addField(new htmlOutputText($objectClass->getType()));
234 if ($objectClass->getIsObsolete()) {
235 $row->addLabel(new htmlOutputText(_('Obsolete')));
236 $row->addField(new htmlOutputText(_('yes')));
237 }
238 if (!empty($objectClass->getSupClasses())) {
239 $row->addLabel(new htmlOutputText(_('Inherits from')), 'bold-mobile-only');
240 $subClasses = new htmlGroup();
241 foreach ($objectClass->getSupClasses() as $subClass) {
242 $subClasses->addElement(new htmlDiv(null, new htmlLink($subClass, 'schema.php?display=objectClass&sel=' . rawurlencode($subClass))));
243 }
244 $row->addField($subClasses);
245 }
246 if (!empty($objectClass->getChildObjectClasses())) {
247 $row->addLabel(new htmlOutputText(_('Parent to')), 'bold-mobile-only');
248 $subClasses = new htmlGroup();
249 foreach ($objectClass->getChildObjectClasses() as $subClass) {
250 $subClasses->addElement(new htmlDiv(null, new htmlLink($subClass, 'schema.php?display=objectClass&sel=' . rawurlencode($subClass))));
251 }
252 $row->addField($subClasses);
253 }
254 if (!empty($objectClass->getMustAttrs())) {
255 $row->addLabel(new htmlOutputText(_('Required attributes')), 'bold-mobile-only');
256 $attributes = new htmlGroup();
257 foreach ($objectClass->getMustAttrs() as $attribute) {
258 $attributes->addElement(new htmlDiv(null, new htmlLink($attribute->getName(), 'schema.php?display=attribute&sel=' . rawurlencode($attribute->getName()))));
259 }
260 $row->addField($attributes);
261 }
262 if (!empty($objectClass->getMayAttrs())) {
263 $row->addLabel(new htmlOutputText(_('Optional attributes')), 'bold-mobile-only');
264 $attributes = new htmlGroup();
265 foreach ($objectClass->getMayAttrs() as $attribute) {
266 $attributes->addElement(new htmlDiv(null, new htmlLink($attribute->getName(), 'schema.php?display=attribute&sel=' . rawurlencode($attribute->getName()))));
267 }
268 $row->addField($attributes);
269 }
270 }
271 }
272
273 /**
274 * Displays the attributes list.
275 *
276 * @param htmlResponsiveRow $row row
277 */
278 function displayAttributeList(htmlResponsiveRow $row): void {
279 $attributes = get_schema_attributes(null);
280 if (!$attributes) {
281 $row->add(new htmlStatusMessage("ERROR", _("Unable to retrieve schema!")), 12);
282 return;
283 }
284 $row->addLabel(new htmlOutputText(_('Jump to an attribute type')));
285 $availableAttributes = [_('all') => ''];
286 foreach ($attributes as $attribute) {
287 $availableAttributes[$attribute->getName()] = $attribute->getName();
288 }
289 $selectedAttribute = [];
290 if (isset($_GET['sel']) && (empty($_GET['sel']) || array_key_exists(strtolower($_GET['sel']), $attributes))) {
291 $selectedAttribute[0] = $_GET['sel'];
292 }
293 if (empty($selectedAttribute) && (count($availableAttributes) > 1)) {
294 // select first attribute by default
295 $attributeNames = array_keys($availableAttributes);
296 $selectedAttribute[0] = $attributeNames[1];
297 }
298 $attributeSelect = new htmlSelect('lam-schema-select', $availableAttributes, $selectedAttribute);
299 $attributeSelect->addDataAttribute('display', 'attribute');
300 $attributeSelect->setHasDescriptiveElements(true);
301 $attributeSelect->setSortElements(false);
302 $row->addField($attributeSelect);
303 $row->addVerticalSpacer('1rem');
304
305 foreach ($attributes as $name => $attribute) {
306 if (!empty($selectedAttribute[0]) && ($name !== strtolower($selectedAttribute[0]))) {
307 continue;
308 }
309 $row->add(new htmlSubTitle($attribute->getName()));
310 if (!empty($attribute->getDescription())) {
311 $row->addLabel(new htmlOutputText(_('Description')), 'bold-mobile-only');
312 $row->addField(new htmlOutputText($attribute->getDescription()));
313 }
314 $row->addLabel(new htmlOutputText(_('OID')), 'bold-mobile-only');
315 $row->addField(new htmlOutputText($attribute->getOID()));
316 if ($attribute->getIsObsolete()) {
317 $row->addLabel(new htmlOutputText(_('Obsolete')), 'bold-mobile-only');
318 $row->addField(new htmlOutputText(_('yes')));
319 }
320 if (!empty($attribute->getSupAttribute())) {
321 $row->addLabel(new htmlOutputText(_('Inherits from')), 'bold-mobile-only');
322 $row->addField(new htmlLink($attribute->getSupAttribute(), 'schema.php?display=attribute&sel=' . rawurlencode($attribute->getSupAttribute())));
323 }
324 if (!empty($attribute->getEquality())) {
325 $row->addLabel(new htmlOutputText(_('Equality')), 'bold-mobile-only');
326 $row->addField(new htmlLink($attribute->getEquality(), 'schema.php?display=rule&sel=' . rawurldecode($attribute->getEquality())));
327 }
328 if (!empty($attribute->getOrdering())) {
329 $row->addLabel(new htmlOutputText(_('Ordering')), 'bold-mobile-only');
330 $row->addField(new htmlLink($attribute->getOrdering(), 'schema.php?display=rule&sel=' . rawurldecode($attribute->getOrdering())));
331 }
332 if (!empty($attribute->getSubstr())) {
333 $row->addLabel(new htmlOutputText(_('Substring Rule')), 'bold-mobile-only');
334 $row->addField(new htmlLink($attribute->getSubstr(), 'schema.php?display=rule&sel=' . rawurldecode($attribute->getSubstr())));
335 }
336 if (!empty($attribute->getSyntaxOID())) {
337 $row->addLabel(new htmlOutputText(_('Syntax')), 'bold-mobile-only');
338 $row->addField(new htmlLink($attribute->getSyntaxOID(), 'schema.php?display=syntax&sel=' . rawurldecode($attribute->getSyntaxOID())));
339 }
340 $row->addLabel(new htmlOutputText(_('Single valued')), 'bold-mobile-only');
341 $row->addField(new htmlOutputText($attribute->getIsSingleValue() ? _('yes') : _('no')));
342 $row->addLabel(new htmlOutputText(_('Collective')), 'bold-mobile-only');
343 $row->addField(new htmlOutputText($attribute->getIsCollective() ? _('yes') : _('no')));
344 $row->addLabel(new htmlOutputText(_('User modification')), 'bold-mobile-only');
345 $row->addField(new htmlOutputText($attribute->getIsNoUserModification() ? _('no') : _('yes')));
346 if (!empty($attribute->getUsage())) {
347 $row->addLabel(new htmlOutputText(_('Usage')), 'bold-mobile-only');
348 $row->addField(new htmlOutputText($attribute->getUsage()));
349 }
350 if (!empty($attribute->getMaxLength())) {
351 $row->addLabel(new htmlOutputText(_('Maximum length')), 'bold-mobile-only');
352 $row->addField(new htmlOutputText((string) $attribute->getMaxLength()));
353 }
354 if (!empty($attribute->getAliases())) {
355 $row->addLabel(new htmlOutputText(_('Aliases')), 'bold-mobile-only');
356 $aliases = new htmlGroup();
357 foreach ($attribute->getAliases() as $alias) {
358 $aliases->addElement(new htmlDiv(null, new htmlLink($alias, 'schema.php?display=attribute&sel=' . rawurlencode($alias))));
359 }
360 $row->addField($aliases);
361 }
362 if (!empty($attribute->getUsedInObjectClasses())) {
363 $row->addLabel(new htmlOutputText(_('Used by object classes')), 'bold-mobile-only');
364 $objectClasses = new htmlGroup();
365 foreach ($attribute->getUsedInObjectClasses() as $objectClass) {
366 $objectClasses->addElement(new htmlDiv(null, new htmlLink($objectClass, 'schema.php?display=objectClass&sel=' . rawurlencode($objectClass))));
367 }
368 $row->addField($objectClasses);
369 }
370
371 }
372 }