# 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
            session_timeout = self.config.get("session", "timeout")
        except (configparser.NoSectionError, configparser.NoOptionError):
            session_timeout = 5
        for session in sessions:
            if len(session.data) > 0:
                sec_last_event = max(session.data) / 1000
            else:
                sec_last_event = 0
            sec_session_start = time.mktime(session.timestamp.timetuple())
            sec_now = time.mktime(datetime.utcnow().timetuple())
            if (sec_now - (sec_session_start + sec_last_event)) >= float(
                session_timeout
            ):
                # TODO: We need to close sockets in this case
                logger.info("Session timed out: %s", session.id)
                session.set_ended()
                sessions.remove(session)

    def start(self):
        self.enabled = True
        while self.enabled:
            try:
                event = self.log_queue.get(timeout=2)
            except Empty:
                self._process_sessions()
            else:
                if self.public_ip:
                    event["public_ip"] = self.public_ip

                if self.friends_feeder:

# 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

            session_timeout = self.config.get("session", "timeout")
        except (configparser.NoSectionError, configparser.NoOptionError):
            session_timeout = 5
        for session in sessions:
            if len(session.data) > 0:
                sec_last_event = max(session.data) / 1000
            else:
                sec_last_event = 0
            sec_session_start = time.mktime(session.timestamp.timetuple())
            sec_now = time.mktime(datetime.utcnow().timetuple())
            if (sec_now - (sec_session_start + sec_last_event)) >= float(
                session_timeout
            ):
                # TODO: We need to close sockets in this case
                logger.info("Session timed out: %s", session.id)
                session.set_ended()
                sessions.remove(session)

    def start(self):
        self.enabled = True
        while self.enabled:
            try:
                event = self.log_queue.get(timeout=2)
            except Empty:
                self._process_sessions()
            else:
                if self.public_ip:
                    event["public_ip"] = self.public_ip

                if self.friends_feeder:

                    self.friends_feeder.log(json.dumps(event, default=json_default))