def AddMapping(self, src, dest):
     try:
         portforward.add_mapping(protocol_string_to_enum(src), protocol_string_to_enum(dest))
         logger.debug("Done")
         return True
     except socket.error as e:
         logger.debug("Fail\n\t-%s", e)
         return False
 def AddMapping(self, src, dest):
     try:
         portforward.add_mapping(protocol_string_to_enum(src),
                                 protocol_string_to_enum(dest))
         logger.debug("Done")
         return True
     except socket.error as e:
         logger.debug("Fail\n\t-%s", e)
         return False
    logger.error("Could not bind to proxy socket - is another instance running?")
    sys.exit(1)
server.listen(1)

try:
    while True:
        client, _ = server.accept()

        # Go ahead and assume a command, since the client
        # will never send a lone True/False
        msgtype, params = socketproto.read_message(client)

        if msgtype == socketproto.Messages.AddProxy:
            src, dest = params
            try:
                portforward.add_mapping(src, dest)
                socketproto.write_message(client, True)
                logger.debug("Done")
            except socket.error as e:
                socketproto.write_message(client, False)
                logger.debug("Fail\n\t-%s", e)

        elif msgtype == socketproto.Messages.DelProxy:
            src = params
            try:
                portforward.del_mapping(src)
                socketproto.write_message(client, True)
                logger.debug("Done")
            except KeyError:
                socketproto.write_message(client, False)
                logger.debug("Fail")
Exemplo n.º 4
0
        "Could not bind to proxy socket - is another instance running?")
    sys.exit(1)
server.listen(1)

try:
    while True:
        client, _ = server.accept()

        # Go ahead and assume a command, since the client
        # will never send a lone True/False
        msgtype, params = socketproto.read_message(client)

        if msgtype == socketproto.Messages.AddProxy:
            src, dest = params
            try:
                portforward.add_mapping(src, dest)
                socketproto.write_message(client, True)
                logger.debug("Done")
            except socket.error as e:
                socketproto.write_message(client, False)
                logger.debug("Fail\n\t-%s", e)

        elif msgtype == socketproto.Messages.DelProxy:
            src = params
            try:
                portforward.del_mapping(src)
                socketproto.write_message(client, True)
                logger.debug("Done")
            except KeyError:
                socketproto.write_message(client, False)
                logger.debug("Fail")