def main(self): logger.info("Frameworkd is starting up...") conf = OssimConf (Const.CONFIG_FILE) ap = ApacheNtopProxyManager(conf) self.checkEncryptionKey(conf['ossim_host'],conf['ossim_base'],conf['ossim_user'],conf['ossim_pass']) logger.info("Check ntop proxy configuration ...") ap.refreshConfiguration() ap.close() t=None for c in self.__classes : conf_entry = "frameworkd_" + c.lower() logger.info("Conf entry:%s value: %s" % (conf_entry,conf[conf_entry])) if str(conf[conf_entry]).lower() in ('1', 'yes', 'true'): logger.info(c.upper() + " is enabled") #print conf_entry exec "from %s import %s" % (c, c) exec "t = %s()" % (c) t.start() else: logger.info(c.upper() + " is disabled") #Autodiscovery #Ntop if str(conf["network_auto_discovery"]) in ('1', 'yes', 'true'): logger.info("NtopDiscovery" + " is enabled") exec "from %s import %s" % ("NtopDiscovery", "NtopDiscovery") exec "t = %s()" % ("NtopDiscovery") t.start() #Nedi if str(conf["nedi_autodiscovery"]) in ('1', 'yes', 'true'): logger.info("nediDiscovery" + " is enabled") exec "from %s import %s" % ("nediDiscovery", "nediDiscovery") exec "t = %s()" % ("nediDiscovery") t.start()
def handle(self): global controlmanager global bkmanager global asechandler self.__id = None logger.debug("Request from: %s:%i" % (self.client_address)) while 1: try: line = self.rfile.readline().rstrip('\n') if len(line) > 0: command = line.split()[0] # set sane default response response = "" # check if we are a "control" request message if command == "control": # spawn our control timer if controlmanager == None: controlmanager = ControlManager(OssimConf()) response = controlmanager.process(self, command, line) # otherwise we are some form of standard control message elif command == "nagios": if self.__nagiosmanager == None: self.__nagiosmanager = NagiosManager(OssimConf()) response = self.__nagiosmanager.process(line) elif command == "ping": response = "pong\n" elif command == "add_asset" or command == "remove_asset" or command == "refresh_asset_list": linebk = "" if controlmanager == None: controlmanager = ControlManager(OssimConf()) linebk = "action=\"refresh_asset_list\"\n" response = controlmanager.process(self, command, linebk) # elif command == "refresh_inventory_task": # if controlmanager == None: # controlmanager = ControlManager(OssimConf()) # response = controlmanager.process(self, command, linebk) elif command == "refresh_sensor_list": logger.info("Check ntop proxy configuration ...") ap = ApacheNtopProxyManager(OssimConf()) ap.refreshConfiguration() ap.close() elif command == "backup": if bkmanager == None: bkmanager= BackupRestoreManager(OssimConf()) response = bkmanager.process(line) elif command == "asec": if asechandler == None: asechandler = ASECHandler(OssimConf()) response = asechandler.process_web(self, line) elif command == "asec_m":#struct.unpack('!H',line[0:2])[0] == 0x1F1F: #it's a tlv if asechandler == None: asechandler = ASECHandler(OssimConf()) response = asechandler.process(self,line) elif command == "ws": [ws_data] = re.findall('ws_data=(.*)$', line) try: ws_json = json.loads(ws_data) logger.info("Received new WS: %s" % str(ws_json)) except Exception, msg: logger.warning ("WS json is invalid: '%s'" % line) else: if ws_json['ws_id'] != '': for ws_id in ws_json['ws_id'].split(','): try: ws_handler = WSHandler(OssimConf(), ws_id) except Exception, msg: logger.warning (msg) else: # response = ws_handler.process_json(ws_type, ws_data) response = ws_handler.process_json('insert', ws_json) else: logger.warning ("WS command does not contain a ws_id field: '%s'" % line) else: a = Action.Action(line) a.start() # Group Alarms #ag = AlarmGroup.AlarmGroup() #ag.start() # return the response as appropriate if len(response) > 0: self.wfile.write(response) line = ""
def handle(self): global controlmanager self.__id = None logger.debug("Request from: %s:%i" % (self.client_address)) while 1: try: line = self.rfile.readline().rstrip('\n') if len(line) > 0: command = line.split()[0] # set sane default response response = "" # check if we are a "control" request message if command == "control": # spawn our control timer if controlmanager == None: controlmanager = ControlManager(OssimConf(Const.CONFIG_FILE)) response = controlmanager.process(self, command, line) # otherwise we are some form of standard control message elif command == "nessus": if self.__nessusmanager == None: self.__nessusmanager = NessusManager response = self.__nessusmanager.process(line) elif command == "nagios": if self.__nagiosmanager == None: self.__nagiosmanager = NagiosManager(OssimConf(Const.CONFIG_FILE)) response = self.__nagiosmanager.process(line) elif command == "nfsen": if self.__nfsenmanager == None: self.__nfsenmanager = NfsenManager(OssimConf(Const.CONFIG_FILE)) response = self.__nfsenmanager.process(line) elif command == "ping": response = "pong\n" elif command == "add_asset" or command == "remove_asset" or command == "refresh_asset_list": linebk = "" if controlmanager == None: controlmanager = ControlManager(OssimConf(Const.CONFIG_FILE)) linebk = "action=\"refresh_asset_list\"\n" response = controlmanager.process(self, command, linebk) elif command == "refresh_sensor_list": logger.info("Check ntop proxy configuration ...") ap = ApacheNtopProxyManager(OssimConf(Const.CONFIG_FILE)) ap.refreshConfiguration() ap.close() else: a = Action.Action(line) a.start() # Group Alarms #ag = AlarmGroup.AlarmGroup() #ag.start() # return the response as appropriate if len(response) > 0: self.wfile.write(response) line = "" else: return except socket.error, e: logger.warning("Client disconnected...%s" % e ) except IndexError: logger.error("IndexError")