Client now communicates over SSL. Added configuration file. Pulled wok's frontend...
authorJack Allnutt <m2ys4u@Gmail.com>
Sat, 16 Jul 2011 16:53:36 +0000 (17:53 +0100)
committerJack Allnutt <m2ys4u@Gmail.com>
Sat, 16 Jul 2011 16:53:36 +0000 (17:53 +0100)
index.php
js/gateway.js
node/cert.pem [new file with mode: 0644]
node/config.json [new file with mode: 0644]
node/kiwi.js
node/server.key [new file with mode: 0644]

index 9624789a3d83ba19b474865eea7a5cdcb1aa00b2..857983c30c201d003d8c859538456c74dee919f3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -47,7 +47,8 @@
 <link rel="stylesheet" type="text/css" href="css/touchscreen_tweaks.css">\r
 <?php } ?>\r
 \r
-<script src="http://<?php echo $node_server; ?>:7777/socket.io/socket.io.js"></script>\r
+<script type="text/javascript">var kiwi_server = 'https://<?php echo $node_server; ?>:7777/';</script>\r
+<script src="https://<?php echo $node_server; ?>:7777/socket.io/socket.io.js"></script>\r
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>\r
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>\r
 <script type="text/javascript" src="js/jquery.json-2.2.min.js"></script>\r
@@ -63,7 +64,6 @@
        var agent = '<?php echo $agent; ?>';\r
        var touchscreen = <?php echo ($touchscreen) ? 'true' : 'false'; ?>;\r
        var init_data = {};\r
-       var kiwi_server = 'wss://<?php echo $node_server; ?>:7777/';\r
        \r
        $(document).ready(function(){\r
                if(touchscreen) $('#kiwi').addClass('touchscreen');\r
index b5b252c4bf6a276e64310e2c3f021e3f38ea8b65..5598a288b3b53c8810ab1afa306f824fb1108759 100644 (file)
@@ -1,5 +1,5 @@
 /*jslint browser: true, confusion: true, sloppy: true, maxerr: 50, indent: 4 */
-/*globals io, $ */
+/*globals io, $, kiwi_server */
 var gateway = {
 
     revision: 16,
diff --git a/node/cert.pem b/node/cert.pem
new file mode 100644 (file)
index 0000000..1b1aaed
--- /dev/null
@@ -0,0 +1,14 @@
+-----BEGIN CERTIFICATE-----
+MIICKzCCAZQCCQCHW0Kmpb9HBTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJH
+QjERMA8GA1UEChMIS2l3aSBJUkMxFzAVBgNVBAMTDktpd2kgV3JhbmdsZXJzMR8w
+HQYJKoZIhvcNAQkBFhBraXdpQGtpd2lpcmMuY29tMB4XDTExMDcxNjE1NDQxM1oX
+DTExMDgxNTE1NDQxM1owWjELMAkGA1UEBhMCR0IxETAPBgNVBAoTCEtpd2kgSVJD
+MRcwFQYDVQQDEw5LaXdpIFdyYW5nbGVyczEfMB0GCSqGSIb3DQEJARYQa2l3aUBr
+aXdpaXJjLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0h+kOA69tiJD
+u0COP0Wh0I9wVqAENQlRA5GowcH7r2Y3D9CbBIguw4Ss48kfXhDQa6sP9qsGvEAR
+kSkHcxIt+BRVtGjmzrZbGzObyOOm8rStcLiYCXas7m5U/mxy4vppL2eAX26az5wy
+f1vYGukhH1XRUdObxNNnLoNDWPJG8+sCAwEAATANBgkqhkiG9w0BAQUFAAOBgQBU
+fARp2ZADZ89EiqUTRsCe8b8gXTO0Z3ov9LFTYhlpwH0RZ3fn9sE9A4mwrRlJC44W
+Z21sflIuXNFDerraedmx+fQwmwNBR6MMJgVN5nYw/x24QJf0C7ujIZrs4lxJdqwf
+yBRE6B7pJYPkk+aPHx/LSsbi9avMBfW+LQtkVOCuZg==
+-----END CERTIFICATE-----
diff --git a/node/config.json b/node/config.json
new file mode 100644 (file)
index 0000000..a1ac706
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    "port":           7777,
+    "listen_ssl":     true,
+    "ssl_key":        "server.key",
+    "ssl_cert":       "cert.pem",
+    "quit_message":   "KiwiIRC",
+    "cap_options":    []
+}
index f46eed5376c2f5ca45084c19e0b444c01e186ae5..f43f1785f0336f505e523347fddbe0b25f051353 100644 (file)
@@ -3,10 +3,16 @@
 var tls = require('tls'),
     net = require('net'),
     http = require('http'),
+    fs = require('fs'),
     ws = require('socket.io'),
     _ = require('./lib/underscore.min.js'),
     starttls = require('./lib/starttls.js');
 
+asdf = fs.readFileSync('config.json', 'ascii')
+console.log(asdf, typeof asdf);
+var config = JSON.parse(asdf);
+console.log(config);
+
 var ircNumerics = {
     RPL_WELCOME:        '001',
     RPL_ISUPPORT:       '005',
@@ -178,7 +184,7 @@ var parseIRCMessage = function (websocket, ircSocket, data) {
             websocket.emit('message', {event: 'msg', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing});
             break;
         case 'CAP':
-            caps = [];
+            caps = config.cap_options;
             options = msg.trailing.split(" ");
             switch (_.first(msg.params.split(" "))) {
             case 'LS':
@@ -246,9 +252,21 @@ var parseIRCMessage = function (websocket, ircSocket, data) {
 
 var ircSocketDataHandler = function (data, websocket, ircSocket) {
     var i;
-    data = data.split("\r\n");            
+    if ((ircSocket.holdLast) && (ircSocket.held !== '')) {
+        data = ircSocket.held + data;
+        ircSocket.holdLast = false;
+        ircSocket.held = '';
+    }
+    if (data.substring(data.length-2,0) === '\r\n') {
+        ircSocket.holdLast = true;
+    }
+    data = data.split("\r\n");         
     for (i = 0; i < data.length; i++) {
         if (data[i]) {
+            if ((ircSocket.holdLast) && (i === data.length-1)) {
+                ircSocket.held = data[i];
+                break;
+            }
             console.log("->" + data[i]);
             parseIRCMessage(websocket, ircSocket, data[i]);
         }
@@ -256,7 +274,11 @@ var ircSocketDataHandler = function (data, websocket, ircSocket) {
 };
 
 //setup websocket listener
-var io = ws.listen(7777, {secure: true});
+if (config.listen_ssl) {
+    var io = ws.listen(config.port, {secure: true, key: fs.readFileSync(config.ssl_key), cert: fs.readFileSync(config.ssl_cert)});
+} else {
+    var io = ws.listen(config.port, {secure: false});
+}
 io.sockets.on('connection', function (websocket) {
     websocket.on('irc connect', function (nick, host, port, ssl, callback) {
         var ircSocket;
@@ -327,7 +349,7 @@ io.sockets.on('connection', function (websocket) {
     });
     websocket.on('disconnect', function () {
         if ((!websocket.sentQUIT) && (websocket.ircSocket)) {
-            websocket.ircSocket.end('QUIT :KiwiIRC\r\n');
+            websocket.ircSocket.end('QUIT :' + config.quit_messages + '\r\n');
             websocket.sentQUIT = true;
             websocket.ircSocket.destroySoon();
         }
diff --git a/node/server.key b/node/server.key
new file mode 100644 (file)
index 0000000..6d6a3a4
--- /dev/null
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQDSH6Q4Dr22IkO7QI4/RaHQj3BWoAQ1CVEDkajBwfuvZjcP0JsE
+iC7DhKzjyR9eENBrqw/2qwa8QBGRKQdzEi34FFW0aObOtlsbM5vI46bytK1wuJgJ
+dqzublT+bHLi+mkvZ4BfbprPnDJ/W9ga6SEfVdFR05vE02cug0NY8kbz6wIDAQAB
+AoGBANBlPVOzmwfWd+JxJiMuhkv41uuzDDklokmt3vc70sik0ZtHw1b9UZPsNCQ+
+RnPerTb7k3uLJ8TwrfuP+6lusFL8bwzXBaPZOZmSf2aQz8o6MAyY8B8gxjDi/NoW
+b5jtpXGFNayjc5O7tDjBsd/g88vk3EjnpJZ0P4H3gC+hhCCRAkEA7lGFVou8/ht7
+vTpbHEP13mjYG7OUmJqTXavkrit9UDDcZukt6I7TAB42LPyI7DnjB8i358bdmQQj
+x4R1mNZadQJBAOG2msKY+PFQGUpP18HlFze7JPbc0L5CLeiVIrXV9+xY7FgyGzwU
+UvI9ZyHhqzsgU2/9yW2+beaS8S8LCkGAiN8CQQCcmfMNiOua6wJnuQYPz9Sr3qdL
+pLjbgo+duQufK7K/1CuwcD+bluauKCwfaZ6r4+n8vneilXoeR6sfOzpvQUPVAkBJ
+ZJUB/bfEz6TJkxi3BYT9LC8izj5Z/y7qV8QHmGGbSnbfXruYV4t5FRo53CVPfn1j
+BwS+WJNnzBP8lfxpvB/FAkAf6mPKzWlMnWYXg6gII9lQZQ1EIn258Hi7vrFw9+Ic
+lDbndynaxh97wqKoloRckXF3D9FZM0w7YIS541Cih42u
+-----END RSA PRIVATE KEY-----