def guess_xpra_display(socket_dir, socket_dirs): dotxpra = DotXpra(socket_dir, socket_dirs) results = dotxpra.sockets() live = [display for state, display in results if state==DotXpra.LIVE] if len(live)==0: raise InitException("no existing xpra servers found") if len(live)>1: raise InitException("too many existing xpra servers found, cannot guess which one to use") return live[0]
def get_sessions(self): uid = self.get_uid() gid = self.get_gid() try: sockdir = DotXpra(socket_dir, actual_username=self.username) results = sockdir.sockets(check_uid=uid) displays = [display for state, display in results if state==DotXpra.LIVE] except Exception, e: log.error("cannot get socker directory for %s: %s", self.username, e) displays = []
def guess_xpra_display(socket_dir, socket_dirs): dotxpra = DotXpra(socket_dir, socket_dirs) results = dotxpra.sockets() live = [display for state, display in results if state == DotXpra.LIVE] if len(live) == 0: raise InitException("no existing xpra servers found") if len(live) > 1: raise InitException( "too many existing xpra servers found, cannot guess which one to use" ) return live[0]
def get_sessions(self): uid = self.get_uid() gid = self.get_gid() try: sockdir = DotXpra(socket_dir, socket_dirs, actual_username=self.username) results = sockdir.sockets(check_uid=uid) displays = [display for state, display in results if state==DotXpra.LIVE] except Exception as e: log.error("Error: cannot get socket directory for '%s':", self.username) log.error(" %s", e) displays = [] return uid, gid, displays, {}, {}
def get_sessions(self): uid = self.get_uid() gid = self.get_gid() try: sockdir = DotXpra(socket_dir, actual_username=self.username) results = sockdir.sockets(check_uid=uid) displays = [display for state, display in results if state==DotXpra.LIVE] except Exception as e: log.error("Error: cannot get socket directory for '%s':", self.username) log.error(" %s", e) displays = [] return uid, gid, displays, {}, {}
def pick_display(parser, opts, extra_args): if len(extra_args) == 0: # Pick a default server sockdir = DotXpra(opts.sockdir or get_default_socket_dir()) servers = sockdir.sockets() live_servers = [display for (state, display) in servers if state is DotXpra.LIVE] if len(live_servers) == 0: parser.error("cannot find a live server to connect to") 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 pick_display(parser, opts, extra_args): if len(extra_args) == 0: # Pick a default server sockdir = DotXpra(opts.sockdir or get_default_socket_dir()) servers = sockdir.sockets() live_servers = [ display for (state, display) in servers if state is DotXpra.LIVE ] if len(live_servers) == 0: parser.error("cannot find a live server to connect to") 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 run_list(parser, opts, extra_args): if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra() results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") else: sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: sys.stdout.write("\t%s session at %s" % (state, display)) if state is DotXpra.DEAD: try: os.unlink(sockdir.socket_path(display)) except OSError: pass else: sys.stdout.write(" (cleaned up)") sys.stdout.write("\n")
def run_list(parser, opts, extra_args): assert "gtk" not in sys.modules if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra() results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") else: sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: sys.stdout.write("\t%s session at %s" % (state, display)) if state is DotXpra.DEAD: try: os.unlink(sockdir.socket_path(display)) except OSError: pass else: sys.stdout.write(" (cleaned up)") sys.stdout.write("\n")
def pick_display(parser, opts, extra_args): if len(extra_args) == 0: if not XPRA_LOCAL_SERVERS_SUPPORTED: parser.error("need to specify a display") # Pick a default server sockdir = DotXpra() servers = sockdir.sockets() live_servers = [ display for (state, display) in servers if state is DotXpra.LIVE ] if len(live_servers) == 0: parser.error("cannot find a live server to connect to") 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 pick_display(parser, opts, extra_args): if len(extra_args) == 0: if not XPRA_LOCAL_SERVERS_SUPPORTED: parser.error("need to specify a display") # Pick a default server sockdir = DotXpra() servers = sockdir.sockets() live_servers = [display for (state, display) in servers if state is DotXpra.LIVE] if len(live_servers) == 0: parser.error("cannot find a live server to connect to") 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 pick_display(parser, opts, extra_args): if len(extra_args) == 0: # Pick a default server sockdir = DotXpra(opts.socket_dir or get_default_socket_dir()) servers = sockdir.sockets() live_servers = [display for (state, display) in servers if state is DotXpra.LIVE] if len(live_servers) == 0: if not LOCAL_SERVERS_SUPPORTED: parser.error("this installation does not support local servers, you must specify a remote display") parser.error("cannot find a live server to connect to") elif len(live_servers) == 1: return parse_display_name(parser.error, opts, live_servers[0]) else: parser.error("there are multiple servers running, please specify") elif len(extra_args) == 1: return parse_display_name(parser.error, opts, extra_args[0]) else: parser.error("too many arguments")
def run_list(parser, opts, extra_args): assert "gtk" not in sys.modules if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra(opts.socket_dir) results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") return 1 sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: may_cleanup_socket(sockdir, state, display) #now, re-probe the "unknown" ones: unknown = [ display for state, display in results if state == DotXpra.UNKNOWN ] if len(unknown) > 0: sys.stdout.write("Re-probing unknown sessions: %s\n" % (", ".join(unknown))) counter = 0 while len(unknown) > 0 and counter < 5: time.sleep(1) counter += 1 probe_list = list(unknown) unknown = [] for display in probe_list: state = sockdir.server_state(display) if state is DotXpra.DEAD: may_cleanup_socket(sockdir, state, display) elif state is DotXpra.UNKNOWN: unknown.append(display) else: sys.stdout.write("\t%s session at %s\n" % (state, display)) #now cleanup those still unknown: clean_states = [DotXpra.DEAD, DotXpra.UNKNOWN] for display in unknown: state = sockdir.server_state(display) may_cleanup_socket(sockdir, state, display, clean_states=clean_states) return 0
def run_list(parser, opts, extra_args): assert "gtk" not in sys.modules if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra(opts.socket_dir) results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") return 1 sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: may_cleanup_socket(sockdir, state, display) #now, re-probe the "unknown" ones: unknown = [display for state, display in results if state==DotXpra.UNKNOWN] if len(unknown)>0: sys.stdout.write("Re-probing unknown sessions: %s\n" % (", ".join(unknown))) counter = 0 while len(unknown)>0 and counter<5: time.sleep(1) counter += 1 probe_list = list(unknown) unknown = [] for display in probe_list: state = sockdir.server_state(display) if state is DotXpra.DEAD: may_cleanup_socket(sockdir, state, display) elif state is DotXpra.UNKNOWN: unknown.append(display) else: sys.stdout.write("\t%s session at %s\n" % (state, display)) #now cleanup those still unknown: clean_states = [DotXpra.DEAD, DotXpra.UNKNOWN] for display in unknown: state = sockdir.server_state(display) may_cleanup_socket(sockdir, state, display, clean_states=clean_states) return 0
def load_auth_file(): global auth_data, auth_data_time, password_file, socket_dir, socket_dirs ptime = 0 if password_file: if not os.path.exists(password_file): log.error("password file is missing: %s", password_file) auth_data = None return auth_data try: ptime = os.stat(password_file).st_mtime except Exception as e: log.error("error accessing password file time: %s", e) if auth_data is None or ptime != auth_data_time: auth_data = {} auth_data_time = ptime if password_file: f = None try: with open(password_file, mode='rb') as f: data = f.read() except Exception as e: log.error("error loading %s: %s", password_file, e) data = "" log("loaded %s bytes from %s", len(data), password_file) else: data = os.environ.get('XPRA_PASSWORD', "") i = 0 for line in data.splitlines(): i += 1 line = line.strip() if len(line) == 0 or line.startswith("#"): continue log("line %s: %s", i, line) if line.find("|") < 0: #assume old style file with just the password #get all the displays for the current user: sockdir = DotXpra(socket_dir, socket_dirs) results = sockdir.sockets() displays = [ display for state, display in results if state == DotXpra.LIVE ] auth_data[""] = line, os.getuid(), os.getgid( ), displays, {}, {} log("Warning: assuming this is a single password for all users" ) continue ldata = line.split("|") log("found %s fields at line %s", len(ldata), i) if len(ldata) < 4: log.warn("skipped line %s of %s: not enough fields", i, password_file) continue #parse fields: username = ldata[0] password = ldata[1] def getsysid(s, default_value): if not s: return default_value try: return int(s) except: return default_value uid = getsysid(ldata[2], os.getuid()) gid = getsysid(ldata[3], os.getgid()) displays = ldata[4].split(",") env_options = {} session_options = {} if len(ldata) >= 6: env_options = parseOptions(ldata[5]) if len(ldata) >= 7: session_options = parseOptions(ldata[6]) auth_data[ username] = password, uid, gid, displays, env_options, session_options log("loaded auth data from file %s: %s", password_file, auth_data) return auth_data
def load_auth_file(): global auth_data, auth_data_time, password_file, socket_dir ptime = 0 if password_file: if not os.path.exists(password_file): log.error("password file is missing: %s", password_file) auth_data = None return auth_data try: ptime = os.stat(password_file).st_mtime except Exception as e: log.error("error accessing password file time: %s", e) if auth_data is None or ptime!=auth_data_time: auth_data = {} auth_data_time = ptime if password_file: f = None try: with open(password_file, mode='rb') as f: data = f.read() except Exception as e: log.error("error loading %s: %s", password_file, e) data = "" else: data = os.environ.get('XPRA_PASSWORD') i = 0 for line in data.splitlines(): i += 1 line = line.strip() if len(line)==0 or line.startswith("#"): continue log("line %s: %s", i, line) if line.find("|")<0: #assume old style file with just the password #get all the displays for the current user: sockdir = DotXpra(socket_dir) results = sockdir.sockets() displays = [display for state, display in results if state==DotXpra.LIVE] auth_data[""] = line, os.getuid(), os.getgid(), displays, {}, {} log("Warning: assuming this is a single password for all users") continue ldata = line.split("|") log("found %s fields at line %s", len(ldata), i) if len(ldata)<4: log.warn("skipped line %s of %s: not enough fields", i, password_file) continue #parse fields: username = ldata[0] password = ldata[1] def getsysid(s, default_value): if not s: return default_value try: return int(s) except: return default_value uid = getsysid(ldata[2], os.getuid()) gid = getsysid(ldata[3], os.getgid()) displays = ldata[4].split(",") env_options = {} session_options = {} if len(ldata)>=6: env_options = parseOptions(ldata[5]) if len(ldata)>=7: session_options = parseOptions(ldata[6]) auth_data[username] = password, uid, gid, displays, env_options, session_options log("loaded auth data from file %s: %s", password_file, auth_data) return auth_data
f.close() except Exception, e: log.error("error loading %s: %s", password_file, e) data = "" i = 0 for line in data.splitlines(): i += 1 line = line.strip() if len(line)==0 or line.startswith("#"): continue debug("line %s: %s", i, line) if line.find("|")<0: #assume old style file with just the password #get all the displays for the current user: sockdir = DotXpra(socket_dir) results = sockdir.sockets() displays = [display for state, display in results if state==DotXpra.LIVE] auth_data[""] = line, os.getuid(), os.getgid(), displays, {}, {} debug("Warning: assuming this is a single password for all users") continue ldata = line.split("|") debug("found %s fields at line %s", len(ldata), i) if len(ldata)<4: log.warn("skipped line %s of %s: not enough fields", i, password_file) continue #parse fields: username = ldata[0] password = ldata[1] def getsysid(s, default_value): if not s: return default_value