Package ioids :: Module ioids
[hide private]
[frames] | no frames]

Source Code for Module ioids.ioids

  1  """ 
  2  Main module for IOIDS 
  3   
  4  Inter-Organisational Intrusion Detection System (IOIDS) 
  5   
  6  Check README in the IOIDS folder for more information. 
  7   
  8  @author: Michael Pilgermann 
  9  @contact: mailto:mpilgerm@glam.ac.uk 
 10  @license: GPL (General Public License) 
 11  """ 
 12   
13 -class IOIDS:
14
15 - def __init__(self):
16 """ 17 Registers closing down signals. 18 """ 19 pass
20
21 - def __str__(self):
22 """ 23 Some basic information about the object. 24 """ 25 return "IOIDS - Inter-Organisational Intrusion Detection System"
26 27
28 - def startup(self):
29 """ 30 Start required listeners and services. 31 32 Also connects against G4DS. 33 """ 34 from tools import printAction, finishActionLine, SUCESS_POS, SUCESS_NEG, SUCESS_SKIP 35 from errorhandling import IoidsException 36 37 print "\n" + "*" * 90 38 printAction(0, "Starting up IOIDS",1) 39 40 printAction(1, "Start IOIDS logging") 41 from ioidslogging import getDefaultLogger 42 try: 43 getDefaultLogger() 44 finishActionLine() 45 except IoidsException, msg: 46 finishActionLine(SUCESS_NEG) 47 printAction(2, str(msg)) 48 finishActionLine(SUCESS_NEG) 49 50 printAction(1, "Loading G4DS Key") 51 try: 52 from config import LOCATION_PRIVATE_KEY 53 file = open(LOCATION_PRIVATE_KEY) 54 file.close() 55 finishActionLine() 56 except IOError, msg: 57 finishActionLine(SUCESS_NEG) 58 printAction(2, "Reported error: %s" %(msg), 1) 59 raise IoidsException("Could not load key for G4DS connection.") 60 61 printAction(1, "Connect against database backend") 62 try: 63 from dbconnector import getDBConnector 64 getDBConnector().connect() 65 finishActionLine() 66 printAction(2, "Testing connection") 67 getDBConnector().testConnection() 68 finishActionLine() 69 except Exception, msg: 70 finishActionLine(SUCESS_NEG) 71 printAction(2, str(msg)) 72 finishActionLine(SUCESS_NEG) 73 raise IoidsException("Could not establish connection to database backend.") 74 75 printAction(1, "Connect against G4DS") 76 try: 77 from g4dsconnector import getG4dsConnector 78 getG4dsConnector().connect() 79 finishActionLine() 80 except IoidsException, msg: 81 finishActionLine(SUCESS_NEG) 82 printAction(2, str(msg)) 83 finishActionLine(SUCESS_NEG) 84 raise IoidsException("Could not establish G4DS connection.") 85 86 printAction(1, "Loading policies into memory") 87 try: 88 from policyengine import getPolicyEngine 89 getPolicyEngine().startup() 90 finishActionLine() 91 except Exception, msg: 92 finishActionLine(SUCESS_NEG) 93 printAction(2, str(msg)) 94 finishActionLine(SUCESS_NEG) 95 raise IoidsException("Could not load ioids policies.") 96 97 printAction(1, "Initialise event trigger") 98 try: 99 from eventtrigger import EventTrigger 100 self._trigger = EventTrigger() 101 self._trigger.startup() 102 finishActionLine() 103 except IoidsException, msg: 104 finishActionLine(SUCESS_NEG) 105 printAction(2, str(msg)) 106 finishActionLine(SUCESS_NEG) 107 raise IoidsException("Could not initialise Event trigger.") 108 109 printAction(1, "Initialise data engine") 110 try: 111 from dataengine import getDataEngine 112 getDataEngine().startup() 113 finishActionLine() 114 except IoidsException, msg: 115 finishActionLine(SUCESS_NEG) 116 printAction(2, str(msg)) 117 finishActionLine(SUCESS_NEG) 118 raise IoidsException("Could not initialise data engine.") 119 120 printAction(0, "IOIDS running") 121 finishActionLine() 122 print "*" * 90 + "\n"
123 124
125 - def shutdown(self):
126 """ 127 Shutdown connected listeners and services. 128 """ 129 from tools import printAction, finishActionLine, SUCESS_POS, SUCESS_NEG, SUCESS_SKIP 130 from errorhandling import IoidsException 131 132 print "\n" + "*" * 90 133 printAction(0, "Shutting down IOIDS",1) 134 135 printAction(1, "Shutting down event trigger") 136 try: 137 self._trigger.shutdown() 138 finishActionLine() 139 except IoidsException, msg: 140 finishActionLine(SUCESS_NEG) 141 printAction(2, str(msg)) 142 finishActionLine(SUCESS_NEG) 143 raise IoidsException("Could not shutdown Event trigger.") 144 145 printAction(1, "Shutting down data engine") 146 try: 147 from dataengine import getDataEngine 148 getDataEngine().shutdown() 149 finishActionLine() 150 except IoidsException, msg: 151 finishActionLine(SUCESS_NEG) 152 printAction(2, str(msg)) 153 finishActionLine(SUCESS_NEG) 154 raise IoidsException("Could not shutdown data engine.") 155 156 printAction(1, "Closing down connection to G4DS") 157 try: 158 from g4dsconnector import getG4dsConnector 159 getG4dsConnector().disconnect() 160 finishActionLine() 161 except IoidsException, msg: 162 finishActionLine(SUCESS_NEG) 163 printAction(2, str(msg)) 164 finishActionLine(SUCESS_NEG) 165 166 printAction(1, "Closing down connection to database backend") 167 try: 168 from dbconnector import getDBConnector 169 getDBConnector().disconnect() 170 finishActionLine() 171 except IoidsException, msg: 172 finishActionLine(SUCESS_NEG) 173 printAction(2, str(msg)) 174 finishActionLine(SUCESS_NEG) 175 176 printAction (1,"Shutting down Logging") 177 from ioidslogging import getDefaultLogger 178 getDefaultLogger().closedown() 179 finishActionLine() 180 181 printAction(0, "Shutdown complete") 182 finishActionLine() 183 print "*" * 90 + "\n"
184 185
186 -def SignalHandler(sig, id):
187 import signal 188 global ioidsInst 189 if sig == signal.SIGTERM or sig == signal.SIGINT: 190 ioidsInst.shutdown() 191 import sys 192 sys.exit(1)
193 194 195 if __name__ == "__main__": 196 """ 197 Let's startup a IOIDS instance here. 198 """ 199 global ioidsInst 200 from errorhandling import IoidsException 201 202 ioidsInst = IOIDS() 203 try: 204 ioidsInst.startup() 205 except IoidsException, msg: 206 print "\nIOIDS could not be started - error message:\n\t%s" %(msg) 207 import sys 208 sys.exit(1) 209 210 import signal 211 signal.signal(signal.SIGTERM, SignalHandler) 212 signal.signal(signal.SIGINT, SignalHandler) 213 214 while 1: 215 raw_input() # to stop ioids, you may use CTRL-C (SIGINT); so this only runs indefinite 216