def validateUserPath(self, path):
    '''Takes a path relative to the user's root dir and validates that it is valid and within the user's root'''
    path = rdw_helpers.joinPaths(self.getUserDB().getUserRoot(self.getUsername()), rdw_helpers.encodePath(path))
    path = path.rstrip("/")
    realPath = os.path.realpath(path)
    if realPath != path:
       raise rdw_helpers.accessDeniedError
    
    # Make sure that the path starts with the user root
    # This check should be accomplished by ensurePathValid, but adding for a sanity check
    if realPath.find(rdw_helpers.encodePath(self.getUserDB().getUserRoot(self.getUsername()))) != 0:
       raise rdw_helpers.accessDeniedError
Example #2
0
    def validateUserPath(self, path):
        '''Takes a path relative to the user's root dir and validates that it is valid and within the user's root'''
        path = rdw_helpers.joinPaths(
            self.getUserDB().getUserRoot(self.getUsername()),
            rdw_helpers.encodePath(path))
        path = path.rstrip("/")
        realPath = os.path.realpath(path)
        if realPath != path:
            raise rdw_helpers.accessDeniedError

        # Make sure that the path starts with the user root
        # This check should be accomplished by ensurePathValid, but adding for a sanity check
        if realPath.find(
                rdw_helpers.encodePath(self.getUserDB().getUserRoot(
                    self.getUsername()))) != 0:
            raise rdw_helpers.accessDeniedError
Example #3
0
   def getParmsForPage(self, userRoot, repo="", path="", restore=""):
      repo = encodePath(repo)
      path = encodePath(path)
      # Build "parent directories" links
      parentDirs = []
      parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, "/", False), "parentDir" : repo.lstrip("/") })
      parentDirPath = "/"
      for parentDir in path.split("/"):
         if parentDir:
            parentDirPath = joinPaths(parentDirPath, parentDir)
            parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, parentDirPath, False), "parentDir" : parentDir })
      parentDirs[-1]["parentPath"] = "" # Clear link for last parent, so it doesn't show it as a link

      # Set up warning about in-progress backups, if necessary
      if librdiff.backupIsInProgressForRepo(joinPaths(userRoot, repo)):
         backupWarning = "Warning: a backup is currently in progress to this location.  The displayed data may be inconsistent."
      else:
         backupWarning = ""

      restoreUrl = ""
      viewUrl = ""
      if restore == "T":
         title = "Restore"
         viewUrl = self.buildBrowseUrl(repo, path, False)
         tempDates = librdiff.getDirRestoreDates(joinPaths(userRoot, repo), path)
         tempDates.reverse() # sort latest first
         restoreDates = []
         for x in tempDates:
            restoreDates.append({ "dateStr" : x.getDisplayString(),
                                 "dirRestoreUrl" : self.buildRestoreUrl(repo, path, x) })
         entries = []
      else:
         title = "Browse"
         restoreUrl = self.buildBrowseUrl(repo, path, True)
         restoreDates = []

         # Get list of actual directory entries
         fullRepoPath = joinPaths(userRoot, repo)
         libEntries = librdiff.getDirEntries(fullRepoPath, path)

         entries = []
         for libEntry in libEntries:
            entryLink = ""
            if libEntry.isDir:
               entryLink = self.buildBrowseUrl(repo, joinPaths(path, libEntry.name), False)
               fileType = "folder"
               size = " "
               sizeinbytes = 0
               changeDates = []
            else:
               entryLink = self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), libEntry.changeDates[-1])
               fileType = "file"
               entryChangeDates = libEntry.changeDates[:-1]
               entryChangeDates.reverse()
               size = rdw_helpers.formatFileSizeStr(libEntry.fileSize)
               sizeinbytes = libEntry.fileSize
               changeDates = [ { "changeDateUrl" : self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), x),
                                 "changeDateStr" : x.getDisplayString() } for x in entryChangeDates]

            showRevisionsText = (len(changeDates) > 0) or libEntry.isDir
            entries.append({ "filename" : libEntry.name,
                           "fileRestoreUrl" : entryLink,
                           "filetype" : fileType,
                           "exists" : libEntry.exists,
                           "date" : libEntry.changeDates[-1].getDisplayString(),
                           "dateinseconds" : libEntry.changeDates[-1].getLocalSeconds(),
                           "size" : size,
                           "sizeinbytes" : sizeinbytes,
                           "hasPrevRevisions" : len(changeDates) > 0,
                           "numPrevRevisions" : str(len(changeDates)),
                           "hasMultipleRevisions" : len(changeDates) > 1,
                           "showRevisionsText" : showRevisionsText,
                           "changeDates" : changeDates})

      return { "title" : title, "files" : entries, "parentDirs" : parentDirs, "restoreUrl" : restoreUrl, "viewUrl" : viewUrl, "restoreDates" : restoreDates, "warning" : backupWarning }
Example #4
0
    def getParmsForPage(self, userRoot, repo="", path="", restore=""):
        repo = encodePath(repo)
        path = encodePath(path)
        # Build "parent directories" links
        parentDirs = []
        parentDirs.append({
            "parentPath": self.buildBrowseUrl(repo, "/", False),
            "parentDir": repo.lstrip("/")
        })
        parentDirPath = "/"
        for parentDir in path.split("/"):
            if parentDir:
                parentDirPath = joinPaths(parentDirPath, parentDir)
                parentDirs.append({
                    "parentPath":
                    self.buildBrowseUrl(repo, parentDirPath, False),
                    "parentDir":
                    parentDir
                })
        parentDirs[-1][
            "parentPath"] = ""  # Clear link for last parent, so it doesn't show it as a link

        # Set up warning about in-progress backups, if necessary
        if librdiff.backupIsInProgressForRepo(joinPaths(userRoot, repo)):
            backupWarning = "Warning: a backup is currently in progress to this location.  The displayed data may be inconsistent."
        else:
            backupWarning = ""

        restoreUrl = ""
        viewUrl = ""
        if restore == "T":
            title = "Restore"
            viewUrl = self.buildBrowseUrl(repo, path, False)
            tempDates = librdiff.getDirRestoreDates(joinPaths(userRoot, repo),
                                                    path)
            tempDates.reverse()  # sort latest first
            restoreDates = []
            for x in tempDates:
                restoreDates.append({
                    "dateStr":
                    x.getDisplayString(),
                    "dirRestoreUrl":
                    self.buildRestoreUrl(repo, path, x)
                })
            entries = []
        else:
            title = "Browse"
            restoreUrl = self.buildBrowseUrl(repo, path, True)
            restoreDates = []

            # Get list of actual directory entries
            fullRepoPath = joinPaths(userRoot, repo)
            libEntries = librdiff.getDirEntries(fullRepoPath, path)

            entries = []
            for libEntry in libEntries:
                entryLink = ""
                if libEntry.isDir:
                    entryLink = self.buildBrowseUrl(
                        repo, joinPaths(path, libEntry.name), False)
                    fileType = "folder"
                    size = " "
                    sizeinbytes = 0
                    changeDates = []
                else:
                    entryLink = self.buildRestoreUrl(
                        repo, joinPaths(path, libEntry.name),
                        libEntry.changeDates[-1])
                    fileType = "file"
                    entryChangeDates = libEntry.changeDates[:-1]
                    entryChangeDates.reverse()
                    size = rdw_helpers.formatFileSizeStr(libEntry.fileSize)
                    sizeinbytes = libEntry.fileSize
                    changeDates = [{
                        "changeDateUrl":
                        self.buildRestoreUrl(repo,
                                             joinPaths(path, libEntry.name),
                                             x),
                        "changeDateStr":
                        x.getDisplayString()
                    } for x in entryChangeDates]

                showRevisionsText = (len(changeDates) > 0) or libEntry.isDir
                entries.append({
                    "filename":
                    libEntry.name,
                    "fileRestoreUrl":
                    entryLink,
                    "filetype":
                    fileType,
                    "exists":
                    libEntry.exists,
                    "date":
                    libEntry.changeDates[-1].getDisplayString(),
                    "dateinseconds":
                    libEntry.changeDates[-1].getLocalSeconds(),
                    "size":
                    size,
                    "sizeinbytes":
                    sizeinbytes,
                    "hasPrevRevisions":
                    len(changeDates) > 0,
                    "numPrevRevisions":
                    str(len(changeDates)),
                    "hasMultipleRevisions":
                    len(changeDates) > 1,
                    "showRevisionsText":
                    showRevisionsText,
                    "changeDates":
                    changeDates
                })

        return {
            "title": title,
            "files": entries,
            "parentDirs": parentDirs,
            "restoreUrl": restoreUrl,
            "viewUrl": viewUrl,
            "restoreDates": restoreDates,
            "warning": backupWarning
        }