From 1eaf214f2b686d9fd37922a23db07a57de604ae4 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Sat, 16 Jul 2011 17:53:36 +0100 Subject: [PATCH] Client now communicates over SSL. Added configuration file. Pulled wok's frontend commits. --- index.php | 4 ++-- js/gateway.js | 2 +- node/cert.pem | 14 ++++++++++++++ node/config.json | 8 ++++++++ node/kiwi.js | 30 ++++++++++++++++++++++++++---- node/server.key | 15 +++++++++++++++ 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 node/cert.pem create mode 100644 node/config.json create mode 100644 node/server.key diff --git a/index.php b/index.php index 9624789..857983c 100644 --- a/index.php +++ b/index.php @@ -47,7 +47,8 @@ - + + @@ -63,7 +64,6 @@ var agent = ''; var touchscreen = ; var init_data = {}; - var kiwi_server = 'wss://:7777/'; $(document).ready(function(){ if(touchscreen) $('#kiwi').addClass('touchscreen'); diff --git a/js/gateway.js b/js/gateway.js index b5b252c..5598a28 100644 --- a/js/gateway.js +++ b/js/gateway.js @@ -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 index 0000000..1b1aaed --- /dev/null +++ b/node/cert.pem @@ -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 index 0000000..a1ac706 --- /dev/null +++ b/node/config.json @@ -0,0 +1,8 @@ +{ + "port": 7777, + "listen_ssl": true, + "ssl_key": "server.key", + "ssl_cert": "cert.pem", + "quit_message": "KiwiIRC", + "cap_options": [] +} diff --git a/node/kiwi.js b/node/kiwi.js index f46eed5..f43f178 100644 --- a/node/kiwi.js +++ b/node/kiwi.js @@ -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 index 0000000..6d6a3a4 --- /dev/null +++ b/node/server.key @@ -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----- -- 2.25.1