예제 #1
0
def start(_settings, _backend, telnet_port=8023):
    """
    Start telnet server
    """
    global settings
    global backend
    backend = _backend

    # Settings
    settings = _settings()

    # Thread sensitive interface for stdout/stdin
    std.setup()

    # Telnet
    telnet_factory = ServerFactory()
    telnet_factory.protocol = lambda: TelnetTransport(TelnetDeployer)

    # Handle signals
    def handle_sigint(signal, frame):
        if active_sessions:
            print 'Running, %i active session(s).' % len(active_sessions)
        else:
            print 'No active sessions, exiting'
            reactor.stop()

    signal.signal(signal.SIGINT, handle_sigint)

    # Run the reactor!
    print 'Listening telnet on localhost:%s...' % telnet_port

    reactor.listenTCP(telnet_port, telnet_factory)
    reactor.run()
예제 #2
0
    def run_server():
        # Set logging
        stream = None
        if logfile:
            logging.basicConfig(filename=logfile, level=logging.DEBUG)
        elif not daemonized:
            logging.basicConfig(filename="/dev/stdout", level=logging.DEBUG)
        else:
            # If no logging file was given, and we're daemonized, create a temp
            # logfile for monitoring.
            stream = NamedTemporaryFile(delete=True, suffix=socket2.replace("/", "-"))
            logging.basicConfig(stream=stream, level=logging.DEBUG)

        logging.info("Socket server started at %s" % socket2)

        # Thread sensitive interface for stdout/stdin
        std.setup()

        # Set thread pool size (max parrallel interactive processes.)
        if thread_pool_size:
            reactor.suggestThreadPoolSize(thread_pool_size)

        # Set process name
        set_title(stream.name if stream else logfile)

        # Run Twisted reactor
        reactor.run()

        # Remove logging file (this will automatically delete the NamedTemporaryFile)
        if stream:
            stream.close()
예제 #3
0
def start(_settings, _backend, telnet_port=8023):
    """
    Start telnet server
    """
    global settings
    global backend
    backend = _backend

    # Settings
    settings = _settings()

    # Thread sensitive interface for stdout/stdin
    std.setup()

    # Telnet
    telnet_factory = ServerFactory()
    telnet_factory.protocol = lambda: TelnetTransport(TelnetDeployer)

    # Handle signals
    def handle_sigint(signal, frame):
        if active_sessions:
            print 'Running, %i active session(s).' % len(active_sessions)
        else:
            print 'No active sessions, exiting'
            reactor.stop()

    signal.signal(signal.SIGINT, handle_sigint)

    # Run the reactor!
    print 'Listening telnet on localhost:%s...' % telnet_port

    reactor.listenTCP(telnet_port, telnet_factory)
    reactor.run()
예제 #4
0
    def run_server():
        # Set logging
        stream = None
        if logfile:
            logging.basicConfig(filename=logfile, level=logging.DEBUG)
        elif not daemonized:
            logging.basicConfig(filename='/dev/stdout', level=logging.DEBUG)
        else:
            # If no logging file was given, and we're daemonized, create a temp
            # logfile for monitoring.
            stream = NamedTemporaryFile(delete=True, suffix=socket2.replace('/', '-'))
            logging.basicConfig(stream=stream, level=logging.DEBUG)

        logging.info('Socket server started at %s' % socket2)

        # Thread sensitive interface for stdout/stdin
        std.setup()

        # Set thread pool size (max parrallel interactive processes.)
        if thread_pool_size:
            reactor.suggestThreadPoolSize(thread_pool_size)

        # Set process name
        set_title(stream.name if stream else logfile)

        # Run Twisted reactor
        reactor.run()

        # Remove logging file (this will automatically delete the NamedTemporaryFile)
        if stream:
            stream.close()
예제 #5
0
def start(root_node,
          auth_backend=None,
          port=8023,
          logfile=None,
          extra_loggers=None):
    """
    Start telnet server
    """
    # Set logging
    if logfile:
        logging.basicConfig(filename=logfile, level=logging.DEBUG)
    else:
        logging.basicConfig(filename='/dev/stdout', level=logging.DEBUG)

    # Thread sensitive interface for stdout/stdin
    std.setup()

    # Telnet
    factory = ServerFactory()
    factory.connectionPool = set()  # List of currently, active connections
    factory.protocol = lambda: TelnetTransport(TelnetDeployer)
    factory.root_node = root_node()
    factory.auth_backend = auth_backend
    factory.extra_loggers = extra_loggers or []

    # Handle signals
    def handle_sigint(signal, frame):
        if factory.connectionPool:
            logging.info('Running, %i active session(s).' %
                         len(factory.connectionPool))
        else:
            logging.info('No active sessions, exiting')
            reactor.stop()

    signal.signal(signal.SIGINT, handle_sigint)

    # Run the reactor!
    logging.info(
        'Listening for incoming telnet connections on localhost:%s...' % port)

    # Set process name
    suffix = (' --log "%s"' % logfile if logfile else '')
    setproctitle('deploy:%s telnet-server --port %i%s' %
                 (root_node.__class__.__name__, port, suffix))

    # Run server
    reactor.listenTCP(port, factory)
    reactor.run()
예제 #6
0
def start(root_node, auth_backend=None, port=8023, logfile=None, extra_loggers=None):
    """
    Start telnet server
    """
    # Set logging
    if logfile:
        logging.basicConfig(filename=logfile, level=logging.DEBUG)
    else:
        logging.basicConfig(filename='/dev/stdout', level=logging.DEBUG)

    # Thread sensitive interface for stdout/stdin
    std.setup()

    # Telnet
    factory = ServerFactory()
    factory.connectionPool = set() # List of currently, active connections
    factory.protocol = lambda: TelnetTransport(TelnetDeployer)
    factory.root_node = root_node()
    factory.auth_backend = auth_backend
    factory.extra_loggers = extra_loggers or []

    # Handle signals
    def handle_sigint(signal, frame):
        if factory.connectionPool:
            logging.info('Running, %i active session(s).' % len(factory.connectionPool))
        else:
            logging.info('No active sessions, exiting')
            reactor.stop()

    signal.signal(signal.SIGINT, handle_sigint)

    # Run the reactor!
    logging.info('Listening for incoming telnet connections on localhost:%s...' % port)

    # Set process name
    suffix = (' --log "%s"' % logfile if logfile else '')
    setproctitle('deploy:%s telnet-server --port %i%s' %
            (root_node.__class__.__name__, port, suffix))

    # Run server
    reactor.listenTCP(port, factory)
    reactor.run()
예제 #7
0
 def __init__(self, copy_to_original_stdout=True):
     self.copy_to_original_stdout = copy_to_original_stdout
     std.setup()
예제 #8
0
 def __init__(self, copy_to_original_stdout=True):
     self.copy_to_original_stdout = copy_to_original_stdout
     std.setup()