def admin_mailer(device_id, violation_id, *args, **kwargs): TAG = 'admin mailer' base = DBHelper() cur = base.cursor log = Logger('AdminMailer') device = DeviceDBHelper() violation = ViolationsDBHelper() user = UserDBHelper() company = CompanyDBHelper() email_list = [] device_os_mapper = {'ios': 'iOS', 'samsung': 'android'} ### Device information ### device_info = device.get_device(str(device_id), status=True) if device_info: device_os = device_info.get('os') device_os = device_os_mapper.get(device_os) device_os_version = device_info.get('os_version') user_info = user.get_user(str(device_info.get('user_id'))) else: device_os = None device_os_version = None user_info = None ### User information ### if user_info: username = user_info.get('name') company_id = user_info.get('company_id') company_info = company.get_company(str(company_id)) else: username = None company_info = None company_id = None ### Violation information ### violation_info = violation.get_violation(str(violation_id)) if violation_info: violation_time = violation_info.get('timestamp') violation_time = violation_time.strftime('%d %b, %Y at %H:%M:%S') else: violation_time = None ### Company information ### if company_info: company_name = company_info.get('name') ### Query to get admin information for the particulat company ### try: cur.execute("""SELECT * FROM admin_profile WHERE company_id = {0}""".format(company_id)) except Exception as err: log.e(TAG, 'Exception : ' + repr(err)) if cur.rowcount > 0: rows = cur.fetchall() for row in rows: # ipdb.set_trace() email_list.append(row[1]) else: log.i( TAG, """No admin user found for the violated device with company id : {0}""".format(company_id)) print "Query over admin went wrong" else: company_name = None if len(email_list) > 0 and all( x is not None for x in ( username, company_name, violation_time, device_os)): message = loader.load('violation_mail.html').generate( username=username, company_name=company_name, violation_time=violation_time, device_os=device_os, device_os_version=device_os_version) try: ses_conn.send_email('*****@*****.**', 'User MDM Violations Notification', message, email_list, format='html') except Exception as err: log.e(TAG, "Error in sending mail from ses side.") else: log.i( TAG, """No admin found for the violated device with company id : {0}""".format(company_id))
def merge(self, device_id): user_helper = UserDBHelper() device_helper = DeviceDBHelper() roles_helper = RoleDBHelper() teams_helper = TeamDBHelper() company_helper = CompanyDBHelper() policy_helper = PolicyDBHelper() if device_id is not None: device_details = device_helper.get_device(device_id) if device_details is not None and 'user_id' in device_details: user_details = user_helper.get_user( str(device_details['user_id'])) team_id = user_details['team_id'] role_id = user_details['role_id'] company_id = user_details['company_id'] team_details = teams_helper.get_team(str(team_id)) role_details = roles_helper.get_role(str(role_id)) company_details = company_helper.get_company(str(company_id)) if user_details is not None and 'policy_id' in user_details: policy_id_user = user_details['policy_id'] else: print 'No user details found' if team_details is not None and 'policy_id' in team_details: policy_id_team = team_details['policy_id'] else: print 'no team details found' if role_details is not None and 'policy_id' in role_details: policy_id_role = role_details['policy_id'] else: print 'no role details found' if (company_details is not None and 'policy_id' in company_details): policy_id_company = company_details['policy_id'] else: print 'no company details found' if policy_id_company is not None: print 'company policy id=', policy_id_company policy_company = policy_helper.get_policy( str(policy_id_company)) else: policy_company = None if policy_id_role is not None: print 'role policy id=', policy_id_role policy_role = policy_helper.get_policy(str(policy_id_role)) else: policy_role = None if policy_id_team is not None: print 'team policy id=', policy_id_team policy_team = policy_helper.get_policy(str(policy_id_team)) else: policy_team = None if policy_id_user is not None: print 'user policy id=', policy_id_user policy_user = policy_helper.get_policy(str(policy_id_user)) else: policy_user = None return self.merge_policies( policy_company, policy_role, policy_team, policy_user) else: print 'Invalid device id'
def merge(self, device_id): user_helper = UserDBHelper() device_helper = DeviceDBHelper() roles_helper = RoleDBHelper() teams_helper = TeamDBHelper() company_helper = CompanyDBHelper() policy_helper = PolicyDBHelper() if device_id is not None: device_details = device_helper.get_device(device_id) if device_details is not None and 'user_id' in device_details: user_details = user_helper.get_user( str(device_details['user_id'])) team_id = user_details['team_id'] role_id = user_details['role_id'] company_id = user_details['company_id'] team_details = teams_helper.get_team(str(team_id)) role_details = roles_helper.get_role(str(role_id)) company_details = company_helper.get_company(str(company_id)) if user_details is not None and 'policy_id' in user_details: policy_id_user = user_details['policy_id'] else: print 'No user details found' if team_details is not None and 'policy_id' in team_details: policy_id_team = team_details['policy_id'] else: print 'no team details found' if role_details is not None and 'policy_id' in role_details: policy_id_role = role_details['policy_id'] else: print 'no role details found' if (company_details is not None and 'policy_id' in company_details): policy_id_company = company_details['policy_id'] else: print 'no company details found' if policy_id_company is not None: print 'company policy id=', policy_id_company policy_company = policy_helper.get_policy( str(policy_id_company)) else: policy_company = None if policy_id_role is not None: print 'role policy id=', policy_id_role policy_role = policy_helper.get_policy(str(policy_id_role)) else: policy_role = None if policy_id_team is not None: print 'team policy id=', policy_id_team policy_team = policy_helper.get_policy(str(policy_id_team)) else: policy_team = None if policy_id_user is not None: print 'user policy id=', policy_id_user policy_user = policy_helper.get_policy(str(policy_id_user)) else: policy_user = None return self.merge_policies(policy_company, policy_role, policy_team, policy_user) else: print 'Invalid device id'
def admin_mailer(device_id, violation_id, *args, **kwargs): TAG = 'admin mailer' base = DBHelper() cur = base.cursor log = Logger('AdminMailer') device = DeviceDBHelper() violation = ViolationsDBHelper() user = UserDBHelper() company = CompanyDBHelper() email_list = [] device_os_mapper = {'ios': 'iOS', 'samsung': 'android'} ### Device information ### device_info = device.get_device(str(device_id), status=True) if device_info: device_os = device_info.get('os') device_os = device_os_mapper.get(device_os) device_os_version = device_info.get('os_version') user_info = user.get_user(str(device_info.get('user_id'))) else: device_os = None device_os_version = None user_info = None ### User information ### if user_info: username = user_info.get('name') company_id = user_info.get('company_id') company_info = company.get_company(str(company_id)) else: username = None company_info = None company_id = None ### Violation information ### violation_info = violation.get_violation(str(violation_id)) if violation_info: violation_time = violation_info.get('timestamp') violation_time = violation_time.strftime('%d %b, %Y at %H:%M:%S') else: violation_time = None ### Company information ### if company_info: company_name = company_info.get('name') ### Query to get admin information for the particulat company ### try: cur.execute("""SELECT * FROM admin_profile WHERE company_id = {0}""".format(company_id)) except Exception as err: log.e(TAG, 'Exception : ' + repr(err)) if cur.rowcount > 0: rows = cur.fetchall() for row in rows: # ipdb.set_trace() email_list.append(row[1]) else: log.i( TAG, """No admin user found for the violated device with company id : {0}""".format(company_id)) print "Query over admin went wrong" else: company_name = None if len(email_list) > 0 and all( x is not None for x in (username, company_name, violation_time, device_os)): message = loader.load('violation_mail.html').generate( username=username, company_name=company_name, violation_time=violation_time, device_os=device_os, device_os_version=device_os_version) try: ses_conn.send_email('*****@*****.**', 'User MDM Violations Notification', message, email_list, format='html') except Exception as err: log.e(TAG, "Error in sending mail from ses side.") else: log.i( TAG, """No admin found for the violated device with company id : {0}""".format(company_id))
def admin_mailer(device_id, violation_id, *args, **kwargs): TAG='admin mailer' base = DBHelper() cur = base.cursor log = Logger('AdminMailer') device = DeviceDBHelper() violation = ViolationsDBHelper() user = UserDBHelper() company = CompanyDBHelper() email_list = [] device_os_mapper = {'ios': 'iOS', 'samsung': 'android'} ### Device information ### device_info = device.get_device(str(device_id), status=True) if device_info: device_os = device_info.get('os') device_os = device_os_mapper.get(device_os) device_os_version = device_info.get('os_version') user_info = user.get_user(str(device_info.get('user_id'))) else: device_os = None device_os_version = None user_info = None ### User information ### if user_info: username = user_info.get('name') company_id = user_info.get('company_id') company_info = company.get_company(str(company_id)) else: username = None company_info = None company_id = None ### Violation information ### violation_info = violation.get_violation(str(violation_id)) if violation_info: violation_time = violation_info.get('timestamp') violation_time = violation_time.strftime('%d %b, %Y at %H:%M:%S') else: violation_time = None ### Company information ### if company_info: company_name = company_info.get('name') ### Query to get admin information for the particulat company ### try: cur.execute("""SELECT * FROM admin_profile WHERE company_id = {0}""".format(company_id)) except Exception, err: log.e(TAG, 'Exception : ' + repr(err)) if cur.rowcount > 0: rows = cur.fetchall() for row in rows: #ipdb.set_trace() email_list.append(row[1]) else: log.i(TAG, """No admin user found for the violated device with company id : {0}""".format(company_id)) print "Query over admin went wrong"