예제 #1
0
def ack_profile_list(request: ProfileList, device: Device, response: dict):
    """Acknowledge a ``ProfileList`` response.
    
    Args:
        request (ProfileList): The command instance that generated this response.
        device (Device): The device responding to the command.
        response (dict): The raw response dictionary, de-serialized from plist.
    Returns:
          void: Reserved for future use
    """
    schema = ProfileListResponse()
    profile_list = schema.load(response)

    for pl in device.installed_payloads:
        db.session.delete(pl)

    # Impossible to calculate delta, so all profiles get wiped
    for p in device.installed_profiles:
        db.session.delete(p)

    desired_profiles = {}
    # for tag in device.tags:
    #     for p in tag.profiles:
    #         desired_profiles[p.uuid] = p

    remove_profiles = []

    for profile in profile_list.data['ProfileList']:
        profile.device = device

        # device.udid may have dashes (macOS) or not (iOS)
        profile.device_udid = device.udid

        for payload in profile.payload_content:
            payload.device = device
            payload.profile_id = profile.id

        db.session.add(profile)

        # Reconcile profiles which should be installed
        if profile.payload_uuid in desired_profiles:
            del desired_profiles[profile.payload_uuid]
        else:
            remove_profiles.append(profile)

    # Queue up some desired profiles
    for puuid, p in desired_profiles.items():
        c = commands.InstallProfile(None, profile=p)
        dbc = DBCommand.from_model(c)
        dbc.device = device
        db.session.add(dbc)

    # for remove_profile in remove_profiles:
    #     c = commands.RemoveProfile(None, Identifier=remove_profile.payload_identifier)
    #     dbc = DBCommand.from_model(c)
    #     dbc.device = device
    #     db.session.add(dbc)

    db.session.commit()
예제 #2
0
def ack_profile_list(request: DBCommand, device: Device, response: dict):
    """Acknowledge a ``ProfileList`` response.

    This is used as the trigger to perform InstallProfile/RemoveProfiles as we have the most current data about
    what exists on the device.

    The set of profiles to install is a result of:

        set(desired) - set(installed) = set(install)

    The set of profiles to remove is a result of:

        set(installed) - set(desired) = set(remove)

    EXCEPT THAT:
        - You never want to remove the enrollment profile unless you are "unmanaging" the device.
        - You can't remove profiles not installed by this MDM.

    Args:
        request (ProfileList): The command instance that generated this response.
        device (Device): The device responding to the command.
        response (dict): The raw response dictionary, de-serialized from plist.
    Returns:
          void: Reserved for future use
    """
    schema = ProfileListResponse()
    profile_list = schema.load(response)

    for pl in device.installed_payloads:
        db.session.delete(pl)

    # Impossible to calculate delta, so all profiles get wiped
    for p in device.installed_profiles:
        db.session.delete(p)

    desired_profiles = {}
    for tag in device.tags:
        for p in tag.profiles:
            desired_profiles[p.uuid] = p

    remove_profiles = []

    for profile in profile_list.data['ProfileList']:
        profile.device = device

        # device.udid may have dashes (macOS) or not (iOS)
        profile.device_udid = device.udid

        for payload in profile.payload_content:
            payload.device = device
            payload.profile_id = profile.id

        db.session.add(profile)

        # Reconcile profiles which should be installed
        if profile.payload_uuid in desired_profiles:
            del desired_profiles[profile.payload_uuid]
        else:
            if not profile.is_managed:
                current_app.logger.debug(
                    "Skipping removal of unmanaged profile: %s",
                    profile.payload_display_name)
            else:
                current_app.logger.debug("Going to remove: %s",
                                         profile.payload_display_name)
                remove_profiles.append(profile)

    # Queue up some desired profiles
    for puuid, p in desired_profiles.items():
        c = commands.InstallProfile(None, profile=p)
        dbc = DBCommand.from_model(c)
        dbc.device = device
        db.session.add(dbc)

    for remove_profile in remove_profiles:
        c = commands.RemoveProfile(
            None, Identifier=remove_profile.payload_identifier)
        dbc = DBCommand.from_model(c)
        dbc.device = device
        db.session.add(dbc)

    db.session.commit()