def do_test_control_send_file(self, data): f = self._temp_file(data) try: display = self.find_free_display() server = self.check_start_server(display) xvfb, client = self.run_client(display, "--file-transfer=yes") assert pollwait(client, CLIENT_TIMEOUT) is None #send a file to this client: send_file_command = [ "control", display, "send-file", f.name, "0", "*" ] send_file = self.run_xpra(send_file_command) assert pollwait( send_file, CLIENT_TIMEOUT ) == 0, "send-file command returncode is %s" % send_file.poll() time.sleep(1) #now verify the file can be found in the download directory from xpra.platform.paths import get_download_dir filename = os.path.join(os.path.expanduser(get_download_dir()), os.path.basename(f.name)) assert os.path.exists(filename), "cannot find %s" % filename readback = load_binary_file(filename) assert readback == data, "file data corrupted" os.unlink(filename) #cleanup: client.terminate() xvfb.terminate() server.terminate() finally: f.close()
def safe_open_download_file(basefilename, mimetype): from xpra.platform.paths import get_download_dir #make sure we use a filename that does not exist already: dd = os.path.expanduser(get_download_dir()) wanted_filename = os.path.abspath(os.path.join(dd, os.path.basename(basefilename))) ext = MIMETYPE_EXTS.get(mimetype) if ext: #on some platforms (win32), #we want to force an extension #so that the file manager can display them properly when you double-click on them if not wanted_filename.endswith("."+ext): wanted_filename += "."+ext filename = wanted_filename base = 0 while os.path.exists(filename): filelog("cannot save file as %s: file already exists", filename) root, ext = os.path.splitext(wanted_filename) base += 1 filename = root+("-%s" % base)+ext flags = os.O_CREAT | os.O_RDWR | os.O_EXCL try: flags |= os.O_BINARY #@UndefinedVariable (win32 only) except: pass fd = os.open(filename, flags) filelog("using filename '%s'", filename) return filename, fd
def safe_open_download_file(basefilename, mimetype): from xpra.platform.paths import get_download_dir dd = os.path.expanduser(get_download_dir()) filename = os.path.abspath(os.path.join(dd, basename(basefilename))) ext = MIMETYPE_EXTS.get(mimetype) if ext and not filename.endswith("."+ext): #on some platforms (win32), #we want to force an extension #so that the file manager can display them properly when you double-click on them filename += "."+ext #make sure we use a filename that does not exist already: root, ext = os.path.splitext(filename) base = 0 while os.path.exists(filename): filelog("cannot save file as %s: file already exists", filename) base += 1 filename = root+("-%s" % base)+ext filelog("safe_open_download_file(%s, %s) will use '%s'", basefilename, mimetype, filename) flags = os.O_CREAT | os.O_RDWR | os.O_EXCL try: flags |= os.O_BINARY #@UndefinedVariable (win32 only) except AttributeError: pass with umask_context(0o133): fd = os.open(filename, flags) filelog("using filename '%s', file descriptor=%s", filename, fd) return filename, fd
def safe_open_download_file(basefilename, mimetype): from xpra.platform.paths import get_download_dir #make sure we use a filename that does not exist already: dd = os.path.expanduser(get_download_dir()) wanted_filename = os.path.abspath( os.path.join(dd, os.path.basename(basefilename))) ext = MIMETYPE_EXTS.get(mimetype) if ext: #on some platforms (win32), #we want to force an extension #so that the file manager can display them properly when you double-click on them if not wanted_filename.endswith("." + ext): wanted_filename += "." + ext filename = wanted_filename base = 0 while os.path.exists(filename): filelog("cannot save file as %s: file already exists", filename) root, ext = os.path.splitext(wanted_filename) base += 1 filename = root + ("-%s" % base) + ext flags = os.O_CREAT | os.O_RDWR | os.O_EXCL try: flags |= os.O_BINARY #@UndefinedVariable (win32 only) except: pass fd = os.open(filename, flags) filelog("using filename '%s'", filename) return filename, fd
def main(): if "-v" in sys.argv or "--verbose" in sys.argv: log.enable_debug() add_debug_category("nvfbc") from xpra.platform import program_context with program_context("NvFBC-Capture", "NvFBC Capture"): from xpra.platform.paths import get_download_dir from xpra.util import print_nested_dict from xpra.os_util import WIN32, LINUX if WIN32: from xpra.codecs.nvfbc import fbc_capture_win as fbc_capture #@UnresolvedImport @UnusedImport elif LINUX: from xpra.codecs.nvfbc import fbc_capture_linux as fbc_capture #@UnresolvedImport @Reimport else: raise Exception("nvfbc is not support on %s" % sys.platform) fbc_capture.init_module() log.info("Info:") print_nested_dict(fbc_capture.get_info(), print_fn=log.info) log.info("Status:") print_nested_dict(fbc_capture.get_status(), print_fn=log.info) try: log("creating test capture class") if USE_NVFBC_CUDA: c = fbc_capture.NvFBC_CUDACapture() #@UndefinedVariable else: c = fbc_capture.NvFBC_SysCapture() #@UndefinedVariable log("Capture=%s", c) c.init_context() assert c.refresh() except Exception as e: log("Capture()", exc_info=True) log.error("Error: failed to create test capture instance:") log.error(" %s", e) return 1 image = c.get_image() assert image from PIL import Image w = image.get_width() h = image.get_height() pixels = memoryview_to_bytes(image.get_pixels()) stride = image.get_rowstride() rgb_format = image.get_pixel_format() try: img = Image.frombuffer("RGB", (w, h), pixels, "raw", rgb_format, stride, 1) filename = os.path.join( os.path.expanduser(get_download_dir()), "screenshot-%s-%i.png" % (rgb_format, time.time())) img.save(filename, "png") log.info("screenshot saved to %s", filename) return 0 except Exception as e: log.warn("Error: failed to save %s:", rgb_format) log.warn(" %s", e) return 1
def show_downloads(self, _btn): downloads = os.path.expanduser(get_download_dir()) if WIN32: os.startfile(downloads) #@UndefinedVariable pylint: disable=no-member return if OSX: cmd = ["open", downloads] else: cmd = ["xdg-open", downloads] proc = subprocess.Popen(cmd) getChildReaper().add_process(proc, "show-downloads", cmd, ignore=True, forget=True)
def main(): import sys import os.path if "-v" in sys.argv or "--verbose" in sys.argv: log.enable_debug() from xpra.platform import program_context with program_context("Screen-Capture", "Screen Capture"): capture = GDICapture() image = capture.take_screenshot() from xpra.platform.paths import get_download_dir filename = os.path.join(get_download_dir(), "gdi-screenshot-%i.png" % time.time()) with open(filename, 'wb') as f: f.write(image[4])
def __init__(self, show_file_upload_cb=None): self.show_file_upload_cb = show_file_upload_cb self.populate_timer = None self.table = None self.requests = [] self.expire_labels = {} self.window = gtk.Window() window_defaults(self.window) self.window.connect("delete-event", self.close) self.window.set_default_size(400, 150) self.window.set_title("Transfers") icon_pixbuf = self.get_icon("download.png") if icon_pixbuf: self.window.set_icon(icon_pixbuf) self.window.set_position(WIN_POS_CENTER) vbox = gtk.VBox(False, 0) vbox.set_spacing(10) self.alignment = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0) vbox.pack_start(self.alignment, expand=True, fill=True) # Buttons: hbox = gtk.HBox(False, 20) vbox.pack_start(hbox) def btn(label, tooltip, callback, icon_name=None): b = self.btn(label, tooltip, callback, icon_name) hbox.pack_start(b) if self.show_file_upload_cb: btn("Upload", "", self.show_file_upload_cb, "upload.png") btn("Close", "", self.close, "quit.png") downloads = get_download_dir() if downloads: btn("Show Downloads Folder", "", self.show_downloads, "browse.png") def accel_close(*_args): self.close() add_close_accel(self.window, accel_close) vbox.show_all() self.window.vbox = vbox self.window.add(vbox) self.populate_table()
def show_downloads(self, _btn): downloads = os.path.expanduser(get_download_dir()) if WIN32: os.startfile(downloads) #@UndefinedVariable pylint: disable=no-member return if OSX: cmd = ["open", downloads] else: cmd = ["xdg-open", downloads] try: proc = subprocess.Popen(cmd) except Exception as e: log("show_downloads()", exc_info=True) log.error("Error: failed to open 'Downloads' folder:") log.error(" %s", e) else: getChildReaper().add_process(proc, "show-downloads", cmd, ignore=True, forget=True)
def do_test_control_send_file(self, data): f = self._temp_file(data) try: display = self.find_free_display() server = self.check_start_server(display) xvfb, client = self.run_client(display) assert pollwait(client, CLIENT_TIMEOUT) is None #send a file to this client: send_file_command = ["control", display, "send-file", f.name, "1", "*"] send_file = self.run_xpra(send_file_command) assert pollwait(send_file, CLIENT_TIMEOUT)==0, "send-file command returncode is %s" % send_file.poll() #now verify the file can be found in the download directory from xpra.platform.paths import get_download_dir filename = os.path.join(os.path.expanduser(get_download_dir()), os.path.basename(f.name)) assert os.path.exists(filename), "cannot find %s" % filename readback = load_binary_file(filename) assert readback==data os.unlink(filename) #cleanup: client.terminate() xvfb.terminate() server.terminate() finally: f.close()
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS, DEFAULT_PULSEAUDIO_COMMAND, XDUMMY, XDUMMY_WRAPPER, DISPLAYFD, DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_default_log_dir, get_socket_dirs, get_remote_run_xpra_scripts try: from xpra.platform.info import get_username username = get_username() except: username = "" if WIN32 or OSX or PYTHON3: xvfb = "" elif XDUMMY: xvfb = get_Xdummy_command(use_wrapper=XDUMMY_WRAPPER, log_dir=get_default_log_dir()) else: xvfb = get_Xvfb_command() def addtrailingslash(v): if v.endswith("/"): return v return v+"/" if WIN32: bind_dirs = [] else: bind_dirs = [addtrailingslash(get_socket_dirs()[0])] GLOBAL_DEFAULTS = { "encoding" : "", "title" : "@title@ on @client-machine@", "username" : username, "auth" : "", "vsock-auth" : "", "tcp-auth" : "", "wm-name" : DEFAULT_NET_WM_NAME, "session-name" : "", "dock-icon" : "", "tray-icon" : "", "window-icon" : "", "password-file" : "", "clipboard" : "yes", "clipboard-filter-file" : "", "remote-clipboard" : "CLIPBOARD", "local-clipboard" : "CLIPBOARD", "pulseaudio-command": " ".join(DEFAULT_PULSEAUDIO_COMMAND), "encryption" : "", "tcp-encryption" : "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "ssh" : DEFAULT_SSH_COMMAND, "xvfb" : " ".join(xvfb), "socket-dir" : "", "log-dir" : get_default_log_dir(), "log-file" : "$DISPLAY.log", "border" : "auto,5:off", "window-close" : "auto", "max-size" : "", "desktop-scaling" : "auto", "display" : "", "tcp-proxy" : "", "download-path" : get_download_dir(), "open-command" : OPEN_COMMAND, "remote-logging" : "both", "lpadmin" : "/usr/sbin/lpadmin", "lpinfo" : "/usr/sbin/lpinfo", "pdf-printer" : "", "postscript-printer": "", "debug" : "", "input-method" : "none", "sound-source" : "", "html" : "", "socket-permissions": "600", "exec-wrapper" : "", "dbus-launch" : "dbus-launch --close-stderr", "webcam" : "auto", "quality" : 0, "min-quality" : 30, "speed" : 0, "min-speed" : 30, "compression_level" : 1, "dpi" : 0, "video-scaling" : 1, "file-size-limit" : 10, "idle-timeout" : 0, "server-idle-timeout" : 0, "sync-xvfb" : 0, "auto-refresh-delay": 0.15, "daemon" : CAN_DAEMONIZE, "use-display" : False, "displayfd" : DISPLAYFD, "fake-xinerama" : not OSX and not WIN32, "resize-display" : not OSX and not WIN32, "tray" : True, "pulseaudio" : not OSX and not WIN32, "dbus-proxy" : not OSX and not WIN32, "mmap" : ["off", "on"][not OSX and not WIN32], "mmap-group" : False, "speaker" : ["disabled", "on"][has_sound_support], "microphone" : ["disabled", "off"][has_sound_support], "readonly" : False, "keyboard-sync" : True, "pings" : False, "cursors" : True, "bell" : True, "notifications" : True, "xsettings" : not OSX and not WIN32, "system-tray" : True, "sharing" : False, "delay-tray" : False, "windows" : True, "exit-with-children": False, "exit-with-client" : False, "start-after-connect": False, "start-new-commands": False, "av-sync" : True, "exit-ssh" : True, "dbus-control" : not WIN32 and not OSX, "opengl" : OPENGL_DEFAULT, "mdns" : not WIN32, "file-transfer" : True, "printing" : True, "open-files" : False, "swap-keys" : OSX, #only used on osx "shadow-fullscreen" : False, "global-menus" : True, "pulseaudio-configure-commands" : [" ".join(x) for x in DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS], "socket-dirs" : [], "remote-xpra" : get_remote_run_xpra_scripts(), "encodings" : ["all"], "video-encoders" : ["all"], "csc-modules" : ["all"], "video-decoders" : ["all"], "speaker-codec" : [], "microphone-codec" : [], "compressors" : ["all"], "packet-encoders" : ["all"], "key-shortcut" : get_default_key_shortcuts(), "bind" : bind_dirs, "bind-vsock" : [], "bind-tcp" : [], "start" : [], "start-child" : [], "start-after-connect" : [], "start-child-after-connect" : [], "start-on-connect" : [], "start-child-on-connect" : [], "env" : DEFAULT_ENV, } return GLOBAL_DEFAULTS
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS, DEFAULT_PULSEAUDIO_COMMAND, \ DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_remote_run_xpra_scripts try: from xpra.platform.info import get_username username = get_username() except: username = "" conf_dirs = [os.environ.get("XPRA_CONF_DIR")] build_root = os.environ.get("RPM_BUILD_ROOT") if build_root: conf_dirs.append(os.path.join(build_root, "etc", "xpra")) xpra_cmd = sys.argv[0] bin_dir = None if len(sys.argv) > 0: for strip in ("/usr/bin", "/bin"): pos = xpra_cmd.find(strip) if pos >= 0: bin_dir = xpra_cmd[:pos + len(strip)] root = xpra_cmd[:pos] or "/" conf_dirs.append(os.path.join(root, "etc", "xpra")) break if sys.prefix == "/usr": conf_dirs.append("/etc/xpra") else: conf_dirs.append(os.path.join(sys.prefix, "etc", "xpra")) for conf_dir in [x for x in conf_dirs if x]: if os.path.exists(conf_dir): break xvfb = detect_xvfb_command(conf_dir, bin_dir) def addtrailingslash(v): if v.endswith("/"): return v return v + "/" if WIN32: bind_dirs = ["Main"] else: bind_dirs = ["auto"] ssl_protocol = "TLSv1_2" if sys.version_info < (2, 7, 9): ssl_protocol = "SSLv23" GLOBAL_DEFAULTS = { "encoding": "", "title": "@title@ on @client-machine@", "username": username, "password": "", "auth": "", "vsock-auth": "", "tcp-auth": "", "ssl-auth": "", "wm-name": DEFAULT_NET_WM_NAME, "session-name": "", "dock-icon": "", "tray-icon": "", "window-icon": "", "password-file": "", "keyboard-raw": False, "keyboard-layout": "", "keyboard-layouts": [], "keyboard-variant": "", "keyboard-variants": [], "keyboard-options": "", "clipboard": "yes", "clipboard-direction": "both", "clipboard-filter-file": "", "remote-clipboard": "CLIPBOARD", "local-clipboard": "CLIPBOARD", "pulseaudio-command": " ".join(DEFAULT_PULSEAUDIO_COMMAND), "encryption": "", "tcp-encryption": "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "pidfile": "", "ssh": DEFAULT_SSH_COMMAND, "systemd-run": get_default_systemd_run(), "systemd-run-args": "", "xvfb": " ".join(xvfb), "socket-dir": "", "log-dir": "auto", "log-file": "$DISPLAY.log", "border": "auto,5:off", "window-close": "auto", "max-size": "", "desktop-scaling": "auto", "display": "", "tcp-proxy": "", "download-path": get_download_dir(), "open-command": OPEN_COMMAND, "remote-logging": "both", "lpadmin": "/usr/sbin/lpadmin", "lpinfo": "/usr/sbin/lpinfo", "add-printer-options": ["-E", "-o printer-is-shared=false", "-u allow:$USER"], "pdf-printer": "", "postscript-printer": DEFAULT_POSTSCRIPT_PRINTER, "debug": "", "input-method": "none", "sound-source": "", "html": "auto", "socket-permissions": "600", "exec-wrapper": "", "dbus-launch": "dbus-launch --close-stderr", "webcam": ["auto", "no"][OSX], #ssl options: "ssl": "auto", "ssl-key": "", "ssl-cert": "", "ssl-protocol": ssl_protocol, "ssl-ca-certs": "default", "ssl-ca-data": "", "ssl-ciphers": "DEFAULT", "ssl-client-verify-mode": "optional", "ssl-server-verify-mode": "required", "ssl-verify-flags": "X509_STRICT", "ssl-check-hostname": False, "ssl-server-hostname": "localhost", "ssl-options": "ALL,NO_COMPRESSION", "quality": 0, "min-quality": 30, "speed": 0, "min-speed": 30, "compression_level": 1, "dpi": 0, "video-scaling": 1, "file-size-limit": 100, "idle-timeout": 0, "server-idle-timeout": 0, "sync-xvfb": 0, "auto-refresh-delay": 0.15, "daemon": CAN_DAEMONIZE, "use-display": False, "fake-xinerama": not OSX and not WIN32, "resize-display": not OSX and not WIN32, "tray": True, "pulseaudio": not OSX and not WIN32, "dbus-proxy": not OSX and not WIN32, "mmap": ["no", "yes"][not OSX and not WIN32], "mmap-group": False, "speaker": ["disabled", "on"][has_sound_support()], "microphone": ["disabled", "off"][has_sound_support()], "readonly": False, "keyboard-sync": True, "pings": False, "cursors": True, "bell": True, "notifications": True, "xsettings": not OSX and not WIN32, "system-tray": True, "sharing": False, "delay-tray": False, "windows": True, "exit-with-children": False, "exit-with-client": False, "start-after-connect": False, "start-new-commands": False, "proxy-start-sessions": True, "av-sync": True, "exit-ssh": True, "dbus-control": not WIN32 and not OSX, "opengl": get_opengl_default(), "mdns": not WIN32, "file-transfer": True, "printing": True, "open-files": False, "swap-keys": OSX, #only used on osx "desktop-fullscreen": False, "global-menus": True, "pulseaudio-configure-commands": [" ".join(x) for x in DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS], "socket-dirs": [], "remote-xpra": get_remote_run_xpra_scripts(), "encodings": ["all"], "proxy-video-encoders": [], "video-encoders": ["all"], "csc-modules": ["all"], "video-decoders": ["all"], "speaker-codec": [], "microphone-codec": [], "compressors": ["all"], "packet-encoders": ["all"], "key-shortcut": get_default_key_shortcuts(), "bind": bind_dirs, "bind-vsock": [], "bind-tcp": [], "bind-ssl": [], "start": [], "start-child": [], "start-after-connect": [], "start-child-after-connect": [], "start-on-connect": [], "start-child-on-connect": [], "start-env": DEFAULT_ENV, "env": [], } return GLOBAL_DEFAULTS
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_COMMAND, XDUMMY, XDUMMY_WRAPPER, DISPLAYFD, DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_default_log_dir try: from xpra.platform.info import get_username username = get_username() except: username = "" if WIN32 or OSX or PYTHON3: xvfb = "" elif XDUMMY: xvfb = get_Xdummy_command(use_wrapper=XDUMMY_WRAPPER) else: xvfb = get_Xvfb_command() GLOBAL_DEFAULTS = { "encoding": "", "title": "@title@ on @client-machine@", "username": username, "auth": "", "tcp-auth": "", "wm-name": DEFAULT_NET_WM_NAME, "remote-xpra": "~/.xpra/run-xpra", "session-name": "", "dock-icon": "", "tray-icon": "", "window-icon": "", "password-file": "", "clipboard": "yes", "clipboard-filter-file": "", "remote-clipboard": "CLIPBOARD", "local-clipboard": "CLIPBOARD", "pulseaudio-command": DEFAULT_PULSEAUDIO_COMMAND, "encryption": "", "tcp-encryption": "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "ssh": DEFAULT_SSH_COMMAND, "xvfb": " ".join(xvfb), "socket-dir": "", "log-dir": get_default_log_dir(), "log-file": "$DISPLAY.log", "border": "auto,0", "max-size": "", "desktop-scaling": "auto", "display": "", "tcp-proxy": "", "download-path": get_download_dir(), "open-command": OPEN_COMMAND, "lpadmin": "/usr/sbin/lpadmin", "lpinfo": "/usr/sbin/lpinfo", "pdf-printer": "", "postscript-printer": "", "debug": "", "input-method": "none", "sound-source": "", "html": "", "socket-permissions": "600", "quality": 0, "min-quality": 30, "speed": 0, "min-speed": 0, "compression_level": 1, "dpi": 0, "video-scaling": 1, "file-size-limit": 10, "idle-timeout": 0, "server-idle-timeout": 0, "sync-xvfb": 0, "auto-refresh-delay": 0.15, "daemon": CAN_DAEMONIZE, "use-display": False, "displayfd": DISPLAYFD, "fake-xinerama": not OSX and not WIN32, "tray": True, "pulseaudio": not OSX and not WIN32, "dbus-proxy": not OSX and not WIN32, "mmap": not OSX and not WIN32, "mmap-group": False, "speaker": ["disabled", "on"][has_sound_support], "microphone": ["disabled", "off"][has_sound_support], "readonly": False, "keyboard-sync": True, "pings": False, "cursors": True, "bell": True, "notifications": True, "xsettings": not OSX and not WIN32, "system-tray": True, "sharing": False, "delay-tray": False, "windows": True, "exit-with-children": False, "exit-with-client": False, "start-new-commands": False, "remote-logging": WIN32 or OSX, "av-sync": True, "exit-ssh": True, "dbus-control": not WIN32 and not OSX, "opengl": OPENGL_DEFAULT, "mdns": not WIN32, "file-transfer": True, "printing": True, "open-files": False, "swap-keys": OSX, #only used on osx "shadow-fullscreen": False, "global-menus": True, "socket-dirs": [], "encodings": ["all"], "video-encoders": ["all"], "csc-modules": ["all"], "video-decoders": ["all"], "speaker-codec": [], "microphone-codec": [], "compressors": ["all"], "packet-encoders": ["all"], "key-shortcut": [ "Meta+Shift+F1:show_menu", "Meta+Shift+F2:show_start_new_command", "Meta+Shift+F4:quit", "Meta+Shift+F5:increase_quality", "Meta+Shift+F6:decrease_quality", "Meta+Shift+F7:increase_speed", "Meta+Shift+F8:decrease_speed", "Meta+Shift+F10:magic_key", "Meta+Shift+F11:show_session_info", "Meta+Shift+plus:scaleup", "Meta+Shift+plusminus:scaleup", #the keyname on OSX... "Meta+Shift+minus:scaledown", "Meta+Shift+underscore:scaledown", "Meta+Shift+emdash:scaledown", #OSX "Meta+Shift+KP_Add:scaleup", "Meta+Shift+KP_Subtract:scaledown", "Meta+Shift+KP_Multiply:scalereset", "Meta+Shift+degree:scalereset", #OSX ], "bind-tcp": [], "start": [], "start-child": [], "env": DEFAULT_ENV, } return GLOBAL_DEFAULTS
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS, DEFAULT_PULSEAUDIO_COMMAND, \ DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_remote_run_xpra_scripts try: from xpra.platform.info import get_username username = get_username() except: username = "" conf_dirs = [os.environ.get("XPRA_CONF_DIR")] build_root = os.environ.get("RPM_BUILD_ROOT") if build_root: conf_dirs.append(os.path.join(build_root, "etc", "xpra")) xpra_cmd = sys.argv[0] bin_dir = None if len(sys.argv)>0: for strip in ("/usr/bin", "/bin"): pos = xpra_cmd.find(strip) if pos>=0: bin_dir = xpra_cmd[:pos+len(strip)] root = xpra_cmd[:pos] or "/" conf_dirs.append(os.path.join(root, "etc", "xpra")) break if sys.prefix=="/usr": conf_dirs.append("/etc/xpra") else: conf_dirs.append(os.path.join(sys.prefix, "etc", "xpra")) for conf_dir in [x for x in conf_dirs if x]: if os.path.exists(conf_dir): break xvfb = detect_xvfb_command(conf_dir, bin_dir) def addtrailingslash(v): if v.endswith("/"): return v return v+"/" if WIN32: bind_dirs = ["Main"] else: bind_dirs = ["auto"] ssl_protocol = "TLSv1_2" if sys.version_info<(2, 7, 9): ssl_protocol = "SSLv23" GLOBAL_DEFAULTS = { "encoding" : "", "title" : "@title@ on @client-machine@", "username" : username, "password" : "", "auth" : "", "vsock-auth" : "", "tcp-auth" : "", "ssl-auth" : "", "wm-name" : DEFAULT_NET_WM_NAME, "session-name" : "", "dock-icon" : "", "tray-icon" : "", "window-icon" : "", "password-file" : "", "keyboard-raw" : False, "keyboard-layout" : "", "keyboard-layouts" : [], "keyboard-variant" : "", "keyboard-variants" : [], "keyboard-options" : "", "clipboard" : "yes", "clipboard-direction" : "both", "clipboard-filter-file" : "", "remote-clipboard" : "CLIPBOARD", "local-clipboard" : "CLIPBOARD", "pulseaudio-command": " ".join(DEFAULT_PULSEAUDIO_COMMAND), "encryption" : "", "tcp-encryption" : "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "pidfile" : "", "ssh" : DEFAULT_SSH_COMMAND, "systemd-run" : get_default_systemd_run(), "systemd-run-args" : "", "xvfb" : " ".join(xvfb), "socket-dir" : "", "log-dir" : "auto", "log-file" : "$DISPLAY.log", "border" : "auto,5:off", "window-close" : "auto", "max-size" : "", "desktop-scaling" : "auto", "display" : "", "tcp-proxy" : "", "download-path" : get_download_dir(), "open-command" : OPEN_COMMAND, "remote-logging" : "both", "lpadmin" : "/usr/sbin/lpadmin", "lpinfo" : "/usr/sbin/lpinfo", "add-printer-options" : ["-E", "-o printer-is-shared=false", "-u allow:$USER"], "pdf-printer" : "", "postscript-printer": DEFAULT_POSTSCRIPT_PRINTER, "debug" : "", "input-method" : "none", "sound-source" : "", "html" : "auto", "socket-permissions": "600", "exec-wrapper" : "", "dbus-launch" : "dbus-launch --close-stderr", "webcam" : ["auto", "no"][OSX], #ssl options: "ssl" : "auto", "ssl-key" : "", "ssl-cert" : "", "ssl-protocol" : ssl_protocol, "ssl-ca-certs" : "default", "ssl-ca-data" : "", "ssl-ciphers" : "DEFAULT", "ssl-client-verify-mode" : "optional", "ssl-server-verify-mode" : "required", "ssl-verify-flags" : "X509_STRICT", "ssl-check-hostname": False, "ssl-server-hostname": "localhost", "ssl-options" : "ALL,NO_COMPRESSION", "quality" : 0, "min-quality" : 30, "speed" : 0, "min-speed" : 30, "compression_level" : 1, "dpi" : 0, "video-scaling" : 1, "file-size-limit" : 100, "idle-timeout" : 0, "server-idle-timeout" : 0, "sync-xvfb" : 0, "auto-refresh-delay": 0.15, "daemon" : CAN_DAEMONIZE, "use-display" : False, "fake-xinerama" : not OSX and not WIN32, "resize-display" : not OSX and not WIN32, "tray" : True, "pulseaudio" : not OSX and not WIN32, "dbus-proxy" : not OSX and not WIN32, "mmap" : ["no", "yes"][not OSX and not WIN32], "mmap-group" : False, "speaker" : ["disabled", "on"][has_sound_support()], "microphone" : ["disabled", "off"][has_sound_support()], "readonly" : False, "keyboard-sync" : True, "pings" : False, "cursors" : True, "bell" : True, "notifications" : True, "xsettings" : not OSX and not WIN32, "system-tray" : True, "sharing" : False, "delay-tray" : False, "windows" : True, "exit-with-children": False, "exit-with-client" : False, "start-after-connect": False, "start-new-commands": False, "proxy-start-sessions": True, "av-sync" : True, "exit-ssh" : True, "dbus-control" : not WIN32 and not OSX, "opengl" : get_opengl_default(), "mdns" : not WIN32, "file-transfer" : True, "printing" : True, "open-files" : False, "swap-keys" : OSX, #only used on osx "desktop-fullscreen": False, "global-menus" : True, "pulseaudio-configure-commands" : [" ".join(x) for x in DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS], "socket-dirs" : [], "remote-xpra" : get_remote_run_xpra_scripts(), "encodings" : ["all"], "proxy-video-encoders" : [], "video-encoders" : ["all"], "csc-modules" : ["all"], "video-decoders" : ["all"], "speaker-codec" : [], "microphone-codec" : [], "compressors" : ["all"], "packet-encoders" : ["all"], "key-shortcut" : get_default_key_shortcuts(), "bind" : bind_dirs, "bind-vsock" : [], "bind-tcp" : [], "bind-ssl" : [], "start" : [], "start-child" : [], "start-after-connect" : [], "start-child-after-connect" : [], "start-on-connect" : [], "start-child-on-connect" : [], "start-env" : DEFAULT_ENV, "env" : [], } return GLOBAL_DEFAULTS
def _process_send_file(self, packet): #send-file basefilename, printit, openit, filesize, 0, data) from xpra.platform.paths import get_download_dir basefilename, mimetype, printit, openit, filesize, file_data, options = packet[ 1:8] options = typedict(options) if printit: l = printlog assert self.printing else: l = filelog assert self.file_transfer l("received file: %s", [ basefilename, mimetype, printit, openit, filesize, "%s bytes" % len(file_data), options ]) assert filesize > 0, "invalid file size: %s" % filesize assert file_data, "no data!" if len(file_data) != filesize: l.error("Error: invalid data size for file '%s'", basefilename) l.error(" received %i bytes, expected %i bytes", len(file_data), filesize) return if filesize > self.file_size_limit * 1024 * 1024: l.error("Error: file '%s' is too large:", basefilename) l.error(" %iMB, the file size limit is %iMB", filesize // 1024 // 1024, self.file_size_limit) return #check digest if present: import hashlib def check_digest(algo="sha1", libfn=hashlib.sha1): digest = options.get(algo) if not digest: return u = libfn() u.update(file_data) l("%s digest: %s - expected: %s", algo, u.hexdigest(), digest) if digest != u.hexdigest(): l.error( "Error: data does not match, invalid %s file digest for %s", algo, basefilename) l.error(" received %s, expected %s", u.hexdigest(), digest) raise Exception("failed %s digest verification" % algo) check_digest("sha1", hashlib.sha1) check_digest("md5", hashlib.md5) #make sure we use a filename that does not exist already: dd = os.path.expanduser(get_download_dir()) wanted_filename = os.path.abspath( os.path.join(dd, os.path.basename(basefilename))) EXTS = { "application/postscript": "ps", "application/pdf": "pdf", "raw": "raw", } ext = EXTS.get(mimetype) if ext: #on some platforms (win32), #we want to force an extension #so that the file manager can display them properly when you double-click on them if not wanted_filename.endswith("." + ext): wanted_filename += "." + ext filename = wanted_filename base = 0 while os.path.exists(filename): l("cannot save file as %s: file already exists", filename) root, ext = os.path.splitext(wanted_filename) base += 1 filename = root + ("-%s" % base) + ext flags = os.O_CREAT | os.O_RDWR | os.O_EXCL try: flags |= os.O_BINARY #@UndefinedVariable (win32 only) except: pass fd = os.open(filename, flags) try: os.write(fd, file_data) finally: os.close(fd) l.info("downloaded %s bytes to %s file%s:", filesize, (mimetype or "unknown"), ["", " for printing"][int(printit)]) l.info(" %s", filename) if printit: printer = options.strget("printer") title = options.strget("title") print_options = options.dictget("options") #TODO: how do we print multiple copies? #copies = options.intget("copies") #whitelist of options we can forward: safe_print_options = dict((k, v) for k, v in print_options.items() if k in ("PageSize", "Resolution")) l("safe print options(%s) = %s", options, safe_print_options) self._print_file(filename, mimetype, printer, title, safe_print_options) return elif openit: self._open_file(filename)
def _process_send_file(self, packet): #send-file basefilename, printit, openit, filesize, 0, data) from xpra.platform.paths import get_download_dir basefilename, mimetype, printit, openit, filesize, file_data, options = packet[1:11] options = typedict(options) if printit: l = printlog assert self.printing else: l = filelog assert self.file_transfer l("received file: %s", [basefilename, mimetype, printit, openit, filesize, "%s bytes" % len(file_data), options]) assert filesize>0, "invalid file size: %s" % filesize assert file_data, "no data!" if len(file_data)!=filesize: l.error("Error: invalid data size for file '%s'", basefilename) l.error(" received %i bytes, expected %i bytes", len(file_data), filesize) return if filesize>self.file_size_limit*1024*1024: l.error("Error: file '%s' is too large:", basefilename) l.error(" %iMB, the file size limit is %iMB", filesize//1024//1024, self.file_size_limit) return #check digest if present: import hashlib def check_digest(algo="sha1", libfn=hashlib.sha1): digest = options.get(algo) if not digest: return u = libfn() u.update(file_data) l("%s digest: %s - expected: %s", algo, u.hexdigest(), digest) if digest!=u.hexdigest(): l.error("Error: data does not match, invalid %s file digest for %s", algo, basefilename) l.error(" received %s, expected %s", u.hexdigest(), digest) return check_digest("sha1", hashlib.sha1) check_digest("md5", hashlib.md5) #make sure we use a filename that does not exist already: dd = os.path.expanduser(get_download_dir()) wanted_filename = os.path.abspath(os.path.join(dd, os.path.basename(basefilename))) EXTS = {"application/postscript" : "ps", "application/pdf" : "pdf", "raw" : "raw", } ext = EXTS.get(mimetype) if ext: #on some platforms (win32), #we want to force an extension #so that the file manager can display them properly when you double-click on them if not wanted_filename.endswith("."+ext): wanted_filename += "."+ext filename = wanted_filename base = 0 while os.path.exists(filename): l("cannot save file as %s: file already exists", filename) root, ext = os.path.splitext(wanted_filename) base += 1 filename = root+("-%s" % base)+ext flags = os.O_CREAT | os.O_RDWR | os.O_EXCL try: flags |= os.O_BINARY #@UndefinedVariable (win32 only) except: pass fd = os.open(filename, flags) try: os.write(fd, file_data) finally: os.close(fd) l.info("downloaded %s bytes to %s file%s:", filesize, (mimetype or "unknown"), ["", " for printing"][int(printit)]) l.info(" %s", filename) if printit: printer = options.strget("printer") title = options.strget("title") print_options = options.dictget("options") #TODO: how do we print multiple copies? #copies = options.intget("copies") #whitelist of options we can forward: safe_print_options = dict((k,v) for k,v in print_options.items() if k in ("PageSize", "Resolution")) l("safe print options(%s) = %s", options, safe_print_options) self._print_file(filename, mimetype, printer, title, safe_print_options) return elif openit: self._open_file(filename)
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS, DEFAULT_PULSEAUDIO_COMMAND, XDUMMY, XDUMMY_WRAPPER, DISPLAYFD, DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_default_log_dir, get_socket_dirs, get_remote_run_xpra_scripts try: from xpra.platform.info import get_username username = get_username() except: username = "" if WIN32 or OSX or PYTHON3: xvfb = "" elif XDUMMY: xvfb = get_Xdummy_command(use_wrapper=XDUMMY_WRAPPER, log_dir=get_default_log_dir()) else: xvfb = get_Xvfb_command() def addtrailingslash(v): if v.endswith("/"): return v return v+"/" if WIN32: bind_dirs = [] else: bind_dirs = [addtrailingslash(get_socket_dirs()[0])] GLOBAL_DEFAULTS = { "encoding" : "", "title" : "@title@ on @client-machine@", "username" : username, "auth" : "", "vsock-auth" : "", "tcp-auth" : "", "wm-name" : DEFAULT_NET_WM_NAME, "session-name" : "", "dock-icon" : "", "tray-icon" : "", "window-icon" : "", "password-file" : "", "clipboard" : "yes", "clipboard-filter-file" : "", "remote-clipboard" : "CLIPBOARD", "local-clipboard" : "CLIPBOARD", "pulseaudio-command": " ".join(DEFAULT_PULSEAUDIO_COMMAND), "encryption" : "", "tcp-encryption" : "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "ssh" : DEFAULT_SSH_COMMAND, "xvfb" : " ".join(xvfb), "socket-dir" : "", "log-dir" : get_default_log_dir(), "log-file" : "$DISPLAY.log", "border" : "auto,5:off", "window-close" : "auto", "max-size" : "", "desktop-scaling" : "auto", "display" : "", "tcp-proxy" : "", "download-path" : get_download_dir(), "open-command" : OPEN_COMMAND, "remote-logging" : "both", "lpadmin" : "/usr/sbin/lpadmin", "lpinfo" : "/usr/sbin/lpinfo", "pdf-printer" : "", "postscript-printer": "", "debug" : "", "input-method" : "none", "sound-source" : "", "html" : "", "socket-permissions": "600", "exec-wrapper" : "", "dbus-launch" : "dbus-launch --close-stderr", "webcam" : "auto", "quality" : 0, "min-quality" : 30, "speed" : 0, "min-speed" : 30, "compression_level" : 1, "dpi" : 0, "video-scaling" : 1, "file-size-limit" : 10, "idle-timeout" : 0, "server-idle-timeout" : 0, "sync-xvfb" : 0, "auto-refresh-delay": 0.15, "daemon" : CAN_DAEMONIZE, "use-display" : False, "displayfd" : DISPLAYFD, "fake-xinerama" : not OSX and not WIN32, "resize-display" : not OSX and not WIN32, "tray" : True, "pulseaudio" : not OSX and not WIN32, "dbus-proxy" : not OSX and not WIN32, "mmap" : not OSX and not WIN32, "mmap-group" : False, "speaker" : ["disabled", "on"][has_sound_support], "microphone" : ["disabled", "off"][has_sound_support], "readonly" : False, "keyboard-sync" : True, "pings" : False, "cursors" : True, "bell" : True, "notifications" : True, "xsettings" : not OSX and not WIN32, "system-tray" : True, "sharing" : False, "delay-tray" : False, "windows" : True, "exit-with-children": False, "exit-with-client" : False, "start-after-connect": False, "start-new-commands": False, "av-sync" : True, "exit-ssh" : True, "dbus-control" : not WIN32 and not OSX, "opengl" : OPENGL_DEFAULT, "mdns" : not WIN32, "file-transfer" : True, "printing" : True, "open-files" : False, "swap-keys" : OSX, #only used on osx "shadow-fullscreen" : False, "global-menus" : True, "pulseaudio-configure-commands" : [" ".join(x) for x in DEFAULT_PULSEAUDIO_CONFIGURE_COMMANDS], "socket-dirs" : [], "remote-xpra" : get_remote_run_xpra_scripts(), "encodings" : ["all"], "video-encoders" : ["all"], "csc-modules" : ["all"], "video-decoders" : ["all"], "speaker-codec" : [], "microphone-codec" : [], "compressors" : ["all"], "packet-encoders" : ["all"], "key-shortcut" : get_default_key_shortcuts(), "bind" : bind_dirs, "bind-vsock" : [], "bind-tcp" : [], "start" : [], "start-child" : [], "start-after-connect" : [], "start-child-after-connect" : [], "start-on-connect" : [], "start-child-on-connect" : [], "env" : DEFAULT_ENV, } return GLOBAL_DEFAULTS
def get_defaults(): global GLOBAL_DEFAULTS if GLOBAL_DEFAULTS is not None: return GLOBAL_DEFAULTS from xpra.platform.features import DEFAULT_SSH_COMMAND, OPEN_COMMAND, DEFAULT_PULSEAUDIO_COMMAND, XDUMMY, XDUMMY_WRAPPER, DISPLAYFD, DEFAULT_ENV, CAN_DAEMONIZE from xpra.platform.paths import get_download_dir, get_default_log_dir try: from xpra.platform.info import get_username username = get_username() except: username = "" if WIN32 or OSX or PYTHON3: xvfb = "" elif XDUMMY: xvfb = get_Xdummy_command(use_wrapper=XDUMMY_WRAPPER) else: xvfb = get_Xvfb_command() GLOBAL_DEFAULTS = { "encoding" : "", "title" : "@title@ on @client-machine@", "username" : username, "auth" : "", "tcp-auth" : "", "wm-name" : DEFAULT_NET_WM_NAME, "remote-xpra" : "~/.xpra/run-xpra", "session-name" : "", "dock-icon" : "", "tray-icon" : "", "window-icon" : "", "password-file" : "", "clipboard" : "yes", "clipboard-filter-file" : "", "remote-clipboard" : "CLIPBOARD", "local-clipboard" : "CLIPBOARD", "pulseaudio-command": DEFAULT_PULSEAUDIO_COMMAND, "encryption" : "", "tcp-encryption" : "", "encryption-keyfile": "", "tcp-encryption-keyfile": "", "ssh" : DEFAULT_SSH_COMMAND, "xvfb" : " ".join(xvfb), "socket-dir" : "", "log-dir" : get_default_log_dir(), "log-file" : "$DISPLAY.log", "border" : "auto,0", "max-size" : "", "desktop-scaling" : "auto", "display" : "", "tcp-proxy" : "", "download-path" : get_download_dir(), "open-command" : OPEN_COMMAND, "lpadmin" : "/usr/sbin/lpadmin", "lpinfo" : "/usr/sbin/lpinfo", "pdf-printer" : "", "postscript-printer": "", "debug" : "", "input-method" : "none", "sound-source" : "", "html" : "", "socket-permissions": "600", "quality" : 0, "min-quality" : 30, "speed" : 0, "min-speed" : 0, "compression_level" : 1, "dpi" : 0, "video-scaling" : 1, "file-size-limit" : 10, "idle-timeout" : 0, "server-idle-timeout" : 0, "sync-xvfb" : 0, "auto-refresh-delay": 0.15, "daemon" : CAN_DAEMONIZE, "use-display" : False, "displayfd" : DISPLAYFD, "fake-xinerama" : not OSX and not WIN32, "tray" : True, "pulseaudio" : not OSX and not WIN32, "dbus-proxy" : not OSX and not WIN32, "mmap" : not OSX and not WIN32, "mmap-group" : False, "speaker" : ["disabled", "on"][has_sound_support], "microphone" : ["disabled", "off"][has_sound_support], "readonly" : False, "keyboard-sync" : True, "pings" : False, "cursors" : True, "bell" : True, "notifications" : True, "xsettings" : not OSX and not WIN32, "system-tray" : True, "sharing" : False, "delay-tray" : False, "windows" : True, "exit-with-children": False, "exit-with-client" : False, "start-new-commands": False, "remote-logging" : WIN32 or OSX, "av-sync" : True, "exit-ssh" : True, "dbus-control" : not WIN32 and not OSX, "opengl" : OPENGL_DEFAULT, "mdns" : not WIN32, "file-transfer" : True, "printing" : True, "open-files" : False, "swap-keys" : OSX, #only used on osx "shadow-fullscreen" : False, "global-menus" : True, "socket-dirs" : [], "encodings" : ["all"], "video-encoders" : ["all"], "csc-modules" : ["all"], "video-decoders" : ["all"], "speaker-codec" : [], "microphone-codec" : [], "compressors" : ["all"], "packet-encoders" : ["all"], "key-shortcut" : [ "Meta+Shift+F1:show_menu", "Meta+Shift+F2:show_start_new_command", "Meta+Shift+F4:quit", "Meta+Shift+F5:increase_quality", "Meta+Shift+F6:decrease_quality", "Meta+Shift+F7:increase_speed", "Meta+Shift+F8:decrease_speed", "Meta+Shift+F10:magic_key", "Meta+Shift+F11:show_session_info", "Meta+Shift+plus:scaleup", "Meta+Shift+plusminus:scaleup", #the keyname on OSX... "Meta+Shift+minus:scaledown", "Meta+Shift+underscore:scaledown", "Meta+Shift+emdash:scaledown", #OSX "Meta+Shift+KP_Add:scaleup", "Meta+Shift+KP_Subtract:scaledown", "Meta+Shift+KP_Multiply:scalereset", "Meta+Shift+degree:scalereset", #OSX ], "bind-tcp" : [], "start" : [], "start-child" : [], "env" : DEFAULT_ENV, } return GLOBAL_DEFAULTS