app.locals repalced

This commit is contained in:
2026-04-28 12:51:46 +02:00
parent d84ee90cd2
commit 9ffea9ee45
7 changed files with 109 additions and 98 deletions

View File

@@ -20,7 +20,6 @@ module.exports = {
releaseNotes: new HotReload(path.join(localPath.source, 'models', 'releasenotes.json')),
configuration: new HotReload(path.join(localPath.source, 'models', 'configuration.json')),
stylesheet: new HotReload(path.join(localPath.source, 'models', 'stylesheet.json')),
indexRoutes: new HotReload(path.join(localPath.source, 'routes', 'indexRoutes.js'), { historyLimit: 50, fileType: 'js' }),
startMenuItems: new HotReload(path.join(localPath.source, 'models', 'integratedStartMenuItems.json'))
},
}

View File

@@ -15,45 +15,24 @@ const { on } = require('cluster');
// const { start } = require('repl');
// const WebSocket = require('ws');
//#endregion
require('module-alias/register'); // define paths in package.json
process.env.TZ = 'Europe/Berlin';
const { localPath, cache, runtimeFile } = require('@root/globalize.js');
//#region Paths
app.locals.path = {
root: dirname(require.main.filename),
plugins: `${dirname(require.main.filename)}/plugins`,
public: `${dirname(require.main.filename)}/public`,
source: `${dirname(require.main.filename)}/src`,
}
//#endregion
process.env.TZ = 'Europe/Berlin';
//#region Nesessary json files
const jsonFiles = ['configuration.json', 'stylesheet.json'];
for (var i = 0; i < jsonFiles.length; i++) {
if(!fs.existsSync(`${app.locals.path.source}/models/${jsonFiles[i]}`)) {
fs.copyFileSync(`${app.locals.path.source}/backups/${jsonFiles[i]}.temp`, `${app.locals.path.source}/models/${jsonFiles[i]}`);
if(!fs.existsSync(`${localPath.source}/models/${jsonFiles[i]}`)) {
fs.copyFileSync(`${localPath.source}/backups/${jsonFiles[i]}.temp`, `${localPath.source}/models/${jsonFiles[i]}`);
}
}
app.locals.stylesheet = JSON.parse(fs.readFileSync(`${app.locals.path.source}/models/stylesheet.json`, 'utf-8'));
app.locals.configuration = JSON.parse(fs.readFileSync(`${app.locals.path.source}/models/configuration.json`, 'utf-8'));
app.locals.package = JSON.parse(fs.readFileSync(`${app.locals.path.root}/package.json`, 'utf-8'));
app.locals.startMenuItems = [ ];
(async () => {
// const server = https.createServer({
// key: fs.readFileSync(`${app.locals.path.source}/secure/${app.locals.configuration.certificate.key}`),
// cert: fs.readFileSync(`${app.locals.path.source}/secure/${app.locals.configuration.certificate.chain}`),
// pfx: fs.readFileSync(`${app.locals.path.source}/secure/${app.locals.configuration.certificate.pfx}`),
// passphrase: "password",
// //cert: fs.readFileSync(`${app.locals.path.source}/secure/${app.locals.configuration.certificate.chain}`),
// }, app);
const securePath = `${app.locals.path.source}/secure`;
const certConfig = app.locals.configuration.certificate;
const securePath = `${localPath.source}/secure`;
const certConfig = runtimeFile.configuration.live.certificate;
let httpsOptions = {};
@@ -105,9 +84,9 @@ const server = https.createServer(httpsOptions, app);
await service.get('socketManager').addAsync('admin');
service.set('sqlManager', new SqlManager());
service.get('sqlManager').addInstance('main', app.locals.configuration.integration.sql.connect);
service.get('sqlManager').addInstance('main', runtimeFile.configuration.live.integration.sql.connect);
databaseModel.set('eventlog', require(`${app.locals.path.source}/models/eventlogModel`)(service.get('sqlManager').getInstance('main')));
databaseModel.set('eventlog', require(`${localPath.source}/models/eventlogModel`)(service.get('sqlManager').getInstance('main')));
databaseModel.set('eventlogView', require(`@models/eventlogView`)(service.get('sqlManager').getInstance('main')));
service.set('eventManager', new EventManager(app, databaseModel.get('eventlog'), databaseModel.get('eventlogView'), service.get('socketManager')));
@@ -136,22 +115,22 @@ const server = https.createServer(httpsOptions, app);
databaseModel.set('rolePermissionsModel', require(`@models/rolePermissionsModel`)(service.get('sqlManager').getInstance('main')));
service.set('rbacManager', new RBACManager(databaseModel));
service.set('authenticationManager', new AuthenticationManager(databaseModel.get('authentication'), app.locals.configuration.integration.token.secret));
service.set('authenticationManager', new AuthenticationManager(databaseModel.get('authentication'), runtimeFile.configuration.live.integration.token.secret));
service.set('activeDirectoryManager', new ActiveDirectory(app.locals.configuration.integration.activedirectory))
service.set('activeDirectoryManager', new ActiveDirectory(runtimeFile.configuration.live.integration.activedirectory))
// everytime last created service!
service.set('pluginManager', new PluginManager(app, databaseModel.get('plugin'), app.locals.path.plugins, app.locals.configuration.plugin.chown, service));
service.set('pluginManager', new PluginManager(app, databaseModel.get('plugin'), localPath.plugins, runtimeFile.configuration.live.plugin.chown, service));
exports.databaseModel = databaseModel;
exports.service = service;
exports.path = app.locals.path;
exports.path = localPath;
//#endregion
//#region Service-Registration/Middleware/Utils/Helpers
require(`${app.locals.path.root}/utils.js`);
let helpers = service.get('fileSystemManager').loadAllFiles(`${app.locals.path.public}/helpers`, '.js');
require(`${localPath.root}/utils.js`);
let helpers = service.get('fileSystemManager').loadAllFiles(`${localPath.public}/helpers`, '.js');
exports.helpers = helpers;
// app.use(service.get('vaultifyManager').createMiddleware());
@@ -160,17 +139,17 @@ const server = https.createServer(httpsOptions, app);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cookieParser());
app.use(favicon(`${app.locals.path.public}/images/radix_os_icon.ico`));
app.use(favicon(`${localPath.public}/images/radix_os_icon.ico`));
app.use(express.static(app.locals.path.root));
app.use(express.static(app.locals.path.public));
app.use(express.static(app.locals.path.source));
app.use(express.static(localPath.root));
app.use(express.static(localPath.public));
app.use(express.static(localPath.source));
app.use(function(request, response, next) {
if (!request.secure) {
return response.redirect("https://" + request.headers.host + request.url + app.locals.configuration.server.port);
return response.redirect("https://" + request.headers.host + request.url + runtimeFile.configuration.live.server.port);
}
next(); // Http redirection to secure protocol
})
@@ -180,8 +159,8 @@ const server = https.createServer(httpsOptions, app);
//#region App config values
app.set('view engine', '.hbs');
app.set('views', [
`${app.locals.path.public}/views`,
`${app.locals.path.public}/views/integrated`
`${localPath.public}/views`,
`${localPath.public}/views/integrated`
]);
app.set('trust proxy', true)
//#endregion
@@ -196,13 +175,13 @@ const server = https.createServer(httpsOptions, app);
app.engine('hbs', create({
extname: 'hbs',
helpers: helpers,
partialsDir: `${app.locals.path.public}/views/partials`,
layoutsDir: `${app.locals.path.public}/views/layouts`,
defaultLayout: `${app.locals.path.public}/views/layouts/default.hbs`
partialsDir: `${localPath.public}/views/partials`,
layoutsDir: `${localPath.public}/views/layouts`,
defaultLayout: `${localPath.public}/views/layouts/default.hbs`
}).engine)
server.listen(app.locals.configuration.server.port, () => {
server.listen(runtimeFile.configuration.live.server.port, () => {
(async () => {
const databaseTest = await service.get('sqlManager').test("main"); // Check if database connection is established
service.get('eventManager').write(null, databaseTest.levelId, null, databaseTest.message);
@@ -223,15 +202,15 @@ const server = https.createServer(httpsOptions, app);
//#region Implement routes
require(`${app.locals.path.source}/routes/loginRoutes.js`).route(app, service); // #1 - no token security! important: first!!!
require(`${app.locals.path.source}/routes/indexRoutes.js`).route(app, service); // #2 - token security enabled at this point
require(`${app.locals.path.source}/routes/adminRoutes.js`).route(app, service); // #3 - token security always enabled
require(`${localPath.source}/routes/loginRoutes.js`).route(app, service); // #1 - no token security! important: first!!!
require(`${localPath.source}/routes/indexRoutes.js`).route(app, service); // #2 - token security enabled at this point
require(`${localPath.source}/routes/adminRoutes.js`).route(app, service); // #3 - token security always enabled
//#endregion
app.use(service.get('rbacManager').authenticate());
//#region Implements sockets
require(`${app.locals.path.source}/sockets/mainSocket.js`)(
require(`${localPath.source}/sockets/mainSocket.js`)(
app,
service.get('socketManager'),
'/',
@@ -241,7 +220,7 @@ const server = https.createServer(httpsOptions, app);
service.get('eventManager'),
service.get('activeDirectoryManager')
);
require(`${app.locals.path.source}/sockets/adminSocket.js`)(
require(`${localPath.source}/sockets/adminSocket.js`)(
app,
service.get('socketManager'),
'admin',
@@ -253,11 +232,11 @@ const server = https.createServer(httpsOptions, app);
setTimeout(() => {
service.get('eventManager').write(null, 1, null,
`${app.locals.configuration.server.name} is running`,
`fqdn: https://${os.hostname()}:${app.locals.configuration.server.port}/`,
`${runtimeFile.configuration.live.server.name} is running`,
`fqdn: https://${os.hostname()}:${runtimeFile.configuration.live.server.port}/`,
`process id: ${process.pid}`,
`url: ${os.hostname()}`,
`port: ${app.locals.configuration.server.port}`
`port: ${runtimeFile.configuration.live.server.port}`
)
}, 1000);
});

View File

@@ -15,7 +15,8 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
},
{
"label": "Configs",
@@ -30,7 +31,8 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
},
{
"label": "RBAC",
@@ -46,9 +48,15 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
}
]
},
"onlyAdministration": false,
"defaultSize": {
"width": "900px",
"height": "900px"
}
},
{
@@ -71,9 +79,15 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
}
]
},
"onlyAdministration": false,
"defaultSize": {
"width": "1200px",
"height": "1200px"
}
},
{
@@ -96,9 +110,15 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
}
]
},
"onlyAdministration": false,
"defaultSize": {
"width": "900px",
"height": "800px"
}
},
{
@@ -121,10 +141,12 @@
"scope": "SYSTEM",
"action": "Administration"
}
]
],
"authorized": true
}
]
}
},
"onlyAdministration": false
},
{
"section": "Benutzer",
@@ -146,9 +168,15 @@
"scope": "SYSTEM",
"action": "Default_Access"
}
]
],
"authorized": true
}
]
},
"onlyAdministration": false,
"defaultSize": {
"width": "460px",
"height": "515px"
}
},
{
@@ -167,9 +195,15 @@
"scope": "SYSTEM",
"action": "Default_Access"
}
]
],
"authorized": true
}
]
},
"onlyAdministration": false,
"defaultSize": {
"width": 800,
"height": 600
}
}
]

View File

@@ -4,8 +4,8 @@ const path = require('path');
const { renderWindow } = require('@services/renderWindow.js');
const { service } = require('@root/server.js');
const { File: HotReload } = require(`@services/hotReload.js`);
const { localPath, cache, runtimeFile } = require('@root/globalize.js');
const { doesNotReject } = require('assert');
// let startMenuItemContext = require('@models/integratedStartmenuItems.js')
@@ -16,15 +16,14 @@ module.exports = {
res.render('desktop', { layout: 'default', startMenuItems: startMenuItems });
});
app.post('/api/open_app', (req, res) => {
const { name, view, viewLabel, location, size, state, zIndex } = req.body;
const pluginPath = path.join(global.path.plugins, name, 'plugin.json');
const pluginPath = path.join(localPath.plugins, name, 'plugin.json');
let context = fs.existsSync(pluginPath)
? service.get('fileSystemManager').loadJSON(pluginPath)
: (JSON.parse(JSON.stringify(global.json.startMenuItems.live))).find(item => item.name == name);
: runtimeFile.startMenuItems.live.find(item => item.name == name);
context.defaultSize =
context.menu.items.find(item => item.label == viewLabel)?.defaultSize ||
@@ -34,8 +33,6 @@ module.exports = {
res.json({ name, view, viewLabel, context, location, size, state, zIndex });
});
app.get('/api/NotifyTray/getTrays', async (req, res) => {
const objectGuid = req.cookies.ObjectGUID;
// console.log(await service.get('notifyTray').getOpenNotifications(objectGuid))
@@ -99,7 +96,7 @@ module.exports = {
});
app.get('/api/help/getTabs', async (req, res) => {
const tabNames = (await startMenuItems(app, req.cookies.sAMAccountName))
const tabNames = cache.startMenuItems
.filter(plugin => plugin.active && plugin.menu.items.some(i => i.authorized))
.map(plugin => ({ name: plugin.menu.label }));
res.status(200).json(tabNames);
@@ -107,7 +104,7 @@ module.exports = {
app.post('/api/help/getHelp', async (req, res) => {
const { name } = req.body;
const props = (await startMenuItems(app, req.cookies.sAMAccountName))
const props = cache.startMenuItems
.filter(plugin => plugin.name === name && plugin.active && plugin.menu.items.some(i => i.authorized))
.map(async plugin => (
{

View File

@@ -1,4 +1,5 @@
const { Op } = require('sequelize');
const { localPath, cache, runtimeFile } = require('@root/globalize.js');
/**
* Custom event logging class
*
@@ -27,8 +28,8 @@ class EventManager {
async write(objectGuid, levelId, pluginName = null, ...args) {
const err = new Error();
const stackLine = args[0].stack !== undefined ? args[0].stack : err.stack.split('\n')[2]; // calls trace-line
//const trace = stackLine.split("\n") !== undefined ? stackLine.split("\n")[1].trim() : stackLine.match(/\/.*\d+/)[0].replace(this.app.locals.path.root, '') || ''; // path:line:column
const trace = stackLine?.split("\n")?.[1]?.trim() ?? stackLine?.match(/\/.*\d+/)?.[0]?.replace(this.app.locals.path.root, '') ?? '';
//const trace = stackLine.split("\n") !== undefined ? stackLine.split("\n")[1].trim() : stackLine.match(/\/.*\d+/)[0].replace(this.localPath.root, '') || ''; // path:line:column
const trace = stackLine?.split("\n")?.[1]?.trim() ?? stackLine?.match(/\/.*\d+/)?.[0]?.replace(localPath.root, '') ?? '';
// const message = !Array.isArray(...args) ? [...args][0] : [...args][0][0]
const message = args[0].stack !== undefined ? args[0].message : args.join('\r\n\t');
@@ -48,7 +49,7 @@ class EventManager {
this.socketManager.broadcast('admin', 'eventlog_table', newLogEntry);
}
if(this.app.locals.configuration.debug.active && levelId >= this.app.locals.configuration.debug.levelId) {
if(runtimeFile.configuration.live.debug.active && levelId >= runtimeFile.configuration.live.debug.levelId) {
this.socketManager.broadcast('admin', 'eventlog', { levelId: levelId, pluginName: pluginName, datetime: `[${dateFormat(new Date(), 'yyyy-mm-dd HH:MM:SS')}]`, trace: `[${trace}]`, message: message })
}
@@ -68,7 +69,7 @@ class EventManager {
async writeLog(objectGuid, levelId, pluginName = null, ...args) {
const err = new Error();
const stackLine = args[0].stack !== undefined ? args[0].stack : err.stack.split('\n')[2]; // calls trace-line
const trace = args[0].stack !== undefined ? stackLine.split("\n")[1].trim() : stackLine.match(/\/.*\d+/)[0].replace(this.app.locals.path.root, ''); // path:line:column
const trace = args[0].stack !== undefined ? stackLine.split("\n")[1].trim() : stackLine.match(/\/.*\d+/)[0].replace(localPath.root, ''); // path:line:column
// const message = !Array.isArray(...args) ? [...args][0] : [...args][0][0]
const message = args[0].stack !== undefined ? args[0].message : args.join('\r\n\t');
@@ -98,7 +99,7 @@ class EventManager {
async clear() {
const err = new Error();
const stackLine = err.stack.split('\n')[2]; // calls trace-line
const trace = stackLine.match(/\/.*\d+/)[0].replace(this.app.locals.path.root, ''); // path:line:column
const trace = stackLine.match(/\/.*\d+/)[0].replace(localPath.root, ''); // path:line:column
const message = `${this.EventLog.tableName} cleared successfully`;
await this.EventLog.destroy({

View File

@@ -1,11 +1,12 @@
const { service } = require('@root/server.js');
const { localPath, cache, runtimeFile } = require('@root/globalize.js');
module.exports = {
renderWindow: async function(app, view, data = {}, extraData = {}, res) {
const name = res.req.body.name;
const label = res.req.body.viewLabel;
try {
const plugin = app.locals.startMenuItems.find(plugin => plugin.name == name);
const plugin = cache.startMenuItems.find(plugin => plugin.name == name);
const windowData = plugin.menu.items.find(item => item.label == label);
// Alle Daten zusammenführen

View File

@@ -1,31 +1,30 @@
const { exec } = require('child_process');
const path = require('path');
const { permission } = require('process');
const { dirname } = require('path');
const { File: HotReload } = require(`@services/hotReload.js`);
const { service } = require(`@root/server.js`);
const { json } = require('body-parser');
const { localPath, cache, runtimeFile } = require('@root/globalize.js');
// let integratedStartmenuItems = require('@models/integratedStartmenuItems');
global.path = {
root: dirname(require.main.filename),
source:`${dirname(require.main.filename)}/src`,
public: `${dirname(require.main.filename)}/public`,
plugins: `${dirname(require.main.filename)}/plugins`
};
// global.path = {
// root: dirname(require.main.filename),
// source:`${dirname(require.main.filename)}/src`,
// public: `${dirname(require.main.filename)}/public`,
// plugins: `${dirname(require.main.filename)}/plugins`
// };
global.json = {
releaseNotes: new HotReload(path.join(global.path.source, 'models', 'releasenotes.json')),
configuration: new HotReload(path.join(global.path.source, 'models', 'configuration.json')),
stylesheet: new HotReload(path.join(global.path.source, 'models', 'stylesheet.json')),
indexRoutes: new HotReload(path.join(global.path.source, 'routes', 'indexRoutes.js'), { historyLimit: 50, fileType: 'js' }),
startMenuItems: new HotReload(path.join(global.path.source, 'models', 'integratedStartMenuItems.json'))
}
// global.json = {
// releaseNotes: new HotReload(path.join(global.path.source, 'models', 'releasenotes.json')),
// configuration: new HotReload(path.join(global.path.source, 'models', 'configuration.json')),
// stylesheet: new HotReload(path.join(global.path.source, 'models', 'stylesheet.json')),
// indexRoutes: new HotReload(path.join(global.path.source, 'routes', 'indexRoutes.js'), { historyLimit: 50, fileType: 'js' }),
// startMenuItems: new HotReload(path.join(global.path.source, 'models', 'integratedStartMenuItems.json'))
// }
module.exports = startMenuItems = async function (app, objectGuid) {
const debug = global.json.configuration.live.debug.startMenuItems;
const debug = runtimeFile.configuration.live.debug.startMenuItems;
let logContent = [];
function safeClone(obj) {
@@ -39,9 +38,10 @@ module.exports = startMenuItems = async function (app, objectGuid) {
// =========================
// Load menu sources
// =========================
const integratedStartmenuItems =
service.get('fileSystemManager')
.loadJSON(global.json.startMenuItems.filePath) || [];
const integratedStartmenuItems = runtimeFile.startMenuItems.live;
// const integratedStartmenuItems =
// service.get('fileSystemManager')
// .loadJSON(global.json.startMenuItems.filePath) || [];
const plugins = service
.get('pluginManager')
@@ -149,7 +149,7 @@ module.exports = startMenuItems = async function (app, objectGuid) {
allPlugins = allPlugins
.filter(p => !p.onlyAdministration)
.filter(p => p.active);
app.locals.startMenuItems = allPlugins;
cache.startMenuItems = allPlugins;
if(debug) {
service.get('eventManager').writeLog(objectGuid, 0, 'StartMenuItems', logContent);
}