summaryrefslogtreecommitdiffstats
path: root/pykolab/plugins/roundcubedb/__init__.py
blob: a7f289e291351da70169b7a6c3f4b98f67579f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
# Copyright 2014 Kolab Systems AG (http://www.kolabsys.com)
#
# Thomas Bruederli (Kolab Systems) <bruederli(a)kolabsys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 or, at your option, any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import os
import pykolab
import subprocess

from pykolab.translate import _

log = pykolab.getLogger('pykolab.plugins.roundcubedb')
conf = pykolab.getConf()

class KolabRoundcubedb(object):
    """
        Pykolab plugin to update Roundcube's database on Kolab users db changes
    """

    def __init__(self):
        pass

    def add_options(self, *args,  **kw):
        pass

    def user_delete(self, *args, **kw):
        """
            The arguments passed to the 'user_delete' hook:

            user - full user entry from LDAP
            domain - domain name
        """

        log.debug(_("user_delete: %r") % (kw), level=9)

        if os.path.isdir('/usr/share/roundcubemail'):
            rcpath = '/usr/share/roundcubemail/'
        elif os.path.isdir('/usr/share/roundcube'):
            rcpath = '/usr/share/roundcube/'
        else:
            log.error(_("Roundcube installation path not found."))
            return False

        result_attribute = conf.get('cyrus-sasl', 'result_attribute')

        # execute Roundcube's bin/deluser.sh script to do the work
        if kw.has_key('user') and kw['user'].has_key(result_attribute) and os.path.exists(rcpath + 'bin/deluser.sh'):
            proc = subprocess.Popen([ 'sudo -u apache', rcpath + 'bin/deluser.sh', kw['user'][result_attribute] ], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
            procout, procerr = proc.communicate()
            if proc.returncode != 0:
                log.error(rcpath + "bin/deluser.sh exited with error %d: %r" % (proc.returncode, procerr))
            else:
                log.debug(rcpath + "bin/deluser.sh success: %r; %r" % (procout, procerr), level=9)

        return None