secure connections

This commit is contained in:
Evert Prants 2016-09-25 17:13:14 +03:00
parent bcc0b86ed9
commit f688465164
5 changed files with 29 additions and 6 deletions

View File

@ -8,3 +8,8 @@
default_quit_msg="Teemant IRC" default_quit_msg="Teemant IRC"
default_part_msg="Bye!" default_part_msg="Bye!"
secure_by_default=false secure_by_default=false
timeout=3000
encoding="utf-8"
[tls]
rejectUnauthorized=false

View File

@ -31,6 +31,8 @@
<input type="text" name="server" id="server" value="irc.icynet.ml"> <input type="text" name="server" id="server" value="irc.icynet.ml">
<label for="port">Port</label> <label for="port">Port</label>
<input type="number" name="port" id="port" value="6667"> <input type="number" name="port" id="port" value="6667">
<label for="secure">Secure connection</label>
Use SSL <input type="checkbox" name="secure" id="secure">
<input type="submit" value="Connect"> <input type="submit" value="Connect">
</form> </form>
</div> </div>

View File

@ -750,7 +750,7 @@ class IRCConnector {
server: server, server: server,
port: port, port: port,
password: null, password: null,
secure: false }); secure: clientdom.connector.secure.checked });
return true; return true;
} }
@ -1250,6 +1250,7 @@ window.onload = function() {
clientdom.connector['channel'] = clientdom.connector.form.querySelector('#channel'); clientdom.connector['channel'] = clientdom.connector.form.querySelector('#channel');
clientdom.connector['server'] = clientdom.connector.form.querySelector('#server'); clientdom.connector['server'] = clientdom.connector.form.querySelector('#server');
clientdom.connector['port'] = clientdom.connector.form.querySelector('#port'); clientdom.connector['port'] = clientdom.connector.form.querySelector('#port');
clientdom.connector['secure'] = clientdom.connector.form.querySelector('#secure');
clientdom['tabby'] = irc.primaryFrame.querySelector('.tabby') clientdom['tabby'] = irc.primaryFrame.querySelector('.tabby')
clientdom['frame'] = irc.primaryFrame.querySelector('#chat'); clientdom['frame'] = irc.primaryFrame.querySelector('#chat');
clientdom['letterbox'] = clientdom.frame.querySelector('.letterbox'); clientdom['letterbox'] = clientdom.frame.querySelector('.letterbox');

View File

@ -1,5 +1,6 @@
let EventEmitter = require('events').EventEmitter; let EventEmitter = require('events').EventEmitter;
let net = require('net'); let net = require('net');
let tls = require('tls');
let configuration = require(__dirname+"/config"); let configuration = require(__dirname+"/config");
let parse = require(__dirname+"/parser"); let parse = require(__dirname+"/parser");
let webirc = require(__dirname+"/webirc"); let webirc = require(__dirname+"/webirc");
@ -174,7 +175,7 @@ class IRCConnectionHandler {
case "NOTICE": case "NOTICE":
if(line.user.nickname != "") if(line.user.nickname != "")
this.conn.emit('pass_to_client', {type: "message", messageType: "notice", to: line.arguments[0], this.conn.emit('pass_to_client', {type: "message", messageType: "notice", to: line.arguments[0],
user: line.user, message: line.trailing, server: serverName}); user: line.user, message: line.trailing, server: serverName});
else else
this.conn.emit('pass_to_client', {type: "server_message", messageType: "notice", message: line.trailing, server: serverName, from: realServerName}); this.conn.emit('pass_to_client', {type: "server_message", messageType: "notice", message: line.trailing, server: serverName, from: realServerName});
break; break;
@ -357,7 +358,8 @@ class IRCConnection extends EventEmitter {
autojoin: [], autojoin: [],
secure: configuration.client.secure_by_default, secure: configuration.client.secure_by_default,
password: "", password: "",
address: "0.0.0.0" address: "0.0.0.0",
rejectUnauthorized: configuration.tls.rejectUnauthorized
}; };
this.userInfo = userInfo; this.userInfo = userInfo;
@ -379,6 +381,7 @@ class IRCConnection extends EventEmitter {
max_channel_length: 64, max_channel_length: 64,
supportedModes: {} supportedModes: {}
}; };
this.authorizationError = '';
this.queue = {}; this.queue = {};
} }
@ -391,13 +394,14 @@ class IRCConnection extends EventEmitter {
} }
connect() { connect() {
this.socket = net.createConnection(this.config.port, this.config.server, () => { this.socket = (this.config.secure ? tls : net).connect({port: this.config.port, host: this.config.server,
rejectUnauthorized: this.config.rejectUnauthorized}, () => {
this.connected = true; this.connected = true;
this.authenticate(); this.authenticate();
}); });
this.socket.setEncoding('utf8'); this.socket.setEncoding(configuration.client.encoding);
this.socket.setTimeout(3000); this.socket.setTimeout(configuration.client.timeout);
this.socket.on('error', (data) => { this.socket.on('error', (data) => {
this.emit('connerror', {type: "sock_error", message: "A socket error occured.", raw: data}); this.emit('connerror', {type: "sock_error", message: "A socket error occured.", raw: data});

View File

@ -109,6 +109,10 @@ io.sockets.on('connection', function (socket) {
newConnection.on('line', function(line) { newConnection.on('line', function(line) {
console.log("["+socket.id+"] <-", line); console.log("["+socket.id+"] <-", line);
}); });
newConnection.on('debug_log', function(data) {
console.log("["+socket.id+"] <-", data);
});
} }
newConnection.on('connerror', (data) => { newConnection.on('connerror', (data) => {
@ -123,6 +127,9 @@ io.sockets.on('connection', function (socket) {
inconnect = false; inconnect = false;
} }
if(config.server.debug)
console.log(data);
socket.emit('act_client', {type: (inconnect == true ? 'server_message' : 'connect_message'), server: connectiondata.server, message: message, error: true}); socket.emit('act_client', {type: (inconnect == true ? 'server_message' : 'connect_message'), server: connectiondata.server, message: message, error: true});
}); });
@ -136,6 +143,10 @@ io.sockets.on('connection', function (socket) {
if(newConnection.authenticated == false) { if(newConnection.authenticated == false) {
message = "Failed to connect to the server!"; message = "Failed to connect to the server!";
if(config.server.debug)
console.log(data);
inconnect = false; inconnect = false;
} }