This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/modules/calendar/caldav.py is in tryton-modules-calendar 4.2.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import urlparse
import urllib
from string import atoi
import xml.dom.minidom
from pywebdav.lib import propfind
from pywebdav.lib.errors import DAV_NotFound, DAV_Error, DAV_Forbidden
from pywebdav.lib.utils import get_uriparentpath
from pywebdav.lib.constants import DAV_VERSION_1, DAV_VERSION_2
from trytond.modules.webdav.protocol import TrytonDAVInterface, LOCAL, \
        WebDAVAuthRequestHandler
from trytond.pool import Pool
from trytond.transaction import Transaction

domimpl = xml.dom.minidom.getDOMImplementation()

TrytonDAVInterface.PROPS['urn:ietf:params:xml:ns:caldav'] = (
    'calendar-description',
    'calendar-data',
    'calendar-home-set',
    'calendar-user-address-set',
    'schedule-inbox-URL',
    'schedule-outbox-URL',
    )
TrytonDAVInterface.PROPS['DAV:'] = tuple(list(TrytonDAVInterface.PROPS['DAV:'])
    + ['principal-collection-set'])
TrytonDAVInterface.M_NS['urn:ietf:params:xml:ns:caldav'] = '_get_caldav'
DAV_VERSION_1['version'] += ',calendar-access,calendar-schedule'
DAV_VERSION_2['version'] += ',calendar-access,calendar-schedule'

_mk_prop_response = propfind.PROPFIND.mk_prop_response


def mk_prop_response(self, uri, good_props, bad_props, doc):
    res = _mk_prop_response(self, uri, good_props, bad_props, doc)
    parent_uri = get_uriparentpath(uri and uri.strip('/') or '')
    if not parent_uri:
        return res
    dbname, parent_uri = TrytonDAVInterface.get_dburi(parent_uri)
    if parent_uri in ('Calendars', 'Calendars/'):
        ad = doc.createElement('calendar')
        ad.setAttribute('xmlns', 'urn:ietf:params:xml:ns:caldav')
        # Disable groupdav attribute for iPhone
        # vc = doc.createElement('vevent-collection')
        # vc.setAttribute('xmlns', 'http://groupdav.org/')
        cols = res.getElementsByTagName('D:collection')
        if cols:
            cols[0].parentNode.appendChild(ad)
            # cols[0].parentNode.appendChild(vc)
    return res

propfind.PROPFIND.mk_prop_response = mk_prop_response


def _get_caldav_calendar_description(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_calendar_description', None):
        raise DAV_NotFound
    try:
        res = Collection.get_calendar_description(dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    return res

TrytonDAVInterface._get_caldav_calendar_description = \
    _get_caldav_calendar_description


def _get_caldav_calendar_data(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_calendar_data', None):
        raise DAV_NotFound
    try:
        res = Collection.get_calendar_data(dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    return res

TrytonDAVInterface._get_caldav_calendar_data = _get_caldav_calendar_data


def _get_caldav_calendar_home_set(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_calendar_home_set', None):
        raise DAV_NotFound
    try:
        res = Collection.get_calendar_home_set(dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    uparts = list(urlparse.urlsplit(uri))
    uparts[2] = urllib.quote(dbname + res)
    doc = domimpl.createDocument(None, 'href', None)
    href = doc.documentElement
    href.tagName = 'D:href'
    # iPhone doesn't handle "http" in href
    # huri = doc.createTextNode(urlparse.urlunsplit(uparts))
    huri = doc.createTextNode(urllib.quote('/' + dbname + res))
    href.appendChild(huri)
    return href

TrytonDAVInterface._get_caldav_calendar_home_set = \
    _get_caldav_calendar_home_set


def _get_caldav_calendar_user_address_set(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_calendar_user_address_set', None):
        raise DAV_NotFound
    try:
        res = Collection.get_calendar_user_address_set(
            dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    doc = domimpl.createDocument(None, 'href', None)
    href = doc.documentElement
    href.tagName = 'D:href'
    huri = doc.createTextNode('MAILTO:' + res)
    href.appendChild(huri)
    return href

TrytonDAVInterface._get_caldav_calendar_user_address_set = \
    _get_caldav_calendar_user_address_set


def _get_caldav_schedule_inbox_URL(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_schedule_inbox_URL', None):
        raise DAV_NotFound
    try:
        res = Collection.get_schedule_inbox_URL(dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    uparts = list(urlparse.urlsplit(uri))
    uparts[2] = urllib.quote(dbname + res)
    doc = domimpl.createDocument(None, 'href', None)
    href = doc.documentElement
    href.tagName = 'D:href'
    huri = doc.createTextNode(urlparse.urlunsplit(uparts))
    href.appendChild(huri)
    return href

TrytonDAVInterface._get_caldav_schedule_inbox_URL = \
    _get_caldav_schedule_inbox_URL


def _get_caldav_schedule_outbox_URL(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_NotFound
    pool = Pool(Transaction().database.name)
    try:
        Collection = pool.get('webdav.collection')
    except KeyError:
        raise DAV_NotFound
    if not getattr(Collection, 'get_schedule_outbox_URL', None):
        raise DAV_NotFound
    try:
        res = Collection.get_schedule_outbox_URL(dburi, cache=LOCAL.cache)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    uparts = list(urlparse.urlsplit(uri))
    uparts[2] = urllib.quote(dbname + res)
    doc = domimpl.createDocument(None, 'href', None)
    href = doc.documentElement
    href.tagName = 'D:href'
    huri = doc.createTextNode(urlparse.urlunsplit(uparts))
    href.appendChild(huri)
    return href

TrytonDAVInterface._get_caldav_schedule_outbox_URL = \
    _get_caldav_schedule_outbox_URL

_prev_get_dav_principal_collection_set = hasattr(TrytonDAVInterface,
        '_get_dav_principal_collection_set') and \
                TrytonDAVInterface._get_dav_principal_collection_set or None


def _get_dav_principal_collection_set(self, uri):
    dbname, dburi = self._get_dburi(uri)
    if dburi.startswith('Calendars'):
        uparts = list(urlparse.urlsplit(uri))
        uparts[2] = urllib.quote(dbname + '/Calendars/')
        doc = domimpl.createDocument(None, 'href', None)
        href = doc.documentElement
        href.tagName = 'D:href'
        huri = doc.createTextNode(urlparse.urlunsplit(uparts))
        href.appendChild(huri)
        return href
    if _prev_get_dav_principal_collection_set:
        return _prev_get_dav_principal_collection_set(self, uri)
    raise DAV_NotFound

TrytonDAVInterface._get_dav_principal_collection_set = \
    _get_dav_principal_collection_set


def _get_caldav_post(self, uri, body, contenttype=''):
    dbname, dburi = self._get_dburi(uri)
    if not dbname:
        raise DAV_Forbidden
    pool = Pool(Transaction().database.name)
    Calendar = pool.get('calendar.calendar')
    if not getattr(Calendar, 'post', None):
        raise DAV_NotFound
    try:
        res = Calendar.post(dburi, body)
    except DAV_Error, exception:
        self._log_exception(exception)
        raise
    except Exception, exception:
        self._log_exception(exception)
        raise DAV_Error(500)
    return res

TrytonDAVInterface._get_caldav_post = _get_caldav_post

_prev_do_POST = WebDAVAuthRequestHandler.do_POST


def do_POST(self):
    dc = self.IFACE_CLASS

    uri = urlparse.urljoin(self.get_baseuri(dc), self.path)
    uri = urllib.unquote(uri)

    dbname, dburi = TrytonDAVInterface.get_dburi(uri)
    if dburi.startswith('Calendars'):
        # read the body
        body = None
        if 'Content-Length' in self.headers:
            l = self.headers['Content-Length']
            body = self.rfile.read(atoi(l))
        ct = None
        if 'Content-Type' in self.headers:
            ct = self.headers['Content-Type']

        try:
            DATA = '%s\n' % dc._get_caldav_post(uri, body, ct)
        except DAV_Error, exception:
            ec, _ = exception
            return self.send_status(ec)
        self.send_body(DATA, 200, 'OK', 'OK')
        return
    return _prev_do_POST(self)

WebDAVAuthRequestHandler.do_POST = do_POST