feat(nodejs): control access to forgotten page using config variable

This commit is contained in:
Serik Ibragimov
2024-04-22 15:47:58 +05:00
parent 39a61835ea
commit a722b142bb
5 changed files with 28 additions and 6 deletions

View File

@ -37,6 +37,7 @@ const users = require('./helpers/users');
const configServer = config.get('server'); const configServer = config.get('server');
const siteUrl = configServer.get('siteUrl'); const siteUrl = configServer.get('siteUrl');
const enableForgotten = configServer.get('enableForgotten');
const fileChoiceUrl = configServer.has('fileChoiceUrl') ? configServer.get('fileChoiceUrl') : ''; const fileChoiceUrl = configServer.has('fileChoiceUrl') ? configServer.get('fileChoiceUrl') : '';
const cfgSignatureEnable = configServer.get('token.enable'); const cfgSignatureEnable = configServer.get('token.enable');
const cfgSignatureUseForRequest = configServer.get('token.useforrequest'); const cfgSignatureUseForRequest = configServer.get('token.useforrequest');
@ -99,6 +100,7 @@ app.get('/', (req, res) => { // define a handler for default page
users, users,
languages: configServer.get('languages'), languages: configServer.get('languages'),
serverVersion: config.get('version'), serverVersion: config.get('version'),
enableForgotten,
}); });
} catch (ex) { } catch (ex) {
console.log(ex); // display error message in the console console.log(ex); // display error message in the console
@ -108,6 +110,15 @@ app.get('/', (req, res) => { // define a handler for default page
}); });
app.get('/forgotten', async (req, res) => { app.get('/forgotten', async (req, res) => {
if (!enableForgotten) {
res.status(403);
res.render(
'error',
{ message: 'The forgotten page is disabled.' }
);
return;
}
function getForgottenList() { function getForgottenList() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
documentService.commandRequest('getForgottenList', '', (err, data, ress) => { documentService.commandRequest('getForgottenList', '', (err, data, ress) => {
@ -152,6 +163,11 @@ app.get('/forgotten', async (req, res) => {
}); });
app.delete('/forgotten', (req, res) => { // define a handler for removing forgotten file app.delete('/forgotten', (req, res) => { // define a handler for removing forgotten file
if (!enableForgotten) {
res.sendStatus(403);
return;
}
try { try {
const fileName = req.query.filename; const fileName = req.query.filename;
if (fileName && typeof fileName === 'string') { // if the forgotten file name is defined if (fileName && typeof fileName === 'string') { // if the forgotten file name is defined

View File

@ -26,6 +26,7 @@
"storagePath": "/files", "storagePath": "/files",
"maxFileSize": 1073741824, "maxFileSize": 1073741824,
"maxNameLength": 50, "maxNameLength": 50,
"enableForgotten": true,
"mobileRegEx": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", "mobileRegEx": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"token": { "token": {
"enable": false, "enable": false,

View File

@ -85,6 +85,7 @@ exports.registerRoutes = function registerRoutes(app) {
editedExts, editedExts,
fillExts, fillExts,
languages: configServer.get('languages'), languages: configServer.get('languages'),
enableForgotten: configServer.get('enableForgotten'),
}); });
} catch (ex) { } catch (ex) {
console.log(ex); // display error message in the console console.log(ex); // display error message in the console

View File

@ -120,9 +120,11 @@
<li> <li>
<a href="wopi">Wopi</a> <a href="wopi">Wopi</a>
</li> </li>
<li> <% if (enableForgotten) { %>
<a href="forgotten">Forgotten files</a> <li>
</li> <a href="forgotten">Forgotten files</a>
</li>
<% } %>
</menu> </menu>
<div id="portal-info" style="display: <%= storedFiles.length > 0 ? "none" : "table-cell" %>"> <div id="portal-info" style="display: <%= storedFiles.length > 0 ? "none" : "table-cell" %>">
<span class="portal-name">ONLYOFFICE Document Editors Welcome!</span> <span class="portal-name">ONLYOFFICE Document Editors Welcome!</span>

View File

@ -111,9 +111,11 @@
<li class="active"> <li class="active">
<a href="wopi">Wopi</a> <a href="wopi">Wopi</a>
</li> </li>
<li> <% if (enableForgotten) { %>
<a href="forgotten">Forgotten files</a> <li>
</li> <a href="forgotten">Forgotten files</a>
</li>
<% } %>
</menu> </menu>
<div id="portal-info" style="display: <%= storedFiles.length > 0 ? "none" : "table-cell" %>"> <div id="portal-info" style="display: <%= storedFiles.length > 0 ? "none" : "table-cell" %>">
<% if (!wopiEnable) <% if (!wopiEnable)