def print_debug(error_level, message): b = bcolors() # print when password is found if error_level == 'OK': print b.OK + message + b.ENDC # print when password is not found elif error_level == 'FAILED': print b.FAIL + message + b.ENDC # print messages depending of their criticism elif error_level == 'CRITICAL': logging.error(b.FAIL + '[CRITICAL] ' + message + '\n' + b.ENDC) elif error_level == 'ERROR': logging.error(b.FAIL + '[ERROR] ' + message + '\n' + b.ENDC) elif error_level == 'WARNING': logging.warning(b.WARNING + message + '\n' + b.ENDC) elif error_level == 'DEBUG': logging.debug(message + '\n') elif error_level == 'INFO': logging.info(message + '\n') else: logging.info('[%s] %s' % (error_level, message))
def parseJsonResultToBuffer(jsonString, color=False): green = '' reset = '' title = '' if color: b = bcolors() green = b.OK title = b.TITLE reset = b.ENDC buffer = '' try: for json in jsonString: if json: if 'Passwords' not in json: buffer += 'No passwords found for this user !' else: for all_passwords in json['Passwords']: buffer += '{title_color}------------------- {password_category} -----------------{reset_color}\r\n'.format(title_color=title, password_category=all_passwords[0]['Category'], reset_color=reset) for password_by_category in all_passwords[1]: buffer += '\r\n{green_color}Password found !!!{reset_color}\r\n'.format(green_color=green, reset_color=reset) constant.nbPasswordFound += 1 for dic in password_by_category.keys(): try: buffer += '%s: %s\r\n' % (dic, password_by_category[dic].encode('utf-8')) except: buffer += '%s: %s\r\n' % (dic, password_by_category[dic].encode(encoding='utf-8',errors='replace')) buffer += '\r\n' except Exception as e: print_debug('ERROR', 'Error parsing the json results: %s' % e) print_debug('ERROR', 'json content: %s' % jsonString) return buffer
def print_debug(error_level, message): b = bcolors() # print when password is found if error_level == "OK": print b.OK + message + b.ENDC # print when password is not found elif error_level == "FAILED": print b.FAIL + message + b.ENDC # print messages depending of their criticism elif error_level == "CRITICAL": logging.error(b.FAIL + "[CRITICAL] " + message + "\n" + b.ENDC) elif error_level == "ERROR": logging.error(b.FAIL + "[ERROR] " + message + "\n" + b.ENDC) elif error_level == "WARNING": logging.warning(b.WARNING + message + "\n" + b.ENDC) elif error_level == "DEBUG": logging.debug(message + "\n") elif error_level == "INFO": logging.info(message + "\n") else: logging.info("[%s] %s" % (error_level, message))
def parseJsonResultToBuffer(jsonString, color=False): green = '' reset = '' title = '' if color: b = bcolors() green = b.OK title = b.TITLE reset = b.ENDC buffer = '' try: for json in jsonString: if json: if 'Passwords' not in json: buffer += 'No passwords found for this user !' else: for all_passwords in json['Passwords']: buffer += '{title_color}------------------- {password_category} -----------------{reset_color}\r\n'.format( title_color=title, password_category=all_passwords[0]['Category'], reset_color=reset) for password_by_category in all_passwords[1]: buffer += '\r\n{green_color}Password found !!!{reset_color}\r\n'.format( green_color=green, reset_color=reset) constant.nbPasswordFound += 1 for dic in password_by_category.keys(): try: buffer += '%s: %s\r\n' % ( dic, password_by_category[dic].encode( 'utf-8')) except: buffer += '%s: %s\r\n' % ( dic, password_by_category[dic].encode( encoding='utf-8', errors='replace')) buffer += '\r\n' except Exception as e: print_debug('ERROR', 'Error parsing the json results: %s' % e) print_debug('ERROR', 'json content: %s' % jsonString) return buffer