Example #1
0
    def _render_location(self, package, version, path):
        """
        renders a location page, can be a folder or a file
        """
        try:
            location = Location(
                session, current_app.config["SOURCES_DIR"], current_app.config["SOURCES_STATIC"], package, version, path
            )
        except (FileOrFolderNotFound, InvalidPackageOrVersionError):
            raise Http404ErrorSuggestions(package, version, path)

        if location.is_symlink():
            # check if it's secure
            symlink_dest = os.readlink(location.sources_path)
            dest = os.path.normpath(  # absolute, target file
                os.path.join(os.path.dirname(location.sources_path), symlink_dest)
            )
            # note: adding trailing slash because normpath drops them
            if dest.startswith(os.path.normpath(location.version_path) + "/"):
                # symlink is safe; redirect to its destination
                redirect_url = os.path.normpath(os.path.join(os.path.dirname(location.path_to), symlink_dest))
                self.render_func = bind_redirect(url_for(request.endpoint, path_to=redirect_url), code=301)
                return dict(redirect=redirect_url)
            else:
                raise Http403Error("insecure symlink, pointing outside package/version/")

        if location.is_dir():  # folder, we list its content
            return self._render_directory(location)

        elif location.is_file():  # file
            return self._render_file(location)

        else:  # doesn't exist
            raise Http404Error(None)
Example #2
0
def get_sources_path(session, package, version, config, path):
    """Creates a sources_path. Returns exception when it arises"""
    location = Location(session, config["SOURCES_DIR"],
                        config["SOURCES_STATIC"], package, version, path)

    file_ = SourceFile(location)

    return location.sources_path, file_
Example #3
0
def get_sources_path(session, package, version, config, path):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    location = Location(session, config["SOURCES_DIR"],
                        config["SOURCES_STATIC"], package, version, path)

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(config['SOURCES_STATIC'],
                                               config['SOURCES_DIR'], 1)
    return sources_path, file_
Example #4
0
def get_sources_path(session, package, version, config):
    """Creates a sources_path. Returns exception when it arises"""
    location = Location(
        session,
        config["SOURCES_DIR"],
        config["SOURCES_STATIC"],
        package,
        version,
        "debian/copyright",
    )

    return location.sources_path
Example #5
0
    def _render_location(self, package, version, path):
        """
        renders a location page, can be a folder or a file
        """
        try:
            location = Location(session,
                                current_app.config["SOURCES_DIR"],
                                current_app.config["SOURCES_STATIC"],
                                package, version, path)
        except (FileOrFolderNotFound, InvalidPackageOrVersionError):
            raise Http404ErrorSuggestions(package, version, path)

        if location.is_symlink():
            # check if it's secure
            symlink_dest = os.readlink(location.sources_path)
            dest = os.path.normpath(  # absolute, target file
                os.path.join(os.path.dirname(location.sources_path),
                             symlink_dest))
            # note: adding trailing slash because normpath drops them
            if dest.startswith(os.path.normpath(location.version_path) + '/'):
                # symlink is safe; redirect to its destination
                redirect_url = os.path.normpath(
                    os.path.join(os.path.dirname(location.path_to),
                                 symlink_dest))
                self.render_func = bind_redirect(url_for(request.endpoint,
                                                 path_to=redirect_url),
                                                 code=301)
                return dict(redirect=redirect_url)
            else:
                raise Http403Error(
                    'insecure symlink, pointing outside package/version/')

        if location.is_dir():  # folder, we list its content
            return self._render_directory(location)

        elif location.is_file():  # file
            return self._render_file(location)

        else:  # doesn't exist
            raise Http404Error(None)
Example #6
0
def get_sources_path(session, package, version, config, path):
    ''' Creates a sources_path. Returns exception when it arises
    '''
    try:
        location = Location(session, config["SOURCES_DIR"],
                            config["SOURCES_STATIC"], package, version, path)
    except (FileOrFolderNotFound, InvalidPackageOrVersionError) as e:
        raise e

    file_ = SourceFile(location)

    sources_path = file_.get_raw_url().replace(config['SOURCES_STATIC'],
                                               config['SOURCES_DIR'], 1)
    return sources_path, file_