From 328bdcb841ecaa72c69379e6ccd7165f44e7c2e4 Mon Sep 17 00:00:00 2001 From: octo Date: Fri, 6 May 2005 15:53:25 +0000 Subject: [PATCH] Many more fixes.. Trying to get all this work now.. --- lib/LiCoM/Config.pm | 21 ++++++++++++--------- lib/LiCoM/Connection.pm | 6 +----- lib/LiCoM/Person.pm | 3 +-- licom.cgi | 34 +++++++++++++++++++--------------- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/lib/LiCoM/Config.pm b/lib/LiCoM/Config.pm index f62c7d4..295f7eb 100644 --- a/lib/LiCoM/Config.pm +++ b/lib/LiCoM/Config.pm @@ -2,21 +2,22 @@ package LiCoM::Config; use strict; use warnings; +use Carp (qw(cluck confess)); use Exporter; -@LiCoM::Config::EXPORT_OK = ('get_config read_config'); +@LiCoM::Config::EXPORT_OK = (qw(get_config set_config read_config)); @LiCoM::Config::ISA = ('Exporter'); our $Config = {}; return (1); -=head1 STATIC FUNCTIONS +=head1 EXPORTED FUNCTIONS =over 4 -=item LiCoM::Config-EB (I<$key>) +=item B (I<$key>) Returns the value for I<$key> or undef if it's unknown. @@ -24,9 +25,10 @@ Returns the value for I<$key> or undef if it's unknown. sub get_config { - my $pkg = shift; my $key = shift; + cluck ("\$key was not defined") unless (defined ($key)); + if (!%$Config) { read_config (); @@ -35,7 +37,7 @@ sub get_config return ($Config->{$key}); } -=item LiCoM::Config-EB (I<$key>, I<$value>) +=item B (I<$key>, I<$value>) Sets the value of I<$key> to I<$value>. @@ -43,14 +45,15 @@ Sets the value of I<$key> to I<$value>. sub set_config { - my $pkg = shift; my $key = shift; my $val = shift; + cluck ("\$key was not defined") unless (defined ($key)); + $Config->{$key} = $val; } -=item LiCoM::Config-EB ([I<@files>]) +=item B ([I<@files>]) Read the config from the files given or F and F<~/.licomrc> if no files were given. @@ -75,10 +78,10 @@ sub read_config my $file = $_; next unless (-r $file); - read_file ($file, $config); + read_file ($file, $Config); } - return ($config); + return ($Config); } sub read_file diff --git a/lib/LiCoM/Connection.pm b/lib/LiCoM/Connection.pm index ad78378..ef8955f 100644 --- a/lib/LiCoM/Connection.pm +++ b/lib/LiCoM/Connection.pm @@ -13,7 +13,6 @@ LiCoM::Connection - Represents the connection to an LDAP-server. =cut -our %Config = get_config (); our $Ldap; @LiCoM::Connection::EXPORT_OK = (qw($Ldap)); @@ -37,13 +36,12 @@ sub connect my %opts = @_; my $bind_dn = $opts{'bind_dn'}; - my $base_dn = $opts{'base_dn'}; my $uri = $opts{'uri'}; my $passwd = $opts{'password'}; my $msg; - die unless ($bind_dn and $base_dn and $uri and defined ($passwd)); + die unless ($bind_dn and $uri and defined ($passwd)); $Ldap = Net::LDAP->new ($uri); @@ -54,8 +52,6 @@ sub connect return (0); } - $Config{'base_dn'} = $base_dn; - return (1); } diff --git a/lib/LiCoM/Person.pm b/lib/LiCoM/Person.pm index b5c2fdf..a5bf4e2 100644 --- a/lib/LiCoM/Person.pm +++ b/lib/LiCoM/Person.pm @@ -4,6 +4,7 @@ use strict; use warnings; use LiCoM::Config (qw(get_config)); +use LiCoM::Connection (qw($Ldap)); use Net::LDAP; use Net::LDAP::Filter; @@ -44,8 +45,6 @@ our %ExternalNames = password => 'userPassword' ); -our $Ldap; - return (1); =head1 STATIC FUNCTIONS diff --git a/licom.cgi b/licom.cgi index 59eddd6..f0dfd12 100755 --- a/licom.cgi +++ b/licom.cgi @@ -9,13 +9,14 @@ use CGI::Carp (qw(fatalsToBrowser)); use URI::Escape; use Data::Dumper; -use LiCoM::Config (qw(get_config)); -use LiCoM::Person; +use LiCoM::Config (qw(get_config set_config read_config)); +use LiCoM::Connection (); +use LiCoM::Group (); +use LiCoM::Person (); our $Debug = 0; -our $Config = {}; -our @MultiFields = (qw(address homephone cellphone officephone fax mail uri group)); +our @MultiFields = (qw(address homephone cellphone officephone fax mail uri)); our %FieldNames = ( @@ -49,24 +50,25 @@ our %Actions = vcard => \&action_vcard ); -$Config = get_config (); +read_config (); # make sure AuthLDAPRemoteUserIsDN is enabled. die unless ($ENV{'REMOTE_USER'}); -$Config->{'base_dn'} = $ENV{'REMOTE_USER'}; +set_config ('base_dn', $ENV{'REMOTE_USER'}); -die unless (defined ($Config->{'uri'}) and defined ($Config->{'base_dn'}) - and defined ($Config->{'bind_dn'}) and defined ($Config->{'password'})); +die unless (defined (get_config ('uri')) + and defined (get_config ('base_dn')) + and defined (get_config ('bind_dn')) + and defined (get_config ('password'))); -LiCoM::Person->connect +LiCoM::Connection->connect ( - uri => $Config->{'uri'}, - base_dn => $Config->{'base_dn'}, - bind_dn => $Config->{'bind_dn'}, - password => $Config->{'password'} + uri => get_config ('uri'), + bind_dn => get_config ('bind_dn'), + password => get_config ('password') ) or die; -our ($UserCN, $UserID) = LiCoM::Person->get_user ($Config->{'base_dn'}); +our ($UserCN, $UserID) = LiCoM::Person->get_user ($ENV{'REMOTE_USER'}); if (!$UserID and $Action ne 'save') { @@ -95,7 +97,7 @@ elsif (ref ($Actions{$Action}) eq 'ARRAY') } } -LiCoM::Person->disconnect (); +LiCoM::Connection->disconnect (); exit (0); @@ -107,6 +109,8 @@ sub action_browse $group = shift if (@_); $group ||= ''; + return (''); + my @all; if ($group) { -- 2.11.0