# Path: conpot/protocols/tftp/tftp_handler.py
# class TFTPState(tftpy.TftpStates.TftpState):
# class TFTPServerState(TFTPState):
# class TFTPStateServerRecvRRQ(TFTPServerState):
# class TFTPStateServerRecvWRQ(TFTPServerState):
# class TFTPStateServerStart(TFTPState):
# class TFTPContextServer(tftpy.TftpContexts.TftpContextServer):
#     def __int__(self, context):
#     def handle(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def serverInitial(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def make_subdirs(self):
#     def handle(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def __int__(self, host, port, timeout, root, dyn_file_func, upload_open):
#     def start(self, buffer):
#     def end(self):
# 
# Path: conpot/core/protocol_wrapper.py
# def conpot_protocol(cls):
#     class Wrapper(object):
#         def __init__(self, *args, **kwargs):
#             self.wrapped = cls(*args, **kwargs)
#             self.cls = cls
#             if self.cls.__name__ not in "Proxy":
#                 if self.cls not in core_interface.protocols:
#                     core_interface.protocols[self.cls] = []
# 
#                 core_interface.protocols[self.cls].append(self.wrapped)
# 
#             self.__class__.__name__ = self.cls.__name__
# 
#         def __getattr__(self, name):
#             if name == "handle":
#                 # assuming that handle function from a class is only called when a client tries to connect with an
#                 # enabled protocol, update the last_active (last_attacked attribute)
#                 # FIXME: No handle function in HTTPServer
#                 core_interface.last_active = datetime.now().strftime(
#                     "%b %d %Y - %H:%M:%S"
#                 )
#             return self.wrapped.__getattribute__(name)
# 
#         def __repr__(self):
#             return self.wrapped.__repr__()
# 
#         __doc__ = cls.__doc__
#         __module__ = cls.__module__
# 
#     return Wrapper
# 
# Path: conpot/utils/networking.py
# def get_interface_ip(destination_ip: str):
#     # returns interface ip from socket in case direct udp socket access not possible
#     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#     s.connect((destination_ip, 80))
#     socket_ip = s.getsockname()[0]
#     s.close()
#     return socket_ip


import gevent
import os
import conpot.core as conpot_core
import logging
from lxml import etree
from conpot.protocols.tftp import tftp_handler
from gevent.server import DatagramServer
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.utils.networking import get_interface_ip
from tftpy import TftpException, TftpTimeout
        if self.vfs.access(self.root, 0, os.R_OK):
            logger.debug(
                "TFTP root {} is readable".format(self.vfs.getcwd() + self.root)
            )
        else:
            raise TftpException("The TFTP root must be readable")
        if self.vfs.access(self.root, 0, os.W_OK):
            logger.debug(
                "TFTP root {} is writable".format(self.vfs.getcwd() + self.root)
            )
        else:
            logger.warning(
                "The TFTP root {} is not writable".format(self.vfs.getcwd() + self.root)
            )

    def handle(self, buffer, client_addr):
        session = conpot_core.get_session(
            "tftp",
            client_addr[0],
            client_addr[1],
            get_interface_ip(client_addr[0]),
            self.server._socket.getsockname()[1],
        )
        logger.info(
            "New TFTP client has connected. Connection from {}:{}. ".format(
                client_addr[0], client_addr[1]
            )
        )
        session.add_event({"type": "NEW_CONNECTION"})
        logger.debug("Read %d bytes", len(buffer))

# Path: conpot/protocols/tftp/tftp_handler.py
# class TFTPState(tftpy.TftpStates.TftpState):
# class TFTPServerState(TFTPState):
# class TFTPStateServerRecvRRQ(TFTPServerState):
# class TFTPStateServerRecvWRQ(TFTPServerState):
# class TFTPStateServerStart(TFTPState):
# class TFTPContextServer(tftpy.TftpContexts.TftpContextServer):
#     def __int__(self, context):
#     def handle(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def serverInitial(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def make_subdirs(self):
#     def handle(self, pkt, raddress, rport):
#     def handle(self, pkt, raddress, rport):
#     def __int__(self, host, port, timeout, root, dyn_file_func, upload_open):
#     def start(self, buffer):
#     def end(self):
# 
# Path: conpot/core/protocol_wrapper.py
# def conpot_protocol(cls):
#     class Wrapper(object):
#         def __init__(self, *args, **kwargs):
#             self.wrapped = cls(*args, **kwargs)
#             self.cls = cls
#             if self.cls.__name__ not in "Proxy":
#                 if self.cls not in core_interface.protocols:
#                     core_interface.protocols[self.cls] = []
# 
#                 core_interface.protocols[self.cls].append(self.wrapped)
# 
#             self.__class__.__name__ = self.cls.__name__
# 
#         def __getattr__(self, name):
#             if name == "handle":
#                 # assuming that handle function from a class is only called when a client tries to connect with an
#                 # enabled protocol, update the last_active (last_attacked attribute)
#                 # FIXME: No handle function in HTTPServer
#                 core_interface.last_active = datetime.now().strftime(
#                     "%b %d %Y - %H:%M:%S"
#                 )
#             return self.wrapped.__getattribute__(name)
# 
#         def __repr__(self):
#             return self.wrapped.__repr__()
# 
#         __doc__ = cls.__doc__
#         __module__ = cls.__module__
# 
#     return Wrapper
# 
# Path: conpot/utils/networking.py
# def get_interface_ip(destination_ip: str):
#     # returns interface ip from socket in case direct udp socket access not possible
#     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#     s.connect((destination_ip, 80))
#     socket_ip = s.getsockname()[0]
#     s.close()
#     return socket_ip


# Path: conpot/protocols/tftp/tftp_server.py
import gevent
import os
import conpot.core as conpot_core
import logging
from lxml import etree
from conpot.protocols.tftp import tftp_handler
from gevent.server import DatagramServer
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.utils.networking import get_interface_ip
from tftpy import TftpException, TftpTimeout

        if self.vfs.access(self.root, 0, os.R_OK):
            logger.debug(
                "TFTP root {} is readable".format(self.vfs.getcwd() + self.root)
            )
        else:
            raise TftpException("The TFTP root must be readable")
        if self.vfs.access(self.root, 0, os.W_OK):
            logger.debug(
                "TFTP root {} is writable".format(self.vfs.getcwd() + self.root)
            )
        else:
            logger.warning(
                "The TFTP root {} is not writable".format(self.vfs.getcwd() + self.root)
            )

    def handle(self, buffer, client_addr):
        session = conpot_core.get_session(
            "tftp",
            client_addr[0],
            client_addr[1],
            get_interface_ip(client_addr[0]),
            self.server._socket.getsockname()[1],
        )
        logger.info(
            "New TFTP client has connected. Connection from {}:{}. ".format(
                client_addr[0], client_addr[1]
            )
        )
        session.add_event({"type": "NEW_CONNECTION"})
        logger.debug("Read %d bytes", len(buffer))

        context = tftp_handler.TFTPContextServer(