Esempio n. 1
0
def server_cmd():

    logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG)

    parser = argparse.ArgumentParser(usage='pywizard-screen-server [options] -- [command to execute]')
    parser.add_argument('--in', type=str, default='127.0.0.1:5556', dest='in_addr',
                        help="Address for screen input. Dafault: 127.0.0.1:5556")
    parser.add_argument('--out', type=str, default='127.0.0.1:5557', dest='out_addr',
                        help="Address for screen output. Default: 127.0.0.1:5557")

    parser.add_argument('--https', action='store_true', default=False)
    parser.add_argument('--client-auth', action='store_true', default=False)
    parser.add_argument('--cert', type=str, default=None)
    parser.add_argument('--cert-key', type=str, default=None)
    parser.add_argument('--client-auth-cert-ca', type=str, default=None)

    kwargs = parser.parse_args()

    if kwargs.https and (not kwargs.cert or not kwargs.cert_key):
        print 'If --https enabled, --cert and --cert-key are required!'
        exit(1)

    if kwargs.client_auth and (not kwargs.https or not kwargs.client_auth_cert_ca):
        print 'If --client-auth enabled, --https and --client-auth-cert-ca are required!'
        exit(1)

    in_stream, socket_out = connect_sockets(kwargs.in_addr, kwargs.out_addr, server=True)

    kwargs = dict(kwargs.__dict__)
    del kwargs['in_addr']
    del kwargs['out_addr']

    logging.info('Starting server on port 8888')
    PywizrdTerminalServer(in_stream=in_stream, socket_out=socket_out, **kwargs).listen(8888)
Esempio n. 2
0
def screen_cmd():
    logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG)

    parser = argparse.ArgumentParser(usage='pywizard-screen [options] -- [command to execute]')
    parser.add_argument('--id', type=str, help="Terminal id. 36 chars", default=uuid())

    parser.add_argument('--in', type=str, default='127.0.0.1:5557', dest='in_addr',
                        help="Address for screen input. Dafault: 127.0.0.1:5557")
    parser.add_argument('--out', type=str, default='127.0.0.1:5556', dest='out_addr',
                        help="Address for screen output. Default: 127.0.0.1:5556")

    try:
        pos = sys.argv.index('--')
        argv = sys.argv[1:pos]
        if pos == (len(sys.argv) - 1):
            command = None
        else:
            command = sys.argv[pos + 1:]

    except ValueError:
        argv = sys.argv[1:]
        command = None

    args = parser.parse_args(argv)

    if not command:
        parser.print_help()
    else:
        logging.info('Screen id: %s' % args.id)
        exec_with_remote_screen(args.id, command, *connect_sockets(args.in_addr, args.out_addr, subscribe_id=args.id))
Esempio n. 3
0
def test_simple_connect():
    in_stream, socket_out = connect_sockets('127.0.0.1:5557', '127.0.0.1:5556')

    assert not in_stream is None
    assert not socket_out is None