Exemplo n.º 1
0
def RunPreflight(runtype, server_url=None):
  """Run the full Preflight script."""

  NoteLastRun()
  # support enterprise/802.1x user-context wifi auth.
  # don't bother to perform preflight and exit OK immediately since there's no
  # network connection.
  if runtype == 'logoutinstall':
    sys.exit(0)

  # load the NONSECURE ManagedInstalls.plist
  regular_config = munkicommon.ManagedInstallsPreferences()

  if server_url:
    regular_config['SoftwareRepoURL'] = server_url

  secure_config = munkicommon.SecureManagedInstallsPreferences()

  # update the ClientIdentifier key with the custom client id.
  client_id = flight_common.GetClientIdentifier(runtype)
  secure_config['ClientIdentifier'] = client_id['track']

  # load user settings
  try:
    user_settings = flight_common.GetUserSettings()
  except ValueError as e:
    logging.warning('User settings are malformed: %s', str(e))
    user_settings = {'__malformed': True}

  # If the munki exec is an auto run (launchd), exit if on WWAN or Android WAP.
  client_exit = None
  if runtype == 'auto':
    if network_detect.IsOnWwan():
      client_exit = 'WWAN device ppp0 is active'
    elif network_detect.IsOnAndroidWap():
      client_exit = 'Android WAP tether is active'
    elif network_detect.IsOnIosWap():
      client_exit = 'iOS WAP tether is active'
    elif network_detect.IsOnMifi():
      client_exit = 'MiFi tether is active'
    elif network_detect.IsOnBackoffWLAN():
      client_exit = 'Backoff WLAN SSID detected'

  # get a client auth token/cookie from the server, and post connection data.
  client, feedback = LoginToServer(
      secure_config, client_id, user_settings, client_exit)

  WriteRootCaCerts(client)

  if feedback.get('upload_logs'):
    # write new token/client_id headers to secure plist and upload logs.
    flight_common.UploadClientLogFiles(client)

  if feedback.get('pkill_installd'):
    # terminate any pending installations, like misbehaving Apple updates.
    flight_common.Pkill(process='installd', waitfor=2)

  if feedback.get('pkill_softwareupdated'):
    # terminate potentially hung softareupdated processes.
    flight_common.Pkill(process='softwareupdated', waitfor=2)

  if feedback.get('repair'):
    # write new token/client_id headers to secure plist and repair client.
    try:
      logging.info('Reinstalling Munki client....')
      flight_common.RepairClient()
      logging.info('Client successfully reinstalled.')
    except flight_common.RepairClientError as e:
      logging.exception(u'RepairClientError: %s', e)

  if feedback.get('logging_level'):
    regular_config['LoggingLevel'] = feedback.get('logging_level')
  else:
    regular_config['LoggingLevel'] = 1  # default to 1 if not set by server.

  if feedback.get('exit'):
    logging.warning('preflight received EXIT feedback from server; exiting....')
    sys.exit(STATUS_SERVER_EXIT_FEEDBACK[0])

  # post recent MSU logs
  logs = GetManagedSoftwareUpdateLogs()
  PostManagedSoftwareUpdateLogs(client, logs)

  # load user settings
  if user_settings:
    regular_config['UserSettings'] = user_settings
  else:
    if 'UserSettings' in regular_config:
      del regular_config['UserSettings']  # wipe existing UserSettings.

  # setup blank directory for capath setting
  path = CreateEmptyDirectory()
  regular_config['SoftwareRepoCAPath'] = path

  # enable MSU logging
  regular_config['MSULogEnabled'] = True


  # If setting is enabled, force Simian Apple SUS integration.
  if client_id.get('applesus'):
    regular_config['InstallAppleSoftwareUpdates'] = True
    # Get Apple Software Update Service catalog from server and set locally.
    flight_common.GetAppleSUSCatalog()

  # Report installs/etc to server.
  flight_common.UploadAllManagedInstallReports(
      client, client_id.get('on_corp', 'None'))

  # Delete the temp dir that munkicommon creates on import.
  munkicommon.cleanUpTmpDir()

  logging.debug('Preflight completed successfully.')
Exemplo n.º 2
0
    client_id = flight_common.GetClientIdentifier(runtype)
    secure_config['ClientIdentifier'] = client_id['track']

    # load user settings
    try:
        user_settings = flight_common.GetUserSettings()
    except ValueError, e:
        logging.warning('User settings are malformed: %s', str(e))
        user_settings = {'__malformed': True}

    # If the munki exec is an auto run (launchd), exit if on WWAN or Android WAP.
    client_exit = None
    if runtype == 'auto':
        if network_detect.IsOnWwan():
            client_exit = 'WWAN device ppp0 is active'
        elif network_detect.IsOnAndroidWap():
            client_exit = 'Android WAP tether is active'
        elif network_detect.IsOnIosWap():
            client_exit = 'iOS WAP tether is active'
        elif network_detect.IsOnMifi():
            client_exit = 'MiFi tether is active'

    # get a client auth token/cookie from the server, and post connection data.
    client, feedback = LoginToServer(secure_config, client_id, user_settings,
                                     client_exit)

    WriteRootCaCerts(client)

    if feedback.get('upload_logs'):
        # write new token/client_id headers to secure plist and upload logs.
        flight_common.UploadClientLogFiles(client)