def render(self, renderer):
        renderer.format("Starting Manuskript web console.\n")
        renderer.format("Press Ctrl-c to return to the interactive shell.\n")

        if os.path.isdir(self.pre_load):
            self.worksheet_fd = WebConsoleDocument(
                self.pre_load, session=self.session)

            return self._serve_wsgi()

        with utils.TempDirectory() as temp_dir:
            logging.info("Using working directory %s", temp_dir)

            # We need to copy the pre load file into the working file.
            if self.pre_load:
                dst = os.path.join(temp_dir, os.path.basename(self.pre_load))
                shutil.copy(self.pre_load, dst)

                logging.info("Initialized from %s", self.pre_load)

                self.worksheet_fd = io_manager.ZipFileManager(
                    dst, mode="a")
            else:
                self.worksheet_fd = io_manager.ZipFileManager(
                    os.path.join(temp_dir, "rekall.zip"), mode="a")

            self._serve_wsgi()
Beispiel #2
0
        def save_current_worksheet():  # pylint: disable=unused-variable
            """Save the current worksheet into worksheet directory."""
            worksheet = app.config['worksheet']
            session = app.config['worksheet'].session
            worksheet_dir = session.GetParameter("notebook_dir", ".")
            path = os.path.normpath(request.args.get("path", ""))
            full_path = os.path.join(worksheet_dir, "./" + path)

            with open(full_path, "wb") as out_zip:
                with zipfile.ZipFile(
                        out_zip, mode="w",
                        compression=zipfile.ZIP_DEFLATED) as out_fd:
                    cells = worksheet.GetData("notebook_cells") or []
                    out_fd.writestr("notebook_cells", json.dumps(cells))

                    for cell in cells:
                        # Copy all the files under this cell id:
                        path = "%s/" % cell["id"]
                        for filename in worksheet.ListFiles():
                            if filename.startswith(path):
                                with worksheet.Open(filename) as in_fd:
                                    # Limit reading to a reasonable size (10Mb).
                                    out_fd.writestr(filename,
                                                    in_fd.read(100000000))

            worksheet.Close()

            app.config["worksheet"] = io_manager.ZipFileManager(full_path,
                                                                mode="a")

            return "Worksheet is saved", 200
Beispiel #3
0
        def load_new_worksheet():  # pylint: disable=unused-variable
            session = app.config['worksheet'].session
            worksheet_dir = session.GetParameter("notebook_dir", ".")
            path = os.path.normpath(request.args.get("path", ""))
            full_path = os.path.join(worksheet_dir, "./" + path)

            # First check that this is a valid Rekall file.
            try:
                fd = io_manager.ZipFileManager(full_path, mode="a")
                if not fd.GetData("notebook_cells"):
                    raise IOError
            except IOError:
                return "File is not a valid Rekall File.", 500

            old_worksheet = app.config["worksheet"]
            old_worksheet.Close()

            app.config["worksheet"] = fd

            return "Worksheet is updated", 200