Opensource Calendar and Address book server: DAViCal

As many of you, I’ve been using Google Calendar features for a long time. But that was not completely satisfying, from a pure “opensource” and intellectual property perspective…
I was also looking for a way to synchronize my various Thunderbird installations (my wife and I are both using several calendars and several address books…) across all devices we have at home/work (Linux, Windows, smartphones,…).

Yesterday, thanks to a colleague (another geek ? Check his website: ezIX), I found the answer. I decided to setup my own server for Calendar and for Address books.
This is DAViCal.

DAViCal is a CalDAV server (with support for CardDAV), that relies on PHP and PostgreSQL.

  • CalDAV is an open standard for the exchange of calendering and task/todo/memo information between a client and a server.
  • CardDAV is an open standard for the exchange of contact/address book information between a client and a server.

From my understanding, this project is led by Andrew McMillian who has done a great job there !

Of course, I read on the web that it was not perfect, especially the interface design. This is true, but that’s not the objective of the tool. This tool is there to provide CalDAV and CardDAV services, and it does it well ! Thanks Andrew…

I decided to install it on my own computer, hosted at home.
This is part of my “big project” of building my home-made datacenter, and getting rid of all this “cloudy” stuff, where well-known companies are hosting your data for free (from a financial perspective), but where you loose all types of confidentiality and property on them…
This is my data. This is my asset. This is my life !
(but that’s another debate, let’s get back to the technical part now…)

Install server

The server installation is not “out of the box”, so I’m sharing my procedure: it may help (I read a few documents on the web about this, and the DAViCal web site itself is not always easy to follow…)

Pre-requisites

I’m using an Ubuntu 12.04 server.
DAViCal requires apache + php + postgres installed.
As I already installed apache & php for other needs (Piwigo), I just need to focus on the missing parts:

  • postgres installation:
    sudo apt-get install postgresql

    Then, I setup the postgres user password (write it down in your safe repository, you may need it later…):

    sudo -u postgres psql postgres
    \password postgres
  • apache installation:
    Apache/PHP were already installed on my computer. Otherwise:

    sudo apt-get install apache2 php5

    I just added one missing package:

    sudo apt-get install php5-curl

Davical

  • Package installation
    First, I used the default installation:
    sudo apt-get install davical
    This will install all necessary dependencies automatically.
    But later, I decided to migrate to a more recent version of the package. I went to the author’s site, and found an almost up-to-date and already packaged version on : http://debian.mcmillan.net.nz/debian/morgue/
    I downloaded 2 packages: davical and libawl, that I installed directly:

    sudo dpkg -i davical_1.1.0-1_all.deb libawl-php_0.52-1_all.deb
  • Database setup
    I’m not 100% sure that all tasks here are mandatory. I followed several recommendations from the web, and my knowledge of Postgres is poor, so…
    • Create needed users:
      createuser -h localhost -U postgres -W davical_dba
      createuser -h localhost -U postgres -W davical_app

      Answer questions and do not provide any password for those new Postgres accounts

    • Modify Postgres conf file
      Edit file pg_hba.conf file:

      sudo vi /etc/postgresql/9.1/main/pg_hba.conf

      and add those lines before others:

      # Install DaviCal
      local all all trust
      local davical davical_dba trust
      local davical davical_app trust
      host davical davical_app 127.0.0.1/32 trust

      Remember to restart Postgres:

      sudo /etc/init.d/postgresql reload
    • Setup database
      Use the provided script:

      sudo su postgres -c /usr/share/davical/dba/create-database.sh

      Note: at the end of the script, you are provided the password of the DAViCal “admin” user. Write it down carefully, you will need it to connect on the web interface later

    • Adjust Postgres conf file
      Remove/Comment the line providing trust to everyone (first line that you added before):

      sudo vi /etc/postgresql/9.1/main/pg_hba.conf

      Remember to restart Postgres:

      sudo /etc/init.d/postgresql reload
  • Apache setup
    There are various ways to setup Apache. One of them is to create a specific VirtualHost for DAViCal.
    The one I chose was simply to add an alias and a few setup configuration commands.
    I created a new file in /etc/apache2/conf.d, named davical.conf.
    Content:

    Alias /davical "/usr/share/davical/htdocs"
    
    	Options FollowSymLinks
    	DirectoryIndex index.php
    	
    		AddType application/x-httpd-php .php
    		php_flag magic_quotes_gpc Off
    		php_flag register_globals Off
    		php_admin_flag allow_url_fopen Off
    		php_value include_path .
    		php_value open_basedir 1
    		php_value error_reporting "E_ALL & ~E_NOTICE"
    	
    
    
    

    Here again, you need to restart Apache server:

    sudo /etc/init.d/apache2 reload
  • DAViCal configuration
    • Setup server configuration
      All is to be done in /etc/davical, by creating a single file (if you didn’t setup Virtualhosts and played with DNS aliases). Just edit a file named config.php.
      My file content is:

      <?php
      $c->pg_connect[] = "dbname=davical host=localhost user=davical_app";
      $c->system_name = "DAViCal CalDAV Server";
      $c->admin_email ='your_email_address@yourdomain';
      $c->local_tzid = 'Europe/Paris';
      $c->collections_always_exist = false;
      $c->default_locale = "fr_FR";
      $c->domain_name = "your_public_server_name";
      

      Note that I’m hosting this service at home, behind an “Internet box”. Because of that, my computer name is not the name publicly available on the Internet. So, I used the “domain_name” parameter and set it up to my “Internet box” public DNS name.

    • Setup DAViCal data
      At this point, you should be able to access your DAViCal server web interface, using http://localhost/davical URL.
      Use the “admin” account (with the password provided by the DB installation script earlier).

      Now that you reached DAViCal admin web interface, you can create users, groups and resources.
      To put it in a nutshell, I did the following:

      • Created 2 users (one for my wife, one for me)
      • Created one group (“family”), and associated my wife account and mine to it. This simplifies common permissions management (as I will add my children accounts later also)
      • Created one resource (“common”)
      • Granted “Read/Write” permissions on resource “common” to the group “family”. Like this, my wife and myself are fully owner of the “common” calendar
      • Granted “Read” permissions on my account calendar to my wife, and vice-versa. This allows us to see each other agenda with our own account

      I also created additional calendars (“collections”) on existing accounts, but that’s the same story…

Calendar usage

The beauty of this solution is that CalDAV is widely supported on several devices/softwares.
It is available on iPhone, on Android, as well as on several tools on Windows and on Linux.
Unfortunately, it is not available on WebOS… :-(
For now on, I need to use it with Thunderbird.

I’m using Thunderbird 15, with Lightning 1.7 (if you don’t have Lightning add-on… then you don’t have any calendar feature in Thunderbird ! Go and install it first 😉 )

In order to setup any of the calendars you have access to, simply create a new calendar in Lightning, type = CalDAV, and provide the URL according to the following rule:
http://<your_public_server_name>/davmail/caldav.php/<user>/<collection>
Replacing:

  • <your_public_server_name> with… your public server fully qualified domain name
  • <user> with your own “person” name, or someone else “person” name. It can even be a “resource” name if you created one as I did
  • <collection> with the “collection” calendar name. By default, when you create a “person” or a “resource”, a default calendar “collection” is created. Its name is “calendar”. But you may have additional calendars by creating new “collections”

This is what you can expect:

Address book usage

Here again, I’m going to use CardDAV protocol with Thunderbird.
It works on other software/devices, but Thunderbird is currently not supporting CardDAV protocol by default ! :-(
When you open your Address Book application from TB, you cannot request creation of any “remote book”.

The solution I found is to use a special add-on : SOGo Connector Thunderbird extension
Once installed, you are granted an additional menu in the Address Book application. Go to File -> New -> Remote Address Book. You can now provide the DAViCal address book URL.
Syntax is the same as for calendars:
http://<your_public_server_name>/davmail/caldav.php/<user>/<collection>
Replacing:

  • <your_public_server_name> with… your public server fully qualified domain name
  • <user> with your own “person” name, or someone else “person” name. It can even be a “resource” name if you created one as I did
  • <collection> with the “collection” Address Book name. By default, when you create a “person” or a “resource”, a default Address Book “collection” is created. Its name is “addresses”. But you may have additional Address Books by creating new “collections”

Not a lot to say here, this is quite straight forward.
You can create/delete any contact in this Address Book.
You can also (and I used it intensively) move contacts from local Address Books to your remote ones…
Everything was ready to use in few seconds…

So far, I just noticed a small issue about synchronization. The Address Books didn’t seem to synchronize by default (or I didn’t wait longer enough during my tests). This is not really a problem, as you don’t modify your address book so often. And when you do so, you can always force synchronization, using the right-click menu option “Synchronize”…

Conclusion

I need to continue using those features to provide additional feedback.
Nevertheless, I’m already very satisfied with the result !
It solves one critical issue I had with Thunderbird (multiple instances => inconsistent address books).
It also provides an “home made” solution for both Calendars and Address Books, which is intellectually satisfying…

Let’s see how much efficient it is in the future !

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>