text
stringlengths
1
93.6k
# Allow user to specify log file name
log_file_name = input("Enter the log file name > ")
f = open("%s.txt" % log_file_name, "w+")
# Record the search summary of which keywords were used in the initial query
f.write("====== SEARCH SUMMARY ======")
f.write("\nInformant keyword used: %s" % inform_keyword)
if confirm_keywords != "":
f.write("\nConfirmation keywords used: %s" % confirm_keywords)
f.write("\n")
# Record the results log from Github code search
f.write("\n====== RESULTS LOG ======")
f.write(results_log_output)
# Record the unique repos discovered
f.write("\n====== DISCOVERED REPOS ======")
f.write(repo_list_results)
# If informant analysis was performed, record that as well
if informant_analysis_results != "":
f.write("\n\n====== INFORMANT ANALYSIS RESULTS ======")
f.write(informant_analysis_results)
print("\nResults have been logged!")
exit_banner()
f.close()
sys.exit(0)
else:
exit_banner()
sys.exit(0)
else:
exit_banner()
sys.exit(0)
def exit_banner():
print("\n============================================")
print("Thank you for using Gitformant! Goodbye...")
print("============================================")
def remove_dupes(seq):
# Order preserving remove duplicates from list function
checked = []
for e in seq:
if e not in checked:
checked.append(e)
return checked
def log_repo_list():
# Output list of discovered repos to user
repo_results = ""
for repo in remove_dupes(repos):
repo_results += "\n+ https://github.com/%s" % repo
return repo_results
def output(data, current_page):
# Check if the current page is greater than one, if so, update index accordingly
if current_page > 1:
count = current_page * 100 + 1
# But, if the current page is one, then at least 100 results
# have been returned, just add 1
elif current_page == 1:
count = 100 + 1
# Otherwise, we are at the beginning
else:
count = 1
# Display information about the file where the keyword march was found
# Show the owner and repository
output_results = ""
for snip in data[1]:
output_result = "\n%s. File: %s" % (str(count).zfill(2), snip['html_url'])
output_result += "\n Owner: %s" % snip['repository']['full_name']
output_result += "\n Repository: %s" % snip['repository']['html_url']
output_result += "\n"
output_results += output_result
count += 1
return output_results
def informant_analysis(repo_names, confirm_keywords):
print("\nStarting analysis, please wait...")
# For each unique repo, perform an analysis of how confident the assessment is of
# the confidentiality level
analysis_results = ""
for repo_name in remove_dupes(repos):
analysis_result = "\nRepository: https://github.com/%s" % repo_name
if confirm_keywords != "":
confirm_total = len(confirm_keywords)
confirm_success = 0
# For each keyword in the confirm_keywords list, check if there was a hit
# in the repository search
for keyword in confirm_keywords:
confirm_count = github_confirmation(repo_name, keyword)
analysis_result += "\nFound %s hit(s) for: %s" % (confirm_count, keyword)
if confirm_count != 0:
# Increment the successful confirm keyword hit counter
confirm_success += 1
# Confidence level is a measure of how many confirmation keywords were hit
# and how many in total were provided by the user
confidence_level = (float(confirm_success) / float(confirm_total)) * 100
# Depending on the percentage of keywords hit vs keywords provided,
# assign a description for level of confidence from VERY LOW to VERY HIGH
if confidence_level >= 75:
analysis_result += "\nConfidence level: VERY HIGH (%s%%)" % confidence_level
elif confidence_level >= 50:
analysis_result += "\nConfidence level: HIGH (%s%%)" % confidence_level