def __init__(self, ircd): self.manhole = makeService({ 'namespace': {'ircd': ircd}, 'passwd': 'manhole.passwd', 'telnetPort': None, 'sshPort': 'tcp:65432:interface=127.0.0.1' })
def makeService(self, options): """ Construct a TriblerChain Crawler service. """ crawler_service = MultiService() crawler_service.setName("Market") manhole_namespace = {} if options["manhole"] > 0: port = options["manhole"] manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % port, 'sshPort': None, 'passwd': os.path.join(os.path.dirname(__file__), 'passwd'), }) crawler_service.addService(manhole) reactor.callWhenRunning(self.start_tribler, options) return crawler_service
def test_passwd(self): """ The C{--passwd} command-line option will load a passwd-like file. """ self.options.parseOptions( ["--telnetPort", "tcp:22", "--passwd", self.filename]) service = manhole_tap.makeService(self.options) portal = service.services[0].factory.protocol.portal self.assertEqual(len(portal.checkers.keys()), 2) # Ensure it's the passwd file we wanted by trying to authenticate self.assertTrue( self.successResultOf( portal.login( UsernamePassword(*self.usernamePassword), None, telnet.ITelnetProtocol, ))) self.assertIsInstance( self.failureResultOf( portal.login(UsernamePassword(b"wrong", b"user"), None, telnet.ITelnetProtocol)).value, error.UnauthorizedLogin, )
def makeService(self, options): """ Construct a dispersy service. """ tracker_service = MultiService() tracker_service.setName("Bartercast Crawler") # crypto if options["crypto"] == 'NoCrypto': crypto = NoCrypto() else: crypto = NoVerifyCrypto() container = [None] manhole_namespace = {} if options["manhole"]: port = options["manhole"] manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % port, 'sshPort': None, 'passwd': os.path.join(os.path.dirname(__file__), 'passwd'), }) tracker_service.addService(manhole) manhole.startService() def run(): # setup dispersy = BartercastCrawler( StandaloneEndpoint(options["port"], options["ip"]), unicode(options["statedir"]), bool(options["silent"]), crypto) container[0] = dispersy manhole_namespace['dispersy'] = dispersy self._stopping = False def signal_handler(sig, frame): msg("Received signal '%s' in %s (shutting down)" % (sig, frame)) if not self._stopping: self._stopping = True dispersy.stop().addCallback(lambda _: reactor.stop) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) # start print "starting dispersy" if not dispersy.start(): raise RuntimeError("Unable to start Dispersy") # wait forever reactor.exitCode = 0 reactor.callWhenRunning(run) # TODO: exit code return tracker_service
def makeService(self, options): """ Construct a tunnel helper service. """ tunnel_helper_service = MultiService() tunnel_helper_service.setName("Tunnel_helper") manhole_namespace = {} if options["manhole"]: port = options["manhole"] manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % port, 'sshPort': None, 'passwd': os.path.join(os.path.dirname(__file__), 'passwd'), }) tunnel_helper_service.addService(manhole) reactor.callWhenRunning(self.start_tunnel, options) return tunnel_helper_service
def makeService(self, options): multiService = service.MultiService() conf = InfobobConfig() with open(options.config) as cfgFile: conf.load(cfgFile) conf.config_loc = options.config self.ircFactory = irc.InfobobFactory(conf) clientService = internet.TCPClient if conf['irc.ssl']: clientService = partial(internet.SSLClient, contextFactory=ClientContextFactory()) self.ircService = clientService( conf['irc.server'], conf['irc.port'], self.ircFactory) self.ircService.setServiceParent(multiService) conf.dbpool = database.InfobobDatabaseRunner(conf) if (conf['misc.manhole.socket'] is not None and conf['misc.manhole.passwd_file']): from twisted.conch.manhole_tap import makeService self.manholeService = makeService(dict( telnetPort="unix:" + conf['misc.manhole.socket'].encode(), sshPort=None, namespace={'self': self, 'conf': conf}, passwd=conf['misc.manhole.passwd_file'], )) self.manholeService.setServiceParent(multiService) self.webService = internet.TCPServer( conf['web.port'], http.makeSite(http.DEFAULT_TEMPLATES_DIR, conf.dbpool)) self.webService.setServiceParent(multiService) return multiService
def start_site(config, resource): log.info('Starting the API on port %s' % config.port) if config.manhole: log.info('Starting the manhole on port 8008') multiService = manhole_tap.makeService( dict(namespace=globals(), telnetPort='8008', sshPort='8009', sshKeyDir='sshKeyDir', sshKeyName='id_rsa', sshKeySize=4096, passwd='passwd')) telnetService, sshService = multiService.services telnetFactory = telnetService.factory sshFactory = sshService.factory reactor.listenTCP(8008, telnetFactory, interface='localhost') reactor.listenTCP(8009, sshFactory, interface='localhost') site = PixelatedSite(resource) site.displayTracebacks = False if config.sslkey and config.sslcert: reactor.listenSSL(config.port, site, _ssl_options(config.sslkey, config.sslcert), interface=config.host) else: reactor.listenTCP(config.port, site, interface=config.host)
def startManhole(self, result = None): self.manhole = makeService({ "namespace": { "ircd": self.ircd }, "passwd": self.ircd.config.get("manhole_passwd", "manhole.passwd"), "telnetPort": self.ircd.config.get("manhole_bind_telnet", None), "sshPort": self.ircd.config.get("manhole_bind_ssh", None) }) self.manhole.startService()
def __init__(self, ircd): self.manhole = makeService({ 'namespace': { 'ircd': ircd }, 'passwd': 'manhole.passwd', 'telnetPort': None, 'sshPort': 'tcp:65432:interface=127.0.0.1' })
def makeService(root): manholeService = manhole_tap.makeService({ 'telnetPort': 'tcp:9998:interface=127.0.0.1', 'sshPort': False, 'passwd': 'twisted/passwd.txt', 'namespace': {'app': service.IServiceCollection(root)} }) manholeService.setName("manhole") manholeService.setServiceParent(root)
def telnet_service(user_file): import roost namespace = {'roost': roost, 'xbee': roost.find_service('xbee')} shell_options = { 'namespace' : namespace, 'passwd' : user_file, 'sshPort' : None, 'telnetPort' : '4040', } return manhole_tap.makeService(shell_options)
def startSshShellServer(self): #reactor.listenTCP(2222, getManholeFactory(globals(), admin='aaa')) from twisted.conch import manhole_tap import os self.curPath = os.getcwd() svc = manhole_tap.makeService({'telnetPort':'tcp:2111',\ 'passwd':os.path.join(self.curPath,'pass.txt'),\ 'sshPort':'tcp:2222','namespace':globals()}) svc.startService() print 'starting http server' self.startHttpServer()
def onLoad(self): while self.manhole is None or not self.manhole.running: try: self.manhole = makeService({ "namespace": {"bot": self.bot}, "passwd": os.path.join("Data", "manhole.passwd"), "telnetPort": None, "sshPort": str(self.port) }) self.manhole.startService() except CannotListenError: self.port += 1
def makeService(self, options): """ Construct a dispersy service. """ tracker_service = MultiService() tracker_service.setName("Bartercast Crawler") # crypto if options["crypto"] == 'NoCrypto': crypto = NoCrypto() else: crypto = NoVerifyCrypto() container = [None] manhole_namespace = {} if options["manhole"]: port = options["manhole"] manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % port, 'sshPort': None, 'passwd': os.path.join(os.path.dirname(__file__), 'passwd'), }) tracker_service.addService(manhole) manhole.startService() def run(): # setup dispersy = BartercastCrawler(StandaloneEndpoint(options["port"], options["ip"]), unicode(options["statedir"]), bool(options["silent"]), crypto) container[0] = dispersy manhole_namespace['dispersy'] = dispersy self._stopping = False def signal_handler(sig, frame): msg("Received signal '%s' in %s (shutting down)" % (sig, frame)) if not self._stopping: self._stopping = True try: dispersy.stop() except Exception, e: msg("Got exception when stopping dispersy: %s" % e) reactor.stop() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) # start print "starting dispersy" if not dispersy.start(): raise RuntimeError("Unable to start Dispersy")
def start_manhole(): """ Starts a manhole telnet server listening on MANHOLE_PORT """ passwd_path = os.path.join(environ['PROJECT_DIR'], 'lib', 'passwd') global manhole manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface:127.0.0.1' % MANHOLE_PORT, 'sshPort': None, 'passwd': passwd_path, })
def test_telnetPort(self): """ L{manhole_tap.makeService} will make a telnet service on the port defined by C{--telnetPort}. It will not make a SSH service. """ self.options.parseOptions(["--telnetPort", "tcp:222"]) service = manhole_tap.makeService(self.options) self.assertIsInstance(service, MultiService) self.assertEqual(len(service.services), 1) self.assertIsInstance(service.services[0], StreamServerEndpointService) self.assertIsInstance(service.services[0].factory.protocol, manhole_tap.makeTelnetProtocol) self.assertEqual(service.services[0].endpoint._port, 222)
def startManhole(self, result=None): self.manhole = makeService({ "namespace": { "ircd": self.ircd }, "passwd": self.ircd.config.get("manhole_passwd", "manhole.passwd"), "telnetPort": self.ircd.config.get("manhole_bind_telnet", None), "sshPort": self.ircd.config.get("manhole_bind_ssh", None) }) self.manhole.startService()
def onLoad(self): while self.manhole is None or not self.manhole.running: try: self.manhole = makeService({ "namespace": {"bot": self.bot}, "passwd": os.path.join("data", "manhole.passwd"), "telnetPort": None, "sshPort": "tcp:{}:interface=127.0.0.1".format(self.port), "sshKeyDir": os.path.join("data"), "sshKeyName": "manhole.sshkey", "sshKeySize": 4096 }) self.manhole.startService() except CannotListenError: self.port += 1
def start_manhole(): """ Starts a manhole telnet server listening on MANHOLE_PORT """ passwd_path = path.join(environ['PROJECT_DIR'], 'lib', 'passwd') global manhole manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % MANHOLE_PORT, 'sshPort': None, 'passwd': passwd_path, })
def startService(self): self.config = self.parent.getServiceNamed("config") port = self.config.get("port", 5022, "controlTCPMod") passwd = self.config.get("passwd", "data/passwd", "controlTCPMod") control = self.parent.getServiceNamed("control").handle_command manholeService = manhole_tap.makeService({ 'telnetPort': '', 'sshPort': str(port), 'passwd': passwd, 'namespace': { 'app': self.parent, 'c': control } }) manholeService.setName("manhole") self.addService(manholeService) # f = factory.SSHFactory() # f.portal = portal.Portal(SSHRealm(self)) # f.publicKeys = {'ssh-rsa': keys.Key.fromString('ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEArzJx8OYOnJmzf4tfBEvLi8DVPrJ3/c9k2I/Az64fxjHf9imyRJbixtQhlH9lfNjUIx+4LmrJH5QNRsFporcHDKOTwTTYLh5KmRpslkYHRivcJSkbh/C+BR3utDS555mV')} # privateKey = """-----BEGIN RSA PRIVATE KEY----- #MIIByAIBAAJhAK8ycfDmDpyZs3+LXwRLy4vA1T6yd/3PZNiPwM+uH8Yx3/YpskSW #4sbUIZR/ZXzY1CMfuC5qyR+UDUbBaaK3Bwyjk8E02C4eSpkabJZGB0Yr3CUpG4fw #vgUd7rQ0ueeZlQIBIwJgbh+1VZfr7WftK5lu7MHtqE1S1vPWZQYE3+VUn8yJADyb #Z4fsZaCrzW9lkIqXkE3GIY+ojdhZhkO1gbG0118sIgphwSWKRxK0mvh6ERxKqIt1 #xJEJO74EykXZV4oNJ8sjAjEA3J9r2ZghVhGN6V8DnQrTk24Td0E8hU8AcP0FVP+8 #PQm/g/aXf2QQkQT+omdHVEJrAjEAy0pL0EBH6EVS98evDCBtQw22OZT52qXlAwZ2 #gyTriKFVoqjeEjt3SZKKqXHSApP/AjBLpF99zcJJZRq2abgYlf9lv1chkrWqDHUu #DZttmYJeEfiFBBavVYIF1dOlZT0G8jMCMBc7sOSZodFnAiryP+Qg9otSBjJ3bQML #pSTqy7c3a2AScC/YyOwkDaICHnnD3XyjMwIxALRzl0tQEKMXs6hH8ToUdlLROCrP #EhQ0wahUTCk1gKA4uPD6TMTChavbh4K63OvbKg== #-----END RSA PRIVATE KEY-----""" # f.privateKeys = {'ssh-rsa' : keys.Key.fromString(privateKey) } # del privateKey # try: # f.portal.checkers = self.root.getServiceNamed("auth").getCheckers() # except KeyError: # pass # serv=internet.TCPServer( # int(self.config.get("port", 5022, "controlTCPMod")), # f, # interface=self.config.get("interface", "127.0.0.1", "controlTCPMod") # ) # serv.setName("server") # self.addService(serv) service.MultiService.startService(self)
def onLoad(self): while self.manhole is None or not self.manhole.running: try: self.manhole = makeService({ "namespace": { "bot": self.bot }, "passwd": os.path.join("Data", "manhole.passwd"), "telnetPort": None, "sshPort": str(self.port) }) self.manhole.startService() except CannotListenError: self.port += 1
def startService(self): self.config=self.parent.getServiceNamed("config") port = self.config.get("port", 5022, "controlTCPMod") passwd = self.config.get("passwd", "data/passwd", "controlTCPMod") control = self.parent.getServiceNamed("control").handle_command manholeService=manhole_tap.makeService({ 'telnetPort': '', 'sshPort': str(port), 'passwd': passwd, 'namespace': {'app': self.parent, 'c': control} }) manholeService.setName("manhole") self.addService(manholeService) # f = factory.SSHFactory() # f.portal = portal.Portal(SSHRealm(self)) # f.publicKeys = {'ssh-rsa': keys.Key.fromString('ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEArzJx8OYOnJmzf4tfBEvLi8DVPrJ3/c9k2I/Az64fxjHf9imyRJbixtQhlH9lfNjUIx+4LmrJH5QNRsFporcHDKOTwTTYLh5KmRpslkYHRivcJSkbh/C+BR3utDS555mV')} # privateKey = """-----BEGIN RSA PRIVATE KEY----- #MIIByAIBAAJhAK8ycfDmDpyZs3+LXwRLy4vA1T6yd/3PZNiPwM+uH8Yx3/YpskSW #4sbUIZR/ZXzY1CMfuC5qyR+UDUbBaaK3Bwyjk8E02C4eSpkabJZGB0Yr3CUpG4fw #vgUd7rQ0ueeZlQIBIwJgbh+1VZfr7WftK5lu7MHtqE1S1vPWZQYE3+VUn8yJADyb #Z4fsZaCrzW9lkIqXkE3GIY+ojdhZhkO1gbG0118sIgphwSWKRxK0mvh6ERxKqIt1 #xJEJO74EykXZV4oNJ8sjAjEA3J9r2ZghVhGN6V8DnQrTk24Td0E8hU8AcP0FVP+8 #PQm/g/aXf2QQkQT+omdHVEJrAjEAy0pL0EBH6EVS98evDCBtQw22OZT52qXlAwZ2 #gyTriKFVoqjeEjt3SZKKqXHSApP/AjBLpF99zcJJZRq2abgYlf9lv1chkrWqDHUu #DZttmYJeEfiFBBavVYIF1dOlZT0G8jMCMBc7sOSZodFnAiryP+Qg9otSBjJ3bQML #pSTqy7c3a2AScC/YyOwkDaICHnnD3XyjMwIxALRzl0tQEKMXs6hH8ToUdlLROCrP #EhQ0wahUTCk1gKA4uPD6TMTChavbh4K63OvbKg== #-----END RSA PRIVATE KEY-----""" # f.privateKeys = {'ssh-rsa' : keys.Key.fromString(privateKey) } # del privateKey # try: # f.portal.checkers = self.root.getServiceNamed("auth").getCheckers() # except KeyError: # pass # serv=internet.TCPServer( # int(self.config.get("port", 5022, "controlTCPMod")), # f, # interface=self.config.get("interface", "127.0.0.1", "controlTCPMod") # ) # serv.setName("server") # self.addService(serv) service.MultiService.startService(self)
def test_sshPort(self): """ L{manhole_tap.makeService} will make a SSH service on the port defined by C{--sshPort}. It will not make a telnet service. """ # Why the sshKeyDir and sshKeySize params? To prevent it stomping over # (or using!) the user's private key, we just make a super small one # which will never be used in a temp directory. self.options.parseOptions(["--sshKeyDir", self.mktemp(), "--sshKeySize", "512", "--sshPort", "tcp:223"]) service = manhole_tap.makeService(self.options) self.assertIsInstance(service, MultiService) self.assertEqual(len(service.services), 1) self.assertIsInstance(service.services[0], StreamServerEndpointService) self.assertIsInstance(service.services[0].factory, manhole_ssh.ConchFactory) self.assertEqual(service.services[0].endpoint._port, 223)
def test_passwd(self): """ The C{--passwd} command-line option will load a passwd-like file. """ self.options.parseOptions(['--telnetPort', 'tcp:22', '--passwd', self.filename]) service = manhole_tap.makeService(self.options) portal = service.services[0].factory.protocol.portal self.assertEqual(len(portal.checkers.keys()), 2) # Ensure it's the passwd file we wanted by trying to authenticate self.assertTrue(self.successResultOf( portal.login(UsernamePassword(*self.usernamePassword), None, telnet.ITelnetProtocol))) self.assertIsInstance(self.failureResultOf( portal.login(UsernamePassword(b"wrong", b"user"), None, telnet.ITelnetProtocol)).value, error.UnauthorizedLogin)
def makeService(self, options): """ Construct a Tribler service. """ tribler_service = MultiService() tribler_service.setName("Tribler") manhole_namespace = {} if options["manhole"] > 0: port = options["manhole"] manhole = manhole_tap.makeService({ 'namespace': manhole_namespace, 'telnetPort': 'tcp:%d:interface=127.0.0.1' % port, 'sshPort': None, 'passwd': os.path.join(os.path.dirname(__file__), 'passwd'), }) tribler_service.addService(manhole) reactor.callWhenRunning(self.start_tribler, options) return tribler_service
def makeService(self, options): multiService = service.MultiService() conf = InfobobConfig() with open(options.config) as cfgFile: conf.load(cfgFile) conf.config_loc = options.config self.ircFactory = irc.InfobobFactory(conf) clientService = internet.TCPClient if conf['irc.ssl']: clientService = partial(internet.SSLClient, contextFactory=ClientContextFactory()) self.ircService = clientService(conf['irc.server'], conf['irc.port'], self.ircFactory) self.ircService.setServiceParent(multiService) conf.dbpool = database.InfobobDatabaseRunner(conf) if (conf['misc.manhole.socket'] is not None and conf['misc.manhole.passwd_file']): from twisted.conch.manhole_tap import makeService self.manholeService = makeService( dict( telnetPort="unix:" + conf['misc.manhole.socket'].encode(), sshPort=None, namespace={ 'self': self, 'conf': conf }, passwd=conf['misc.manhole.passwd_file'], )) self.manholeService.setServiceParent(multiService) self.webService = internet.TCPServer( conf['web.port'], http.makeSite(http.DEFAULT_TEMPLATES_DIR, conf.dbpool)) self.webService.setServiceParent(multiService) return multiService
self.cy = None clog.info('(doneCleanup) Done shutting down Cy.', syst) elif protocol == 'dc': self.dc = None clog.info('(doneCleanup) Done shutting down Discord.', syst) if not self.irc and not self.cy and not self.dc: self.done.callback(None) application = service.Application("app") yukService = Yukari() yukService.setServiceParent(application) from twisted.conch import manhole_tap manhole_service = manhole_tap.makeService({ "telnetPort": "tcp:{}".format(config['telnet']['port']), "sshPort": None, "namespace": {"y": yukService}, "passwd": "telnet.pw", }) manhole_service.setName("manhole") manhole_service.setServiceParent(yukService) # cytube if CYTUBE: ws_service = WSService() ws_service.setName("cy") ws_service.setServiceParent(yukService) # irc if IRC: irc_service = IrcService() irc_service.setName("irc")
def makeService(self, options): """ Create an instance of PyTIBot """ config = YamlConfig(path=fs.config_file(options["config"])) if not (config["Connection"] and all([ config["Connection"].get(option, False) for option in mandatory_settings ])): raise EnvironmentError("Reading config file failed, mandatory" " fields not set!\nPlease reconfigure") mService = MultiService() # irc client ircserver = config["Connection"]["server"] ircsslport = config["Connection"].get("sslport", None) ircport = config["Connection"].get("port", None) ircbotfactory = PyTIBotFactory(config) if ircsslport: irc_cl = internet.SSLClient(ircserver, ircsslport, ircbotfactory, ssl.ClientContextFactory()) elif ircport: irc_cl = internet.TCPClient(ircserver, ircport, ircbotfactory) else: raise EnvironmentError("Neither sslport nor port are given for " "the irc connection!\nPlease reconfigure") irc_cl.setServiceParent(mService) # manhole for debugging if config["Manhole"]: telnetPort = config.Manhole.get("telnetport", None) if telnetPort: telnetPort = "tcp:{}".format(telnetPort) sshPort = config.Manhole.get("sshport", None) sshKeyDir = config.Manhole.get("sshKeyDir", "<USER DATA DIR>") sshKeyName = config.Manhole.get("sshKeyName", "server.key") sshKeySize = config.Manhole.get("sshKeySize", 4096) if sshPort: sshPort = "ssl:{}".format(sshPort) options = { 'namespace': { 'get_bot': ircbotfactory.get_bot }, 'passwd': os.path.join(fs.adirs.user_config_dir, 'manhole_cred'), 'sshPort': sshPort, 'sshKeyDir': sshKeyDir, 'sshKeyName': sshKeyName, 'sshKeySize': sshKeySize, 'telnetPort': telnetPort } tn_sv = manhole_tap.makeService(options) tn_sv.setServiceParent(mService) if (config["HTTPLogServer"] and ("port" in config["HTTPLogServer"] or "sshport" in config["HTTPLogServer"])): channels = config["HTTPLogServer"]["channels"] if not isinstance(channels, list): channels = [channels] if len(channels) == 1: title = config["HTTPLogServer"].get("title", "PyTIBot Log Server") search_pagelen = config["HTTPLogServer"].get( "search_pagelen", 5) indexer_procs = config["HTTPLogServer"].get("indexer_procs", 1) root = LogPage(channels[0], log.get_channellog_dir(config), title, search_pagelen, indexer_procs, singlechannel=True) else: root = BasePage(config) httpfactory = Site(root) port = config["HTTPLogServer"].get("port", None) if port: http_sv = internet.TCPServer(port, httpfactory) http_sv.setServiceParent(mService) sslport = config["HTTPLogServer"].get("sslport", None) privkey = config["HTTPLogServer"].get("privkey", None) cert = config["HTTPLogServer"].get("certificate", None) if sslport and privkey and cert: sslContext = ssl.DefaultOpenSSLContextFactory(privkey, cert) https_sv = internet.SSLServer(sslport, httpfactory, sslContext) https_sv.setServiceParent(mService) return mService
def makeService(self, options): """ Create an instance of PyTIBot """ config = YamlConfig(path=fs.config_file(options["config"])) if not (config["Connection"] and all([config["Connection"].get(option, False) for option in mandatory_settings])): raise EnvironmentError("Reading config file failed, mandatory" " fields not set!\nPlease reconfigure") mService = MultiService() # irc client ircserver = config["Connection"]["server"] ircsslport = config["Connection"].get("sslport", None) ircport = config["Connection"].get("port", None) ircbotfactory = PyTIBotFactory(config) if ircsslport: irc_cl = internet.SSLClient(ircserver, ircsslport, ircbotfactory, ssl.ClientContextFactory()) elif ircport: irc_cl = internet.TCPClient(ircserver, ircport, ircbotfactory) else: raise EnvironmentError("Neither sslport nor port are given for " "the irc connection!\nPlease reconfigure") irc_cl.setServiceParent(mService) # manhole for debugging if config["Manhole"]: telnetPort = config.Manhole.get("telnetport", None) if telnetPort: telnetPort = "tcp:{}".format(telnetPort) sshPort = config.Manhole.get("sshport", None) sshKeyDir = config.Manhole.get("sshKeyDir", "<USER DATA DIR>") sshKeyName = config.Manhole.get("sshKeyName", "server.key") sshKeySize = config.Manhole.get("sshKeySize", 4096) if sshPort: sshPort = "ssl:{}".format(sshPort) options = {'namespace': {'get_bot': ircbotfactory.get_bot}, 'passwd': os.path.join(fs.adirs.user_config_dir, 'manhole_cred'), 'sshPort': sshPort, 'sshKeyDir': sshKeyDir, 'sshKeyName': sshKeyName, 'sshKeySize': sshKeySize, 'telnetPort': telnetPort} tn_sv = manhole_tap.makeService(options) tn_sv.setServiceParent(mService) if (config["HTTPLogServer"] and ("port" in config["HTTPLogServer"] or "sshport" in config["HTTPLogServer"])): channels = config["HTTPLogServer"]["channels"] if not isinstance(channels, list): channels = [channels] if len(channels) == 1: title = config["HTTPLogServer"].get("title", "PyTIBot Log Server") search_pagelen = config["HTTPLogServer"].get("search_pagelen", 5) root = LogPage(channels[0], log.get_channellog_dir(config), title, search_pagelen, singlechannel=True) else: root = BasePage(config) httpfactory = Site(root) port = config["HTTPLogServer"].get("port", None) if port: http_sv = internet.TCPServer(port, httpfactory) http_sv.setServiceParent(mService) sslport = config["HTTPLogServer"].get("sslport", None) privkey = config["HTTPLogServer"].get("privkey", None) cert = config["HTTPLogServer"].get("certificate", None) if sslport and privkey and cert: sslContext = ssl.DefaultOpenSSLContextFactory( privkey, cert) https_sv = internet.SSLServer(sslport, httpfactory, sslContext) https_sv.setServiceParent(mService) return mService
def enableManhole(site,application): from twisted.conch import manhole_tap manhole_tap.makeService({'telnetPort':'tcp:9001', 'sshPort':'tcp:9002','namespace':{'service':site}, 'passwd':'passwd'}).setServiceParent(application)
# Create application application = service.Application("Aoi") #logfile = DailyLogFile("aoi.log", "logs") #application.setComponent(ILogObserver, FileLogObserver(logfile).emit) # Connect MultiService "topService" to the application topService.setServiceParent(application) ### IRC irc_service = IrcService() irc_service.setName("irc") irc_service.setServiceParent(topService) ## manhole from twisted.conch import manhole_tap manhole_service = manhole_tap.makeService({ "telnetPort": "tcp:8181", "sshPort": None, "namespace": { "service": topService }, "passwd": "pw.txt", }) manhole_service.setName("manhole") manhole_service.setServiceParent(topService) from twisted.internet import reactor reactor.addSystemEventTrigger('before', 'shutdown', topService.cleanup)
clog.info('(doneCleanup) Done shutting down Cy.', sys) if not self.irc and not self.cy: self.done.callback(None) application = service.Application("app") yukService = Yukari() yukService.setServiceParent(application) from twisted.conch import manhole_tap manhole_service = manhole_tap.makeService({ "telnetPort": "tcp:{}".format(config['telnet']['port']), "sshPort": None, "namespace": { "y": yukService }, "passwd": "telnet.pw", }) manhole_service.setName("manhole") manhole_service.setServiceParent(yukService) # cytube ws_service = WSService() ws_service.setName("cy") ws_service.setServiceParent(yukService) # irc irc_service = IrcService()
def makeService(self, options): dataDir = FilePath(os.path.expanduser(options['data'])) if not dataDir.isdir(): dataDir.makedirs() os.environ['TXCONNECT_DATABASE_NAME'] = dataDir.child('dj.sqlite3').path os.environ['TXCONNECT_TRAFFICLOG_DATABASE_NAME'] = dataDir.child('trafficlog.sqlite3').path from txconnect import dbthread dbthread.setup() # have to import these after dbthread is setup from txconnect.directconnect import search, hub_herder, peer_herder, interfaces from txconnect import plugin_service, queuestore, sharestore, memory, web_service, config from txconnect import downloader_manager, trafficlog, extutils locator = components.ReprableComponentized() txconnectService = service.MultiService() txconnectService.name = 'txconnect' locator.setComponent(service.IServiceCollection, txconnectService) configObj = config.Config(dataDir) locator.setComponent(interfaces.IConfig, configObj) memoryService = memory.MemoryService(locator) memoryService.setServiceParent(txconnectService) locator.setComponent(interfaces.IMessageMemory, memoryService) downloadQueue = queuestore.QueueStore(locator) locator.setComponent(interfaces.IDownloadQueue, downloadQueue) downloaderManager = downloader_manager.DownloaderManager(locator) downloaderManager.setServiceParent(txconnectService) locator.setComponent(interfaces.IDownloaderManager, downloaderManager) fileSource = sharestore.ShareStore(locator) fileSource.setServiceParent(txconnectService) locator.setComponent(interfaces.IFileSource, fileSource) searchHerder = search.SearchHerder(locator) searchHerder.setServiceParent(txconnectService) locator.setComponent(interfaces.ISearchHerder, searchHerder) hubHerder = hub_herder.HubHerder(locator) hubHerder.setServiceParent(txconnectService) locator.setComponent(interfaces.IHubHerder, hubHerder) peerHerder = peer_herder.PeerHerder(locator) peerHerder.setServiceParent(txconnectService) locator.setComponent(interfaces.IPeerHerder, peerHerder) trafficLogger = trafficlog.TrafficLogger(locator) trafficLogger.setServiceParent(txconnectService) webService = web_service.make_service(locator) webService.setServiceParent(txconnectService) extUtils = extutils.ExtUtilsService() extUtils.setServiceParent(txconnectService) locator.setComponent(interfaces.IHasher, extUtils) locator.setComponent(interfaces.IDirLister, extUtils) if configObj.has_key('manhole') and configObj['manhole'].has_key('port'): from twisted.conch import manhole_tap manholeService = manhole_tap.makeService({ 'telnetPort': str(configObj['manhole']['port']), 'namespace': {'locator': locator}, 'passwd': 'passwd', 'sshPort': None, }) manholeService.setName('manhole') manholeService.setServiceParent(txconnectService) plugins = plugin_service.PluginService(locator) plugins.setServiceParent(txconnectService) return txconnectService