Merge pull request #1218 from nblanke/color-refactor

Refactoring of the no-color flag
pull/1271/head
Siddharth Dushantha 3 years ago committed by GitHub
commit 28b49ef898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,10 +4,10 @@ This module defines the objects for notifying the caller about the
results of queries. results of queries.
""" """
from result import QueryStatus from result import QueryStatus
from colorama import Fore, Style, init from colorama import Fore, Style
class QueryNotify(): class QueryNotify:
"""Query Notify Object. """Query Notify Object.
Base class that describes methods available to notify the results of Base class that describes methods available to notify the results of
@ -15,6 +15,7 @@ class QueryNotify():
It is intended that other classes inherit from this base class and It is intended that other classes inherit from this base class and
override the methods to implement specific functionality. override the methods to implement specific functionality.
""" """
def __init__(self, result=None): def __init__(self, result=None):
"""Create Query Notify Object. """Create Query Notify Object.
@ -110,7 +111,8 @@ class QueryNotifyPrint(QueryNotify):
Query notify class that prints results. Query notify class that prints results.
""" """
def __init__(self, result=None, verbose=False, color=True, print_all=False):
def __init__(self, result=None, verbose=False, print_all=False):
"""Create Query Notify Print Object. """Create Query Notify Print Object.
Contains information about a specific method of notifying the results Contains information about a specific method of notifying the results
@ -122,19 +124,14 @@ class QueryNotifyPrint(QueryNotify):
results for this query. results for this query.
verbose -- Boolean indicating whether to give verbose output. verbose -- Boolean indicating whether to give verbose output.
print_all -- Boolean indicating whether to only print all sites, including not found. print_all -- Boolean indicating whether to only print all sites, including not found.
color -- Boolean indicating whether to color terminal output
Return Value: Return Value:
Nothing. Nothing.
""" """
# Colorama module's initialization.
init(autoreset=True)
super().__init__(result) super().__init__(result)
self.verbose = verbose self.verbose = verbose
self.print_all = print_all self.print_all = print_all
self.color = color
return return
@ -153,14 +150,11 @@ class QueryNotifyPrint(QueryNotify):
""" """
title = "Checking username" title = "Checking username"
if self.color: print(Style.BRIGHT + Fore.GREEN + "[" +
print(Style.BRIGHT + Fore.GREEN + "[" + Fore.YELLOW + "*" +
Fore.YELLOW + "*" + Fore.GREEN + f"] {title}" +
Fore.GREEN + f"] {title}" + Fore.WHITE + f" {message}" +
Fore.WHITE + f" {message}" + Fore.GREEN + " on:")
Fore.GREEN + " on:")
else:
print(f"[*] {title} {message} on:")
return return
@ -186,53 +180,41 @@ class QueryNotifyPrint(QueryNotify):
# Output to the terminal is desired. # Output to the terminal is desired.
if result.status == QueryStatus.CLAIMED: if result.status == QueryStatus.CLAIMED:
if self.color: print(Style.BRIGHT + Fore.WHITE + "[" +
print((Style.BRIGHT + Fore.WHITE + "[" + Fore.GREEN + "+" +
Fore.GREEN + "+" + Fore.WHITE + "]" +
Fore.WHITE + "]" + response_time_text +
response_time_text + Fore.GREEN +
Fore.GREEN + f" {self.result.site_name}: " +
f" {self.result.site_name}: " + Style.RESET_ALL +
Style.RESET_ALL + f"{self.result.site_url_user}")
f"{self.result.site_url_user}"))
else:
print(f"[+]{response_time_text} {self.result.site_name}: {self.result.site_url_user}")
elif result.status == QueryStatus.AVAILABLE: elif result.status == QueryStatus.AVAILABLE:
if self.print_all: if self.print_all:
if self.color: print(Style.BRIGHT + Fore.WHITE + "[" +
print((Style.BRIGHT + Fore.WHITE + "[" + Fore.RED + "-" +
Fore.RED + "-" + Fore.WHITE + "]" +
Fore.WHITE + "]" + response_time_text +
response_time_text + Fore.GREEN + f" {self.result.site_name}:" +
Fore.GREEN + f" {self.result.site_name}:" + Fore.YELLOW + " Not Found!")
Fore.YELLOW + " Not Found!"))
else:
print(f"[-]{response_time_text} {self.result.site_name}: Not Found!")
elif result.status == QueryStatus.UNKNOWN: elif result.status == QueryStatus.UNKNOWN:
if self.print_all: if self.print_all:
if self.color: print(Style.BRIGHT + Fore.WHITE + "[" +
print(Style.BRIGHT + Fore.WHITE + "[" + Fore.RED + "-" +
Fore.RED + "-" + Fore.WHITE + "]" +
Fore.WHITE + "]" + Fore.GREEN + f" {self.result.site_name}:" +
Fore.GREEN + f" {self.result.site_name}:" + Fore.RED + f" {self.result.context}" +
Fore.RED + f" {self.result.context}" + Fore.YELLOW + f" ")
Fore.YELLOW + f" ")
else:
print(f"[-] {self.result.site_name}: {self.result.context} ")
elif result.status == QueryStatus.ILLEGAL: elif result.status == QueryStatus.ILLEGAL:
if self.print_all: if self.print_all:
msg = "Illegal Username Format For This Site!" msg = "Illegal Username Format For This Site!"
if self.color: print(Style.BRIGHT + Fore.WHITE + "[" +
print((Style.BRIGHT + Fore.WHITE + "[" + Fore.RED + "-" +
Fore.RED + "-" + Fore.WHITE + "]" +
Fore.WHITE + "]" + Fore.GREEN + f" {self.result.site_name}:" +
Fore.GREEN + f" {self.result.site_name}:" + Fore.YELLOW + f" {msg}")
Fore.YELLOW + f" {msg}"))
else:
print(f"[-] {self.result.site_name} {msg}")
else: else:
# It should be impossible to ever get here... # It should be impossible to ever get here...

@ -23,6 +23,7 @@ from result import QueryStatus
from result import QueryResult from result import QueryResult
from notify import QueryNotifyPrint from notify import QueryNotifyPrint
from sites import SitesInformation from sites import SitesInformation
from colorama import init
module_name = "Sherlock: Find Usernames Across Social Networks" module_name = "Sherlock: Find Usernames Across Social Networks"
__version__ = "0.14.0" __version__ = "0.14.0"
@ -591,7 +592,14 @@ def main():
if args.tor or args.unique_tor: if args.tor or args.unique_tor:
print("Using Tor to make requests") print("Using Tor to make requests")
print("Warning: some websites might refuse connecting over Tor, so note that using this option might increase connection errors.") print("Warning: some websites might refuse connecting over Tor, so note that using this option might increase connection errors.")
if args.no_color:
# Disable color output.
init(strip=True, convert=False)
else:
# Enable color output.
init(autoreset=True)
# Check if both output methods are entered as input. # Check if both output methods are entered as input.
if args.output is not None and args.folderoutput is not None: if args.output is not None and args.folderoutput is not None:
print("You can only use one of the output methods.") print("You can only use one of the output methods.")
@ -648,8 +656,7 @@ def main():
# Create notify object for query results. # Create notify object for query results.
query_notify = QueryNotifyPrint(result=None, query_notify = QueryNotifyPrint(result=None,
verbose=args.verbose, verbose=args.verbose,
print_all=args.print_all, print_all=args.print_all)
color=not args.no_color)
# Run report on all specified users. # Run report on all specified users.
for username in args.username: for username in args.username:

Loading…
Cancel
Save