def share(self): # XXX: Not very pythonic >:( log.debug("Establishing XMPP connection") if not self.xmpp.connect(): die("Could not connect, see xmpp.log for details") # Join all rooms muc_plugin = self.xmpp.get_plugin('xep_0045') log.debug("Joining rooms: {}".format(self.config.strategy['rooms'])) for room in self.config.strategy['rooms']: muc_plugin.joinMUC(room, self.config.options['nick']) # Process XMPP events in another thread log.debug("Spawning XMPP worker") self.xmpp.process() ''' Spawn a new shell in a pseudo terminal, pty polls with select() and notifies LineReader when data is available. There's an annoying bug right now; pty doesn't know when to die because it never gets EOF. Idk how to deal with this but you can just hit crlf twice after exiting the shell. ''' log.info("@_@ You are being watched @_@") pty.spawn(self.config.options['shell'], self.reader.read) log.info("X_X You are alone again X_X") # Close XMPP connection # XXX: If I didn't set send_close=False here, this took a long time # to exit. My guess is that hipchat doesn't properly respond to the # stream footer but idk. log.debug("Tearing down XMPP connection") self.xmpp.disconnect(send_close=False)
def __init__(self, strategy): default_options = {"shell": "/bin/bash", "ttl": 60} default_strategy = {"people": [], "rooms": []} config, schema = load_jsons('config.json', 'config.schema.json') validate(config, schema) # Get strategy try: config['strategy'] = config['strategies'][strategy] except KeyError: die("No such strategy: {}".format(strategy)) # Get password from environment try: password_env = config['strategy']['password_env'] config['strategy']['password'] = os.environ[password_env] except KeyError: die("Missing required environment variable: {}".format( password_env)) self.__dict__.update( **{ "options": merge_dicts(default_options, config['options']), "strategy": merge_dicts(default_strategy, config['strategy']) })
def __init__(self, strategy): default_options = { "shell": "/bin/bash", "ttl": 60 } default_strategy = { "people": [], "rooms": [] } config, schema = load_jsons('config.json', 'config.schema.json') validate(config, schema) # Get strategy try: config['strategy'] = config['strategies'][strategy] except KeyError: die("No such strategy: {}".format(strategy)) # Get password from environment try: password_env = config['strategy']['password_env'] config['strategy']['password'] = os.environ[password_env] except KeyError: die("Missing required environment variable: {}".format(password_env)) self.__dict__.update(**{ "options": merge_dicts(default_options, config['options']), "strategy": merge_dicts(default_strategy, config['strategy']) })
def share(self): # XXX: Not very pythonic >:( log.debug("Establishing XMPP connection") if not self.xmpp.connect(): die("Could not connect, see xmpp.log for details") # Join all rooms muc_plugin = self.xmpp.get_plugin('xep_0045') log.debug("Joining rooms: {}".format(self.config.strategy['rooms'])) for room in self.config.strategy['rooms']: muc_plugin.joinMUC(room, self.config.options['nick']) # Process XMPP events in another thread log.debug("Spawning XMPP worker") self.xmpp.process() ''' Spawn a new shell in a pseudo terminal, pty polls with select() and notifies LineReader when data is available. There's an annoying bug right now; pty doesn't know when to die because it never gets EOF. Idk how to deal with this but you can just hit crlf twice after exiting the shell. ''' log.info("@_@ You are being watched @_@") pty.spawn(self.config.options['shell'], self.reader.read) log.info("X_X You are alone again X_X") # Close XMPP connection # XXX: If I didn't set send_close=False here, this took a long time # to exit. My guess is that hipchat doesn't properly respond to the # stream footer but idk. log.debug("Tearing down XMPP connection") self.xmpp.disconnect(send_close=False)