From 9168f9d5a8a6333e45309fdeabb2f71a368a5fce Mon Sep 17 00:00:00 2001 From: RblSb Date: Thu, 14 May 2020 01:14:10 +0300 Subject: Option to disable unregistered local admins --- src/server/HttpServer.hx | 6 ++++-- src/server/Main.hx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/server') diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx index 38cfcfe..aeabe2c 100644 --- a/src/server/HttpServer.hx +++ b/src/server/HttpServer.hx @@ -38,12 +38,14 @@ class HttpServer { static var customDir:String; static var hasCustomRes = false; static var allowedLocalFiles:Map = []; + static var allowLocalRequests = false; - public static function init(dir:String, ?customDir:String):Void { + public static function init(dir:String, ?customDir:String, allowLocalRequests:Bool):Void { HttpServer.dir = dir; if (customDir == null) return; HttpServer.customDir = customDir; hasCustomRes = FileSystem.exists(customDir); + HttpServer.allowLocalRequests = allowLocalRequests; } public static function serveFiles(req:IncomingMessage, res:ServerResponse):Void { @@ -51,7 +53,7 @@ class HttpServer { if (url == "/") url = "/index.html"; var filePath = dir + url; - if (req.connection.remoteAddress == req.connection.localAddress + if (allowLocalRequests && req.connection.remoteAddress == req.connection.localAddress || allowedLocalFiles[url]) { if (serveLocalFile(res, url)) return; } diff --git a/src/server/Main.hx b/src/server/Main.hx index b4fe68e..31ac1f9 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -87,7 +87,7 @@ class Main { }); final dir = '$rootDir/res'; - HttpServer.init(dir, '$rootDir/user/res'); + HttpServer.init(dir, '$rootDir/user/res', config.localAdmins); Lang.init('$dir/langs'); final server = Http.createServer((req, res) -> { @@ -238,7 +238,7 @@ class Main { final id = freeIds.length > 0 ? freeIds.shift() : clients.length; final name = 'Guest ${id + 1}'; trace('$name connected ($ip)'); - final isAdmin = req.connection.localAddress == ip; + final isAdmin = config.localAdmins && req.connection.localAddress == ip; final client = new Client(ws, req, id, name, 0); client.isAdmin = isAdmin; clients.push(client); -- cgit v1.2.3