Esempio n. 1
0
    def getGenericAnswers(self, name, instruction, prompts):
        """
        Called from conch.

        Returns a L{Deferred} with the responses to the prompts.

        @param name: The name of the authentication currently in progress.
        @param instruction: Describes what the authentication wants.
        @param prompts: A list of (prompt, echo) pairs, where prompt is a
        string to display and echo is a boolean indicating whether the
        user's response should be echoed as they type it.
        """
        log.msg('getGenericAnswers name:"%s" instruction:"%s" prompts:%s',
                name, instruction, pformat(prompts))
        if not prompts:
            # RFC 4256 - In the case that the server sends a `0' num-prompts
            # field in the request message, the client MUST send a response
            # message with a `0' num-responses field to complete the exchange.
            d = defer.succeed([])
        else:
            responses = []
            found_prompt = False
            for prompt, echo in prompts:
                if 'password' in prompt.lower():
                    found_prompt = True
                    try:
                        responses.append(self._getPassword())
                    except NoPasswordException:
                        # This shouldn't happen - we don't support keyboard interactive
                        # auth unless a password is specified
                        log.msg("getGenericAnswers called with empty password")
            if not found_prompt:
                log.warning('No known prompts: %s', pformat(prompts))
            d = defer.succeed(responses)
        return d
Esempio n. 2
0
    def activate(self):
        self.installable = []
        self.uninstallable = []
        installed = {}
        available = {}
        for i in self.store.query(InstalledPlugin):
            installed[i.path] = i.version

        for a in getPlugins(isqueal.ISquealPlugin, plugins):
            path = a.__name__ + "." + a.__module__
            available[path] = a

        for path, plugin in available.items():
            if path in installed:
                self.uninstallable.append({
                    'plugin': plugin,
                    'version': a.version,
                    'path': path
                })
                if plugin.version > installed[path]:
                    log.warning("Plugin %s has been upgraded" % path)
                elif plugin.version < installed[path]:
                    log.warning("Plugin %s has been downgraded" % path)
            else:
                self.installable.append({
                    'plugin': plugin,
                    'version': a.version,
                    'path': path
                })

        for path, version in installed.items():
            if path not in available:
                print "Plugin", path, "has been removed"
Esempio n. 3
0
def loadClass(cfg, log, plugin):
    section = "plugin:%s" % plugin
    if not section in cfg.sections(): 
        log.msg("Plugin: %s can't be loaded :-( section %s is missing" % (plugin, section), system='sgas.Setup')
        return None
    if not config.PLUGIN_CLASS in cfg.options(section):
        log.msg("Plugin: %s can't be loaded :-( option %s is missing in %s" % (plugin, config.PLUGIN_CLASS, section), system='sgas.Setup')
        return None
    if not config.PLUGIN_PACKAGE in cfg.options(section):
        log.msg("Plugin: %s can't be loaded :-( option %s is missing in %s" % (plugin, config.PLUGIN_PACKAGE, section), system='sgas.Setup')
        return None
           
    m = re.search(r'^(.*)\.([^\.]+)$',cfg.get(section,config.PLUGIN_PACKAGE))
    if not m:
        log.warning("Plugin: %s can't be loaded; the %s definition seems malformed in %s" % (plugin, config.PLUGIN_PACKAGE, section), system='sgas.Setup')
        return None

    ppackage = m.groups()
    pclass = cfg.get(section,config.PLUGIN_CLASS)
              
    # import module
    pluginModule = __import__(ppackage[0],globals(),locals(),[ppackage[1]])
    
    # Create class
    pluginClass = getattr(getattr(pluginModule,ppackage[1]),pclass)
        
    return pluginClass
Esempio n. 4
0
 def _on_facebook_request(self, callback, response):
     if response.error:
         log.warning("Error response %s fetching %s", response.error,
                         response.request.url)
         callback(None)
         return
     callback(escape.json_decode(response.body))
Esempio n. 5
0
 def _on_facebook_request(self, callback, response):
     if response.error:
         log.warning("Error response %s fetching %s", response.error,
                     response.request.url)
         callback(None)
         return
     callback(escape.json_decode(response.body))
Esempio n. 6
0
    def channelClosed(self, channel):
        if not channel.conn:
            log.warning("Channel %r failed to open", channel.id)
            # Channel has no connection, so we were still trying to open it
            # The normal error handling won't notify us since the channel never successfully opened.
            channel.openFailed(None)

        connection.SSHConnection.channelClosed(self, channel)
Esempio n. 7
0
    def channelClosed(self, channel):
        if not channel.conn:
            log.warning("Channel %r failed to open", channel.id)
            # Channel has no connection, so we were still trying to open it
            # The normal error handling won't notify us since the channel never successfully opened.
            channel.openFailed(None)

        connection.SSHConnection.channelClosed(self, channel)
Esempio n. 8
0
 def bootstrap(self, *args):
     try:
         self.protocol.add_event_listener('CONF_CHANGED', self._conf_changed)
     except (RuntimeError, e):
         ## for Tor versions which don't understand CONF_CHANGED
         ## there's nothing we can really do.
         log.warning("Can't listen for CONF_CHANGED event; won't stay up-to-date with other clients.")
     return self.protocol.get_info_raw("config/names").addCallbacks(self._do_setup, log.err).addCallback(self.do_post_bootstrap).addErrback(log.err)
Esempio n. 9
0
def twisted_log(eventDict):
    log = logging.getLogger('twisted')
    if 'failure' in eventDict:
        log.error(eventDict.get('why') or 'Unhandled exception' + '\n' + str(eventDict['failure'].getTraceback()))
    elif 'warning' in eventDict:
        log.warning(eventDict['warning'])
    else:
        log.debug(' '.join([str(m) for m in eventDict['message']]))
Esempio n. 10
0
    def closed(self):
        if self.exit_status is None and self.running and self.exit_defer and not self.exit_defer.called:
            log.warning("Channel has been closed without receiving an exit status")
            self.exit_defer.errback(failure.Failure(exc_value=ChannelClosedEarlyError()))

        for callback in self.end_callbacks:
            callback()
        self.loseConnection()
Esempio n. 11
0
 def close(self):
     """Explicitly close this instance of the class. This is to make sure
     that all is closed down correctly, even if the garbage collector can't
     destroy the instance."""
     if hasattr(self, 'db'):
         try:
             self.db.close()
         except Exception, e:
             log.warning("Problems with db.close: %s" % e)
Esempio n. 12
0
    def close(self):
        """Explicitly close this instance, as python's garbage collector can't
        close the database connections when Twisted is reusing the threads.

        """
        if hasattr(self, 'db'):
            try:
                self.db.close()
            except Exception, e:
                log.warning("Problems with db.close: %s" % e)
Esempio n. 13
0
def twisted_log(eventDict):
    log = logging.getLogger('twisted')
    if 'failure' in eventDict:
        log.error(
            eventDict.get('why') or 'Unhandled exception' + '\n' +
            str(eventDict['failure'].getTraceback()))
    elif 'warning' in eventDict:
        log.warning(eventDict['warning'])
    else:
        log.debug(' '.join([str(m) for m in eventDict['message']]))
Esempio n. 14
0
    def close(self):
        """Explicitly close this instance, as python's garbage collector can't
        close the database connections when Twisted is reusing the threads.

        """
        if hasattr(self, 'db'):
            try:
                self.db.close()
            except Exception, e:
                log.warning("Problems with db.close: %s" % e)
Esempio n. 15
0
    def closed(self):
        if self.exit_status is None and self.running and self.exit_defer and not self.exit_defer.called:
            log.warning(
                "Channel has been closed without receiving an exit status")
            self.exit_defer.errback(
                failure.Failure(exc_value=ChannelClosedEarlyError()))

        for callback in self.end_callbacks:
            callback()
        self.loseConnection()
Esempio n. 16
0
File: auth.py Progetto: powo/cyclone
    def _on_access_token(self, redirect_uri, client_id, client_secret, callback, fields, response):
        if response.error:
            log.warning("Facebook auth error: %s" % str(response))
            callback(None)
            return

        args = escape.parse_qs_bytes(escape.native_str(response.body))
        session = {"access_token": args["access_token"][-1], "expires": args.get("expires")}

        self.facebook_request(
            path="/me",
            callback=self.async_callback(self._on_get_user_info, callback, session, fields),
            access_token=session["access_token"],
            fields=",".join(fields),
        )
Esempio n. 17
0
    def channelOpen(self, data):
        self.data = []
        self.running = True

        if self.start_defer:
            log.debug("Channel %s is open, calling deferred", self.id)
            self.start_defer.callback(self)
            self.conn.sendRequest(self, "exec", common.NS(self.command), wantReply=True).addCallback(
                self._cbExecSendRequest
            )
        else:
            # A missing start defer means that we are no longer expected to do anything when the channel opens
            # It probably means we gave up on this connection and failed the job, but later the channel opened up
            # correctly.
            log.warning("Channel open delayed, giving up and closing")
            self.loseConnection()
Esempio n. 18
0
    def channelOpen(self, data):
        self.data = []
        self.running = True

        if self.start_defer:
            log.debug("Channel %s is open, calling deferred", self.id)
            self.start_defer.callback(self)
            self.conn.sendRequest(self,
                                  'exec',
                                  common.NS(self.command),
                                  wantReply=True).addCallback(
                                      self._cbExecSendRequest)
        else:
            # A missing start defer means that we are no longer expected to do anything when the channel opens
            # It probably means we gave up on this connection and failed the job, but later the channel opened up
            # correctly.
            log.warning("Channel open delayed, giving up and closing")
            self.loseConnection()
Esempio n. 19
0
    def onMessage(self, msg, binary):
        if binary:
            log.warning('Binary message ignored {!r}'.format(msg))
            return
        jd = json.loads(msg)
        jd['data'] = json.loads(jd['data'])
        if jd['action'].startswith('1-questions-active'):
            qid = do_something(jd)
            if qid not in self.seen:
                self.sendMessage('1-question-{}'.format(qid))
		try:
                qinfo = Site('stackoverflow').questions(qid).filter('withbody')[0]._data                
	            qinfo['_id'] = qid
        	    qinfo['datetime_seen'] = datetime.now()
                posts.insert(qinfo)
                self.seen.add(qid)
		except Exception:
			pass
Esempio n. 20
0
    def _on_access_token(self, redirect_uri, client_id, client_secret,
                         callback, fields, response):
        if response.error:
            log.warning('Facebook auth error: %s' % str(response))
            callback(None)
            return

        args = escape.parse_qs_bytes(escape.native_str(response.body))
        session = {
            "access_token": args["access_token"][-1],
            "expires": args.get("expires")
        }

        self.facebook_request(path="/me",
                              callback=self.async_callback(
                                  self._on_get_user_info, callback, session,
                                  fields),
                              access_token=session["access_token"],
                              fields=",".join(fields))
Esempio n. 21
0
    def _on_access_token(self, redirect_uri, client_id, client_secret,
                         callback, fields, response):

        if response.error:
            log.warning('GitHub auth error: %s' % str(response))
            callback(None)
            return

        args = escape.parse_qs_bytes(escape.native_str(response.body))
        session = {
            "access_token": args["access_token"][-1],
            "token_type": args["token_type"][-1],
        }

        self.github_request(
            path="/user",
            callback=self.async_callback(
                self._on_get_user_info, callback, session, fields),
            access_token=session["access_token"],
            fields=",".join(fields)
        )
Esempio n. 22
0
        # the auth class? It is supposed to be thread safe.
        #self.ba = BofhdAuth(self.db)
        self.operator_id = operator_id

    def close(self):
        """Explicitly close this instance of the class. This is to make sure
        that all is closed down correctly, even if the garbage collector can't
        destroy the instance."""
        if hasattr(self, 'db'):
            try:
                self.db.close()
            except Exception, e:
                log.warning("Problems with db.close: %s" % e)
        else:
            # TODO: this could be removed later, when it is considered stable
            log.warning("db doesn't exist")

    def search_members_flat(self, groupname):
        # TODO: add access control for who is allowed to get the members. Only
        # moderators of the given group?
        #if not self.ba.is_superuser(self.operator_id):
        #    raise NotAuthorizedError('Only for superusers')
        # Raises Cerebrum.modules.bofh.errors.PermissionDenied - how to handle
        # these?
        #self.ba.can_set_trait(self.operator_id)
        try:
            self.grp.clear()
            self.grp.find_by_name(groupname)
        except Errors.NotFoundError:
            raise Errors.CerebrumRPCException("Group %s not found." % groupname)
        grp_id = self.grp.entity_id
Esempio n. 23
0
 def _warn(self, obj):
     tlog.warning( str(obj) )
Esempio n. 24
0
        #self.ba = BofhdAuth(self.db)
        self.operator_id = operator_id

    def close(self):
        """Explicitly close this instance, as python's garbage collector can't
        close the database connections when Twisted is reusing the threads.

        """
        if hasattr(self, 'db'):
            try:
                self.db.close()
            except Exception, e:
                log.warning("Problems with db.close: %s" % e)
        else:
            # TODO: this could be removed later, when it is considered stable
            log.warning("db doesn't exist")

    def search_mac_addresses(self, hostname, mac_address):
        """Search for hostnames and their MAC addresses."""
        m_id = a_id = None
        if hostname:
            a_id = self.finder.find_a_record(hostname)
            self.aaaa.clear()
            self.aaaa.find(a_id)
            if not self.aaaa.mac:
                return ()
            if mac_address and mac_address != self.aaaa.mac:
                return ()
            return ((self.aaaa.name, self.aaaa.mac),)
        # Return either the complete list of hosts and their MAC addresses, or
        # only the host with the given MAC address:
Esempio n. 25
0
    def list(self):
        return [x[0] for x in self.q]

    def remove(self, func):
        return self.q.remove(func)

    def clear(self):
        self.q.clear()


try:
    import redis
except Exception as e:
    # raise e
    log.warning('not install redis module!!!')


@implementer(ISpiderQueue)
class RedisSpiderQueue(object):
    """store by redis"""
    def __init__(self,
                 key='sort_name',
                 db=0,
                 password=None,
                 host='localhost',
                 port=6379,
                 decode_responses=True):
        if password:
            print('-=' * 50)
            print(password)