def setFamilyToScan(self, familyList, blacklist_ignore): """ It puts the oid of the families to scan according to family value: familyList = None --> Scan all families known familyList = DEFAULT_FAMILY --> Scan default families familyList = [General, ...] --> Scan families specified """ if familyList == None: #all families oidListFamily = [ family.keys() for family in self.familyDict.values() ] else: #DEFAULT_FAMILY or [General, ...] oidListFamily = [ family.keys() for (name, family) in self.familyDict.items() if name in familyList ] oidList = [oid for family in oidListFamily for oid in family] if blacklist_ignore: return (oidList) else: blacklist_ = blacklist.Blacklist() return (blacklist_.removeBlacklistedOid(oidList))
def _check_blacklist(self): ''' Check if the current requester address has been blacklisted. ''' blst = blacklist.Blacklist() return blst.check_and_add(self._requester_addr)
def __init__(self, cfg=None): """ Create new object by reading a configuration file. :param: cfg (string) the path of the configuration file. """ default_cfg = 'twitter.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.api_key = config.get('access_config', 'api_key') self.api_secret = config.get('access_config', 'api_secret') self.access_token = config.get('access_config', 'access_token') self.token_secret = config.get('access_config', 'token_secret') self.mirrors = config.get('general', 'mirrors') self.i18ndir = config.get('i18n', 'dir') logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'twitter.log') loglevel = config.get('log', 'level') blacklist_cfg = config.get('blacklist', 'cfg') self.bl = blacklist.Blacklist(blacklist_cfg) self.bl_max_request = config.get('blacklist', 'max_requests') self.bl_max_request = int(self.bl_max_request) self.bl_wait_time = config.get('blacklist', 'wait_time') self.bl_wait_time = int(self.bl_wait_time) core_cfg = config.get('general', 'core_cfg') self.core = core.Core(core_cfg) except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except blacklist.ConfigError as e: raise InternalError("Blacklist error: %s" % str(e)) except core.ConfigError as e: raise InternalError("Core error: %s" % str(e)) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting Twitter logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) self.log = log
def __init__(self, cfg=None): """Create new object by reading a configuration file. :param: cfg (string) the path of the configuration file. """ # define a set of default values default_cfg = 'xmpp.cfg' config = ConfigParser.ConfigParser() if cfg is None or not os.path.isfile(cfg): cfg = default_cfg try: with open(cfg) as f: config.readfp(f) except IOError: raise ConfigError("File %s not found!" % cfg) try: self.user = config.get('account', 'user') self.password = config.get('account', 'password') self.mirrors = config.get('general', 'mirrors') self.max_words = config.get('general', 'max_words') self.max_words = int(self.max_words) core_cfg = config.get('general', 'core_cfg') self.core = core.Core(core_cfg) self.i18ndir = config.get('i18n', 'dir') blacklist_cfg = config.get('blacklist', 'cfg') self.bl = blacklist.Blacklist(blacklist_cfg) self.bl_max_req = config.get('blacklist', 'max_requests') self.bl_max_req = int(self.bl_max_req) self.bl_wait_time = config.get('blacklist', 'wait_time') self.bl_wait_time = int(self.bl_wait_time) logdir = config.get('log', 'dir') logfile = os.path.join(logdir, 'xmpp.log') loglevel = config.get('log', 'level') except ConfigParser.Error as e: raise ConfigError("Configuration error: %s" % str(e)) except blacklist.ConfigError as e: raise InternalError("Blacklist error: %s" % str(e)) except core.ConfigError as e: raise InternalError("Core error: %s" % str(e)) # logging log = logging.getLogger(__name__) logging_format = utils.get_logging_format() date_format = utils.get_date_format() formatter = logging.Formatter(logging_format, date_format) log.info('Redirecting XMPP logging to %s' % logfile) logfileh = logging.FileHandler(logfile, mode='a+') logfileh.setFormatter(formatter) logfileh.setLevel(logging.getLevelName(loglevel)) log.addHandler(logfileh) # stop logging on stdout from now on log.propagate = False self.log = log
"--ip", help="Select the ip on which the DNS server is to be active") argp.add_argument( "-p", "--port", type=int, help="Select the port number on which the DNS server is to be active") argp.add_argument( "-bl", "--blacklist", help="Select the file from which the blacklist is to be read") args = argp.parse_args() if args.ip == None: ip = "localhost" else: ip = args.ip if args.port == None: port = 53 else: port = args.port if args.blacklist == None: blackfile = "blacklist.txt" else: blackfile = args.blacklist B = blacklist.Blacklist(blackfile) DNSGuard(ip, port, B) pass