X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=licom.cgi;h=58c88ccfd1f22b1d19f8abd81a26ca5c7b8e3856;hb=088609f68349c6888d73aaa60708d7bab4a8e7d0;hp=4af14ad7b37a84e185cf24b420d28fc7502891fd;hpb=0b46496344123e462825844a676997b77823b365;p=licom.git
diff --git a/licom.cgi b/licom.cgi
index 4af14ad..58c88cc 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));
@@ -43,24 +44,29 @@ our %Actions =
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
);
-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 +95,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 +110,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 +127,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\tContact Groups
\n\t\t\n);
for (sort (keys (%groups)))
@@ -146,7 +154,7 @@ sub action_browse
}
else
{
- print qq(\t\tAll Contacts
\n);
+ print qq(\t\tContacts without a group
\n);
}
print qq(\t\t\n);
@@ -158,6 +166,10 @@ sub action_browse
print qq(\t\t\t- $cn
\n);
}
+ if (!@all)
+ {
+ print "\t\t\t- There are no matching entries.
\n";
+ }
print qq(\t\t
\n\n);
print qq(\t\t
EOF
@@ -340,7 +353,7 @@ sub action_search
push (@filter, [[lastname => $pattern], [firstname => $pattern]]);
}
- my @matches = Person->search (@filter);
+ my @matches = LiCoM::Person->search (@filter);
if (!@matches)
{
@@ -357,7 +370,7 @@ sub action_search
}
print qq(\t\n);
- for (@matches)
+ for (sort { $a->name () cmp $b->name () } (@matches))
{
my $person = $_;
my $cn = $person->name ();
@@ -392,7 +405,7 @@ sub action_edit
if ($cn)
{
- $person = Person->load ($cn);
+ $person = LiCoM::Person->load ($cn);
if (!$person)
{
@@ -469,6 +482,8 @@ EOF
my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field;
my @values = @{$contacts->{$field}};
+ next if (!$UserID and $field eq 'group');
+
push (@values, '');
for (@values)
@@ -543,7 +558,7 @@ sub action_save
my $contacts = get_contacts ();
- my $person = Person->create (lastname => $lastname, firstname => $firstname, %$contacts);
+ my $person = LiCoM::Person->create (lastname => $lastname, firstname => $firstname, %$contacts);
if (!$person)
{
@@ -566,7 +581,7 @@ sub action_save
sub action_update
{
my $cn = $UserID ? param ('cn') : $UserCN;
- my $person = Person->load ($cn);
+ my $person = LiCoM::Person->load ($cn);
die unless ($person);
@@ -596,6 +611,8 @@ sub action_update
{
my $field = $_;
+ next if (!$UserID and $field eq 'group');
+
if (defined ($contacts->{$field}))
{
my $values = $contacts->{$field};
@@ -623,7 +640,7 @@ sub action_vcard
$cn = shift if (@_);
die unless ($cn);
- my $person = Person->load ($cn);
+ my $person = LiCoM::Person->load ($cn);
die unless ($person);
my %vcard_types =
@@ -657,6 +674,8 @@ EOF
my $vc_fld = $vcard_types{$field};
my $values = $person->get ($field);
+ next unless ($vc_fld);
+
for (@$values)
{
my $value = $_;
@@ -672,19 +691,19 @@ sub action_verify
$cn = shift if (@_);
die unless ($cn);
- my $person = Person->load ($cn);
+ my $person = LiCoM::Person->load ($cn);
die unless ($person);
my ($mail) = $person->get ('mail');
$mail ||= '';
my $message;
- my $password = $person->password ();
+ my $password = $person->get ('password');
if (!$password)
{
$password = pwgen ();
- $person->password ($password);
+ $person->set ('password', $password);
}
$message = qq(The password for the record "$cn" is "$password".);
@@ -709,7 +728,7 @@ sub action_verify
sub action_verify_send_mail
{
my $person = shift;
- my $owner = Person->load ($UserCN);
+ my $owner = LiCoM::Person->load ($UserCN);
my $smh;
my ($owner_mail) = $owner->get ('mail');
@@ -730,10 +749,10 @@ sub action_verify_send_mail
my $person_name = $person->name ();
my ($person_mail) = $person->get ('mail');
my $person_gn = $person->firstname ();
- my $password = $person->password ();
+ my $password = $person->get ('password');
my $host = $ENV{'HTTP_HOST'};
- my $url = 'http://' . $host . $MySelf;
+ my $url = (defined ($ENV{'HTTPS'}) ? 'https://' : 'http://') . $host . $MySelf;
open ($smh, "| /usr/sbin/sendmail -t -f $owner_mail") or die ("open pipe to sendmail: $!");
print $smh <load ($cn);
+ $person or die;
+
+ my $cn_esc = uri_escape ($cn);
+
+ print <Really delete $cn?
+
+
+ You are about to delete $cn. Are you
+ totally, absolutely sure you want to do this?
+
+
+
+
+EOF
+}
+
+sub action_do_del
+{
+ my $cn = param ('cn');
+ $cn or die;
+
+ my $person = LiCoM::Person->load ($cn);
+ $person or die;
+
+ $person->delete ();
+
+ print <$cn has been deleted.
+
+EOF
+ action_browse ();
+}
+
sub html_start
{
my $title = shift;
@@ -987,6 +1054,7 @@ Content-Type: text/html; charset=UTF-8
EOF
+
if ($UserID)
{
my $search = param ('search') || '';
@@ -1025,34 +1093,6 @@ sub html_end
EOF
}
-sub read_config
-{
- my $file = '/var/www/html/cgi.verplant.org/address/book.conf';
- my $fh;
-
- 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);
-
- for (qw(uri bind_dn password))
- {
- die ("Not defined: $_") unless (defined ($Config{$_}));
- }
-}
-
sub pwgen
{
my $len = @_ ? shift : 6;
@@ -1113,9 +1153,9 @@ sub verify_fields
my $number = $_;
next unless ($number);
- if ($number !~ m/^\+/)
+ if ($number !~ m/^\+[0-9 \-]+$/)
{
- push (@errors, 'Telephone numbers have to begin with the country code, e.g. "+49 911 123456"');
+ push (@errors, 'Telephone numbers have to begin with the country code and only numbers, spaces and dashes are allowed, e.g. "+49 911-123456"');
last;
}
}
@@ -1148,8 +1188,8 @@ sub get_contacts
{
for (@values)
{
- $_ =~ s/\D//g;
- $_ = '+' . $_;
+ $_ =~ s/[^0-9 \-]//g;
+ $_ = '+' . $_ if ($_);
}
}