diff --git a/LICENSE b/LICENSE index 8b23445..6e23713 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 +Copyright (c) 2019 Josua Robson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bef3292..1886134 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,16 @@ An open source chat server for the chat client - sqlite3 - winston - worker-farm + +# Settings file default format +```json +{ + "ips": { + "type": "blacklist", + "list": [] + }, + "register_on_fail": true, + "encryption_key_size": 16384, + "port": 22068 +} +``` diff --git a/main.js b/main.js index 203ee7d..cd8746c 100644 --- a/main.js +++ b/main.js @@ -307,8 +307,6 @@ function socket_init(socket, ondata) sock.sock = socket; sock.new = true; - console.log("Connection from "+socket.localAddress); - // Create the recieve ordered memory model var recieve_ordered_memory = { buffer: new Buffer.alloc(0), @@ -394,6 +392,42 @@ var connections = []; // Create a server var server = net.createServer(function(socket) { + console.log("Connection from "+socket.remoteAddress); + + // Is this a whitelist + if(settings.ips.type == "whitelist") + { + // Is the ip not in the whitelist + if(!settings.ips.list.includes(socket.remoteAddress)) + { + // Close the socket + socket.destroy(); + + // Tell the user + console.log("User at "+socket.remoteAddress+" failed. Reason: whitelist"); + + // Return + return; + } + } + + // Is this a blacklist + if(settings.ips.type == "blacklist") + { + // Is the ip in the blacklist + if(settings.ips.list.includes(socket.remoteAddress)) + { + // Close the socket + socket.destroy(); + + // Tell the user + console.log("User at "+socket.remoteAddress+" failed. Reason: blacklist"); + + // Return + return; + } + } + // Setup the sock varible var sock; @@ -600,15 +634,16 @@ var server = net.createServer(function(socket) sock.logged_in = false; }); -// Set the default port -var port = 22068; - -// Is port set -if(settings.port) -{ - // Set the specified port - port = settings.port; -} +// Set some default settings +settings.port = settings.port || 22068; +settings.ips = settings.ips || { + type: "blacklist", + list: [] +}; +settings.ips.type = settings.ips.type || "blacklist"; +settings.ips.list = settings.ips.list || []; +settings.register_on_fail = settings.register_on_fail || true; +settings.encryption_key_size = settings.encryption_key_size || 16384; // Listen for data -server.listen(port, ''); +server.listen(settings.port, ''); diff --git a/settings.json b/settings.json index 17ac4c4..f492b6c 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,8 @@ { - "encryption_key_size": 16384, - "register_on_fail": true, - "port": 22068 + "ips": { + "type": "whitelist", + "list": [ + "::ffff:127.0.0.1" + ] + } }