This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
amsterdam
executable file
·78 lines (70 loc) · 3.04 KB
/
amsterdam
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
#!/usr/bin/env python
# Copyright (C) 2015,2016 Stamus Networks
#
# You can copy, redistribute or modify this Program under the terms of
# the GNU General Public License version 3 as published by the Free
# Software Foundation.
#
# 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
# version 3 along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
import sys
import argparse
import os.path
from amsterdam import Amsterdam, AmsterdamException, AMSTERDAM_VERSION
parser = argparse.ArgumentParser(description='Amsterdam, SELKS on docker')
parser.add_argument('-i', '--iface', default=None, help='Host iface to sniff')
parser.add_argument('-v', '--verbose', default=False, action="count", help="Show verbose output, use multiple times increase verbosity")
parser.add_argument('-d', '--data', default=None, help='Directory to store generated data into (default to ./data)')
parser.add_argument('-n', '--name', default=None, help='Set project name')
parser.add_argument('-f', '--full', default=False, const=True, action='store_const', help="Do a full update of instance. This will erase any modified version of config and Dockerfile")
parser.add_argument('command', metavar='command', nargs=1, help='Amsterdam command [setup|start|stop|restart|update|rm])', default=None)
parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + AMSTERDAM_VERSION)
args = parser.parse_args()
if args.command[0] not in ['setup', 'start', 'stop', 'restart', 'update', 'rm']:
sys.stderr.write("Invalid command: '%s'\n" % args.command)
sys.exit(-1)
basepath = './data'
if args.data:
basepath = args.data
if not args.name:
args.name = os.path.basename(args.data)
try:
ams = Amsterdam(args.name, args.iface, basepath)
except AmsterdamException as err:
sys.stderr.write("%s\n" % (err))
sys.exit(-1)
if args.command[0] == 'setup':
if args.iface == None:
sys.stderr.write("You need to specify an interface with -i to setup the system\n")
sys.exit(-1)
if ams.setup(args) != 0:
sys.exit(-1)
if args.command[0] == 'start':
try:
if ams.start(args) != 0:
sys.exit(-1)
except KeyboardInterrupt:
ams.stop(args)
elif args.command[0] == 'stop':
if ams.stop(args) != 0:
sys.exit(-1)
elif args.command[0] == 'restart':
if ams.restart(args) != 0:
sys.exit(-1)
elif args.command[0] == 'update':
if args.iface == None:
sys.stderr.write("You need to specify an interface with -i to update the system\n")
sys.exit(-1)
if ams.update(args) != 0:
sys.exit(-1)
elif args.command[0] == 'rm':
sys.stdout.write("Please remove the data directory if you want to clean the system\n")
if ams.rm(args) != 0:
sys.exit(-1)