mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Made configurable.
This commit is contained in:
parent
5980afc86f
commit
9678560c98
@ -37,23 +37,43 @@ __revision__ = "$Id$"
|
||||
|
||||
import plugins
|
||||
|
||||
import irclib
|
||||
import ircmsgs
|
||||
import ircutils
|
||||
import callbacks
|
||||
import configurable
|
||||
|
||||
###
|
||||
# RootWarner: Warns users who join a channel as root.
|
||||
###
|
||||
class RootWarner(irclib.IrcCallback):
|
||||
class RootWarner(callbacks.Privmsg, configurable.Mixin):
|
||||
configurables = configurable.Dictionary(
|
||||
[('warn', configurable.BoolType, True,
|
||||
"""Determines whether the bot will warn people who join the channel
|
||||
with an ident of 'root' or '~root'."""),
|
||||
('warning', configurable.StrType,
|
||||
'Don\'t IRC as root -- it\'s very possible that there is a '
|
||||
'security flaw latent in your irc client (remember the BitchX '
|
||||
'format string vulnerabilities of days past?) and if you\'re '
|
||||
'IRCing as root, your entire box could be compromised.',
|
||||
"""The message that is to be sent to users joining the channel with
|
||||
an ident of 'root' or '~root'."""),
|
||||
('kick', configurable.BoolType, False,
|
||||
"""Determines whether the bot will kick people who join the channel
|
||||
with an ident of 'root' or '~root'.""")]
|
||||
)
|
||||
def __init__(self):
|
||||
callbacks.Privmsg.__init__(self)
|
||||
configurable.Mixin.__init__(self)
|
||||
|
||||
def doJoin(self, irc, msg):
|
||||
user = ircutils.userFromHostmask(msg.prefix)
|
||||
if user == 'root' or user == '~root':
|
||||
irc.queueMsg(ircmsgs.privmsg(msg.nick,
|
||||
'Don\'t IRC as root -- it\'s very possible that there is a '\
|
||||
'security flaw in latent in your irc client (remember the '\
|
||||
'BitchX format string vulnerabilities of days past?) and if '\
|
||||
'you\'re IRCing as root, your entire box could be compromised.'))
|
||||
|
||||
channel = msg.args[0]
|
||||
s = self.configurables.get('warning', channel)
|
||||
if self.configurables.get('warn', channel):
|
||||
irc.queueMsg(ircmsgs.privmsg(msg.nick, s))
|
||||
if self.configurables.get('kick', channel):
|
||||
irc.queueMsg(ircmsgs.kick(channel, msg.nick, s))
|
||||
|
||||
Class = RootWarner
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
@ -33,7 +33,6 @@ from testsupport import *
|
||||
|
||||
class RootWarnerTestCase(PluginTestCase):
|
||||
plugins = ('RootWarner',)
|
||||
|
||||
def test(self):
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
|
||||
self.assertNotError(' ')
|
||||
@ -42,6 +41,26 @@ class RootWarnerTestCase(PluginTestCase):
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!~foo@host'))
|
||||
self.assertNoResponse(' ', 1)
|
||||
|
||||
def testConfigWarn(self):
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
|
||||
self.assertNotError(' ')
|
||||
self.assertNotError('config #foo warn off')
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
|
||||
self.assertNoResponse(' ', 1)
|
||||
|
||||
def testConfigKick(self):
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
|
||||
self.assertNotError(' ')
|
||||
self.assertNotError('config #foo warn off')
|
||||
self.assertNotError('config #foo kick on')
|
||||
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
|
||||
m = self.getMsg(' ')
|
||||
self.assertEqual(m.command, 'KICK')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user