index aee8992d20544b59f1b48c7f4682a0a364f514f0..bffd1baa7356ed2f9ce796e95a6740076b938bf0 100644 (file)
*/
+
+/****************
+ * FUNCTIONS
+
+Step_Migrate - Constructor.
+update_strings - Used to update the displayed step informations.
+initialize_checks - Initialize migration steps.
+check_ldap_permissions - Check if the used admin account has full access to the ldap database.
+check_gosaAccounts - Check if there are users without the required objectClasses.
+migrate_gosaAccounts - Migrate selected users to GOsa user accounts.
+check_organizationalUnits - Check if there are departments, that are not visible for GOsa
+migrate_organizationalUnits - Migrate selected departments
+check_administrativeAccount - Check if there is at least one acl entry available
+checkBase - Check if there is a root object available
+
+get_user_list - Get list of available users
+get_group_list - Get list of groups
+
+create_admin
+create_admin_user
+
+execute - Generate html output of this plugin
+save_object - Save posts
+array_to_ldif - Create ldif output of an ldap result array
+
+ ****************/
+
+
+
class Step_Migrate extends setup_step
{
var $languages = array();
var $acl_create_changes = ""; // Contains ldif information about changes
var $acl_create_confirmed= FALSE;
+ /* Checks initialised ? */
+ var $checks_initialised = FALSE;
+
+ /* Users outside to people ou */
+ var $outside_users = array();
+ var $outside_users_dialog = FALSE;
+
+ /* Users outside to groups ou */
+ var $outside_groups = array();
+ var $outside_groups_dialog = FALSE;
+
+ /* Win-Workstations outside to reserved ou */
+ var $outside_winstations = array();
+ var $outside_winstations_dialog = FALSE;
+
+ /* check for multiple use of same uidNumber */
+ var $check_uidNumbers = array();
+ var $check_uidNumbers_dialog = FALSE;
+
+ /* check for multiple use of same gidNumber */
+ var $check_gidNumbers = array();
+ var $check_gidNumbers_dialog = FALSE;
+
+
function Step_Migrate()
{
$this->update_strings();
- $this->initialize_checks();
}
function update_strings()
$this->checks['deps_visible']['STATUS'] = FALSE;
$this->checks['deps_visible']['STATUS_MSG']= "";
$this->checks['deps_visible']['ERROR_MSG'] = "";
- $this->check_visible_organizationalUnits();
+ $this->check_organizationalUnits();
$this->checks['users_visible']['TITLE'] = _("Checking for invisible user");
$this->checks['users_visible']['STATUS'] = FALSE;
$this->checks['users_visible']['STATUS_MSG']= "";
$this->checks['users_visible']['ERROR_MSG'] = "";
- $this->check_invisible_gosaAccounts();
+ $this->check_gosaAccounts();
$this->checks['acls']['TITLE'] = _("Checking for administrational account");
$this->checks['acls']['STATUS'] = FALSE;
$this->checks['acls']['STATUS_MSG']= "";
$this->checks['acls']['ERROR_MSG'] = "";
- $this->check_acls();
+ $this->check_administrativeAccount();
+
+ $this->checks['outside_users']['TITLE'] = _("Checking for users outside the people department.");
+ $this->checks['outside_users']['STATUS'] = FALSE;
+ $this->checks['outside_users']['STATUS_MSG']= "";
+ $this->checks['outside_users']['ERROR_MSG'] = "";
+ $this->search_outside_users();
+
+ $this->checks['outside_groups']['TITLE'] = _("Checking for groups outside the groups department.");
+ $this->checks['outside_groups']['STATUS'] = FALSE;
+ $this->checks['outside_groups']['STATUS_MSG']= "";
+ $this->checks['outside_groups']['ERROR_MSG'] = "";
+ $this->search_outside_groups();
+
+ $this->checks['outside_winstations']['TITLE'] = _("Checking for windows workstations outside the winstation department.");
+ $this->checks['outside_winstations']['STATUS'] = FALSE;
+ $this->checks['outside_winstations']['STATUS_MSG']= "";
+ $this->checks['outside_winstations']['ERROR_MSG'] = "";
+ $this->search_outside_winstations();
+
+ $this->checks['uidNumber_usage']['TITLE'] = _("Checking for multiple use of same uidNumber value.");
+ $this->checks['uidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['uidNumber_usage']['STATUS_MSG']= "";
+ $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
+ $this->check_uidNumber();
+
+ $this->checks['gidNumber_usage']['TITLE'] = _("Checking for multiple use of same gidNumber value.");
+ $this->checks['gidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['gidNumber_usage']['STATUS_MSG']= "";
+ $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
+ $this->check_gidNumber();
}
-
- /* Check Acls if there is at least one object with acls defined
- */
- function check_acls()
+
+ function check_uidNumber()
{
- /* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap = new LDAP($cv['admin'],
$cv['password'],
FALSE,
$cv['tls']);
- /* Search for gosaAcls */
$ldap->cd($cv['base']);
- $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
+ $res = $ldap->search("uidNumber=*",array("dn","uidNumber"));
+ if(!$res){
+ $this->checks['uidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['uidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
- if($ldap->count() ==0){
- $this->checks['acls']['STATUS'] = TRUE;
- $this->checks['acls']['STATUS_MSG']= _("Ok");
- $this->checks['acls']['ERROR_MSG'] = "<input type='submit' name='retry_acls' value='"._("Retry")."'>";
+ $this->check_uidNumbers= array();
+ $tmp = array();
+ while($attrs = $ldap->fetch()){
+ $tmp[$attrs['uidNumber'][0]][] = $attrs;
+ }
+
+ foreach($tmp as $id => $entries){
+ if(count($entries) > 1){
+ foreach($entries as $entry){
+ $this->check_uidNumbers[base64_encode($entry['dn'])] = $entry;
+ }
+ }
+ }
+
+ if($this->check_uidNumbers){
+ $this->checks['uidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['uidNumber_usage']['STATUS_MSG']= _("Failed");
+ $this->checks['uidNumber_usage']['ERROR_MSG'] =
+ sprintf(_("Found %s duplicated uidNumber values."),count($this->check_uidNumbers));
+ return(false);
}else{
- $this->checks['acls']['STATUS'] = FALSE;
- $this->checks['acls']['STATUS_MSG']= _("Failed");
- $this->checks['acls']['ERROR_MSG'] = "<input type='submit' name='retry_acls' value='"._("Retry")."'>";
- $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
+ $this->checks['uidNumber_usage']['STATUS'] = TRUE;
+ $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ok");
+ $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
+ return(TRUE);
}
+ }
- return($ldap->count()>=1);
+ function check_gidNumber()
+ {
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $ldap->cd($cv['base']);
+ $res = $ldap->search("gidNumber=*",array("dn","gidNumber"));
+ if(!$res){
+ $this->checks['gidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['gidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
+
+ $this->check_gidNumbers= array();
+ $tmp = array();
+ while($attrs = $ldap->fetch()){
+ $tmp[$attrs['gidNumber'][0]][] = $attrs;
+ }
+
+ foreach($tmp as $id => $entries){
+ if(count($entries) > 1){
+ foreach($entries as $entry){
+ $this->check_gidNumbers[base64_encode($entry['dn'])] = $entry;
+ }
+ }
+ }
+
+ if($this->check_gidNumbers){
+ $this->checks['gidNumber_usage']['STATUS'] = FALSE;
+ $this->checks['gidNumber_usage']['STATUS_MSG']= _("Failed");
+ $this->checks['gidNumber_usage']['ERROR_MSG'] =
+ sprintf(_("Found %s duplicated gidNumber values."),count($this->check_gidNumbers));
+ return(false);
+ }else{
+ $this->checks['gidNumber_usage']['STATUS'] = TRUE;
+ $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ok");
+ $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
+ return(TRUE);
+ }
+ }
+
+
+ /* Search for winstations outside the winstation ou */
+ function search_outside_winstations()
+ {
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ /* Get winstation ou */
+ if($cv['generic_settings']['wws_ou_active']) {
+ $winstation_ou = $cv['generic_settings']['ws_ou'];
+ }else{
+ $winstation_ou = "ou=winstations";
+ }
+
+ $ldap->cd($cv['base']);
+ $res = $ldap->search("(&(objectClass=posixGroup)(sambaGroupType=2)(sambaSID=*))",array("dn","sambaSID"));
+ if(!$res){
+ $this->checks['outside_winstations']['STATUS'] = FALSE;
+ $this->checks['outside_winstations']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['outside_winstations']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
+
+ $this->outside_winstations = array();
+ while($attrs = $ldap->fetch()){
+ if(preg_match("/-516$/","",$attrs['sambaSID'][0]) && !preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])){
+ $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs;
+ }
+ }
+
+ if(count($this->outside_winstations)){
+ $this->checks['outside_winstations']['STATUS'] = FALSE;
+ $this->checks['outside_winstations']['STATUS_MSG']= _("Failed");
+ $this->checks['outside_winstations']['ERROR_MSG'] =
+ sprintf(_("Found %s winstations outside the predefined winstation department ou '%s'."),count($this->outside_winstations),$winstation_ou);
+ return(false);
+ }else{
+ $this->checks['outside_winstations']['STATUS'] = TRUE;
+ $this->checks['outside_winstations']['STATUS_MSG']= _("Ok");
+ $this->checks['outside_winstations']['ERROR_MSG'] = "";
+ return(TRUE);
+ }
+ }
+
+
+ /* Search for groups outside the group ou */
+ function search_outside_groups()
+ {
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $group_ou = $cv['groupou'];
+ $ldap->cd($cv['base']);
+ $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
+ if(!$res){
+ $this->checks['outside_groups']['STATUS'] = FALSE;
+ $this->checks['outside_groups']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
+
+
+ $this->outside_groups = array();
+ while($attrs = $ldap->fetch()){
+ if(!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])){
+ $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
+ }
+ }
+
+ if(count($this->outside_groups)){
+ $this->checks['outside_groups']['STATUS'] = FALSE;
+ $this->checks['outside_groups']['STATUS_MSG']= _("Failed");
+ $this->checks['outside_groups']['ERROR_MSG'] =
+ sprintf(_("Found %s groups outside the selected group ou '%s'."),count($this->outside_groups),$group_ou);
+ return(false);
+ }else{
+ $this->checks['outside_groups']['STATUS'] = TRUE;
+ $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
+ $this->checks['outside_groups']['ERROR_MSG'] = "";
+ return(TRUE);
+ }
+ }
+
+ /* Search for users outside the people ou */
+ function search_outside_users()
+ {
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+ $people_ou = $cv['peopleou'];
+ $ldap->cd($cv['base']);
+ $res = $ldap->search("(objectClass=gosaAccount)",array("dn"));
+ if(!$res){
+ $this->checks['outside_users']['STATUS'] = FALSE;
+ $this->checks['outside_users']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
+
+
+ $this->outside_users = array();
+ while($attrs = $ldap->fetch()){
+ if(!preg_match("/^[^,]+,".normalizePreg($people_ou)."/",$attrs['dn'])){
+ $attrs['selected'] = FALSE;
+ $attrs['ldif'] = "";
+ $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
+ }
+ }
+
+ if(count($this->outside_users)){
+ $this->checks['outside_users']['STATUS'] = FALSE;
+ $this->checks['outside_users']['STATUS_MSG']= _("Failed");
+ $this->checks['outside_users']['ERROR_MSG'] =
+ sprintf(_("Found %s users outside the selected user ou '%s'."),count($this->outside_users),$people_ou);
+ $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Migrate")."'>";
+ return(false);
+ }else{
+ $this->checks['outside_users']['STATUS'] = TRUE;
+ $this->checks['outside_users']['STATUS_MSG']= _("Ok");
+ $this->checks['outside_users']['ERROR_MSG'] = "";
+ return(TRUE);
+ }
}
$testEntry['description']= "Created by GOsa setup, this object can be removed.";
$testEntry['ou'] = $name;
+ /* check if simple ldap cat will be successful
+ */
+ $res = $ldap->cat($cv['base']);
+ if(!$res){
+ $this->checks['permissions']['STATUS'] = FALSE;
+ $this->checks['permissions']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ return(false);
+ }
+
/* Try to create dummy object
*/
$ldap->cd ($dn);
$this->checks['permissions']['STATUS_MSG']= _("Failed");
$this->checks['permissions']['ERROR_MSG'] =
sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
- $this->checks['permissions']['ERROR_MSG'].=
- "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
return(false);
}
$this->checks['permissions']['STATUS_MSG']= _("Failed");
$this->checks['permissions']['ERROR_MSG'] =
sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
- $this->checks['permissions']['ERROR_MSG'].=
- "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
return(false);
}
/* Create & remove of dummy object was successful */
$this->checks['permissions']['STATUS'] = TRUE;
$this->checks['permissions']['STATUS_MSG']= _("Ok");
- $this->checks['permissions']['ERROR_MSG'] = "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
+ $this->checks['permissions']['ERROR_MSG'] = "";
return(true);
}
/* Check if there are users which will
* be invisible for GOsa
*/
- function check_invisible_gosaAccounts()
+ function check_gosaAccounts()
{
/* Remember old list of ivisible users, to be able to set
* the 'html checked' status for the checkboxes again
/* Get all invisible users
*/
$ldap->cd($cv['base']);
- $ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
+ $res =$ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
while($attrs = $ldap->fetch()){
if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
$attrs['checked'] = FALSE;
}
/* No invisible */
- if(count($this->users_to_migrate) == 0){
+ if(!$res){
+ $this->checks['users_visible']['STATUS'] = FALSE;
+ $this->checks['users_visible']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ }elseif(count($this->users_to_migrate) == 0){
$this->checks['users_visible']['STATUS'] = TRUE;
$this->checks['users_visible']['STATUS_MSG']= _("Ok");
$this->checks['users_visible']['ERROR_MSG'] = "";
- $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate_refresh' value='"._("Retry")."'>";
}else{
$this->checks['users_visible']['STATUS'] = FALSE;
$this->checks['users_visible']['STATUS_MSG']= "";
$this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."),
count($this->users_to_migrate));
$this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."'>";
- $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate_refresh' value='"._("Reload list"). "'>";
}
}
/* Check if there are invisible organizational Units
*/
- function check_visible_organizationalUnits()
+ function check_organizationalUnits()
{
$cnt_ok = 0;
$old = $this->deps_to_migrate;
/* Get all invisible departments */
$ldap->cd($cv['base']);
- $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
+ $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
while($attrs = $ldap->fetch()){
$attrs['checked'] = FALSE;
$attrs['before'] = "";
/* If we have no invisible departments found
* tell the user that everything is ok
*/
- if(count($this->deps_to_migrate) == 0){
+ if(!$res){
+ $this->checks['deps_visible']['STATUS'] = FALSE;
+ $this->checks['deps_visible']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ }elseif(count($this->deps_to_migrate) == 0 ){
$this->checks['deps_visible']['STATUS'] = TRUE;
$this->checks['deps_visible']['STATUS_MSG']= _("Ok");
$this->checks['deps_visible']['ERROR_MSG'] = "";
- $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate_refresh' value='"._("Retry")."'>";
}else{
$this->checks['deps_visible']['STATUS'] = FALSE;
$this->checks['deps_visible']['STATUS_MSG']= "";//sprintf(_("%s entries found"),count($this->deps_to_migrate));
$this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
$this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
- $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate_refresh' value='"._("Reload list")."'>";
}
}
}
- function get_user_list()
+ /* Check Acls if there is at least one object with acls defined
+ */
+ function check_administrativeAccount()
{
- /* Get collected configuration settings */
- $cv = $this->parent->captured_values;
-
/* Establish ldap connection */
- $ldap = new LDAP($cv['admin'],
- $cv['password'],
- $cv['connection'],
- FALSE,
- $cv['tls']);
-
- $ldap->cd($cv['base']);
- $ldap->search("(objectClass=gosaAccount)",array("dn"));
-
- $tmp = array();
- while($attrs = $ldap->fetch()){
- $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
- }
-
- return($tmp);
- }
-
- function get_group_list()
- {
- /* Get collected configuration settings */
$cv = $this->parent->captured_values;
-
- /* Establish ldap connection */
$ldap = new LDAP($cv['admin'],
$cv['password'],
$cv['connection'],
FALSE,
$cv['tls']);
-
+
+ /* Search for gosaAcls */
$ldap->cd($cv['base']);
- $ldap->search("(objectClass=posixGroup)",array("dn"));
-
- $tmp = array();
- while($attrs = $ldap->fetch()){
- $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
+ $res = $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)".
+ "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
+ if(!$res){
+ $this->checks['acls']['STATUS'] = FALSE;
+ $this->checks['acls']['STATUS_MSG']= _("Ldap query failed.");
+ $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
+ }elseif($ldap->count()){
+ $this->checks['acls']['STATUS'] = TRUE;
+ $this->checks['acls']['STATUS_MSG']= _("Ok");
+ }else{
+ $this->checks['acls']['STATUS'] = FALSE;
+ $this->checks['acls']['STATUS_MSG']= _("Failed");
+ $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
}
-
- return($tmp);
+ return($ldap->count()>=1);
}
}
}
}
+
+ function create_admin_user()
+ {
+ if(isset($_POST['new_user_password']) && !empty($_POST['new_user_password'])){
+ $pwd = $_POST['new_user_password'];
+ }else{
+ print_red(_("Please specify a valid password for the new GOsa admin user."));
+ return(FALSE);
+ }
+
+ /* Establish ldap connection */
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
- function execute()
+ /* Get current base attributes */
+ $ldap->cd($cv['base']);
+
+ if($cv['peopledn'] == "cn"){
+ $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
+ }else{
+ $dn = "uid=admin,".$cv['peopleou'].",".$cv['base'];
+ }
+
+ $methods = @passwordMethod::get_available_methods_if_not_loaded();
+ $p_m = $methods[$cv['encryption']];
+ $p_c = new $p_m(array());
+ $hash = $p_c->generate_hash($pwd);
+
+ $new_user=array();
+ $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
+ $new_user['givenName'] = "System";
+ $new_user['sn'] = "Administrator";
+ $new_user['cn'] = "System Administrator";
+ $new_user['uid'] = "admin";
+ $new_user['userPassword'] = $hash;
+
+ $ldap->cd($cv['base']);
+ $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
+ $ldap->cd($dn);
+ $res = $ldap->add($new_user);
+ $this->acl_create_selected = $dn;
+ $this->create_admin();
+
+ if(!$res){
+ print_red($ldap->get_error());
+ }
+
+ $this->acl_create_dialog=FALSE;
+ $this->check_administrativeAccount();
+ }
+
+
+ function migrate_outside_users($perform = FALSE)
{
- /* Permission check */
- $this->check_ldap_permissions();
+ /* Establish ldap connection */
+ $cv = $this->parent->captured_values;
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $ldap->cd($cv['base']);
+
+ /* Check if there was a destination department posted */
+ if(isset($_POST['move_user_to'])){
+ $destination_dep = $_POST['move_user_to'];
+ }else{
+ print_red(_("Couldn't move users to specified department."));
+ return(false);
+ }
+
+ foreach($this->outside_users as $b_dn => $data){
+ $this->outside_users[$b_dn]['ldif'] ="";
+ if($data['selected']){
+ $dn = base64_decode($b_dn);
+ $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
+ if(!$perform){
+ $this->outside_users[$b_dn]['ldif'] = $dn."<br>".$d_dn;
+
+ /* Check if there are references to this object */
+ $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
+ $refs = "";
+ while($attrs = $ldap->fetch()){
+ $ref_dn = $attrs['dn'];
+ $refs .= "<br />".$ref_dn;
+ }
+ if(!empty($refs)){
+ $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
+ }
+
+ }else{
+ $this->move($dn,$d_dn);
+ }
+ }
+ }
+ }
+
+ function execute()
+ {
+ /* Initialise checks if this is the first call */
+ if(!$this->checks_initialised || isset($_POST['reload'])){
+ $this->initialize_checks();
+ $this->checks_initialised = TRUE;
+ }
+
/*************
- * Root object check
+ * User outside the people ou
*************/
-
- if(isset($_POST['retry_root'])) {
- $this->checkBase();
+
+ if(isset($_POST['outside_users_dialog_cancel'])){
+ $this->outside_users_dialog = FALSE;
+ $this->dialog = FALSE;
+ }
+
+ if(isset($_POST['outside_users_dialog_whats_done'])){
+ $this->migrate_outside_users(FALSE);
+ }
+
+ if(isset($_POST['outside_users_dialog_perform'])){
+ $this->migrate_outside_users(TRUE);
+ $this->search_outside_users();
}
+ if(isset($_POST['outside_users_dialog'])){
+ $this->outside_users_dialog = TRUE;
+ $this->dialog = TRUE;
+ }
+
+ if($this->outside_users_dialog){
+ $smarty = get_smarty();
+ $smarty->assign("ous",$this->get_all_people_ous());
+ $smarty->assign("method","outside_users");
+ $smarty->assign("outside_users",$this->outside_users);
+ return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
+ }
+
+ /*************
+ * Root object check
+ *************/
+
if(isset($_POST['retry_root_create'])){
+
+ $state = $this->checks['root']['STATUS'];
$this->checkBase(FALSE);
+ if($state != $this->checks['root']['STATUS']){
+ $this->initialize_checks();
+ }
}
/*************
*************/
if(isset($_POST['retry_acls'])){
- $this->check_acls();
+ $this->check_administrativeAccount();
}
if(isset($_POST['create_acls'])){
$this->create_admin(TRUE);
}
+ if(isset($_POST['create_admin_user'])){
+ $this->create_admin_user();
+ }
+
if($this->acl_create_dialog){
$smarty = get_smarty();
+ $smarty->assign("new_user_password",@$_POST['new_user_password']);
$smarty->assign("users" ,$this->get_user_list());
+ $smarty->assign("users_cnt" ,count($this->get_user_list()));
$smarty->assign("groups",$this->get_group_list());
+ $smarty->assign("groups_cnt",count($this->get_group_list()));
$smarty->assign("type" ,$this->acl_create_type);
$smarty->assign("method","create_acls");
$smarty->assign("acl_create_selected",$this->acl_create_selected);
/* Refresh list of deparments */
if(isset($_POST['users_visible_migrate_refresh'])){
- $this->check_invisible_gosaAccounts();
+ $this->check_gosaAccounts();
}
/* Open migration dialog */
/* Start migration */
if(isset($_POST['users_visible_migrate_migrate'])){
if($this->migrate_gosaAccounts()){
- $this->check_invisible_gosaAccounts();
+ $this->check_gosaAccounts();
}
}
/* Refresh list of deparments */
if(isset($_POST['deps_visible_migrate_refresh'])){
- $this->check_visible_organizationalUnits();
+ $this->check_organizationalUnits();
}
/* Open migration dialog */
/* Start migration */
if(isset($_POST['deps_visible_migrate_migrate'])){
if($this->migrate_organizationalUnits()){
- $this->check_visible_organizationalUnits();
+ $this->check_organizationalUnits();
}
}
function save_object()
{
+ /* Capture all selected users from outside_users_dialog */
+ if($this->outside_users_dialog){
+ foreach($this->outside_users as $dn => $data){
+ if(isset($_POST['select_user_'.$dn])){
+ $this->outside_users[$dn]['selected'] = TRUE;
+ }else{
+ $this->outside_users[$dn]['selected'] = FALSE;
+ }
+ }
+ }
+
/* Get "create acl" dialog posts */
if($this->acl_create_dialog){
if(isset($_POST['create_acls_create'])){
}
- // checks for valid base entry
+ /* Check if the root object exists.
+ * If the parameter just_check is true, then just check if the
+ * root object is missing and update the info messages.
+ * If the Parameter is false, try to create a new root object.
+ */
function checkBase($just_check = TRUE)
{
/* Get collected setup informations */
if($just_check){
$this->checks['root']['STATUS'] = FALSE;
$this->checks['root']['STATUS_MSG']= _("Failed");
- $this->checks['root']['ERROR_MSG'] = "<input type='submit' name='retry_root' value='"._("Retry")."'>";
$this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
return(FALSE);
}else{
- /* Try to find out which values are necessary */
+ echo "REMOVE this : Autocreation of the root object will be done by create_missing_tree later. !!!!!!!";
+
+ /* Try to find out which values are necessary */
$tmp = $ldap->get_objectclasses();
$oc = $tmp['organization'];
- $must_attrs = array();
- if(preg_match("/MUST/",$oc)){
- $must = preg_replace("/^.* MUST/","",$oc);
- $must = preg_replace("/MAY.*$/","",$must);
- $must = trim(preg_replace("/[\(\)\$]/","",$must));
- $must_attrs = split(" ",$must);
- foreach($must_attrs as $key => $attrs){
- if(empty($attrs)){
- unset($must_attrs[$key]);
- }
- }
+
+ $must_attrs = $oc['MUST'];
+ if(!is_array($must_attrs)){
+ $must_attrs = array($must_attrs);
}
-
+
/* Root object does not exists try to create it */
$ldapadd["objectclass"][0]="top";
$ldapadd["objectclass"][1]="organization";
/* Add root object */
$ldap->cd($cv['base']);
$res = $ldap->add($ldapadd);
-
+
+ /* Add root object */
+ $ldap->cd($cv['base']);
+ # $res = $ldap->create_missing_trees($cv['base']);
+
/* If adding failed, tell the user */
if(!$res){
$this->checks['root']['STATUS'] = FALSE;
/* Create & remove of dummy object was successful */
$this->checks['root']['STATUS'] = TRUE;
$this->checks['root']['STATUS_MSG']= _("Ok");
- $this->checks['root']['ERROR_MSG'] = "<input type='submit' name='retry_root' value='"._("Retry")."'>";
}
}
return(preg_replace("/\n$/","",$ret));
}
+
+
+ function get_user_list()
+ {
+ /* Get collected configuration settings */
+ $cv = $this->parent->captured_values;
+
+ /* Establish ldap connection */
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $ldap->cd($cv['base']);
+ $ldap->search("(objectClass=gosaAccount)",array("dn"));
+
+ $tmp = array();
+ while($attrs = $ldap->fetch()){
+ $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
+ }
+ return($tmp);
+ }
+
+
+ function get_all_people_ous()
+ {
+ /* Get collected configuration settings */
+ $cv = $this->parent->captured_values;
+
+ /* Establish ldap connection */
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $ldap->cd($cv['base']);
+ $ldap->search("(".$cv['peopleou'].")",array("dn"));
+
+ if($ldap->count() == 0 ){
+ $add_dn = $cv['peopleou'].",".$cv['base'];
+ $naming_attr = preg_replace("/=.*$/","",$add_dn);
+ $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
+ $add = array();
+ $add['objectClass'] = array("organizationalUnit");
+ $add[$naming_attr] = $naming_value;
+
+ $ldap->cd($cv['base']);
+ $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
+ $ldap->cd($add_dn);
+ $ldap->add($add);
+ }
+
+ $ldap->search("(".$cv['peopleou'].")",array("dn"));
+ $tmp = array();
+ while($attrs= $ldap->fetch()){
+ if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
+ $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
+ }
+ }
+ return($tmp);
+ }
+
+
+ function get_group_list()
+ {
+ /* Get collected configuration settings */
+ $cv = $this->parent->captured_values;
+
+ /* Establish ldap connection */
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ $ldap->cd($cv['base']);
+ $ldap->search("(objectClass=posixGroup)",array("dn"));
+
+ $tmp = array();
+ while($attrs = $ldap->fetch()){
+ $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
+ }
+ return($tmp);
+ }
+
+
+ function move($source,$destination)
+ {
+ /* Get collected configuration settings */
+ $cv = $this->parent->captured_values;
+
+ /* Establish ldap connection */
+ $ldap = new LDAP($cv['admin'],
+ $cv['password'],
+ $cv['connection'],
+ FALSE,
+ $cv['tls']);
+
+ /* Update object references in gosaGroupOfNames */
+ $ogs_to_fix = array();
+ $ldap->cd($cv['base']);
+ $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
+ while ($attrs= $ldap->fetch()){
+ $dn = $attrs['dn'];
+ $attrs = $this->cleanup_array($attrs);
+ $member_new = array($destination);
+ foreach($attrs['member'] as $member){
+ if($member != $source){
+ $member_new[] = $member;
+ }
+ }
+ $attrs['member'] = $member_new;
+ $ogs_to_fix[$dn] = $attrs;
+ }
+
+ /* Copy source to destination dn */
+ $ldap->cat($source);
+ $new_data = $this->cleanup_array($ldap->fetch());
+ $ldap->cd($destination);
+ $res = $ldap->add($new_data);
+
+ /* Display warning if copy failed */
+ if(!$res){
+ print_red(_("Failed to copy '%s' to '%s'. Ldap says '%s'."),$source,$destination,$ldap->get_error());
+ }else{
+ $res = $ldap->rmDir($source);
+ show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
+
+ /* Object is copied, so update its references */
+ foreach($ogs_to_fix as $dn => $data){
+ $ldap->cd($dn);
+ $ldap->modify($data);
+ }
+ }
+ }
+
+
+ /* Cleanup ldap result to be able to write it be to ldap */
+ function cleanup_array($attrs)
+ {
+ foreach($attrs as $key => $value) {
+ if(is_numeric($key) || in_array($key,array("count","dn"))){
+ unset($attrs[$key]);
+ }
+ if(is_array($value) && isset($value['count'])){
+ unset($attrs[$key]['count']);
+ }
+ }
+ return($attrs);
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: