def testWhois(self): user = wFD(self._loggedInUser(u'someguy')) yield user user = user.getResult() otherguy = service.User("otherguy") otherguy.itergroups = lambda: iter( [service.Group('groupA'), service.Group('groupB')]) otherguy.signOn = 10 otherguy.lastMessage = time.time() - 15 add = wFD(self.realm.addUser(otherguy)) yield add add.getResult() user.transport.clear() user.write('WHOIS otherguy\r\n') r = self._response(user) self.assertEqual(len(r), 5) wuser, wserver, idle, channels, end = r self.assertEqual(wuser[0], 'realmname') self.assertEqual(wuser[1], '311') self.assertEqual(wuser[2][0], 'someguy') self.assertEqual(wuser[2][1], 'otherguy') self.assertEqual(wuser[2][2], 'otherguy') self.assertEqual(wuser[2][3], 'realmname') self.assertEqual(wuser[2][4], '*') self.assertEqual(wuser[2][5], 'otherguy') self.assertEqual(wserver[0], 'realmname') self.assertEqual(wserver[1], '312') self.assertEqual(wserver[2][0], 'someguy') self.assertEqual(wserver[2][1], 'otherguy') self.assertEqual(wserver[2][2], 'realmname') self.assertEqual(wserver[2][3], 'Hi mom!') self.assertEqual(idle[0], 'realmname') self.assertEqual(idle[1], '317') self.assertEqual(idle[2][0], 'someguy') self.assertEqual(idle[2][1], 'otherguy') self.assertEqual(idle[2][2], '15') self.assertEqual(idle[2][3], '10') self.assertEqual(idle[2][4], "seconds idle, signon time") self.assertEqual(channels[0], 'realmname') self.assertEqual(channels[1], '319') self.assertEqual(channels[2][0], 'someguy') self.assertEqual(channels[2][1], 'otherguy') self.assertEqual(channels[2][2], '#groupA #groupB') self.assertEqual(end[0], 'realmname') self.assertEqual(end[1], '318') self.assertEqual(end[2][0], 'someguy') self.assertEqual(end[2][1], 'otherguy') self.assertEqual(end[2][2], 'End of WHOIS list.')
def testWhois(self): user = self._loggedInUser("someguy") otherguy = service.User("otherguy") otherguy.itergroups = lambda: iter( [service.Group("groupA"), service.Group("groupB")]) otherguy.signOn = 10 otherguy.lastMessage = time.time() - 15 self.successResultOf(self.realm.addUser(otherguy)) user.transport.clear() user.write("WHOIS otherguy\r\n") r = self._response(user) self.assertEqual(len(r), 5) wuser, wserver, idle, channels, end = r self.assertEqual(wuser[0], "realmname") self.assertEqual(wuser[1], "311") self.assertEqual(wuser[2][0], "someguy") self.assertEqual(wuser[2][1], "otherguy") self.assertEqual(wuser[2][2], "otherguy") self.assertEqual(wuser[2][3], "realmname") self.assertEqual(wuser[2][4], "*") self.assertEqual(wuser[2][5], "otherguy") self.assertEqual(wserver[0], "realmname") self.assertEqual(wserver[1], "312") self.assertEqual(wserver[2][0], "someguy") self.assertEqual(wserver[2][1], "otherguy") self.assertEqual(wserver[2][2], "realmname") self.assertEqual(wserver[2][3], "Hi mom!") self.assertEqual(idle[0], "realmname") self.assertEqual(idle[1], "317") self.assertEqual(idle[2][0], "someguy") self.assertEqual(idle[2][1], "otherguy") self.assertEqual(idle[2][2], "15") self.assertEqual(idle[2][3], "10") self.assertEqual(idle[2][4], "seconds idle, signon time") self.assertEqual(channels[0], "realmname") self.assertEqual(channels[1], "319") self.assertEqual(channels[2][0], "someguy") self.assertEqual(channels[2][1], "otherguy") self.assertEqual(channels[2][2], "#groupA #groupB") self.assertEqual(end[0], "realmname") self.assertEqual(end[1], "318") self.assertEqual(end[2][0], "someguy") self.assertEqual(end[2][1], "otherguy") self.assertEqual(end[2][2], "End of WHOIS list.")
def testGroupAddition(self): realm = service.InMemoryWordsRealm("realmname") p = service.Group("testgroup") self.successResultOf(realm.addGroup(p)) group = self.successResultOf(realm.getGroup("testGroup")) self.assertIdentical(p, group)
def testGetTopic(self): user = self._loggedInUser(u'useruser') group = service.Group("somechannel") group.meta["topic"] = "This is a test topic." group.meta["topic_author"] = "some_fellow" group.meta["topic_date"] = 77777777 self.successResultOf(self.realm.addGroup(group)) user.transport.clear() user.write("JOIN #somechannel\r\n") response = self._response(user) self.assertEqual(response[3][0], 'realmname') self.assertEqual(response[3][1], '332') # XXX Sigh. irc.parsemsg() is not as correct as one might hope. self.assertEqual(response[3][2], ['useruser', '#somechannel', 'This is a test topic.']) self.assertEqual(response[4][1], '333') self.assertEqual(response[4][2], ['useruser', '#somechannel', 'some_fellow', '77777777']) user.transport.clear() user.write('TOPIC #somechannel\r\n') response = self._response(user) self.assertEqual(response[0][1], '332') self.assertEqual(response[0][2], ['useruser', '#somechannel', 'This is a test topic.']) self.assertEqual(response[1][1], '333') self.assertEqual(response[1][2], ['useruser', '#somechannel', 'some_fellow', '77777777'])
def testGroupAddition(self): realm = service.InMemoryWordsRealm("realmname") p = service.Group("testgroup") d = wFD(realm.addGroup(p)) yield d d.getResult() d = wFD(realm.getGroup(u"testGroup")) yield d group = d.getResult() self.assertIdentical(p, group)
def testWho(self): group = service.Group("groupname") self.successResultOf(self.realm.addGroup(group)) users = [] for nick in "userone", "usertwo", "userthree": u = self._loggedInUser(nick) users.append(u) users[-1].write("JOIN #groupname\r\n") for user in users: user.transport.clear() users[0].write("WHO #groupname\r\n") r = self._response(users[0]) self.assertFalse(self._response(users[1])) self.assertFalse(self._response(users[2])) wantusers = ["userone", "usertwo", "userthree"] for (prefix, code, stuff) in r[:-1]: self.assertEqual(prefix, "realmname") self.assertEqual(code, "352") ( myname, group, theirname, theirhost, theirserver, theirnick, flag, extra, ) = stuff self.assertEqual(myname, "userone") self.assertEqual(group, "#groupname") self.assertTrue(theirname in wantusers) self.assertEqual(theirhost, "realmname") self.assertEqual(theirserver, "realmname") wantusers.remove(theirnick) self.assertEqual(flag, "H") self.assertEqual(extra, "0 " + theirnick) self.assertFalse(wantusers) prefix, code, stuff = r[-1] self.assertEqual(prefix, "realmname") self.assertEqual(code, "315") myname, channel, extra = stuff self.assertEqual(myname, "userone") self.assertEqual(channel, "#groupname") self.assertEqual(extra, "End of /WHO list.")
def testWho(self): group = service.Group('groupname') add = wFD(self.realm.addGroup(group)) yield add add.getResult() users = [] for nick in u'userone', u'usertwo', u'userthree': u = wFD(self._loggedInUser(nick)) yield u u = u.getResult() users.append(u) users[-1].write('JOIN #groupname\r\n') for user in users: user.transport.clear() users[0].write('WHO #groupname\r\n') r = self._response(users[0]) self.failIf(self._response(users[1])) self.failIf(self._response(users[2])) wantusers = ['userone', 'usertwo', 'userthree'] for (prefix, code, stuff) in r[:-1]: self.assertEqual(prefix, 'realmname') self.assertEqual(code, '352') (myname, group, theirname, theirhost, theirserver, theirnick, flag, extra) = stuff self.assertEqual(myname, 'userone') self.assertEqual(group, '#groupname') self.failUnless(theirname in wantusers) self.assertEqual(theirhost, 'realmname') self.assertEqual(theirserver, 'realmname') wantusers.remove(theirnick) self.assertEqual(flag, 'H') self.assertEqual(extra, '0 ' + theirnick) self.failIf(wantusers) prefix, code, stuff = r[-1] self.assertEqual(prefix, 'realmname') self.assertEqual(code, '315') myname, channel, extra = stuff self.assertEqual(myname, 'userone') self.assertEqual(channel, '#groupname') self.assertEqual(extra, 'End of /WHO list.')
def testGetTopic(self): user = self._loggedInUser("useruser") group = service.Group("somechannel") group.meta["topic"] = "This is a test topic." group.meta["topic_author"] = "some_fellow" group.meta["topic_date"] = 77777777 self.successResultOf(self.realm.addGroup(group)) user.transport.clear() user.write("JOIN #somechannel\r\n") response = self._response(user) self.assertEqual(response[3][0], "realmname") self.assertEqual(response[3][1], "332") # XXX Sigh. irc.parsemsg() is not as correct as one might hope. self.assertEqual( response[3][2], ["useruser", "#somechannel", "This is a test topic."] ) self.assertEqual(response[4][1], "333") self.assertEqual( response[4][2], ["useruser", "#somechannel", "some_fellow", "77777777"] ) user.transport.clear() user.write("TOPIC #somechannel\r\n") response = self._response(user) self.assertEqual(response[0][1], "332") self.assertEqual( response[0][2], ["useruser", "#somechannel", "This is a test topic."] ) self.assertEqual(response[1][1], "333") self.assertEqual( response[1][2], ["useruser", "#somechannel", "some_fellow", "77777777"] )
pidfile = config.configuration.get('pidfile', None) if pidfile is not None: with open(pidfile, 'w+') as pf: pf.write("%s\n" % str(os.getpid())) for room in config.campfire.rooms(): config.rooms[room['id']] = room config.rooms[room['id']]['channel'] = util.campNameToString(room['name']) config.rooms[room['id']]['stream'] = None config.rooms[room['id']]['streaming'] = False config.rooms[room['id']]['heartbeat'] = None log.msg('Adding %s to IRC as %s' % (room['name'], config.rooms[room['id']]['channel'])) config.irc_realm.addGroup(service.Group(config.rooms[room['id']]['channel'])) user_db = checkers.InMemoryUsernamePasswordDatabaseDontUse(**config.users) irc_portal = portal.Portal(config.irc_realm, [user_db]) # Start IRC and Manhole reactor.listenTCP(int(config.configuration.get('port', 6667)), LuckyStrikeIRCFactory(config.irc_realm, irc_portal)) if config.args.debug: admin_password = util.generate_password() log.msg('Staring ManHole with admin password: %s' % admin_password) reactor.listenTCP( int(config.configuration.get('manhole_port', 2222)), getManholeFactory(globals(), admin=admin_password), interface='127.0.0.1'
# Last updated: 2013.01.27 # This code is in the public domain #------------------------------------------------------------------------------- import sys from twisted.cred import checkers, portal from twisted.internet import reactor from twisted.internet.endpoints import TCP4ServerEndpoint from twisted.python import log from twisted.words import service ROOM = 'room' USERS = dict(user1='pass1', user2='pass2', user3='pass3', user4='pass4') if __name__ == '__main__': log.startLogging(sys.stdout) # Initialize the Cred authentication system used by the IRC server. realm = service.InMemoryWordsRealm('testrealm') realm.addGroup(service.Group(ROOM)) user_db = checkers.InMemoryUsernamePasswordDatabaseDontUse(**USERS) portal = portal.Portal(realm, [user_db]) # IRC server factory. ircfactory = service.IRCFactory(realm, portal) # Connect a server to the TCP port 6667 endpoint and start listening. endpoint = TCP4ServerEndpoint(reactor, 6667) endpoint.listen(ircfactory) reactor.run()