From: hickert Date: Wed, 2 May 2007 07:00:14 +0000 (+0000) Subject: Added wisntation migration X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=12f4329f7b974d9b4e858dbfe8b838c117d7c818;p=gosa.git Added wisntation migration git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6219 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index 949cdbe03..be6ff373f 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -275,15 +275,23 @@ class Step_Migrate extends setup_step 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"; } + + if($cv['samba_version'] == 3){ + $oc = "sambaSamAccount"; + }else{ + $oc = "sambaAccount"; + } $ldap->cd($cv['base']); - $res = $ldap->search("(&(objectClass=posixGroup)(sambaGroupType=2)(sambaSID=*))",array("dn","sambaSID")); + $res = $ldap->search("(&(objectClass=".$oc.")(uid=*$))",array("dn","sambaSID")); if(!$res){ $this->checks['outside_winstations']['STATUS'] = FALSE; $this->checks['outside_winstations']['STATUS_MSG']= _("Ldap query failed."); @@ -293,7 +301,9 @@ class Step_Migrate extends setup_step $this->outside_winstations = array(); while($attrs = $ldap->fetch()){ - if(preg_match("/-516$/","",$attrs['sambaSID'][0]) && !preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])){ + if(!preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])){ + $attrs['selected'] = FALSE; + $attrs['ldif'] = ""; $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs; } } @@ -303,6 +313,7 @@ class Step_Migrate extends setup_step $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); + $this->checks['outside_winstations']['ERROR_MSG'].= ""; return(false); }else{ $this->checks['outside_winstations']['STATUS'] = TRUE; @@ -369,7 +380,7 @@ class Step_Migrate extends setup_step $cv['tls']); $people_ou = $cv['peopleou']; $ldap->cd($cv['base']); - $res = $ldap->search("(objectClass=gosaAccount)",array("dn")); + $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn")); if(!$res){ $this->checks['outside_users']['STATUS'] = FALSE; $this->checks['outside_users']['STATUS_MSG']= _("Ldap query failed."); @@ -859,6 +870,54 @@ class Step_Migrate extends setup_step } + function migrate_outside_winstations($perform = FALSE) + { + /* 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_winstation_to'])){ + $destination_dep = $_POST['move_winstation_to']; + }else{ + print_red(_("Couldn't move users to specified department.")); + return(false); + } + + foreach($this->outside_winstations as $b_dn => $data){ + $this->outside_winstations[$b_dn]['ldif'] =""; + if($data['selected']){ + $dn = base64_decode($b_dn); + $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn); + if(!$perform){ + $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":
\t".$dn."
"._("to").":
\t".$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 .= "
\t".$ref_dn; + } + if(!empty($refs)){ + $this->outside_winstations[$b_dn]['ldif'] .= "

"._("Updating following references too").":".$refs; + } + + }else{ + $this->move($dn,$d_dn); + } + } + } + } + + function migrate_outside_groups($perform = FALSE) { /* Establish ldap connection */ @@ -962,6 +1021,36 @@ class Step_Migrate extends setup_step $this->checks_initialised = TRUE; } + /************* + * Winstations outside the group ou + *************/ + + if(isset($_POST['outside_winstations_dialog_cancel'])){ + $this->outside_winstations_dialog = FALSE; + $this->dialog = FALSE; + } + + if(isset($_POST['outside_winstations_dialog_whats_done'])){ + $this->migrate_outside_winstations(FALSE); + } + + if(isset($_POST['outside_winstations_dialog_perform'])){ + $this->migrate_outside_winstations(TRUE); + $this->search_outside_winstations(); + } + + if(isset($_POST['outside_winstations_dialog'])){ + $this->outside_winstations_dialog = TRUE; + $this->dialog = TRUE; + } + + if($this->outside_winstations_dialog){ + $smarty = get_smarty(); + $smarty->assign("ous",$this->get_all_winstation_ous()); + $smarty->assign("method","outside_winstations"); + $smarty->assign("outside_winstations",$this->outside_winstations); + return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__)))); + } /************* * Groups outside the group ou *************/ @@ -1173,6 +1262,17 @@ class Step_Migrate extends setup_step function save_object() { + /* Capture all selected winstations from outside_winstations_dialog */ + if($this->outside_winstations_dialog){ + foreach($this->outside_winstations as $dn => $data){ + if(isset($_POST['select_winstation_'.$dn])){ + $this->outside_winstations[$dn]['selected'] = TRUE; + }else{ + $this->outside_winstations[$dn]['selected'] = FALSE; + } + } + } + /* Capture all selected groups from outside_groups_dialog */ if($this->outside_groups_dialog){ foreach($this->outside_groups as $dn => $data){ @@ -1410,6 +1510,53 @@ class Step_Migrate extends setup_step return($tmp); } + function get_all_winstation_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']); + + /* 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']); + $ldap->search("(".$winstation_ou.")",array("dn")); + + if($ldap->count() == 0 ){ + $add_dn = $cv['groupou'].",".$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("(".$winstation_ou.")",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_all_group_ous() { diff --git a/setup/setup_migrate.tpl b/setup/setup_migrate.tpl index b726897c5..cbf5a8ee0 100644 --- a/setup/setup_migrate.tpl +++ b/setup/setup_migrate.tpl @@ -31,6 +31,53 @@
 
{/foreach} + {elseif $method == "outside_winstations"} + +

{t}Move windows workstations into a valid windows workstation department{/t}

+ + {t}This dialog allows you to move the displayed windows workstations into a valid department{/t} +
+ {t}Be careful with this tool, there may be references pointing to this workstations that can't be migrated.{/t} +
+
+ + {foreach from=$outside_winstations item=val key=key} + {if $outside_winstations.$key.selected} + + {else} + + {/if} + +  {$outside_winstations.$key.dn} + {if $outside_winstations.$key.ldif != ""} +
+
+
+{$outside_winstations.$key.ldif}
+
+
+
+ {/if} +
+ {/foreach} + +

+ {t}Move selected windows workstations into the following GOsa department{/t} : + +
+ + +

+ + +

 

+
+ +
+ + {elseif $method == "outside_groups"}

{t}Move groups into valid group departments{/t}