our %Actions =
(
- browse => [\&html_start, \&action_browse, \&html_end],
- default => [\&html_start, \&action_browse, \&html_end],
+ 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],
save => [\&html_start, \&action_save, \&html_end],
search => [\&html_start, \&action_search, \&html_end],
+ verify => [\&html_start, \&action_verify, \&html_end],
vcard => \&action_vcard
);
my $person = $_;
my @g = $person->get ('group');
- $groups{$_} = 1 for (@g);
+ $groups{$_} = (defined ($groups{$_}) ? $groups{$_} + 1 : 1) for (@g);
}
- print qq(\t<h2>Contact Groups</h2>\n\t<ul class="groups">\n);
+ print qq(\t\t<h2>Contact Groups</h2>\n\t\t<ul class="groups">\n);
for (sort (keys (%groups)))
{
my $group = $_;
my $group_esc = uri_escape ($group);
+ my $num = $groups{$group};
- print qq(\t\t<li><a href="$MySelf?action=browse&group=$group_esc">$group</a></li>\n);
+ print qq(\t\t\t<li><a href="$MySelf?action=browse&group=$group_esc">$group</a> ($num)</li>\n);
}
if (!%groups)
{
- print qq(\t\t<li class="empty">There are no groups yet.</li>\n);
+ print qq(\t\t\t<li class="empty">There are no groups yet.</li>\n);
}
- print qq(\t</ul>\n);
+ print qq(\t\t</ul>\n\n);
+ }
+
+ if ($group eq '*')
+ {
+ print qq(\t\t<h2>All Contacts</h2>\n);
}
else
{
- print qq(\t<h2>Contact Group "$group"</h2>\n\t<ul class="results">\n);
- for (@all)
- {
- my $person = $_;
- my $cn = $person->name ();
- my $cn_esc = uri_escape ($cn);
+ print qq(\t\t<h2>Contact Group "$group"</h2>\n);
+ }
- print qq(\t\t<li><a href="$MySelf?action=detail&cn=$cn_esc">$cn</a></li>\n);
- }
- print qq(\t</ul>\n);
+ print qq(\t\t<ul class="results">\n);
+ for (@all)
+ {
+ my $person = $_;
+ my $cn = $person->name ();
+ my $cn_esc = uri_escape ($cn);
+
+ print qq(\t\t\t<li><a href="$MySelf?action=detail&cn=$cn_esc">$cn</a></li>\n);
}
+ print qq(\t\t</ul>\n\n);
}
sub action_detail
}
}
print <<EOF;
+ <th colspan="2" class="menu">
+ [<a href="$MySelf?action=verify&cn=$cn_esc">Verify</a>]
+ [<a href="$MySelf?action=vcard&cn=$cn_esc">vCard</a>]
+ [<a href="$MySelf?action=edit&cn=$cn_esc">Edit</a>]
+ </th>
</table>
- <div class="detail menu">
- [<a href="$MySelf?action=edit&cn=$cn_esc">edit</a>]
- [<a href="$MySelf?action=vcard&cn=$cn_esc">vCard</a>]
- </div>
EOF
}
<input type="hidden" name="cn" value="$cn" />
<table class="edit">
<tr>
- <td>Lastname</td>
+ <th>Lastname</th>
EOF
if ($UserID)
{
print <<EOF;
</tr>
<tr>
- <td>Firstname</td>
+ <th>Firstname</th>
EOF
if ($UserID)
{
print <<EOF;
<tr>
- <td>$print</td>
+ <th>$print</th>
<td><input type="text" name="$field" value="$value" /></td>
</tr>
EOF
print <<EOF;
<tr>
- <td colspan="2">
+ <th colspan="2" class="menu">
EOF
- print qq(\t\t\t\t\t<input type="submit" name="button" value="Update" />\n) if ($UserID);
+ if ($UserID)
+ {
+ print <<EOF;
+ <input type="submit" name="button" value="Cancel" />
+ <input type="submit" name="button" value="Apply" />
+EOF
+ }
print <<EOF;
<input type="submit" name="button" value="Save" />
- </td>
+ </th>
</tr>
</table>
</form>
die unless ($UserID);
+ my $button = lc (param ('button'));
+ $button ||= 'save';
+
+ if ($button eq 'cancel')
+ {
+ action_browse ();
+ return;
+ }
+
if (!param ('lastname') or !param ('firstname'))
{
print qq(\t<div class="error">You have to give both, first and lastname, to identify this record.</div>\n);
$cn = $person->name ();
- if (param ('button') eq 'Update')
+ if ($button eq 'apply')
{
action_edit (cn => $cn);
}
die unless ($person);
+ my $button = lc (param ('button'));
+ $button ||= 'save';
+
+ if ($UserID and $button eq 'cancel')
+ {
+ action_detail ($cn);
+ return;
+ }
+
if ($UserID)
{
my $lastname = param ('lastname');
}
}
- if (param ('button') eq 'Update' or !$UserID)
+ if ($button eq 'apply' or !$UserID)
{
action_edit (cn => $cn);
}
print "END:VCARD\n";
}
+sub action_verify
+{
+ my $cn = param ('cn');
+ $cn = shift if (@_);
+ die unless ($cn);
+
+ my $person = Person->load ($cn);
+ die unless ($person);
+
+ my ($mail) = $person->get ('mail');
+ $mail ||= '';
+
+ my $message;
+ my $password = $person->password ();
+
+ if (!$password)
+ {
+ $password = pwgen ();
+ $person->password ($password);
+ }
+
+ $message = qq(The password for the record "$cn" is "$password".);
+
+ if ($mail)
+ {
+ action_verify_send_mail ($person);
+ $message .= qq( A request for verification has been sent to $mail.);
+ }
+ else
+ {
+ $message .= q( There was no e-mail address, thus no verification request could be sent.);
+ }
+
+ print qq(\t\t<div class="message">$message</div>\n);
+
+ action_detail ($cn);
+}
+
+sub action_verify_send_mail
+{
+ my $person = shift;
+ my $owner = Person->load ($UserCN);
+ my $smh;
+
+ my $max_width = 0;
+ for (keys %FieldNames)
+ {
+ $max_width = length $FieldNames{$_} if ($max_width < length $FieldNames{$_});
+ }
+ $max_width++;
+
+ my $person_name = $person->name ();
+ my ($person_mail) = $person->get ('mail');
+ my $person_gn = $person->firstname ();
+ my $password = $person->password ();
+
+ my $owner_name = $owner->name ();
+ my ($owner_mail) = $owner->get ('mail');
+ $owner_mail ||= $ENV{'SERVER_ADMIN'};
+
+ my $host = $ENV{'HTTP_HOST'};
+ my $url = 'http://' . $host . $MySelf;
+
+ open ($smh, '| /usr/sbin/sendmail -t') or die ("open pipe to sendmail: $!");
+ print $smh <<EOM;
+To: $person_name <$person_mail>
+From: $owner_name <$owner_mail>
+Subject: Please verify our entry in my address book
+
+Hello $person_gn,
+
+the following is your entry in my address book:
+EOM
+ for (@MultiFields)
+ {
+ my $field = $_;
+ my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field;
+ my @values = $person->get ($field);
+
+ for (@values)
+ {
+ printf $smh ('%'.$max_width."s: %-s\n", $print, $_);
+ }
+ }
+ print $smh <<EOM;
+
+If this entry is outdated or incomplete, please take a minute and correct it.
+ Address: $url
+ Username: $person_name
+ Password: $password
+
+Thank you very much :) Regards,
+$owner_name
+EOM
+ close ($smh);
+}
+
sub html_start
{
my $title = shift;
- $title = q(octo's Lightweight Address Book) unless ($title);
+ $title = q(Lightweight Contact Manager) unless ($title);
print <<EOF;
Content-Type: text/html; charset=UTF-8
<title>$title</title>
<style type="text/css">
<!--
+a
+{
+ color: blue;
+ background-color: inherit;
+ text-decoration: none;
+}
+
+a:hover
+{
+ text-decoration: underline;
+}
+
+a:visited
+{
+ color: navy;
+ background-color: inherit;
+}
+
body
{
color: black;
width: 100%;
}
+div.foot a
+{
+ color: black;
+ background-color: inherit;
+ text-decoration: none;
+}
+
+div.foot a:hover
+{
+ text-decoration: underline;
+}
+
div.menu form
{
display: inline;
text-align: left;
vertical-align: top;
}
+
+th.menu
+{
+ text-align: right;
+}
+
+th.menu a
+{
+ color: blue;
+ background-color: transparent;
+}
//-->
</style>
</head>
<hr />
EOF
}
- print "\t\t<h1>octo's Lightweight Address Book</h1>\n";
+ print "\t\t<h1>$title</h1>\n";
}
sub html_end
{
print <<EOF;
- <div class="foot">octo's Lightweight Address Book <octo at verplant.org></div>
+ <div class="foot">
+ "Lightweight Contact Manager",
+ written 2005 by <a href="http://verplant.org/">Florian octo Forster</a>
+ <octo at verplant.org>
+ </div>
</body>
</html>
EOF
die ("Not defined: $_") unless (defined ($Config{$_}));
}
}
+
+sub pwgen
+{
+ my $len = @_ ? shift : 6;
+ my $retval = '';
+
+ while (!$retval)
+ {
+ my $numbers = 0;
+ my $lchars = 0;
+ my $uchars = 0;
+
+ while (length ($retval) < $len)
+ {
+ my $chr = int (rand (128));
+
+ if ($chr >= 48 and $chr < 58)
+ {
+ $numbers++;
+ }
+ elsif ($chr >= 65 and $chr < 91)
+ {
+ $uchars++;
+ }
+ elsif ($chr >= 97 and $chr < 123)
+ {
+ $lchars++;
+ }
+ else
+ {
+ next;
+ }
+ $retval .= chr ($chr);
+ }
+
+ $retval = '' if (!$numbers or !$lchars or !$uchars);
+ }
+
+ return ($retval);
+}