Permalink
Browse files

Updated ident

  • Loading branch information...
1 parent bb83c6d commit 8c160b429d3990ba27d7e58ef5ef216fb183c68d Evan Fosmark committed Aug 31, 2010
Showing with 25 additions and 41 deletions.
  1. +1 −1 README
  2. +2 −15 docs/ident.rst
  3. +22 −25 ircutils/ident.py
View
2 README
@@ -12,7 +12,7 @@ and simple support for writing IRC bots. Its features include:
* Automatic channel tracking
* CTCP compatibility
* Advanced message handling
- * Configurable ident server
+ * Basic ident server
:Home page: http://dev.guardedcode.com/projects/ircutils/
:Documentation: http://dev.guardedcode.com/docs/ircutils/
View
@@ -2,26 +2,13 @@ ircutils.ident
==============
.. automodule:: ircutils.ident
-
-Servers
--------
.. note::
The standard ident port is 113; however, since on many operating systems
any port below 1024 is protected, you may either have to have root access.
Otherwise, set up a port forward that goes from 113 to something higher,
and serve on that.
-.. autoclass:: FakeIdentServer
- :members: start
-
.. autoclass:: IdentServer
- :members: start
-
-
-Client
-------
-.. autoclass:: IdentClient
- :members:
Example
@@ -42,10 +29,10 @@ doesn't have to wait at the "Checking for ident..." phase::
# Set up the bot
example = ExampleBot("example_bot")
- # Set up the ident server
+ # Set up the ident server.
# We use 1113 here because 113 is protected by the operating system,
# so we have to forward port 113 on the router to 1113 locally.
- identd = ident.FakeIdentServer(port=1113)
+ identd = ident.IdentServer(port=1113)
# Since we are running more than one server at the same time, we want to
# take advantage of the asynchronous nature of IRCUtils, so we start
View
@@ -1,7 +1,8 @@
-""" This module contains two distinct ident server implemtations:
-``IdentServer`` and ``FakeIdentServer``. IdentServer is a fully functional
-(RFC-1413 compatible) ident server for Unix machines. FakeIdentServer can be
-used instead in order to specify your own output data. Typically, this is ideal.
+""" This module contains a quick ident server implentation:
+``IdentServer``. IdentServer is a functional ident server that returns fake data
+and can be used with IRC bots or clients. This is useful for two reasons; it
+speeds up connection time, and some servers require an ident response for
+security purposes.
"""
import asyncore, asynchat
@@ -38,53 +39,49 @@ class _IdentChannel(asynchat.async_chat):
to the IdentServer. It isn't designed to be used directly.
"""
- def __init__(self, server, sock, addr):
+ def __init__(self, userid, sock, addr):
""" Set up the object by specifying the terminator and initializing the
input buffer and using the socket passed from the dispatcher. The
terminator for the ident protocol is CR+LF.
"""
asynchat.async_chat.__init__(self, sock)
self.set_terminator("\r\n")
- self.server = server
+ self.userid = userid
def found_terminator(self):
""" When this is activated, it means that the terminator (\r\n) has been
read. When that happens, we get the input data, clear the buffer,
and then handle the data collected.
"""
- response = self.handle_request("".join(self.incoming))
+ request = "".join(self.incoming)
+ sysos = get_operating_system()
+
+ response = (request, "USERID", sysos, self.userid)
+
self.incoming = []
self.push(":".join(response))
self.close_when_done()
-
- def handle_request(self, request):
- if self.server.response != USERID:
- return request, ERROR, self.server.response
-
- sysos = get_operating_system()
- userid = generate_fake_userid()
-
- return request, "USERID", sysos, userid
+
class IdentServer(asyncore.dispatcher):
- """ A simple and configurable ident server. """
+ """ A quick and easy ident server. In order to run the ident server inline
+ with an IRC bot or client, be sure to use ``start_all()`` instead of
+ calling the ``start()`` method.
- def __init__(self, port=113):
- """ Create the ident server by creating a typical socket and then
- binding it to the port specified.
-
- """
+ """
+ def __init__(self, port=113, userid=None):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.bind(("", port))
self.listen(5)
-
+ self.userid = userid or generate_fake_userid()
+
def handle_accept(self):
""" Dispatch a request onto an _IdentChannel instance. """
- _IdentChannel(self, *self.accept())
-
+ _IdentChannel(self.userid, *self.accept())
+
def start(self):
""" Begin serving ident requests on the port specified. """
asyncore.loop(map=self._map)

0 comments on commit 8c160b4

Please sign in to comment.