def makeService(self, opts): from carchive.a2aproxy.resource import buildResource from carchive.util import LimitedSite, LimitedTCPServer L = logging.INFO if opts['debug']: L = logging.DEBUG handle = Log2Twisted() handle.setFormatter(logging.Formatter("%(levelname)s:%(name)s %(message)s")) root = logging.getLogger() root.addHandler(handle) root.setLevel(L) serv = service.MultiService() fact = LimitedSite(buildResource(opts['appl'])) serv.addService(LimitedTCPServer(opts['port'], fact, interface=opts['ip'])) if ShellFactory and opts['manhole']: print 'Opening Manhole' SF = ShellFactory() SS = TCPServer(opts['manhole'], SF, interface='127.0.0.1') # populate manhole shell locals SF.namespace['site'] = fact serv.addService(SS) else: print 'No Manhole' return serv
def makeService(self, opts): from carchive.a2aproxy.resource import buildResource from carchive.util import LimitedSite, LimitedTCPServer L = logging.INFO if opts['debug']: L = logging.DEBUG handle = Log2Twisted() handle.setFormatter( logging.Formatter("%(levelname)s:%(name)s %(message)s")) root = logging.getLogger() root.addHandler(handle) root.setLevel(L) serv = service.MultiService() fact = LimitedSite(buildResource(opts['appl'])) serv.addService( LimitedTCPServer(opts['port'], fact, interface=opts['ip'])) if ShellFactory and opts['manhole']: print 'Opening Manhole' SF = ShellFactory() SS = TCPServer(opts['manhole'], SF, interface='127.0.0.1') # populate manhole shell locals SF.namespace['site'] = fact serv.addService(SS) else: print 'No Manhole' return serv
def enable(self): log.debug ("Manhole: Enabled") self.config = deluge.configmanager.ConfigManager("manhole.conf", DEFAULT_PREFS) sf = ShellFactory() sf.username = self.config['username'] sf.password = self.config['password'] self.listenport = reactor.listenTCP(self.config['port'], sf)
def makeService(self, opts): from carchive._conf import ConfigDict from carchive.archmiddle.proxy import buildResource from carchive.archmiddle.info import InfoCache, KeyNameMap server = ConfigDict(opts['config'], 'server') mapping = ConfigDict(opts['config'], 'mapping') handle = Log2Twisted() handle.setFormatter(logging.Formatter("%(message)s")) root = logging.getLogger() root.addHandler(handle) root.setLevel(server.getint('log.level', logging.INFO)) # turn down the noise level... CRL = logging.getLogger('carchive.rpcmunge') if CRL.isEnabledFor(logging.DEBUG): CRL.setLevel(logging.INFO) mservice = service.MultiService() _M = [] for k, v in mapping.iteritems(): v = v.split() _M.append((k, int(v[0]), v[1:])) KM = KeyNameMap(_M) info = InfoCache(server['url'], KM) root, leaf = buildResource(info, reactor) fact = Site(root) info.pvlimit = server.getint('cache.limit', 500) info.timeout = server.getfloat('cache.timeout', 3600) mservice.addService( TCPServer(server.getint('port'), fact, interface=server.get('interface', ''))) if ShellFactory and server.getint('manhole.port', 0): print 'Opening Manhole' SF = ShellFactory() SS = TCPServer(server.getint('manhole.port', 0), SF, interface='127.0.0.1') # populate manhole shell locals SF.namespace['site'] = fact SF.namespace['node'] = leaf SF.namespace['info'] = info mservice.addService(SS) else: print 'No Manhole' return mservice
def makeService(self, opts): from carchive._conf import ConfigDict from carchive.archmiddle.proxy import buildResource from carchive.archmiddle.info import InfoCache, KeyNameMap server = ConfigDict(opts["config"], "server") mapping = ConfigDict(opts["config"], "mapping") handle = Log2Twisted() handle.setFormatter(logging.Formatter("%(message)s")) root = logging.getLogger() root.addHandler(handle) root.setLevel(server.getint("log.level", logging.INFO)) # turn down the noise level... CRL = logging.getLogger("carchive.rpcmunge") if CRL.isEnabledFor(logging.DEBUG): CRL.setLevel(logging.INFO) mservice = service.MultiService() _M = [] for k, v in mapping.iteritems(): v = v.split() _M.append((k, int(v[0]), v[1:])) KM = KeyNameMap(_M) info = InfoCache(server["url"], KM) root, leaf = buildResource(info, reactor) fact = Site(root) info.pvlimit = server.getint("cache.limit", 500) info.timeout = server.getfloat("cache.timeout", 3600) mservice.addService(TCPServer(server.getint("port"), fact, interface=server.get("interface", ""))) if ShellFactory and server.getint("manhole.port", 0): print "Opening Manhole" SF = ShellFactory() SS = TCPServer(server.getint("manhole.port", 0), SF, interface="127.0.0.1") # populate manhole shell locals SF.namespace["site"] = fact SF.namespace["node"] = leaf SF.namespace["info"] = info mservice.addService(SS) else: print "No Manhole" return mservice
def main(): port = 6687 address = '127.0.0.1' collab_factory = CollabClientFactory() shell_factory = ShellFactory() shell_factory.username = "" shell_factory.password = "" shell_factory.namespace['factory'] = collab_factory shell_factory.namespace.update(packets) collab_connection = collab_factory.connect_to_server(address, port) manhole_connection = reactor.listenTCP(6686, shell_factory) reactor.run()
def makeService(self, options): """ Construct a TCPServer from a factory defined in myproject. """ s = MultiService() irp = internet.TCPServer(int(options["port"]), IRPServerFactory()) irp.setServiceParent(s) manholeFactory = ShellFactory() manholeFactory.username = "******" manholeFactory.password = "******" manholeFactory.namespace["foo"] = 12 manholeService = internet.TCPServer(8000, manholeFactory) manholeService.setServiceParent(s) return s
def main(): port = 6687 server_factory = CollabServerFactory() shell_factory = ShellFactory() server_endpoint = TCP4ServerEndpoint(reactor, port) shell_factory.username = "" shell_factory.password = "" def get_client(): for i in server_factory.protocols: return server_factory.protocols[i] def run_packets(): c = get_client() c.document_added(add_packet) c.document_opened(open_packet) c.text_modified(text_mod_packet) shell_factory.namespace['get_client'] = get_client shell_factory.namespace['runp'] = run_packets shell_factory.namespace['factory'] = server_factory server_connection = server_endpoint.listen(server_factory) shell_connection = reactor.listenTCP(6684, shell_factory) reactor.run()
def main(): port = 6687 address = '127.0.0.1' collab_factory = PollFactory() shell_factory = ShellFactory() shell_factory.username = "" shell_factory.password = "" def get_client(): for i in collab_factory.protocols: return collab_factory.protocols[i] def run_packets(): c = get_client() c.transport.write(add_packet) c.transport.write(open_packet) c.transport.write(text_mod_packet) shell_factory.namespace['factory'] = collab_factory shell_factory.namespace['get_client'] = get_client shell_factory.namespace['runp'] = run_packets shell_factory.namespace.update(packets) collab_connection = collab_factory.connect_to_server(address, port) manhole_connection = reactor.listenTCP(6686, shell_factory) reactor.run()
def __init__(self, namespace=None): ShellFactory.__init__(self) self.namespace.update(namespace or {})
from server import Server from web.server import process from datetime import datetime server = Server() httpserver = http.HTTPFactory() httpserver.protocol().requestFactory.process = process #httpserver.protocol.requestFactory.process = process reactor.addSystemEventTrigger('before', 'shutdown', server.cleanup) application = service.Application(SERVER_NAME) log_path = config.log_path log_rotate = int(config.log_rotate_interval) logfile = LogFile('gateway.log', log_path, rotateLength=log_rotate) logOb = FileLogObserver(logfile) logOb.formatTime = lambda when: datetime.fromtimestamp(when).strftime( '%m/%d %T.%f') application.setComponent(ILogObserver, logOb.emit) internet.TCPServer(config.port, server, backlog=500).setServiceParent( service.IServiceCollection(application)) internet.TCPServer(config.httport, httpserver).setServiceParent( service.IServiceCollection(application)) internet.TCPServer(config.adminport, ShellFactory(), interface='127.0.0.1').setServiceParent( service.IServiceCollection(application))
sys.setdefaultencoding('utf-8') from os.path import abspath, dirname, join, normpath PREFIX = normpath(dirname(abspath(__file__))) for path in (PREFIX, normpath(join(PREFIX, '../lib'))): if path not in sys.path: sys.path = [path] + sys.path import setting SERVER_NAME = 'GAMESERVER' import log log.init(setting.LOG_THRESHOLD) import redis redis.init(setting.REDIS_CONF) from server import Server from datetime import datetime server = Server() reactor.addSystemEventTrigger('before', 'shutdown', server.cleanup) application = service.Application(SERVER_NAME) logfile = LogFile('game.log', join(PREFIX, '../logs'), rotateLength=setting.LOG_ROTATE_INTERVAL) logOb = FileLogObserver(logfile) logOb.formatTime = lambda when : datetime.fromtimestamp(when).strftime('%m/%d %T.%f') application.setComponent( ILogObserver, logOb.emit ) internet.TCPServer(setting.GAMESERVER['port'], server, interface=setting.GAMESERVER['hostname']).setServiceParent(service.IServiceCollection(application)) internet.TCPServer(setting.GAMESERVER['adminport'], ShellFactory(), interface=setting.GAMESERVER['hostname']).setServiceParent(service.IServiceCollection(application))
def start(reactor, namespace, port, username, password): shell_factory = ShellFactory() shell_factory.username = username shell_factory.password = password shell_factory.namespace = namespace reactor.listenTCP(port, shell_factory)
try: out = sys.stdout sys.stdout = self try: code = compile(cmd, fn, "eval") result = eval(code, self.namespace) if isinstance(result, Deferred): result = yield result except: try: code = compile(cmd, fn, "exec") exec(code in self.namespace) except Exception as e: self.write("Internal error: %s.\r\n>>> " % e) return finally: sys.stdout = out if result is not None: self.transport.write(repr(result)) self.transport.write("\r\n") self.transport.write(">>> ") if __name__ == "__main__": shell = ShellFactory() shell.protocol = MyShell # Open a Telnet server that will simulate a Python server # with the current environment reactor.listenTCP(4243, shell) reactor.run()
syslog_conf = (syslog_conf[0], int(syslog_conf[1])) else: syslog_conf = syslog_conf[0] init_logger( syslog_conf ) ''' from server import Server from datetime import datetime server = Server() reactor.addSystemEventTrigger('before', 'shutdown', server.cleanup) application = service.Application(SERVER_NAME) log_path = config.log_path log_rotate = int(config.log_rotate_interval) logfile = LogFile('message.log', log_path, rotateLength=log_rotate) logOb = FileLogObserver(logfile) logOb.formatTime = lambda when: datetime.fromtimestamp(when).strftime( '%m/%d %T.%f') application.setComponent(ILogObserver, logOb.emit) internet.TCPServer(config.port, server, interface=config.interface).setServiceParent( service.IServiceCollection(application)) internet.TCPServer(config.adminport, ShellFactory(), interface=config.interface).setServiceParent( service.IServiceCollection(application))
reactor.addSystemEventTrigger('before', 'shutdown', beforeandaftershutdown, 'Before') reactor.addSystemEventTrigger('during', 'shutdown', beforeandaftershutdown, 'During') reactor.addSystemEventTrigger('after', 'shutdown', beforeandaftershutdown, 'After') if config.rpc_enabled: internet.TCPServer( config.rpc_port, server.Site(s.getRPC()), interface="127.0.0.1").setServiceParent(serviceCollection) if config.statsd: from bnw.core import statsd hostport = config.statsd.split(':',1) statsd.setup(hostport[0], int(hostport[1])) if config.manhole: shell_factory = ShellFactory() shell_factory.password = config.manhole shell_tcp_server = internet.TCPServer(4040, shell_factory, interface="127.0.0.1") shell_tcp_server.setServiceParent(serviceCollection) if config.webui_enabled: import bnw.web.site http_server = bnw.web.site.get_site() http_server.listen(config.webui_port, "127.0.0.1") bnw.core.base.timertime = 0 def checkload(lasttime): currenttime = time() if lasttime is not None: bnw.core.base.timertime = currenttime - lasttime reactor.callLater(1, checkload, currenttime)
def __init__(self, name): ShellFactory.__init__(self) IbidSourceFactory.__init__(self, name) self.name = name