From af3a5da71316c355de04e64a5a34d4fc1856220e Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 6 Nov 2013 19:07:32 +0100 Subject: webchat: border around chatbox --- webchat/public/reset.css | 1 + 1 file changed, 1 insertion(+) (limited to 'webchat') diff --git a/webchat/public/reset.css b/webchat/public/reset.css index 17e10567..c291544d 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -49,6 +49,7 @@ q:before, q:after { border-spacing: 0; background-color: black; color: white; + border: 5px solid black; } .chat_from { color:grey; -- cgit v1.2.3 From aec1b767fd0223029332b14e5834c555efc345ff Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 6 Nov 2013 20:24:26 +0100 Subject: webchat: better layout --- webchat/hello_web.js | 7 +++---- webchat/public/client.js | 2 +- webchat/public/reset.css | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 45f6fc56..dd2f26e3 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -93,11 +93,10 @@ var app = connect() res.write(''); res.write(''); res.write(''); - res.write('
'); + res.write('
'); res.write('hello, this is #krebs:
'); - res.write('
'); - res.end('
'); - res.write('
'); + res.write('
'); + res.end('
'); }) var server = http.createServer(options, app); diff --git a/webchat/public/client.js b/webchat/public/client.js index 95b67ad0..e13ab1f7 100644 --- a/webchat/public/client.js +++ b/webchat/public/client.js @@ -26,7 +26,7 @@ $(function connect() { var safe_message = $('
').text(object.message).html(); safe_message = replaceURLWithHTMLLinks(safe_message); var safe_from = $('
').text(object.from).html(); - $('#chatbox').append(''+safe_from+''+safe_message+''); + $(''+(new Date).getHours() + ':' + (new Date).getMinutes() + ':' + (new Date).getSeconds()+''+safe_from+''+safe_message+'').insertBefore('#foot'); } catch (error) { console.log(error); diff --git a/webchat/public/reset.css b/webchat/public/reset.css index c291544d..2b67f153 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -21,6 +21,7 @@ time, mark, audio, video { border: 0; font-size: 100%; font: inherit; + font-family: monospace; vertical-align: baseline; } /* HTML5 display-role reset for older browsers */ @@ -50,11 +51,21 @@ q:before, q:after { background-color: black; color: white; border: 5px solid black; + width: 100%; + height:100%; + opacity: 0.8; +} +#input{ + width: 100%; + background-color: black; + border: 1px solid black; + color: white; } .chat_from { color:grey; font-weight: bold; text-align: right; + font-size:12px; } .chat_from:after { content: ":"; @@ -68,6 +79,21 @@ q:before, q:after { left: 0; right: 0; } +#chatter { + width: 75%; +} +.chat_date,.chat_from,.chat_msg{ +} +.chat_msg{ + width: 100%; +} a { color: red; } +.chat_date { + color: green; +} +.chat_date:after { + content: ""; + padding-right: 4px; +} \ No newline at end of file -- cgit v1.2.3 From c4854e60e33bc81cb5b6140241026576cbddcc0d Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 6 Nov 2013 21:52:51 +0100 Subject: webchat: write only ip as name --- webchat/hello_web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index dd2f26e3..86e12957 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -47,7 +47,7 @@ irc_client.on('message#krebs', function(from, message) { var echo = sockjs.createServer(); echo.on('connection', function(conn) { - var origin = '['+conn.remoteAddress+':'+conn.remotePort+']'; + var origin = conn.remoteAddress; Clients.push(conn); Clients.broadcast({from: 'system', message: origin + ' has joined'}) irc_client.say("#krebs", origin + ' has joined'); -- cgit v1.2.3 From 2f0f23ec0e54aaa0dc7a9c28217f7daca72ea455 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 6 Nov 2013 21:53:51 +0100 Subject: webchat: nick and time display --- webchat/hello_web.js | 4 ++-- webchat/public/client.js | 29 ++++++++++++++++++++++++++++- webchat/public/reset.css | 3 +++ 3 files changed, 33 insertions(+), 3 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 86e12957..8e2a0bb8 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -94,8 +94,8 @@ var app = connect() res.write(''); res.write(''); res.write('
'); - res.write('hello, this is #krebs:
'); - res.write('
'); + res.write('hello, this is the official krebs support:
'); + res.write('
'); res.end('
'); }) diff --git a/webchat/public/client.js b/webchat/public/client.js index e13ab1f7..e7179449 100644 --- a/webchat/public/client.js +++ b/webchat/public/client.js @@ -6,9 +6,36 @@ function setMaybeNick (input) { var match = /^\/nick\s+(.+)$/.exec(input); if (match) { nick = match[1]; + $('#nick').html(nick); } } +function getCurTime () { + date = new Date; + h = date.getHours(); + if(h<10) + { + h = "0"+h; + } + m = date.getMinutes(); + if(m<10) + { + m = "0"+m; + } + s = date.getSeconds(); + if(s<10) + { + s = "0"+s; + } + return ''+h+':'+m+':'+s; +}; + +$(function updateTime () { + $('#time').html(getCurTime()); + setTimeout(updateTime,'1000'); + return true; +}); + var nick; $(function connect() { @@ -26,7 +53,7 @@ $(function connect() { var safe_message = $('
').text(object.message).html(); safe_message = replaceURLWithHTMLLinks(safe_message); var safe_from = $('
').text(object.from).html(); - $(''+(new Date).getHours() + ':' + (new Date).getMinutes() + ':' + (new Date).getSeconds()+''+safe_from+''+safe_message+'').insertBefore('#foot'); + $(''+getCurTime()+''+safe_from+''+safe_message+'').insertBefore('#foot'); } catch (error) { console.log(error); diff --git a/webchat/public/reset.css b/webchat/public/reset.css index 2b67f153..931ab453 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -96,4 +96,7 @@ a { .chat_date:after { content: ""; padding-right: 4px; +} +#time { + color: #00FF00; } \ No newline at end of file -- cgit v1.2.3 From 2b8ec51abb846040efcbbb1d4c2b6d1e4b6bab01 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 13:32:56 +0100 Subject: webchat: refactored hello_web.js --- webchat/hello_web.js | 81 +++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 36 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 8e2a0bb8..076097f0 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -4,59 +4,68 @@ var sockjs = require('sockjs'); var connect = require('connect'); var irc = require('irc'); var Clients = []; -Clients.broadcast = function(object) { + +Clients.broadcast = function(object) { //broadcast to all clients Clients.forEach(function(client) { client.write(JSON.stringify(object)); }); } -var pingTimeoutDelay = 5*60*1000 -var lastping = setTimeout(reconnect, pingTimeoutDelay) -var irc_client = new irc.Client('irc.freenode.net', 'kweb', { - channels: ['#krebs'], - sasl: true, +var irc_reconnect = function() { //reconnt to irc + console.log("reconnecting due to pingtimeout"); + irc_client.disconnect(); + irc_client.connect(); +} + +var pingTimeoutDelay = 5*60*1000 +var lastping = setTimeout(irc_reconnect, pingTimeoutDelay) + +var irc_client = new irc.Client('irc.freenode.net', 'kweb', { //create irc_client to talk to irc + channels: ['#krebs'], //todo: read from local_config + sasl: true, secure: true, - userName: 'kweb', - realName: 'kweb', + userName: 'kweb', //todo: read from local_config + realName: 'kweb', //todo: read from local_config password: fs.readFileSync(__dirname+'/local_config/irc.key').toString(), - debug: true, + debug: false, showErrors: true, + floodProtection: true, port: 6697, autoRejoin: true, autoConnect: true, stripColors: true }); -var reconnect = function() { - console.log("reconnecting due to pingtimeout"); - irc_client.disconnect(); - irc_client.connect(); -} -irc_client.on('ping', function(server) { +irc_client.on('ping', function(server) { //restart timer on server ping console.log("got ping from server, renewing timeout for automatic reconnect"); clearTimeout(lastping); - lastping = setTimeout(reconnect, pingTimeoutDelay); + lastping = setTimeout(irc_reconnect, pingTimeoutDelay); //reconnect after irc timeout }) irc_client.on('message#krebs', function(from, message) { console.log({ from: from, message: message }); - Clients.broadcast({ from: from, message: message }); + Clients.broadcast({ from: from, message: message }); //broadcast irc messages to all connected clients clearTimeout(lastping); }); +var web_serv_options = { //certificates for https + key: fs.readFileSync(__dirname+'/local_config/server_npw.key'), + cert: fs.readFileSync(__dirname+'/local_config/server.crt'), +}; + var echo = sockjs.createServer(); echo.on('connection', function(conn) { var origin = conn.remoteAddress; Clients.push(conn); Clients.broadcast({from: 'system', message: origin + ' has joined'}) - irc_client.say("#krebs", origin + ' has joined'); - conn.write(JSON.stringify({from: 'system', message: 'hello'})) +// irc_client.say("#krebs", origin + ' has joined'); + conn.write(JSON.stringify({from: 'system', message: 'hello'})) //welcome message conn.on('data', function(data) { console.log('data:',data); try { var object = JSON.parse(data); - if (/^\/nick\s+(.+)$/.test(object.message)) { + if (/^\/nick\s+(.+)$/.test(object.message)) { //if nick is send use nick instead of ip object.from = origin; } else if (typeof object.nick === 'string') { object.from = object.nick; @@ -71,35 +80,35 @@ echo.on('connection', function(conn) { console.log(error); } }); -conn.on('close', function() { +conn.on('close', function() { //propagate if client quits the page Clients.splice(Clients.indexOf(conn)); Clients.broadcast({from: 'system', message: origin + ' has quit'}) - irc_client.say("#krebs", origin + ' has quit'); +// irc_client.say("#krebs", origin + ' has quit'); }); }); -var options = { - key: fs.readFileSync(__dirname+'/local_config/server_npw.key'), - cert: fs.readFileSync(__dirname+'/local_config/server.crt'), -}; var app = connect() .use(connect.logger('dev')) .use(connect.static(__dirname+'/public')) .use( function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); - res.write(''); - res.write(''); - res.write(''); - res.write(''); - res.write(''); - res.write('
'); - res.write('hello, this is the official krebs support:
'); - res.write('
'); - res.end('
'); + page_template='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='
'; + page_template+='
'; + page_template+='
'; + page_template+='hello, this is the official krebs support:
\n'; + page_template+='
\n'; + page_template+='
'; + page_template+='
'; + res.end(page_template); }) -var server = http.createServer(options, app); +var server = http.createServer(web_serv_options, app); echo.installHandlers(server, {prefix:'/echo'}); server.listen(1337, '0.0.0.0'); console.log('Server running at https://127.0.0.1:1337/'); -- cgit v1.2.3 From 7d45af90928ef9b1b4f6f7e316eb73f9a5ae0094 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 13:33:31 +0100 Subject: webchat: autoscroll --- webchat/public/client.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'webchat') diff --git a/webchat/public/client.js b/webchat/public/client.js index e7179449..ca71b537 100644 --- a/webchat/public/client.js +++ b/webchat/public/client.js @@ -52,8 +52,11 @@ $(function connect() { console.log(object.message); var safe_message = $('
').text(object.message).html(); safe_message = replaceURLWithHTMLLinks(safe_message); - var safe_from = $('
').text(object.from).html(); - $(''+getCurTime()+''+safe_from+''+safe_message+'').insertBefore('#foot'); + var safe_from = $('
').text(object.from).html(); + $(''+getCurTime()+''+safe_from+''+safe_message+'').insertBefore('#foot'); + + var elem = document.getElementById('chatter'); + elem.scrollTop = elem.scrollHeight; } catch (error) { console.log(error); -- cgit v1.2.3 From a8dcc8b3ce76916d3299956b64aa765cb8321482 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 13:33:42 +0100 Subject: webchat: better css --- webchat/public/reset.css | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'webchat') diff --git a/webchat/public/reset.css b/webchat/public/reset.css index 931ab453..3f9ecbb9 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -48,16 +48,13 @@ q:before, q:after { #chatbox { border-collapse: collapse; border-spacing: 0; - background-color: black; color: white; - border: 5px solid black; width: 100%; - height:100%; - opacity: 0.8; + vertical-align: bottom; } #input{ width: 100%; - background-color: black; + background-color: #555555; border: 1px solid black; color: white; } @@ -81,6 +78,12 @@ q:before, q:after { } #chatter { width: 75%; + height: 100%; + background-color: black; + opacity: 0.8; + overflow: auto; + overflow-x: hidden; + vertical-align: bottom; } .chat_date,.chat_from,.chat_msg{ } -- cgit v1.2.3 From f6a2242158fe17d33fbf9f292b1e930041bce1d7 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 13:41:15 +0100 Subject: webchat: no more empty messages --- webchat/hello_web.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 076097f0..4d420268 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -65,22 +65,24 @@ echo.on('connection', function(conn) { console.log('data:',data); try { var object = JSON.parse(data); - if (/^\/nick\s+(.+)$/.test(object.message)) { //if nick is send use nick instead of ip - object.from = origin; - } else if (typeof object.nick === 'string') { - object.from = object.nick; - } else { - object.from = origin; - }; - console.log(object.message); - irc_client.say("#krebs", object.from + ' → ' + object.message); - Clients.broadcast(object); + if (object.message.length > 0) { //if message is not empty + if (/^\/nick\s+(.+)$/.test(object.message)) { //if nick is send use nick instead of ip + object.from = origin; + } else if (typeof object.nick === 'string') { + object.from = object.nick; + } else { + object.from = origin; + }; + console.log(object.message); + irc_client.say("#krebs", object.from + ' → ' + object.message); + Clients.broadcast(object); + } } catch (error) { console.log(error); } }); -conn.on('close', function() { //propagate if client quits the page + conn.on('close', function() { //propagate if client quits the page Clients.splice(Clients.indexOf(conn)); Clients.broadcast({from: 'system', message: origin + ' has quit'}) // irc_client.say("#krebs", origin + ' has quit'); -- cgit v1.2.3 From a60cc6eb1b4007f67fe67c1b2865c73e2c8e45db Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 14:09:38 +0100 Subject: webchat: smaller timeout --- webchat/hello_web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 4d420268..9bcb70d0 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -17,7 +17,7 @@ var irc_reconnect = function() { //reconnt to irc irc_client.connect(); } -var pingTimeoutDelay = 5*60*1000 +var pingTimeoutDelay = 3*60*1000 var lastping = setTimeout(irc_reconnect, pingTimeoutDelay) var irc_client = new irc.Client('irc.freenode.net', 'kweb', { //create irc_client to talk to irc -- cgit v1.2.3 From 9cbb93099faebd80cc44d68c818fb9e4e985950e Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 14:10:04 +0100 Subject: webchat: now with links --- webchat/hello_web.js | 7 +++++-- webchat/public/reset.css | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index 9bcb70d0..da30f357 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -105,8 +105,11 @@ var app = connect() page_template+='
'; page_template+='hello, this is the official krebs support:
\n'; page_template+='
\n'; - page_template+='
'; - page_template+='
'; + page_template+='
'; + page_template+='
'; res.end(page_template); }) diff --git a/webchat/public/reset.css b/webchat/public/reset.css index 3f9ecbb9..c99fc307 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -102,4 +102,13 @@ a { } #time { color: #00FF00; +} +#sideboard { + position: absolute; + top: 0; + right: 0; + height: 100%; + width: 24%; + background-color: black; + opacity: 0.8; } \ No newline at end of file -- cgit v1.2.3 From 289c983910e86d0b6fa877724859345093da6d20 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 14:27:43 +0100 Subject: webchat: links layout and fix --- webchat/hello_web.js | 5 +++-- webchat/public/reset.css | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js index da30f357..8ef737fc 100644 --- a/webchat/hello_web.js +++ b/webchat/hello_web.js @@ -107,8 +107,9 @@ var app = connect() page_template+='
\n'; page_template+='
'; page_template+='
'; res.end(page_template); diff --git a/webchat/public/reset.css b/webchat/public/reset.css index c99fc307..65f68058 100644 --- a/webchat/public/reset.css +++ b/webchat/public/reset.css @@ -111,4 +111,9 @@ a { width: 24%; background-color: black; opacity: 0.8; +} +#links { + font-size: 14px; + position: absolute; + bottom: 5px; } \ No newline at end of file -- cgit v1.2.3 From 4915624169ef18312b83a480be74b4a039ccb9c3 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 7 Nov 2013 16:17:12 +0100 Subject: webchat: renamed hello_web to index.js --- webchat/hello_web.js | 120 --------------------------------------------------- webchat/index.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 120 deletions(-) delete mode 100644 webchat/hello_web.js create mode 100644 webchat/index.js (limited to 'webchat') diff --git a/webchat/hello_web.js b/webchat/hello_web.js deleted file mode 100644 index 8ef737fc..00000000 --- a/webchat/hello_web.js +++ /dev/null @@ -1,120 +0,0 @@ -var fs = require('fs'); -var http = require('https'); -var sockjs = require('sockjs'); -var connect = require('connect'); -var irc = require('irc'); -var Clients = []; - -Clients.broadcast = function(object) { //broadcast to all clients - Clients.forEach(function(client) { - client.write(JSON.stringify(object)); - }); -} - -var irc_reconnect = function() { //reconnt to irc - console.log("reconnecting due to pingtimeout"); - irc_client.disconnect(); - irc_client.connect(); -} - -var pingTimeoutDelay = 3*60*1000 -var lastping = setTimeout(irc_reconnect, pingTimeoutDelay) - -var irc_client = new irc.Client('irc.freenode.net', 'kweb', { //create irc_client to talk to irc - channels: ['#krebs'], //todo: read from local_config - sasl: true, - secure: true, - userName: 'kweb', //todo: read from local_config - realName: 'kweb', //todo: read from local_config - password: fs.readFileSync(__dirname+'/local_config/irc.key').toString(), - debug: false, - showErrors: true, - floodProtection: true, - port: 6697, - autoRejoin: true, - autoConnect: true, - stripColors: true -}); - - -irc_client.on('ping', function(server) { //restart timer on server ping - console.log("got ping from server, renewing timeout for automatic reconnect"); - clearTimeout(lastping); - lastping = setTimeout(irc_reconnect, pingTimeoutDelay); //reconnect after irc timeout -}) - -irc_client.on('message#krebs', function(from, message) { - console.log({ from: from, message: message }); - Clients.broadcast({ from: from, message: message }); //broadcast irc messages to all connected clients - clearTimeout(lastping); -}); - -var web_serv_options = { //certificates for https - key: fs.readFileSync(__dirname+'/local_config/server_npw.key'), - cert: fs.readFileSync(__dirname+'/local_config/server.crt'), -}; - -var echo = sockjs.createServer(); -echo.on('connection', function(conn) { - var origin = conn.remoteAddress; - Clients.push(conn); - Clients.broadcast({from: 'system', message: origin + ' has joined'}) -// irc_client.say("#krebs", origin + ' has joined'); - conn.write(JSON.stringify({from: 'system', message: 'hello'})) //welcome message - conn.on('data', function(data) { - console.log('data:',data); - try { - var object = JSON.parse(data); - if (object.message.length > 0) { //if message is not empty - if (/^\/nick\s+(.+)$/.test(object.message)) { //if nick is send use nick instead of ip - object.from = origin; - } else if (typeof object.nick === 'string') { - object.from = object.nick; - } else { - object.from = origin; - }; - console.log(object.message); - irc_client.say("#krebs", object.from + ' → ' + object.message); - Clients.broadcast(object); - } - - } catch (error) { - console.log(error); - } - }); - conn.on('close', function() { //propagate if client quits the page - Clients.splice(Clients.indexOf(conn)); - Clients.broadcast({from: 'system', message: origin + ' has quit'}) -// irc_client.say("#krebs", origin + ' has quit'); -}); -}); - - -var app = connect() - .use(connect.logger('dev')) - .use(connect.static(__dirname+'/public')) - .use( function (req, res) { - res.writeHead(200, {'Content-Type': 'text/html'}); - page_template='\n'; - page_template+='\n'; - page_template+='\n'; - page_template+='\n'; - page_template+='\n'; - page_template+='
'; - page_template+='
'; - page_template+='
'; - page_template+='hello, this is the official krebs support:
\n'; - page_template+='
\n'; - page_template+='
'; - page_template+='
'; - res.end(page_template); - - }) -var server = http.createServer(web_serv_options, app); -echo.installHandlers(server, {prefix:'/echo'}); -server.listen(1337, '0.0.0.0'); -console.log('Server running at https://127.0.0.1:1337/'); diff --git a/webchat/index.js b/webchat/index.js new file mode 100644 index 00000000..8ef737fc --- /dev/null +++ b/webchat/index.js @@ -0,0 +1,120 @@ +var fs = require('fs'); +var http = require('https'); +var sockjs = require('sockjs'); +var connect = require('connect'); +var irc = require('irc'); +var Clients = []; + +Clients.broadcast = function(object) { //broadcast to all clients + Clients.forEach(function(client) { + client.write(JSON.stringify(object)); + }); +} + +var irc_reconnect = function() { //reconnt to irc + console.log("reconnecting due to pingtimeout"); + irc_client.disconnect(); + irc_client.connect(); +} + +var pingTimeoutDelay = 3*60*1000 +var lastping = setTimeout(irc_reconnect, pingTimeoutDelay) + +var irc_client = new irc.Client('irc.freenode.net', 'kweb', { //create irc_client to talk to irc + channels: ['#krebs'], //todo: read from local_config + sasl: true, + secure: true, + userName: 'kweb', //todo: read from local_config + realName: 'kweb', //todo: read from local_config + password: fs.readFileSync(__dirname+'/local_config/irc.key').toString(), + debug: false, + showErrors: true, + floodProtection: true, + port: 6697, + autoRejoin: true, + autoConnect: true, + stripColors: true +}); + + +irc_client.on('ping', function(server) { //restart timer on server ping + console.log("got ping from server, renewing timeout for automatic reconnect"); + clearTimeout(lastping); + lastping = setTimeout(irc_reconnect, pingTimeoutDelay); //reconnect after irc timeout +}) + +irc_client.on('message#krebs', function(from, message) { + console.log({ from: from, message: message }); + Clients.broadcast({ from: from, message: message }); //broadcast irc messages to all connected clients + clearTimeout(lastping); +}); + +var web_serv_options = { //certificates for https + key: fs.readFileSync(__dirname+'/local_config/server_npw.key'), + cert: fs.readFileSync(__dirname+'/local_config/server.crt'), +}; + +var echo = sockjs.createServer(); +echo.on('connection', function(conn) { + var origin = conn.remoteAddress; + Clients.push(conn); + Clients.broadcast({from: 'system', message: origin + ' has joined'}) +// irc_client.say("#krebs", origin + ' has joined'); + conn.write(JSON.stringify({from: 'system', message: 'hello'})) //welcome message + conn.on('data', function(data) { + console.log('data:',data); + try { + var object = JSON.parse(data); + if (object.message.length > 0) { //if message is not empty + if (/^\/nick\s+(.+)$/.test(object.message)) { //if nick is send use nick instead of ip + object.from = origin; + } else if (typeof object.nick === 'string') { + object.from = object.nick; + } else { + object.from = origin; + }; + console.log(object.message); + irc_client.say("#krebs", object.from + ' → ' + object.message); + Clients.broadcast(object); + } + + } catch (error) { + console.log(error); + } + }); + conn.on('close', function() { //propagate if client quits the page + Clients.splice(Clients.indexOf(conn)); + Clients.broadcast({from: 'system', message: origin + ' has quit'}) +// irc_client.say("#krebs", origin + ' has quit'); +}); +}); + + +var app = connect() + .use(connect.logger('dev')) + .use(connect.static(__dirname+'/public')) + .use( function (req, res) { + res.writeHead(200, {'Content-Type': 'text/html'}); + page_template='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='\n'; + page_template+='
'; + page_template+='
'; + page_template+='
'; + page_template+='hello, this is the official krebs support:
\n'; + page_template+='
\n'; + page_template+='
'; + page_template+='
'; + res.end(page_template); + + }) +var server = http.createServer(web_serv_options, app); +echo.installHandlers(server, {prefix:'/echo'}); +server.listen(1337, '0.0.0.0'); +console.log('Server running at https://127.0.0.1:1337/'); -- cgit v1.2.3