This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
forked from heia-fr/sirano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sirano.py
169 lines (149 loc) · 5.22 KB
/
sirano.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
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
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# Sirano is a network trace and log file anonymizer.
#
# Copyright (C) 2015 HES-SO // HEIA-FR
# Copyright (C) 2015 Loic Gremaud <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""SIRANO - SIP/RTP Trafic Anonymizer"""
import argparse
import os
from sirano.app import App, Phase
class Sirano:
"""
Class for the sirano launcher
"""
def __init__(self):
pass
@staticmethod
def phase_1(project_name):
"""
Discovery phase
"""
app = App(project_name)
app.phase = Phase.phase_1
app.load()
app.manager.file.add_files()
app.manager.file.discover_all()
app.manager.data.save_all()
app.log.info("Phase 1: discovery complete")
app.save_report()
@staticmethod
def phase_2(project_name):
"""
Generation phase
"""
app = App(project_name)
app.phase = Phase.phase_2
app.load()
app.manager.data.process_all()
app.manager.data.save_all()
app.log.info("Phase 2: generation complete")
app.save_report()
@staticmethod
def phase_3(project_name):
"""
Anonymization phase
"""
app = App(project_name)
app.phase = Phase.phase_3
app.load()
app.manager.file.add_files()
app.manager.file.anonymize_all()
app.log.info("Phase 3: anonymization complete")
app.save_report()
@staticmethod
def phase_4(project_name):
"""
Validation phase
"""
app = App(project_name)
app.phase = Phase.phase_4
app.load()
app.manager.file.add_files()
app.manager.file.validate_all()
app.log.info("Phase 4: validation complete")
app.save_report()
@staticmethod
def pass_through(project_name):
"""
Pass through all phases
"""
Sirano.phase_1(project_name)
Sirano.phase_2(project_name)
Sirano.phase_3(project_name)
Sirano.phase_4(project_name)
@staticmethod
def create(project_name):
"""
Create a new project
:param project_name: The project name
:type project_name: str
"""
app = App(project_name)
app.create()
@staticmethod
def archive(project_name):
"""
Archive the project
:param project_name: The project name
:type project_name: str
"""
app = App(project_name)
app.archive()
if __name__ == '__main__':
__author__ = "Loic Gremaud <[email protected]>"
__copyright__ = "Copyright (C) 2015 Loic Gremaud"
__license__ = "Licence"
__version__ = "0.2.1"
parser = argparse.ArgumentParser("sirano")
subparsers = parser.add_subparsers(title='action', help="The action to start", dest="action")
parser_process = subparsers.add_parser('process', help="Process a anonymization phase")
parser_process.add_argument("phase", type=int, choices=[0, 1, 2, 3, 4],
help="The phase number : {"
"0: pass through, "
"1: discovery, "
"2: generation, "
"3: anonymization and "
"4: validation}")
parser_process.add_argument("project", help="The project name")
parser_create = subparsers.add_parser('create', help="Create a new project")
parser_create.add_argument("project", help="The project name")
parser_archive = subparsers.add_parser('archive', help="Archive an existent project")
parser_archive.add_argument("project", help="The project name")
args = parser.parse_args()
if args.action == "process":
if not os.path.isdir("projects/" + args.project):
parser.error("Project '{}' not exists".format(args.project))
exit(1)
if args.phase == 0:
Sirano.pass_through(args.project)
elif args.phase == 1:
Sirano.phase_1(args.project)
elif args.phase == 2:
Sirano.phase_2(args.project)
elif args.phase == 3:
Sirano.phase_3(args.project)
elif args.phase == 4:
Sirano.phase_4(args.project)
elif args.action == "create":
Sirano.create(args.project)
elif args.action == "archive":
if not os.path.isdir("projects/" + args.project):
parser.error("Project '{}' not exists".format(args.project))
exit(1)
Sirano.archive(args.project)