| 1 |
<?php |
| 2 |
namespace LAM\TOOLS\TESTS; |
| 3 |
use htmlResponsiveRow; |
| 4 |
use htmlTitle; |
| 5 |
use htmlStatusMessage; |
| 6 |
use htmlSubTitle; |
| 7 |
use htmlOutputText; |
| 8 |
use htmlImage; |
| 9 |
use LAM\SCHEMA\ObjectClass; |
| 10 |
use function LAM\SCHEMA\get_schema_objectclasses; |
| 11 |
use function LAM\SCHEMA\get_cached_schema; |
| 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 |
include_once(__DIR__ . "/../../lib/security.inc"); |
| 42 |
|
| 43 |
include_once(__DIR__ . "/../../lib/config.inc"); |
| 44 |
|
| 45 |
include_once(__DIR__ . "/../../lib/modules.inc"); |
| 46 |
|
| 47 |
include_once(__DIR__ . "/../../lib/schema.inc"); |
| 48 |
|
| 49 |
|
| 50 |
startSecureSession(); |
| 51 |
enforceUserIsLoggedIn(); |
| 52 |
|
| 53 |
|
| 54 |
if (!checkIfWriteAccessIsAllowed()) { |
| 55 |
die(); |
| 56 |
} |
| 57 |
|
| 58 |
checkIfToolIsActive('toolTests'); |
| 59 |
|
| 60 |
setlanguage(); |
| 61 |
|
| 62 |
include_once __DIR__ . '/../../lib/adminHeader.inc'; |
| 63 |
echo "<div class=\"smallPaddingContent\">\n"; |
| 64 |
|
| 65 |
$container = new htmlResponsiveRow(); |
| 66 |
|
| 67 |
$container->add(new htmlTitle(_("Schema test"))); |
| 68 |
|
| 69 |
get_schema_objectclasses(); |
| 70 |
$classes = get_cached_schema('objectclasses'); |
| 71 |
|
| 72 |
if (!is_array($classes)) { |
| 73 |
$container->add(new htmlStatusMessage('ERROR', _('Unable to retrieve schema!'), _('You do not have the required access rights or the LDAP schema is not published by your server.'))); |
| 74 |
} |
| 75 |
else { |
| 76 |
|
| 77 |
$typeManager = new \LAM\TYPES\TypeManager(); |
| 78 |
$types = $typeManager->getConfiguredTypes(); |
| 79 |
foreach ($types as $type) { |
| 80 |
$moduleNames = $_SESSION['config']->get_AccountModules($type->getId()); |
| 81 |
$container->add(new htmlSubTitle($type->getAlias())); |
| 82 |
foreach ($moduleNames as $moduleName) { |
| 83 |
$error = checkSchemaForModule($moduleName, $type->getScope(), $type->getId()); |
| 84 |
$message = _("No problems found."); |
| 85 |
$icon = '../../graphics/pass.svg'; |
| 86 |
if ($error != null) { |
| 87 |
$icon = '../../graphics/del.svg'; |
| 88 |
$message = $error; |
| 89 |
} |
| 90 |
|
| 91 |
$aliasName = getModuleAlias($moduleName, $type->getScope()) ?? ''; |
| 92 |
$container->add(new htmlOutputText($aliasName), 10, 3); |
| 93 |
|
| 94 |
$container->add(new htmlImage($icon), 2); |
| 95 |
|
| 96 |
$container->add(new htmlOutputText($message), 12, 7); |
| 97 |
$container->addVerticalSpacer('0.5rem'); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
parseHtml(null, $container, [], true); |
| 103 |
|
| 104 |
echo "</div>\n"; |
| 105 |
include_once __DIR__ . '/../../lib/adminFooter.inc'; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
function checkSchemaForModule($name, $scope, $typeId): ?string { |
| 116 |
$module = new $name($scope); |
| 117 |
$classes = $module->getManagedObjectClasses($typeId); |
| 118 |
$attrs = $module->getManagedAttributes($typeId); |
| 119 |
$aliases = array_flip($module->getLDAPAliases($typeId)); |
| 120 |
if (count($classes) === 0) { |
| 121 |
return null; |
| 122 |
} |
| 123 |
$schemaClasses = get_cached_schema('objectclasses'); |
| 124 |
$schemaAttrs = []; |
| 125 |
|
| 126 |
foreach ($classes as $objectClass) { |
| 127 |
if (!isset($schemaClasses[strtolower($objectClass)]) || !($schemaClasses[strtolower($objectClass)] instanceof ObjectClass)) { |
| 128 |
return sprintf(_("The object class %s is not supported by your LDAP server."), $objectClass); |
| 129 |
} |
| 130 |
|
| 131 |
$schemaAttrs = array_merge($schemaAttrs, getRecursiveAttributesFromObjectClass($schemaClasses[strtolower($objectClass)])); |
| 132 |
} |
| 133 |
|
| 134 |
foreach ($attrs as $attributeName) { |
| 135 |
if (str_starts_with($attributeName, 'INFO.')) { |
| 136 |
continue; |
| 137 |
} |
| 138 |
if (!in_array_ignore_case($attributeName, $schemaAttrs) && !in_array_ignore_case(str_replace(';binary', '', $attributeName), $schemaAttrs)) { |
| 139 |
if (isset($aliases[$attributeName]) && in_array_ignore_case($aliases[$attributeName], $schemaAttrs)) { |
| 140 |
continue; |
| 141 |
} |
| 142 |
return sprintf(_("The attribute %s is not supported for the object class %s by your LDAP server."), $attributeName, implode("/", $classes)); |
| 143 |
} |
| 144 |
} |
| 145 |
return null; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
function getRecursiveAttributesFromObjectClass($oClass): array { |
| 155 |
$attrs = []; |
| 156 |
$attrs = array_merge($attrs, $oClass->getMustAttrNames()); |
| 157 |
$attrs = array_merge($attrs, $oClass->getMayAttrNames()); |
| 158 |
$subClassNames = $oClass->getSupClasses(); |
| 159 |
foreach ($subClassNames as $subClassName) { |
| 160 |
$schemaClasses = get_cached_schema('objectclasses'); |
| 161 |
$subClass = $schemaClasses[strtolower($subClassName)]; |
| 162 |
if ($subClass instanceof ObjectClass) { |
| 163 |
$attrs = array_merge($attrs, getRecursiveAttributesFromObjectClass($subClass)); |
| 164 |
} |
| 165 |
} |
| 166 |
return $attrs; |
| 167 |
} |