Exemplo n.º 1
0
    def RenderOption(self, option, request, response):
        if option == "Windows":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="Windows")

        elif option == "Linux":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="Linux")

        elif option == "OSX":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="OSX")

        elif option == "Regex":
            return self.RenderFromTemplate(
                self.form_template,
                response,
                form=forms.SemanticProtoFormRenderer(
                    rdfvalue.ForemanAttributeRegex(),
                    prefix=self.prefix).RawHTML(request))

        elif option == "Integer":
            return self.RenderFromTemplate(
                self.form_template,
                response,
                form=forms.SemanticProtoFormRenderer(
                    rdfvalue.ForemanAttributeInteger(),
                    prefix=self.prefix).RawHTML(request))
Exemplo n.º 2
0
    def ParseOption(self, option, request):
        """Parse the form that is selected by option."""
        if option == "Windows":
            return implementation.GRRHunt.MATCH_WINDOWS

        elif option == "Linux":
            return implementation.GRRHunt.MATCH_LINUX

        elif option == "OSX":
            return implementation.GRRHunt.MATCH_DARWIN

        elif option == "Label":
            label_name = ClientLabelNameFormRenderer(
                descriptor=type_info.TypeInfoObject(),
                default="",
                prefix=self.prefix).ParseArgs(request)
            regex = aff4_rdfvalues.AFF4ObjectLabelsList.RegexForStringifiedValueMatch(
                label_name)

            return rdf_foreman.ForemanAttributeRegex(attribute_name="Labels",
                                                     attribute_regex=regex)

        elif option == "Regex":
            return forms.SemanticProtoFormRenderer(
                rdf_foreman.ForemanAttributeRegex(),
                prefix=self.prefix).ParseArgs(request)

        elif option == "Integer":
            return forms.SemanticProtoFormRenderer(
                rdf_foreman.ForemanAttributeInteger(),
                prefix=self.prefix).ParseArgs(request)
Exemplo n.º 3
0
  def RenderAjax(self, request, response):
    """Parse the flow args from the form and launch the flow."""
    self.flow_name = request.REQ.get("flow_path", "").split("/")[-1]
    self.client_id = request.REQ.get("client_id", None)
    self.dom_node = request.REQ.get("dom_node")

    flow_cls = flow.GRRFlow.classes.get(self.flow_name)
    if flow_cls is not None:

      self.args = forms.SemanticProtoFormRenderer(
          flow_cls.args_type(), prefix="args").ParseArgs(request)

      try:
        self.args.Validate()
      except ValueError as e:
        return self.RenderFromTemplate(self.ajax_error_template,
                                       response, error=e)

      self.runner_args = forms.SemanticProtoFormRenderer(
          flow.FlowRunnerArgs(), prefix="runner_").ParseArgs(request)

      self.runner_args.Validate()

      self.flow_id = flow.GRRFlow.StartFlow(client_id=self.client_id,
                                            flow_name=self.flow_name,
                                            token=request.token,
                                            args=self.args,
                                            runner_args=self.runner_args)

    return renderers.TemplateRenderer.Layout(
        self, request, response, apply_template=self.ajax_template)
Exemplo n.º 4
0
  def Layout(self, request, response):
    """Render the form for creating the flow args."""
    self.flow_name = os.path.basename(request.REQ.get("flow_path", ""))
    self.flow_cls = flow.GRRFlow.classes.get(self.flow_name)
    if aff4.issubclass(self.flow_cls, flow.GRRFlow):
      self.flow_found = True

      self.form = forms.SemanticProtoFormRenderer(
          self.flow_cls.GetDefaultArgs(token=request.token),
          prefix="args").RawHTML(request)

      self.runner_form = forms.SemanticProtoFormRenderer(
          flow.FlowRunnerArgs(flow_name=self.flow_name),
          prefix="runner").RawHTML(request)

    return super(SemanticProtoFlowForm, self).Layout(request, response)
Exemplo n.º 5
0
    def RenderOption(self, option, request, response):
        # Depending on the plugin we render a different protobuf.
        plugin = output_plugin.OutputPlugin.classes.get(option)

        if plugin and plugin.description:
            return forms.SemanticProtoFormRenderer(plugin.args_type(),
                                                   id=self.id,
                                                   prefix=self.prefix).Layout(
                                                       request, response)
Exemplo n.º 6
0
  def Layout(self, request, response):
    """Render the form for creating the flow args."""
    self.flow_name = self._GetFlowName(request)
    self.flow_cls = flow.GRRFlow.classes.get(self.flow_name)

    if aff4.issubclass(self.flow_cls, flow.GRRFlow):
      self.flow_found = True

      self.form = forms.SemanticProtoFormRenderer(
          self.flow_cls.GetDefaultArgs(token=request.token),
          prefix="args").RawHTML(request)

      self.runner_form = forms.SemanticProtoFormRenderer(
          flow_runner.FlowRunnerArgs(flow_name=self.flow_name),
          prefix="runner").RawHTML(request)

    response = super(SemanticProtoFlowForm, self).Layout(request, response)
    return self.CallJavascript(response, "SemanticProtoFlowForm.Layout",
                               renderer=self.__class__.__name__)
Exemplo n.º 7
0
  def Layout(self, request, response):
    cron_args = rdfvalue.CreateCronJobFlowArgs()
    cron_args.flow_runner_args.flow_name = "CreateGenericHuntFlow"

    self.cron_form = forms.SemanticProtoFormRenderer(
        cron_args, id=self.id,
        supressions=self.cron_suppressions,
        prefix="cron").RawHTML(request)

    return super(CronConfigureSchedule, self).Layout(request, response)
Exemplo n.º 8
0
  def ParseCronParameters(self):
    cron_parmeters = forms.SemanticProtoFormRenderer(
        rdfvalue.CreateCronJobFlowArgs(), prefix="cron").ParseArgs(
            self.request)

    cron_parmeters.flow_runner_args.flow_name = "CreateGenericHuntFlow"
    cron_parmeters.flow_args.hunt_runner_args = self.ParseHuntRunnerArgs()
    cron_parmeters.flow_args.hunt_args = self.ParseHuntArgs()

    return cron_parmeters
Exemplo n.º 9
0
    def RenderAjax(self, request, response):
        """Parse the flow args from the form and launch the flow."""
        self.flow_name = self._GetFlowName(request)
        self.client_id = request.REQ.get("client_id", None)
        self.dom_node = request.REQ.get("dom_node")

        flow_cls = flow.GRRFlow.classes.get(self.flow_name)
        if flow_cls is not None:

            self.args = forms.SemanticProtoFormRenderer(
                flow_cls.args_type(), prefix="args").ParseArgs(request)

            try:
                self.args.Validate()
            except ValueError as e:
                return self.CallJavascript(
                    response,
                    "SemanticProtoFlowForm.RenderAjaxError",
                    error=str(e))

            self.runner_args = forms.SemanticProtoFormRenderer(
                flow_runner.FlowRunnerArgs(),
                prefix="runner_").ParseArgs(request)

            self.runner_args.Validate()

            self.flow_id = flow.GRRFlow.StartFlow(client_id=self.client_id,
                                                  flow_name=self.flow_name,
                                                  token=request.token,
                                                  args=self.args,
                                                  runner_args=self.runner_args)

        self.args_html = semantic.FindRendererForObject(
            self.args).RawHTML(request)
        self.runner_args_html = semantic.FindRendererForObject(
            self.runner_args).RawHTML(request)
        response = renderers.TemplateRenderer.Layout(
            self, request, response, apply_template=self.ajax_template)
        return self.CallJavascript(response,
                                   "SemanticProtoFlowForm.RenderAjax",
                                   renderer=self.__class__.__name__,
                                   dom_node=self.dom_node)
Exemplo n.º 10
0
    def ParseOption(self, option, request):
        """Parse the form that is selected by option."""
        if option == "Windows":
            return implementation.GRRHunt.MATCH_WINDOWS

        elif option == "Linux":
            return implementation.GRRHunt.MATCH_LINUX

        elif option == "OSX":
            return implementation.GRRHunt.MATCH_DARWIN

        elif option == "Regex":
            return forms.SemanticProtoFormRenderer(
                rdfvalue.ForemanAttributeRegex(),
                prefix=self.prefix).ParseArgs(request)

        elif option == "Integer":
            return forms.SemanticProtoFormRenderer(
                rdfvalue.ForemanAttributeInteger(),
                prefix=self.prefix).ParseArgs(request)
Exemplo n.º 11
0
    def ParseFlowArgs(self):
        """Parse the flow and flow_runner args."""
        if self.flow_runner_args is not None:
            return self.flow_runner_args, self.flow_args

        flow_path = self.request.REQ.get("flow_path", "")
        flow_name = os.path.basename(flow_path)
        if not flow_name:
            raise ValueError("No flow specified. Please select a flow.")

        flow_cls = flow.GRRFlow.GetPlugin(flow_name)
        self.flow_args = forms.SemanticProtoFormRenderer(
            flow_cls.args_type(), prefix="args").ParseArgs(self.request)

        self.flow_runner_args = forms.SemanticProtoFormRenderer(
            flow.FlowRunnerArgs(), prefix="runner").ParseArgs(self.request)

        self.flow_runner_args.flow_name = flow_name

        return self.flow_runner_args, self.flow_args
Exemplo n.º 12
0
    def ParseCronParameters(self):
        params = forms.SemanticProtoFormRenderer(
            cronjobs.CreateCronJobFlowArgs(),
            prefix="cron").ParseArgs(self.request)

        params.flow_runner_args.flow_name = "CreateAndRunGenericHuntFlow"
        params.flow_args.hunt_runner_args = self.ParseHuntRunnerArgs()
        params.flow_args.hunt_runner_args.description = ("%s Cron" %
                                                         params.description)
        params.flow_args.hunt_args = self.ParseHuntArgs()

        return params
Exemplo n.º 13
0
  def RenderAjax(self, request, response):
    """Starts ModifyHuntFlow that actually modifies a hunt."""
    hunt_urn = rdfvalue.RDFURN(request.REQ.get("hunt_id"))

    args = forms.SemanticProtoFormRenderer(
        hunts_standard.ModifyHuntFlowArgs()).ParseArgs(request)

    flow.GRRFlow.StartFlow(flow_name="ModifyHuntFlow", token=request.token,
                           hunt_urn=hunt_urn, args=args)

    return self.RenderFromTemplate(self.ajax_template, response,
                                   unique=self.unique)
Exemplo n.º 14
0
    def ParseOption(self, option, request):
        # Depending on the plugin we parse a different protobuf.
        plugin = output_plugin.OutputPlugin.classes.get(option)

        if plugin and plugin.description:
            result = output_plugin.OutputPluginDescriptor(plugin_name=option)
            result.plugin_args = forms.SemanticProtoFormRenderer(
                plugin.args_type(), id=self.id,
                prefix=self.prefix).ParseArgs(request)
            result.plugin_args.Validate()

            return result
Exemplo n.º 15
0
  def RenderAjax(self, request, response):
    """Ajax hanlder for this renderer."""
    settings = forms.SemanticProtoFormRenderer(
        proto_obj=rdfvalue.GUISettings(),
        prefix="settings").ParseArgs(request)

    flow.GRRFlow.StartFlow(flow_name="UpdateSettingsFlow",
                           args=settings, token=request.token)

    response = self.RenderFromTemplate(self.ajax_template, response,
                                       unique=self.unique)
    return self.CallJavascript(response, "RenderAjax")
Exemplo n.º 16
0
    def RenderOption(self, option, request, response):
        if option == "Windows":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="Windows")

        elif option == "Linux":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="Linux")

        elif option == "OSX":
            return self.RenderFromTemplate(self.match_system_template,
                                           response,
                                           system="OSX")

        elif option == "Label":
            return self.RenderFromTemplate(
                self.form_template,
                response,
                form=ClientLabelNameFormRenderer(
                    descriptor=type_info.TypeInfoObject(friendly_name="Label"),
                    default="",
                    prefix=self.prefix).RawHTML(request))

        elif option == "Regex":
            return self.RenderFromTemplate(
                self.form_template,
                response,
                form=forms.SemanticProtoFormRenderer(
                    rdf_foreman.ForemanAttributeRegex(),
                    prefix=self.prefix).RawHTML(request))

        elif option == "Integer":
            return self.RenderFromTemplate(
                self.form_template,
                response,
                form=forms.SemanticProtoFormRenderer(
                    rdf_foreman.ForemanAttributeInteger(),
                    prefix=self.prefix).RawHTML(request))
Exemplo n.º 17
0
  def RenderAjax(self, request, response):
    aff4_path = rdfvalue.RDFURN(request.REQ.get("aff4_path"))
    args = forms.SemanticProtoFormRenderer(
        filesystem.RecursiveListDirectoryArgs()).ParseArgs(request)

    fd = aff4.FACTORY.Open(aff4_path, token=request.token)
    args.pathspec = fd.real_pathspec

    flow.GRRFlow.StartFlow(client_id=aff4_path.Split()[0],
                           flow_name="RecursiveListDirectory",
                           args=args,
                           notify_to_user=True,
                           token=request.token)
    return self.RenderFromTemplate(self.ajax_template, response)
Exemplo n.º 18
0
    def ParseHuntRunnerArgs(self):
        """Parse the hunt runner arguments, rules and output plugins."""
        if self.hunt_runner_args is not None:
            return self.hunt_runner_args

        self.hunt_runner_args = forms.SemanticProtoFormRenderer(
            implementation.HuntRunnerArgs(),
            prefix="hunt_runner").ParseArgs(self.request)

        self.hunt_runner_args.hunt_name = "GenericHunt"

        # Parse out the rules.
        self.ParseRules(self.hunt_runner_args)

        return self.hunt_runner_args
Exemplo n.º 19
0
  def Layout(self, request, response):
    """Layout handler."""
    hunt_urn = rdfvalue.RDFURN(request.REQ.get("hunt_id"))
    with aff4.FACTORY.Open(hunt_urn, aff4_type="GRRHunt",
                           token=request.token) as hunt:

      runner = hunt.GetRunner()

      hunt_args = hunts_standard.ModifyHuntFlowArgs(
          client_limit=runner.args.client_limit,
          expiry_time=runner.context.expires,
      )

      self.hunt_params_form = forms.SemanticProtoFormRenderer(
          hunt_args, supressions=["hunt_urn"]).RawHTML(request)

      self.check_access_subject = hunt_urn

      return super(ModifyHuntDialog, self).Layout(request, response)
Exemplo n.º 20
0
    def Layout(self, request, response):
        """Layout the hunt flow form."""
        self.flow_path = request.REQ.get("flow_path", "")
        self.flow_name = os.path.basename(self.flow_path)

        hunt_runner_form = forms.SemanticProtoFormRenderer(
            implementation.HuntRunnerArgs(),
            id=self.id,
            supressions=self.suppressions,
            prefix="hunt_runner")

        self.hunt_params_form = hunt_runner_form.RawHTML(request)

        self.flow_description = flow_management.FlowInformation(
            id=self.id).RawHTML(request)

        if self.flow_name in flow.GRRFlow.classes:
            return super(HuntFlowForm, self).Layout(request, response)
        else:
            return self.RenderFromTemplate(self.nothing_selected_template,
                                           response)
Exemplo n.º 21
0
 def Layout(self, request, response):
   args = filesystem.RecursiveListDirectoryArgs()
   self.recursive_refresh_form = forms.SemanticProtoFormRenderer(
       args, supressions=["pathspec"]).RawHTML(request)
   return super(RecursiveRefreshDialog, self).Layout(request, response)
Exemplo n.º 22
0
  def Layout(self, request, response):
    user_settings = self.GetUserSettings(request)
    self.user_settings_form = forms.SemanticProtoFormRenderer(
        proto_obj=user_settings, prefix="settings").RawHTML(request)

    return super(UserSettingsDialog, self).Layout(request, response)