Skip to content

Commit

Permalink
Feature: improved style of headers enabled when exporting to PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc-st committed Nov 22, 2024
1 parent 102665a commit 7168941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a target="_blank" href="https://www.python.org/downloads/" title="Minimum Python version required to run this tool"><img src="https://img.shields.io/badge/Python-%3E%3D3.8-blue?labelColor=343b41"></a>
<a target="_blank" href="LICENSE" title="License of this tool"><img src="https://img.shields.io/badge/License-MIT-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/releases" title="Latest release of this tool"><img src="https://img.shields.io/github/v/release/rfc-st/humble?display_name=release&label=Latest%20Release&labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/commits/master" title="Latest commit of this tool"><img src="https://img.shields.io/badge/Latest_Commit-2024--11--21-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/commits/master" title="Latest commit of this tool"><img src="https://img.shields.io/badge/Latest_Commit-2024--11--22-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/actions?query=workflow%3ACodeQL" title="Results of the last analysis of this tool with CodeQL"><img src="https://github.com/rfc-st/humble/workflows/CodeQL/badge.svg"></a>
<a target="_blank" href="https://pkg.kali.org/pkg/humble" title="Official tool in Kali Linux"><img src="https://img.shields.io/badge/Kali%20Linux-Tool-blue?labelColor=343b41"></a>
<br />
Expand Down
36 changes: 24 additions & 12 deletions humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
URL_STRING = ('rfc-st', ' URL : ', 'caniuse')

current_time = datetime.now().strftime("%Y/%m/%d - %H:%M:%S")
local_version = datetime.strptime('2024-11-21', '%Y-%m-%d').date()
local_version = datetime.strptime('2024-11-22', '%Y-%m-%d').date()


class SSLContextAdapter(requests.adapters.HTTPAdapter):
Expand Down Expand Up @@ -836,9 +836,7 @@ def get_enabled_headers(args, headers_l, l_secure):
sec_headers = [header for header in l_secure if header in headers_d]
for header in sec_headers:
print_enabled_headers(args, header, headers_d)
if not sec_headers:
print_detail_l('[no_sec_headers]') if args.output else \
print_detail_r('[no_sec_headers]', is_red=True)
print_nosec_headers(args) if not sec_headers else None
print('\n')


Expand All @@ -856,6 +854,11 @@ def print_enabled_headers(args, header, headers_d):
{headers_d[header]}')


def print_nosec_headers(args):
print_detail_l('[no_sec_headers]') if args.output else \
print_detail_r('[no_sec_headers]', is_red=True)


def print_missing_headers(args, headers_l, l_detail, l_miss):
m_cnt = 0
headers_set = set(headers_l)
Expand Down Expand Up @@ -1192,8 +1195,8 @@ def set_pdf_links(i, pdf_string):

def set_pdf_color(pdf, line):
if re.search(RE_PATTERN[10], line):
line = f" {line[19:]}"
pdf.set_text_color(0, 128, 0)
set_pdf_style(pdf, line)
return
elif re.search(RE_PATTERN[7], line):
line = f" {line[19:]}"
pdf.set_text_color(102, 0, 51)
Expand All @@ -1202,6 +1205,18 @@ def set_pdf_color(pdf, line):
pdf.multi_cell(197, 6, text=line, align='L', new_y=YPos.LAST)


def set_pdf_style(pdf, line):
pdf_line = line[19:]
c_index = pdf_line.find(': ')
if c_index != -1:
ln_header = f'<font color="#008000">{pdf_line[:c_index + 2]}</font>'
ln_value = f'<font color="#000000">{pdf_line[c_index + 2:]}</font>'
ln_final = f"&nbsp;{ln_header}{ln_value}<br><br>"
else:
ln_final = f'&nbsp;<font color="#008000">{pdf_line}</font><br><br>'
pdf.write_html(ln_final)


def generate_html():
copyfile(path.join(OS_PATH, HUMBLE_DIRS[0], HUMBLE_FILES[8]),
final_filename)
Expand Down Expand Up @@ -2391,11 +2406,8 @@ def custom_help_formatter(prog):

compat_headers = sorted(header for header in t_sec if header in headers)

if compat_headers:
print_browser_compatibility(compat_headers)
else:
print_detail_l('[no_sec_headers]') if args.output else \
print_detail_r('[no_sec_headers]', is_red=True)
print_browser_compatibility(compat_headers) if compat_headers else \
print_nosec_headers(args)

# Analysis summary and changes with respect to the previous one
print(linesep.join(['']*2))
Expand Down Expand Up @@ -2423,7 +2435,7 @@ class PDF(FPDF):

def header(self):
self.set_font('Courier', 'B', 9)
self.set_y(15)
self.set_y(5)
self.set_text_color(0, 0, 0)
self.cell(0, 5, get_detail('[pdf_title]'), new_x="CENTER",
new_y="NEXT", align='C')
Expand Down

0 comments on commit 7168941

Please sign in to comment.