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

cvs at kolab.org cvs at kolab.org
Thu Apr 14 17:02:26 CEST 2011


Author: wickert

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

Added Files:
	kolab-cn2uid 
Log Message:
Add kolab-cn2uid script for the 2.3.0 release

--- NEW FILE: kolab-cn2uid ---
<?php
#!/kolab/bin/php -q

//get all arguments
$arg= getopt("i:o:");

if(count($arg)<2)
{
   echo "Usage:  php kolab-cn2uid -i file.ldif -o file2.ldif\n\n-i input ldif file\n-o output ldif file\n\n";
}
else
{

if (file_exists($arg['i']))
{
    $pattern="uid:";
    $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)
      {
        $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]);
      }
      
      
        
    }
    
    $input = implode("\n\n" ,$chunks);
    file_put_contents($arg['o'],$input);
    
}
    
    

else
{
    
    echo "Error: The file ".$arg['i']." does not exist\n";
}
}

function FindReplacement($inputarray,$what)
{
    
    for($i=0;$i<count($inputarray);++$i)
    {
        if(preg_match("/".$what."/",$inputarray[$i]))
        {
            $row=$i;
            
        }
        
    }
    
    return $row;
}

?>





More information about the commits mailing list