Code Monkey home page Code Monkey logo

kdav's Introduction

kDAV - Kopano CalDAV & CardDAV

Implements CalDAV and CardDAV support for Kopano 8.6.2 or newer. Due to minimal PHP requirements of SabreDAV we recommend the use of PHP 7.0.

As DAV server SabreDAV is used.

License

kDAV is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation; either version 3 or (at your option) any later version.

Install

Basics

The described method is intended for development and testing. It's simplistic and aims to work fast and easy. How this code will be distributed to end users still needs to be defined.

You should have got a checkout/clone of the repository. The main dependencies are installed via Composer, to do that, first get composer itself. Installation instructions can be found here. It's recommend to install composer locally into the main kDAV directory. Then just do

# ./composer.phar install

kDAV configuration

All configs are handled in the config.php file. Adjust MAPI_SERVER to connect to your Kopano instance. The DAV_ROOT_URI parameter must match your webserver configuration, so that it points directly to the server.php file. The default value can be kept if kDAV runs in the root of the domain.

This is the simplest way to setup, running with Apache at port 443:

<VirtualHost *:443>
    DocumentRoot /your-kdav-working-directory/kdav
    ServerName develop.local

    <Directory /your-kdav-working-directory/kdav>
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine On
    # redirect well-known url http://sabre.io/dav/service-discovery/
    # (redirect may need to be done to the absolute external url)
    RewriteRule ^/.well-known/carddav$ / [R]
    RewriteRule ^/.well-known/caldav$ / [R]
    # This makes every request go to server.php
    RewriteRule ^/(.*)$ /server.php [L]

    # Output buffering needs to be off, to prevent high memory usage
    php_flag output_buffering off

    # This is also to prevent high memory usage
    php_flag always_populate_raw_post_data off

    # SabreDAV is not compatible with mbstring function overloading
    php_flag mbstring.func_overload off

    # set higher limits by default
    php_value memory_limit 256M
    php_value max_execution_time 259200

</VirtualHost>

Remember to enable mod_rewrite.

SSL is strongly recommended if you use real passwords.

Sync states

kDAV makes use of sqlite to manage sync states. Make sure that your php version has a module for it.

The default location for the sync states db is /var/lib/kopano/kdav/syncstate.db. This location should be writeable for the webserver process (e.g. www-data on Debian).

log4php configuration

kDAV uses Apache's log4php for logging. The configuration file is log4php.xml located in the root folder. The default log location is /var/log/kdav/kdav.log. It is required to create the log directory first:

mkdir -p /var/log/kdav

and grant permissions for the webserver user to write to that directory e.g.

chown -R www-data. /var/log/kdav

The default log4php configuration doesn't rotate the log file, so it might be a good idea to configure logrotate utility for kdav.log e.g by creating /etc/logrotate.d/kdav with the following content:

/var/log/kdav/*.log {
    size 1k
    create www-data www-data
    compress
    rotate 4
}

Access

As first step, point your webbrowser to:

http://develop.local/

Login with the username + password of a valid Kopano user.

If you don't get the Sabre/Dav overview, check your webserver error logfiles.

In your CalDAV client, set the server URL to

http://develop.local/calendars/<user>/Calendar/

The IP address can of course also be used.

Reporting and Development

Development is done at https://stash.kopano.io/projects/KC/repos/kdav/browse. If you have any feedback or questions please open up a topic at the Kopano forum.

PHPUnit tests

kDAV uses PHPUnit for unit tests. It's installed by composer. The executable binary is vendor/phpunit/phpunit/phpunit, so creating a symlink in the project's folder makes it easier:

ln -s vendor/phpunit/phpunit/phpunit phpunit

In order to run all the test execute:

./phpunit tests

In order to run a specific test pass a path to a specific class as parameter, e.g.:

./phpunit tests\KopanoCardDavBackendTest

Q & A

Q: Which version of Kopano do I need? A: It's recommended to install Kopano 8.6.2 (soon available from the pre-final repo) or a recent master

Q: Which version of PHP is needed? A: We recommend to use PHP7, but currently it also still works with PHP 5.6

Q: Will there be deb & rpm packages? A: Yes, once we have received enough feedback and kDAV is moving towards a final release we will also add packages.

Q: Which clients were tested against kDAV? A: We have focused our testing on Apple OS X and the builtin Calendar, Contact and Reminders apps. But we have already received positive feedback about Thunderbird/Lightning and Evolution as well.

Q: How do I configure clients for kDAV? A: From the Internet Account setting screen you have to choose Add Other Account... from where the options CalDAV Account and CardDAV Account become available. The option for the Advanced account type has to be chosen in both cases, since we want to specify the Server Address manually. For the Server Path a simple / can be given, as Apple Calendars will auto discover all the calendars of the given user automatically. If you ever want to link to a specific calendar from another client, the address kDAV is available from (in above example kdav.example.com) can also be opened in a webbrowser.

A picture is sometimes more worth than a thousand words: Calendar & Reminder setup:

  • 0_1525700254010_CalDAV1.PNG
  • 1_1525700254010_CalDAV2.PNG
  • 2_1525700254011_CalDAV3.PNG
  • 3_1525700254011_CalDAV4.PNG

Contact setup:

  • 0_1525700327110_CardDAV1.PNG
  • 1_1525700327111_CardDAV2.PNG
  • 2_1525700327111_CardDAV3.PNG

If you have configured kDAV in a subdir, e.g. domain.tld/kdav, the configuration is slightly different:

  • 4_20191003155143_CardDAV4.PNG

Make sure that the last part of the Server Path is equal to the User Name.

Q: That seems really hard to setup at clients. Isn't there any easier way? A: Yes, there is. You could setup kDAV for service discovery. Visit http://sabre.io/dav/service-discovery/ for more information.

Q: The initial sync has worked, but new contacts or changes to existing contacts aren't synced. A: Per default Contacts sync once per hour. It is possible however in Contacts' preferences to configure a different fetch period.

  • 5_20191003163719_CardDAV5.PNG

  • 6_20191003163824_CardDAV6.PNG

Known Issues

  • there were reports about syncing on Apple devices taking a very long time. (Tests with Thunderbird/Lighning showed a fast sync)

kdav's People

Contributors

bosim avatar fbartels avatar jelly avatar longsleep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kdav's Issues

kDAV - all day events are shown one day too early in calendar apps

Hi,

I am running Kopano server 11.0.2 together with the latest version of Kopano kdav.
My SabreDAV version is 3.2.2.

When I create an all day event, it is shown correctly in Microsoft Outlook as well as in Kopano WebApp.
It is also displayed correctly on my iPhone's calendar app.

But when I use Kopano kDAV, all day events are shown one day too early.
All other events are shown correctly.

I've already checked my Kopano server for timezone issues - Ubuntu, PHP, MySQL and Z-Push are all configured to use "Europe/Berlin".

Does anybody know how to solve this issue?

Thanks in advance,
David

kdav does not sync correctly - 500 internal Server Error

Hello all,

we installed kdav on us kopano Server on UCS. It works with accounts with a few contacts, but with the central address book with over 400 contacts, we get an error. But don’t know what is to do, or where is the issue. Here is the end of the Log:

https://darkdevil.osit.cc/index.php/s/zc2YJFyEiXaAxTr

On some vcard i get this error in the webbrowser:

<d:error><s:sabredav-version>3.2.2</s:sabredav-version><s:exception>Sabre\VObject\ParseException</s:exception><s:message>Invalid Mimedir file. Line starting at 10 did not follow iCalendar/vCard conventions</s:message></d:error>

This is the last one in the list. So i think there is the error. But how i can identify what contact this is?

Random calendars

After deployed I could see events in mac calendar from Kopano. But Kdav starts creating weird random calendars on its own. Even calendars that are not in Kopano Calendar:

10.97.150.37 - - [30/Nov/2021:09:56:16 +0000] "MKCALENDAR /kdav/calendars/user1/370C0949-B7D7-4E86-9402-9BA4ED79D159/ HTTP/1.1" 201 0
10.97.150.37 - - [30/Nov/2021:09:56:20 +0000] "MKCALENDAR /kdav/calendars/user1/1A15AE10-01B8-4748-A2CB-8E1BCD909DB6/ HTTP/1.1" 201 0
10.97.150.37 - - [30/Nov/2021:10:05:55 +0000] "MKCALENDAR /kdav/calendars/user1/D8D2BCC8-B903-4C3D-BFED-E4F77B86AAE2/ HTTP/1.1" 201 0
10.97.150.37 - - [30/Nov/2021:10:08:05 +0000] "MKCALENDAR /kdav/calendars/user1/981959DA-9ED8-4A29-A6A7-BDE6562EF7BC/ HTTP/1.1" 201 0

image

Also I found issues of events not being showed in mac calendar.

Also synchronisation is not working fine.

I see these errors in the logs:

30.11.2021 13:14:12 [ 5483] [ERROR]  dav KopanoDavBackend->Sync(): Unable to get value from token: 0000000000 - folderId: principals/user1:f7758d40f8f24f568ae2382ce4232d1f480200000000 - /usr/share/kopano-kdav/lib/KopanoCardDavBackend.php:375
30.11.2021 13:14:13 [ 5395] [ERROR]  dav KopanoDavBackend->Sync(): Unable to get value from token: 0000000000 - folderId: principals/user1:f7758d40f8f24f568ae2382ce4232d1f520200000000 - /usr/share/kopano-kdav/lib/KopanoCardDavBackend.php:375
30.11.2021 13:16:12 [ 5295] [ERROR]  dav KopanoDavBackend->Sync(): Unable to get value from token: 0000000000 - folderId: principals/user1:f7758d40f8f24f568ae2382ce4232d1f480200000000 - /usr/share/kopano-kdav/lib/KopanoCardDavBackend.php:375
30.11.2021 13:16:13 [ 5275] [ERROR]  dav KopanoDavBackend->Sync(): Unable to get value from token: 0000000000 - folderId: principals/user2:f7758d40f8f24f568ae2382ce4232d1f520200000000 - /usr/share/kopano-kdav/lib/KopanoCardDavBackend.php:375

I tried to manually refresh or refresh calendar every minute. It does not work.
I have to remove the account from Mac calendar and add it again in order to get the latest events.

sabredav doesn't work when developer mode is disabled

In an otherwise perfectly working setup, setting DEVELOPER_MODE to false breaks sabredav.
When the dav URL is accessed, the following is printed in the browser:

<d:error><s:sabredav-version>3.2.2</s:sabredav-version><s:exception>Sabre\DAV\Exception\NotImplemented</s:exception> <s:message>There was no plugin in the system that was willing to handle this GET method. Enable the Browser plugin to get a better result here.</s:message></d:error>

Shared calenders from other users not shown

I am not able to sync a calender from another user. I tried using .../calendars/otheruser but it ends up in my own calendars. The web ui to browse through what is avaiable in the dav api does not list the other user. So it seems not be considered. so far? It is a feature in the current ical implementation for kopano. So kdav cannot replace the "old" one yet.

kdav segfaults on contacts sync

Hi,

for some reason when syncing contacts it crashes with segfault:

(gdb) bt                                                                                                                                                                                                                                     
#0  0x00007fe330b8a0a0 in zend_fetch_resource () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                  
#1  0x00007fe328c666b9 in ?? () from /usr/lib/php/20170718/mapi.so                                                                                                                                                                           
#2  0x00007fe31d5685e4 in ?? () from /usr/lib/x86_64-linux-gnu/kopano/libkcclient.so                                                                                                                                                         
#3  0x00007fe31d56b5a0 in ?? () from /usr/lib/x86_64-linux-gnu/kopano/libkcclient.so                                                                                                                                                         
#4  0x00007fe328c8bfa2 in ?? () from /usr/lib/php/20170718/mapi.so                                                                                                                                                                           
#5  0x00007fe330c2407b in execute_ex () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                           
#6  0x00007fe330b63fee in zend_call_function () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                   
#7  0x00007fe330a9b504 in ?? () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                                   
#8  0x00007fe330c2407b in execute_ex () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                           
#9  0x00007fe330b63fee in zend_call_function () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                   
#10 0x00007fe330a9b504 in ?? () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                                   
#11 0x00007fe330c2407b in execute_ex () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                           
#12 0x00007fe330c259b7 in zend_execute () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                         
#13 0x00007fe330b745a2 in zend_execute_scripts () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                 
#14 0x00007fe330b10490 in php_execute_script () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                   
#15 0x00007fe330c27b12 in ?? () from /usr/lib/apache2/modules/libphp7.2.so                                                                                                                                                                   
b#16 0x00005615d7db0be0 in ap_run_handler ()                                                                                                                                                                                                 
#17 0x00005615d7db115d in ap_invoke_handler ()                                                                                                                                                                                               
#18 0x00005615d7dc80ec in ap_internal_redirect ()                                                                                                                                                                                            
#19 0x00007fe32c8f3f35 in ?? () from /usr/lib/apache2/modules/mod_rewrite.so                                                                                                                                                                 
#20 0x00005615d7db0be0 in ap_run_handler ()                                                                                                                                                                                                  
#21 0x00005615d7db115d in ap_invoke_handler ()                                                                                                                                                                                               
#22 0x00005615d7dc8d1b in ap_process_async_request ()                                                                                                                                                                                        
#23 0x00005615d7dc8ef0 in ap_process_request ()                                                                                                                                                                                              
#24 0x00005615d7dc513d in ?? ()                                                                                                                                                                                                              
#25 0x00005615d7dba9f0 in ap_run_process_connection ()                                                                                                                                                                                       
#26 0x00007fe331192831 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so                                                                                                                                                             
#27 0x00007fe331192b44 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so                                                                                                                                                             
#28 0x00007fe3311935b4 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so                                                                                                                                                             
#29 0x00005615d7d9419e in ap_run_mpm ()                                                                                                                                                                                                      
#30 0x00005615d7d8ca7b in main ()                                                                                                                                                                                                            

In kdav logs this also appears:
30.01.2019 13:03:28 [29492] [WARN ] error /var/www/html/kdav/lib/PHPWrapper.php:136 Use of undefined constant SYNC_E_IGNORE - assumed 'SYNC_E_IGNORE' (this will throw an Error in a future version of PHP) (2)

Ubuntu 18.04, php 7.2.10, kopano 8.7.80.529 & latest kdav.

accessing public folders

until now i havent found a way to make kdav work with my contacts in public folders.
any thougths on this? when will it be possible ?

thanks in advance

VCard does not handle multi line entries

The vcard api produces cards like these
BEGIN:VCARD
VERSION:3.0
PRODID:-//Kopano//libicalmapi 8.7.25//EN
N:;X U.
FN:X U.
ORG:Dr. X
TEL;TYPE=WORK:(0511) xxx xxx
ADR;TYPE=WORK:;;Sutelstr. xxx
30659 Hannover
UID:040000008200E00074C5B7101A82E0080000000080C5729AF2E9D801000000000000000001000000D0FA8F9481F447F7BB93FF61B3A0B9BE
NOTE:
REV:2022-10-27T10:55:19Z
END:VCARD

The linebreak for ADR;TYPE is wrong. Because the new line with 30659 is treated as a new vcard entry and causes an error, because it is unknown.
Same happens e.g. for NOTE where multi line entries maybe more common in germany.

The current solutions result not being able to sync contacts as long there is any contact with a multi line entry. The adresesses were actually broken because all of them were german and in Kopano everything was placed in the street field. That could be fixed by fixing the data. Contacts with notes could be fixed by deleting the note or remove line breaks. That is not a good solution.
There might be a use case for linebreaks in the street field in the future. Especially with non german adresses.

I found how multi line entries should be handled here mangstadt/ez-vcard#3

PDO doesn't recognise mysql string (SYNC_DB)

Trying to move to mysql and away from sqlite, I found that the current implementation doesn't work. The constructor in lib/KopaanoSyncStates.php does not recognise the PDO string, causing php-fpm to crashdump and webbrowsers to display a HTTP 500 / page not operational error.

The journal shows this when you try to access kdav:

Mai 19 02:14:01 mx1 systemd[1]: Started A high performance web server and a reverse proxy server.
Mai 19 02:14:16 mx1 nginx[1997]: 2019/05/19 02:14:16 [error] 1999#1999: *1 FastCGI sent in stderr: "PHP message: PHP Warning:  date(): Invalid date.timezone value 'Europe\Berlin', we selected the timezone 'UTC' for now. in /usr/share/webapps/kopano-kdav/vendor/apache/log4php/src/main/php/pattern/LoggerPatternConverterDate.php on line 74PHP message: PHP Warning:  date(): Invalid date.timezone value 'Europe\Berlin', we selected the timezone 'UTC' for now. in /usr/share/webapps/kopano-kdav/vendor/apache/log4php/src/main/php/pattern/LoggerPatternConverterDate.php on line 74PHP message: PHP Warning:  date(): Invalid date.timezone value 'Europe\Berlin', we selected the timezone 'UTC' for now. in /usr/share/webapps/kopano-kdav/vendor/apache/log4php/src/main/php/pattern/LoggerPatternConverterDate.php on line 74PHP message: PHP Warning:  date(): Invalid date.timezone value 'Europe\Berlin', we selected the timezone 'UTC' for now. in /usr/share/webapps/kopano-kdav/vendor/apache/log4php/src/main/php/pattern/LoggerPatternConverterDate.php on line 74PHP message: PHP Warning:  date(): Invalid date.timezone value 'Europe\Berlin', we selected the timezone 'UTC' for now. in /usr/share/webapps/kopano-kdav/vendor/apache/log4php/src/main/php/pattern/LoggerPatternConverterDate.php on line 74PHP message: PHP Fatal error:  Uncaught PDOException: could not find driver in /usr/share/webapps/kopano-kdav/lib/KopanoSyncState.php:45
Mai 19 02:14:16 mx1 nginx[1997]: Stack trace:
Mai 19 02:14:16 mx1 nginx[1997]: #0 /usr/share/webapps/kopano-kdav/lib/KopanoSyncState.php(45): PDO->__construct('"mysql:dbname=s...')
Mai 19 02:14:16 mx1 nginx[1997]: #1 /usr/share/webapps/kopano-kdav/lib/KopanoDavBackend.php(48): Kopano\DAV\KopanoSyncState->__construct(Object(Kopano\DAV\KLogger), '"mysql:dbname=s...')
Mai 19 02:14:16 mx1 nginx[1997]: #2 /usr/share/webapps/kopano-kdav/server.php(54): Kopano\DAV\KopanoDavBackend->__construct(Object(Kopano\DAV\KLogger))
Mai 19 02:14:16 mx1 nginx[1997]: #3 {main}
Mai 19 02:14:16 mx1 nginx[1997]:   thrown in /usr/share/webapps/kopano-kdav/lib/KopanoSyncState.php on line 45" while reading response header from upstream, client: 78.94.14.198, server: dav.maerz.cc, request: "GET /server.php HTTP/2.0", upstream: "fastcgi://unix:/run/php-fpm/webapp.sock

When the error is thrown, config.php reads this:

define('SYNC_DB', '"mysql:dbname=sabredav","user","pass"');

I have also tried this with the same result:

define('SYNC_DB', "'mysql:dbname=sabredav;host=localhost', 'user', 'pass'");
define('SYNC_DB', "mysql:dbname=sabredav;unix_socket=/run/mysqld/mysqld.sock");

The ugly workaround is to hard-code $dbstring in lib/KopanoSyncState.php with the same string as shown above - working perfectly fine:

    public function __construct($logger, $dbstring) {
        $this->logger = $logger;
        $this->logger->trace("Using db %s", $dbstring);
        // $this->db = new \PDO($dbstring);
        $this->db = new \PDO('mysql:dbname=sabredav','user','pass');

Which is also documented upstream in the official sabredav documentation found at:
http://sabre.io/dav/authentication/

Encoding Error In CardDav

If you create change or an Contact via CardDav The encoding gets mangeled.
(UTF-8 interpreted as iso-8859-1 ?)
If you change the contact in the Kopano Webgui the carracters arrive corrrectly at the CardDav clients.

Tested with:
Thunderbid + CardBook
Win10

Examples:
Expected
ÄÜÖ -> Ã�Ã�Ã�
Comércio -> Comércio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.