mirror of https://github.com/calzoneman/sync.git
Fix a bug with IP forwarding
This commit is contained in:
parent
e6150301b1
commit
7aac0a0f9f
|
@ -18,6 +18,15 @@ exports.WEBSERVER_PORT = 8080; // Webserver port. Binding port 80 requires root
|
|||
exports.MAX_PER_IP = 10;
|
||||
exports.GUEST_LOGIN_DELAY = 60; // Seconds
|
||||
|
||||
/*
|
||||
Set to true if you are behind a reverse proxy (e.g. Cloudflare)
|
||||
so that client IPs are passed through correctly.
|
||||
|
||||
If you are not behind a reverse proxy, leave it as false, otherwise
|
||||
clients can fake their IP address in the x-forwarded-for header
|
||||
*/
|
||||
exports.REVERSE_PROXY = false;
|
||||
|
||||
var nodemailer = require("nodemailer");
|
||||
exports.MAIL = false;
|
||||
/* Example for setting up email:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.3",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
24
server.js
24
server.js
|
@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const VERSION = "2.0.2";
|
||||
const VERSION = "2.0.3";
|
||||
|
||||
var fs = require("fs");
|
||||
var Logger = require("./logger.js");
|
||||
|
@ -36,16 +36,16 @@ app.get("/api/:apireq(*)", function(req, res, next) {
|
|||
});
|
||||
|
||||
function getClientIP(req) {
|
||||
var ip;
|
||||
var ip = false;
|
||||
var raw = req.connection.remoteAddress;
|
||||
var forward = req.header("x-forwarded-for");
|
||||
if(forward) {
|
||||
if(Config.REVERSE_PROXY && forward) {
|
||||
ip = forward.split(",")[0];
|
||||
}
|
||||
if(!ip) {
|
||||
ip = req.connection.remoteAddress;
|
||||
}
|
||||
Logger.syslog.log("/" + ip + " is proxied by /" + raw);
|
||||
return ip;
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
app.get("/nws/connect", function(req, res, next) {
|
||||
var socket = NWS.newConnection(req, res);
|
||||
|
@ -128,7 +128,15 @@ fs.exists("chanlogs", function(exists) {
|
|||
});
|
||||
|
||||
function getSocketIP(socket) {
|
||||
return socket.handshake.headers["x-forwarded-for"] || socket.handshake.address.address;
|
||||
var raw = socket.handshake.address.address;
|
||||
if(Config.REVERSE_PROXY) {
|
||||
if(typeof socket.handshake.headers["x-forwarded-for"] == "string") {
|
||||
var ip = socket.handshake.headers["x-forwarded-for"].split(",")[0];
|
||||
Logger.syslog.log("/" + ip + " is proxied by /" + raw);
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
return socket.handshake.address.address;
|
||||
}
|
||||
|
||||
exports.io.sockets.on("connection", function(socket) {
|
||||
|
|
Loading…
Reference in New Issue