-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
util.py
66 lines (48 loc) · 1.43 KB
/
util.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
import log
import re
import os
list_options = ["general", "user", "group", "computer", "regex", "all"]
set_options = ["user", "group", "computer", "regex"]
def validate_export_command(f):
result = 'exports/' + re.sub(r'(.txt|/)', '', f) + '.txt'
return result
def validate_list_command(c):
if c not in list_options:
return False
else:
return True
def validate_set_option(option):
if option not in set_options:
return False
else:
return True
# Will validate for group, user, and computer input
def validate_common_config(c):
if c == "":
return False
else:
return True
# Will validate for regex input, special case
def validate_regex_config(c):
if c == "":
return False
else:
return True
def validate_user_input(i):
special_characters = ['{', '}', '[', ']', '(', ')', '^', '$', '.', '*', '+', '?', '\\', '|', '\'', '\"']
for character in special_characters:
if character in i:
i = i.replace(character, '\\' + character)
return i
def handle_export(count, path):
file = open(path, 'a+')
if count == 0:
file.close()
os.remove(path)
log.log_no_results()
else:
file.close()
log.log_successful_export(path)
def strip_ansi_escape_sequences(text):
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', text)