View previous topic :: View next topic |
Author |
Message |
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Sun Nov 28, 2004 3:26 am Post subject: howto: ldap addressbook for kmail |
|
|
After seeing https://forums.gentoo.org/viewtopic.php?t=126278
(Creating a central outlook addressbook with OpenLDAP howto), I did write a ldap schema for kmail and templates for phpldapadmin for managing entries. Hope it helps someone.
neccessry programs in addition to apache2 and php support:
emerge openldap phpldapadmin
1)create a ldap scheme (kaddressbookperson.schema)
2)slapd configiration (slapd.conf)
2)create phpldapadmin template (new_kaddress_template.php)
3)phpldap configiration (template_config.php)
KAddresbook supports following ldap attributes (from current kaddressbook source code):
Quote: | static QMap<QString, QString>& adrbookattr2ldap()
{
static QMap<QString, QString> keys;
if ( keys.isEmpty() ) {
keys[ i18n( "Title" ) ] = "title";
keys[ i18n( "Full Name" ) ] = "cn";
keys[ i18n( "Email" ) ] = "mail";
keys[ i18n( "Home Number" ) ] = "homePhone";
keys[ i18n( "Work Number" ) ] = "telephoneNumber";
keys[ i18n( "Mobile Number" ) ] = "mobile";
keys[ i18n( "Fax Number" ) ] = "facsimileTelephoneNumber";
keys[ i18n( "Pager" ) ] = "pager";
keys[ i18n( "Street") ] = "street";
keys[ i18n( "State" ) ] = "st";
keys[ i18n( "Country" ) ] = "co";
keys[ i18n( "City" ) ] = "l";
keys[ i18n( "Organization" ) ] = "o";
keys[ i18n( "Company" ) ] = "Company";
keys[ i18n( "Department" ) ] = "department";
keys[ i18n( "Zip Code" ) ] = "postalCode";
keys[ i18n( "Postal Address" ) ] = "postalAddress";
keys[ i18n( "Description" ) ] = "description";
keys[ i18n( "User ID" ) ] = "uid";
}
return keys;
}
|
1) kaddressbookPerson schema:
first we need to create attributes for the above keys.
create the follwoing file /etc/openldap/scheme/kaddressbookperson.schema
Code: |
# Schema for ldap-kaddressbook
#
# kaddressbookPerson
#
attributetype (1.3.6.1.4.1.4203.666.11.2
NAME 'Company'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
attributetype (1.3.6.1.4.1.4203.666.11.3
NAME 'department'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
objectclass (1.3.6.1.4.1.4203.666.11.1 NAME 'kaddressbookPerson'
DESC 'Personal data for KAddressBook'
STRUCTURAL
MUST (cn)
MAY ( title $
mail $
homePhone $
telephoneNumber $
mobile $
facsimileTelephoneNumber $
pager $
street $
st $
co $
l $
o $
Company $
department $
postalCode $
postalAddress $
description $
uid)
)
|
2)configuring slapd:
we tell ldap about our schema.
insert the following lines into /etc/openldap/slapd.conf
Code: |
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/kadressbookperson.schema
|
3)creating phpldapadmin template:
this is a long one, you can copy and paste.
this file creates a form, so we can enter new adresses into ldap database.
create the folling file /var/www/localhost/htdocs/phpldapadmin/templates/creation/new_kaddress_template.php
Code: |
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/templates/creation/new_kaddress_template.php,v 1.9 2004/05/05 12:47:54 uugdave Exp $
// customize this to your needs
$default_container = "ou=kaddressbookPerson";
// Common to all templates
$container = $_POST['container'];
$server_id = $_POST['server_id'];
// Unique to this template
$step = isset( $_POST['step'] ) ? $_POST['step'] : 1;
check_server_id( $server_id ) or pla_error( "Bad server_id: " . htmlspecialchars( $server_id ) );
have_auth_info( $server_id ) or pla_error( "Not enough information to login to server. Please check your configuration." );
?>
<script language="javascript">
<!--
/*
* Populates the common name field based on the last
* name concatenated with the first name, separated
* by a blank
*/
function autoFillCommonName( form )
{
var first_name;
var last_name;
var common_name;
first_name = form.first_name.value;
last_name = form.last_name.value;
common_name = first_name + ' ' + last_name;
form.common_name.value = common_name;
}
-->
</script>
<center><h2>New Address Book Entry<br />
<small>(KAdressBookPerson)</small></h2>
</center>
<?php if( $step == 1 ) { ?>
<form action="creation_template.php" method="post" id="address_form" name="address_form">
<input type="hidden" name="step" value="2" />
<input type="hidden" name="server_id" value="<?php echo $server_id; ?>" />
<input type="hidden" name="template" value="<?php echo htmlspecialchars( $_POST['template'] ); ?>" />
<input type="hidden" name="common_name" id="common_name" value="" />
<center>
<table class="confirm">
<tr class="spacer"><td colspan="3"/></tr>
<tr>
<td><img src="images/uid.png" /></td>
<td class="heading">Name:</td>
<td>
<input type="text" name="first_name"
id="first_name" value="first" onChange="autoFillCommonName(this.form)" />
<input type="text" name="last_name"
id="last_name" value="last" onChange="autoFillCommonName(this.form)" />
</td>
</tr>
<tr>
<td></td>
<td class="heading">Title</td>
<td><input type="text" name="title" id="title" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Email:</td>
<td><input type="text" name="email_address" id="email_address" value="" /></td>
</tr>
<tr>
<td><img src="images/phone.png" /></td>
<td class="heading">Home phone:</td>
<td><input type="text" name="home_phone" id="home_phone" value="" /></td>
</tr>
<tr>
<td><img src="images/phone.png" /></td>
<td class="heading">Work phone:</td>
<td><input type="text" name="work_phone" id="work_phone" value="" /></td>
</tr>
<tr>
<td><img src="images/phone.png" /></td>
<td class="heading">Mobile:</td>
<td><input type="text" name="mobile_number" id="mobile_number" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Fax:</td>
<td><input type="text" name="fax_number" id="fax_number" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Pager:</td>
<td><input type="text" name="pager_number" id="pager_number" value="" /></td>
</tr>
<tr class="spacer"><td colspan="3" /></tr>
<tr>
<td><img src="images/mail.png" /></td>
<td class="heading">Street:</td>
<td><input type="text" name="street_address" id="street_address" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">City:</td>
<td><input type="text" name="city" id="city" value="" /></td>
<tr>
<tr>
<td></td>
<td class="heading">State:</td>
<td><input type="text" name="state" id="state" value="" /></td>
<tr>
<tr>
<td></td>
<td class="heading">Zip Code:</td>
<td><input type="text" name="zip_code" id="zip_code" value="" /></td>
<tr>
<tr>
<td></td>
<td class="heading">Country:</td>
<td><input type="text" name="country" id="country" value="" /></td>
</tr>
<tr class="spacer"><td colspan="3"/></tr>
<tr>
<td><img src="images/mail.png" /></td>
<td class="heading">Postal Address:</td>
<td><input type="text" name="postal_address" id="postal_address" value="" /></td>
</tr>
<tr class="spacer"><td colspan="3"/></tr>
<tr>
<td></td>
<td class="heading">Organization:</td>
<td><input type="text" name="organization" id="organization" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Company:</td>
<td><input type="text" name="company" id="company" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Department:</td>
<td><input type="text" name="department" id="department" value="" /></td>
</tr>
<tr class="spacer"><td colspan="3"/></tr>
<tr>
<td valign="top"><img src="images/move.png" /></td>
<td class="heading" valign="top">Notes:</td>
<td><textarea rows="10" cols="30" name="description" id="description"></textarea></td>
</tr>
<tr class="spacer"><td colspan="3"/></tr>
<tr>
<td valign="top"><img src="images/uid.png" /></td>
<td class="heading" valign="top">UID:</td>
<td><input type="text" name="uid" id="uid" value="" /></td>
</tr>
<tr>
<td></td>
<td class="heading">Container:</td>
<td><input type="text" name="container" size="40"
value="<?php if( isset( $container ) )
echo htmlspecialchars( $container );
else
echo htmlspecialchars( $default_container . ',' . $servers[$server_id]['base'] ); ?>" />
<?php draw_chooser_link( 'address_form.container' ); ?></td>
</td>
</tr>
<tr>
<td colspan="3"><center><br /><input type="submit" value="Proceed >>" /></td>
</tr>
</table>
</center>
<?php } elseif( $step == 2 ) {
$common_name = trim( $_POST['common_name'] );
$first_name = trim( $_POST['first_name'] );
$last_name = trim( $_POST['last_name'] );
$title = trim( $_POST['title'] );
$email_address = trim( $_POST['email_address'] );
$home_phone = trim( $_POST['home_phone'] );
$work_phone = trim( $_POST['work_phone'] );
$mobile_number = trim( $_POST['mobile_number'] );
$fax_number = trim( $_POST['fax_number'] );
$pager_number = trim( $_POST['pager_number'] );
$street_address = trim( $_POST['street_address'] );
$city = trim( $_POST['city'] );
$state = trim( $_POST['state'] );
$zip_code = trim( $_POST['zip_code'] );
$country = trim( $_POST['country'] );
$postal_address = trim( $_POST['postal_address'] );
$organization = trim( $_POST['organization'] );
$company = trim( $_POST['company'] );
$department = trim( $_POST['department'] );
$description = trim( $_POST['description'] );
$uid = trim( $_POST['uid'] );
$container = trim( $_POST['container'] );
/* Critical assertions */
0 != strlen( $common_name ) or
pla_error( "You cannot leave the Common Name blank. Please go back and try again." );
?>
<center><h3>Confirm entry creation:</h3></center>
<form action="create.php" method="post">
<input type="hidden" name="server_id" value="<?php echo $server_id; ?>" />
<input type="hidden" name="new_dn" value="<?php echo htmlspecialchars( 'cn=' . $common_name . ',' . $container ); ?>" />
<!-- ObjectClasses -->
<?php $object_classes = rawurlencode( serialize( array( 'top', 'kaddressbookPerson' ) ) ); ?>
<input type="hidden" name="object_classes" value="<?php echo $object_classes; ?>" />
<!-- The array of attributes/values -->
<input type="hidden" name="attrs[]" value="cn" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($common_name);?>" />
<input type="hidden" name="attrs[]" value="title" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($title);?>" />
<input type="hidden" name="attrs[]" value="mail" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($email_address);?>" />
<input type="hidden" name="attrs[]" value="homePhone" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($home_phone);?>" />
<input type="hidden" name="attrs[]" value="telephoneNumber" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($work_phone);?>" />
<input type="hidden" name="attrs[]" value="mobile" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($mobile_number);?>" />
<input type="hidden" name="attrs[]" value="facsimileTelephoneNumber" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($fax_number);?>" />
<input type="hidden" name="attrs[]" value="pager" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($pager_number);?>" />
<input type="hidden" name="attrs[]" value="street" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($street_address);?>" />
<input type="hidden" name="attrs[]" value="l" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($city);?>" />
<input type="hidden" name="attrs[]" value="st" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($state);?>" />
<input type="hidden" name="attrs[]" value="postalCode" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($zip_code);?>" />
<input type="hidden" name="attrs[]" value="co" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($country);?>" />
<input type="hidden" name="attrs[]" value="postalAddress" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($postal_address);?>" />
<input type="hidden" name="attrs[]" value="o" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($organization);?>" />
<input type="hidden" name="attrs[]" value="Company" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($company);?>" />
<input type="hidden" name="attrs[]" value="department" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($department);?>" />
<input type="hidden" name="attrs[]" value="description" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($description);?>" />
<input type="hidden" name="attrs[]" value="uid" />
<input type="hidden" name="vals[]" value="<?php echo htmlspecialchars($uid);?>" />
<center>
<table class="confirm">
<tr class="odd">
<td class="heading">Name:</td>
<td><b><?php echo htmlspecialchars( $common_name ); ?></b></td>
</tr>
<tr class="even">
<td class="heading">Title:</td>
<td><b><?php echo htmlspecialchars( $title ); ?></b></td>
</tr>
<tr class="odd">
<td class="heading">Email:</td>
<td><a href="mailto:<?php echo htmlspecialchars( $email_address ); ?>"><?php echo htmlspecialchars( $email_address ); ?></a></td>
</tr>
<tr class="even">
<td class="heading">Home phone:</td>
<td><?php echo htmlspecialchars( $home_phone ); ?></td>
</tr>
<tr class="even">
<td class="heading">Work phone:</td>
<td><?php echo htmlspecialchars( $work_phone ); ?></td>
</tr>
<tr class="even">
<td class="heading">Mobile:</td>
<td><?php echo htmlspecialchars( $mobile_number ); ?></td>
</tr>
<tr class="even">
<td class="heading">Fax:</td>
<td><?php echo htmlspecialchars( $fax_number ); ?></td>
</tr>
<tr class="even">
<td class="heading">Pager:</td>
<td><?php echo htmlspecialchars( $pager_number ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="odd">
<td colspan="2">Address:</td>
<tr class="odd">
<td class="heading">Street:</td>
<td><?php echo htmlspecialchars( $street_address ); ?></td>
</tr>
<tr class="odd">
<td></td>
<td><?php echo htmlspecialchars( $city ); ?>, 
<?php echo htmlspecialchars( $state ); ?> 
<?php echo htmlspecialchars( $zip_code ); ?></td>
</tr>
<tr class="odd">
<td class="heading">Country:</td>
<td><?php echo htmlspecialchars( $country ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="even">
<td class="heading">Postal address:</td>
<td><?php echo htmlspecialchars( $postal_address ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="odd">
<td class="heading">Organization:</td>
<td><?php echo htmlspecialchars( $organization ); ?></td>
</tr>
<tr class="odd">
<td class="heading">Company:</td>
<td><?php echo htmlspecialchars( $company ); ?></td>
</tr>
<tr class="odd">
<td class="heading">Department:</td>
<td><?php echo htmlspecialchars( $department ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="even">
<td class="heading">Notes:</td>
<td><?php echo htmlspecialchars( $description ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="odd">
<td class="heading">UID:</td>
<td><?php echo htmlspecialchars( $uid ); ?></td>
</tr>
<tr class="spacer"><td colspan="2"/></tr>
<tr class="even">
<td class="heading">Container:</td>
<td><?php echo htmlspecialchars( $container ); ?></td>
</tr>
</table>
<br /><input type="submit" value="Create Address" />
</center>
</form>
<?php } ?>
</body>
</html>
|
4)configuring phpldapadmin:
so that we see an entry in the create menu for addressbook.
modify the /var/www/localhost/htdocs/phpldapadmin/templates/template_config.php
Code: |
$templates[] =
array( 'desc' => 'KAddressBook (kaddressbookPerson)',
'icon' => 'images/user.png',
'handler' => 'new_kaddress_template.php' );
|
Now, restart slapd
Code: |
/etc/init.d/slapd restart
|
point your browser http://localhost/phpldapadmin/
create new kaddressbook entries.
you can search and import those addressbook entries from within kmail.
Unfortunately given address is imported as a work adress. kaddressbook doesn't support for importing keys other than listed at the very beggining. |
|
Back to top |
|
|
numerodix l33t
Joined: 18 Jul 2002 Posts: 743 Location: nl.eu
|
Posted: Sun Nov 28, 2004 2:40 pm Post subject: |
|
|
Having set up kaddressbook to work with ldap, couldn't you just use that to add contacts instead of the detour with phpldapadmin?
Also, I don't suppose it's possible to store *all* the data about a person in ldap, is there? Because right now you can add a new contact, fill in all data in the dialog box in kaddressbook and store it on the ldap server, but only the fields in the ldap scheme will actually be saved. Isn't there any way to dump all of that info into ldap? _________________ undvd - ripping dvds should be as simple as unzip |
|
Back to top |
|
|
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Sun Nov 28, 2004 7:53 pm Post subject: |
|
|
I don't think kaddessbook support writing directy into ldap. you can export address book in "ldif" format and write that into ldap database,using any ldap admin tool or command line ldap tools |
|
Back to top |
|
|
Sonic Lux Guru
Joined: 07 Mar 2004 Posts: 375 Location: Dresden / Germany
|
Posted: Mon Nov 29, 2004 12:19 am Post subject: |
|
|
The schema file works with Evolution and Mozilla Mail Client ?
Thx
Sonic |
|
Back to top |
|
|
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Mon Nov 29, 2004 7:41 am Post subject: |
|
|
I haven't tried that since i don't use evolution and mozilla mail client? if you search mozilla bugzilla, there is a schema posted in there. |
|
Back to top |
|
|
Sonic Lux Guru
Joined: 07 Mar 2004 Posts: 375 Location: Dresden / Germany
|
Posted: Mon Nov 29, 2004 9:26 am Post subject: |
|
|
alkan wrote: | I haven't tried that since i don't use evolution and mozilla mail client? if you search mozilla bugzilla, there is a schema posted in there. |
ok thx, i will test it |
|
Back to top |
|
|
numerodix l33t
Joined: 18 Jul 2002 Posts: 743 Location: nl.eu
|
Posted: Mon Nov 29, 2004 1:06 pm Post subject: |
|
|
alkan wrote: | I don't think kaddessbook support writing directy into ldap. you can export address book in "ldif" format and write that into ldap database,using any ldap admin tool or command line ldap tools |
I can confirm that it does.. _________________ undvd - ripping dvds should be as simple as unzip |
|
Back to top |
|
|
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Mon Nov 29, 2004 3:48 pm Post subject: |
|
|
numerodix wrote: | I can confirm that it does.. |
how? Would you please share? |
|
Back to top |
|
|
numerodix l33t
Joined: 18 Jul 2002 Posts: 743 Location: nl.eu
|
Posted: Mon Nov 29, 2004 6:40 pm Post subject: |
|
|
Certainly.. to begin with, I followed the howto you quoted in your first post: https://forums.gentoo.org/viewtopic.php?t=126278
Then I set up kaddressbook to use the ldap server just carrying over the settings from the server side.
Code: | /etc/openldap/slapd.conf
database ldbm
suffix "dc=my,dc=lan"
rootdn "cn=Manager,dc=my,dc=lan"
rootpw mypassword
|
In kaddressbook, select Add in the "Address Books" tab, choose LDAP and enter this:
Code: | user: cn=Manager,dc=my,dc=lan
password: mypassword
host: server-ip
port: 389
ldap version: 3 //very important!!
dn: ou=addressbook,dc=my,dc=lan
security: no
authentication: simple |
Thus you query the ldap server as the manager which grants you read/write status and you can add/edit entries with kaddressbook.
Of course this doesn't do much for security but since it's a private lan.. there is an option to use ssl but I could not get that working, haven't been able to connect through the ssl socket. _________________ undvd - ripping dvds should be as simple as unzip |
|
Back to top |
|
|
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Mon Nov 29, 2004 7:53 pm Post subject: |
|
|
thanks a ton. how did i miss that? I thought that button was only for adding addressbook resource in kaddressbook format. Then, I don't need to use phpldapadmin anymore. |
|
Back to top |
|
|
Sonic Lux Guru
Joined: 07 Mar 2004 Posts: 375 Location: Dresden / Germany
|
Posted: Mon Nov 29, 2004 8:41 pm Post subject: |
|
|
Hmm i have a problem.
---
klauncher said: Unknown protocol 'ldap'.
---
Why?
Sonic |
|
Back to top |
|
|
alkan Guru
Joined: 06 Aug 2004 Posts: 385 Location: kasimlar yaylasi
|
Posted: Mon Nov 29, 2004 9:59 pm Post subject: |
|
|
did you enable ldap support when emerging kdelibs?
USE="ldap" emerge kdelibs
or put it in /etc/make.conf and emerge kdellibs |
|
Back to top |
|
|
|