Skip to content

Commit

Permalink
moved dfsdetect to protected urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewiski committed Apr 18, 2024
1 parent 15d128b commit 645dfb2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
35 changes: 19 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var defaultConfig = {
"logDirectory": "logs",
"adminRoute": "/admin",
"logLevel": "info",
"redirectClientsToCRMOnLogin": true,
"useHttp": true,
"useHttps": false,
"httpport": 49080,
Expand Down Expand Up @@ -446,7 +447,7 @@ var handlePluginPublicFileRequest = function (req, res) {



var handlePublicFileRequest = function (req, res) {
var handlePublicFileRequest = function (req, res, next) {
var filePath = req.path;

if (filePath === "/" && urlPrefix !== "") {
Expand All @@ -462,7 +463,7 @@ var handlePublicFileRequest = function (req, res) {

if(filePath.endsWith("scriptsettings.json")){
let scriptSettings = {
urlPrefix: urlPrefix,
urlPrefix: urlPrefix
}
res.json(scriptSettings);
return;
Expand Down Expand Up @@ -516,23 +517,22 @@ var handlePublicFileRequest = function (req, res) {

let fileExt = path.extname(filePath);
if( filePath.includes("/api/") == false && (fileExt === "" || fileExt === ".htm" || fileExt === ".html")){
if(commonData.menutItemsRefreshed === undefined || moment().diff(commonData.menutItemsRefreshed, 'minutes') > 5){
uispToolsApiHandler.getMenuItems({})
}else{

}

filePath = "/index.htm";
res.sendFile(filePath, { root: path.join(__dirname, 'public') });
}else{
res.sendStatus(404);
if (uispToolsApiRequestHandler.checkForRedirect(req, res) == false){
res.sendStatus(404);
}

}
}

} ;



uispToolsApiRequestHandler.bindRoutes(routes);
uispToolsApiRequestHandler.bindRoutes({"express": app});



Expand Down Expand Up @@ -608,13 +608,7 @@ routes.get('/' + urlPrefix + 'plugins/*', function (req, res) {
handlePluginPublicFileRequest(req, res);
});

routes.get('/*', function (req, res) {
handlePublicFileRequest(req, res);
});

routes.get('/' + urlPrefix + '*', function (req, res) {
handlePublicFileRequest(req, res);
});


app.use('/', pluginRoutes);
Expand All @@ -624,8 +618,17 @@ app.use('/', pluginRoutes);
app.use('/', routes);


routes.get('/*', function (req, res, next) {

handlePublicFileRequest(req, res,next);

});


if(urlPrefix !== ""){
routes.get('/' + urlPrefix + '*', function (req, res) {
handlePublicFileRequest(req, res);
});
}


var io = null;
Expand Down
10 changes: 9 additions & 1 deletion uispToolsApiHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,15 @@ var UispToolsApiHandler = function (options) {
projections : { linkText: 1, linkUrl: 1, linkTarget: 1, pageContentGuid: 1, roleId: 1, contentType: 1, parentPageContentGuid: 1} ,
sort: [['displayOrder', 1 ]['parentPageContentGuid', 1 ]]
};

if(options.find){
fetchOptions.find = options.find;
}
if(options.projections){
fetchOptions.projections = options.projections;
}
if(options.sort){
fetchOptions.sort = options.sort;
}
if(options.menuGuid){
fetchOptions.find.menuGuid = options.menuGuid;
}
Expand Down
53 changes: 47 additions & 6 deletions uispToolsApiRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const appName = "uispToolsApiRequestHandler";
const extend = require('extend');
const Defer = require('node-promise').defer;

const express = require('express');

var moment = require('moment');

Expand All @@ -16,7 +16,8 @@ var UispToolsApiRequestHandler = function (options) {
logUtilHelper:null,
uispToolsApiHandler: null,
urlPrefix: "",
allowDirectUispQuerys: false
allowDirectUispQuerys: false,
routes: null
};

self.options = extend({}, defaultOptions, options);
Expand Down Expand Up @@ -50,9 +51,12 @@ var UispToolsApiRequestHandler = function (options) {



var BindRoutes = function (routes) {
var BindRoutes = function (options) {

try {
self.options.app = options.express
self.options.routes = express.Router();
let routes = self.options.routes;

routes.get('/' + self.options.urlPrefix + 'api/PageContent/MenuItems', getMenuItems);
routes.get('/' + self.options.urlPrefix + 'api/PageContent/PageContentGuid/:guid', getPageByPageContentGuid);
Expand Down Expand Up @@ -90,13 +94,49 @@ var UispToolsApiRequestHandler = function (options) {
routes.delete('/' + self.options.urlPrefix + 'api/crm/*', getCRMData);
routes.delete('/' + self.options.urlPrefix + 'api/nms/*', getNMSData);
}
self.options.app.use('/', routes);

} catch (ex) {
debug("error", ex.msg, ex.stack);
}

}


var checkForRedirect = function (req, res, next) {
try {
let fetchOptions = {
find: { deleted: false, contentType: { $eq: "redirect" }, linkUrl: req.path},
projections : { linkUrl: 1, contentType: 1, content: 1},
sort: [['displayOrder', 1 ]['parentPageContentGuid', 1 ]]
}
self.options.uispToolsApiHandler.getMenuItems(fetchOptions).then(
function (menuItems) {
for (let i = 0; i < menuItems.length; i++) {
var menuItem = menuItems[i];
res.redirect(menuItem.content);
return true;
}
if(next !== undefined || next !== null){
next();
}
return false;
},
function (error) {
debug("error", "BindRoutes getMenuItems", error);
if(next !== undefined || next !== null){
next();
}
return false;
}
);
} catch (ex) {
debug("error", "checkForRedirect", { "msg": ex.message, "stack": ex.stack });
if(next !== undefined || next !== null){
next();
}
return false;
}
}

var getAnonymousClientSideSettings = function(req, res, next){
try {
Expand Down Expand Up @@ -617,8 +657,8 @@ var getMenuItems = function (req, res, next) {
try {
let options = {}
self.options.uispToolsApiHandler.getMenuItems(options).then(
function (docs) {
res.json(docs);
function (menuItems) {
res.json(menuItems);
},
function(err){
handleHttpRequestError(req, res, err);
Expand Down Expand Up @@ -674,6 +714,7 @@ var getMenuItems = function (req, res, next) {
self.checkSuperAdminApiAccess = checkSuperAdminApiAccess;
self.nmsApiQuery = nmsApiQuery;
self.crmApiQuery = crmApiQuery;
self.checkForRedirect = checkForRedirect;

};
module.exports = UispToolsApiRequestHandler;

0 comments on commit 645dfb2

Please sign in to comment.