#!/usr/bin/perl # LiCoM - Lightweight contact manager # Copyright (c) 2005-2006 Florian octo Forster # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; only version 2 of the License is applicable. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software # Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; use warnings; use lib (qw(lib)); use Encode (qw(encode decode is_utf8)); use CGI (':cgi'); use CGI::Carp (qw(fatalsToBrowser)); use URI::Escape; use HTML::Entities (qw(encode_entities)); use LiCoM::Config (qw(get_config set_config read_config)); use LiCoM::Connection (); use LiCoM::Group (); use LiCoM::Person (); our $Debug = 0; our @MultiFields = (qw(address homephone cellphone officephone fax mail uri)); our %FieldNames = ( address => 'Address', homephone => 'Home Phone', cellphone => 'Cell Phone', officephone => 'Office Phone', fax => 'FAX', mail => 'E-Mail', uri => 'URI (Homepage)', group => 'Group' ); our $MySelf = $ENV{'SCRIPT_NAME'}; our $Action = param_utf8 ('action'); $Action ||= 'default'; our %Actions = ( browse => [\&html_start, \&action_browse, \&html_end], default => [\&html_start, \&action_browse, \&html_end], detail => [\&html_start, \&action_detail, \&html_end], edit => [\&html_start, \&action_edit, \&html_end], list => [\&html_start, \&action_list, \&html_end], save => [\&html_start, \&action_save, \&html_end], search => [\&html_start, \&action_search, \&html_end], verify => [\&html_start, \&action_verify, \&html_end], delete => [\&html_start, \&action_ask_del, \&html_end], expunge => [\&html_start, \&action_do_del, \&html_end], vcard => \&action_vcard, edit_group => [\&html_start, \&action_edit_group, \&html_end], save_group => [\&html_start, \&action_save_group, \&html_end] ); read_config (); # make sure AuthLDAPRemoteUserIsDN is enabled. die unless ($ENV{'REMOTE_USER'}); #set_config ('base_dn', $ENV{'REMOTE_USER'}); die ("Configuration is incomplete") unless (defined (get_config ('uri')) and defined (get_config ('base_dn')) and defined (get_config ('bind_dn')) and defined (get_config ('password'))); LiCoM::Connection->connect ( uri => get_config ('uri'), bind_dn => get_config ('bind_dn'), password => get_config ('password') ) or die ("Unable to connect to LDAP directory server " . get_config ('uri')); our ($UserCN, $UserID) = LiCoM::Person->get_user ($ENV{'REMOTE_USER'}); if (!$UserID and $Action ne 'save') { $Action = 'edit'; } if (!$UserCN) { die ("No such user in the LDAP directory: " . $ENV{'REMOTE_USER'}); } if (!defined ($Actions{$Action})) { die ("No such action: $Action"); } if (ref ($Actions{$Action}) eq 'CODE') { $Actions{$Action}->(); } elsif (ref ($Actions{$Action}) eq 'ARRAY') { for (@{$Actions{$Action}}) { $_->(); } } LiCoM::Connection->disconnect (); exit (0); ### sub action_browse { my $group = param_utf8 ('group'); $group = shift if (@_); $group ||= ''; if (!$group) { my @groups = LiCoM::Group->all (); print qq(\t\t

Contact groups

\n\t\t