The trunk can use the main server again (for the time being).
[switzerland.git] / switzerland / server / SwitzerlandConfig.py
blobd9a515d2bb2a5eca17aa95224ec43725710913bc
1 import getopt
2 import sys
3 import platform
5 from switzerland.common import Protocol
7 if platform.system() != "Windows":
8 default_pcap_logdir = "/var/log/switzerland-pcaps"
9 default_logfile = "/var/log/switzerland-server.log"
10 else:
11 default_pcap_logdir = "c:\switzerland\pcaplogs"
12 default_logfile = "c:\switzerland\serverlog"
15 class SwitzerlandConfig:
16 def __init__(self,
17 getopt=False,
18 port=Protocol.default_port,
19 sloppy=False,
20 seriousness=0,
21 keep_threads=False,
22 keep_reconciliators=False,
23 logging=True,
24 logfile=default_logfile,
25 pcap_logdir=default_pcap_logdir,
26 allow_fake_ips=False,
27 send_flow_status_updates=True,
28 client_contact_period=45 # controls pings to clients
30 self.port = port
31 self.sloppy = sloppy # Yes if we expect clients to send us flows that
32 # shouldn't be here. True for some test cases
33 # perhaps, but not True in general.
34 self.keep_threads = keep_threads # (Keep threads around even after they've
35 # finished ; used for unit tests)
36 self.keep_reconciliators = keep_reconciliators
37 self.seriousness_threshold = seriousness
38 self.logging = logging
39 self.pcap_logdir = pcap_logdir
40 self.logfile = logfile
41 self.allow_fake_ips = allow_fake_ips
42 self.send_flow_status_updates = send_flow_status_updates
43 self.client_contact_period = client_contact_period
45 if getopt:
46 self.get_options()
48 def get_options(self):
49 try:
50 (opts, args) = \
51 getopt.gnu_getopt(sys.argv[1:], 'p:hL:P:', \
52 ['port=', 'help'])
53 except:
54 self.usage()
56 for opt in opts:
57 if opt[0] == '-p' or opt[0] == '--port':
58 self.port = int(opt[1])
59 elif opt[0] == '-h' or opt[0] == '--help':
60 self.usage()
61 elif opt[0] == '-L' or opt[0] == '--logfile':
62 self.logfile = opt[1]
63 elif opt[0] == '-P' or opt[0] == '--pcap-logs':
64 self.pcap_logdir = opt[1]
67 def usage(self):
68 print "%s [OPTIONS]" % sys.argv[0]
69 print "server for switzerland network traffic auditing system"
70 print
71 print " -h, --help print usage info"
72 print " -p, --port <port number> port to listen on"
73 print ' -L, --logfile <file> Write a copy of the output to <file>. "-" for none'
74 print " (defaults to " + default_logfile + ")"
75 print " -P, --pcap-logs <dir> Sets the directory to which PCAPs of modified"
76 print ' packets will be written. "-" for none.'
77 print " (defaults to " + default_pcap_logdir + ")"
79 sys.exit(0)