Exemplo n.º 1
0
    def default(self, path=b"", date="", failures=""):
        validate_isinstance(date, str)

        # Validate date
        startTime = librdiff.RdiffTime() - timedelta(days=5)
        endTime = None
        if date:
            try:
                date = int(date)
            except:
                logger.exception("invalid date")
                raise cherrypy.HTTPError(400, _("Invalid date."))
            # Set the start and end time to be the start and end of the day,
            # respectively, to get all entries for that day
            startTime = librdiff.RdiffTime(date)
            startTime.set_time(0, 0, 0)
            endTime = librdiff.RdiffTime(date)
            endTime.set_time(23, 59, 59)

        # Limit the scope to the given path.
        if path:
            user_repos = [self.app.store.get_repo(path)]
        else:
            user_repos = self.app.currentuser.repo_objs

        failuresOnly = failures != ""
        messages = self._getUserMessages(user_repos, not failuresOnly, True,
                                         startTime, endTime)

        return self._compile_template("status.html",
                                      messages=messages,
                                      failuresOnly=failuresOnly)
Exemplo n.º 2
0
    def default(self, graph, path, **kwargs):
        """
        Called to show every graphs
        """
        validate_isinstance(graph, bytes)
        graph = graph.decode('ascii', 'replace')
        repo_obj = self.app.store.get_repo(path)

        # check if data should be shown.
        if graph == 'data':
            return self._data(repo_obj, **kwargs)
        elif graph in ['activities', 'errors', 'files', 'sizes', 'times']:
            return self._page(repo_obj, graph, **kwargs)
        # Raise error.
        raise cherrypy.NotFound()
Exemplo n.º 3
0
    def default(self, path=b"", restore="", limit='10'):
        validate_isinstance(restore, str)
        limit = validate_int(limit)
        restore = bool(restore)

        # Check user access to the given repo & path
        (repo_obj, path_obj) = self.app.store.get_repo_path(path)

        # Build the parameters
        # Build "parent directories" links
        # TODO This Should to me elsewhere. It contains logic related to librdiff encoding.
        parents = []
        parents.append({"path": b"", "name": repo_obj.display_name})
        parent_path_b = b""
        for part_b in path_obj.path.split(b'/'):
            if part_b:
                parent_path_b = os.path.join(parent_path_b, part_b)
                display_name = repo_obj._decode(repo_obj.unquote(part_b))
                parents.append({"path": parent_path_b, "name": display_name})

        # Set up warning about in-progress backups, if necessary
        warning = False
        status = repo_obj.status
        if status[0] != 'ok':
            warning = status[1] + ' ' + _(
                "The displayed data may be inconsistent.")

        dir_entries = []
        restore_dates = []
        if restore:
            restore_dates = path_obj.change_dates[:-limit - 1:-1]
        else:
            # Get list of actual directory entries
            dir_entries = path_obj.dir_entries[::-1]

        parms = {
            "repo": repo_obj,
            "path": path_obj,
            "limit": limit,
            "dir_entries": dir_entries,
            "parents": parents,
            "restore_dates": restore_dates,
            "warning": warning
        }
        return self._compile_template("browse.html", **parms)
Exemplo n.º 4
0
    def default(self, path=b"", date=None, kind=None, usetar=None):
        validate_isinstance(path, bytes)
        validate_isinstance(date, str)
        validate(kind is None or kind in ARCHIVERS)
        validate(usetar is None or isinstance(usetar, str))

        logger.debug("restoring [%r][%s]", path, date)

        # Check user access to repo / path.
        path_obj = self.app.currentuser.get_repo_path(path)[1]

        # Get the restore date
        try:
            RdiffTime(int(date))
        except:
            logger.warning("invalid date %s", date)
            raise cherrypy.HTTPError(400, _("Invalid date."))

        # Get if backup in progress
        # status = repo_obj.status
        # if status[0] != 'ok':
        #    raise cherrypy.HTTPError(500, _(status[1] + ' ' + _("""Restores are disabled.""")))

        # Determine the kind.
        kind = kind or 'zip'
        if usetar is not None:
            kind = 'tar.gz'

        # Restore file(s)
        filename, fileobj = path_obj.restore(int(date), kind=kind)

        # Define content-disposition.
        cherrypy.response.headers[
            "Content-Disposition"] = _content_disposition(filename)

        # Set content-type based on filename extension
        content_type = _content_type(filename)
        cherrypy.response.headers['Content-Type'] = content_type

        # Stream the data.
        # Make use of _serve_fileobj() because the fsstat() function on a pipe
        # return a size of 0 for Content-Length. This behavior brake all the flow.
        return _serve_fileobj(fileobj,
                              content_type=content_type,
                              content_length=None)