Synology DS211

From Davical
Revision as of 03:17, 1 July 2014 by Fenton (talk | contribs) (Add formatting)
Jump to navigationJump to search

Synology DS 211 with DSM 5.0

From Daniel via the DAViCal-General mailing list:

Experiences with installing DAViCal on a Synology DS211 with DSM 5.0. My starting point was a script previously published by CyberLine on GitHub Gist ( Unfortunately, the script would not work out of the box, so here is what I had to do. Please note that the following is not meant to be run as a script. Rather, use it as copy-paste base for your terminal.

  • The installation of optware-devel is buggy because of a conflict between wget-ssl and wget. It is not possible to just uninstall wget, because it is needed for ipkg. So, first fetch the new wget-ssl, then remove the old and install the new:
ipkg remove wget && ipkg install wget-ssl_1.12-2_arm.ipk
  • Now, install system tools and second postgres
ipkg install perl perl-dbi make sed postgresql binutils busybox optware-devel
  • Patch postgres config for non conflicting if not exists
if [ "0" == $(egrep '^port = 5433$' /opt/var/pgsql/data/postgresql.conf | wc -l) ]; then
    echo "port = 5433" >> /opt/var/pgsql/data/postgresql.conf
  • Install needed host entries for DAViCal
if [ "0" == $(grep davical /opt/var/pgsql/data/pg_hba.conf | wc -l) ]; then
    echo -a "local   davical    davical_app   trust\nlocal   davical    davical_dba   trust" >> /opt/var/pgsql/data/pg_hba.conf
  • Start the installed postgres cluster
/opt/etc/init.d/S98postgresql start
  • Install needed perl packages.

Installation of CPAN does not work out of the box ("Can't locate CPAN/Meta/"). I solved this by:

cpan CPAN::Meta

This will draw in a number of other dependencies, just confirm all dialogs. This step takes a looong time!

  • Now, the following should work:
cpan -fi CPAN YAML
  • Build the perl package for davical installation
mkdir -p /usr/local/etc/davical
wget -O - | tar -xz -C /usr/local
cd /usr/local/DBD-Pg-2.19.3 && perl Makefile.PL LD=/opt/bin/ld && make && make install
  • Edit vhost file /opt/etc/apache2/conf.d/davical.vhost
        Alias /cal /opt/share/davical/htdocs
        <Directory /opt/share/davical/htdocs/>
                AllowOverride None

(i.e., no php directives, no virtual host!)

  • If you prefer a virtual host, create one in the DSM web interface linking to the sub directory "cal".
  • Check for needed open_basedir modification.

I did this manually in DSM web interface, adding this to the open_basedir directive:


This will then be in /etc/php/conf.d/user-settings.ini

  • Append davical.vhost to the user apache if not exists
if [ "0" == $(egrep '^Include /opt/etc/apache2/conf.d/davical.vhost' /etc/httpd/conf/httpd.conf-user | wc -l) ]; then
    echo "Include /opt/etc/apache2/conf.d/davical.vhost" >> /etc/httpd/conf/httpd.conf-user
  • Restart the user apache
/usr/syno/sbin/synoservicecfg --restart httpd-user
  • Install davical if not exists
if [ ! -e "/opt/share/davical" ]; then
    wget -O - | tar -xz -C /opt/share/
    mv /opt/share/davical-1.1.1/ /opt/share/davical/
    echo "davical installation exists. nothing to do."
  • Install needed "awl" if not exists
if [ ! -e "/opt/share/awl/" ]; then
    wget -O - | tar -xz -C /opt/share/
    mv /opt/share/awl-0.53/ /opt/share/awl/
    echo "awl installation exists. nothing to do.";
  • Install davical database if not exists
if [ "0" == $(psql -p 5433 -l template1 postgres | grep davical | wc -l) ]; then
    PGPORT=5433 PGUSER=postgres /opt/share/davical/dba/
  • Adjust connect string in DAViCal config (/opt/share/davical/config/example-config.php):
$c->pg_connect[] = "dbname=davical port=5433 user=davical_app host=localhost";
  • Soft link sample config files for each interface if not exists
for ADDR in $(ip -4  addr list | grep inet | awk '{print $2}' | awk -F '/' '{print $1}'); do
    if [ ! -e "/usr/local/etc/davical/$ADDR-conf.php" ]; then
        ln -s /opt/share/davical/config/example-config.php /usr/local/etc/davical/$ADDR-conf.php
  • Make also a softlink for possible DNS entries you want to use (.../your.domain.tld-conf.php).

Now, the installation should work. Point your browser to your diskstation IP/cal and complete DAViCal setup.

Using the DSM LDAP server for user management

Add the following to your config /opt/share/davical/config/example-config.php:

$c->authenticate_hook['call'] = 'LDAP_check';
$c->authenticate_hook['config'] = array(
    'host' => 'localhost', //host name of your LDAP Server
    'port' => '389',              //port
    'protocolVersion' => '3', //Version of LDAP protocol to use
    'baseDNUsers'=> 'cn=users,dc=xxx,dc=xxx', //where to look at valid user
    'filterUsers' => 'objectClass=inetOrgPerson', //filter which must validate a user according to RFC4515, i.e. surrounded by brackets
    'baseDNGroups' => 'cn=groups,dc=xxx,dc=xxx', //where to look for groups
    'filterGroups' => 'objectClass=posixGroup', //filter with same rules as filterUsers
    'mapping_field' => array("username" => "cn",
                             "modified" => "modifyTimestamp",
                             "fullname" => "gecos" ,
                             "email" =>"mail"
                             ), //used to create the user based on his ldap properties
    'group_mapping_field' => array("username" => "cn",
                             "updated" => "modifyTimestamp",
                             "fullname" => "description" ,
                             "members" =>"memberUid"
                             ), //used to create the group based on the ldap properties
    'format_updated'=> array('Y' => array(0,4),'m' => array(4,2),'d'=> array(6,2),'H' => array(8,2),'M'=>array(10,2),'S' => array(12,2)),
  $c->do_not_sync_from_ldap = array( 'admin' => true ); // do not affect admin account on ldap sync

Finally, in order to get LDAP to work, I had to edit the file /opt/share/davical/inc/Principal.php. The reason is that Postgres on my DiskStation is really old (v 8.2.13) and does not seem to support some type casting used on LDAP sync. Otherwise, on importing LDAP users, I get plenty of errors in the style "cannot write to database". So what I did was to simply comment out line 540:

// $param_name = 'cast('.$param_name.' as text)::BIT(24)';

I know this is really ugly but seemed to solve my issues.