diff --git a/config.js b/config.js index ba7df15..2d06f53 100644 --- a/config.js +++ b/config.js @@ -168,15 +168,22 @@ Config.prototype.Application = function(app) { var domain = req.headers.host.split(':')[0]; // Set the parameters mapping res.locals.mapping = parameters.vhost[domain]; - res.locals.view_dir = __dirname + '/sites/' + res.locals.mapping + '/views'; - - next(); - }); - // Set favicon if is enabled in configuration parameters - if (parameters.favicon) { - app.use(express.favicon(__dirname + parameters.favicon)); - } + // Check if site exists, otherwise send error + if(res.locals.mapping) { + // Set the view directory + res.locals.view_dir = __dirname + '/sites/' + res.locals.mapping + '/views'; + // Set favicon if is enabled in configuration parameters + if (misc_params[res.locals.mapping].favicon) { + app.use(express.favicon(__dirname + '/sites/' + res.locals.mapping + misc_params[res.locals.mapping].favicon)); + } + next(); + + } else { + utils.applog('error', "Requested and invalid site from: " + req.connection.remoteAddress); + res.send(parameters.server_error); + } + }); // maintenance mode middleware app.use(function (req, res, next) { @@ -236,6 +243,10 @@ Config.prototype.Application = function(app) { // Set the default locals app.use(function(req, res, next){ + // Set guest role + if (!req.session.role) { + req.session.role = 1000; + } res.locals.title = misc_params[res.locals.mapping].title; res.locals.site_url = misc_params[res.locals.mapping].site_url; res.locals.session = req.session; diff --git a/lib/hbs.js b/lib/hbs.js index 6f35eef..4d36f15 100644 --- a/lib/hbs.js +++ b/lib/hbs.js @@ -1,3 +1,11 @@ +/* + * MuContent + * + * This library is based on hbs library: + * Allow multisiste view system + * + */ + // builtin var fs = require('fs'); @@ -77,8 +85,9 @@ exports.__express = function(filename, options, cb) { if (options.layout !== undefined && !options.layout) { return render_file(options, cb); } -/*console.log(options.mapping); -console.log(options.settings);*/ + + // This allow the view path for multiste, in options you can find res.locals variable + // For example: options.mapping var view_dir = options.settings.views; var layout_filename = path.join(view_dir, options.layout || 'layout' + extension); diff --git a/params.js b/params.js index 952ff16..10e3d33 100644 --- a/params.js +++ b/params.js @@ -33,6 +33,9 @@ module.exports = { // Mapping the vhost and sites: domain -> site name references vhost: { "localhost": 'default', -// "www.pinco.net": 'pinco' + "www.pinco.net": 'pinco' }, + + // Error for site not found or other + server_error: "Sorry, server error, please contact: ", }; diff --git a/sites/default/settings/menu.js b/sites/default/settings/menu.js index 95bbd03..b84ac8e 100644 --- a/sites/default/settings/menu.js +++ b/sites/default/settings/menu.js @@ -14,6 +14,7 @@ module.exports = { // title is the handler in the locales files to get the title based on language // Examples: // {title: "search", path: "/test", acl: {0: true, 1: false}}, // If you set acl, you resticted the role +// {title: "search", path: "/test", acl: {1000: true}}, // role 1000 identify guests // {title: "you", path: "/you", icon: "icon-off"} // If you don't set acl, all can access ] diff --git a/sites/default/settings/route.js b/sites/default/settings/route.js index d4b7c57..2718fbc 100644 --- a/sites/default/settings/route.js +++ b/sites/default/settings/route.js @@ -13,7 +13,8 @@ module.exports = { /* Example: {route: '/logout', acl: {0: true, 1: true}}, // Put in route the same route defined in express.js, for example, a route with params: + {route: '/objects/edit/:id', acl: {0: true, 1: true}, ajax: true}, */ - ], // Role legend: 0 (admin), 1 (user), add other if you want and modify the defaults + ], // Role legend: 0 (admin), 1 (user), 1000 (guest), add other if you want and modify the defaults };