files/
.users.json
.config.json
+.tokens.json
[5.2.0]
* Disable folder listing by default
* Do not render welcome screen if folder listing is enabled
+
+[5.3.0]
+* Replacing redis token store with local json file
"icon": "logo.png",
"addons": {
"ldap": {},
- "redis": {},
"localstorage": {}
},
"mediaLinks": [
"integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=",
"dev": true
},
- "double-ended-queue": {
- "version": "2.1.0-0",
- "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
- "integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
- },
"dtrace-provider": {
"version": "0.2.8",
"resolved": "https://registry.npmjs.org/dtrace-provider/-/dtrace-provider-0.2.8.tgz",
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.9.tgz",
"integrity": "sha1-PtqOZfI80qF+YTAbHwADOWr17No="
},
- "redis": {
- "version": "2.8.0",
- "resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
- "integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==",
- "requires": {
- "double-ended-queue": "2.1.0-0",
- "redis-commands": "1.3.1",
- "redis-parser": "2.6.0"
- }
- },
- "redis-commands": {
- "version": "1.3.1",
- "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.3.1.tgz",
- "integrity": "sha1-gdgm9F+pyLIBH0zXoP5ZfSQdRCs="
- },
- "redis-parser": {
- "version": "2.6.0",
- "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
- "integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
- },
"reduce-component": {
"version": "1.0.1",
"resolved": "http://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz",
"passport-http-bearer": "^1.0.1",
"passport-ldapjs": "^1.0.3",
"readline-sync": "^1.4.9",
- "redis": "^2.8.0",
"request": "^2.83.0",
"safetydance": "^0.1.1",
"serve-index": "^1.9.1",
files = require('./src/files.js')(path.resolve(__dirname, process.argv[2] || 'files'));
-var rootFolder = path.resolve(__dirname, process.argv[2] || 'files');
-var configFile = path.resolve(__dirname, process.argv[3] || '.config.json');
+const ROOT_FOLDER = path.resolve(__dirname, process.argv[2] || 'files');
+const CONFIG_FILE = path.resolve(__dirname, process.argv[3] || '.config.json');
// Ensure the root folder exists
-mkdirp.sync(rootFolder);
+mkdirp.sync(ROOT_FOLDER);
var config = {
folderListingEnabled: false
config.folderListingEnabled = !!req.body.folderListingEnabled;
- fs.writeFile(configFile, JSON.stringify(config), function (error) {
+ fs.writeFile(CONFIG_FILE, JSON.stringify(config), function (error) {
if (error) return next(new HttpError(500, 'unable to save settings'));
next(new HttpSuccess(201, {}));
// Load the config file
try {
- config = require(configFile);
+ console.log(`Using config file: ${CONFIG_FILE}`);
+ config = require(CONFIG_FILE);
} catch (e) {
- if (e.code === 'MODULE_NOT_FOUND') console.log(`Config file ${configFile} not found`);
- else console.log(`Cannot load config file ${configFile}`, e);
+ if (e.code === 'MODULE_NOT_FOUND') console.log(`Config file ${CONFIG_FILE} not found`);
+ else console.log(`Cannot load config file ${CONFIG_FILE}`, e);
}
if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = true;
app.use('/api', passport.session());
app.use(router);
app.use('/_admin', express.static(__dirname + '/frontend'));
-app.use('/', express.static(rootFolder));
+app.use('/', express.static(ROOT_FOLDER));
app.use('/', function welcomePage(req, res, next) {
if (config.folderListingEnabled || req.path !== '/') return next();
res.status(200).sendFile(path.join(__dirname, '/frontend/welcome.html'));
if (config.folderListingEnabled) return next();
res.sendFile(__dirname + '/frontend/404.html');
});
-app.use('/', serveIndex(rootFolder, { icons: true }));
+app.use('/', serveIndex(ROOT_FOLDER, { icons: true }));
app.use(lastMile());
var server = app.listen(3000, function () {
var port = server.address().port;
console.log('Surfer listening on http://%s:%s', host, port);
- console.log('Using base path', rootFolder);
+ console.log('Using base path', ROOT_FOLDER);
});
var passport = require('passport'),
path = require('path'),
safe = require('safetydance'),
+ fs = require('fs'),
bcrypt = require('bcryptjs'),
uuid = require('uuid/v4'),
- redis = require('redis'),
BearerStrategy = require('passport-http-bearer').Strategy,
LdapStrategy = require('passport-ldapjs').Strategy,
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess;
-var LOCAL_AUTH_FILE = path.resolve(process.env.LOCAL_AUTH_FILE || './.users.json');
+const LOCAL_AUTH_FILE = path.resolve(process.env.LOCAL_AUTH_FILE || './.users.json');
+const TOKENSTORE_FILE = path.resolve(process.env.TOKENSTORE_FILE || './.tokens.json');
var tokenStore = {
data: {},
+ save: function () {
+ try {
+ fs.writeFileSync(TOKENSTORE_FILE, JSON.stringify(tokenStore.data), 'utf-8');
+ } catch (e) {
+ console.error(`Unable to save tokenstore file at ${TOKENSTORE_FILE}`, e);
+ }
+ },
get: function (token, callback) {
callback(tokenStore.data[token] ? null : 'not found', tokenStore.data[token]);
},
set: function (token, data, callback) {
tokenStore.data[token] = data;
+ tokenStore.save();
callback(null);
},
del: function (token, callback) {
delete tokenStore.data[token];
+ tokenStore.save();
callback(null);
}
};
-if (process.env.REDIS_URL) {
- console.log('Enable redis token store');
-
- var redisClient = redis.createClient(process.env.REDIS_URL);
-
- if (process.env.REDIS_PASSWORD) {
- console.log('Using redis auth');
- redisClient.auth(process.env.REDIS_PASSWORD);
- }
-
- // overwrite the tokenStore api
- tokenStore.get = function (token, callback) {
- redisClient.get(token, function (error, result) {
- callback(error || null, safe.JSON.parse(result));
- });
- };
- tokenStore.set = function (token, data, callback) {
- redisClient.set(token, JSON.stringify(data), callback);
- };
- tokenStore.del = redisClient.del.bind(redisClient);
-} else {
- console.log('Use in-memory token store');
+// load token store data if any
+try {
+ console.log(`Using tokenstore file: ${TOKENSTORE_FILE}`);
+ tokenStore.data = JSON.parse(fs.readFileSync(TOKENSTORE_FILE, 'utf-8'));
+} catch (e) {
+ // start with empty token store
}
function issueAccessToken() {
var LDAP_USERS_BASE_DN = process.env.LDAP_USERS_BASE_DN;
if (LDAP_URL && LDAP_USERS_BASE_DN) {
- console.log('Enable ldap auth');
+ console.log('Using ldap auth');
exports.login = [ passport.authenticate('ldap'), issueAccessToken() ];
} else {
- console.log('Use local user file:', LOCAL_AUTH_FILE);
+ console.log(`Using local user file: ${LOCAL_AUTH_FILE}`);
exports.login = [
function (req, res, next) {
set -eu
export NODE_ENV=production
+export TOKENSTORE_FILE=/app/data/tokens.json
if [[ ! -d "/app/data/surfer_root" ]]; then
echo "=> Migrating root folder from /app/data to /app/data/surfer_root"