Added default values to the README, added whitelist/blacklist
This commit is contained in:
parent
3715cfda6b
commit
d9fcccd753
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019
|
Copyright (c) 2019 Josua Robson
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
13
README.md
13
README.md
|
@ -15,3 +15,16 @@ An open source chat server for the chat client
|
||||||
- sqlite3
|
- sqlite3
|
||||||
- winston
|
- winston
|
||||||
- worker-farm
|
- worker-farm
|
||||||
|
|
||||||
|
# Settings file default format
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ips": {
|
||||||
|
"type": "blacklist",
|
||||||
|
"list": []
|
||||||
|
},
|
||||||
|
"register_on_fail": true,
|
||||||
|
"encryption_key_size": 16384,
|
||||||
|
"port": 22068
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
59
main.js
59
main.js
|
@ -307,8 +307,6 @@ function socket_init(socket, ondata)
|
||||||
sock.sock = socket;
|
sock.sock = socket;
|
||||||
sock.new = true;
|
sock.new = true;
|
||||||
|
|
||||||
console.log("Connection from "+socket.localAddress);
|
|
||||||
|
|
||||||
// Create the recieve ordered memory model
|
// Create the recieve ordered memory model
|
||||||
var recieve_ordered_memory = {
|
var recieve_ordered_memory = {
|
||||||
buffer: new Buffer.alloc(0),
|
buffer: new Buffer.alloc(0),
|
||||||
|
@ -394,6 +392,42 @@ var connections = [];
|
||||||
// Create a server
|
// Create a server
|
||||||
var server = net.createServer(function(socket)
|
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
|
// Setup the sock varible
|
||||||
var sock;
|
var sock;
|
||||||
|
|
||||||
|
@ -600,15 +634,16 @@ var server = net.createServer(function(socket)
|
||||||
sock.logged_in = false;
|
sock.logged_in = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set the default port
|
// Set some default settings
|
||||||
var port = 22068;
|
settings.port = settings.port || 22068;
|
||||||
|
settings.ips = settings.ips || {
|
||||||
// Is port set
|
type: "blacklist",
|
||||||
if(settings.port)
|
list: []
|
||||||
{
|
};
|
||||||
// Set the specified port
|
settings.ips.type = settings.ips.type || "blacklist";
|
||||||
port = settings.port;
|
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
|
// Listen for data
|
||||||
server.listen(port, '');
|
server.listen(settings.port, '');
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"encryption_key_size": 16384,
|
"ips": {
|
||||||
"register_on_fail": true,
|
"type": "whitelist",
|
||||||
"port": 22068
|
"list": [
|
||||||
|
"::ffff:127.0.0.1"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue