def do_tempban(self, client, duration=2, reason=None): # sm_addban <time> <steamid> [reason] if reason: self.output.write('sm_addban %s "%s" %s' % (int(time2minutes(duration)), client.guid, reason)) else: self.output.write('sm_addban %s "%s"' % (int(time2minutes(duration)), client.guid)) self.do_kick(client, reason)
def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData(type = penalty.get('type'), reason = penalty.get('reason'), keyword = penalty.get('reasonkeyword'), duration = functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData(type = penalty.get('type'), reason = penalty.get('reason'), keyword = penalty.get('reasonkeyword'), duration = functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badWords.append(self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadWordPenalty)) if word != None: # has a plain word self._badWords.append(self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadWordPenalty)) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badNames.append(self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadNamePenalty)) if word != None: # has a plain word self._badNames.append(self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadNamePenalty))
def do_tempban(self, client, duration=2, reason=None): """ Tempban a client. :param client: The client to tempban :param duration: The tempban duration :param reason: The reason for the tempban """ # sm_addban <time> <steamid> [reason] if reason: self.output.write('sm_addban %s "%s" %s' % (int(time2minutes(duration)), client.guid, reason)) else: self.output.write('sm_addban %s "%s"' % (int(time2minutes(duration)), client.guid)) self.do_kick(client, reason)
def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_word( rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_name( rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None)
def getWarning(self, warning): if not warning: warning = 'default' try: w = self.config.getTextTemplate('warn_reasons', warning) if w[:1] == '/': w = self.config.getTextTemplate('warn_reasons', w[1:]) if w[:1] == '/': self.error('getWarning: Possible warning recursion %s, %s', warning, w) return None expire, warning = w.split(',', 1) warning = warning.strip() if warning[:6] == '/spam#': warning = self.getSpam(warning[6:]) return (functions.time2minutes(expire.strip()), warning) except ConfigParser.NoOptionError: return None except Exception, msg: self.error('getWarning: Could not get warning "%s": %s\n%s', warning, msg, traceback.extract_tb(sys.exc_info()[2])) return None
def do_tempban(self, client, duration=2, reason=None): # kickban <steamid> reason <days> days = float(time2minutes(duration)) / 1440.0 if reason: self.output.write('kickban %s "%s" %s' % (client.guid, reason, days)) else: self.output.write('kickban %s "%s"' % (client.guid, days))
def onLoadConfig(self): try: self.logLocation = self.config.get('settings', 'log_location') if self.logLocation: self.logLocation = b3.getAbsolutePath(self.logLocation) elif not self.logLocation: self.verbose('Log disabled in config') except: self.logLocation = None try: self.maxnames = self.config.getint('settings', 'maxnames') except: self.maxnames = 5 self.debug('No Config Value Set. Using Default Max Names of 5.') try: self.action = self.config.get('settings', 'action') except: self.action = 'kick' self.debug('No Config Value Set. Using Kick As Default Action') if self.action == 'tempban': try: self.duration = self.config.get('settings', 'tempban_duration') self.duration = functions.time2minutes(self.duration) self.debug('Tempban duration set to %s' % self.duration) except: self.duration = functions.time2minutes('2h') self.debug('No Config Value set for tempban_duration, using 2 hours') try: self.ignoreLevel = self.config.getint('settings', 'ignore_level') except: self.ignoreLevel = 100 self.debug('No Config Value Set. Only superadmin is ignored') try: self.notify = self.config.getint('settings', 'notify') except: self.notify = None self.debug('Notifications disabled in config.') if self.config.has_section('messages'): for (penalty, message) in self.config.items('messages'): self._default_messages[penalty] = message
def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData(type = penalty.get('type'), reason = penalty.get('reason'), keyword = penalty.get('reasonkeyword'), duration = functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData(type = penalty.get('type'), reason = penalty.get('reason'), keyword = penalty.get('reasonkeyword'), duration = functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_word(rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_name(rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None)
def test_str_s(self): self.assertEqual(functions.time2minutes('0 s'), 0) self.assertEqual(functions.time2minutes('0 s'), 0) self.assertEqual(functions.time2minutes('60s'), 1) self.assertEqual(functions.time2minutes('120s'), 2) self.assertEqual(functions.time2minutes('5s'), 5.0 / 60) self.assertEqual(functions.time2minutes('90s'), 1.5)
def test_str_w(self): self.assertEqual(functions.time2minutes('0 w'), 0) self.assertEqual(functions.time2minutes('0 w'), 0) self.assertEqual(functions.time2minutes('60w'), 60*7*24*60) self.assertEqual(functions.time2minutes('120w'), 120*7*24*60) self.assertEqual(functions.time2minutes('5w'), 5*7*24*60) self.assertEqual(functions.time2minutes('90w'), 90*7*24*60)
def test_str_d(self): self.assertEqual(functions.time2minutes('0 d'), 0) self.assertEqual(functions.time2minutes('0 d'), 0) self.assertEqual(functions.time2minutes('60d'), 60*24*60) self.assertEqual(functions.time2minutes('120d'), 120*24*60) self.assertEqual(functions.time2minutes('5d'), 5*24*60) self.assertEqual(functions.time2minutes('90d'), 90*24*60)
def test_str_s(self): self.assertEqual(functions.time2minutes('0 s'), 0) self.assertEqual(functions.time2minutes('0 s'), 0) self.assertEqual(functions.time2minutes('60s'), 1) self.assertEqual(functions.time2minutes('120s'), 2) self.assertEqual(functions.time2minutes('5s'), 5.0/60) self.assertEqual(functions.time2minutes('90s'), 1.5)
def test_str_d(self): self.assertEqual(functions.time2minutes('0 d'), 0) self.assertEqual(functions.time2minutes('0 d'), 0) self.assertEqual(functions.time2minutes('60d'), 60 * 24 * 60) self.assertEqual(functions.time2minutes('120d'), 120 * 24 * 60) self.assertEqual(functions.time2minutes('5d'), 5 * 24 * 60) self.assertEqual(functions.time2minutes('90d'), 90 * 24 * 60)
def test_str_w(self): self.assertEqual(functions.time2minutes('0 w'), 0) self.assertEqual(functions.time2minutes('0 w'), 0) self.assertEqual(functions.time2minutes('60w'), 60 * 7 * 24 * 60) self.assertEqual(functions.time2minutes('120w'), 120 * 7 * 24 * 60) self.assertEqual(functions.time2minutes('5w'), 5 * 7 * 24 * 60) self.assertEqual(functions.time2minutes('90w'), 90 * 7 * 24 * 60)
def test_str_s(self): self.assertEqual(functions.time2minutes("0 s"), 0) self.assertEqual(functions.time2minutes("0 s"), 0) self.assertEqual(functions.time2minutes("60s"), 1) self.assertEqual(functions.time2minutes("120s"), 2) self.assertEqual(functions.time2minutes("5s"), 5.0 / 60) self.assertEqual(functions.time2minutes("90s"), 1.5)
def test_str_w(self): self.assertEqual(functions.time2minutes("0 w"), 0) self.assertEqual(functions.time2minutes("0 w"), 0) self.assertEqual(functions.time2minutes("60w"), 60 * 7 * 24 * 60) self.assertEqual(functions.time2minutes("120w"), 120 * 7 * 24 * 60) self.assertEqual(functions.time2minutes("5w"), 5 * 7 * 24 * 60) self.assertEqual(functions.time2minutes("90w"), 90 * 7 * 24 * 60)
def test_str_d(self): self.assertEqual(functions.time2minutes("0 d"), 0) self.assertEqual(functions.time2minutes("0 d"), 0) self.assertEqual(functions.time2minutes("60d"), 60 * 24 * 60) self.assertEqual(functions.time2minutes("120d"), 120 * 24 * 60) self.assertEqual(functions.time2minutes("5d"), 5 * 24 * 60) self.assertEqual(functions.time2minutes("90d"), 90 * 24 * 60)
def tempban(self, client, reason='', duration=2, admin=None, silent=False, *kwargs): duration = time2minutes(duration) if isinstance(client, Client) and not client.guid: # client has no guid, kick instead return self.kick(client, reason, admin, silent) elif isinstance(client, str) and re.match('^[0-9]+$', client): self.write(self.getCommand('tempban', cid=client, reason=reason)) return elif admin: fullreason = self.getMessage('temp_banned_by', self.getMessageVariables(client=client, reason=reason, admin=admin, banduration=b3.functions.minutesStr(duration))) else: fullreason = self.getMessage('temp_banned', self.getMessageVariables(client=client, reason=reason, banduration=b3.functions.minutesStr(duration))) if self._tempban_with_frozensand: minutes = duration days = hours = 0 while minutes >= 60: hours += 1 minutes -= 60 while hours >= 24: days += 1 hours -= 24 cmd = self.getCommand('auth-tempban', cid=client.cid, days=days, hours=hours, minutes=int(minutes)) self.info('sending ban to Frozen Sand : %s' % cmd) rv = self.write(cmd) if rv: if rv == "Auth services disabled" or rv.startswith("auth: not banlist available."): self.warning(rv) elif rv.startswith("auth: sending ban"): self.info(rv) time.sleep(.250) else: self.warning(rv) time.sleep(.250) if client.connected: cmd = self.getCommand('tempban', cid=client.cid, reason=reason) self.info('sending ban to server : %s' % cmd) rv = self.write(cmd) if rv: self.info(rv) if not silent and fullreason != '': self.say(fullreason) self.queueEvent(b3.events.Event(b3.events.EVT_CLIENT_BAN_TEMP, {'reason': reason, 'duration': duration, 'admin': admin} , client)) client.disconnect()
def _get_censor_data(self, name, regexp, penalty, default): try: regexp = re.compile(regexp, re.IGNORECASE) except re.error: self.error('invalid regular expression: %s - %s' % (name, regexp)) raise if penalty is not None: pd = PenaltyData(type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) else: pd = default return CensorData(name=name, penalty=pd, regexp=regexp)
def penalizeClient(self, type, client, reason, keyword=None, duration=0, admin=None, data=''): if reason == None: reason = self.getReason(keyword) duration = functions.time2minutes(duration) if type == self.PENALTY_KICK: client.kick(reason, keyword, admin, False, data) elif type == self.PENALTY_TEMPBAN: client.tempban(reason, keyword, duration, admin, False, data) elif type == self.PENALTY_BAN: client.ban(reason, keyword, admin, False, data) elif type == self.PENALTY_WARNING: self.warnClient(client, keyword, admin, True, data, duration) else: if self.console.inflictCustomPenalty(type, client=client, reason=reason, duration=duration, admin=admin, data=data) is not True: self.error('penalizeClient(): type %s not found', type)
def inflictCustomPenalty(self, type, client, reason=None, duration=None, admin=None, data=None): if type == 'slap' and client: cmd = self.getCommand('slap', cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == 'nuke' and client: cmd = self.getCommand('nuke', cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == 'mute' and client: if duration is None: seconds = 60 else: seconds = round(float(time2minutes(duration) * 60), 0) # make sure to unmute first cmd = self.getCommand('mute', cid=client.cid, seconds=0) self.write(cmd) # then mute cmd = self.getCommand('mute', cid=client.cid, seconds=seconds) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == 'kill' and client: cmd = self.getCommand('kill', cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True
def inflictCustomPenalty(self, type, client, reason=None, duration=None, admin=None, data=None): if type == "slap" and client: cmd = self.getCommand("slap", cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == "nuke" and client: cmd = self.getCommand("nuke", cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == "mute" and client: if duration is None: seconds = 60 else: seconds = round(float(time2minutes(duration) * 60), 0) # make sure to unmute first cmd = self.getCommand("mute", cid=client.cid, seconds=0) self.write(cmd) # then mute cmd = self.getCommand("mute", cid=client.cid, seconds=seconds) self.write(cmd) if reason: client.message("%s" % reason) return True elif type == "kill" and client: cmd = self.getCommand("kill", cid=client.cid) self.write(cmd) if reason: client.message("%s" % reason) return True
class CensorPlugin(b3.plugin.Plugin): _adminPlugin = None _reClean = re.compile(r'[^0-9a-z ]+', re.I) _defaultBadWordPenalty = None _defaultBadNamePenalty = None _maxLevel = 0 _ignoreLength = 3 def onStartup(self): self._adminPlugin = self.console.getPlugin('admin') if not self._adminPlugin: return False self.registerEvent(b3.events.EVT_CLIENT_SAY) self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY) self.registerEvent(b3.events.EVT_CLIENT_NAME_CHANGE) self.registerEvent(b3.events.EVT_CLIENT_AUTH) def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badWords.append( self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadWordPenalty)) if word != None: # has a plain word self._badWords.append( self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadWordPenalty)) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badNames.append( self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadNamePenalty)) if word != None: # has a plain word self._badNames.append( self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadNamePenalty)) def _getCensorData(self, name, regexp, penalty, defaultPenalty): try: regexp = re.compile(regexp, re.I) except re.error, e: self.error('Invalid regular expression: %s - %s' % (name, regexp)) raise if penalty is not None: pd = PenaltyData(type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes( penalty.get('duration'))) else: pd = defaultPenalty return CensorData(penalty=pd, regexp=regexp)
def onLoadConfig(self): """ Load plugin configuration. """ assert isinstance(self.config, XmlConfigParser) try: self._maxLevel = self.config.getint('settings', 'max_level') self.debug('loaded settings/max_level: %s' % self._maxLevel) except NoOptionError: self.warning('could not find settings/max_level in config file, ' 'using default: %s' % self._maxLevel) except ValueError as e: self.error('could not load settings/max_level config value: %s' % e) self.debug('using default value (%s) for settings/max_level' % self._maxLevel) try: self._ignoreLength = self.config.getint('settings', 'ignore_length') self.debug('loaded settings/ignore_length: %s' % self._ignoreLength) except NoOptionError: self.warning('could not find settings/ignore_length in config file, ' 'using default: %s' % self._ignoreLength) except ValueError as e: self.error('could not load settings/ignore_length config value: %s' % e) self.debug('using default value (%s) for settings/ignore_length' % self._ignoreLength) default_badwords_penalty_nodes = self.config.get('badwords/penalty') if len(default_badwords_penalty_nodes): penalty = default_badwords_penalty_nodes[0] self._defaultBadWordPenalty = PenaltyData(type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) else: self.warning('no default badwords penalty found in configuration file: ' 'using default (%s)' % self._defaultBadNamePenalty) default_badnames_penalty_nodes = self.config.get('badnames/penalty') if len(default_badnames_penalty_nodes): penalty = default_badnames_penalty_nodes[0] self._defaultBadNamePenalty = PenaltyData(type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) else: self.warning('no default badnames penalty found in configuration file: ' 'using default (%s)' % self._defaultBadNamePenalty) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_word(rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_name(rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None)
def onLoadConfig(self): try: self._maxLevel = self.config.getint("settings", "max_level") except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint("settings", "ignore_length") except: self._ignoreLength = 3 penalty = self.config.get("badwords/penalty")[0] self._defaultBadWordPenalty = PenaltyData( type=penalty.get("type"), reason=penalty.get("reason"), keyword=penalty.get("reasonkeyword"), duration=functions.time2minutes(penalty.get("duration")), ) penalty = self.config.get("badnames/penalty")[0] self._defaultBadNamePenalty = PenaltyData( type=penalty.get("type"), reason=penalty.get("reason"), keyword=penalty.get("reasonkeyword"), duration=functions.time2minutes(penalty.get("duration")), ) # load bad words into memory self._badWords = [] for e in self.config.get("badwords/badword"): regexp = e.find("regexp") word = e.find("word") penalty = e.find("penalty") if regexp != None: # has a regular expression self._badWords.append( self._getCensorData(e.get("name"), regexp.text.strip(), penalty, self._defaultBadWordPenalty) ) if word != None: # has a plain word self._badWords.append( self._getCensorData( e.get("name"), "\\s" + word.text.strip() + "\\s", penalty, self._defaultBadWordPenalty ) ) # load bad names into memory self._badNames = [] for e in self.config.get("badnames/badname"): regexp = e.find("regexp") word = e.find("word") penalty = e.find("penalty") if regexp != None: # has a regular expression self._badNames.append( self._getCensorData(e.get("name"), regexp.text.strip(), penalty, self._defaultBadNamePenalty) ) if word != None: # has a plain word self._badNames.append( self._getCensorData( e.get("name"), "\\s" + word.text.strip() + "\\s", penalty, self._defaultBadNamePenalty ) )
def test_str_m(self): self.assertEqual(functions.time2minutes("145m"), 145) self.assertEqual(functions.time2minutes("0 m"), 0) self.assertEqual(functions.time2minutes("0 m"), 0) self.assertEqual(functions.time2minutes("5m"), 5)
self.info('"bad guid" penalty : %s' % self.bad_guid_penalty) try: penalty = self.config.get('settings', '1337_port_penalty') if penalty not in PENALTIES: raise HaxbusterurtConfigError("bad penalty keyword for 1337_port_penalty. Using default instead. Expecting on of \"%s\"" % ', '.join(PENALTIES.keys())) else: self.port_1337_penalty = penalty.lower() except Exception, err: self.warning(err) self.port_1337_penalty = PENALTY_DEFAULT self.info('1337 port penalty : %s' % self.port_1337_penalty) try: duration = self.config.get('settings', 'tempban_duration') duration_minutes = time2minutes(duration) if duration_minutes <= 0: raise HaxbusterurtConfigError("bad value for tempban_duration \"%s\"" % duration) self.tempban_duration = duration_minutes except Exception, err: self.warning(err) self.info('tempban duration : %s' % minutesStr(self.tempban_duration)) def enable(self): b3.plugin.Plugin.enable(self) self.checkAllClients() def onEvent(self, event): if not event.client:
try: penalty = self.config.get('settings', '1337_port_penalty') if penalty not in PENALTIES: raise HaxbusterurtConfigError( "bad penalty keyword for 1337_port_penalty. Using default instead. Expecting on of \"%s\"" % ', '.join(PENALTIES.keys())) else: self.port_1337_penalty = penalty.lower() except Exception, err: self.warning(err) self.port_1337_penalty = PENALTY_DEFAULT self.info('1337 port penalty : %s' % self.port_1337_penalty) try: duration = self.config.get('settings', 'tempban_duration') duration_minutes = time2minutes(duration) if duration_minutes <= 0: raise HaxbusterurtConfigError( "bad value for tempban_duration \"%s\"" % duration) self.tempban_duration = duration_minutes except Exception, err: self.warning(err) self.info('tempban duration : %s' % minutesStr(self.tempban_duration)) def enable(self): b3.plugin.Plugin.enable(self) self.checkAllClients() def onEvent(self, event): if not event.client: return
def test_str(self): self.assertEqual(functions.time2minutes(''), 0)
def test_None(self): self.assertEqual(functions.time2minutes(None), 0)
def test_int(self): self.assertEqual(functions.time2minutes(0), 0) self.assertEqual(functions.time2minutes(1), 1) self.assertEqual(functions.time2minutes(154), 154)
def test_str_m(self): self.assertEqual(functions.time2minutes('145m'), 145) self.assertEqual(functions.time2minutes('0 m'), 0) self.assertEqual(functions.time2minutes('0 m'), 0) self.assertEqual(functions.time2minutes('5m'), 5)
def test_str_h(self): self.assertEqual(functions.time2minutes('145h'), 145*60) self.assertEqual(functions.time2minutes('0 h'), 0) self.assertEqual(functions.time2minutes('0 h'), 0) self.assertEqual(functions.time2minutes('5h'), 5*60)
class CensorPlugin(b3.plugin.Plugin): _adminPlugin = None _reClean = re.compile(r'[^0-9a-z ]+', re.I) _defaultBadWordPenalty = None _defaultBadNamePenalty = None _maxLevel = 0 _ignoreLength = 3 def onStartup(self): self._adminPlugin = self.console.getPlugin('admin') if not self._adminPlugin: return False self.registerEvent(b3.events.EVT_CLIENT_SAY) self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY) self.registerEvent(b3.events.EVT_CLIENT_NAME_CHANGE) self.registerEvent(b3.events.EVT_CLIENT_AUTH) def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_word( rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): penalty_node = e.find('penalty') word_node = e.find('word') regexp_node = e.find('regexp') self._add_bad_name( rulename=e.get('name'), penalty=penalty_node, word=word_node.text if word_node is not None else None, regexp=regexp_node.text if regexp_node is not None else None) def _add_bad_word(self, rulename, penalty=None, word=None, regexp=None): if word is regexp is None: self.warning( "badword rule [%s] has no word and no regular expression to search for" % rulename) elif word is not None and regexp is not None: self.warning( "badword rule [%s] cannot have both a word and regular expression to search for" % rulename) elif regexp is not None: # has a regular expression self._badWords.append( self._getCensorData(rulename, regexp.strip(), penalty, self._defaultBadWordPenalty)) self.debug("badword rule '%s' loaded" % rulename) elif word is not None: # has a plain word self._badWords.append( self._getCensorData(rulename, '\\s' + word.strip() + '\\s', penalty, self._defaultBadWordPenalty)) self.debug("badword rule '%s' loaded" % rulename) def _add_bad_name(self, rulename, penalty=None, word=None, regexp=None): if word is regexp is None: self.warning( "badname rule [%s] has no word and no regular expression to search for" % rulename) elif word is not None and regexp is not None: self.warning( "badname rule [%s] cannot have both a word and regular expression to search for" % rulename) elif regexp is not None: # has a regular expression self._badNames.append( self._getCensorData(rulename, regexp.strip(), penalty, self._defaultBadNamePenalty)) self.debug("badname rule '%s' loaded" % rulename) elif word is not None: # has a plain word self._badNames.append( self._getCensorData(rulename, '\\s' + word.strip() + '\\s', penalty, self._defaultBadNamePenalty)) self.debug("badname rule '%s' loaded" % rulename) def _getCensorData(self, name, regexp, penalty, defaultPenalty): try: regexp = re.compile(regexp, re.I) except re.error, e: self.error('Invalid regular expression: %s - %s' % (name, regexp)) raise if penalty is not None: pd = PenaltyData(type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes( penalty.get('duration'))) else: pd = defaultPenalty return CensorData(name=name, penalty=pd, regexp=regexp)
def test_str_h(self): self.assertEqual(functions.time2minutes('145h'), 145 * 60) self.assertEqual(functions.time2minutes('0 h'), 0) self.assertEqual(functions.time2minutes('0 h'), 0) self.assertEqual(functions.time2minutes('5h'), 5 * 60)
def onLoadConfig(self): try: self._maxLevel = self.config.getint('settings', 'max_level') except: self._maxLevel = 0 try: self._ignoreLength = self.config.getint('settings', 'ignore_length') except: self._ignoreLength = 3 penalty = self.config.get('badwords/penalty')[0] self._defaultBadWordPenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) penalty = self.config.get('badnames/penalty')[0] self._defaultBadNamePenalty = PenaltyData( type=penalty.get('type'), reason=penalty.get('reason'), keyword=penalty.get('reasonkeyword'), duration=functions.time2minutes(penalty.get('duration'))) # load bad words into memory self._badWords = [] for e in self.config.get('badwords/badword'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badWords.append( self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadWordPenalty)) if word != None: # has a plain word self._badWords.append( self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadWordPenalty)) # load bad names into memory self._badNames = [] for e in self.config.get('badnames/badname'): regexp = e.find('regexp') word = e.find('word') penalty = e.find('penalty') if regexp != None: # has a regular expression self._badNames.append( self._getCensorData(e.get('name'), regexp.text.strip(), penalty, self._defaultBadNamePenalty)) if word != None: # has a plain word self._badNames.append( self._getCensorData(e.get('name'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadNamePenalty))
def test_str(self): self.assertEqual(functions.time2minutes(""), 0)
def tempban(self, client, reason='', duration=2, admin=None, silent=False, *kwargs): duration = time2minutes(duration) if isinstance(client, Client) and not client.guid: # client has no guid, kick instead return self.kick(client, reason, admin, silent) elif isinstance(client, str) and re.match('^[0-9]+$', client): self.write(self.getCommand('tempban', cid=client, reason=reason)) return elif admin: fullreason = self.getMessage( 'temp_banned_by', self.getMessageVariables( client=client, reason=reason, admin=admin, banduration=b3.functions.minutesStr(duration))) else: fullreason = self.getMessage( 'temp_banned', self.getMessageVariables( client=client, reason=reason, banduration=b3.functions.minutesStr(duration))) if self._tempban_with_frozensand: minutes = duration days = hours = 0 while minutes >= 60: hours += 1 minutes -= 60 while hours >= 24: days += 1 hours -= 24 cmd = self.getCommand('auth-tempban', cid=client.cid, days=days, hours=hours, minutes=int(minutes)) self.info('sending ban to Frozen Sand : %s' % cmd) rv = self.write(cmd) if rv: if rv == "Auth services disabled" or rv.startswith( "auth: not banlist available."): self.warning(rv) elif rv.startswith("auth: sending ban"): self.info(rv) time.sleep(.250) else: self.warning(rv) time.sleep(.250) if client.connected: cmd = self.getCommand('tempban', cid=client.cid, reason=reason) self.info('sending ban to server : %s' % cmd) rv = self.write(cmd) if rv: self.info(rv) if not silent and fullreason != '': self.say(fullreason) self.queueEvent( b3.events.Event(b3.events.EVT_CLIENT_BAN_TEMP, { 'reason': reason, 'duration': duration, 'admin': admin }, client)) client.disconnect()
def test_str_h(self): self.assertEqual(functions.time2minutes("145h"), 145 * 60) self.assertEqual(functions.time2minutes("0 h"), 0) self.assertEqual(functions.time2minutes("0 h"), 0) self.assertEqual(functions.time2minutes("5h"), 5 * 60)