# 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


import logging
import socket
import cpppo
import contextlib
import time
import sys
import traceback
import conpot.core as conpot_core
from lxml import etree
from cpppo.server import network
from cpppo.server.enip import logix
from cpppo.server.enip import parser
from cpppo.server.enip import device
from conpot.core.protocol_wrapper import conpot_protocol
        self.server_addr = dom.xpath("//enip/@host")[0]
        self.server_port = int(dom.xpath("//enip/@port")[0])
        self.vendor_id = int(dom.xpath("//enip/device_info/VendorId/text()")[0])
        self.device_type = int(dom.xpath("//enip/device_info/DeviceType/text()")[0])
        self.product_rev = int(
            dom.xpath("//enip/device_info/ProductRevision/text()")[0]
        )
        self.product_code = int(dom.xpath("//enip/device_info/ProductCode/text()")[0])
        self.product_name = dom.xpath("//enip/device_info/ProductName/text()")[0]
        self.serial_number = dom.xpath("//enip/device_info/SerialNumber/text()")[0]
        self.mode = dom.xpath("//enip/mode/text()")[0]
        self.timeout = float(dom.xpath("//enip/timeout/text()")[0])
        self.latency = float(dom.xpath("//enip/latency/text()")[0])

        # parse device tags, these tags will be further processed by the ENIP server
        self.dtags = []
        for t in dom.xpath("//enip/tags/tag"):
            name = t.xpath("@name")[0]
            type = t.xpath("type/text()")[0]
            value = t.xpath("value/text()")[0]
            addr = t.xpath("addr/text()")[0]
            size = 1
            try:
                size = int(t.xpath("size/text()")[0])
            except:
                raise AssertionError("Invalid tag size: %r" % size)

            self.dtags.append(self.Tag(name, type, size, value, addr))



# 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/enip/enip_server.py
import logging
import socket
import cpppo
import contextlib
import time
import sys
import traceback
import conpot.core as conpot_core
from lxml import etree
from cpppo.server import network
from cpppo.server.enip import logix
from cpppo.server.enip import parser
from cpppo.server.enip import device
from conpot.core.protocol_wrapper import conpot_protocol

        self.server_addr = dom.xpath("//enip/@host")[0]
        self.server_port = int(dom.xpath("//enip/@port")[0])
        self.vendor_id = int(dom.xpath("//enip/device_info/VendorId/text()")[0])
        self.device_type = int(dom.xpath("//enip/device_info/DeviceType/text()")[0])
        self.product_rev = int(
            dom.xpath("//enip/device_info/ProductRevision/text()")[0]
        )
        self.product_code = int(dom.xpath("//enip/device_info/ProductCode/text()")[0])
        self.product_name = dom.xpath("//enip/device_info/ProductName/text()")[0]
        self.serial_number = dom.xpath("//enip/device_info/SerialNumber/text()")[0]
        self.mode = dom.xpath("//enip/mode/text()")[0]
        self.timeout = float(dom.xpath("//enip/timeout/text()")[0])
        self.latency = float(dom.xpath("//enip/latency/text()")[0])

        # parse device tags, these tags will be further processed by the ENIP server
        self.dtags = []
        for t in dom.xpath("//enip/tags/tag"):
            name = t.xpath("@name")[0]
            type = t.xpath("type/text()")[0]
            value = t.xpath("value/text()")[0]
            addr = t.xpath("addr/text()")[0]
            size = 1
            try:
                size = int(t.xpath("size/text()")[0])
            except:
                raise AssertionError("Invalid tag size: %r" % size)

            self.dtags.append(self.Tag(name, type, size, value, addr))



@conpot_protocol