示例#1
0
def test_DoS(client_class_constructor, args):
    """ utility method for running DoS tests
        See: test_DoS_*_client.py
    """

    assert len(args) == 2, "usage: test_DoS_client :DISPLAY"
    import socket
    from xpra.dotxpra import DotXpra
    from xpra.protocol import SocketConnection
    import logging
    logging.root.setLevel(logging.DEBUG)
    logging.root.addHandler(logging.StreamHandler(sys.stderr))
    opts = AdHocStruct()
    opts.password_file = ""
    opts.encoding = "rgb24"
    opts.jpegquality = 0
    display = sys.argv[1]
    target = DotXpra().socket_path(display)
    print("will attempt to connect to socket: %s" % target)
    sock = socket.socket(socket.AF_UNIX)
    sock.connect(target)
    conn = SocketConnection(sock)
    print("socket connection=%s" % conn)
    app = client_class_constructor(conn, opts)
    try:
        app.run()
    finally:
        app.cleanup()
    print("ended")
    print("")
示例#2
0
        elif len(live_servers) == 1:
            return parse_display_name(parser, opts, live_servers[0])
        else:
            parser.error("there are multiple servers running, please specify")
    elif len(extra_args) == 1:
        return parse_display_name(parser, opts, extra_args[0])
    else:
        parser.error("too many arguments")


def _socket_connect(sock, target):
    try:
        sock.connect(target)
    except socket.error, e:
        sys.exit("Connection failed: %s" % (e, ))
    return SocketConnection(sock, target)


def connect_or_fail(display_desc):
    if display_desc["type"] == "ssh":
        cmd = (display_desc["full_remote_xpra"] + ["_proxy"] +
               display_desc["display_as_args"])
        try:
            child = Popen(cmd, stdin=PIPE, stdout=PIPE)
        except OSError, e:
            sys.exit("Error running ssh program '%s': %s" % (cmd[0], e))

        def abort_test(action):
            """ if ssh dies, we don't need to try to read/write from its sockets """
            e = child.poll()
            if e is not None:
示例#3
0
        elif len(live_servers) == 1:
            return parse_display_name(parser, opts, live_servers[0])
        else:
            parser.error("there are multiple servers running, please specify")
    elif len(extra_args) == 1:
        return parse_display_name(parser, opts, extra_args[0])
    else:
        parser.error("too many arguments")


def _socket_connect(sock, target):
    try:
        sock.connect(target)
    except socket.error, e:
        sys.exit("Connection failed: %s" % (e, ))
    return SocketConnection(sock)


def connect_or_fail(display_desc):
    if display_desc["type"] == "ssh":
        cmd = (display_desc["full_remote_xpra"] + ["_proxy"] +
               display_desc["display_as_args"])
        try:
            child = Popen(cmd, stdin=PIPE, stdout=PIPE)
        except OSError, e:
            sys.exit("Error running ssh program '%s': %s" % (cmd[0], e))

        def abort_test(action):
            """ if ssh dies, we don't need to try to read/write from its sockets """
            e = child.poll()
            if e is not None:
示例#4
0
class ApplicationWindow:
    def __init__(self):
        pass

    def create_window(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_default_size(400, 300)
        self.window.set_border_width(20)
        self.window.set_title(APPLICATION_NAME)
        icon_pixbuf = get_icon_from_file(os.path.join(ICONS_DIR, "xpra.png"))
        if icon_pixbuf:
            self.window.set_icon(icon_pixbuf)
        self.window.set_position(gtk.WIN_POS_CENTER)

        vbox = gtk.VBox(False, 0)
        vbox.set_spacing(15)

        # Title
        hbox = gtk.HBox(False, 0)
        if icon_pixbuf:
            image = gtk.Image()
            image.set_from_pixbuf(icon_pixbuf)
            hbox.pack_start(image)
        label = gtk.Label("Connect to xpra server")
        label.modify_font(pango.FontDescription("sans 13"))
        hbox.pack_start(label)
        vbox.pack_start(hbox)

        # Mode:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("Mode: "))
        self.mode_combo = gtk.combo_box_new_text()
        self.mode_combo.get_model().clear()
        self.mode_combo.append_text("tcp")
        if not sys.platform.startswith("win"):
            #when we fix the build on win32 to include putty
            #this can be enabled again:
            self.mode_combo.append_text("ssh")
        if xpra_opts.mode == "tcp" or sys.platform.startswith("win"):
            self.mode_combo.set_active(0)
        else:
            self.mode_combo.set_active(1)

        def mode_changed(*args):
            if self.mode_combo.get_active_text() == "ssh":
                self.port_entry.set_text("22")
            else:
                self.port_entry.set_text("%s" % xpra_opts.port)

        self.mode_combo.connect("changed", mode_changed)
        hbox.pack_start(self.mode_combo)
        vbox.pack_start(hbox)

        # Encoding:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("Encoding: "))
        self.encoding_combo = gtk.combo_box_new_text()
        self.encoding_combo.get_model().clear()
        for option in XPRA_ENCODING_OPTIONS:
            self.encoding_combo.append_text(option)
        self.encoding_combo.set_active(
            XPRA_ENCODING_OPTIONS.index(xpra_opts.encoding))
        hbox.pack_start(self.encoding_combo)
        vbox.pack_start(hbox)

        # JPEG:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        self.jpeg_label = gtk.Label("JPEG Compression: ")
        hbox.pack_start(self.jpeg_label)
        self.jpeg_combo = gtk.combo_box_new_text()
        self.jpeg_combo.get_model().clear()
        for option in XPRA_COMPRESSION_OPTIONS:
            self.jpeg_combo.append_text(option)
        self.jpeg_combo.set_active(2)
        hbox.pack_start(self.jpeg_combo)
        vbox.pack_start(hbox)
        self.encoding_combo.connect("changed", self.encoding_changed)

        # Host:Port
        hbox = gtk.HBox(False, 0)
        hbox.set_spacing(5)
        self.host_entry = gtk.Entry(max=128)
        self.host_entry.set_width_chars(40)
        self.host_entry.set_text(xpra_opts.host)
        self.port_entry = gtk.Entry(max=5)
        self.port_entry.set_width_chars(5)
        self.port_entry.set_text(str(xpra_opts.port))
        hbox.pack_start(self.host_entry)
        hbox.pack_start(gtk.Label(":"))
        hbox.pack_start(self.port_entry)
        vbox.pack_start(hbox)

        # Password
        hbox = gtk.HBox(False, 0)
        hbox.set_spacing(20)
        self.password_entry = gtk.Entry(max=128)
        self.password_entry.set_width_chars(30)
        self.password_entry.set_text("")
        self.password_entry.set_visibility(False)
        hbox.pack_start(gtk.Label("Password: "******"red")
        if color_obj:
            self.info.modify_fg(gtk.STATE_NORMAL, color_obj)
        vbox.pack_start(self.info)

        # Connect button:
        self.button = gtk.Button("Connect")
        self.button.connect("clicked", self.connect_clicked, None)
        connect_icon = get_icon_from_file(os.path.join(ICONS_DIR, "retry.png"))
        if connect_icon:
            self.button.set_image(scaled_image(connect_icon, 24))
        vbox.pack_start(self.button)

        def accel_close(*args):
            gtk.main_quit()

        add_close_accel(self.window, accel_close)

        self.window.add(vbox)

    def show(self):
        self.window.show_all()
        self.encoding_changed()

    def run(self):
        self.show()
        gtk.main()

    def encoding_changed(self, *args):
        is_jpeg = self.encoding_combo.get_active_text() == "jpeg"
        if is_jpeg:
            self.jpeg_combo.show()
            self.jpeg_label.show()
        else:
            self.jpeg_combo.hide()
            self.jpeg_label.hide()

    def do_connect(self):
        if xpra_opts.mode == "tcp" and not sys.platform.startswith("win"):
            """ Use built-in connector (faster and gives feedback) - does not work on win32... (dunno why) """
            self.connect_tcp()
        else:
            self.launch_xpra()

    def connect_clicked(self, *args):
        self.update_options_from_gui()
        self.do_connect()

    def connect_tcp(self):
        self.info.set_text("Connecting.")
        host = xpra_opts.host
        port = xpra_opts.port
        self.info.set_text("Connecting..")
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.info.set_text("Connecting...")
            sock.connect((host, int(port)))
        except Exception, e:
            self.info.set_text("Socket error: %s" % e)
            print("error %s" % e)
            return
        self.info.set_text("Connection established")
        try:
            from xpra.protocol import SocketConnection
            global socket_wrapper
            socket_wrapper = SocketConnection(sock, "xprahost")
        except Exception, e:
            self.info.set_text("Xpra Client error: %s" % e)
            print("Xpra Client error: %s" % e)
            return
示例#5
0
class ApplicationWindow:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_default_size(400, 300)
        self.window.set_border_width(20)

        # Title
        vbox = gtk.VBox(False, 0)
        vbox.set_spacing(15)
        label = gtk.Label("Connect to xpra server")
        label.modify_font(pango.FontDescription("sans 13"))
        vbox.pack_start(label)

        # Mode:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("Mode: "))
        self.mode_combo = gtk.combo_box_new_text()
        self.mode_combo.get_model().clear()
        for option in ["tcp", "ssh"]:
            self.mode_combo.append_text(option)
        self.mode_combo.set_active(0)
        hbox.pack_start(self.mode_combo)
        vbox.pack_start(hbox)

        # JPEG:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("JPEG Compression: "))
        self.jpeg_combo = gtk.combo_box_new_text()
        self.jpeg_combo.get_model().clear()
        for option in XPRA_COMPRESSION_OPTIONS:
            self.jpeg_combo.append_text(option)
        self.jpeg_combo.set_active(0)
        hbox.pack_start(self.jpeg_combo)
        vbox.pack_start(hbox)

        # Host:Port
        hbox = gtk.HBox(False, 0)
        hbox.set_spacing(5)
        self.host_entry = gtk.Entry(max=128)
        self.host_entry.set_width_chars(40)
        if len(sys.argv) > 1:
            self.host_entry.set_text(sys.argv[1])
        else:
            self.host_entry.set_text("127.0.0.1")
        self.port_entry = gtk.Entry(max=5)
        self.port_entry.set_width_chars(5)
        if len(sys.argv) > 2:
            self.port_entry.set_text(sys.argv[2])
        else:
            self.port_entry.set_text("16010")
        hbox.pack_start(self.host_entry)
        hbox.pack_start(gtk.Label(":"))
        hbox.pack_start(self.port_entry)
        vbox.pack_start(hbox)

        # Info Label
        self.info = gtk.Label()
        self.info.set_line_wrap(True)
        self.info.set_size_request(360, -1)
        vbox.pack_start(self.info)

        # Connect button:
        self.button = gtk.Button("Connect")
        self.button.connect("clicked", self.connect_clicked, None)
        vbox.pack_start(self.button)

        self.window.add(vbox)
        self.window.show_all()

    def connect_tcp(self):
        self.info.set_text("Connecting.")
        host = self.host_entry.get_text()
        port = self.port_entry.get_text()
        self.info.set_text("Connecting..")
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.info.set_text("Connecting...")
            sock.connect((host, int(port)))
        except Exception, e:
            self.info.set_text("Socket error: %s" % e)
            return
        self.info.set_text("Connection established")
        try:
            from xpra.protocol import SocketConnection
            global socket_wrapper
            socket_wrapper = SocketConnection(sock)
        except Exception, e:
            self.info.set_text("Xpra Client error: %s" % e)
            return
示例#6
0
class ApplicationWindow:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_default_size(400, 300)
        self.window.set_border_width(20)

        # Title
        vbox = gtk.VBox(False, 0)
        vbox.set_spacing(15)
        label = gtk.Label("Connect to xpra server")
        label.modify_font(pango.FontDescription("sans 13"))
        vbox.pack_start(label)

        # Mode:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("Mode: "))
        self.mode_combo = gtk.combo_box_new_text()
        self.mode_combo.get_model().clear()
        self.mode_combo.append_text("tcp")
        if not sys.platform.startswith("win"):
            #when we fix the build on win32 to include putty
            #this can be enabled again:
            self.mode_combo.append_text("ssh")
        if xpra_opts.mode == "tcp" or sys.platform.startswith("win"):
            self.mode_combo.set_active(0)
        else:
            self.mode_combo.set_active(1)
        hbox.pack_start(self.mode_combo)
        vbox.pack_start(hbox)

        # Encoding:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("Encoding: "))
        self.encoding_combo = gtk.combo_box_new_text()
        self.encoding_combo.get_model().clear()
        for option in XPRA_ENCODING_OPTIONS:
            self.encoding_combo.append_text(option)
        self.encoding_combo.set_active(
            XPRA_ENCODING_OPTIONS.index(xpra_opts.encoding))
        hbox.pack_start(self.encoding_combo)
        vbox.pack_start(hbox)

        # JPEG:
        hbox = gtk.HBox(False, 20)
        hbox.set_spacing(20)
        hbox.pack_start(gtk.Label("JPEG Compression: "))
        self.jpeg_combo = gtk.combo_box_new_text()
        self.jpeg_combo.get_model().clear()
        for option in XPRA_COMPRESSION_OPTIONS:
            self.jpeg_combo.append_text(option)
        self.jpeg_combo.set_active(2)
        hbox.pack_start(self.jpeg_combo)
        vbox.pack_start(hbox)

        # Host:Port
        hbox = gtk.HBox(False, 0)
        hbox.set_spacing(5)
        self.host_entry = gtk.Entry(max=128)
        self.host_entry.set_width_chars(40)
        self.host_entry.set_text(xpra_opts.host)
        self.port_entry = gtk.Entry(max=5)
        self.port_entry.set_width_chars(5)
        self.port_entry.set_text(str(xpra_opts.port))
        hbox.pack_start(self.host_entry)
        hbox.pack_start(gtk.Label(":"))
        hbox.pack_start(self.port_entry)
        vbox.pack_start(hbox)

        # Password
        hbox = gtk.HBox(False, 0)
        hbox.set_spacing(20)
        self.password_entry = gtk.Entry(max=128)
        self.password_entry.set_width_chars(30)
        self.password_entry.set_text("")
        self.password_entry.set_visibility(False)
        hbox.pack_start(gtk.Label("Password: "******"Connect")
        self.button.connect("clicked", self.connect_clicked, None)
        vbox.pack_start(self.button)

        self.window.add(vbox)
        self.window.show_all()

    def connect_tcp(self):
        self.info.set_text("Connecting.")
        host = xpra_opts.host
        port = xpra_opts.port
        self.info.set_text("Connecting..")
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.info.set_text("Connecting...")
            sock.connect((host, int(port)))
        except Exception, e:
            self.info.set_text("Socket error: %s" % e)
            print("error %s" % e)
            return
        self.info.set_text("Connection established")
        try:
            from xpra.protocol import SocketConnection
            global socket_wrapper
            socket_wrapper = SocketConnection(sock, "xprahost")
        except Exception, e:
            self.info.set_text("Xpra Client error: %s" % e)
            print("Xpra Client error: %s" % e)
            return