Merge branch 'pull_request_5'
authorChristopher Zorn <christopher@mochimedia.com>
Wed, 4 May 2011 16:45:13 +0000 (09:45 -0700)
committerChristopher Zorn <christopher@mochimedia.com>
Wed, 4 May 2011 16:45:13 +0000 (09:45 -0700)
INSTALL.txt
punjab.tac
punjab/__init__.py
punjab/tap.py [deleted file]
twisted/plugins/punjab.py [deleted file]
twisted/plugins/punjab_plugin.py [new file with mode: 0644]

index 0757810..ceee27e 100644 (file)
@@ -3,15 +3,15 @@ INSTALLING PUNJAB
 =================
 
 This document contains instructions on installing punjab
-on your system. 
+on your system.
 
 -------------
 Obtaining Punjab
 -------------
 
-Punjab can be located at the punjab web site, 
+Punjab can be located at the punjab web site,
 
-   http://code.stanziq.com/punjab
+   http://github.com/twonds/punjab
 
 
 -------------
@@ -24,15 +24,15 @@ Please make sure all dependencies are met before submitting a troubleshooting qu
 
 - Twisted >= 2.5
 
-  - Twisted-names 
+  - Twisted-names
   - Twisted-words >= 0.6.0
   - Twisted-web  >= 0.5.0
 
   Recommended
     - Twisted-conch >= 0.5.0
 
-  NOTE : 
-    You can download all of these packages with the Twisted Sumo package. 
+  NOTE :
+    You can download all of these packages with the Twisted Sumo package.
     http://twistedmatrix.com/
 
 - pyopenssl - if you want tls to work.
@@ -44,8 +44,8 @@ Please make sure all dependencies are met before submitting a troubleshooting qu
 Installing Punjab
 -------------
 
-1. Untar the current punjab-X.X.tar.gz file in a directory you would 
-   like punjab to reside. 
+1. Untar the current punjab-X.X.tar.gz file in a directory you would
+   like punjab to reside.
 
 shell>tar vxzf punjab-X.X.tar.gz
 
@@ -53,45 +53,27 @@ shell>tar vxzf punjab-X.X.tar.gz
 
 shell>python setup.py install
 
-3. Configure punjab - using a tac file.
+3. Run punjab
 
-shell>edit punjab.tac
-# punjab tac file
-from twisted.web import server, resource, static
-from twisted.application import service, internet
+shell>twistd punjab
 
-from punjab.httpb  import Httpb, HttpbService
+Run "twistd punjab --help" for options.
 
-root = static.File("./html") # a static html directory
+4. HAVE FUN!!
 
-b = resource.IResource(HttpbService(1))
-root.putChild('bosh', b) # url for BOSH
-
-site  = server.Site(root)
-
-application = service.Application("punjab")
-internet.TCPServer(5280, site).setServiceParent(application)
-
-
-4. Run punjab 
-
-shell>twistd -y punjab.tac
-
-5. HAVE FUN!!
-
-
---------------
-Using a tac file.
 
 
 ---------------------------
 Extending Punjab
 ---------------------------
 
-You are able to extend punjab in many ways. 
+You are able to extend punjab in many ways.
+
+For configuration flexibility you can use a .tac file. See punjab.tac for
+details.
 
 -------------
 Support
 -------------
 
- http://code.stanziq.com/punjab
+ http://github.com/twonds/punjab
index 1197730..cd3a3d9 100644 (file)
@@ -1,4 +1,6 @@
 # punjab tac file
+# tac documentation is at the following URL:
+# http://twistedmatrix.com/documents/current/core/howto/application.html
 from twisted.web import server, resource, static
 from twisted.application import service, internet
 
@@ -25,3 +27,4 @@ site  = server.Site(root)
 application = service.Application("punjab")
 internet.TCPServer(5280, site).setServiceParent(application)
 
+# To run this simply to twistd -y punjab.tac
index a562f49..f0b064e 100644 (file)
@@ -2,11 +2,30 @@
 Punjab - multiple http interfaces to jabber.
 
 """
-from twisted.python import log
+from OpenSSL import SSL
+
 from twisted.application import service
+from twisted.internet import ssl
+from twisted.python import log
+
 import patches
 
 
+
+# Override DefaultOpenSSLContextFactory to call ctx.use_certificate_chain_file
+# instead of ctx.use_certificate_file, to allow certificate chains to be loaded.
+class OpenSSLContextFactoryChaining(ssl.DefaultOpenSSLContextFactory):
+    def __init__(self, *args, **kwargs):
+        ssl.DefaultOpenSSLContextFactory.__init__(self, *args, **kwargs)
+
+    def cacheContext(self):
+        ctx = self._contextFactory(self.sslmethod)
+        ctx.set_options(SSL.OP_NO_SSLv2)
+        ctx.use_certificate_chain_file(self.certificateFileName)
+        ctx.use_privatekey_file(self.privateKeyFileName)
+        self._context = ctx
+
+
 def uriCheck(elem, uri):
     """
     This is a hack for older versions of twisted words, we need to get rid of it.
@@ -87,11 +106,8 @@ def makeService(config):
 
     site  = server.Site(r)
 
-
     if config['ssl']:
-        from twisted.internet import ssl
-        from OpenSSL import SSL
-        ssl_context = ssl.DefaultOpenSSLContextFactory(config['ssl_privkey'],
+        ssl_context = OpenSSLContextFactoryChaining(config['ssl_privkey'],
                                                        config['ssl_cert'],
                                                        SSL.SSLv23_METHOD,)
         sm = internet.SSLServer(int(config['port']),
diff --git a/punjab/tap.py b/punjab/tap.py
deleted file mode 100644 (file)
index 7c3d80a..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-
-from twisted.python import usage
-import punjab
-
-class Options(usage.Options):
-    optParameters = [
-        ('host', None, 'localhost'),
-        ('port', None, 5280),
-        ('httpb', 'b', "http-bind"),
-        ('polling', None, '15'),
-        ('html_dir', None, "./html"),
-        ('ssl', None, None),
-        ('ssl_privkey', None, "ssl.key"),
-        ('ssl_cert', None, "ssl.crt"),
-        ('white_list', None, None,
-            'Comma separated list of domains to allow connections to. \
-            Begin an entry with a period to allow connections to subdomains. \
-            e.g.: --white_list=.example.com,domain.com'),
-        ('black_list', None, None,
-         'Comma separated list of domains to deny connections to. ' \
-         'Begin an entry with a period to deny connections to subdomains. '\
-         'e.g.: --black_list=.example.com,domain.com'),
-    ]
-
-    optFlags = [
-        ('verbose', 'v', 'Show traffic'), 
-    ]
-    
-
-def makeService(config):
-    return punjab.makeService(config)
diff --git a/twisted/plugins/punjab.py b/twisted/plugins/punjab.py
deleted file mode 100644 (file)
index 4eebfc3..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-
-from twisted.scripts.mktap import _tapHelper
-       
-Punjab = _tapHelper(
-               "Punjab",
-                "punjab.tap",
-               "A HTTP XMPP client interface",
-                "punjab")
diff --git a/twisted/plugins/punjab_plugin.py b/twisted/plugins/punjab_plugin.py
new file mode 100644 (file)
index 0000000..9e4841c
--- /dev/null
@@ -0,0 +1,45 @@
+from zope.interface import implements
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from twisted.application.service import IServiceMaker
+
+# Due to the directory layout, and the fact that plugin directories aren't
+# modules (no __init__.py), this file is named something other than punjab.py,
+# to ensure that this import pulls in the right module.
+import punjab
+
+class Options(usage.Options):
+    optParameters = [
+        ('host', None, 'localhost'),
+        ('port', None, 5280),
+        ('httpb', 'b', "http-bind"),
+        ('polling', None, '15'),
+        ('html_dir', None, "./html"),
+        ('ssl', None, None),
+        ('ssl_privkey', None, "ssl.key"),
+        ('ssl_cert', None, "ssl.crt"),
+        ('white_list', None, None,
+            'Comma separated list of domains to allow connections to. \
+            Begin an entry with a period to allow connections to subdomains. \
+            e.g.: --white_list=.example.com,domain.com'),
+        ('black_list', None, None,
+         'Comma separated list of domains to deny connections to. ' \
+         'Begin an entry with a period to deny connections to subdomains. '\
+         'e.g.: --black_list=.example.com,domain.com'),
+    ]
+
+    optFlags = [
+        ('verbose', 'v', 'Show traffic'),
+    ]
+
+class ServiceFactory(object):
+    implements(IServiceMaker, IPlugin)
+    tapname = "punjab"
+    description = "A HTTP XMPP client interface"
+    options = Options
+
+    def makeService(self, options):
+        return punjab.makeService(options)
+
+service = ServiceFactory()
+