From: octo Date: Sun, 24 Apr 2005 21:15:55 +0000 (+0000) Subject: First version of mutt-licom.pl X-Git-Tag: Release-0.1~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=668385f6b26d5280882b020656034d701157fb02;p=licom.git First version of mutt-licom.pl --- diff --git a/mutt-licom.pl b/mutt-licom.pl index e3991f8..894bd1e 100755 --- a/mutt-licom.pl +++ b/mutt-licom.pl @@ -1,56 +1,49 @@ -#! /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 (); + +die unless (defined ($Config->{'uri'}) and defined ($Config->{'bind_dn'}) + and defined ($Config->{'password'})); + +$Config->{'base_dn'} = $Config->{'bind_dn'} unless (defined ($Config->{'base_dn'})); -use Net::LDAP; +our @Patterns = (); +for (@ARGV) +{ + my $temp = $_; + $temp =~ s/[^\.\*\w\s]//g; -my $ldap = Net::LDAP->new($ldapserver) or die "$@"; + next unless ($temp); -$ldap->bind("$domain\\$username", password=>$password); + $temp =~ s/\**$/*/; + push (@Patterns, [[lastname => $temp], [firstname => $temp], [mail => $temp]]); +} + +die ('No (valid) patterns found.') unless (@Patterns); -my $mesg = $ldap->search (base => $basedn, - filter => "(|(cn=*$search*) (rdn=*$search*) (uid=*$search*) (mail=*$search*))", - attrs => ['mail','cn']); +our @Matches = LiCoM::Person->search (@Patterns, [[mail => '*']]); -$mesg->code && die $mesg->error; +print STDOUT scalar (@Matches), ' ', (scalar (@Matches) == 1 ? 'entry' : 'entries'), " found.\n"; -print(scalar($mesg->all_entries), " entries found\n"); +for (@Matches) +{ + my $person = $_; + my $cn = $person->name (); + my @mail = $person->get ('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"); - } + for (@mail) + { + print "$_\t$cn\tFound by LiCoM\n"; } -$ldap->unbind; +} + +LiCoM::Person->disconnect (); + +exit (0);