def main(args): """ Main function """ try: options, arguments = getopt.getopt(args[1:], "6A:np:vy") except getopt.error: sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]") if arguments: sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]") prefer_ipv6 = 0 # address = 'master.neubot.org' address = "localhost" runner = 1 port = 8080 noisy = 0 fakeprivacy = 0 for name, value in options: if name == "-6": prefer_ipv6 = 1 elif name == "-A": address = value elif name == "-n": runner = 0 elif name == "-p": port = int(value) elif name == "-v": noisy = 1 elif name == "-y": fakeprivacy = 1 if os.path.isfile(DATABASE.path): DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) else: logging.warning("skype: database file is missing: %s", DATABASE.path) BACKEND.use_backend("null") if noisy: log.set_verbose() if runner: result = runner_clnt.runner_client( CONFIG["agent.api.address"], CONFIG["agent.api.port"], CONFIG["verbose"], "skype" ) if result: sys.exit(0) logging.info("skype: running the test in the local process context...") if not fakeprivacy and not privacy.allowed_to_run(): privacy.complain() logging.info("skype: otherwise use -y option to temporarily provide " "privacy permissions") sys.exit(1) handler = SkypeNegotiate() handler.connect((address, port), prefer_ipv6, 0, {}) POLLER.loop()
def main(args): """ Main function """ try: options, arguments = getopt.getopt(args[1:], "6A:fp:v") except getopt.error: sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]") if arguments: sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]") prefer_ipv6 = 0 address = "master.neubot.org" force = 0 port = 8080 noisy = 0 for name, value in options: if name == "-6": prefer_ipv6 = 1 elif name == "-A": address = value elif name == "-f": force = 1 elif name == "-p": port = int(value) elif name == "-v": noisy = 1 if os.path.isfile(DATABASE.path): DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) else: logging.warning("speedtest: database file is missing: %s", DATABASE.path) BACKEND.use_backend("null") if noisy: log.set_verbose() conf = CONFIG.copy() conf["speedtest.client.uri"] = "http://%s:%d/" % (address, port) conf["prefer_ipv6"] = prefer_ipv6 if not force: if runner_clnt.runner_client(conf["agent.api.address"], conf["agent.api.port"], CONFIG["verbose"], "speedtest"): sys.exit(0) logging.warning("speedtest: failed to contact Neubot; is Neubot running?") sys.exit(1) logging.info("speedtest: run the test in the local process context...") client = ClientSpeedtest(POLLER) client.configure(conf) client.connect_uri() POLLER.loop()
def main(args): ''' Main function ''' try: options, arguments = getopt.getopt(args[1:], '6A:fp:v') except getopt.error: sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]') if arguments: sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]') prefer_ipv6 = 0 address = 'master.neubot.org' force = 0 port = 8080 noisy = 0 for name, value in options: if name == '-6': prefer_ipv6 = 1 elif name == '-A': address = value elif name == '-f': force = 1 elif name == '-p': port = int(value) elif name == '-v': noisy = 1 if os.path.isfile(DATABASE.path): DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) else: logging.warning('raw: database file is missing: %s', DATABASE.path) BACKEND.use_backend('null') if noisy: log.set_verbose() if not force: result = runner_clnt.runner_client(CONFIG['agent.api.address'], CONFIG['agent.api.port'], CONFIG['verbose'], 'raw') if result: sys.exit(0) logging.warning('raw: failed to contact Neubot; is Neubot running?') sys.exit(1) logging.info('raw: run the test in the local process context...') handler = RawNegotiate() handler.connect((address, port), prefer_ipv6, 0, {}) POLLER.loop()
def subcommand_status(args): ''' Status subcommand ''' try: options, arguments = getopt.getopt(args[1:], 'v') except getopt.error: sys.exit('usage: neubot status [-v]') if arguments: sys.exit('usage: neubot status [-v]') for opt in options: if opt[0] == '-v': log.set_verbose() running = utils_ctl.is_running('127.0.0.1', '9774', log.is_verbose()) if not running: sys.exit('ERROR: neubot is not running')
def subcommand_stop(args): ''' Stop subcommand ''' try: options, arguments = getopt.getopt(args[1:], 'v') except getopt.error: sys.exit('usage: neubot stop [-v]') if arguments: sys.exit('usage: neubot stop [-v]') for opt in options: if opt[0] == '-v': log.set_verbose() if os.getuid() != 0 and os.geteuid() != 0: sys.exit('ERROR: must be root') cmdline = ['/bin/launchctl', 'stop', 'org.neubot'] logging.debug('main_macos: about to exec: %s', str(cmdline)) retval = subprocess.call(cmdline) logging.debug('main_macos: return value: %d', retval) sys.exit(retval)
def subcommand_start(args): ''' Start subcommand ''' try: options, arguments = getopt.getopt(args[1:], 'adv') except getopt.error: sys.exit('usage: neubot start [-adv]') if arguments: sys.exit('usage: neubot start [-adv]') args = '-d' debug = 0 for opt in options: if opt[0] == '-a': args += 'a' elif opt[0] == '-d': debug = 1 elif opt[0] == '-v': log.set_verbose() args += 'v' if os.getuid() != 0 and os.geteuid() != 0: sys.exit('ERROR: must be root') if debug: import neubot.updater.unix sys.argv = ['neubot updater_unix', args] logging.debug('main_macos: about to run: %s', str(sys.argv)) neubot.updater.unix.main() sys.exit(1) # should not happen cmdline = ['/bin/launchctl', 'start', 'org.neubot'] logging.debug('main_macos: about to exec: %s', str(cmdline)) retval = subprocess.call(cmdline) logging.debug('main_macos: return value: %d', retval) sys.exit(retval)
def main(args): """ Main function """ try: options, arguments = getopt.getopt(args[1:], "6A:b:d:flnp:v") except getopt.error: sys.exit(USAGE) if arguments: sys.exit(USAGE) prefer_ipv6 = 0 address = "127.0.0.1" backend = "volatile" datadir = None # means: pick the default force = 0 listen = 0 negotiate = 1 port = 80 noisy = 0 for name, value in options: if name == "-6": prefer_ipv6 = 1 elif name == "-A": address = value elif name == "-b": backend = value elif name == "-d": datadir = value elif name == "-f": force = 1 elif name == "-l": listen = 1 elif name == "-n": negotiate = 0 elif name == "-p": port = int(value) elif name == "-v": noisy = 1 if noisy: log.set_verbose() conf = CONFIG.copy() BACKEND.use_backend(backend) BACKEND.datadir_init(None, datadir) if listen: if not negotiate: server = DASHServerSmpl(POLLER) server.configure(conf) server.listen((address, port)) else: # Code adapted from neubot/server.py conf["http.server.rootdir"] = "" server = ServerHTTP(POLLER) server.configure(conf) server.listen((address, port)) negotiate_server = NegotiateServer(POLLER) negotiate_server.configure(conf) server.register_child(negotiate_server, "/negotiate") server.register_child(negotiate_server, "/collect") dash_negotiate_server = DASHNegotiateServer() negotiate_server.register_module("dash", dash_negotiate_server) dash_server = DASHServerGlue(POLLER, dash_negotiate_server) dash_server.configure(conf) server.register_child(dash_server, "/dash") elif not force: result = runner_clnt.runner_client(CONFIG["agent.api.address"], CONFIG["agent.api.port"], CONFIG["verbose"], "dash") if result: sys.exit(0) logging.warning("dash: failed to contact Neubot; is Neubot running?") sys.exit(1) else: if negotiate: client = DASHNegotiateClient(POLLER) else: client = DASHClientSmpl(POLLER, None, DASH_RATES) client.configure(conf) client.connect((address, port)) POLLER.loop()
def main(args): """ Main function """ try: options, arguments = getopt.getopt(args[1:], '6A:fp:v') except getopt.error: sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]') if arguments: sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]') prefer_ipv6 = 0 address = 'master.neubot.org' force = 0 port = 8080 noisy = 0 for name, value in options: if name == '-6': prefer_ipv6 = 1 elif name == '-A': address = value elif name == '-f': force = 1 elif name == '-p': port = int(value) elif name == '-v': noisy = 1 if os.path.isfile(DATABASE.path): DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) else: logging.warning('speedtest: database file is missing: %s', DATABASE.path) BACKEND.use_backend('null') if noisy: log.set_verbose() conf = CONFIG.copy() conf["speedtest.client.uri"] = "http://%s:%d/" % (address, port) conf["prefer_ipv6"] = prefer_ipv6 if not force: if runner_clnt.runner_client(conf["agent.api.address"], conf["agent.api.port"], CONFIG['verbose'], "speedtest"): sys.exit(0) logging.warning( 'speedtest: failed to contact Neubot; is Neubot running?') sys.exit(1) logging.info('speedtest: run the test in the local process context...') client = ClientSpeedtest(POLLER) client.configure(conf) # # XXX Quick and dirty fix such that `neubot speedtest` when # there is no daemon running considers both the master and # the backup master server. At the same time, respect user # choices if she overrides the default URI. # if CONFIG['speedtest.client.uri'] == 'http://master.neubot.org/': client.connect(('localhost', 8080)) else: client.connect_uri() POLLER.loop()
def main(args): ''' This function is invoked when the user wants to run precisely this module. ''' try: options, arguments = getopt.getopt(args[1:], '6A:fp:v') except getopt.error: sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]') if arguments: sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]') prefer_ipv6 = 0 address = 'master.neubot.org' force = 0 port = 6881 noisy = 0 for name, value in options: if name == '-6': prefer_ipv6 = 1 elif name == '-A': address = value elif name == '-f': force = 1 elif name == '-p': port = int(value) elif name == '-v': noisy = 1 if os.path.isfile(DATABASE.path): DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) else: logging.warning('bittorrent: database file is missing: %s', DATABASE.path) BACKEND.use_backend('null') if noisy: log.set_verbose() config.register_descriptions() # Needed? conf = CONFIG.copy() config.finalize_conf(conf) conf['bittorrent.address'] = address conf['bittorrent.port'] = port conf['prefer_ipv6'] = prefer_ipv6 if not force: if runner_clnt.runner_client(conf["agent.api.address"], conf["agent.api.port"], CONFIG['verbose'], "bittorrent"): sys.exit(0) logging.warning( 'bittorrent: failed to contact Neubot; is Neubot running?') sys.exit(1) logging.info('bittorrent: run the test in the local process context...') # # When we're connecting to a remote host to perform a test # we want Neubot to quit at the end of the test. When this # happens the test code publishes the "testdone" event, so # here we prepare to intercept the event and break our main # loop. # NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop()) run(POLLER, conf) POLLER.loop()