This repository has been archived by the owner on May 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createhtml.py
85 lines (62 loc) · 2.57 KB
/
createhtml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import datetime
import os
import imgkit
from jinja2 import Environment, FileSystemLoader
import glob
def createhtml(searchpasswords,search,template_vars,users,datescantime):
searchfolders = []
if searchpasswords == 'True':
searchfolders.append('password')
if search != '':
searchfolders.append(search)
template_vars["searchfolders"]=searchfolders
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("template.html")
cwd = os.path.dirname(os.path.abspath(__file__))
# datescan = datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
newpath = r'.\\'+str(datescantime)
## Creates datefolder
if not os.path.exists(newpath):
os.makedirs(newpath)
## Add to template_env the dateNameFolder
template_vars['folderdate'] = datescantime
# Creates report per user
for user in users:
print(template_vars)
jpgfiles = []
template_vars[user] = {}
print(template_vars)
template_vars['current'] = user
template_vars['users'][user]["PasswordsInMails"] = []
template_vars['users'][user][search] = []
pages = glob.glob(cwd+'\\' + str(datescantime) +'\\'+ user + '\\' + '**/*.html') ## Searchs webpages in folder
# Creates JPG for each webpage
for index in range(len(pages)):
try:
jpgfile = pages[index] + '.jpg'
imgkit.from_file(pages[index], jpgfile)
jpgfiles.append(jpgfile)
print(pages[index])
except:
pass
# Creates webpage per working username
if any("password" in s for s in pages):
for s in pages:
if "password".lower() in s.lower():
template_vars['users'][user]["PasswordsInMails"].append(s)
if any(search in s for s in pages):
for s in pages:
if search.lower() in s.lower():
template_vars['users'][user][search].append(s)
template_vars['thumbs']=jpgfiles
template_vars['pages'] = pages
template_vars['cwd'] = cwd
template = env.get_template("template.html")
html_out = template.render(template_vars)
with open(r'.\\' + str(datescantime) + '\\' + user + '.html', 'a') as html_file:
html_file.write(html_out)
#Creates Summary
template = env.get_template("report_template.html")
html_out = template.render(template_vars)
with open(r'.\\' + str(datescantime) + '\\' + 'report' + '.html', 'a') as html_file:
html_file.write(html_out)