# 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 str_to_bytes(x):
#     return x if isinstance(x, bytes) else str(x).encode("ascii")


from gevent.server import StreamServer
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.utils.networking import str_to_bytes
import datetime
import logging
import random
import conpot.core as conpot_core
# Copyright (C) 2015  Lukas Rist <glaslos@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""
Service support based on gaspot.py [https://github.com/sjhilt/GasPot]
Original authors: Kyle Wilhoit and Stephen Hilt
"""


logger = logging.getLogger(__name__)

# 9999 indicates that the command was not understood and
# FF1B is the checksum for the 9999
AST_ERROR = "9999FF1B\n"



# 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 str_to_bytes(x):
#     return x if isinstance(x, bytes) else str(x).encode("ascii")


# Path: conpot/protocols/guardian_ast/guardian_ast_server.py
from gevent.server import StreamServer
from conpot.core.protocol_wrapper import conpot_protocol
from conpot.utils.networking import str_to_bytes
import datetime
import logging
import random
import conpot.core as conpot_core

# Copyright (C) 2015  Lukas Rist <glaslos@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""
Service support based on gaspot.py [https://github.com/sjhilt/GasPot]
Original authors: Kyle Wilhoit and Stephen Hilt
"""


logger = logging.getLogger(__name__)

# 9999 indicates that the command was not understood and
# FF1B is the checksum for the 9999
AST_ERROR = "9999FF1B\n"



@conpot_protocol