created an interactive pause that you will be able to skip or exit from

This commit is contained in:
ekultek 2017-11-25 19:59:38 -06:00
parent ddf46c6bbe
commit 00da736256

View file

@ -101,15 +101,29 @@ def get_pgp_keys(url_list, query, attribute="pre", **kwargs):
proxy = kwargs.get("proxy", None)
xforward = kwargs.get("xforward", None)
verbose = kwargs.get("verbose", False)
amount_to_search = kwargs.get("search_amount", 75) # TODO:/ add a way to increase this
data_sep = "-" * 30
extracted_keys, identifiers = set(), []
# regex to match the beginning of a PGP key
identity_matcher = re.compile(r"\bbegin.pgp.public.key.block", re.I)
for url in url_list:
amount_left = len(url_list)
lib.core.settings.logger.info(lib.core.settings.set_color(
"checking a maximum of {} PGP keys...".format(amount_to_search)
))
for i, url in enumerate(url_list, start=1):
if i >= amount_to_search:
break
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"checking '{}'...".format(url), level=10
))
if i % 25 == 0:
lib.core.settings.logger.info(lib.core.settings.set_color(
"currently checking PGP key #{}, {} left to check ({} total found)...".format(
i, amount_to_search - i, amount_left
)
))
identifiers.append(lib.core.settings.PGP_IDENTIFIER_REGEX.search(str(url)).group())
req = requests.get(
url,
@ -125,7 +139,7 @@ def get_pgp_keys(url_list, query, attribute="pre", **kwargs):
extracted_keys.add(context)
for i, k in enumerate(extracted_keys):
pgp_key = str(k).split("<{}>".format(attribute)) # split the string by the tag
pgp_key = pgp_key[1].split("</{}>".format(attribute))[0] # split it against by an end tag
pgp_key = pgp_key[1].split("</{}>".format(attribute))[0] # split it again by the end tag
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"found PGP:", level=10
@ -139,36 +153,40 @@ def get_pgp_keys(url_list, query, attribute="pre", **kwargs):
def pgp_main(query, verbose=False):
try:
query = lib.core.settings.replace_http(query, queries=False, complete=True).split(".")[0]
# make sure the query isn't going to fail
except Exception:
query = query
lib.core.settings.logger.info(lib.core.settings.set_color(
"searching public PGP files with given query '{}'...".format(query)
))
try:
html = obtain_html(
lib.core.settings.AUTHORIZED_SEARCH_ENGINES["pgp"], query, agent=lib.core.settings.DEFAULT_USER_AGENT
)
except ReadTimeout:
lib.core.settings.logger.warning(lib.core.settings.set_color(
"connection timed out, assuming no PGP keys...", level=30
))
html = None
if html is not None:
urls = gather_urls(html)
try:
query = lib.core.settings.replace_http(query, queries=False, complete=True).split(".")[0]
# make sure the query isn't going to fail
except Exception:
query = query
lib.core.settings.logger.info(lib.core.settings.set_color(
"found a total of {} URLs...".format(len(urls))
"searching public PGP files with given query '{}'...".format(query)
))
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"found a '{}'...".format(urls), level=10
try:
html = obtain_html(
lib.core.settings.AUTHORIZED_SEARCH_ENGINES["pgp"], query, agent=lib.core.settings.DEFAULT_USER_AGENT
)
except ReadTimeout:
lib.core.settings.logger.warning(lib.core.settings.set_color(
"connection timed out, assuming no PGP keys...", level=30
))
lib.core.settings.logger.info(lib.core.settings.set_color(
"gathering PGP key(s) and writing to a file...", level=25
))
return get_pgp_keys(urls, query, verbose=verbose)
else:
lib.core.settings.logger.warning(lib.core.settings.set_color(
"did not find anything using query '{}'...".format(query), level=30
))
html = None
if html is not None:
urls = gather_urls(html)
lib.core.settings.logger.info(lib.core.settings.set_color(
"found a total of {} URLs...".format(len(urls))
))
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"found a '{}'...".format(urls), level=10
))
lib.core.settings.logger.info(lib.core.settings.set_color(
"gathering PGP key(s) and writing to a file...", level=25
))
return get_pgp_keys(urls, query, verbose=verbose)
else:
lib.core.settings.logger.warning(lib.core.settings.set_color(
"did not find anything using query '{}'...".format(query), level=30
))
except KeyboardInterrupt:
if not lib.core.common.pause():
lib.core.common.shutdown()