Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/local/bin/perl ###################################################################### +########### # Lista + # # version 2.1 + # ###################################################################### +########### # Objetivo : Enlace de usuarios NT con LDAP para envio de mail + # # Comunicacion : LDAP + # # Fuente : Perl [ Win32 ] + # # Compilacion : Win32. executable. + # # Fecha : 16-Ago-2001 9:36 + # ###################################################################### +########### # # Formato de entrada de la lista : # # UserNT # ###################################################################### +########### use Mozilla::LDAP::Conn; use Mozilla::LDAP::Entry; use Mozilla::LDAP::Utils; use win32::lanman; # inicializa variables # $host = "host.com"; $port="389"; $searchbase = "o=Test,c=AR"; $maxentries = "10000"; # entradas a recuperar @atfind = ( mail, uid, cn, departmentnumber, employeenumber, telephone +number ); print "\nVersion 1.0 <-> 16-08-2001\n"; # # EVALUA PARAMETROS # if ( eval(@ARGV) < 2 ) { PrintHelp(); exit 1; } if ( (uc($ARGV[0]) eq "U") || (uc($ARGV[0]) eq "-U")) { $OPTION = 1; } elsif ((uc($ARGV[0]) eq "L") || (uc($ARGV[0]) eq "-L")) { $OPTION = 2; } else { PrintHelp(); exit 1; } open FILESI, ">OK.txt"; open FILENO, ">NOK.txt"; open DEBUG, ">DEBUG.txt"; print FILESI "UidNT,*,Mail,UidNs, ApeyNom, CC, leg, te \n"; # hace la conexion $conn = new Mozilla::LDAP::Conn( $host, $port ); die "No se puede conectar a LDAP \n" unless $conn; # Lectura del TXT # if ($OPTION eq 2) { @datos = `type $ARGV[1]`; }elsif ($OPTION eq 1) { if ($ARGV[1] eq "") { PrintHelp(); exit 2; }else{ @datos=$ARGV[1]; } } $server=$ARGV[2]; chomp($server); # Proceso de busqueda # $i=0; foreach $usuarioNT (@datos) { chomp($usuarioNT); $i=$i+1; ($linea)=&searchNT($usuarioNT,$server); ($campo1, $campo2, $campo3, $campo4) = split(/,/, $linea); print "Procesando $i.- ($campo1, $campo2, $campo3, $campo4)\n"; if ($campo1 =~ /[0-9]/) { $filter="(employeenumber=$campo1)"; print "\nProcesando . \r"; ($ok)= &salida($searchbase, $filter, @atfind); print DEBUG "1,$ok,$filter\n"; if ($ok==0){ $campo=$campo1; $campo =~ tr /A//; $campo =~ s/A//eg; $filter="(employeenumber=$campo)"; print "Procesando .. \r"; ($ok)= &salida($searchbase, $filter, @atfind); print DEBUG "2,$ok,$filter\n"; if ($ok==0){ $campo=$campo1; $campo =~ tr /B//; $campo =~ s/B//eg; $filter="(employeenumber=$campo)"; print "Procesando ... \r"; ($ok)= &salida($searchbase, $filter, @atfind); print DEBUG "3,$ok,$filter\n"; if ($ok==0){ $campo=$campo3." ".$campo2; $filter="(cn=$campo)"; print "Procesando .... \r"; ($ok)= &salida($searchbase, $filter, @atfind); print DEBUG "4,$ok,$filter\n"; if ($ok==0){ $campo=$campo3; $campo=~ tr / //; $campo=~ s/ //eg; $campos= substr($campo, 0, 1); $campo=$campos.$campo2; $filter="uid=$campo"; print "Procesando ..... \r"; ($ok)= &salida($searchbase,$filter,@atfind); print DEBUG "5,$ok,$filter\n"; if ($ok==0){ print FILENO ("$campo1,$campo2,$campo3 \n" +); } } } } } }else{ $filter="uid=$campo1"; ($ok)= &salida($searchbase, $filter, @atfind); if ($ok==0){ $campo=$campo3." ".$campo2; $filter="(cn=$campo)"; print "Procesando ...... \r"; ($ok)= &salida($searchbase, $filter, @atfind); print DEBUG "6,$ok,$filter\n"; if ($ok==0){ $campo=$campo3; $campo=~ tr / //; $campo=~ s/ //eg; $campos= substr($campo, 0, 1); $campo=$campos.$campo2; $filter="uid=$campo"; print "Procesando ....... \r"; ($ok)= &salida($searchbase,$filter,@atfind); print DEBUG "7,$ok,$filter\n"; if ($ok==0){ print FILENO ("$campo1,$campo2,$campo3 \n"); } } } } # Proceso de salida # sub salida { ($searchbase,$filter,@atfind) = @_; $entry = $conn->search( $searchbase, "sub", $filter, 0, @atfind ); + if ($entry) { # si hay una entrada $cn = $entry->{cn}[0]; $uid = $entry->{uid}[0]; $cc = $entry->{departmentnumber}[0]; $leg = $entry->{employeenumber}[0]; $te = $entry->{telephonenumber}[0]; $mail = $entry->{mail}[0]; print FILESI "$campo1,*,$mail,$uid,$cn,$cc,$leg,$te\n"; print "Procesado \r"; if ($OPTION eq 1) { print "\nmail: $mail \nuid: $uid \nN&A: $cn \nCC: $cc \nL +eg: $leg \nTE: $te \n"; } $ok =1; }else { # no encuentro nada $ok =0; } } } print "\nFin de la busqueda ... \n"; print "\nBuscar datos en ok.txt y en nok.txt, y ver errores en debug.t +xt ... \n"; # Cierra conexion # $conn->close if $conn; close(archivos); close(archivon); close(debug); exit; ################ # # # ################ sub PrintHelp { print "Uso: nt2ldap.pl -l <Lista> <PDC-NT> / -u <userNT> <PDC-NT>\ +n\n"; print "Formato de la lista entrada: userNT\n\n"; print "Formato de salida : \n"; print "Archivo OK.txt : UidNT,*,Mail, UidLdap, ApeyNom, CC, leg, t +e \n"; print "Formato de salida :\n"; print "Archivo NOK.txt : idem del de entrada \n"; } ################ # # # ################ sub searchNT { ($user,$server)=@_; $server="\\\\".$server; if(!Win32::Lanman::NetUserGetInfo($server,$user,\%info)){ # get the error code $error=Win32::Lanman::GetLastError(); print "Algun error a ocurrido; error: $error "; $datosNT="$user,,,"; }else{ $fn = $info{full_name}; ($campo1, $campo2) = split(/,/, $fn); $fn="$campo1,$campo2"; $lg = $info{comment}; ($trash, $campo2) = split(/\(/, $lg); ($lg, $trash) = split(/\)/, $campo2); $datosNT = "$user,$fn,$lg"; } return($datosNT); }

In reply to nt2ldap by ZinMostaccho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-19 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found