Merge pull request #140 from leebaird/master

Code review of lib directory.
This commit is contained in:
Matt 2018-12-29 11:48:50 -05:00 committed by GitHub
commit f9352844ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 127 additions and 166 deletions

0
lib/__init__.py Normal file → Executable file
View file

194
lib/graphs.py Normal file → Executable file
View file

@ -26,26 +26,25 @@
=====================================================================================================
"""
import re
import math
import re
class BarGraph:
"""creates horizontal and vertical bar graphs, progress bars and faders"""
"""Creates horizontal and vertical bar graphs, progress bars, and faders."""
def __init__(self, type=''):
#-------------------------------------------------------------------------
# Configuration
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Configuration
#-------------------------------------------------------------------------
# graph type: "hBar", "vBar", "pBar", or "fader"
self.type = type and type or 'hBar'
self.values = [] # graph data: list
# graph background color: string
self.graphBGColor = ''
# graph border: string (CSS-spec: "size style color"; doesn't work with
# NN4)
# graph border: string (CSS-spec: "size style color"; doesn't work with NN4)
self.graphBorder = ''
# graph padding: integer (pixels)
self.graphPadding = 0
@ -90,11 +89,9 @@ def __init__(self, type=''):
self.barColors = []
# bar background color: string
self.barBGColor = ''
# bar border: string (CSS-spec: "size style color"; doesn't work with
# NN4)
# bar border: string (CSS-spec: "size style color"; doesn't work with NN4)
self.barBorder = '2px outset white'
# bar level colors: ascending list (bLevel, bColor[,...]); draw bars >=
# bLevel with bColor
# bar level colors: ascending list (bLevel, bColor[,...]); draw bars >= bLevel with bColor
self.barLevelColors = []
# show values: 0 = % only, 1 = abs. and %, 2 = abs. only, 3 = none
@ -106,8 +103,7 @@ def __init__(self, type=''):
self.absValuesColor = 'black'
# abs. values background color: string
self.absValuesBGColor = '#C0E0FF'
# abs. values border: string (CSS-spec: "size style color"; doesn't
# work with NN4)
# abs. values border: string (CSS-spec: "size style color"; doesn't work with NN4)
self.absValuesBorder = '2px groove white'
# abs. values font family: string (CSS-spec)
self.absValuesFont = 'Arial, Helvetica'
@ -135,8 +131,7 @@ def __init__(self, type=''):
self.legendColor = 'black' # legend font color: string
# legend background color: string
self.legendBGColor = '#F0F0F0'
# legend border: string (CSS-spec: "size style color"; doesn't work
# with NN4)
# legend border: string (CSS-spec: "size style color"; doesn't work with NN4)
self.legendBorder = '2px groove white'
# legend font family: string (CSS-spec)
self.legendFont = 'Arial, Helvetica'
@ -147,7 +142,7 @@ def __init__(self, type=''):
# debug mode: 0 = off, 1 = on; just views some extra information
self.debug = 0
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# default bar colors; only used if barColors isn't set
__colors = (
@ -158,10 +153,10 @@ def __init__(self, type=''):
'#FFA0A0',
'#00A000')
# error messages
# Error messages.
__err_type = 'ERROR: Type must be "hBar", "vBar", "pBar", or "fader"'
# CSS names (don't change)
# CSS names (don't change).
__cssGRAPH = ''
__cssBAR = ''
__cssBARBG = ''
@ -173,7 +168,7 @@ def __init__(self, type=''):
__cssABSVALUES = ''
__cssPERCVALUES = ''
# search pattern for images
# Search pattern for images.
__img_pattern = re.compile(r'\.(jpg|jpeg|jpe|gif|png)')
def set_styles(self):
@ -223,29 +218,25 @@ def set_styles(self):
if self.legendSize:
self.__cssLEGEND += 'font-size:' + str(self.legendSize) + 'px;'
if self.legendBGColor:
self.__cssLEGENDBG += 'background-color:' + \
self.legendBGColor + ';'
self.__cssLEGENDBG += 'background-color:' + self.legendBGColor + ';'
if self.legendBorder:
self.__cssLEGENDBG += 'border:' + self.legendBorder + ';'
if self.absValuesColor:
self.__cssABSVALUES += 'color:' + self.absValuesColor + ';'
if self.absValuesBGColor:
self.__cssABSVALUES += 'background-color:' + \
self.absValuesBGColor + ';'
self.__cssABSVALUES += 'background-color:' + self.absValuesBGColor + ';'
if self.absValuesBorder:
self.__cssABSVALUES += 'border:' + self.absValuesBorder + ';'
if self.absValuesFont:
self.__cssABSVALUES += 'font-family:' + self.absValuesFont + ';'
if self.absValuesSize:
self.__cssABSVALUES += 'font-size:' + \
str(self.absValuesSize) + 'px;'
self.__cssABSVALUES += 'font-size:' + str(self.absValuesSize) + 'px;'
if self.percValuesColor:
self.__cssPERCVALUES += 'color:' + self.percValuesColor + ';'
if self.percValuesFont:
self.__cssPERCVALUES += 'font-family:' + self.percValuesFont + ';'
if self.percValuesSize:
self.__cssPERCVALUES += 'font-size:' + \
str(self.percValuesSize) + 'px;'
self.__cssPERCVALUES += 'font-size:' + str(self.percValuesSize) + 'px;'
def level_color(self, value, color):
"""return bar color for each level"""
@ -253,7 +244,7 @@ def level_color(self, value, color):
for i in range(0, len(self.barLevelColors), 2):
try:
if (self.barLevelColors[i] > 0 and value >= self.barLevelColors[i]) or \
(self.barLevelColors[i] < 0 and value <= self.barLevelColors[i]):
(self.barLevelColors[i] < 0 and value <= self.barLevelColors[i]):
color = self.barLevelColors[i + 1]
except IndexError:
pass
@ -266,8 +257,7 @@ def build_bar(self, value, width, height, color):
bar = '<table border=0 cellspacing=0 cellpadding=0><tr>'
bar += '<td style="' + self.__cssBAR + '" ' + bg + '="' + color + '"'
bar += (value != '') and ' title="' + title + '">' or '>'
bar += '<div style="width:' + \
str(width) + 'px; height:' + str(height) + 'px;'
bar += '<div style="width:' + str(width) + 'px; height:' + str(height) + 'px;'
bar += ' line-height:1px; font-size:1px;"></div>'
bar += '</td></tr></table>'
return bar
@ -291,11 +281,9 @@ def build_value(self, val, max_dec, sum=0, align=''):
if align:
value += ' align=' + align
value += ' nowrap>'
value += '&nbsp;' + self.absValuesPrefix + \
str(val) + self.absValuesSuffix
value += '&nbsp;' + self.absValuesPrefix + str(val) + self.absValuesSuffix
if sum:
value += ' / ' + self.absValuesPrefix + \
str(sum) + self.absValuesSuffix
value += ' / ' + self.absValuesPrefix + str(sum) + self.absValuesSuffix
value += '&nbsp;</td>'
return value
@ -317,13 +305,12 @@ def build_legend(self, barColors):
text = ''
legend += '<tr>'
legend += '<td>' + \
self.build_bar(
'',
self.barWidth,
self.barWidth,
color) + '</td>'
legend += '<td style="' + self.__cssLEGEND + \
'" nowrap>' + text + '</td>'
self.build_bar(
'',
self.barWidth,
self.barWidth,
color) + '</td>'
legend += '<td style="' + self.__cssLEGEND + '" nowrap>' + text + '</td>'
legend += '</tr>'
i += 1
@ -336,7 +323,7 @@ def build_hTitle(self, titleLabel, titleValue, titleBar):
title += '<td style="' + self.__cssTITLE + '">' + titleLabel + '</td>'
if titleValue != '':
title += '<td style="' + self.__cssTITLE + \
'">' + titleValue + '</td>'
'">' + titleValue + '</td>'
title += '<td style="' + self.__cssTITLE + '">' + titleBar + '</td>'
title += '</tr>'
return title
@ -349,36 +336,29 @@ def create_hBar(self, value, percent, mPerc, mPerc_neg,
if percent < 0:
percent *= -1
bar += '<td style="' + self.__cssLABELBG + '" height=' + \
str(self.barWidth) + ' width=' + \
str(int(round((mPerc_neg - percent) * mul + valSpace))) + \
' align=right nowrap>'
str(self.barWidth) + ' width=' + \
str(int(round((mPerc_neg - percent) * mul + valSpace))) + \
' align=right nowrap>'
if self.showValues < 2:
bar += '<span style="' + self.__cssPERCVALUES + '">' + \
str(_number_format(percent, self.percValuesDecimals)) + \
'%</span>'
str(_number_format(percent, self.percValuesDecimals)) + '%</span>'
bar += '&nbsp;</td><td style="' + self.__cssLABELBG + '">'
bar += self.build_bar(value, int(round(percent * mul)),
self.barWidth, bColor)
bar += self.build_bar(value, int(round(percent * mul)), self.barWidth, bColor)
bar += '</td><td width=' + str(spacer) + '></td>'
else:
if max_neg:
bar += '<td style="' + self.__cssLABELBG + \
'" width=' + str(spacer_neg) + '>'
bar += '<td style="' + self.__cssLABELBG + '" width=' + str(spacer_neg) + '>'
bar += '<table border=0 cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>'
if percent:
bar += '<td>'
bar += self.build_bar(value, int(round(percent * mul)),
self.barWidth, bColor)
bar += self.build_bar(value, int(round(percent * mul)), self.barWidth, bColor)
bar += '</td>'
else:
bar += '<td width=1 height=' + \
str(self.barWidth + (border * 2)) + '></td>'
bar += '<td width=1 height=' + str(self.barWidth + (border * 2)) + '></td>'
bar += '<td style="' + self.__cssPERCVALUES + '" width=' + \
str(int(round((mPerc - percent) * mul + valSpace))) + \
' align=left nowrap>'
str(int(round((mPerc - percent) * mul + valSpace))) + ' align=left nowrap>'
if self.showValues < 2:
bar += '&nbsp;' + \
str(_number_format(percent, self.percValuesDecimals)) + '%'
bar += '&nbsp;' + str(_number_format(percent, self.percValuesDecimals)) + '%'
bar += '&nbsp;</td>'
bar += '</tr></table>'
@ -392,37 +372,32 @@ def create_vBar(self, value, percent, mPerc, mPerc_neg,
if percent < 0:
percent *= -1
bar += '<td height=' + \
str(spacer) + '></td></tr><tr align=center valign=top><td style="' + \
self.__cssLABELBG + '">'
bar += self.build_bar(value, self.barWidth,
int(round(percent * mul)), bColor)
str(spacer) + '></td></tr><tr align=center valign=top><td style="' + \
self.__cssLABELBG + '">'
bar += self.build_bar(value, self.barWidth, int(round(percent * mul)), bColor)
bar += '</td></tr><tr align=center valign=top>'
bar += '<td style="' + self.__cssLABELBG + '" height=' + \
str(int(round((mPerc_neg - percent) * mul + valSpace))) + \
' nowrap>'
str(int(round((mPerc_neg - percent) * mul + valSpace))) + ' nowrap>'
bar += (self.showValues < 2) and '<span style="' + self.__cssPERCVALUES + '">' + \
str(_number_format(percent, self.percValuesDecimals)) + \
'%</span>' or '&nbsp;'
str(_number_format(percent, self.percValuesDecimals)) + \
'%</span>' or '&nbsp;'
bar += '</td>'
else:
bar += '<td style="' + self.__cssPERCVALUES + '" valign=bottom height=' + \
str(int(round((mPerc - percent) * mul + valSpace))) + \
' nowrap>'
str(int(round((mPerc - percent) * mul + valSpace))) + ' nowrap>'
if self.showValues < 2:
bar += str(_number_format(percent, self.percValuesDecimals)) + \
'%'
bar += str(_number_format(percent, self.percValuesDecimals)) + '%'
bar += '</td>'
if percent:
bar += '</tr><tr align=center valign=bottom><td>'
bar += self.build_bar(value, self.barWidth,
int(round(percent * mul)), bColor)
bar += self.build_bar(value, self.barWidth, int(round(percent * mul)), bColor)
bar += '</td>'
else:
bar += '</tr><tr><td width=' + \
str(self.barWidth + (border * 2)) + ' height=1></td>'
str(self.barWidth + (border * 2)) + ' height=1></td>'
if max_neg:
bar += '</tr><tr><td style="' + self.__cssLABELBG + \
'" height=' + str(spacer_neg) + '>'
'" height=' + str(spacer_neg) + '>'
bar += '<table border=0 cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>'
bar += '</tr></table>'
@ -462,10 +437,10 @@ def create(self):
self.set_styles()
graph = '<table border=0 cellspacing=0 cellpadding=' + \
str(self.graphPadding) + '><tr>'
str(self.graphPadding) + '><tr>'
graph += '<td' + \
(self.__cssGRAPH and ' style="' +
self.__cssGRAPH + '"' or '') + '>'
(self.__cssGRAPH and ' style="' +
self.__cssGRAPH + '"' or '') + '>'
if self.legend and self.type != 'pbar' and self.type != 'fader':
graph += '<table border=0 cellspacing=0 cellpadding=0><tr><td>'
@ -546,7 +521,7 @@ def create(self):
if self.showValues < 2:
if self.type == 'hbar':
valSpace = (self.percValuesDecimals * (self.percValuesSize / 1.6)) + \
(self.percValuesSize * 3.2)
(self.percValuesSize * 3.2)
else:
valSpace = self.percValuesSize * 1.2
else:
@ -583,16 +558,14 @@ def create(self):
if self.type == 'hbar':
if len(t) > 0:
graph += self.build_hTitle(titleLabel,
titleValue, titleBar)
graph += self.build_hTitle(titleLabel, titleValue, titleBar)
for i in range(len(v)):
label = (
lcnt < len(r)) and r[lcnt].strip() or str(lcnt + 1)
lcnt < len(r)) and r[lcnt].strip() or str(lcnt + 1)
rowspan = len(v[i])
graph += '<tr><td style="' + self.__cssLABEL + '"' + \
((rowspan > 1) and ' rowspan=' + str(rowspan) or '') + \
'>'
((rowspan > 1) and ' rowspan=' + str(rowspan) or '') + '>'
graph += '&nbsp;' + label + '&nbsp;</td>'
for j in range(len(v[i])):
@ -606,8 +579,8 @@ def create(self):
[j], max_dec, 0, 'right')
graph += '<td' + (self.__cssBARBG and ' style="' + self.__cssBARBG + '"' or '') + \
' height=100% width=' + \
str(maxSize) + '>'
' height=100% width=' + \
str(maxSize) + '>'
graph += self.create_hBar(
value, percent, mPerc, mPerc_neg,
max_neg, mul, valSpace, bColor, border, spacer, spacer_neg)
@ -617,7 +590,7 @@ def create(self):
if self.labelSpace and i < len(v) - 1:
graph += '<tr><td colspan=3 height=' + \
str(self.labelSpace) + '></td></tr>'
str(self.labelSpace) + '></td></tr>'
lcnt += 1
elif self.type == 'vbar':
@ -625,8 +598,7 @@ def create(self):
if titleBar != '':
titleBar = titleBar.replace('-', '-<br>')
graph += '<td style="' + self.__cssTITLE + \
'" valign=middle>' + titleBar + '</td>'
graph += '<td style="' + self.__cssTITLE + '" valign=middle>' + titleBar + '</td>'
for i in range(len(v)):
for j in range(len(v[i])):
@ -636,8 +608,8 @@ def create(self):
bColor = self.level_color(v[i][j], bc[j])
graph += '<td' + \
(self.__cssBARBG and ' style="' +
self.__cssBARBG + '"' or '') + '>'
(self.__cssBARBG and ' style="' +
self.__cssBARBG + '"' or '') + '>'
graph += self.create_vBar(
value, percent, mPerc, mPerc_neg,
max_neg, mul, valSpace, bColor, border, spacer, spacer_neg)
@ -650,27 +622,24 @@ def create(self):
graph += '</tr><tr align=center>'
if titleValue != '':
graph += '<td style="' + self.__cssTITLE + \
'">' + titleValue + '</td>'
'">' + titleValue + '</td>'
for i in range(len(v)):
for j in range(len(v[i])):
graph += self.build_value(v[i][j], max_dec)
if self.labelSpace:
graph += '<td width=' + \
str(self.labelSpace) + '></td>'
graph += '<td width=' + str(self.labelSpace) + '></td>'
graph += '</tr><tr>'
if titleLabel != '':
graph += '<td style="' + self.__cssTITLE + \
'">' + titleLabel + '</td>'
graph += '<td style="' + self.__cssTITLE + '">' + titleLabel + '</td>'
for i in range(len(v)):
label = (
lcnt < len(r)) and r[lcnt].strip() or str(lcnt + 1)
lcnt < len(r)) and r[lcnt].strip() or str(lcnt + 1)
colspan = len(v[i])
graph += '<td style="' + self.__cssLABEL + '"' + \
((colspan > 1) and ' colspan=' + str(colspan) or '') + \
'>'
((colspan > 1) and ' colspan=' + str(colspan) or '') + '>'
graph += '&nbsp;' + label + '&nbsp;</td>'
if self.labelSpace:
graph += '<td width=' + str(self.labelSpace) + '></td>'
@ -680,8 +649,7 @@ def create(self):
elif self.type == 'pbar' or self.type == 'fader':
if len(t) > 0:
graph += self.build_hTitle(titleLabel,
titleValue, titleBar)
graph += self.build_hTitle(titleLabel, titleValue, titleBar)
for i in range(len(v)):
try:
@ -691,7 +659,7 @@ def create(self):
if m or not i:
label = (
lcnt < len(r)) and r[lcnt].strip() or str(i + 1)
lcnt < len(r)) and r[lcnt].strip() or str(i + 1)
graph += '<tr>'
if len(r):
@ -711,11 +679,11 @@ def create(self):
[0], max_dec, sum, 'right')
graph += '<td' + \
(self.__cssBARBG and ' style="' +
self.__cssBARBG + '"' or '') + '>'
(self.__cssBARBG and ' style="' +
self.__cssBARBG + '"' or '') + '>'
self.barColors = (
len(drc) >= i + 1) and drc[i].strip() or self.__colors[0]
len(drc) >= i + 1) and drc[i].strip() or self.__colors[0]
bColor = self.level_color(v[i][0], self.barColors)
graph += '<table border=0 cellspacing=0 cellpadding=0><tr><td>'
if self.type == 'fader':
@ -726,16 +694,15 @@ def create(self):
graph += self.build_bar(value,
int(round(percent * mul)), self.barWidth, bColor)
graph += '</td><td width=' + \
str(int(round((100 - percent) * mul))) + '></td>'
str(int(round((100 - percent) * mul))) + '></td>'
graph += '</tr></table></td>'
if self.showValues < 2:
graph += '<td style="' + self.__cssPERCVALUES + '" nowrap>&nbsp;' + \
str(_number_format(percent, self.percValuesDecimals)) + \
'%</td>'
str(_number_format(percent, self.percValuesDecimals)) + '%</td>'
graph += '</tr>'
if self.labelSpace and i < len(v) - 1:
graph += '<td colspan=3 height=' + \
str(self.labelSpace) + '></td>'
str(self.labelSpace) + '></td>'
lcnt += 1
else:
@ -756,16 +723,13 @@ def create(self):
if self.legend and self.type != 'pbar' and self.type != 'fader':
graph += '</td><td width=10>&nbsp;</td><td' + \
(self.legendAlign and ' valign=' + self.legendAlign or '') + \
'>'
(self.legendAlign and ' valign=' + self.legendAlign or '') + '>'
graph += self.build_legend(bc)
graph += '</td></tr></table>'
if self.debug:
graph += "<br>sum=%s max=%s max_neg=%s max_dec=%s " % (sum,
max, max_neg, max_dec)
graph += "mPerc=%s mPerc_neg=%s mul=%s valSpace=%s" % (mPerc,
mPerc_neg, mul, valSpace)
graph += "<br>sum=%s max=%s max_neg=%s max_dec=%s " % (sum, max, max_neg, max_dec)
graph += "mPerc=%s mPerc_neg=%s mul=%s valSpace=%s" % (mPerc, mPerc_neg, mul, valSpace)
graph += '</td></tr></table>'
return graph

2
lib/hostchecker.py Normal file → Executable file
View file

@ -4,9 +4,9 @@
Created by laramies on 2008-08-21.
"""
import socket
class Checker():
def __init__(self, hosts):

26
lib/htmlExport.py Normal file → Executable file
View file

@ -1,12 +1,14 @@
from lib import markup
from lib import graphs
import re
from lib import graphs
from lib import markup
class htmlExport():
def __init__(self, users, hosts, vhosts, dnsres,
dnsrev, file, domain, shodan, tldres):
def __init__(self, users, hosts, vhosts, dnsres, dnsrev, file, domain, shodan, tldres):
self.users = users
self.hosts = hosts
self.vhost = vhosts
@ -50,7 +52,6 @@ def styler(self):
font-size: 15px;
line-height: 15px;
letter-spacing: 0.4px;
}
h2{
@ -62,7 +63,6 @@ def styler(self):
margin: 0 0 0 0;
padding: 0 0 0 0;
font-weight: 100;
}
pre {
@ -84,8 +84,6 @@ def styler(self):
def writehtml(self):
page = markup.page()
# page.init (title="theHarvester
# Results",css=('edge.css'),footer="Edge-security 2011")A
page.html()
self.styler()
page.head(self.style)
@ -103,20 +101,20 @@ def writehtml(self):
graph.labels = ['Emails', 'hosts', 'Vhost', 'TLD', 'Shodan']
graph.showValues = 1
page.body(graph.create())
page.h3("E-mails names found:")
page.h3("Emails found:")
if self.users != []:
page.ul(class_="userslist")
page.li(self.users, class_="useritem")
page.ul.close()
else:
page.h2("No emails found")
page.h2("No emails found.")
page.h3("Hosts found:")
if self.hosts != []:
page.ul(class_="softlist")
page.li(self.hosts, class_="softitem")
page.ul.close()
else:
page.h2("No hosts found")
page.h2("No hosts found.")
if self.tldres != []:
page.h3("TLD domains found in TLD expansion:")
page.ul(class_="tldlist")
@ -128,7 +126,7 @@ def writehtml(self):
page.li(self.dnsres, class_="dnsitem")
page.ul.close()
if self.dnsrev != []:
page.h3("Hosts found with reverse lookup :")
page.h3("Hosts found with reverse lookup:")
page.ul(class_="dnsrevlist")
page.li(self.dnsrev, class_="dnsrevitem")
page.ul.close()
@ -143,7 +141,7 @@ def writehtml(self):
for x in self.shodan:
res = x.split("SAPO")
page.h3(res[0])
page.a("Port :" + res[2])
page.a("Port:" + res[2])
page.pre(res[1])
page.pre.close()
ban = res[1]
@ -166,7 +164,7 @@ def writehtml(self):
try:
file.write(x)
except:
print("Exception" + x) # send to logs
print("Exception" + x) # Send to logs.
pass
file.close()
return "ok"

36
lib/markup.py Normal file → Executable file
View file

@ -1,6 +1,5 @@
# This code is in the public domain, it comes
# with absolutely no warranty and you can do
# absolutely whatever you want with it.
# This code is in the public domain, it comes with absolutely no
# warranty and you can do absolutely whatever you want with it.
__date__ = '17 May 2007'
__version__ = '1.7'
@ -21,6 +20,7 @@
Installation: drop markup.py somewhere into your Python path.
""" % ( __version__, __date__ )
class element:
"""This class handles the addition of a new element."""
@ -37,7 +37,7 @@ def __call__(self, *args, **kwargs):
if len(args) > 1:
raise ArgumentError(self.tag)
# if class_ was defined in parent it should be added to every element
# If class_ was defined in parent, it should be added to every element.
if self.parent is not None and self.parent.class_ is not None:
if 'class_' not in kwargs:
kwargs['class_'] = self.parent.class_
@ -57,7 +57,7 @@ def __call__(self, *args, **kwargs):
elif self.tag in self.parent.onetags:
if len(args) == 0:
for myarg, mydict in _argsdicts(args, kwargs):
# here myarg is always None, because len( args ) = 0
# Here myarg is always None, because len( args ) = 0.
self.render(self.tag, True, myarg, mydict)
else:
raise ClosingError(self.tag)
@ -71,11 +71,11 @@ def render(self, tag, single, between, kwargs):
out = "<%s" % tag
for key, value in kwargs.items():
# when value is None that means stuff like <... checked>
# When value is None, that means stuff like <... checked>.
if value is not None:
# strip this so class_ will mean class, etc.
# Strip this so class_ will mean class, etc.
key = key.strip('_')
# special cases, maybe change _ to - overall?
# Special cases, maybe change _ to - overall?
if key == 'http_equiv':
key = 'http-equiv'
elif key == 'accept_charset':
@ -116,8 +116,8 @@ def open(self, **kwargs):
class page:
"""This is our main class representing a document. Elements are added
as attributes of an instance of this class."""
"""This is our main class representing a document. Elements are added as
attributes of an instance of this class."""
def __init__(self, mode='strict_html', case='lower',
onetags=None, twotags=None, separator='\n', class_=None):
@ -178,8 +178,7 @@ def __init__(self, mode='strict_html', case='lower',
self.case = case
self.separator = separator
# init( ) sets it to True so we know that </body></html> has to be
# printed at the end
# init( ) sets it to True so we know that </body></html> has to be printed at the end.
self._full = False
self.class_ = class_
@ -341,8 +340,8 @@ def init(self, lang='en', css=None, metainfo=None, title=None, header=None,
self.header.append(doctype)
def css(self, filelist):
"""This convenience function is only useful for html.
It adds css stylesheet(s) to the document via the <link> element."""
"""This convenience function is only useful for html. It adds CSS
stylesheet(s) to the document via the <link> element."""
if isinstance(filelist, str):
self.link(
@ -359,9 +358,9 @@ def css(self, filelist):
media='all')
def metainfo(self, mydict):
"""This convenience function is only useful for html.
It adds meta information via the <meta> element, the argument is
a dictionary of the form { 'name':'content' }."""
"""This convenience function is only useful for html. It adds meta
information via the <meta> element, the argument is a dictionary of
the form { 'name':'content' }."""
if isinstance(mydict, dict):
for name, content in mydict.items():
@ -401,7 +400,8 @@ def __getattr__(self, attr):
def _argsdicts(args, mydict):
"""A utility generator that pads argument list and dictionary values, will only be called with len( args ) = 0, 1."""
"""A utility generator that pads argument list and dictionary values, will
only be called with len( args ) = 0, 1."""
if len(args) == 0:
args = None,

0
lib/port_scanner.py Normal file → Executable file
View file

11
lib/reportgraph.py Normal file → Executable file
View file

@ -25,17 +25,17 @@ def __init__(self, domain):
def drawlatestscangraph(self,domain,latestscandata):
try:
self.barcolumns= ['email','host','ip','shodan','vhost']
self.barcolumns= ['email', 'host', 'ip', 'shodan', 'vhost']
self.bardata.append(latestscandata['email'])
self.bardata.append(latestscandata['host'])
self.bardata.append(latestscandata['ip'])
self.bardata.append(latestscandata['shodan'])
self.bardata.append(latestscandata['vhost'])
layout = dict(title = "Latest scan - number of targets identified for "+ domain,
layout = dict(title = "Latest scan - number of targets identified for " + domain,
xaxis = dict(title = 'Targets'),
yaxis = dict(title = 'Hits'),)
barchartcode = plotly.offline.plot({
"data": [go.Bar(x=self.barcolumns,y=self.bardata)],
"data": [go.Bar(x=self.barcolumns, y=self.bardata)],
"layout": layout,
}, auto_open=False,include_plotlyjs=False,filename='report.html', output_type='div')
return barchartcode
@ -46,7 +46,7 @@ def drawscattergraphscanhistory(self,domain,scanhistorydomain):
try:
scandata = scanhistorydomain
for i in scandata:
self.scatterxdata.append(datetime.date(datetime.strptime(i['date'],'%Y-%m-%d')))
self.scatterxdata.append(datetime.date(datetime.strptime(i['date'], '%Y-%m-%d')))
self.scattercountemails.append(int(i['email']))
self.scattercounthosts.append(int(i['hosts']))
self.scattercountips.append(int(i['ip']))
@ -90,11 +90,10 @@ def drawscattergraphscanhistory(self,domain,scanhistorydomain):
)
scatterchartcode = plotly.offline.plot({
"data": data,
"layout": layout}, auto_open=False,include_plotlyjs=False,filename='report.html', output_type='div')
"layout": layout}, auto_open=False, include_plotlyjs=False, filename='report.html', output_type='div')
return scatterchartcode
except Exception as e:
print("Error generating HTML for the historical graph for domain: " + str(e))
except Exception as e:
print("Error in the reportgraph module: " + str(e))

24
lib/statichtmlgenerator.py Normal file → Executable file
View file

@ -1,5 +1,5 @@
class htmlgenerator:
def __init__(self,word):
def __init__(self, word):
self.domain = word
def generatepreviousscanresults(self, previousscanresults):
@ -25,9 +25,9 @@ def generatepreviousscanresults(self, previousscanresults):
html += '<td style="width: 157.153px;">' + str(i) + "</td>"
html += '<td style="width: 157.153px;">' + str(i) + "</td>"
html += '<td style="width: 157.153px;">' + str(i) + "</td>"
html +='</tr>'
html += '</tr>'
else:
html='''
html = '''
<h2><span style="color: #000000;"><strong>Previous scan report </strong></span></h2>
<p>&nbsp;</p>
<table style="height: 63px; border-color: #000000;" border="#000000" width="811">
@ -47,8 +47,8 @@ def generatepreviousscanresults(self, previousscanresults):
html += '<td style="width: 157.153px;">' + str(i[2]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[3]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[4]) + "</td>"
html +='</tr>'
html +='''
html += '</tr>'
html += '''
</tbody>
</table>
<p>&nbsp;</p>
@ -82,8 +82,8 @@ def generatelatestscanresults(self, latestscanresults):
html += '<td style="width: 157.153px;">' + str(i[2]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[3]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[4]) + "</td>"
html +='</tr>'
html +='''
html += '</tr>'
html += '''
</tbody>
</table>
<p>&nbsp;</p>
@ -96,7 +96,7 @@ def generatelatestscanresults(self, latestscanresults):
print("Error generating the latest scan results HTML code: " + str(e))
def beginhtml(self):
html ='''
html = '''
<head><script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>
<html>
<body>
@ -143,7 +143,7 @@ def generatedashboardcode(self, scanboarddata):
def generatepluginscanstatistics(self, scanstatistics):
try:
html='''
html = '''
<h2 style="text-align: center;"><span style="color: #ff0000;">theHarvester plugin statistics</span></h2>
<p>&nbsp;</p>
<table style="height: 63px; border-color: #000000; margin-left: auto; margin-right: auto;" border="#000000" width="811">
@ -163,8 +163,8 @@ def generatepluginscanstatistics(self, scanstatistics):
html += '<td style="width: 157.153px;">' + str(i[2]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[3]) + "</td>"
html += '<td style="width: 157.153px;">' + str(i[4]) + "</td>"
html +='</tr>'
html +='''
html += '</tr>'
html += '''
</tbody>
</table>
<p>&nbsp;</p>
@ -172,4 +172,4 @@ def generatepluginscanstatistics(self, scanstatistics):
'''
return html
except Exception as e:
print("Error generating scan statistics HTML code: " + str(e))
print("Error generating scan statistics HTML code: " + str(e))