From: Darren Date: Sat, 1 Oct 2011 17:23:23 +0000 (+0100) Subject: forcessl Kiwi server plugin, ssl checkbox checked if on ssl X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f97fe3d2481d671ee7ba959542b5c12f1a73bb35;p=KiwiIRC.git forcessl Kiwi server plugin, ssl checkbox checked if on ssl --- diff --git a/css/ui.css b/css/ui.css index 59a5dbd..0b98605 100644 --- a/css/ui.css +++ b/css/ui.css @@ -41,7 +41,7 @@ } #kiwi #login input[type=checkbox] { width:auto !important; } -#kiwi #login .more { border-top: 1px dotted #888888; } +#kiwi #login .more { border-top: 1px dotted #888888; font-size: 0.9em;} #kiwi #login .more_link { font-size:12px; position:relative; diff --git a/js/front.events.js b/js/front.events.js index ad0716a..571f854 100644 --- a/js/front.events.js +++ b/js/front.events.js @@ -163,6 +163,11 @@ kiwi.front.events = { Tabview.getServerTab().addMsg(null, ' ', '=== Failed to connect :(', 'status'); kiwi.plugs.run('connect', {success: false}); } + + // Now that we're connected, warn the user if they really want to quit + window.onbeforeunload = function() { + return "Are you sure you leave Kiwi IRC?"; + }; }, onConnectFail: function (e, data) { var reason = (typeof data.reason === 'string') ? data.reason : ''; diff --git a/js/front.js b/js/front.js index a8c5351..a0b8189 100644 --- a/js/front.js +++ b/js/front.js @@ -45,10 +45,6 @@ kiwi.front = { kiwi.front.ui.registerKeys(); - window.onbeforeunload = function() { - return "Are you sure you leave Kiwi IRC?"; - }; - $('#kiwi .toolbars').resize(kiwi.front.ui.doLayoutSize); $(window).resize(kiwi.front.ui.doLayoutSize); diff --git a/node/app.js b/node/app.js index 8b06685..ee31709 100644 --- a/node/app.js +++ b/node/app.js @@ -529,11 +529,19 @@ 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, port, ssl, + min = {}, public_http_path, port, ssl, host, obj, args, secure = (typeof request.client.encrypted === 'object'); //try { if (kiwi.config.handle_http) { + // Run through any plugins.. + args = {request: request, response: response}; + obj = kiwi.kiwi_mod.run('http', args); + if (obj === null) { + return; + } + response = args.response; + uri = url.parse(request.url, true); uri_parts = uri.pathname.split('/'); @@ -593,7 +601,7 @@ this.httpHandler = function (request, response) { debug = (typeof uri.query.debug !== 'undefined'); port = 6667; - ssl = false; + ssl = (typeof request.socket.pair !== 'undefined'); if (uri_parts[1] !== 'client') { if (uri.query) { server_set = ((typeof uri.query.server !== 'undefined') && (uri.query.server !== '')); @@ -701,6 +709,8 @@ this.websocketListen = function (ports, host, handler, key, cert) { hs.listen(port.number, host); console.log("Listening on %s:%d without SSL", host, port.number); } + + kiwi.httpServers.push(hs); }); _.each(kiwi.io, function (io) { diff --git a/node/client/index.html.jade b/node/client/index.html.jade index a24e2a4..ec7e94c 100644 --- a/node/client/index.html.jade +++ b/node/client/index.html.jade @@ -54,7 +54,7 @@ html(lang="en-gb") label(for="port") Port: input(type="text", id="port", name="port", class="port", value=port) li - label(for="password") Server password: + label(for="password") Password: input(type="text", id="password", name="password", class="password") li label(for="ssl") SSL: @@ -159,7 +159,7 @@ html(lang="en-gb") function addEvents(){ - $('.more_link').click(function(){ $('.content.bottom').slideDown('fast'); $('.network').focus(); return false; }); + $('.more_link').click(function(){ $('.content.bottom').slideDown('fast'); $('.channel').focus(); return false; }); $('a.connect').click(function(){ $('.formconnectwindow').submit(); return false; }); var input_submit = function(e){ @@ -169,6 +169,7 @@ html(lang="en-gb") $('.formconnectwindow .channel').keydown(input_submit); $('.formconnectwindow .network').keydown(input_submit); $('.formconnectwindow .port').keydown(input_submit); + $('.formconnectwindow .password').keydown(input_submit); } diff --git a/node/kiwi_modules/forcessl.js b/node/kiwi_modules/forcessl.js new file mode 100644 index 0000000..1b4d46d --- /dev/null +++ b/node/kiwi_modules/forcessl.js @@ -0,0 +1,37 @@ +/* + * forcessl Kiwi module + * Force clients to use an SSL port by redirecting them + */ + +var kiwi = require('../kiwi.js'); + + +exports.onhttp = function (ev) { + // TODO: request.socket.pair seems to only be set in a SSL req, is this + // the best way to check for this? + if (typeof ev.request.socket.pair === 'undefined') { + host = ev.request.headers.host; + //port = 443; + + if (host.search(/:/)) { + //port = parseInt(host.substring(host.search(/:/) + 1), 10); + host = host.substring(0, host.search(/:/)); + } + if (kiwi.config.ports[0].number != 443) { + for (i in kiwi.config.ports) { + if (kiwi.config.ports[i].secure) { + host += ':' + kiwi.config.ports[0].number.toString(); + break; + } + } + } + + console.log('https://' + host + ev.request.url); + ev.response.writeHead(302, {'Location': 'https://' + host + ev.request.url}); + ev.response.end(); + + return null; + } + + return ev; +} \ No newline at end of file