# Path: conpot/core/loggers/taxii_log.py
# class TaxiiLogger(object):
#     def __init__(self, config, dom):
#         self.host = config.get("taxii", "host")
#         self.port = config.getint("taxii", "port")
#         self.inbox_path = config.get("taxii", "inbox_path")
#         self.use_https = config.getboolean("taxii", "use_https")
# 
#         self.client = HttpClient()
#         self.client.setProxy("noproxy")
#         self.stix_transformer = StixTransformer(config, dom)
# 
#     def log(self, event):
#         # converts from conpot log format to STIX compatible xml
#         stix_package = self.stix_transformer.transform(event)
# 
#         # wrapping the stix message in a TAXII envelope
#         content_block = ContentBlock(
#             libtaxii.CB_STIX_XML_11, stix_package.encode("utf-8")
#         )
#         inbox_message = InboxMessage(
#             message_id=generate_message_id(), content_blocks=[content_block]
#         )
#         inbox_xml = inbox_message.to_xml()
# 
#         # the actual call to the TAXII web service
#         response = self.client.callTaxiiService2(
#             self.host, self.inbox_path, libtaxii.VID_TAXII_XML_11, inbox_xml, self.port
#         )
#         response_message = libtaxii.get_message_from_http_response(response, "0")
# 
#         if response_message.status_type != libtaxii.messages.ST_SUCCESS:
#             logger.error(
#                 "Error while transmitting message to TAXII server: %s",
#                 response_message.message,
#             )
#             return False
#         else:
#             return True
# 
# Path: conpot/core/loggers/helpers.py
# def json_default(obj):
#     if isinstance(obj, datetime):
#         return obj.isoformat()
#     elif isinstance(obj, uuid.UUID):
#         return str(obj)
#     elif isinstance(obj, bytes):
#         return str(obj)
#     else:
#         return None


import json
import logging
import time
import configparser
from datetime import datetime
from gevent.queue import Empty
from conpot.core.loggers.sqlite_log import SQLiteLogger
from conpot.core.loggers.hpfriends import HPFriendsLogger
from conpot.core.loggers.syslog import SysLogger
from conpot.core.loggers.taxii_log import TaxiiLogger
from conpot.core.loggers.json_log import JsonLogger
from .loggers.helpers import json_default

        if config.getboolean("json", "enabled"):
            filename = config.get("json", "filename")
            sensorid = config.get("common", "sensorid")
            self.json_logger = JsonLogger(filename, sensorid, public_ip)

        if config.getboolean("hpfriends", "enabled"):
            host = config.get("hpfriends", "host")
            port = config.getint("hpfriends", "port")
            ident = config.get("hpfriends", "ident")
            secret = config.get("hpfriends", "secret")
            channels = eval(config.get("hpfriends", "channels"))
            try:
                self.friends_feeder = HPFriendsLogger(
                    host, port, ident, secret, channels
                )
            except Exception as e:
                logger.exception(e)
                self.friends_feeder = None

        if config.getboolean("syslog", "enabled"):
            host = config.get("syslog", "host")
            port = config.getint("syslog", "port")
            facility = config.get("syslog", "facility")
            logdevice = config.get("syslog", "device")
            logsocket = config.get("syslog", "socket")
            self.syslog_client = SysLogger(host, port, facility, logdevice, logsocket)

        if config.getboolean("taxii", "enabled"):
            # TODO: support for certificates

# Path: conpot/core/loggers/taxii_log.py
# class TaxiiLogger(object):
#     def __init__(self, config, dom):
#         self.host = config.get("taxii", "host")
#         self.port = config.getint("taxii", "port")
#         self.inbox_path = config.get("taxii", "inbox_path")
#         self.use_https = config.getboolean("taxii", "use_https")
# 
#         self.client = HttpClient()
#         self.client.setProxy("noproxy")
#         self.stix_transformer = StixTransformer(config, dom)
# 
#     def log(self, event):
#         # converts from conpot log format to STIX compatible xml
#         stix_package = self.stix_transformer.transform(event)
# 
#         # wrapping the stix message in a TAXII envelope
#         content_block = ContentBlock(
#             libtaxii.CB_STIX_XML_11, stix_package.encode("utf-8")
#         )
#         inbox_message = InboxMessage(
#             message_id=generate_message_id(), content_blocks=[content_block]
#         )
#         inbox_xml = inbox_message.to_xml()
# 
#         # the actual call to the TAXII web service
#         response = self.client.callTaxiiService2(
#             self.host, self.inbox_path, libtaxii.VID_TAXII_XML_11, inbox_xml, self.port
#         )
#         response_message = libtaxii.get_message_from_http_response(response, "0")
# 
#         if response_message.status_type != libtaxii.messages.ST_SUCCESS:
#             logger.error(
#                 "Error while transmitting message to TAXII server: %s",
#                 response_message.message,
#             )
#             return False
#         else:
#             return True
# 
# Path: conpot/core/loggers/helpers.py
# def json_default(obj):
#     if isinstance(obj, datetime):
#         return obj.isoformat()
#     elif isinstance(obj, uuid.UUID):
#         return str(obj)
#     elif isinstance(obj, bytes):
#         return str(obj)
#     else:
#         return None


# Path: conpot/core/log_worker.py
import json
import logging
import time
import configparser
from datetime import datetime
from gevent.queue import Empty
from conpot.core.loggers.sqlite_log import SQLiteLogger
from conpot.core.loggers.hpfriends import HPFriendsLogger
from conpot.core.loggers.syslog import SysLogger
from conpot.core.loggers.taxii_log import TaxiiLogger
from conpot.core.loggers.json_log import JsonLogger
from .loggers.helpers import json_default


        if config.getboolean("json", "enabled"):
            filename = config.get("json", "filename")
            sensorid = config.get("common", "sensorid")
            self.json_logger = JsonLogger(filename, sensorid, public_ip)

        if config.getboolean("hpfriends", "enabled"):
            host = config.get("hpfriends", "host")
            port = config.getint("hpfriends", "port")
            ident = config.get("hpfriends", "ident")
            secret = config.get("hpfriends", "secret")
            channels = eval(config.get("hpfriends", "channels"))
            try:
                self.friends_feeder = HPFriendsLogger(
                    host, port, ident, secret, channels
                )
            except Exception as e:
                logger.exception(e)
                self.friends_feeder = None

        if config.getboolean("syslog", "enabled"):
            host = config.get("syslog", "host")
            port = config.getint("syslog", "port")
            facility = config.get("syslog", "facility")
            logdevice = config.get("syslog", "device")
            logsocket = config.get("syslog", "socket")
            self.syslog_client = SysLogger(host, port, facility, logdevice, logsocket)

        if config.getboolean("taxii", "enabled"):
            # TODO: support for certificates

            self.taxii_logger = TaxiiLogger(config, dom)