Пример #1
0
	def __init__(self):
		# Check for any other instances
		if config.pid and os.name != "posix":
			config.pid = ""
		if config.pid:
			twistd.checkPID(config.pid)

		# Do any auto-update stuff
		xdb.housekeep()

		# Daemonise the process and write the PID file
		if daemonizeme and os.name == "posix":
			twistd.daemonize()
		if config.pid:
			self.writePID()

		jid = config.jid
		if config.useXCP and config.compjid: jid = config.compjid

		if config.saslUsername:
			import sasl
			self.c = sasl.buildServiceManager(jid, config.saslUsername, config.secret, "tcp:%s:%s" % (config.mainServer, config.port))
		else:
			self.c = component.buildServiceManager(jid, config.secret, "tcp:%s:%s" % (config.mainServer, config.port))
		self.transportSvc = PyTransport()
		self.transportSvc.setServiceParent(self.c)
		self.c.startService()

		reactor.addSystemEventTrigger('before', 'shutdown', self.shuttingDown)
Пример #2
0
    def __init__(self):
        # Check for any other instances
        if config.pid and os.name != "posix":
            config.pid = ""
        if config.pid:
            twistd.checkPID(config.pid)

        # Do any auto-update stuff
        xdb.housekeep()

        # Daemonise the process and write the PID file
        if daemonizeme and os.name == "posix":
            twistd.daemonize()
        if config.pid:
            self.writePID()

        jid = config.jid
        if config.useXCP and config.compjid: jid = config.compjid

        if config.saslUsername:
            import sasl
            self.c = sasl.buildServiceManager(
                jid, config.saslUsername, config.secret,
                "tcp:%s:%s" % (config.mainServer, config.port))
        else:
            self.c = component.buildServiceManager(
                jid, config.secret,
                "tcp:%s:%s" % (config.mainServer, config.port))
        self.transportSvc = PyTransport()
        self.transportSvc.setServiceParent(self.c)
        self.c.startService()

        reactor.addSystemEventTrigger('before', 'shutdown', self.shuttingDown)
Пример #3
0
    def __init__(self):
        # Check for any other instances
        if config.pid and os.name != "posix":
            config.pid = ""
        if config.pid:
            twistd.checkPID(config.pid)

        # Do any auto-update stuff
        housekeep.init()

        # Daemonise the process and write the PID file
        if config.background and os.name == "posix":
            twistd.daemonize()
        if config.pid:
            self.writePID()

        # Initialise debugging, and do the other half of SIGHUPstuff
        debug.reloadConfig()
        legacy.reloadConfig()

        # Start the service
        jid = config.jid
        if config.useXCP and config.compjid:
            jid = config.compjid
        self.c = component.buildServiceManager(
            jid, config.secret, "tcp:%s:%s" % (config.mainServer, config.port))
        self.transportSvc = PyTransport()
        self.transportSvc.setServiceParent(self.c)
        self.c.startService()
        reactor.addSystemEventTrigger('before', 'shutdown', self.shuttingDown)
Пример #4
0
def makeService(config):
    # Check for parameters...
    try:
        int(config["rport"], 10)
    except ValueError:
        print "Invalid router port (--rport) provided."
        sys.exit(-1)

    if config["secret"] == None:
        print "Component secret (--secret) is a REQUIRED parameter. Configuration aborted."
        sys.exit(-1)

    if config["proxyips"] == None:
        print "Proxy Network Addresses (--proxyips) is a REQUIRED parameter. Configuration aborted."
        sys.exit(-1)

    # Split and parse the addresses to ensure they are valid
    addresses = config["proxyips"].split(",")
    validAddresses = []
    for a in addresses:
        try:
            ip = None
            port = 7777
            if ":" in a:
                ip, port = a.split(":")
            else:
                ip = a
            socket.inet_pton(socket.AF_INET, ip)
            validAddresses.append((ip, int(port)))
        except socket.error:
            print "Warning! Not using invalid proxy network address: ", a

    # No valid addresses, no proxy65
    if len(validAddresses) < 1:
        print "0 Proxy Network Addresses (--proxyips) found. Configuration aborted."
        sys.exit(-1)

    c = component.buildServiceManager(config["jid"], config["secret"],
                                      ("tcp:%s:%s" %
                                       (config["rhost"], config["rport"])))

    proxySvc = Service(config)
    proxySvc.setServiceParent(c)

    # Construct a multi service to hold all the listening
    # services -- the main proxy65.Service object will then
    # just use that to control when the system should be
    # listening
    listeners = service.MultiService()
    for (ip, port) in validAddresses:
        listener = internet.TCPServer(port, proxySvc, interface=ip)
        listener.setServiceParent(listeners)

    # Set the proxy services listeners variable with the
    # new multiservice
    proxySvc.listeners = listeners
    proxySvc.activeAddresses = validAddresses

    return c
Пример #5
0
def makeService(config):
    # Check for parameters...
    try:
        int(config["rport"], 10)
    except ValueError:
        print "Invalid router port (--rport) provided."
        sys.exit(-1)

    if config["secret"] == None:
        print "Component secret (--secret) is a REQUIRED parameter. Configuration aborted."
        sys.exit(-1)

    if config["proxyips"] == None:
        print "Proxy Network Addresses (--proxyips) is a REQUIRED parameter. Configuration aborted."
        sys.exit(-1)

    # Split and parse the addresses to ensure they are valid
    addresses = config["proxyips"].split(",")
    validAddresses = []
    for a in addresses:
        try:
            ip = None
            port = 7777
            if ":" in a:
                ip, port = a.split(":")
            else:
                ip = a
            socket.inet_pton(socket.AF_INET, ip)            
            validAddresses.append((ip, int(port)))
        except socket.error:
            print "Warning! Not using invalid proxy network address: ", a

    # No valid addresses, no proxy65
    if len(validAddresses) < 1:
        print "0 Proxy Network Addresses (--proxyips) found. Configuration aborted."
        sys.exit(-1)
    
    c = component.buildServiceManager(config["jid"], config["secret"],
                                      ("tcp:%s:%s" % (config["rhost"], config["rport"])))

    proxySvc = Service(config)
    proxySvc.setServiceParent(c)

    # Construct a multi service to hold all the listening
    # services -- the main proxy65.Service object will then
    # just use that to control when the system should be
    # listening
    listeners = service.MultiService()
    for (ip,port) in validAddresses:
        listener = internet.TCPServer(port, proxySvc, interface=ip)
        listener.setServiceParent(listeners)

    # Set the proxy services listeners variable with the
    # new multiservice
    proxySvc.listeners = listeners
    proxySvc.activeAddresses = validAddresses

    return c
Пример #6
0
def main():
	print("Hangouts to XMPP transport")

	config = Config()

	h2xComponent = h2x.h2xComponent(reactor, config)
	f = component.componentFactory(config.JID, config.PASSWORD)
	connector = component.buildServiceManager(config.JID, config.PASSWORD, "tcp:%s:%s" % (config.HOST, config.PORT))
	h2xComponent.setServiceParent(connector)
	connector.startService()
	reactor.run()
Пример #7
0
def main():
    version = '0.3'
    config = ConfigParser.ConfigParser()
    config.read('weather.conf')
  
    jid = config.get('component', 'jid')
    password = config.get('component', 'password')
    host = config.get('component', 'host')
    port = config.get('component', 'port')
    path = config.get('component', 'basepath')
    c = gweather.WeatherComponent(reactor, version, config, jid)
    f = component.componentFactory(jid, password)
    connector = component.buildServiceManager(jid, password,
                                     "tcp:%s:%s" % (host, port))
    c.setServiceParent(connector)
    connector.startService()
    reactor.run() 
Пример #8
0
    def connect(self, port, secret, host=None):
        """ Connect component to an XMPP-server to make it works.

        :param port: port to connect to. Needs to be set the same as in XMPP
        server config.

        :param secret: a secret to connect to XMPP server.

        :param host: a host to connect to XMPP server. It's needed only
        if host to connect is differ from jid."""

        if host is None:
            host = unicode(self.myjid)
        f = component.componentFactory(unicode(self.myjid), secret)
        connector = component.buildServiceManager(unicode(self.myjid), secret,
                                         "tcp:%s:%s" % (host, port))
        self.setServiceParent(connector)
        connector.startService()
Пример #9
0
    def connect(self, port, secret, host=None):
        """ Connect component to an XMPP-server to make it works.

        :param port: port to connect to. Needs to be set the same as in XMPP
        server config.

        :param secret: a secret to connect to XMPP server.

        :param host: a host to connect to XMPP server. It's needed only
        if host to connect is differ from jid."""

        if host is None:
            host = unicode(self.myjid)
        f = component.componentFactory(unicode(self.myjid), secret)
        connector = component.buildServiceManager(unicode(self.myjid), secret,
                                                  "tcp:%s:%s" % (host, port))
        self.setServiceParent(connector)
        connector.startService()
Пример #10
0
import bnw.xmpp.base
from bnw.core.bnw_mongo import open_db
from bnw.xmpp import bnw_component, xmpp_notifier
from bnw.handlers import throttle, mapreduce

bnw.core.base.config.register(config)
application = service.Application("BnW")

open_db()

from twisted.internet import reactor
reactor.callWhenRunning(bnw.core.ensure_indexes.index)

# Set up XMPP component.
sm = component.buildServiceManager(
    config.srvc_name, config.srvc_pwd,
    ('tcp:'+config.xmpp_server))

# Turn on verbose mode.
bnw_component.LogService().setServiceParent(sm)

# Set up our service.
s = bnw_component.BnwService()
s.setServiceParent(sm)

bnw.xmpp.base.service.register(s)
bnw.core.base.notifiers.add(xmpp_notifier.XmppNotifier())

serviceCollection = service.IServiceCollection(application)
sm.setServiceParent(serviceCollection)
Пример #11
0
def makeService(config):
    serviceCollection = service.MultiService()
    cf = None
    try:
        p  = ConfigParser()
        cf = p.parse(config['config'])
    except:
        pass

    if not config['jid'] and cf:
        jname = str(getattr(cf,'name','palaver'))
        #jname = 'palaver'
        for e in cf.elements():
            if e.name == 'name':
                jname = str(e)
    elif config['jid']:
        jname = config['jid']
    else:
        jname = 'palaver'


    if not config['secret'] and cf:
        jsecret = str(getattr(cf, 'secret', 'secret'))
    else:
        jsecret = config['secret']

    if not config['rhost']  and cf:
        rhost = str(getattr(cf, 'ip', 'localhost'))
    else:
        rhost = config['rhost']

    if not config['rport']  and cf:
        rp    = getattr(cf, 'port', 5347)
        if rp:
            rport = int(str(rp))
        else:
            rport = 5347
    else:
        rport = int(config['rport'])

    if not config['spool']  and cf:
        spool = str(getattr(cf, 'spool', ''))
    else:
        spool = config['spool']

    # set up Jabber Component
    sm = component.buildServiceManager(jname, jsecret,
            ("tcp:%s:%s" % (rhost , rport)))

    if config["verbose"]:
        LogService().setServiceParent(sm)

    if cf:
        backend = getattr(cf.backend,'type',None)
        if backend:
            config['backend'] = str(backend)
            if config['backend'] != 'memory' and \
               config['backend'] != 'dir':
                dbuser = getattr(cf.backend,'dbuser',None)
                if dbuser:
                    config['dbuser'] = str(dbuser)
                dbname = getattr(cf.backend,'dbname',None)
                if dbname:
                    config['dbname'] = str(dbname)
                dbpass = getattr(cf.backend,'dbpass',None)
                if dbpass:
                    config['dbpass'] = str(dbpass)
                else:
                    config['dbpass'] = None

                dbport = getattr(cf.backend,'dbport',None)
                if dbport:
                    config['dbport'] = str(dbport)
                else:
                    config['dbport'] = None

                dbhostname = getattr(cf.backend,'dbhostname',None)
                if dbhostname:
                    config['dbhostname'] = str(dbhostname)
                else:
                    config['dbhostname'] = None
    config['plugins'] = {}
    if cf:
        if getattr(cf,'plugins',None):
            for p in cf.plugins.elements():
                plugin = reflect.namedModule(str(p))
                config['plugins'][str(p.name)] = plugin.Plugin()

    if config['backend'] == 'dir':
        import dir_storage
        st = dir_storage.Storage(spool)
    elif config['backend'] == 'memory':
        import memory_storage
        st = memory_storage.Storage()
    elif config['backend'] == 'pgsql':
        import pgsql_storage
        if config['dbhostname']:
            host = config['dbhostname']
        else:
            host = None

        if config['dbpass']:
            dbpass = config['dbpass']
        else:
            dbpass = None

        if config['dbport']:
            dbport = config['dbport']
        else:
            dbport = None

        st = pgsql_storage.Storage(user=config['dbuser'],
                                   database=config['dbname'],
                                   hostname=host,
                                   password=dbpass,
                                   port=dbport,
                                   )

    elif config['backend'] == 'psycopg':
        import psycopg_storage
        if config['dbhostname']:
            host = config['dbhostname']
        else:
            host = None

        if config['dbpass']:
            dbpass = config['dbpass']
        else:
            dbpass = None

        st = psycopg_storage.Storage(user=config['dbuser'],
                                   database=config['dbname'],
                                   hostname=host,
                                   password=dbpass,
                                   )

    sadmins = []
    conference = getattr(cf,'conference', None)
    if conference:
        sa = getattr(conference, 'sadmin', None)
        if sa:
            for u in sa.elements():
                sadmins.append(str(u))

    if len(sadmins)>0:
        st.sadmins = sadmins

    import muc
    bs = muc.groupchat.GroupchatService(st)
    if len(sadmins)>0:
        bs.sadmins = sadmins
    bs.plugins = config['plugins']

    c = IService(bs)
    c.setServiceParent(sm)

    bsc = muc.groupchat.RoomService()
    bsc.plugins = config['plugins']
    bsc.create_rooms = config['create']
    if len(sadmins)>0:
        bsc.sadmins = sadmins


    bsc.setServiceParent(bs)
    rs = IService(bsc)
    if len(config['log'])>1:
        import plog
        rs.logger = plog.HTMLLogger(config['log'])

    rs.setServiceParent(sm)

    if config['admin']==1:
        bsc = muc.groupchat.AdminService()
        bsc.plugins = config['plugins']
        bsc.setServiceParent(bs)
        if len(sadmins)>0:
            bsc.sadmins = sadmins

        IService(bsc).setServiceParent(sm)


    s = PalaverService()
    s.setServiceParent(sm)

    sm.setServiceParent(serviceCollection)


    return serviceCollection