# 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/protocols/modbus/slave_db.py
# class SlaveBase(Databank):
#     def __init__(self, template):
#     def add_slave(self, slave_id, unsigned=True, memory=None):
#     def handle_request(self, query, request, mode):


import struct
import socket
import time
import logging
import sys
import codecs
import modbus_tk.modbus_tcp as modbus_tcp
import modbus_tk.defines as mdef
import conpot.core as conpot_core
from lxml import etree
from gevent.server import StreamServer
from modbus_tk import modbus
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.protocols.modbus import slave_db
# modified by Sooky Peter <xsooky00@stud.fit.vutbr.cz>
# Brno University of Technology, Faculty of Information Technology


# Following imports are required for modbus template evaluation

logger = logging.getLogger(__name__)


@conpot_protocol
class ModbusServer(modbus.Server):
    def __init__(self, template, template_directory, args):
        self.timeout = 5
        self.delay = None
        self.mode = None
        self.host = None
        self.port = None
        self.server = None


# 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/protocols/modbus/slave_db.py
# class SlaveBase(Databank):
#     def __init__(self, template):
#     def add_slave(self, slave_id, unsigned=True, memory=None):
#     def handle_request(self, query, request, mode):


# Path: conpot/protocols/modbus/modbus_server.py
import struct
import socket
import time
import logging
import sys
import codecs
import modbus_tk.modbus_tcp as modbus_tcp
import modbus_tk.defines as mdef
import conpot.core as conpot_core
from lxml import etree
from gevent.server import StreamServer
from modbus_tk import modbus
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.protocols.modbus import slave_db

# modified by Sooky Peter <xsooky00@stud.fit.vutbr.cz>
# Brno University of Technology, Faculty of Information Technology


# Following imports are required for modbus template evaluation

logger = logging.getLogger(__name__)


@conpot_protocol
class ModbusServer(modbus.Server):
    def __init__(self, template, template_directory, args):
        self.timeout = 5
        self.delay = None
        self.mode = None
        self.host = None
        self.port = None
        self.server = None


        databank = slave_db.SlaveBase(template)