X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=mutt-licom.pl;h=07e669c974b51bef1410600d17a7aa62069dcae2;hb=04c295d0621018f6ee4769054001be61aadac7ff;hp=e3991f834ed3d5b7f4385c9e463b0f5bc476491f;hpb=fb2741ec9a3da3376994f3f70f8d0c17bbe70931;p=licom.git diff --git a/mutt-licom.pl b/mutt-licom.pl index e3991f8..07e669c 100755 --- a/mutt-licom.pl +++ b/mutt-licom.pl @@ -1,56 +1,57 @@ -#! /usr/bin/perl -Tw -# 2005-02-24: Fixed for AD/Exchange 2003 & Unicode characters, -# anders@bsdconsulting.no If you find this script useful, let me know. :-) -# -# 2000/2001: Original version obtained from Andreas Plesner Jacobsen at -# World Online Denmark. Worked for me with Exchange versions prior to Exchange -# 2000. -# -# Use it with mutt by putting in your .muttrc: -# set query_command = "/home/user/bin/mutt-ldap.pl '%s'" -# -# Then you can search for your users by name directly from mutt. Press ^t -# after having typed parts of the name. Remember to edit configuration -# variables below. +#!/usr/bin/perl use strict; -use Encode qw/encode decode/; -use vars qw { $ldapserver $domain $username $password $basedn }; - -# --- configuration --- -$ldapserver = "domaincontroller.yourdomain.com"; -$domain = "YOURDOMAIN"; -$username = "myuser"; -$password = "mypassword"; -$basedn = "ou=companyxy,dc=companyxy,dc=tld"; -# --- end configuration --- - -#my $search=shift; -my $search=encode("UTF-8", join(" ", @ARGV)); - -if (!$search=~/[\.\*\w\s]+/) { - print("Invalid search parameters\n"); - exit 1; -} +use warnings; +use lib (qw(lib)); + +use LiCoM::Config (qw(get_config)); +use LiCoM::Person; + +our $Config = get_config (); -use Net::LDAP; +die unless (defined ($Config->{'uri'}) and defined ($Config->{'bind_dn'}) + and defined ($Config->{'password'})); -my $ldap = Net::LDAP->new($ldapserver) or die "$@"; +$Config->{'base_dn'} = $Config->{'bind_dn'} unless (defined ($Config->{'base_dn'})); -$ldap->bind("$domain\\$username", password=>$password); +our @Patterns = (); +for (@ARGV) +{ + my $temp = $_; + $temp =~ s/[^\.\*\w\s]//g; + + next unless ($temp); + + $temp =~ s/\**$/*/; + push (@Patterns, [[lastname => $temp], [firstname => $temp], [mail => $temp]]); +} -my $mesg = $ldap->search (base => $basedn, - filter => "(|(cn=*$search*) (rdn=*$search*) (uid=*$search*) (mail=*$search*))", - attrs => ['mail','cn']); +die ('No (valid) patterns found.') unless (@Patterns); -$mesg->code && die $mesg->error; +LiCoM::Person->connect +( + uri => $Config->{'uri'}, + base_dn => $Config->{'base_dn'}, + bind_dn => $Config->{'bind_dn'}, + password => $Config->{'password'} +) or die; -print(scalar($mesg->all_entries), " entries found\n"); +our @Matches = LiCoM::Person->search (@Patterns, [[mail => '*']]); -foreach my $entry ($mesg->all_entries) { - if ($entry->get_value('mail')) { - print($entry->get_value('mail'),"\t", - decode("UTF-8", $entry->get_value('cn')),"\tFrom Exchange LDAP database\n"); - } +print STDOUT scalar (@Matches), ' ', (scalar (@Matches) == 1 ? 'entry' : 'entries'), " found.\n"; + +for (@Matches) +{ + my $person = $_; + my $cn = $person->name (); + my @mail = $person->get ('mail'); + + for (@mail) + { + print "$_\t$cn\tFound by LiCoM\n"; } -$ldap->unbind; +} + +LiCoM::Person->disconnect (); + +exit (0);