-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporte.py
More file actions
310 lines (271 loc) · 9.6 KB
/
Copy pathreporte.py
File metadata and controls
310 lines (271 loc) · 9.6 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
from datetime import datetime
import os
from typing import Optional, Sequence
from branding import PROJECT_NAME, PROJECT_VERSION, PROJECT_AUTHOR
from config import (
ConfiguracionDiccionario,
SeleccionGeneracion,
ResultadoArchivo
)
from utilidades import Formateador
class ReporteGeneracion:
"""
Clase encargada de crear reportes de generación.
Sirve para:
- Generador universal de combinaciones
- Auditoría por área
"""
def crear_ruta_reporte(
self,
ruta_archivo_generado: str,
prefijo: str
) -> str:
carpeta = os.path.dirname(
os.path.abspath(ruta_archivo_generado)
)
nombre_base = os.path.splitext(
os.path.basename(ruta_archivo_generado)
)[0]
fecha = datetime.now().strftime("%Y%m%d_%H%M%S")
nombre_reporte = f"{prefijo}_{nombre_base}_{fecha}.txt"
return os.path.join(carpeta, nombre_reporte)
def _fecha_actual(self) -> str:
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def _seccion(self, archivo, titulo: str):
archivo.write("\n" + "=" * 70 + "\n")
archivo.write(titulo + "\n")
archivo.write("=" * 70 + "\n")
def _campo(self, archivo, nombre: str, valor):
archivo.write(f"{nombre:<28}: {valor}\n")
def _formatear_lista(self, valores: Sequence[str]) -> str:
resultado = []
for valor in valores:
if valor == "":
resultado.append("[vacío]")
elif valor == " ":
resultado.append("[espacio]")
else:
resultado.append(valor)
return ", ".join(resultado)
def guardar_diccionario_general(
self,
config: ConfiguracionDiccionario,
seleccion: SeleccionGeneracion,
resultado: ResultadoArchivo,
velocidad_estimada: Optional[float] = None
) -> str:
ruta_reporte = self.crear_ruta_reporte(
resultado.ruta_archivo,
"reporte_diccionario"
)
tamano_total = (
config.total_combinaciones
* config.bytes_por_linea
)
velocidad_promedio = 0
if resultado.tiempo_segundos > 0:
velocidad_promedio = (
resultado.elementos_escritos
/ resultado.tiempo_segundos
)
with open(ruta_reporte, "w", encoding="utf-8") as archivo:
self._seccion(
archivo,
"REPORTE DE GENERACIÓN - DICCIONARIO GENERAL"
)
self._campo(archivo, "Fecha de generación", self._fecha_actual())
self._campo(archivo, "Herramienta", PROJECT_NAME)
self._campo(archivo, "Versión", PROJECT_VERSION)
self._campo(archivo, "Autor", PROJECT_AUTHOR)
self._campo(archivo, "Herramienta", PROJECT_NAME)
self._campo(archivo, "Versión", PROJECT_VERSION)
self._campo(archivo, "Autor", PROJECT_AUTHOR)
self._campo(archivo, "Tipo de proceso", "Generador universal")
self._campo(archivo, "Archivo generado", resultado.ruta_archivo)
self._seccion(archivo, "CONFIGURACIÓN DEL DICCIONARIO")
self._campo(archivo, "Caracteres únicos", len(config.caracteres))
self._campo(archivo, "Caracteres usados", config.caracteres)
self._campo(archivo, "Longitud", config.longitud)
self._campo(
archivo,
"Combinaciones totales",
f"{config.total_combinaciones:,}"
)
self._campo(
archivo,
"Peso si genera TODO",
Formateador.tamano_legible(tamano_total)
)
self._campo(
archivo,
"Peso aprox. por línea",
f"{config.bytes_por_linea} bytes"
)
self._seccion(archivo, "ANÁLISIS DE TU SELECCIÓN")
self._campo(archivo, "Modo", seleccion.modo)
self._campo(
archivo,
"Combinaciones a generar",
f"{seleccion.cantidad:,}"
)
self._campo(
archivo,
"Peso estimado",
Formateador.tamano_legible(seleccion.tamano_estimado)
)
self._campo(
archivo,
"Espacio libre",
Formateador.tamano_legible(config.espacio_libre)
)
if seleccion.bytes_solicitados is not None:
self._campo(
archivo,
"Peso solicitado",
Formateador.tamano_legible(
seleccion.bytes_solicitados
)
)
self._seccion(archivo, "RESULTADO FINAL")
self._campo(
archivo,
"Combinaciones escritas",
f"{resultado.elementos_escritos:,}"
)
self._campo(
archivo,
"Tiempo real empleado",
Formateador.tiempo_legible(resultado.tiempo_segundos)
)
self._campo(
archivo,
"Tamaño real del archivo",
Formateador.tamano_legible(resultado.tamano_real)
)
self._campo(
archivo,
"Velocidad promedio",
f"{velocidad_promedio:,.0f} combinaciones/s"
)
if velocidad_estimada is not None:
self._campo(
archivo,
"Velocidad estimada previa",
f"{velocidad_estimada:,.0f} combinaciones/s"
)
return ruta_reporte
def guardar_auditoria_area(
self,
resultado: ResultadoArchivo,
modo: str,
patrones_estimados: int,
patrones_a_generar: int,
peso_estimado: int,
espacio_libre: int,
tokens_base_count: int,
tokens_finales_count: int,
separadores: Sequence[str],
sufijos: Sequence[str],
max_partes: int,
bytes_linea: int,
tamano_total: int,
peso_solicitado: Optional[int] = None,
filtro_datos_sensibles: str = "Activado"
) -> str:
ruta_reporte = self.crear_ruta_reporte(
resultado.ruta_archivo,
"reporte_auditoria"
)
velocidad_promedio = 0
if resultado.tiempo_segundos > 0:
velocidad_promedio = (
resultado.elementos_escritos
/ resultado.tiempo_segundos
)
with open(ruta_reporte, "w", encoding="utf-8") as archivo:
self._seccion(
archivo,
"REPORTE DE GENERACIÓN - AUDITORÍA POR ÁREA"
)
self._campo(archivo, "Fecha de generación", self._fecha_actual())
self._campo(archivo, "Tipo de proceso", "Auditoría por área")
self._campo(archivo, "Archivo generado", resultado.ruta_archivo)
self._campo(
archivo,
"Filtro datos sensibles",
filtro_datos_sensibles
)
self._seccion(archivo, "CONFIGURACIÓN DE AUDITORÍA")
self._campo(archivo, "Tokens base seguros", tokens_base_count)
self._campo(archivo, "Tokens finales", tokens_finales_count)
self._campo(
archivo,
"Separadores",
self._formatear_lista(separadores)
)
self._campo(
archivo,
"Sufijos",
self._formatear_lista(sufijos)
)
self._campo(archivo, "Máx. tokens por patrón", max_partes)
self._campo(
archivo,
"Patrones estimados",
f"{patrones_estimados:,}"
)
self._campo(
archivo,
"Peso si genera TODO",
Formateador.tamano_legible(tamano_total)
)
self._campo(
archivo,
"Peso aprox. por línea",
f"{bytes_linea} bytes"
)
self._seccion(archivo, "ANÁLISIS DE TU SELECCIÓN")
self._campo(archivo, "Modo", modo)
self._campo(
archivo,
"Patrones a generar",
f"{patrones_a_generar:,}"
)
self._campo(
archivo,
"Peso estimado",
Formateador.tamano_legible(peso_estimado)
)
self._campo(
archivo,
"Espacio libre",
Formateador.tamano_legible(espacio_libre)
)
if peso_solicitado is not None:
self._campo(
archivo,
"Peso solicitado",
Formateador.tamano_legible(peso_solicitado)
)
self._seccion(archivo, "RESULTADO FINAL")
self._campo(
archivo,
"Patrones escritos",
f"{resultado.elementos_escritos:,}"
)
self._campo(
archivo,
"Tiempo real empleado",
Formateador.tiempo_legible(resultado.tiempo_segundos)
)
self._campo(
archivo,
"Tamaño real del archivo",
Formateador.tamano_legible(resultado.tamano_real)
)
self._campo(
archivo,
"Velocidad promedio",
f"{velocidad_promedio:,.0f} patrones/s"
)
return ruta_reporte