mirror of
				https://github.com/Mikaela/Limnoria.git
				synced 2025-10-30 23:27:24 +01:00 
			
		
		
		
	Converted to use the new registry dealio.
This commit is contained in:
		
							parent
							
								
									e9b8c406d9
								
							
						
					
					
						commit
						bb92d8e40b
					
				| @ -37,42 +37,37 @@ __revision__ = "$Id$" | ||||
| 
 | ||||
| import plugins | ||||
| 
 | ||||
| import conf | ||||
| import ircmsgs | ||||
| import ircutils | ||||
| import registry | ||||
| import callbacks | ||||
| import configurable | ||||
| 
 | ||||
| ### | ||||
| # RootWarner: Warns users who join a channel as root. | ||||
| ### | ||||
| 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) | ||||
| 
 | ||||
| conf.registerPlugin('RootWarner') | ||||
| conf.registerChannelValue(conf.supybot.plugins.RootWarner, 'warn', | ||||
|     registry.Boolean(True, """Determines whether the bot will warn people who | ||||
|     join the channel with an ident of 'root' or '~root'.""")) | ||||
| conf.registerChannelValue(conf.supybot.plugins.RootWarner, 'warning', | ||||
|     registry.NormalizedString("""Don't IRC as root -- it's very possible that | ||||
|     there's 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.""", """Determines the message that is | ||||
|     to be sent to users joining the channel with an ident of 'root' or '~root'. | ||||
|     """)) | ||||
| conf.registerChannelValue(conf.supybot.plugins.RootWarner, 'kick', | ||||
|     registry.Boolean(False, """Determines whether the bot will kick people who | ||||
|     join the channel with an ident of 'root' or '~root'.""")) | ||||
| class RootWarner(callbacks.Privmsg): | ||||
|     def doJoin(self, irc, msg): | ||||
|         user = ircutils.userFromHostmask(msg.prefix) | ||||
|         if user == 'root' or user == '~root': | ||||
|             channel = msg.args[0] | ||||
|             s = self.configurables.get('warning', channel) | ||||
|             if self.configurables.get('warn', channel): | ||||
|             s = self.registryValue('warning', channel) | ||||
|             if self.registryValue('warn', channel): | ||||
|                 irc.queueMsg(ircmsgs.privmsg(msg.nick, s)) | ||||
|             if self.configurables.get('kick', channel): | ||||
|             if self.registryValue('kick', channel): | ||||
|                 irc.queueMsg(ircmsgs.kick(channel, msg.nick, s)) | ||||
| 
 | ||||
| Class = RootWarner | ||||
|  | ||||
| @ -44,18 +44,26 @@ class RootWarnerTestCase(PluginTestCase): | ||||
|     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) | ||||
|         try: | ||||
|             conf.supybot.plugins.RootWarner.warn.setValue(False) | ||||
|             self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host')) | ||||
|             self.assertNoResponse(' ', 1) | ||||
|         finally: | ||||
|             conf.supybot.plugins.RootWarner.warn.setValue(True) | ||||
| 
 | ||||
|     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') | ||||
|         try: | ||||
|             conf.supybot.plugins.RootWarner.warn.setValue(False) | ||||
|             conf.supybot.plugins.RootWarner.kick.setValue(True) | ||||
|             self.irc.feedMsg(ircmsgs.join('#foo', prefix='foo!root@host')) | ||||
|             m = self.getMsg(' ') | ||||
|             self.assertEqual(m.command, 'KICK') | ||||
|         finally: | ||||
|             conf.supybot.plugins.RootWarner.warn.setValue(True) | ||||
|             conf.supybot.plugins.RootWarner.kick.setValue(False) | ||||
|              | ||||
|          | ||||
|          | ||||
|          | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jeremy Fincher
						Jeremy Fincher