async def status(api, args): '''Determines the status of at least one challenge ''' if not args.yes and not cli.confirm('do you really want to check status?'): app_log.warning("operation cancelled by user.") return False err_sep = format_text(f'{HSEP[:35]} [STDERR] {HSEP[:35]}', 'red') out_sep = format_text(f'{HSEP[:35]} [STDOUT] {HSEP[:35]}', 'blue') exc_sep = format_text(f'{HSEP[:35]} [EXCEPT] {HSEP[:35]}', 'magenta') chall_sep = format_text(HSEP, 'blue', attrs=['bold']) success = True async for build_result in api.status(args.tags, args.slug, args.timeout): rcode = build_result['rcode'] chall_desc = format_text(f"{build_result['slug']}", 'blue') chall_status = format_rcode2str(rcode) print(chall_sep) print(f"{chall_desc} {chall_status}") if rcode < 0: success = False print(exc_sep) print(build_result['exception']) elif rcode > 0: print(out_sep) print(build_result['stdout'].decode().strip()) print(err_sep) print(build_result['stderr'].decode().strip()) return success
async def enum(api, args): '''Enumerates challenges ''' found = False for challenge in api.enum(tags=args.tags, categories=args.categories, slug=args.slug): slug, conf = challenge['slug'], challenge['conf'] if not found: found = True print("challenges:") if conf is None: app_log.error( f"configuration missing. Run `mkctf configure -s {slug}`") continue chall_entry = f"{TAB}- {slug} [{conf['category'].upper()}]" color = 'green' if conf['enabled'] else 'red' chall_entry = format_text(chall_entry, color, attrs=['bold']) del conf['slug'] del conf['enabled'] del conf['category'] description = challenge['description'] or format_text( 'empty description', 'red', attrs=['bold']) chall_details = format_dict2str(conf) chall_details += "\n+ description:" chall_details += indent(f"\n{HSEP}\n{description}\n{HSEP}", TAB) print(chall_entry) if not args.summarize: print(indent(chall_details[1:], TAB * 2)) if not found: app_log.warning("no challenge found.") return found
async def build(api, args): '''Builds at least one challenge ''' if not args.yes and confirm( 'do you really want to perform a build?') == Answer.NO: app_log.warning("operation cancelled by user.") return False err_sep = format_text(f'{HSEP[:35]} [STDERR] {HSEP[:35]}', 'red') out_sep = format_text(f'{HSEP[:35]} [STDOUT] {HSEP[:35]}', 'blue') exc_sep = format_text(f'{HSEP[:35]} [EXCEPT] {HSEP[:35]}', 'magenta') chall_sep = format_text(HSEP, 'blue', attrs=['bold']) success = True async for build_result in api.build(tags=args.tags, categories=args.categories, slug=args.slug, dev=args.dev, timeout=args.timeout): rcode = build_result['rcode'] chall_desc = format_text(f"{build_result['slug']}", 'blue') chall_status = api.rcode2str(rcode) print(chall_sep) print(f"{chall_desc} {chall_status}") if rcode < 0: success = False print(exc_sep) print(build_result['exception']) elif rcode > 0: print(out_sep) print(build_result['stdout'].decode().strip()) print(err_sep) print(build_result['stderr'].decode().strip()) return success
async def enum(api, args): '''Enumerates challenges ''' found = False print("challenges:") for challenge in api.enum(args.tags, args.slug): slug, conf = challenge['slug'], challenge['conf'] found = True if conf is None: app_log.error( f"configuration missing. Run `mkctf configure -s {slug}`") continue static = ' [STANDALONE]' if conf['standalone'] else '' chall_entry = f"{TAB}- {slug}{static}" color = 'green' if conf['enabled'] else 'red' chall_entry = format_text(chall_entry, color, attrs=['bold']) del conf['enabled'] del conf['standalone'] del conf['slug'] description = challenge['description'] or format_text( 'empty description', 'red', attrs=['bold']) text = format_dict2str(conf) text += "\n+ description:" text += indent(f"\n{HSEP}\n{description}\n{HSEP}", TAB) print(chall_entry) print(indent(text[1:], TAB * 2)) if not found: app_log.warning("no challenge found matching given constraints.") return found
def format(self, record): '''[summary] ''' os = super().format(record) return format_text(os, ColoredFormatter.COLORS[record.levelname])