How to customize Zentyal
(hooks, templates and LDAP)

Zentyal Summit 2011

12th November
Carlos Pérez-Aradros <cperez@zentyal.com>

   Linux small business server
Linux small business server




Zentyal...
     Easy to use
     Good integration
     Versatile



...but sometimes you need
     Some specific customization
     Integration with external apps




       www.zentyal.com                      © eBox Technologies S.L. 2011
Linux small business server




Customization options
   Modify source code
      Add new logic or functionality
      Breaks on upgrade      Upstream!

   Templates
      Change configuration files written by Zentyal
   Hooks
      Define custom actions (scripts) on module events
   LDAP
      Integrate external applications



       www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




Customization options
   Modify source code
      Add new logic or functionality
      Breaks on upgrade
   Templates
      Change configuration files written by Zentyal
   Hooks
      Define custom actions (scripts) on module events
   LDAP
      Integrate external applications



       www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




Templates (I)


   Zentyal uses templates to write system configurations files



   Modify templates to:

      Adjust parameters to adapt Zentyal to your requirements

      Add/remove configuration options




       www.zentyal.com                                  © eBox Technologies S.L. 2011
Linux small business server




Templates (II)
   Mason as template processor




       www.zentyal.com                 © eBox Technologies S.L. 2011
Linux small business server




Templates (III)



   Default templates location:
      /usr/share/zentyal/stubs/<module>/<template>.mas
   Custom templates:
      /etc/zentyal/stubs/<module>/<template>.mas




       www.zentyal.com                             © eBox Technologies S.L. 2011
Linux small business server




Templates (IV)
Default stub
/usr/share/zentyal/stubs/network/resolv.conf.mas

        T


                                                         Conf file
                                                         /etc/resolv.conf
        T



Custom stub
/etc/zentyal/stubs/network/resolv.conf.mas


            www.zentyal.com                              © eBox Technologies S.L. 2011
Linux small business server




Templates example: Samba hidden folders
   We want to add a hidden folder in File Sharing module (samba)
   Zentyal GUI doesn't allow this:




       www.zentyal.com                                 © eBox Technologies S.L. 2011
Linux small business server




Templates example: Samba hidden folders
   Copy and edit default template:

   mkdir -p /etc/zentyal/stubs/samba/

   cp /usr/share/zentyal/stubs/samba/smb.conf.mas /etc/zentyal/stubs/samba/




   Write custom configuration



        www.zentyal.com                                         © eBox Technologies S.L. 2011
Linux small business server




Customization options
   Modify source code
      Add new logic or functionality
      Breaks on upgrade
   Templates
      Change configuration files written by Zentyal
   Hooks
      Define custom actions (scripts) on module events
   LDAP
      Integrate external applications



       www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




Hooks (I)
   Execute actions (scripts) during Zentyal save changes process



   Create hook scripts to:

      Watch for changes in any module

      Add custom scripts before/after module actions




       www.zentyal.com                                  © eBox Technologies S.L. 2011
Linux small business server




Hooks (II): paths

   Before saving changes     /etc/zentyal/pre-save/


   After saving changes    /etc/zentyal/post-save/




   /etc/zentyal/hooks/

      Before saving module configuration <module>.presetconf
      After saving module configuration <module>.postsetconf
      Before restarting the service       <module>.preservice


      After restarting the service <module>.postservice



       www.zentyal.com                                                © eBox Technologies S.L. 2011
Linux small business server



                           one time     for each module
Hooks (III)
                           pre-save
                                             .presetconf

                                           Write conf files

                                             .postsetconf


                                             .preservice

                                         Restart daemons

                                             .postservice
       hook
                           post-save

   Zentyal action

         www.zentyal.com                     © eBox Technologies S.L. 2011
Linux small business server




Hooks Example: Firewall


   We want to block traffic from a specific country (using GeoIP)
   Zentyal GUI does not allow this kind of rules


   If we add the rule by hand:
      Firewall module restart will delete it


   Solution:
      Add the rule after firewall restart (postservice hook)


       www.zentyal.com                                   © eBox Technologies S.L. 2011
Linux small business server




Hooks Example: Firewall
   Setup GeoIP
   sudo apt-get install module-assistant

   sudo module-assistant a-i xtables-addons



   wget http://sourceforge.net/projects/xtables-
   addons/files/Xtables-addons/1.38/xtables-addons-1.38.tar.xz



   sudo ./xt_geoip_dl

   sudo ./xt_geoip_build *.csv

   sudo mkdir /var/geoip && sudo cp -r LE /var/geoip




       www.zentyal.com                                   © eBox Technologies S.L. 2011
Linux small business server




Hooks Example: Firewall
   Create the hook


                 /etc/zentyal/hooks/firewall.postservice
   #!/bin/sh
   sudo iptables -I INPUT -m geoip --src-cc KP -j ACCEPT




   Don't forget to make it executable!
      chmod +x /etc/zentyal/hooks/firewall.postservice




        www.zentyal.com                                 © eBox Technologies S.L. 2011
Linux small business server




Hooks: Future (3.0)
   Users operations hooks
      create
      modify
      delete


   Backup
      pre-backup
      post-backup




       www.zentyal.com            © eBox Technologies S.L. 2011
Linux small business server




Customization options
   Modify source code
      Add new logic or functionality
      Breaks on upgrade
   Templates
      Change configuration files written by Zentyal
   Hooks
      Define custom actions (scripts) on module events
   LDAP
      Integrate external applications



       www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration (I)

   Zentyal provides great Users and Groups management



   LDAP integration:

      Central point for users management

      Centralized authentication

      Distributed: master / slave architecture




       www.zentyal.com                                   © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration (II)
   Integrate third apps with Zentyal Users and Groups




       www.zentyal.com                                        © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration (II): settings
   Users and Groups → LDAP Settings




   Server: ldap://localhost:389/ (port 1389 in slaves)
   Users DN: ou=Users,<basedn>
   Groups DN: ou=Groups,<basedn>

        www.zentyal.com                                        © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration (III): filters
uid=cperez,ou=Users,dc=zentyal,dc=com
uid: cperez
                                        Base DN: ou=Users,dc=zentyal,dc=com
loginShell: /usr/sbin/nologin
uidNumber: 2002
                                        Filter: (uid=*)
gidNumber: 1901
homeDirectory: /home/cperez
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: passwordHolder                cn=developers,ou=Groups,dc=zentyal,dc=com
givenName: Carlos                          cn: developers
userPassword: {SHA}...                     gidNumber: 2005
eboxSha1Password: {SHA}...                 objectClass: posixGroup

eboxMd5Password: {MD5}...                  memberUid: cperez

eboxDigestPassword: {MD5}...               memberUid: jsalamero

eboxRealmPassword: {MD5}...                memberUid: ejhernandez

cn:; Carlos Pérez-Aradros Herce            memberUid: jacalvo
                                           memberUid: jamor
sn:; Pérez-Aradros Herce
                                           ...

              www.zentyal.com                                           © eBox Technologies S.L. 2011
                                                                           c
Linux small business server




LDAP Integration example: Wordpress




      www.zentyal.com                   © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration example: Wordpress
   Look for a LDAP Auth backend




       www.zentyal.com                  © eBox Technologies S.L. 2011
Linux small business server




LDAP Integration example: Wordpress




      www.zentyal.com                   © eBox Technologies S.L. 2011
Linux small business server




In summary
   Modify source code
      Add new logic or functionality
      Breaks on upgrade      Upstream!

   Templates
      Change configuration files written by Zentyal
   Hooks
      Define custom actions (scripts) on module events
   LDAP
      Integrate external applications



       www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




Get help
  Zentyal Support Forum
        http://forum.zentyal.org
  Users and Developers mailing lists
        https://lists.zentyal.com/cgi-bin/mailman/listinfo/zentyal-devel
        https://lists.zentyal.com/cgi-bin/mailman/listinfo/zentyal-users
  IRC
        #zentyal at freenode.net
  Official support and training
        http://www.zentyal.com/en/services/              Contribute!


           www.zentyal.com                                      © eBox Technologies S.L. 2011
Linux small business server




Further reading...
   Zentyal Documentation - Advanced Service Customisation
      http://doc.zentyal.org/en/develop.html
   Mason Documentation (Templates)
      http://www.masonhq.com/docs/manual/Devel.html
   xtables addons
      http://xtables-addons.sourceforge.net/
   Openldap filters doc
      http://www.zytrax.com/books/ldap/apa/search.html




       www.zentyal.com                               © eBox Technologies S.L. 2011
Linux small business server




www.zentyal.com
                  ?         © eBox Technologies S.L. 2011

Zentyal Customization (templates, hooks, LDAP)

  • 1.
    How to customizeZentyal (hooks, templates and LDAP) Zentyal Summit 2011 12th November Carlos Pérez-Aradros <cperez@zentyal.com> Linux small business server
  • 2.
    Linux small businessserver Zentyal... Easy to use Good integration Versatile ...but sometimes you need Some specific customization Integration with external apps www.zentyal.com © eBox Technologies S.L. 2011
  • 3.
    Linux small businessserver Customization options Modify source code Add new logic or functionality Breaks on upgrade Upstream! Templates Change configuration files written by Zentyal Hooks Define custom actions (scripts) on module events LDAP Integrate external applications www.zentyal.com © eBox Technologies S.L. 2011
  • 4.
    Linux small businessserver Customization options Modify source code Add new logic or functionality Breaks on upgrade Templates Change configuration files written by Zentyal Hooks Define custom actions (scripts) on module events LDAP Integrate external applications www.zentyal.com © eBox Technologies S.L. 2011
  • 5.
    Linux small businessserver Templates (I) Zentyal uses templates to write system configurations files Modify templates to: Adjust parameters to adapt Zentyal to your requirements Add/remove configuration options www.zentyal.com © eBox Technologies S.L. 2011
  • 6.
    Linux small businessserver Templates (II) Mason as template processor www.zentyal.com © eBox Technologies S.L. 2011
  • 7.
    Linux small businessserver Templates (III) Default templates location: /usr/share/zentyal/stubs/<module>/<template>.mas Custom templates: /etc/zentyal/stubs/<module>/<template>.mas www.zentyal.com © eBox Technologies S.L. 2011
  • 8.
    Linux small businessserver Templates (IV) Default stub /usr/share/zentyal/stubs/network/resolv.conf.mas T Conf file /etc/resolv.conf T Custom stub /etc/zentyal/stubs/network/resolv.conf.mas www.zentyal.com © eBox Technologies S.L. 2011
  • 9.
    Linux small businessserver Templates example: Samba hidden folders We want to add a hidden folder in File Sharing module (samba) Zentyal GUI doesn't allow this: www.zentyal.com © eBox Technologies S.L. 2011
  • 10.
    Linux small businessserver Templates example: Samba hidden folders Copy and edit default template: mkdir -p /etc/zentyal/stubs/samba/ cp /usr/share/zentyal/stubs/samba/smb.conf.mas /etc/zentyal/stubs/samba/ Write custom configuration www.zentyal.com © eBox Technologies S.L. 2011
  • 11.
    Linux small businessserver Customization options Modify source code Add new logic or functionality Breaks on upgrade Templates Change configuration files written by Zentyal Hooks Define custom actions (scripts) on module events LDAP Integrate external applications www.zentyal.com © eBox Technologies S.L. 2011
  • 12.
    Linux small businessserver Hooks (I) Execute actions (scripts) during Zentyal save changes process Create hook scripts to: Watch for changes in any module Add custom scripts before/after module actions www.zentyal.com © eBox Technologies S.L. 2011
  • 13.
    Linux small businessserver Hooks (II): paths Before saving changes /etc/zentyal/pre-save/ After saving changes /etc/zentyal/post-save/ /etc/zentyal/hooks/ Before saving module configuration <module>.presetconf After saving module configuration <module>.postsetconf Before restarting the service <module>.preservice After restarting the service <module>.postservice www.zentyal.com © eBox Technologies S.L. 2011
  • 14.
    Linux small businessserver one time for each module Hooks (III) pre-save .presetconf Write conf files .postsetconf .preservice Restart daemons .postservice hook post-save Zentyal action www.zentyal.com © eBox Technologies S.L. 2011
  • 15.
    Linux small businessserver Hooks Example: Firewall We want to block traffic from a specific country (using GeoIP) Zentyal GUI does not allow this kind of rules If we add the rule by hand: Firewall module restart will delete it Solution: Add the rule after firewall restart (postservice hook) www.zentyal.com © eBox Technologies S.L. 2011
  • 16.
    Linux small businessserver Hooks Example: Firewall Setup GeoIP sudo apt-get install module-assistant sudo module-assistant a-i xtables-addons wget http://sourceforge.net/projects/xtables- addons/files/Xtables-addons/1.38/xtables-addons-1.38.tar.xz sudo ./xt_geoip_dl sudo ./xt_geoip_build *.csv sudo mkdir /var/geoip && sudo cp -r LE /var/geoip www.zentyal.com © eBox Technologies S.L. 2011
  • 17.
    Linux small businessserver Hooks Example: Firewall Create the hook /etc/zentyal/hooks/firewall.postservice #!/bin/sh sudo iptables -I INPUT -m geoip --src-cc KP -j ACCEPT Don't forget to make it executable! chmod +x /etc/zentyal/hooks/firewall.postservice www.zentyal.com © eBox Technologies S.L. 2011
  • 18.
    Linux small businessserver Hooks: Future (3.0) Users operations hooks create modify delete Backup pre-backup post-backup www.zentyal.com © eBox Technologies S.L. 2011
  • 19.
    Linux small businessserver Customization options Modify source code Add new logic or functionality Breaks on upgrade Templates Change configuration files written by Zentyal Hooks Define custom actions (scripts) on module events LDAP Integrate external applications www.zentyal.com © eBox Technologies S.L. 2011
  • 20.
    Linux small businessserver LDAP Integration (I) Zentyal provides great Users and Groups management LDAP integration: Central point for users management Centralized authentication Distributed: master / slave architecture www.zentyal.com © eBox Technologies S.L. 2011
  • 21.
    Linux small businessserver LDAP Integration (II) Integrate third apps with Zentyal Users and Groups www.zentyal.com © eBox Technologies S.L. 2011
  • 22.
    Linux small businessserver LDAP Integration (II): settings Users and Groups → LDAP Settings Server: ldap://localhost:389/ (port 1389 in slaves) Users DN: ou=Users,<basedn> Groups DN: ou=Groups,<basedn> www.zentyal.com © eBox Technologies S.L. 2011
  • 23.
    Linux small businessserver LDAP Integration (III): filters uid=cperez,ou=Users,dc=zentyal,dc=com uid: cperez Base DN: ou=Users,dc=zentyal,dc=com loginShell: /usr/sbin/nologin uidNumber: 2002 Filter: (uid=*) gidNumber: 1901 homeDirectory: /home/cperez objectClass: inetOrgPerson objectClass: posixAccount objectClass: passwordHolder cn=developers,ou=Groups,dc=zentyal,dc=com givenName: Carlos cn: developers userPassword: {SHA}... gidNumber: 2005 eboxSha1Password: {SHA}... objectClass: posixGroup eboxMd5Password: {MD5}... memberUid: cperez eboxDigestPassword: {MD5}... memberUid: jsalamero eboxRealmPassword: {MD5}... memberUid: ejhernandez cn:; Carlos Pérez-Aradros Herce memberUid: jacalvo memberUid: jamor sn:; Pérez-Aradros Herce ... www.zentyal.com © eBox Technologies S.L. 2011 c
  • 24.
    Linux small businessserver LDAP Integration example: Wordpress www.zentyal.com © eBox Technologies S.L. 2011
  • 25.
    Linux small businessserver LDAP Integration example: Wordpress Look for a LDAP Auth backend www.zentyal.com © eBox Technologies S.L. 2011
  • 26.
    Linux small businessserver LDAP Integration example: Wordpress www.zentyal.com © eBox Technologies S.L. 2011
  • 27.
    Linux small businessserver In summary Modify source code Add new logic or functionality Breaks on upgrade Upstream! Templates Change configuration files written by Zentyal Hooks Define custom actions (scripts) on module events LDAP Integrate external applications www.zentyal.com © eBox Technologies S.L. 2011
  • 28.
    Linux small businessserver Get help Zentyal Support Forum http://forum.zentyal.org Users and Developers mailing lists https://lists.zentyal.com/cgi-bin/mailman/listinfo/zentyal-devel https://lists.zentyal.com/cgi-bin/mailman/listinfo/zentyal-users IRC #zentyal at freenode.net Official support and training http://www.zentyal.com/en/services/ Contribute! www.zentyal.com © eBox Technologies S.L. 2011
  • 29.
    Linux small businessserver Further reading... Zentyal Documentation - Advanced Service Customisation http://doc.zentyal.org/en/develop.html Mason Documentation (Templates) http://www.masonhq.com/docs/manual/Devel.html xtables addons http://xtables-addons.sourceforge.net/ Openldap filters doc http://www.zytrax.com/books/ldap/apa/search.html www.zentyal.com © eBox Technologies S.L. 2011
  • 30.
    Linux small businessserver www.zentyal.com ? © eBox Technologies S.L. 2011