diff options
| author | RblSb <msrblsb@gmail.com> | 2020-05-14 01:14:10 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-05-14 01:14:10 +0300 |
| commit | 9168f9d5a8a6333e45309fdeabb2f71a368a5fce (patch) | |
| tree | c36664e9bd9eda5e3208b17a3ee7c5f6bddd4851 /src/server | |
| parent | 2ac659cb17ada55286bed44913cb8479ed1f9288 (diff) | |
Option to disable unregistered local admins
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/HttpServer.hx | 6 | ||||
| -rw-r--r-- | src/server/Main.hx | 4 |
2 files changed, 6 insertions, 4 deletions
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<String, Bool> = []; + 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); |
