From fe1fced7e58004a68a80f0e495164283de300fe4 Mon Sep 17 00:00:00 2001 From: Marak Date: Thu, 12 Jun 2014 21:42:50 -0700 Subject: [PATCH] add optional http basic auth --- README.md | 1 + config.json | 3 +++ package.json | 3 ++- server.js | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97f4d07..b879bb8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Features * Define multiple glob patterns to find log files * List of log files refreshes automatically when new files are added * Live filtering when watching logs +* Authentication to restrict tail viewing Setup ----- diff --git a/config.json b/config.json index e114e2a..11f4986 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,7 @@ { + "basicAuth": false, + "user": "admin", + "password": "admin", "port": 8088, "files": [ { diff --git a/package.json b/package.json index 2035b20..6032aa4 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "flatiron": "~0.3.11", "glob": "~3.2.8", "union": "~0.3.8", - "moment": "~2.5.1" + "moment": "~2.5.1", + "connect": "2.19.6" } } diff --git a/server.js b/server.js index b2d5f7c..9bb02f1 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,7 @@ var moment = require('moment'); var Primus = require('primus.io'); var union = require('union'); +var connect = require('connect'); var ecstatic = require('ecstatic'); var flatiron = require('flatiron'); var app = flatiron.app; @@ -11,7 +12,21 @@ var app = flatiron.app; var tail = require('./lib/tail'); var config = require(__dirname + '/config.json'); -app.use(flatiron.plugins.http); +// If the basicAuth property has been set to true in config.json +// http basic auth is used to restrict access to all pages +// user and password properties are also set in the config.json +if (config.basicAuth) { + app.use(flatiron.plugins.http, { + before: [ + connect.basicAuth(function(user, pass){ + return config.user == user && config.password == pass; + }) + ] + }); +} else { + app.use(flatiron.plugins.http); +} + app.http.before.push(ecstatic(__dirname + '/public'));