示例#1
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        self.log.info('Starting...')

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))
        self.adapter = JabberAdapter(True)
        password = self.options.jabber_pass
        chatroom = self.options.chatroom
        username = self.options.jabber_user
        host = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        server = '%s:%s' % (host, port)

        client = TwistedJabberClient(dialogHandler = self.adapter,
        server = server,
        userId = username, userPassword = password,
        firstRoom = chatroom, debug = True,
        groupServer = groupServer, realHost = realHost, wants_ssl = wants_ssl)

        self.adapter.client = client

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]
        initPluginSystem({'pluginPath': pluginPath, 'plugins': plugins})

        self.log.info('started')

        # connect to the jabber server
        jabber_reactor = client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        # start event loop which will process jabber messages and zenevents
        jabber_reactor.run()
示例#2
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)
                
            if zenUser and jabberId:    
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))
        self.adapter = JabberAdapter(True)
        password = self.options.jabber_pass
        chatroom = self.options.chatroom
        username = self.options.jabber_user
        host = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        server = '%s:%s' % (host, port)

        client = TwistedJabberClient(dialogHandler = self.adapter, 
        server = server,
        userId = username, userPassword = password, 
        firstRoom = chatroom, debug = True, 
        groupServer = groupServer, realHost = realHost, wants_ssl = wants_ssl)

        self.adapter.client = client

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]
        initPluginSystem({'pluginPath': pluginPath, 'plugins': plugins})

        self.log.info('started')

        # connect to the jabber server
        jabber_reactor = client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        # start event loop which will process jabber messages and zenevents
        jabber_reactor.run()
示例#3
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error(
                'SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.'
            )
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error(
                    '--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]'
                )
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error(
                    '--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]'
                )
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(
            Event.Event(device=self.options.monitor,
                        eventClass=App_Start,
                        summary='Jabber Bot started',
                        severity=0,
                        component='xmppbot'))

        password = self.options.jabber_pass
        chatrooms = self.options.chatrooms
        username = self.options.jabber_user
        server = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        resource = self.options.resource

        self.client = TwistedJabberClient(server=server,
                                          username=username,
                                          password=password,
                                          port=port,
                                          groupServer=groupServer,
                                          chatrooms=chatrooms,
                                          ssl=wants_ssl,
                                          realHost=realHost,
                                          resource=resource)

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [
            pluginFile.split('/')[-1].split('.py')[0]
            for pluginFile in glob.glob(os.path.join(pluginPath, '*.py'))
        ]

        self.log.debug("xmppBot loading pugins  %s" % ', '.join(plugins))
        initPluginSystem(pluginPath=pluginPath,
                         plugins=plugins,
                         jabberClient=self.client)

        # connect to the jabber server
        self.log.info('Connecting to server')
        reactor = self.client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        reactor.suggestThreadPoolSize(10)
        reactor.run()
示例#4
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))

        password = self.options.jabber_pass
        chatrooms = self.options.chatrooms
        username = self.options.jabber_user
        server = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        resource = self.options.resource

        self.client = TwistedJabberClient(server=server, username=username, password=password,
                                 port=port,
                                 groupServer=groupServer,
                                 chatrooms=chatrooms, ssl=wants_ssl,
                                 realHost=realHost, resource=resource)

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]

        self.log.debug("xmppBot loading pugins  %s" % ', '.join(plugins))
        initPluginSystem(pluginPath=pluginPath, plugins=plugins, jabberClient=self.client)

        # connect to the jabber server
        self.log.info('Connecting to server')
        reactor = self.client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        reactor.suggestThreadPoolSize(10)
        reactor.run()