NETWORK_NAME = "FooNet"
APP_TITLE = "FooNet Web IRC"
-# Possible types include "cgiirc", "hmac" and None
-WEBIRC_MODE = "cgiirc"
+DNS_TIMEOUT = 5
-# CGIIRC values
-CGIIRC_PASSWORD = "fish"
+# Possible types include "webirc" (CGIIRC style webirc config block),
+# "hmac" (quakenet specific) and None (passes ip and host in realname)
+WEBIRC_MODE = "webirc"
-# HMAC values
+# webirc mode values
+WEBIRC_PASSWORD = "fish"
+# hmac mode values
HMACKEY = "mrmoo"
HMACTEMPORAL = 30
--- /dev/null
+from twisted.names import client
+from twisted.internet import reactor, defer
+
+class LookupException(Exception): pass
+class VerificationException(Exception): pass
+TimeoutException = defer.TimeoutError
+
+def lookupPTR(ip, *args, **kwargs):
+ def callback(result):
+ answer, auth, add = result
+
+ if len(answer) == 0:
+ raise LookupException, "No ANSWERS in PTR response for %s." % repr(ip)
+ return str(answer[0].payload.name)
+
+ ptr = ".".join(ip.split(".")[::-1]) + ".in-addr.arpa."
+ return client.lookupPointer(ptr, **kwargs).addCallback(callback)
+
+def lookupAs(hostname, *args, **kwargs):
+ def callback(result):
+ answer, auth, add = result
+ if len(answer) == 0:
+ raise LookupException, "No ANSWERS in A response for %s." % repr(hostname)
+ return [x.payload.dottedQuad() for x in answer]
+
+ return client.lookupAddress(hostname, *args, **kwargs).addCallback(callback)
+
+def lookupAndVerifyPTR(ip, *args, **kwargs):
+ d = defer.Deferred()
+
+ def gotPTRResult(ptr):
+ def gotAResult(a_records):
+ if ip in a_records:
+ d.callback(ptr)
+ else:
+ raise VerificationException("IP mismatch: %s != %s%s" % (repr(ip), repr(ptr), repr(a_records)))
+ lookupAs(ptr, *args, **kwargs).addCallback(gotAResult).addErrback(d.errback)
+
+ lookupPTR(ip, *args, **kwargs).addCallback(gotPTRResult).addErrback(d.errback)
+ return d
+
+if __name__ == "__main__":
+ import sys
+
+ def callback(x):
+ print x
+ reactor.stop()
+
+ def errback(x):
+ x.printTraceback()
+ reactor.stop()
+
+ d = lookupAndVerifyPTR(sys.argv[1], timeout=[.001])
+ d.addCallbacks(callback, errback)
+
+ reactor.run()
import qwebirc.ircclient as ircclient
from adminengine import AdminEngineAction
from qwebirc.util import HitCounter
-
+import qwebirc.dns as qdns
Sessions = {}
def get_session_id():
reactor.callLater(5, cleanupSession, self.id)
+# DANGER! Breach of encapsulation!
+def connect_notice(line):
+ return "c", "NOTICE", "", ("AUTH", "*** (qwebirc) %s" % line)
+
class Channel:
def __init__(self, request):
self.request = request
raise PassthruException, http_error.NoResource().render(request)
- #def render_GET(self, request):
- #return self.render_POST(request)
-
def newConnection(self, request):
ticket = login_optional(request)
ident = socket.inet_aton(ip).encode("hex")
self.__connect_hit()
- client = ircclient.createIRC(session, nick=nick, ident=ident, ip=ip, realname=realname, perform=perform, hostname=ip)
- session.client = client
-
+
+ def proceed(hostname):
+ client = ircclient.createIRC(session, nick=nick, ident=ident, ip=ip, realname=realname, perform=perform, hostname=hostname)
+ session.client = client
+
+ if config.WEBIRC_MODE != "hmac":
+ notice = lambda x: session.event(connect_notice(x))
+ notice("Looking up your hostname...")
+ def callback(hostname):
+ notice("Found your hostname.")
+ proceed(hostname)
+ def errback(failure):
+ notice("Couldn't look up your hostname!")
+ proceed(ip)
+ qdns.lookupAndVerifyPTR(ip, timeout=[config.DNS_TIMEOUT]).addCallbacks(callback, errback)
+ else:
+ proceed(None) # hmac doesn't care
+
Sessions[id] = session
return id
if config.WEBIRC_MODE == "hmac":
hmac = hmacfn(ident, ip)
self.write("USER %s bleh bleh %s %s :%s" % (ident, ip, hmac, realname))
- elif config.WEBIRC_MODE == "cgiirc":
- self.write("WEBIRC %s cgiirc %s %s" % (config.WEBIRC_PASSWORD, ip, hostname))
+ elif config.WEBIRC_MODE == "webirc":
+ self.write("WEBIRC %s qwebirc %s %s" % (config.WEBIRC_PASSWORD, ip, hostname))
self.write("USER %s bleh %s :%s" % (ident, ip, realname))
else:
if ip == hostname:
else:
dispip = "%s/%s" % (hostname, ip)
- self.write("USER %s bleh bleh :%s -- %s" % (ident, dispip, realname))
+ self.write("USER %s bleh bleh :%s - %s" % (ident, dispip, realname))
self.write("NICK %s" % nick)