From fb2741ec9a3da3376994f3f70f8d0c17bbe70931 Mon Sep 17 00:00:00 2001 From: octo Date: Sun, 24 Apr 2005 20:53:01 +0000 Subject: [PATCH] Changed structure of perl modules to be more useful. Added basic mutt-ldap script. --- lib/LiCoM/Config.pm | 37 +++++++++++++++++++ lib/{ => LiCoM}/Person.pm | 2 +- licom.cgi | 92 +++++++++++++++++++---------------------------- mutt-licom.pl | 56 +++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 56 deletions(-) create mode 100644 lib/LiCoM/Config.pm rename lib/{ => LiCoM}/Person.pm (99%) create mode 100755 mutt-licom.pl diff --git a/lib/LiCoM/Config.pm b/lib/LiCoM/Config.pm new file mode 100644 index 0000000..1c561a2 --- /dev/null +++ b/lib/LiCoM/Config.pm @@ -0,0 +1,37 @@ +package LiCoM::Config; + +use strict; +use warnings; + +use Exporter; + +@LiCoM::Config::EXPORT_OK = ('get_config'); +@LiCoM::Config::ISA = ('Exporter'); + +return (1); + +sub get_config +{ + my $file = @_ ? shift : '/etc/licom/licom.conf'; + my $fh; + my $config = {}; + + open ($fh, "< $file") or die ("open ($file): $!"); + for (<$fh>) + { + chomp; + my $line = $_; + + if ($line =~ m/^(\w+):\s*"(.+)"\s*$/) + { + my $key = lc ($1); + my $val = $2; + + $config->{$key} = $val; + } + } + + close ($fh); + + return ($config); +} diff --git a/lib/Person.pm b/lib/LiCoM/Person.pm similarity index 99% rename from lib/Person.pm rename to lib/LiCoM/Person.pm index 25df303..d51ad28 100644 --- a/lib/Person.pm +++ b/lib/LiCoM/Person.pm @@ -1,4 +1,4 @@ -package Person; +package LiCoM::Person; use strict; use warnings; diff --git a/licom.cgi b/licom.cgi index 4af14ad..5abb2e6 100755 --- a/licom.cgi +++ b/licom.cgi @@ -9,10 +9,11 @@ use CGI::Carp (qw(fatalsToBrowser)); use URI::Escape; use Data::Dumper; -use Person; +use LiCoM::Config (qw(get_config)); +use LiCoM::Person; our $Debug = 0; -our %Config = (); +our $Config = {}; our @MultiFields = (qw(address homephone cellphone officephone fax mail uri group)); @@ -46,21 +47,24 @@ our %Actions = vcard => \&action_vcard ); -read_config (); +$Config = get_config (); # make sure AuthLDAPRemoteUserIsDN is enabled. die unless ($ENV{'REMOTE_USER'}); -$Config{'base_dn'} = $ENV{'REMOTE_USER'}; +$Config->{'base_dn'} = $ENV{'REMOTE_USER'}; -Person->connect +die unless (defined ($Config->{'uri'}) and defined ($Config->{'base_dn'}) + and defined ($Config->{'bind_dn'}) and defined ($Config->{'password'})); + +LiCoM::Person->connect ( - uri => $Config{'uri'}, - base_dn => $Config{'base_dn'}, - bind_dn => $Config{'bind_dn'}, - password => $Config{'password'} + uri => $Config->{'uri'}, + base_dn => $Config->{'base_dn'}, + bind_dn => $Config->{'bind_dn'}, + password => $Config->{'password'} ) or die; -our ($UserCN, $UserID) = Person->get_user ($Config{'base_dn'}); +our ($UserCN, $UserID) = LiCoM::Person->get_user ($Config->{'base_dn'}); if (!$UserID and $Action ne 'save') { @@ -89,9 +93,7 @@ elsif (ref ($Actions{$Action}) eq 'ARRAY') } } -#print qq#
Authenticated as ($UserCN, $UserID, #, $Config{'base_dn'}, qq#)
\n#; - -Person->disconnect (); +LiCoM::Person->disconnect (); exit (0); @@ -106,15 +108,16 @@ sub action_browse my @all; if ($group) { - @all = Person->search ([[group => $group]]); + @all = LiCoM::Person->search ([[group => $group]]); } else { - @all = Person->search (); + @all = LiCoM::Person->search (); } if (!$group) { + my @nogroup = (); my %groups = (); for (@all) { @@ -122,7 +125,10 @@ sub action_browse my @g = $person->get ('group'); $groups{$_} = (defined ($groups{$_}) ? $groups{$_} + 1 : 1) for (@g); + + push (@nogroup, $person) if (!@g); } + @all = @nogroup; print qq(\t\t

Contact Groups

\n\t\t