Example #1
0
 def get(self, environ, base_prefix, path, user):
     try:
         filesystem_path = storage.path_to_filesystem(
             self.folder, path[len("/.web"):])
     except ValueError as e:
         self.logger.debug("Web content with unsafe path %r requested: %s",
                           path,
                           e,
                           exc_info=True)
         return NOT_FOUND
     if os.path.isdir(filesystem_path) and not path.endswith("/"):
         location = posixpath.basename(path) + "/"
         return (client.FOUND, {
             "Location": location,
             "Content-Type": "text/plain"
         }, "Redirected to %s" % location)
     if os.path.isdir(filesystem_path):
         filesystem_path = os.path.join(filesystem_path, "index.html")
     if not os.path.isfile(filesystem_path):
         return NOT_FOUND
     content_type = MIMETYPES.get(
         os.path.splitext(filesystem_path)[1].lower(), FALLBACK_MIMETYPE)
     with open(filesystem_path, "rb") as f:
         answer = f.read()
         last_modified = time.strftime(
             "%a, %d %b %Y %H:%M:%S GMT",
             time.gmtime(os.fstat(f.fileno()).st_mtime))
     headers = {
         "Content-Type": content_type,
         "Last-Modified": last_modified
     }
     return client.OK, headers, answer
Example #2
0
 def get(self, environ, base_prefix, path, user):
     try:
         filesystem_path = storage.path_to_filesystem(
             self.folder, path[len("/.web"):])
     except ValueError as e:
         self.logger.debug("Web content with unsafe path %r requested: %s",
                           path, e, exc_info=True)
         return NOT_FOUND
     if os.path.isdir(filesystem_path) and not path.endswith("/"):
         location = posixpath.basename(path) + "/"
         return (client.FOUND,
                 {"Location": location, "Content-Type": "text/plain"},
                 "Redirected to %s" % location)
     if os.path.isdir(filesystem_path):
         filesystem_path = os.path.join(filesystem_path, "index.html")
     if not os.path.isfile(filesystem_path):
         return NOT_FOUND
     content_type = MIMETYPES.get(
         os.path.splitext(filesystem_path)[1].lower(), FALLBACK_MIMETYPE)
     with open(filesystem_path, "rb") as f:
         answer = f.read()
         last_modified = time.strftime(
             "%a, %d %b %Y %H:%M:%S GMT",
             time.gmtime(os.fstat(f.fileno()).st_mtime))
     headers = {
         "Content-Type": content_type,
         "Last-Modified": last_modified}
     return client.OK, headers, answer
Example #3
0
 def get(self, environ, base_prefix, path, user):
     if not path.startswith("/.web/infcloud/") and path != "/.web/infcloud":
         status, headers, answer = self.base_get(environ, base_prefix, path,
                                                 user)
         if status == client.OK and path in ("/.web/", "/.web/index.html"):
             answer = answer.replace(
                 b"""\
     <nav>
         <ul>""", b"""\
     <nav>
         <ul>
             <li><a href="infcloud">InfCloud</a></li>""")
         return status, headers, answer
     try:
         filesystem_path = storage.path_to_filesystem(
             self.infcloud_folder, path[len("/.web/infcloud"):])
     except ValueError as e:
         self.logger.debug("Web content with unsafe path %r requested: %s",
                           path,
                           e,
                           exc_info=True)
         return NOT_FOUND
     if os.path.isdir(filesystem_path) and not path.endswith("/"):
         location = posixpath.basename(path) + "/"
         return (client.SEE_OTHER, {
             "Location": location,
             "Content-Type": "text/plain"
         }, "Redirected to %s" % location)
     if os.path.isdir(filesystem_path):
         filesystem_path = os.path.join(filesystem_path, "index.html")
     if not os.path.isfile(filesystem_path):
         return NOT_FOUND
     content_type = MIMETYPES.get(
         os.path.splitext(filesystem_path)[1].lower(), FALLBACK_MIMETYPE)
     with open(filesystem_path, "rb") as f:
         answer = f.read()
         last_modified = time.strftime(
             "%a, %d %b %Y %H:%M:%S GMT",
             time.gmtime(os.fstat(f.fileno()).st_mtime))
     headers = {
         "Content-Type": content_type,
         "Last-Modified": last_modified
     }
     return client.OK, headers, answer
 def _get_real_collection(self, href):
     path = path_to_filesystem(self._filesystem_path, href)
     real = os.path.realpath(path).replace(
         self._get_collection_root_folder() + "/",
         "").replace("/" + href, "")
     return next(self.discover(real), None)
 def _is_update(self, href):
     path = path_to_filesystem(self._filesystem_path, href)
     return os.path.isfile(path)
 def _is_symlink(self, href):
     path = path_to_filesystem(self._filesystem_path, href)
     return os.path.islink(path)
    def upload(self, href, vobject_item):
        item = None

        self._plugin_started()

        if not self._check_for_calendar_object(vobject_item):
            return super().upload(href, vobject_item)

        #check for symlinks
        if self._is_symlink(href):
            self.logger.debug("PUT action on symlinked event.")
            self.logger.debug("Continue with the real path of the event.")
            collection = self._get_real_collection(href)
            self._plugin_finished()
            item = collection.upload(href, vobject_item)
            # Track the change
            self._update_history_etag(href, item)
            self._clean_history_cache()
            return item

        if self._is_update(href):
            self.logger.debug("PUT action to update an existing event.")
            vobject_item_old = self.get(href).item
            attendees_old = self._get_attendees(vobject_item_old)
            if not attendees_old:
                self.logger.debug(
                    "No attendees found in the old version on disk.")
            else:
                self.logger.debug(
                    "%i attendees found in the old version on disk.",
                    len(attendees_old))
                users_old = [
                    self._get_user_from_attendee(family_member) for
                    family_member in self._get_family_members(attendees_old)
                ]
                self.logger.debug(
                    "Removing all the symlinks for the attendees of the old version (will be added later again if needed)."
                )
                for user_old in users_old:
                    dest = self._get_default_calendar_for_user(user_old, href)
                    self.logger.debug("Path: " + dest)
                    os.unlink(dest)

        attendees = self._get_attendees(vobject_item)
        if not attendees:
            self.logger.debug(
                "No attendees found in %s, continuing with standard storage.",
                href)
            self._plugin_finished()
            return super().upload(href, vobject_item)

        self.logger.debug("%i attendees found in %s.", len(attendees), href)

        for family_member in self._get_family_members(attendees):
            try:
                user = self._get_user_from_attendee(family_member)

                try:
                    family_member.partstat_param
                except:
                    family_member.partstat_param = "NEEDS-ACTION"

                if family_member.partstat_param == "ACCEPTED":
                    self.logger.debug("PARTSTAT is already set to ACCEPTED.")
                elif family_member.partstat_param == "NEEDS-ACTION":
                    family_member.partstat_param = "ACCEPTED"
                    self.logger.debug(
                        "Set PARTSTAT automatically to ACCEPTED.")

                self.logger.debug(
                    "Creating a symbolic link to make event accessible for %s.",
                    user)
                src = path_to_filesystem(self._filesystem_path, href)
                dest = self._get_default_calendar_for_user(user, href)
                self.logger.debug("Source: " + src)
                self.logger.debug("Destination: " + dest)

                os.symlink(src, dest)

                real = os.path.realpath(dest.replace("/" + href, "")).replace(
                    self._get_collection_root_folder() + "/", "")
                collection = next(self.discover(real))

                # Track the change
                collection._update_history_etag(href, item)
                collection._clean_history_cache()
            except Exception as e:
                self.logger.error(
                    "Plugin encountered an error while trying to auto-accept and/or link for family members."
                )
                self.logger.error(e)

        self._plugin_finished()
        return super().upload(href, vobject_item)
    def delete(self, href=None):
        self._plugin_started()

        current_user = self._get_current_user()
        item = self.get(href)
        vobject_item = item.item

        if not self._check_for_calendar_object(vobject_item):
            super().delete(href)
            return

        #for deleting the whole collection
        #TODO: if deleting whole collection, problem with events symlinked to the collection!
        if href is None:
            self.logger.debug("DELETE action on whole collection.")
            self.logger.debug(
                "Up to now, this plugin is not able to handle this case properly."
            )
            self._plugin_finished()
            super().delete()
            return

        #check for symlinks
        if self._is_symlink(href):
            self.logger.debug("DELETE action on symlinked event.")
            self.logger.debug("The plugin will behave as following:")
            self.logger.debug(
                "Delete the current user from the attendees list and remove the symlink for the current user."
            )
            collection = self._get_real_collection(href)
            item = collection.get(href)
            try:
                vobject_item.vevent.attendee_list = [
                    attendee for attendee in vobject_item.vevent.attendee_list
                    if self._get_user_from_attendee(attendee) != current_user
                ]
                collection = self._get_real_collection(href)
                item = collection.upload(href, vobject_item)

                path = path_to_filesystem(self._filesystem_path, item.href)
                self.logger.debug("Path: " + path)

                os.unlink(path)

                # Track the change
                self._update_history_etag(href, None)
                self._clean_history_cache()

                self._plugin_finished()
                return
            except:
                self.logger.error(
                    "Plugin encountered an error while trying to delete attendees and/or symbolic links for family members."
                )
                self.logger.error(e)

        attendees = self._get_attendees(vobject_item)
        if not attendees:
            self.logger.debug(
                "No attendees found in %s, continuing with standard storage.",
                href)
            self._plugin_finished()
            super().delete(href)
            return

        self.logger.debug("%i attendees found in %s.", len(attendees), href)

        for family_member in self._get_family_members(attendees):
            try:
                user = self._get_user_from_attendee(family_member)

                self.logger.debug(
                    "Deleting symbolic link to delete event for %s too.", user)
                dest = self._get_default_calendar_for_user(user, href)
                self.logger.debug("Path: " + dest)

                os.unlink(dest)

                # Track the change
                self._update_history_etag(href, None)
                self._clean_history_cache()
            except:
                self.logger.error(
                    "Plugin encountered an error while trying to delete symbolic links for family members."
                )
                self.logger.error(e)

        self._plugin_finished()
        super().delete(href)
Example #9
0
 def __init__(self, path, principal=False):
     super().__init__(path, principal)
     self._filesystem_path = storage.path_to_filesystem(
         self.configuration.get("storage", "test_folder"), self.path)
Example #10
0
 def __init__(self, path, principal=False):
     super().__init__(path, principal)
     self._filesystem_path = storage.path_to_filesystem(
         self.configuration.get("storage", "test_folder"), self.path)