2007-12-29 11:02:00 +00:00
< ? php
2018-01-03 17:40:51 +00:00
namespace LAM\TOOLS\TESTS ;
use \htmlResponsiveRow ;
use \htmlTitle ;
use \htmlStatusMessage ;
use \htmlSubTitle ;
use \htmlOutputText ;
use \htmlImage ;
2018-03-04 08:43:32 +00:00
use function \LAM\SCHEMA\get_schema_objectclasses ;
use function \LAM\SCHEMA\get_cached_schema ;
2007-12-29 11:02:00 +00:00
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager ( http :// www . ldap - account - manager . org / )
2018-01-03 17:40:51 +00:00
Copyright ( C ) 2007 - 2018 Roland Gruber
2007-12-29 11:02:00 +00:00
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 2 of the License , or
( at your option ) any later version .
2016-12-19 20:32:08 +00:00
2007-12-29 11:02:00 +00:00
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 .
2016-12-19 20:32:08 +00:00
2007-12-29 11:02:00 +00:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/**
* Tests the lamdaemon script .
*
* @ author Roland Gruber
* @ package tools
*/
/** security functions */
2018-12-22 20:33:07 +00:00
include_once ( __DIR__ . " /../../lib/security.inc " );
2007-12-29 11:02:00 +00:00
/** access to configuration options */
2018-12-22 20:33:07 +00:00
include_once ( __DIR__ . " /../../lib/config.inc " );
2007-12-29 11:02:00 +00:00
/** account modules */
2018-12-22 20:33:07 +00:00
include_once ( __DIR__ . " /../../lib/modules.inc " );
2007-12-29 11:02:00 +00:00
/** LDAP schema */
2018-12-22 20:33:07 +00:00
include_once ( __DIR__ . " /../../lib/schema.inc " );
2007-12-29 11:02:00 +00:00
// start session
startSecureSession ();
2017-02-11 16:11:37 +00:00
enforceUserIsLoggedIn ();
2007-12-29 11:02:00 +00:00
2007-12-30 13:15:39 +00:00
// die if no write access
if ( ! checkIfWriteAccessIsAllowed ()) die ();
2012-07-22 10:37:01 +00:00
checkIfToolIsActive ( 'toolTests' );
2007-12-29 11:02:00 +00:00
setlanguage ();
2018-01-03 17:40:51 +00:00
include '../../lib/adminHeader.inc' ;
2013-01-19 13:18:52 +00:00
echo " <div class= \" user-bright smallPaddingContent \" > \n " ;
2007-12-29 11:02:00 +00:00
2018-01-03 17:40:51 +00:00
$container = new htmlResponsiveRow ();
2010-10-17 13:38:32 +00:00
2018-01-03 17:40:51 +00:00
$container -> add ( new htmlTitle ( _ ( " Schema test " )), 12 );
2007-12-29 11:02:00 +00:00
get_schema_objectclasses ();
$classes = get_cached_schema ( 'objectclasses' );
if ( ! is_array ( $classes )) {
2018-01-03 17:40:51 +00:00
$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.' )), 12 );
2007-12-29 11:02:00 +00:00
}
2010-10-17 13:38:32 +00:00
else {
// loop for active account types
2016-12-28 18:51:48 +00:00
$typeManager = new \LAM\TYPES\TypeManager ();
$types = $typeManager -> getConfiguredTypes ();
foreach ( $types as $type ) {
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $type -> getId ());
2018-01-03 17:40:51 +00:00
$container -> add ( new htmlSubTitle ( $type -> getAlias ()), 12 );
2010-10-17 13:38:32 +00:00
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
2017-04-22 14:14:15 +00:00
$error = checkSchemaForModule ( $modules [ $m ], $type -> getScope (), $type -> getId ());
2010-10-17 13:38:32 +00:00
$message = _ ( " No problems found. " );
$icon = '../../graphics/pass.png' ;
if ( $error != null ) {
$icon = '../../graphics/fail.png' ;
$message = $error ;
}
// module name
2018-01-03 17:40:51 +00:00
$container -> add ( new htmlOutputText ( getModuleAlias ( $modules [ $m ], $type -> getScope ())), 10 , 3 );
2010-10-17 13:38:32 +00:00
// icon
2018-01-03 17:40:51 +00:00
$container -> add ( new htmlImage ( $icon ), 2 );
2010-10-17 13:38:32 +00:00
// text
2018-01-03 17:40:51 +00:00
$container -> add ( new htmlOutputText ( $message ), 12 , 7 );
$container -> addVerticalSpacer ( '0.5rem' );
2007-12-29 11:02:00 +00:00
}
}
}
2010-10-17 13:38:32 +00:00
$tabindex = 1 ;
parseHtml ( null , $container , array (), true , $tabindex , 'user' );
echo " </div> \n " ;
2018-01-03 17:40:51 +00:00
include '../../lib/adminFooter.inc' ;
2007-12-29 11:02:00 +00:00
/**
* Checks if the object classes and attributes for this module are available .
*
* @ param String $name module name
2017-04-22 14:14:15 +00:00
* @ param String $scope type ( user , group , ... )
* @ param String $typeId type id
2007-12-29 11:02:00 +00:00
* @ return String error message or null
*/
2017-04-22 14:14:15 +00:00
function checkSchemaForModule ( $name , $scope , $typeId ) {
$module = new $name ( $scope );
$classes = $module -> getManagedObjectClasses ( $typeId );
$attrs = $module -> getManagedAttributes ( $typeId );
$aliases = array_flip ( $module -> getLDAPAliases ( $typeId ));
2007-12-29 11:02:00 +00:00
if ( sizeof ( $classes ) == 0 ) {
return null ;
}
$schemaClasses = get_cached_schema ( 'objectclasses' );
$schemaAttrs = array ();
// check if object classes are supported
for ( $o = 0 ; $o < sizeof ( $classes ); $o ++ ) {
if ( ! isset ( $schemaClasses [ strtolower ( $classes [ $o ])])) {
return sprintf ( _ ( " The object class %s is not supported by your LDAP server. " ), $classes [ $o ]);
}
// get attribute names
$schemaAttrs = array_merge ( $schemaAttrs , getRecursiveAttributesFromObjectClass ( $schemaClasses [ strtolower ( $classes [ $o ])]));
}
// check if attributes are supported
for ( $a = 0 ; $a < sizeof ( $attrs ); $a ++ ) {
2012-02-08 19:12:00 +00:00
if ( strpos ( $attrs [ $a ], 'INFO.' ) === 0 ) {
continue ;
}
2013-02-25 18:40:17 +00:00
if ( ! in_array_ignore_case ( $attrs [ $a ], $schemaAttrs ) && ! in_array_ignore_case ( str_replace ( ';binary' , '' , $attrs [ $a ]), $schemaAttrs )) {
2007-12-29 11:02:00 +00:00
if ( isset ( $aliases [ $attrs [ $a ]]) && in_array_ignore_case ( $aliases [ $attrs [ $a ]], $schemaAttrs )) {
continue ;
}
2012-02-08 19:12:00 +00:00
return sprintf ( _ ( " The attribute %s is not supported for the object class %s by your LDAP server. " ), $attrs [ $a ], implode ( " / " , $classes ));
2007-12-29 11:02:00 +00:00
}
}
return null ;
}
/**
* Returns the names of all attributes which are managed by the given object class and its parents .
*
* @ param ObjectClass $oClass object class
* @ return array list of attribute names
*/
function getRecursiveAttributesFromObjectClass ( $oClass ) {
$attrs = array ();
$attrs = array_merge ( $attrs , $oClass -> getMustAttrNames ());
$attrs = array_merge ( $attrs , $oClass -> getMayAttrNames ());
$subClassNames = $oClass -> getSupClasses ();
for ( $i = 0 ; $i < sizeof ( $subClassNames ); $i ++ ) {
$schemaClasses = get_cached_schema ( 'objectclasses' );
$subClass = $schemaClasses [ strtolower ( $subClassNames [ $i ])];
$attrs = array_merge ( $attrs , getRecursiveAttributesFromObjectClass ( $subClass ));
}
return $attrs ;
}
?>