예제 #1
0
def update_certs_by_accounts(accounts=None):
    if accounts == "all":
        account_array = HostedAccount().get_airwatch_account_ids()
    else:
        account_array = accounts.split(',')

    if verbose > 0:
        print "MDMi enabled accounts: %s" % account_array

    thread_list = []
    device_total = []
    for account_id in account_array:
        hosted_device = HostedDevice()
        idx = 0
        max = 100
        total = 0
        try:
            while idx >= 0:
                result = hosted_device.do_get_many(idx, max, 'account', account=account_id, deviceEnrollmentStatus='1')
                if result.code >= 200 and result.code < 300:
                    device_list = json.loads(result.content)
                    for device in device_list:
                        #udid = device['attributes']['UDID'][0]
                        device_total.append(device)
                    if len(device_list) == max:
                        idx = idx + 1
                    else:
                        idx = -1
        except Exception, e:
            print "Failed to update the certificate for the account: %s, error message: %s\n" % (account_id, str(e))
        finally:
예제 #2
0
    def _account_ins(self):
        cnt_need_update = self.dev_update_queue.qsize()
        if (cnt_need_update == 0):
            return cnt_need_update
        cnt_result = 0

        while (self.dev_update_queue.qsize() > 0):  # make sure the queue is not empty
            dev = self.dev_update_queue.get(True)  # get by block
            try:
                owner = dev['attributes'].get('deviceOwner', [''])[0]
                udid = dev['attributes'].get('UDID', [''])[0]
                if len(owner) > 0:
                    aidobj = HostedAccount()
                    account = aidobj.get_account_id(**{'objectClass':'hostedUser', 'mail' : owner}) #only hosted user for MDMi
                    if account:
                        devobj = HostedDevice(udid)
                        data = devobj.format_update_data(None, 'replace', account=account[0])
                        result = devobj.do_update(attributes=data)
                        del devobj
                        if result.code >= 200 and result.code < 300:
                            cnt_result = cnt_result + 1
                    del aidobj
            except Exception, e:
                logger.error('Insert account error:%s' % repr(e))
                pass
예제 #3
0
def do_update(udid, device=None):
    try:
        if not device:
            hostedDevice = HostedDevice(udid)
            result = hostedDevice.do_get()
            device = json.loads(result.content)[0]

        if verbose > 0:
            print "Starting off update the certification for the device: %s" % udid
            print "Device information: %s" % str(device)

        device_attr = device['attributes']
        profile_id = device_attr['mdmProfileId'][0]
        account_id = device_attr['account'][0]
        if verbose > 0:
            print "The profile id for this device: %s" % profile_id

        if AirwatchVPNProfile(account_id).install_profile_by_udid(profile_id, udid):
            print "Succeeded in certificate update for the device: %s\n" % udid
        else:
            queue.put(udid)
            print "Failed to update the certificate for the device: %s\n" % udid
    except Exception, e:
        queue.put(udid)
        print "Failed to update the certificate for the device: %s, error message: %s\n" % (udid, str(e))
예제 #4
0
파일: common.py 프로젝트: lls3018/mdmi
def get_device_info(serial_number):
    if not type(serial_number) == str:
        raise Exception('device serial number invalid')

    hosted_device = HostedDevice()
    dev_info = hosted_device.get_device_by_serial_number(serial_number)
    logger.debug('get dev info: %s' % dev_info)
    dev_info = dev_info['attributes']

    dev_owner = ''
    account_id = ''
    mdm_profile_id = ''

    if isinstance(dev_info, dict):
        if isinstance(dev_info['deviceOwner'], list) and len(dev_info['deviceOwner']) > 0:
            dev_owner = dev_info['deviceOwner'][0]
        else:
            dev_owner = dev_info['deviceOwner']

        if isinstance(dev_info['account'], list) and len(dev_info['account']) > 0:
            account_id = dev_info['account'][0]
        else:
            account_id = dev_info['account']

        if isinstance(dev_info['mdmProfileId'], list) and len(dev_info['mdmProfileId']) > 0:
            mdm_profile_id = dev_info['mdmProfileId'][0]
        else:
            mdm_profile_id = dev_info['mdmProfileId']
    else:
        logger.error('device info invalid: %s'% dev_info)
        raise Exception('device info type invalid')

    return dev_owner,account_id, mdm_profile_id
예제 #5
0
파일: tools_base.py 프로젝트: lls3018/mdmi
    def _sync_devinfo(self, udid, devinfo):
        #remove invalid keys and values
        dev_item = dict(devinfo)  #copy one to keep input not be changed.
        for k in dev_item.keys():
            if not dev_item[k]:  #include '' and None
                del dev_item[k]

        devobj = HostedDevice(udid)
        dev_data = devobj.format_update_data(None, 'replace', **dev_item)
        logger.info('Update device information! UDID:%s, data:%s' %
                    (str(udid), repr(dev_data)))
        try:
            result = devobj.do_update(attributes=dev_data)
            if result.code >= 200 and result.code < 300:
                logger.info('Update device %s information success!' %
                            str(udid))
                return 0
            else:
                logger.error('Update device %s information failed!' %
                             str(udid))
                return -1
        except Exception, e:
            logger.error('Update device information failed! error:%s' %
                         repr(e))
            return -1
예제 #6
0
	def get_devices(self):
		'''
			get devices from RS, return all the devices that vpn will expire in 7 days
		'''
		device = HostedDevice()
		rtn = 1
		page_num = 0
		page_size = 400
		while rtn > 0:
			result = device.do_get_many(page_num, page_size, 'devicePlatform')
			page_num += 1
			val = json.loads(result.content)
			self.parse_expire_device(val)
			rtn = len(val)
		self.save_expire_device()
		self.record_retrieve_date()
예제 #7
0
파일: tools_base.py 프로젝트: lls3018/mdmi
 def _get_devinfo_from_rs(self, max, **attributes):
     # return number of the device needed to be updated.
     rs_dev = HostedDevice()
     idx = 0
     total = 0
     try:
         while idx >= 0:
             result = rs_dev.do_get_many(idx, max, 'account', **attributes)
             if result.code >= 200 and result.code < 300:
                 length = self._dispatch_original_devinfo(result.content, self.devinfo_original_queue)
                 if length == max:
                     idx = idx + 1  # more
                 else:
                     idx = -1  # get all
                 total = total + length
         return total
     except Exception, e:
         logger.error('Get device information from RS error! %s' % repr(e))
         return total
예제 #8
0
파일: tools_base.py 프로젝트: lls3018/mdmi
 def _get_devinfo_from_rs(self, max, **attributes):
     # return number of the device needed to be updated.
     rs_dev = HostedDevice()
     idx = 0
     total = 0
     try:
         while idx >= 0:
             result = rs_dev.do_get_many(idx, max, 'account', **attributes)
             if result.code >= 200 and result.code < 300:
                 length = self._dispatch_original_devinfo(
                     result.content, self.devinfo_original_queue)
                 if length == max:
                     idx = idx + 1  # more
                 else:
                     idx = -1  # get all
                 total = total + length
         return total
     except Exception, e:
         logger.error('Get device information from RS error! %s' % repr(e))
         return total
예제 #9
0
파일: tools_base.py 프로젝트: lls3018/mdmi
 def _sync_devinfo(self, udid, devinfo):
     #remove invalid keys and values
     dev_item = dict(devinfo) #copy one to keep input not be changed.
     for k in dev_item.keys():
         if not dev_item[k]: #include '' and None
             del dev_item[k]
             
     devobj = HostedDevice(udid)
     dev_data = devobj.format_update_data(None, 'replace', **dev_item)
     logger.info('Update device information! UDID:%s, data:%s' % (str(udid), repr(dev_data)))
     try:
         result = devobj.do_update(attributes=dev_data)
         if result.code >= 200 and result.code < 300:
             logger.info('Update device %s information success!' % str(udid))
             return 0
         else:
             logger.error('Update device %s information failed!' % str(udid))
             return -1
     except Exception, e:
         logger.error('Update device information failed! error:%s' % repr(e))
         return -1
예제 #10
0
파일: common.py 프로젝트: lls3018/mdmi
def get_device_info(serial_number):
    if not type(serial_number) == str:
        raise Exception('device serial number invalid')

    hosted_device = HostedDevice()
    dev_info = hosted_device.get_device_by_serial_number(serial_number)
    logger.debug('get dev info: %s' % dev_info)
    dev_info = dev_info['attributes']

    dev_owner = ''
    account_id = ''
    mdm_profile_id = ''

    if isinstance(dev_info, dict):
        if isinstance(dev_info['deviceOwner'],
                      list) and len(dev_info['deviceOwner']) > 0:
            dev_owner = dev_info['deviceOwner'][0]
        else:
            dev_owner = dev_info['deviceOwner']

        if isinstance(dev_info['account'],
                      list) and len(dev_info['account']) > 0:
            account_id = dev_info['account'][0]
        else:
            account_id = dev_info['account']

        if isinstance(dev_info['mdmProfileId'],
                      list) and len(dev_info['mdmProfileId']) > 0:
            mdm_profile_id = dev_info['mdmProfileId'][0]
        else:
            mdm_profile_id = dev_info['mdmProfileId']
    else:
        logger.error('device info invalid: %s' % dev_info)
        raise Exception('device info type invalid')

    return dev_owner, account_id, mdm_profile_id