コード例 #1
0
ファイル: page_settings.py プロジェクト: Eeems/rdiffweb
 def _set_encoding(self, repo_obj, new_encoding=None, **kwargs):
     """
     Update repository encoding via Ajax.
     """
     validate(new_encoding)
     try:
         repo_obj.encoding = new_encoding
     except ValueError:
         raise cherrypy.HTTPError(400, _("invalid encoding value"))
     return _("Updated")
コード例 #2
0
ファイル: page_settings.py プロジェクト: Eeems/rdiffweb
    def _delete(self, repo_obj, confirm=None, redirect='/', **kwargs):
        """
        Delete the repository.
        """
        is_maintainer()
        # Validate the name
        validate(confirm)
        if confirm != repo_obj.display_name:
            _logger.debug("do not delete repo, bad confirmation %r != %r", confirm, repo_obj.display_name)
            raise cherrypy.HTTPError(400)

        # Refresh repository list
        repo_obj.delete()

        raise cherrypy.HTTPRedirect(redirect)
コード例 #3
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)
コード例 #4
0
ファイル: page_admin.py プロジェクト: Eeems/rdiffweb
    def _users_handle_action(self, action, username, email, password,
                             user_root, role):

        success = ""

        # We need to change values. Change them, then give back that main
        # page again, with a message
        if username == self.app.currentuser.username:
            # Don't allow the user to changes it's "role" state.
            role = self.app.currentuser.role

        # Fork the behaviour according to the action.
        if action == "edit":
            # Validation
            validate_int(role, 'role should be an integer')
            validate(int(role) in ROLES, 'invalid role')

            user = self.app.store.get_user(username)
            logger.info("updating user [%s] info", user)
            if password:
                user.set_password(password, old_password=None)
            user.user_root = user_root
            user.role = role
            # Avoid updating the email fields is it didn'T changed. see pdsl/minarca#187
            if email != user.email:
                user.email = email
            success = _("User information modified successfully.")

            # Check and update user directory
            if user.user_root:
                self._check_user_root_dir(user.user_root)
                user.update_repos()

        elif action == "add":
            # Validation
            validate_int(role, 'role should be an integer')
            validate(int(role) in ROLES, 'invalid role')

            if username == "":
                raise RdiffWarning(_("The username is invalid."))
            logger.info("adding user [%s]", username)

            user = self.app.store.add_user(username, password)
            if user_root:
                user.user_root = user_root
            user.role = role
            user.email = email

            # Check and update user directory
            if user.user_root:
                self._check_user_root_dir(user.user_root)
                user.update_repos()
            success = _("User added successfully.")

        if action == "delete":
            if username == self.app.currentuser.username:
                raise RdiffWarning(_("You cannot remove your own account!"))
            user = self.app.store.get_user(username)
            if not user:
                raise RdiffWarning(_("User doesn't exists!"))
            try:
                user.delete()
            except ValueError as e:
                raise RdiffWarning(e)
            success = _("User account removed.")

        # Return messages
        return {'success': success}