Made configurable.

This commit is contained in:
Jeremy Fincher 2003-12-10 06:58:17 +00:00
parent 5980afc86f
commit 9678560c98
2 changed files with 48 additions and 9 deletions

View File

@ -37,23 +37,43 @@ __revision__ = "$Id$"
import plugins import plugins
import irclib
import ircmsgs import ircmsgs
import ircutils import ircutils
import callbacks
import configurable
### ###
# RootWarner: Warns users who join a channel as root. # 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): def doJoin(self, irc, msg):
user = ircutils.userFromHostmask(msg.prefix) user = ircutils.userFromHostmask(msg.prefix)
if user == 'root' or user == '~root': if user == 'root' or user == '~root':
irc.queueMsg(ircmsgs.privmsg(msg.nick, channel = msg.args[0]
'Don\'t IRC as root -- it\'s very possible that there is a '\ s = self.configurables.get('warning', channel)
'security flaw in latent in your irc client (remember the '\ if self.configurables.get('warn', channel):
'BitchX format string vulnerabilities of days past?) and if '\ irc.queueMsg(ircmsgs.privmsg(msg.nick, s))
'you\'re IRCing as root, your entire box could be compromised.')) if self.configurables.get('kick', channel):
irc.queueMsg(ircmsgs.kick(channel, msg.nick, s))
Class = RootWarner Class = RootWarner
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -33,7 +33,6 @@ from testsupport import *
class RootWarnerTestCase(PluginTestCase): class RootWarnerTestCase(PluginTestCase):
plugins = ('RootWarner',) plugins = ('RootWarner',)
def test(self): def test(self):
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host')) self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host'))
self.assertNotError(' ') self.assertNotError(' ')
@ -42,6 +41,26 @@ class RootWarnerTestCase(PluginTestCase):
self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!~foo@host')) self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!~foo@host'))
self.assertNoResponse(' ', 1) 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: