-
Notifications
You must be signed in to change notification settings - Fork 1
/
armadillo_cli_add.py
68 lines (55 loc) · 2.6 KB
/
armadillo_cli_add.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
import typer
import utils
app = typer.Typer()
SECTION_NAME = "policy"
# Generate new section name
def get_next_section_name(config):
new_section = SECTION_NAME
if len(config.sections()) != 0:
new_section += '_' + str(int(config.sections()[-1].split('_')[1]) + 1)
else:
new_section += '_1'
return new_section
@app.command(help="Add a 5-tuple policy")
def policy(
src_port: str = typer.Option(...,help="Packet source port"),
dst_port: str = typer.Option(...,help="Packet destination port"),
src_address: str = typer.Option(...,help="Packet source address"),
dst_address: str = typer.Option(...,help="Packet source address"),
protocol: str = typer.Option(...,help="Packet protocol"),
enabled: bool = typer.Option(True, "--enabled/--disabled",help="If the policy enabled")):
filepath = utils.policy_file_path
config = utils.get_config(filepath)
next_section_name = get_next_section_name(config)
config.add_section(next_section_name)
config.set(next_section_name, 'src_port', src_port)
config.set(next_section_name, 'dst_port', dst_port)
config.set(next_section_name, 'src_address', src_address)
config.set(next_section_name, 'dst_address', dst_address)
config.set(next_section_name, 'protocol', protocol)
config.set(next_section_name, 'enabled', str(int(enabled)))
utils.save_to_file(config, filepath)
@app.command(help="Add a DNS policy")
def policy_dns(
domain: str = typer.Option(...,help="domain to avoid e.g: --domain=Iran-online"),
enabled: bool = typer.Option(True, "--enabled/--disabled",help="If the policy enabled")):
filepath = utils.dns_policy_path
config = utils.get_config(filepath)
next_section_name = get_next_section_name(config)
config.add_section(next_section_name)
config.set(next_section_name, 'domain', domain)
config.set(next_section_name, 'enabled', str(int(enabled)))
utils.save_to_file(config, filepath)
@app.command(help="Add a DPI policy")
def policy_dpi(
string: str = typer.Option(...,help="string to avoid e.g: --string='alert tcp any any -> any any (msg:\"Youtube\"; flow:to_server; pcre:\"/.youtube./\"; sid:1; rev:1;)'"),
enabled: bool = typer.Option(True, "--enabled/--disabled",help="If the policy enabled")):
filepath = utils.dpi_policy_path
config = utils.get_config(filepath)
next_section_name = get_next_section_name(config)
config.add_section(next_section_name)
config.set(next_section_name, 'string', string)
config.set(next_section_name, 'enabled', str(int(enabled)))
utils.save_to_file(config, filepath)
if __name__ == "__main__":
app()