-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.py
executable file
·219 lines (180 loc) · 7.96 KB
/
logger.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
'''
Static v0.3 - Copyright 2022 James Slaughter,
This file is part of Static v0.3.
Static v0.3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Static v0.3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Static v0.3. If not, see <http://www.gnu.org/licenses/>.
'''
'''
logger.py - This file is responsible for providing a mechanism to write
log files to the hard drive and read in the static.conf file
logger
Class: This class is responsible for providing a mechanism to write
log files to the hard drive and read in the static.conf file
- Uncomment commented lines in the event troubleshooting is required
'''
#python imports
import sys
import os
import datetime
#programmer generated imports
from fileio import fileio
class logger:
'''
Constructor
'''
def __init__(self):
self.startdatetime = ''
'''
ReportCreate()
Function: - Creates a new log file based on the target
- Adds a header to the log
'''
def ReportCreate(self, logdir, targetlist):
logroot = logdir + 'logroot.html'
FLog = fileio()
self.startdatetime = datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
filename = logroot
data = '<html>\n'
data += '\n--------------------------------------------------------------------------------'
data += '---------------------------------------<br/>'
data += '<head>\n<title>'+ '</title>\n'
data += '\n<strong>Starting Analysis On Targetlist: ' + str(targetlist) + '</strong>' + '\n'
data += '\n<br/><strong>Date/Time: </strong>' + self.startdatetime + '<br/>\n'
data += '--------------------------------------------------------------------------------'
data += '---------------------------------------<br/>\n</head>\n'
data += '<link rel=\"stylesheet\" href=\"/opt/static/static.css\">\n<body>\n'
FLog.WriteNewLogFile(filename, data)
return 0
'''
ReportFooter()
Function: - Adds a footer to close out the log file created in the function above
-
-
'''
def ReportFooter(self, logdir):
FLog = fileio()
filename = logdir + 'logroot.html'
data = '<strong>END OF FILE</strong><br/>'
data += '--------------------------------------------------------------------------------'
data += '---------------------------------------\n<br/>'
data += 'Processed by Static v0.3\n<br/>'
data += '--------------------------------------------------------------------------------'
data += '---------------------------------------\n<br/>'
data += '\n</body>\n</html>\n'
FLog.WriteLogFile(filename, data)
print ('\n')
print ('[*] Report file written to: ' + filename)
return 0
'''
WriteReport()
Function: - Writes to the current log file
- Returns to the caller
'''
def WriteReport(self, logdir, newlogline):
FLog = fileio()
filename = logdir + 'logroot.html'
data = str(newlogline) #+ '\n<br/>'
FLog.WriteLogFile(filename, data)
return 0
'''
LogCreate()
Function: - Creates a new summary log file based on the target
- Adds a header to the log
'''
def SummaryCreate(self, logdir, target):
logroot = logdir + 'logroot.html'
FLog = fileio()
self.startdatetime = datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
filename = logdir + target + '.html'
data = '<html>\n'
data += '\n--------------------------------------------------------------------------------'
data += '---------------------------------------<br/>'
data += '<head>\n<title>' + filename + '</title>\n'
data += '\n<strong>Analysis Target: ' + target + '</strong>' + '\n'
data += '\n<br/><strong>Date/Time: </strong>' + self.startdatetime + '<br/>\n'
data += '--------------------------------------------------------------------------------'
data += '---------------------------------------<br/>\n</head>\n'
data += '<link rel=\"stylesheet\" href=\"/opt/static/static.css\">\n<body>\n'
FLog.WriteNewLogFile(filename, data)
return 0
'''
LogFooter()
Function: - Adds a footer to close out the summary log file created in the function above
'''
def SummaryFooter(self, logdir, target):
FLog = fileio()
filename = logdir + target + '.html'
data = '--------------------------------------------------------------------------------'
data += '---------------------------------------\n<br/>'
data += 'Processed by Static v0.3\n<br/>'
data += '--------------------------------------------------------------------------------'
data += '---------------------------------------\n<br/>'
data += '\n</body>\n</html>\n'
FLog.WriteLogFile(filename, data)
print ('\n[*] Summary file written to: ' + filename)
return 0
'''
WriteStrongLog()
Function: - Writes a bolded line the current summary log file
- Returns to the caller
'''
def WriteStrongLog(self, logdir, target, newlogline):
FLog = fileio()
filename = logdir + target + '.html'
data = '<strong>' + newlogline + '</strong>\n<br/>'
FLog.WriteLogFile(filename, data)
return 0
'''
WriteSubLog()
Function: - Writes a subsection line to the current summary log file
- e.g. |-----------------> <Your Line>
- Returns to the caller
'''
def WriteSubLog(self, logdir, target, newlogline):
FLog = fileio()
filename = logdir + target + '.html'
data = '|--------> ' + newlogline + '\n<br/>'
FLog.WriteLogFile(filename, data)
return 0
'''
WriteStrongSubLog()
Function: - Writes a bolded subsection line to the current summary log file
- e.g. |-----------------> <Your Line>
- Returns to the caller
'''
def WriteStrongSubLog(self, logdir, target, newlogline):
FLog = fileio()
filename = logdir + target + '.html'
data = '|--------> <strong>' + newlogline + '</strong>\n<br/>'
FLog.WriteLogFile(filename, data)
return 0
'''
WriteLog()
Function: - Writes a plain line to the current summary log file
- Returns to the caller
'''
def WriteSummary(self, logdir, target, newlogline):
FLog = fileio()
filename = logdir + target + '.html'
data = newlogline + '\n<br/>'
FLog.WriteLogFile(filename, data)
return 0
'''
WriteConsoleLog()
Function: - Writes a log of print() entries displayed on the console to the current log file
- Returns to the caller
'''
def WriteConsoleLog(self, logdir, target, newlogline):
FLog = fileio()
filename = logdir + target + '.log'
data = newlogline + '\n'
FLog.WriteLogFile(filename, data)
return 0