Kiwi can now listen on multiple ports at the same time.
authorJack Allnutt <m2ys4u@Gmail.com>
Tue, 20 Sep 2011 16:56:43 +0000 (17:56 +0100)
committerJack Allnutt <m2ys4u@Gmail.com>
Tue, 20 Sep 2011 16:56:43 +0000 (17:56 +0100)
Reverted previous change to index.html.jade

node/app.js
node/client/index.html.jade
node/config.json
node/kiwi.js

index 633de3903b3aa8e40d6aca9186ea86c3842e11eb..94769a85f850b2d7f8a4b2c9ee10226b11d07fb6 100644 (file)
@@ -512,7 +512,8 @@ this.ircSocketDataHandler = function (data, websocket, ircSocket) {
 
 this.httpHandler = function (request, response) {
     var uri, uri_parts, subs, useragent, agent, server_set, server, nick, debug, touchscreen, hash,
-        min = {}, public_http_path;
+        min = {}, public_http_path,
+        secure = (typeof request.client.encrypted === 'object');
     if (kiwi.config.handle_http) {
         uri = url.parse(request.url, true);
         uri_parts = uri.pathname.split('/');
@@ -588,13 +589,13 @@ this.httpHandler = function (request, response) {
 
             response.setHeader('X-Generated-By', 'KiwiIRC');
             hash = crypto.createHash('md5').update(touchscreen ? 't' : 'f')
-                                            .update(debug ? 't' : 'f')
-                                            .update(server_set ? 't' : 'f')
-                                            .update(server)
-                                            .update(nick)
-                                            .update(agent)
-                                            .update(JSON.stringify(kiwi.config))
-                                            .digest('base64');
+                .update(debug ? 't' : 'f')
+                .update(server_set ? 't' : 'f')
+                .update(server)
+                .update(nick)
+                .update(agent)
+                .update(JSON.stringify(kiwi.config))
+                .digest('base64');
             if (kiwi.cache.html[hash]) {
                 if (request.headers['if-none-match'] === kiwi.cache.html[hash].hash) {
                     response.statusCode = 304;
@@ -607,7 +608,7 @@ this.httpHandler = function (request, response) {
                 fs.readFile(__dirname + '/client/index.html.jade', 'utf8', function (err, str) {
                     var html, hash2;
                     if (!err) {
-                        html = kiwi.jade.compile(str)({ "touchscreen": touchscreen, "debug": debug, "server_set": server_set, "server": server, "nick": nick, "agent": agent, "config": kiwi.config });
+                        html = kiwi.jade.compile(str)({ "touchscreen": touchscreen, "debug": debug, "secure": secure, "server_set": server_set, "server": server, "nick": nick, "agent": agent, "config": kiwi.config });
                         hash2 = crypto.createHash('md5').update(html).digest('base64');
                         kiwi.cache.html[hash] = {"html": html, "hash": hash2};
                         if (request.headers['if-none-match'] === hash2) {
@@ -634,33 +635,42 @@ this.httpHandler = function (request, response) {
 
 
 
-this.websocketListen = function (port, host, handler, secure, key, cert) {
-    if (kiwi.httpServer) {
-        kiwi.httpServer.close();
+this.websocketListen = function (ports, host, handler, key, cert) {
+    if (kiwi.httpServers.length > 0) {
+        _.each(kiwi.httpServers, function (hs) {
+            hs.close();
+        });
+        kiwi.httpsServers = [];
     }
-    if (secure) {
-        kiwi.httpServer = https.createServer({key: fs.readFileSync(__dirname + '/' + key), cert: fs.readFileSync(__dirname + '/' + cert)}, handler);
-        kiwi.io = ws.listen(kiwi.httpServer, {secure: true});
-        kiwi.httpServer.listen(port, host);
-    } else {
-        kiwi.httpServer = http.createServer(handler);
-        kiwi.io = ws.listen(kiwi.httpServer, {secure: false});
-        kiwi.httpServer.listen(port, host);
-    }
-
-    kiwi.io.set('log level', 1);
-    kiwi.io.enable('browser client minification');
-    kiwi.io.enable('browser client etag');
-    kiwi.io.set('transports', kiwi.config.transports);
-
-    kiwi.io.of('/kiwi').authorization(function (handshakeData, callback) {
-        var address = handshakeData.address.address;
-        
-        if (typeof kiwi.connections[address] === 'undefined') {
-            kiwi.connections[address] = {count: 0, sockets: []};
+    _.each(ports, function (port) {
+        var hs;
+        if (port.secure === true) {
+            hs = https.createServer({key: fs.readFileSync(__dirname + '/' + key), cert: fs.readFileSync(__dirname + '/' + cert)}, handler);
+            kiwi.io.push(ws.listen(hs, {secure: true}));
+            hs.listen(port.number);
+            console.log("Listening on %s, port %d with SSL", host, port.number);
+        } else {
+            hs = http.createServer(handler);
+            kiwi.io.push(ws.listen(hs, {secure: false}));
+            hs.listen(port.number);
+            console.log("Listening on %s, port %d without SSL", host, port.number);
         }
-        callback(null, true);
-    }).on('connection', kiwi.websocketConnection);
+    });
+    
+    _.each(kiwi.io, function (io) {
+        io.set('log level', 1);
+        io.enable('browser client minification');
+        io.enable('browser client etag');
+        io.set('transports', kiwi.config.transports);
+        
+        io.of('/kiwi').authorization(function (handshakeData, callback) {
+            var address = handshakeData.address.address;
+            if (typeof kiwi.connections[address] === 'undefined') {
+                kiwi.connections[address] = {count: 0, sockets: []};
+            }
+            callback(null, true);
+        }).on('connection', kiwi.websocketConnection);
+    });
 };
 
 
@@ -670,6 +680,7 @@ this.websocketListen = function (port, host, handler, secure, key, cert) {
 
 this.websocketConnection = function (websocket) {
     var con;
+    console.log("New connection!");
     websocket.kiwi = {address: websocket.handshake.address.address, buffer: {list: []}};
     con = kiwi.connections[websocket.kiwi.address];
 
@@ -856,15 +867,13 @@ this.rehash = function () {
         console.log('%s config changes: \n', Object.keys(changes).length, changes);
         for (i in changes) {
             switch (i) {
-            case 'port':
+            case 'ports':
             case 'bind_address':
-            case 'listen_ssl':
             case 'ssl_key':
             case 'ssl_cert':
-                kiwi.websocketListen(kiwi.config.port, kiwi.config.bind_address, kiwi.httpHandler, kiwi.config.listen_ssl, kiwi.config.ssl_key, kiwi.config.ssl_cert);
-                delete changes.port;
+                kiwi.websocketListen(kiwi.config.ports, kiwi.config.bind_address, kiwi.httpHandler, kiwi.config.ssl_key, kiwi.config.ssl_cert);
+                delete changes.ports;
                 delete changes.bind_address;
-                delete changes.listen_ssl;
                 delete changes.ssl_key;
                 delete changes.ssl_cert;
                 break;
index f6718501ecf57e1f914d61828740a9a53808b6e5..0ab1d6c7aef27c6f47eaa72a59d06779b37f787f 100644 (file)
@@ -14,84 +14,6 @@ html(xmlns="http://www.w3.org/1999/xhtml", lang="en-gb")
         - if (touchscreen)
             link(rel="stylesheet", type="text/css", href="css/touchscreen_tweaks.css")
 
-    body
-
-        div#kiwi
-            div.connectwindow
-                h1.logo Kiwi IRC
-                div#login
-                    form.formconnectwindow
-                        div.content.top
-                            ul
-                                li
-                                    label(for="nick") Your nickname:
-                                    input(type="text", id="nick", name="nick", class="nick", placeholder="Your nick..", value=nick)
-                            a.connect(href="") Connect...
-
-                        - var display
-                        - if (server_set)
-                            - display = 'display:none'
-                        - else
-                            - display = '';
-                        div.more(style=display)
-                            a(href="", class="more_link") more
-                            div.content.bottom
-                                ul
-                                    li
-                                        label(for="network") Server:
-                                        input(type="text", id="network", name="network", class="network", value=server)
-                                    li
-                                        label(for="channel") Channel:
-                                        input(type="text", id="channel", name="channel", class="channel", value="#kiwiirc")
-                                    li(class="section")
-                                        label(for="port") Port:
-                                        input(type="text", id="port", name="port", class="port", value="6667")
-                                    li
-                                        label(for="ssl") SSL:
-                                        input(type="checkbox", id="ssl", name="ssl", class="ssl")
-                                a.connect(href="") Connect...
-
-
-            
-            div.toolbars
-                div.windowlist
-                    div.poweredby Powered by Kiwi IRC
-                    ul
-
-                div.utilityviewlist
-                    ul
-
-                div.cur_topic(contenteditable="true", spellcheck="true")
-                    //
-                        ul.edit(style="float:right;")
-                            li
-                                img(src="img/more.png")
-                                    ul#kiwi_menu
-                                        li Item 1
-                                        li Item 2
-                                        li Item 3
-                    div.topic(style="margin-right:5em; overflow:hidden; white-space: pre-wrap; word-wrap: break-word;")
-
-            div.userlist
-                ul
-
-            div#windows.windows
-                div.scroller(style="width:100%;height:100%;")
-
-            div.control
-                div.msginput
-                    div.nick
-                        a
-                        | :
-                    input(type="text", name="kiwi_msginput", id="kiwi_msginput")
-                div.plugins
-                    ul
-                        li
-                            a.load_plugin_file Plugins
-                        - if (debug)
-                            li
-                                a.reload_css Reload CSS
-
         script(type="text/javascript", src="/socket.io/socket.io.js")
         script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js")
         script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js")
@@ -110,9 +32,9 @@ html(xmlns="http://www.w3.org/1999/xhtml", lang="en-gb")
 
         - if (touchscreen)
             script(type="text/javascript", src="/js/touchscreen_tweaks.js")
-            
+
         - var proto
-        - if (config.listen_ssl)
+        - if (secure)
             - proto = 'https'
         - else
             - proto = 'http'
@@ -194,4 +116,85 @@ html(xmlns="http://www.w3.org/1999/xhtml", lang="en-gb")
             |        <input type="hidden" class="userbox_nick" value="${nick}" />
             |        <a class="userbox_query">Message</a>
             |        <a class="userbox_whois">Info</a>
-            |    </div>
\ No newline at end of file
+            |    </div>
+
+    body
+
+        div#kiwi
+            div.connectwindow
+                h1.logo Kiwi IRC
+                div#login
+                    form.formconnectwindow
+                        div.content.top
+                            ul
+                                li
+                                    label(for="nick") Your nickname:
+                                    input(type="text", id="nick", name="nick", class="nick", placeholder="Your nick..", value=nick)
+                            a.connect(href="") Connect...
+
+                        - var display
+                        - if (server_set)
+                            - display = 'display:none'
+                        - else
+                            - display = '';
+                        div.more(style=display)
+                            a(href="", class="more_link") more
+                            div.content.bottom
+                                ul
+                                    li
+                                        label(for="network") Server:
+                                        input(type="text", id="network", name="network", class="network", value=server)
+                                    li
+                                        label(for="channel") Channel:
+                                        input(type="text", id="channel", name="channel", class="channel", value="#kiwiirc")
+                                    li(class="section")
+                                        label(for="port") Port:
+                                        input(type="text", id="port", name="port", class="port", value="6667")
+                                    li
+                                        label(for="ssl") SSL:
+                                        input(type="checkbox", id="ssl", name="ssl", class="ssl")
+                                a.connect(href="") Connect...
+
+
+            
+            div.toolbars
+                div.windowlist
+                    div.poweredby Powered by Kiwi IRC
+                    ul
+
+                div.utilityviewlist
+                    ul
+
+                div.cur_topic(contenteditable="true", spellcheck="true")
+                    //
+                        ul.edit(style="float:right;")
+                            li
+                                img(src="img/more.png")
+                                    ul#kiwi_menu
+                                        li Item 1
+                                        li Item 2
+                                        li Item 3
+                    div.topic(style="margin-right:5em; overflow:hidden; white-space: pre-wrap; word-wrap: break-word;")
+
+            div.userlist
+                ul
+
+            div#windows.windows
+                div#panel1.panel
+                    div.scroller(style="width:100%;height:100%;")
+
+                div#panel2.panel
+
+            div.control
+                div.msginput
+                    div.nick
+                        a
+                        | :
+                    input(type="text", name="kiwi_msginput", id="kiwi_msginput")
+                div.plugins
+                    ul
+                        li
+                            a.load_plugin_file Plugins
+                        - if (debug)
+                            li
+                                a.reload_css Reload CSS
index 132c83550c077fd02a1566db7cb77b2ec1781d26..f59d3645fd38e5d024a7f392fe1abf20fe10c985 100644 (file)
@@ -1,11 +1,20 @@
 {
-    "port":             7777,
+    "ports":            [
+                            {
+                                "secure":   true,
+                                "number":   7777
+                            },
+                            {
+                                "secure":   false,
+                                "number":   7778
+                            }
+                            
+                        ],
     "bind_address":     "0.0.0.0",
 
-    "user":                            "",
-    "group":                   "",
+    "user":             "",
+    "group":            "",
 
-    "listen_ssl":       false,
     "ssl_key":          "server.key",
     "ssl_cert":         "cert.pem",
 
@@ -13,7 +22,7 @@
     "cap_options":      [],
 
     "handle_http":      true,
-    "public_http":         "./../",
+    "public_http":      "./../",
 
     "max_client_conns": 2,
 
@@ -27,9 +36,7 @@
                         },
 
     "transports":       [
-                            "websocket",
-                            "flashsocket",
-                            "htmlfile",
+                            
                             "xhr-polling",
                             "jsonp-polling"
                         ]
index e58607c313e114d9132a91fe955f7ace3f83ae17..b6f04db33b3bf83ad00c0445dc9271531ee0ff49 100644 (file)
@@ -122,7 +122,7 @@ if (this.config.handle_http) {
     this.jade = require('jade');
     this.cache = {alljs: '', html: []};
 }
-this.httpServer = null;
+this.httpServers = [];
 this.httpHandler = function (request, response) {
     return app.httpHandler(request, response);
 }
@@ -136,7 +136,7 @@ this.httpHandler = function (request, response) {
  * Websocket handling
  */
 this.connections = {};
-this.io = null;
+this.io = [];
 this.websocketListen = function (port, host, handler, secure, key, cert) {
     return app.websocketListen(port, host, handler, secure, key, cert);
 }
@@ -199,7 +199,7 @@ this.kiwi_mod.printMods();
 
 
 // Start the server up
-this.websocketListen(this.config.port, this.config.bind_address, this.httpHandler, this.config.listen_ssl, this.config.ssl_key, this.config.ssl_cert);
+this.websocketListen(this.config.ports, this.config.bind_address, this.httpHandler, this.config.ssl_key, this.config.ssl_cert);
 
 // Now we're listening on the network, set our UID/GIDs if required
 app.changeUser();