def Handle(self, args, token=None): aff4_path = args.client_id.Add(args.file_path) export_command = u" ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(token.username), "file", "--path", utils.ShellQuote(aff4_path), "--output", "." ]) return ApiGetFileDownloadCommandResult(command=export_command)
def Render(self, args, token=None): results_path = HUNTS_ROOT_PATH.Add(args.hunt_id).Add("Results") export_command_str = " ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(token.username), "--reason", utils.ShellQuote(token.reason), "collection_files", "--path", utils.ShellQuote(results_path), "--output", "." ]) return dict(command=export_command_str)
def Layout(self, request, response, aff4_path=None): aff4_path = aff4_path or request.REQ.get("aff4_path") self.export_command_str = " ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(request.token.username), "--reason", utils.ShellQuote(request.token.reason), "collection_files", "--path", utils.ShellQuote(aff4_path), "--output", "."]) return super(CollectionExportView, self).Layout(request, response)
def Render(self, args, token=None): results_path = HUNTS_ROOT_PATH.Add(args.hunt_id).Add("Results") export_command_str = " ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(token.username), # NOTE: passing reason is no longer necessary, as necessary # approval will be found and cached automatically. "collection_files", "--path", utils.ShellQuote(results_path), "--output", "."]) return dict(command=export_command_str)
def Handle(self, args, token=None): flow_urn = args.client_id.Add("flows").Add(args.flow_id.Basename()) flow_obj = aff4.FACTORY.Open(flow_urn, aff4_type="GRRFlow", mode="r", token=token) output_urn = flow_obj.GetRunner().output_urn export_command_str = " ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(token.username), "collection_files", "--path", utils.ShellQuote(output_urn), "--output", "."]) return ApiGetFlowResultsExportCommandResult(command=export_command_str)
def Handle(self, args, token=None): results_path = args.hunt_id.ToURN().Add("Results") export_command_str = " ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(token.username), # NOTE: passing reason is no longer necessary, as necessary # approval will be found and cached automatically. "collection_files", "--path", utils.ShellQuote(results_path), "--output", "." ]) return ApiGetHuntResultsExportCommandResult(command=export_command_str)
def Layout(self, request, response): """Present a download form.""" self.age = rdfvalue.RDFDatetime(request.REQ.get("age")) client_id = request.REQ.get("client_id") aff4_path = request.REQ.get("aff4_path", client_id) try: fd = aff4.FACTORY.Open(aff4_path, token=request.token, age=self.age) self.path = fd.urn self.hash = fd.Get(fd.Schema.HASH, None) self.size = fd.Get(fd.Schema.SIZE) # If data is available to read - we present the download button. self.file_exists = False try: if fd.Read(1): self.file_exists = True except (IOError, AttributeError): pass self.export_command_str = u" ".join([ config_lib.CONFIG["AdminUI.export_command"], "--username", utils.ShellQuote(request.token.username), "file", "--path", utils.ShellQuote(aff4_path), "--output", "." ]) response = super(DownloadView, self).Layout(request, response) return self.CallJavascript(response, "DownloadView.Layout", aff4_path=aff4_path, client_id=client_id, age_int=int(self.age), file_exists=self.file_exists, renderer=self.__class__.__name__, reason=request.token.reason) except (AttributeError, IOError) as e: # Render the error template instead. self.error_message = e.message return renderers.TemplateRenderer.Layout(self, request, response, self.error_template)
def Handle(self, args, token=None): output_fname = re.sub("[^0-9a-zA-Z]+", "_", utils.SmartStr(args.hunt_id)) code_to_execute = ("""grrapi.Hunt("%s").GetFilesArchive().""" """WriteToFile("./hunt_results_%s.zip")""") % ( args.hunt_id, output_fname) export_command_str = " ".join([ config.CONFIG["AdminUI.export_command"], "--exec_code", utils.ShellQuote(code_to_execute) ]) return ApiGetHuntResultsExportCommandResult(command=export_command_str)
def Handle(self, args, token=None): ValidateVfsPath(args.file_path) output_fname = os.path.basename(args.file_path) code_to_execute = ( """grrapi.Client("%s").File(r\"\"\"%s\"\"\").GetBlob().""" """WriteToFile("./%s")""") % (args.client_id, args.file_path, output_fname) export_command = u" ".join([ config.CONFIG["AdminUI.export_command"], "--exec_code", utils.ShellQuote(code_to_execute) ]) return ApiGetFileDownloadCommandResult(command=export_command)