]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
add option to run flash server
authorChris Porter <redacted>
Fri, 3 Jan 2014 15:10:30 +0000 (15:10 +0000)
committerChris Porter <redacted>
Fri, 3 Jan 2014 15:10:30 +0000 (15:10 +0000)
now works with wss (sadly twisted doesn't allow ssl and non ssl servers on the same port)

js/irc/ircconnection.js
qwebirc/root.py
run.py
twisted/plugins/webirc.py

index 58295cac399104efbef1e592e86c251f56016d69..ca7222ae67fb4d96edf10fe4aae446c13455637a 100644 (file)
@@ -293,7 +293,7 @@ qwebirc.irc.IRCConnection = new Class({
 
     var ws = new WebSocket(this.__wsURL());
     var doRetry = function(e) {
-      ws.onerror = ws.onclose = null;
+      ws.onerror = ws.onclose = ws.onopen = null;
       this.__ws = null;
       if(this.disconnected)
         return;
@@ -531,7 +531,9 @@ qwebirc.util.WebSocket = function(callback) {
       log("unable to install FlashWebSocket");
     } else {
       var ws = window.WebSocket;
-      WebSocket.loadFlashPolicyFile("xmlsocket://" + window.location.host + "/");
+      if(window.location.scheme == "http") /* no point trying port sharing for https */
+        WebSocket.loadFlashPolicyFile("xmlsocket://" + window.location.host + "/");
+
       state.result = true;
       log("FlashWebSocket loaded and installed");
     }
index 36d58f8bd249fd385824b2f62add822304a1f64f..847648fb181c6f09b7e0e10d1584a886e6ba5eb3 100644 (file)
@@ -1,3 +1,4 @@
+from twisted.protocols.policies import TimeoutMixin
 from twisted.web import resource, server, static, http
 from twisted.internet import error, reactor
 import engines
@@ -34,16 +35,21 @@ class ProxyRequest(server.Request):
       return real_ip
       
     return fake_ip
-    
+
+class HTTPChannel(http.HTTPChannel):
+  def timeoutConnection(self):
+    self.transport.abortConnection()
+
 class RootSite(server.Site):
-  protocol = http.HTTPChannel
+  protocol = HTTPChannel
 
   if hasattr(config, "FORWARDED_FOR_HEADER"):
     requestFactory = ProxyRequest
 
-  def __init__(self, path):
+  def __init__(self, path, *args, **kwargs):
     root = RootResource()
-    server.Site.__init__(self, root, timeout=5)
+    kwargs["timeout"] = config.HTTP_REQUEST_TIMEOUT
+    server.Site.__init__(self, root, *args, **kwargs)
     services = {}
     services["StaticEngine"] = root.primaryChild = engines.StaticEngine(path)
 
diff --git a/run.py b/run.py
index 2d44a3aea6e42385d3c39d4d736290d31cdf7237..9c104be8d5c8c162d77306cbda42666598c0375a 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -40,6 +40,7 @@ parser.add_option("-k", "--key", help="Path to SSL key.", dest="sslkey")
 parser.add_option("-H", "--certificate-chain", help="Path to SSL certificate chain file.", dest="sslchain")
 parser.add_option("-P", "--pidfile", help="Path to store PID file", dest="pidfile")
 parser.add_option("-s", "--syslog", help="Log to syslog", action="store_true", dest="syslog", default=False)
+parser.add_option("-f", "--flash-port", help="Port to listen for flash policy connections on.", type="int", dest="flashPort")
 parser.add_option("--profile", help="Run in profile mode, dumping results to this file", dest="profile")
 parser.add_option("--profiler", help="Name of profiler to use", dest="profiler")
 parser.add_option("--syslog-prefix", help="Syslog prefix", dest="syslog_prefix", default="qwebirc")
@@ -81,6 +82,9 @@ if not options.tracebacks:
 if options.clogfile:
   args2+=["--logfile", options.clogfile]
 
+if options.flashPort:
+  args2+=["--flashPort", options.flashPort]
+
 if options.sslcertificate and options.sslkey:
   args2+=["--certificate", options.sslcertificate, "--privkey", options.sslkey, "--https", options.port]
   if options.sslchain:
index 577affadee3534ccf84de71ea165888139aabcd3..81657008cb5cc08e3a5dcf5337933d2f42b792b7 100644 (file)
@@ -6,7 +6,7 @@ from twisted.internet import task, protocol
 from twisted.protocols import basic, policies
 from twisted.plugin import IPlugin
 from twisted.application.service import IServiceMaker
-from twisted.application import internet, strports
+from twisted.application import internet, strports, service
 from twisted.web import static, server
 import urlparse
 import urllib
@@ -22,6 +22,7 @@ class Options(usage.Options):
     ["privkey", "k", "server.pem", "SSL certificate to use for HTTPS."],
     ["certificate-chain", "C", None, "Chain SSL certificate"],
     ["staticpath", "s", "static", "Path to static content"],
+    ["flashPort", None, None, "Port to listen on for flash policy connections."],
   ]
 
   optFlags = [["notracebacks", "n", "Display tracebacks in broken web pages. " +
@@ -44,18 +45,20 @@ class FlashPolicyProtocol(protocol.Protocol, policies.TimeoutMixin):
       self.transport.write(self.factory.response_body)
       self.transport.loseConnection()
       return
-    else:
+    elif self.factory.childProtocol:
       self.setTimeout(None)
-      p = self.factory.site.buildProtocol(self.transport.client)
+      p = self.factory.childProtocol.buildProtocol(self.transport.client)
       p.transport = self.transport
       self.transport.protocol = p
       p.connectionMade()
       p.dataReceived(data)
+    else:
+      self.transport.loseConnection()
 
 class FlashPolicyFactory(protocol.ServerFactory):
   protocol = FlashPolicyProtocol
 
-  def __init__(self, site):
+  def __init__(self, childProtocol=None):
     import config
     base_url = urlparse.urlparse(config.BASE_URL)
     port = base_url.port
@@ -67,7 +70,7 @@ class FlashPolicyFactory(protocol.ServerFactory):
       else:
         raise Exception("Unknown scheme: " + base_url.scheme)
 
-    self.site = site
+    self.childProtocol = childProtocol
     self.response_body = """<cross-domain-policy>
     <allow-access-from domain="%s" to-ports="%d" />
 </cross-domain-policy>""" % (urllib.quote(base_url.hostname), port) + '\0'
@@ -83,15 +86,21 @@ class QWebIRCServiceMaker(object):
       site = RootSite(config['staticpath'], logPath=config['logfile'])
     else:
       site = RootSite(config['staticpath'])
-    
+
+    s = service.MultiService()
     site.displayTracebacks = not config["notracebacks"]
     if config['https']:
       ssl_factory = get_ssl_factory_factory()
-      i = internet.SSLServer(int(config['https']), FlashPolicyFactory(site), ssl_factory(config['privkey'], config['certificate'], certificateChainFile=config["certificate-chain"]), interface=config['ip'])
+      i = internet.SSLServer(int(config['https']), site, ssl_factory(config['privkey'], config['certificate'], certificateChainFile=config["certificate-chain"]), interface=config['ip'])
     else:
       i = internet.TCPServer(int(config['port']), FlashPolicyFactory(site), interface=config['ip'])
-      
-    return i
+
+    i.setServiceParent(s)
+    if config["flashPort"]:
+      f = internet.TCPServer(int(config['flashPort']), FlashPolicyFactory(), interface=config['ip'])
+      f.setServiceParent(s)
+
+    return s
 
 def get_ssl_factory_factory():
   from twisted.internet.ssl import DefaultOpenSSLContextFactory