2018-06-01 17:10:45 +01:00
< ? php
2020-01-10 12:01:31 +00:00
set_include_path ( " .: " . __DIR__ . " /../includes/ " );
include_once " web_functions.inc.php " ;
include_once " ldap_functions.inc.php " ;
include_once " module_functions.inc.php " ;
2018-06-01 17:10:45 +01:00
2019-02-08 11:28:11 +00:00
validate_setup_cookie ();
2018-06-01 17:10:45 +01:00
set_page_access ( " setup " );
2021-07-22 09:12:55 +01:00
render_header ( " $ORGANISATION_NAME account manager setup " );
2018-06-01 17:10:45 +01:00
$ldap_connection = open_ldap_connection ();
2018-06-04 15:20:53 +01:00
$no_errors = TRUE ;
$show_create_admin_button = FALSE ;
2018-06-01 17:10:45 +01:00
# Set up missing stuff
if ( isset ( $_POST [ 'fix_problems' ])) {
?>
< script >
$ ( document ) . ready ( function (){
$ ( '[data-toggle="popover"]' ) . popover ();
});
</ script >
< div class = 'container' >
< div class = " panel panel-default " >
< div class = " panel-heading " > Updating LDAP ...</ div >
< div class = " panel-body " >
< ul class = " list-group " >
< ? php
if ( isset ( $_POST [ 'setup_group_ou' ])) {
2021-03-13 14:11:38 +00:00
$ou_add = @ ldap_add ( $ldap_connection , $LDAP [ 'group_dn' ], array ( 'objectClass' => 'organizationalUnit' , 'ou' => $LDAP [ 'group_ou' ] ));
2018-06-04 15:20:53 +01:00
if ( $ou_add == TRUE ) {
2023-03-27 10:29:07 +01:00
print " $li_good Created OU <strong> { $LDAP [ 'group_dn' ] } </strong></li> \n " ;
2018-06-01 17:10:45 +01:00
}
else {
$error = ldap_error ( $ldap_connection );
2023-03-27 10:29:07 +01:00
print " $li_fail Couldn't create { $LDAP [ 'group_dn' ] } : <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
if ( isset ( $_POST [ 'setup_user_ou' ])) {
2021-03-13 14:11:38 +00:00
$ou_add = @ ldap_add ( $ldap_connection , $LDAP [ 'user_dn' ], array ( 'objectClass' => 'organizationalUnit' , 'ou' => $LDAP [ 'user_ou' ] ));
2018-06-04 15:20:53 +01:00
if ( $ou_add == TRUE ) {
2023-03-27 10:29:07 +01:00
print " $li_good Created OU <strong> { $LDAP [ 'user_dn' ] } </strong></li> \n " ;
2018-06-01 17:10:45 +01:00
}
else {
$error = ldap_error ( $ldap_connection );
2023-03-27 10:29:07 +01:00
print " $li_fail Couldn't create { $LDAP [ 'user_dn' ] } : <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
if ( isset ( $_POST [ 'setup_last_gid' ])) {
$highest_gid = ldap_get_highest_id ( $ldap_connection , 'gid' );
$description = " Records the last GID used to create a Posix group. This prevents the re-use of a GID from a deleted group. " ;
2021-03-13 14:11:38 +00:00
$add_lastgid_r = array ( 'objectClass' => array ( 'device' , 'top' ),
'serialnumber' => $highest_gid ,
'description' => $description );
2023-03-27 10:29:07 +01:00
$gid_add = @ ldap_add ( $ldap_connection , " cn=lastGID, { $LDAP [ 'base_dn' ] } " , $add_lastgid_r );
2018-06-01 17:10:45 +01:00
2018-06-04 15:20:53 +01:00
if ( $gid_add == TRUE ) {
2023-03-27 10:29:07 +01:00
print " $li_good Created <strong>cn=lastGID, { $LDAP [ 'base_dn' ] } </strong></li> \n " ;
2018-06-01 17:10:45 +01:00
}
else {
$error = ldap_error ( $ldap_connection );
2023-03-27 10:29:07 +01:00
print " $li_fail Couldn't create cn=lastGID, { $LDAP [ 'base_dn' ] } : <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
if ( isset ( $_POST [ 'setup_last_uid' ])) {
$highest_uid = ldap_get_highest_id ( $ldap_connection , 'uid' );
$description = " Records the last UID used to create a Posix account. This prevents the re-use of a UID from a deleted account. " ;
2021-03-13 14:11:38 +00:00
$add_lastuid_r = array ( 'objectClass' => array ( 'device' , 'top' ),
'serialnumber' => $highest_uid ,
'description' => $description );
2023-03-27 10:29:07 +01:00
$uid_add = @ ldap_add ( $ldap_connection , " cn=lastUID, { $LDAP [ 'base_dn' ] } " , $add_lastuid_r );
2018-06-01 17:10:45 +01:00
2018-06-04 15:20:53 +01:00
if ( $uid_add == TRUE ) {
2023-03-27 10:29:07 +01:00
print " $li_good Created <strong>cn=lastUID, { $LDAP [ 'base_dn' ] } </strong></li> \n " ;
2018-06-01 17:10:45 +01:00
}
else {
$error = ldap_error ( $ldap_connection );
2023-03-27 10:29:07 +01:00
print " $li_fail Couldn't create cn=lastUID, { $LDAP [ 'base_dn' ] } : <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
if ( isset ( $_POST [ 'setup_default_group' ])) {
$group_add = ldap_new_group ( $ldap_connection , $DEFAULT_USER_GROUP );
2018-06-04 15:20:53 +01:00
if ( $group_add == TRUE ) {
2018-06-01 17:10:45 +01:00
print " $li_good Created default group: <strong> $DEFAULT_USER_GROUP </strong></li> \n " ;
}
else {
$error = ldap_error ( $ldap_connection );
print " $li_fail Couldn't create default group: <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
if ( isset ( $_POST [ 'setup_admins_group' ])) {
$group_add = ldap_new_group ( $ldap_connection , $LDAP [ 'admins_group' ]);
2018-06-04 15:20:53 +01:00
if ( $group_add == TRUE ) {
2023-03-27 10:29:07 +01:00
print " $li_good Created LDAP administrators group: <strong> { $LDAP [ 'admins_group' ] } </strong></li> \n " ;
2018-06-01 17:10:45 +01:00
}
else {
$error = ldap_error ( $ldap_connection );
print " $li_fail Couldn't create LDAP administrators group: <pre> $error </pre></li> \n " ;
2018-06-04 15:20:53 +01:00
$no_errors = FALSE ;
2018-06-01 17:10:45 +01:00
}
}
$admins = ldap_get_group_members ( $ldap_connection , $LDAP [ 'admins_group' ]);
if ( count ( $admins ) < 1 ) {
?>
< div class = " form-group " >
2023-03-27 10:29:07 +01:00
< form action = " <?php print " { $SERVER_PATH } account_manager / new_user . php " ; ?> " method = " post " >
2019-02-08 11:28:11 +00:00
< input type = " hidden " name = " setup_admin_account " >
2018-06-01 17:10:45 +01:00
< ? php
print " $li_fail The LDAP administration group is empty. " ;
print " <a href='#' data-toggle='popover' title='LDAP account administrators' data-content=' " ;
2023-03-27 10:29:07 +01:00
print " Only members of this group ( { $LDAP [ 'admins_group' ] } ) will be able to access the account managment section, so we need to add people to it. " ;
2018-06-01 17:10:45 +01:00
print " '>What's this?</a> " ;
print " <label class='pull-right'><input type='checkbox' name='setup_admin_account' class='pull-right' checked>Create a new account and add it to the admin group? </label> " ;
print " </li> \n " ;
2018-06-04 15:20:53 +01:00
$show_create_admin_button = TRUE ;
2018-06-01 17:10:45 +01:00
}
else {
2023-03-27 10:29:07 +01:00
print " $li_good The LDAP account administrators group (<strong> { $LDAP [ 'admins_group' ] } </strong>) isn't empty.</li> " ;
2018-06-01 17:10:45 +01:00
}
?>
</ ul >
</ div >
</ div >
< ? php
##############
2018-06-04 15:20:53 +01:00
if ( $no_errors == TRUE ) {
if ( $show_create_admin_button == FALSE ) {
2018-06-01 17:10:45 +01:00
?>
2021-03-13 14:11:38 +00:00
</ form >
2018-06-01 17:10:45 +01:00
< div class = 'well' >
2021-07-22 09:12:55 +01:00
< form action = " <?php print $THIS_MODULE_PATH ; ?> " >
2018-06-01 17:10:45 +01:00
< input type = 'submit' class = " btn btn-success center-block " value = 'Finished' class = 'center-block' >
</ form >
</ div >
< ? php
}
else {
?>
2021-03-13 14:11:38 +00:00
< div class = 'well' >
< input type = 'submit' class = " btn btn-warning center-block " value = 'Create new account >' class = 'center-block' >
</ form >
2018-06-01 17:10:45 +01:00
</ div >
< ? php
}
}
2021-03-13 14:11:38 +00:00
else {
2018-06-01 17:10:45 +01:00
?>
2021-03-13 14:11:38 +00:00
</ form >
2018-06-01 17:10:45 +01:00
< div class = 'well' >
2021-07-22 09:12:55 +01:00
< form action = " <?php print $THIS_MODULE_PATH ; ?>/run_checks.php " >
2018-06-01 17:10:45 +01:00
< input type = 'submit' class = " btn btn-danger center-block " value = '< Re-run setup' class = 'center-block' >
</ form >
</ div >
< ? php
}
}
render_footer ();
?>