Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use Net::LDAP; use Net::LDAPS; use Template; my $template_input = '\documentclass[10pt,a4paper]{article} \usepackage{times} \usepackage{xtab} \usepackage{colortbl} \setlength\textheight{290mm} \setlength{\voffset}{-15mm} \begin{document} \begin{center} \begin{xtabular}{lllll} \textbf{Name} & \textbf{Title} & \textbf{Ext.} & \textbf{Mobile} & \te +xtbf{SPD} \\\\ \hline [% FOREACH buildings %] \hline \multicolumn{5}{c}{[% buildingname %]}\\\\ \hline [% FOREACH staff %] [%- IF loop.index % 2 -%]\rowcolor[gray]{0.91}[%- END -%][%name%] & \\ +tiny{[%title%]} & [%extension%] & [%mobile%] & [%mobile_speed_dial%] +\\\\ [% END %] [% END %] \end{xtabular} \end{center} \end{document}'; ##There'll be some customization necessary here my $ldap = Net::LDAPS->new("domain.controller") or die "$@"; my $message = $ldap->bind( "cn=Some User,ou=Service Accounts,dc=company,dc=com +", password => 'Secret' ); $message = $ldap->search( base => "ou=Employees,dc=company,dc=com", filter => "(& (cn=*) (objectClass=user))", ); $message->code && die $message->error; my @skip_names = ( #A list of names to be skipped (service/admin accounts etc) ); my %staff; foreach my $employee ( $message->all_entries ) { my $name = $employee->get_value("cn"); next if ( grep /^\Q$name\E$/, @skip_names ); my $title = $employee->get_value("title") || + ""; my $extension = $employee->get_value("telephoneNumber") || + ""; my $mobile = $employee->get_value("mobile") || + ""; my $mobile_speed_dial = $employee->get_value("pager") || + ""; my $building = $employee->get_value("physicalDeliveryOfficeName") +|| ""; my $useraccount_control = $employee->get_value("userAccountControl +") || ""; next if ( account_disabled($useraccount_control) ); # Skip disa +bled accounts push @{ $staff{$building} }, { name => $name, title => $title, extension => $extension, mobile => $mobile, mobile_speed_dial => $mobile_speed_dial }; } my @buildings; foreach my $building ( sort keys(%staff) ) { my @staff = sort { $a->{name} cmp $b->{name} } @{ $staff{$building +} }; push @buildings, { buildingname => $building, staff => \@staff }; } my $template = Template->new(); my $output; $template->process( \$template_input, { buildings => \@buildings }, \$ +output ) or die $template->e->error(), "\n"; open( my $fh, ">", "phone_list.tex" ) or die "Couldn't open phone_list.tex for writing: $!\n"; print $fh $output; close($fh); sub account_disabled { my $flags = shift; my %check = calculate_flags($flags); return 1 if ( $check{ACCOUNTDISABLE} ); return 0; } sub calculate_flags { my $flags_to_check = shift; my %table = ( SCRIPT => 0x0001, ACCOUNTDISABLE => 0x0002, HOMEDIR_REQUIRED => 0x0008, LOCKOUT => 0x0010, PASSWD_NOTREQD => 0x0020, PASSWD_CANT_CHANGE => 0x0040, ENCRYPTED_TEXT_PWD_ALLOWED => 0x0080, TEMP_DUPLICATE_ACCOUNT => 0x0100, NORMAL_ACCOUNT => 0x0200, INTERDOMAIN_TRUST_ACCOUNT => 0x0800, WORKSTATION_TRUST_ACCOUNT => 0x1000, SERVER_TRUST_ACCOUNT => 0x2000, DONT_EXPIRE_PASSWORD => 0x10000, MNS_LOGON_ACCOUNT => 0x20000, SMARTCARD_REQUIRED => 0x40000, TRUSTED_FOR_DELEGATION => 0x80000, NOT_DELEGATED => 0x100000, USE_DES_KEY_ONLY => 0x200000, DONT_REQ_PREAUTH => 0x400000, PASSWORD_EXPIRED => 0x800000, TRUSTED_TO_AUTH_FOR_DELEGATION => 0x1000000, ); my %results; foreach my $flag ( keys %table ) { $results{$flag} = 1 if ( $flags_to_check & $table{$flag} ); } return %results; }

In reply to Windows Active Directory to PDF Phone List by davis

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: (2)
As of 2024-04-24 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found