wickert: utils/admin kolab-cn2uid,1.1,1.2

cvs at kolab.org cvs at kolab.org
Tue Apr 19 22:39:13 CEST 2011


Author: wickert

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv7919

Modified Files:
	kolab-cn2uid 
Log Message:
Fix script to also rewrite group members. Thanks to Bogo for the fix.

Index: kolab-cn2uid
===================================================================
RCS file: /kolabrepository/utils/admin/kolab-cn2uid,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- kolab-cn2uid	14 Apr 2011 15:02:24 -0000	1.1
+++ kolab-cn2uid	19 Apr 2011 20:39:10 -0000	1.2
@@ -3,6 +3,7 @@
 
 //get all arguments
 $arg= getopt("i:o:");
+$old_values_array=array();
 
 if(count($arg)<2)
 {
@@ -17,34 +18,72 @@
     $input = file_get_contents($arg['i']);
     $chunks = explode("\n\n" ,$input);
     
-    
     for($i=0;$i<count($chunks);$i++)
     {
-    
-      if (strpos($chunks[$i], $pattern)>-1 AND strpos($chunks[$i], "mail:")>-1)
+     // the replaced chunk must have uid: AND kolabInvitationPolicy: params == I am a real boy/girl
+      if (strpos($chunks[$i], $pattern)>-1 AND strpos($chunks[$i], "structuralObjectClass: inetOrgPerson")>-1)
       {
-        $small_chunks= explode("\n",$chunks[$i]);
-        
-        //we will replace with that, removing 'mail:' from the line
-        $replacement = trim(preg_replace("/".$pattern."/","",$small_chunks[FindReplacement($small_chunks,$pattern)]));
-        
-        //we will replace that
-        $toreplace = substr($small_chunks[0], 0, strpos($small_chunks[0],","));
-        
-        //build replacement string. Replace (dn: cn=Fname Lname) with the new pattern
-       $small_chunks[0] = preg_replace("/".$toreplace."/","dn: uid=".$replacement,$small_chunks[0]);
-        
-       $small_chunks_back= implode("\n",$small_chunks);
-       $chunks[$i] = $small_chunks_back;
-             
-       // $chunks[$i] = $small_chunks_back;
-       // print_r($chunks[$i]);
+      	if (strpos($chunks[$i], "sn: n/a")==0)
+		{
+		        $small_chunks= explode("\n",$chunks[$i]);
+		        
+		        //we will replace with that, removing 'mail:' from the line
+		       $replacement = trim(preg_replace("/".$pattern."/","",$small_chunks[FindReplacement($small_chunks,$pattern)]));
+		        
+		        //we will replace that
+		       $toreplace = substr($small_chunks[0], 0, strpos($small_chunks[0],","));
+		       $old_values_array['old'][$i]=preg_replace("/dn: /","",$small_chunks[0]); 
+				
+		        //build replacement string. Replace (dn: cn=Fname Lname) with the new pattern
+		       $small_chunks[0] = preg_replace("/".$toreplace."/","dn: uid=".$replacement,$small_chunks[0]);
+		       
+		       //build a map [old value]->[new value]
+		       $finalarray_oldnew[$old_values_array['old'][$i]]=preg_replace("/dn: /","",$small_chunks[0]); 
+		       $small_chunks_back= implode("\n",$small_chunks);
+		       $chunks[$i] = $small_chunks_back;
+			   
+			   
+		             
+		       // $chunks[$i] = $small_chunks_back;
+		       // print_r($chunks[$i]);
       }
-      
-      
+     } 
         
     }
-    
+
+	for($i=0;$i<count($chunks);$i++)
+    {
+    	if (strpos($chunks[$i], "member:")>-1)
+		{
+			$small_chunks= explode("\n",$chunks[$i]);
+			for ($p=0;$p<count($small_chunks);$p++)
+			{
+				//check if is member:
+				if (strpos($small_chunks[$p], "member:")>-1)
+				{
+					
+					$parcheta = explode(": ", $small_chunks[$p]);
+					if (array_key_exists($parcheta[1], $finalarray_oldnew))
+					{
+						$parcheta[1]=$finalarray_oldnew[$parcheta[1]];
+					}
+					
+					$small_chunks[$p]=implode(": ",$parcheta);
+						
+				}
+				
+				
+			}
+			
+			$small_chunks_back= implode("\n",$small_chunks);
+			$chunks[$i] = $small_chunks_back;
+		}
+		
+	}
+
+
+
+   // print_r($finalarray_oldnew);
     $input = implode("\n\n" ,$chunks);
     file_put_contents($arg['o'],$input);
     





More information about the commits mailing list