diff --git a/nettacker/api/core.py b/nettacker/api/core.py index b86905bd3..6e5bf5e95 100644 --- a/nettacker/api/core.py +++ b/nettacker/api/core.py @@ -213,22 +213,83 @@ def profiles(): Returns: HTML content or available profiles """ - res = "" - for profile in sorted(Nettacker.load_profiles().keys()): - label = ( - "success" - if (profile == "scan") - else "warning" - if (profile == "brute") - else "danger" - if (profile == "vulnerability") - else "default" - ) + all_profiles = Nettacker.load_profiles() + if "all" in all_profiles: + del all_profiles["all"] + if "..." in all_profiles: + del all_profiles["..."] + + categories = { + "scan": { + "title": _("scan_modules_title"), + "desc": _("scan_modules_desc"), + "label": "success", + "profiles": [], + }, + "brute": { + "title": _("brute_modules_title"), + "desc": _("brute_modules_desc"), + "label": "warning", + "profiles": [], + }, + "vuln": { + "title": _("vuln_modules_title"), + "desc": _("vuln_modules_desc"), + "label": "danger", + "profiles": [], + }, + } + + for profile in sorted(all_profiles.keys()): + modules = all_profiles[profile] + cats = set(m.split("_")[-1] for m in modules) + + for cat in cats: + if cat in categories: + categories[cat]["profiles"].append(profile) + elif cat == "vulnerability" or cat == "vuln": + categories["vuln"]["profiles"].append(profile) + + # Dedup and sort + for cat in categories: + categories[cat]["profiles"] = sorted(list(set(categories[cat]["profiles"]))) + + res = """ +