def post(self):
    """Reports get handler.

    Returns:
      A webapp.Response() response.
    """
    session = gaeserver.DoMunkiAuth()
    uuid = main_common.SanitizeUUID(session.uuid)
    report_type = self.request.get('_report_type')
    report_feedback = {}
    message = None
    details = None
    client_id = None
    computer = None

    if report_type == 'preflight' or report_type == 'postflight':
      client_id_str = urllib.unquote(self.request.get('client_id'))
      client_id = common.ParseClientId(client_id_str, uuid=uuid)
      user_settings_str = self.request.get('user_settings')
      user_settings = None
      try:
        if user_settings_str:
          user_settings = util.Deserialize(
              urllib.unquote(str(user_settings_str)))
      except util.DeserializeError:
        logging.warning(
            'Client %s sent broken user_settings: %s',
            client_id_str, user_settings_str)

      pkgs_to_install = self.request.get_all('pkgs_to_install')
      apple_updates_to_install = self.request.get_all(
          'apple_updates_to_install')

      computer = models.Computer.get_by_key_name(uuid)
      ip_address = os.environ.get('REMOTE_ADDR', '')
      if report_type == 'preflight':
        # we want to get feedback now, before preflight_datetime changes.
        client_exit = self.request.get('client_exit', None)
        report_feedback = self.GetReportFeedback(
            uuid, report_type, computer=computer, ip_address=ip_address,
            client_exit=client_exit)

        if self.request.get('json') == '1':
          self.response.out.write(JSON_PREFIX + json.dumps(report_feedback))
        else:
          # For legacy clients that accept a single string, not JSON.
          feedback_to_send = 'OK'
          for feedback in LEGACY_FEEDBACK_LIST:
            if report_feedback.get(feedback.lower()):
              feedback_to_send = feedback
          self.response.out.write(feedback_to_send)

        # if report feedback calls for a client exit, log it.
        if report_feedback.get('exit'):
          if not client_exit:
            # client didn't ask for an exit, which means server decided.
            client_exit = 'Connection from defined exit IP address'
          common.WriteClientLog(
              models.PreflightExitLog, uuid, computer=computer,
              exit_reason=client_exit)

      common.LogClientConnection(
          report_type, client_id, user_settings, pkgs_to_install,
          apple_updates_to_install, computer=computer, ip_address=ip_address,
          report_feedback=report_feedback)


    elif report_type == 'install_report':
      computer = models.Computer.get_by_key_name(uuid)

      self._LogInstalls(self.request.get_all('installs'), computer)

      for removal in self.request.get_all('removals'):
        common.WriteClientLog(
            models.ClientLog, uuid, computer=computer, action='removal',
            details=removal)

      for problem in self.request.get_all('problem_installs'):
        common.WriteClientLog(
            models.ClientLog, uuid, computer=computer,
            action='install_problem', details=problem)
    elif report_type == 'broken_client':
      # Default reason of "objc" to support legacy clients, existing when objc
      # was the only broken state ever reported.
      reason = self.request.get('reason', 'objc')
      details = self.request.get('details')
      logging.warning('Broken Munki client (%s): %s', reason, details)
      common.WriteBrokenClient(uuid, reason, details)
    elif report_type == 'msu_log':
      details = {}
      for k in ['time', 'user', 'source', 'event', 'desc']:
        details[k] = self.request.get(k, None)
      common.WriteComputerMSULog(uuid, details)
    else:
      # unknown report type; log all post params.
      params = []
      for param in self.request.arguments():
        params.append('%s=%s' % (param, self.request.get_all(param)))
      common.WriteClientLog(
          models.ClientLog, uuid, action='unknown', details=str(params))
dataset/ETHPy150Open google/simian/src/simian/mac/munki/handlers/reports.py/Reports.post/original