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
|
||||
|
||||
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
|
||||
|
|
13
README.md
13
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
|
||||
}
|
||||
```
|
||||
|
|
59
main.js
59
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, '');
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"encryption_key_size": 16384,
|
||||
"register_on_fail": true,
|
||||
"port": 22068
|
||||
"ips": {
|
||||
"type": "whitelist",
|
||||
"list": [
|
||||
"::ffff:127.0.0.1"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue