-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
66 lines (55 loc) · 2.52 KB
/
config.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 json
from alert import Alert
class Setting(object):
SYSTEM_MODE = 'system_mode'
PROHIBITED_FILE_TYPES = 'prohibited_file_types'
class Config:
@staticmethod
def get_config():
config_json = None
with open('config.json', 'r') as config_file:
config_json = json.load(config_file)
return config_json
@staticmethod
def save_config(config_json):
# we do this to make sure that the json is valid
validated_config_json = json.loads(config_json)
with open('config.json', 'w') as config_file:
config_file.write(json.dumps(validated_config_json))
config_file.flush()
@staticmethod
def get_setting(setting_name):
config_json = Config.get_config()
return config_json.get(setting_name)
@staticmethod
def get_attack_config(attack_name):
config_json = Config.get_config()
if not config_json.get(Setting.SYSTEM_MODE):
Alert.add_alert(alert_type='ERROR', event='Could not find \'system_mode\' on config.json')
return None
elif config_json[Setting.SYSTEM_MODE] == 'no_action':
return None
elif config_json[Setting.SYSTEM_MODE] != 'per_attack':
return {'action': config_json['system_mode'], 'report_type': 'WARN'}
elif not config_json.get('attack_types'):
Alert.add_alert(alert_type='ERROR', event='Could not find \'attack_types\' on config.json')
return None
else:
for attack_type in config_json['attack_types']:
if attack_type.get('name') == attack_name:
if not attack_type.get('per_attack_action'):
Alert.add_alert(
alert_type='ERROR',
event='No \'per_attack_action\' found for \'%s\' on config.json' % attack_name)
elif not attack_type.get('report_type'):
Alert.add_alert(
alert_type='ERROR',
event='No \'report_type\' found for \'%s\' on config.json' % attack_name)
elif attack_type['per_attack_action'] == 'no_action':
return None
else:
return {'action': attack_type['per_attack_action'], 'report_type': attack_type['report_type']}
Alert.add_alert(
alert_type='ERROR',
event='Could not find attack \'%s\' on config.json' % attack_name)
return None