mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Refactored settings page.
This commit is contained in:
parent
20a4eb0f8f
commit
ab802c0683
39 changed files with 472 additions and 470 deletions
|
@ -12,7 +12,7 @@ process.on('unhandledRejection', (err) => { throw err; });
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const querystring = require('querystring');
|
||||
import {settings} from '../node/utils/Settings';
|
||||
import settings from '../node/utils/Settings';
|
||||
const supertest = require('supertest');
|
||||
|
||||
(async () => {
|
||||
|
|
|
@ -49,7 +49,7 @@ const unescape = (val) => {
|
|||
const fs = require('fs');
|
||||
const log4js = require('log4js');
|
||||
const readline = require('readline');
|
||||
import {settings} from '../node/utils/Settings';
|
||||
import settings from '../node/utils/Settings';
|
||||
const ueberDB = require('ueberdb2');
|
||||
|
||||
const dbWrapperSettings = {
|
||||
|
|
|
@ -14,7 +14,7 @@ process.on('unhandledRejection', (err) => { throw err; });
|
|||
|
||||
const dirtyDb = require('dirty');
|
||||
const log4js = require('log4js');
|
||||
import {settings} from '../node/utils/Settings';
|
||||
import settings from '../node/utils/Settings';
|
||||
const ueberDB = require('ueberdb2');
|
||||
const util = require('util');
|
||||
|
||||
|
@ -22,7 +22,7 @@ process.on('unhandledRejection', (err) => { throw err; });
|
|||
cache: '0', // The cache slows things down when you're mostly writing.
|
||||
writeInterval: 0, // Write directly to the database, don't buffer
|
||||
};
|
||||
const db = new ueberDB.database( // eslint-disable-line new-cap
|
||||
const db = new ueberDB.Database( // eslint-disable-line new-cap
|
||||
settings.dbType,
|
||||
settings.dbSettings,
|
||||
dbWrapperSettings,
|
||||
|
|
|
@ -19,7 +19,7 @@ let valueCount = 0;
|
|||
|
||||
(async () => {
|
||||
// initialize database
|
||||
import {settings} from '../node/utils/Settings';
|
||||
import settings from '../node/utils/Settings';
|
||||
const db = require('../node/db/DB');
|
||||
await db.init();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ const AttributePool = require('../../static/js/AttributePool');
|
|||
const Stream = require('../utils/Stream');
|
||||
const assert = require('assert').strict;
|
||||
const db = require('./DB');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const authorManager = require('./AuthorManager');
|
||||
const padManager = require('./PadManager');
|
||||
const padMessageHandler = require('../handler/PadMessageHandler');
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
const CustomError = require('../utils/customError');
|
||||
const Pad = require('../db/Pad');
|
||||
const db = require('./DB');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
|
||||
/**
|
||||
* A cache of all loaded Pads.
|
||||
|
|
|
@ -24,7 +24,7 @@ const hooks = require('../../static/js/pluginfw/hooks.js');
|
|||
const padManager = require('./PadManager');
|
||||
const readOnlyManager = require('./ReadOnlyManager');
|
||||
const sessionManager = require('./SessionManager');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const webaccess = require('../hooks/express/webaccess');
|
||||
const log4js = require('log4js');
|
||||
const authLogger = log4js.getLogger('auth');
|
||||
|
|
|
@ -25,7 +25,7 @@ import fs from 'fs';
|
|||
const hooks = require('../../static/js/pluginfw/hooks.js');
|
||||
import path from 'path';
|
||||
import resolve from 'resolve';
|
||||
import {root, settings} from '../utils/Settings'
|
||||
import settings from '../utils/Settings'
|
||||
|
||||
const templateCache = new Map();
|
||||
|
||||
|
@ -76,7 +76,7 @@ exports.require = (name: string, args: any, mod: any) => {
|
|||
basedir = path.dirname(mod.filename);
|
||||
paths = mod.paths;
|
||||
}
|
||||
paths.push(root + '/plugin_packages')
|
||||
paths.push(settings.root + '/plugin_packages')
|
||||
|
||||
const ejspath = resolve.sync(name, {paths, basedir, extensions: ['.html', '.ejs']});
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ const exporthtml = require('../utils/ExportHtml');
|
|||
const exporttxt = require('../utils/ExportTxt');
|
||||
const exportEtherpad = require('../utils/ExportEtherpad');
|
||||
const fs = require('fs');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const os = require('os');
|
||||
const hooks = require('../../static/js/pluginfw/hooks');
|
||||
const util = require('util');
|
||||
|
|
|
@ -25,7 +25,7 @@ const padManager = require('../db/PadManager');
|
|||
const padMessageHandler = require('./PadMessageHandler');
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const {Formidable} = require('formidable');
|
||||
const os = require('os');
|
||||
const importHtml = require('../utils/ImportHtml');
|
||||
|
|
|
@ -28,7 +28,7 @@ const AttributeManager = require('../../static/js/AttributeManager');
|
|||
const authorManager = require('../db/AuthorManager');
|
||||
const {padutils} = require('../../static/js/pad_utils');
|
||||
const readOnlyManager = require('../db/ReadOnlyManager');
|
||||
import {abiwordAvailable, exportAvailable, randomVersionString, settings, sofficeAvailable} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const securityManager = require('../db/SecurityManager');
|
||||
const plugins = require('../../static/js/pluginfw/plugin_defs.js');
|
||||
const log4js = require('log4js');
|
||||
|
@ -930,7 +930,7 @@ const handleClientReady = async (socket, message) => {
|
|||
const clientVars = {
|
||||
skinName: settings.skinName,
|
||||
skinVariants: settings.skinVariants,
|
||||
randomVersionString: randomVersionString,
|
||||
randomVersionString: settings.randomVersionString,
|
||||
accountPrivs: {
|
||||
maxRevisions: 100,
|
||||
},
|
||||
|
@ -964,9 +964,9 @@ const handleClientReady = async (socket, message) => {
|
|||
serverTimestamp: Date.now(),
|
||||
sessionRefreshInterval: settings.cookie.sessionRefreshInterval,
|
||||
userId: sessionInfo.author,
|
||||
abiwordAvailable: abiwordAvailable(),
|
||||
sofficeAvailable: sofficeAvailable(),
|
||||
exportAvailable: exportAvailable(),
|
||||
abiwordAvailable: settings.abiwordAvailable(),
|
||||
sofficeAvailable: settings.sofficeAvailable(),
|
||||
exportAvailable: settings.exportAvailable(),
|
||||
plugins: {
|
||||
plugins: plugins.plugins,
|
||||
parts: plugins.parts,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
const log4js = require('log4js');
|
||||
import {settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const stats = require('../../node/stats')
|
||||
|
||||
const logger = log4js.getLogger('socket.io');
|
||||
|
|
|
@ -14,7 +14,7 @@ import fs from 'fs';
|
|||
const hooks = require('../../static/js/pluginfw/hooks');
|
||||
import log4js from 'log4js';
|
||||
const SessionStore = require('../db/SessionStore');
|
||||
import {getEpVersion, getGitCommit, settings} from '../utils/Settings';
|
||||
import settings from '../utils/Settings';
|
||||
const stats = require('../stats')
|
||||
import util from 'util';
|
||||
const webaccess = require('./express/webaccess');
|
||||
|
@ -68,9 +68,9 @@ const closeServer = async () => {
|
|||
exports.createServer = async () => {
|
||||
console.log('Report bugs at https://github.com/ether/etherpad-lite/issues');
|
||||
|
||||
serverName = `Etherpad ${getGitCommit()} (https://etherpad.org)`;
|
||||
serverName = `Etherpad ${settings.getGitCommit()} (https://etherpad.org)`;
|
||||
|
||||
console.log(`Your Etherpad version is ${getEpVersion()} (${getGitCommit()})`);
|
||||
console.log(`Your Etherpad version is ${settings.getEpVersion()} (${settings.getGitCommit()})`);
|
||||
|
||||
await exports.restartServer();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import {QueryType} from "../../types/QueryType";
|
|||
import {PluginType} from "../../types/Plugin";
|
||||
|
||||
const eejs = require('../../eejs');
|
||||
import {getEpVersion, getGitCommit} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
const installer = require('../../../static/js/pluginfw/installer');
|
||||
const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
|
||||
const plugins = require('../../../static/js/pluginfw/plugins');
|
||||
|
@ -24,8 +24,8 @@ exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Functi
|
|||
});
|
||||
|
||||
args.app.get('/admin/plugins/info', (req:any, res:any) => {
|
||||
const gitCommit = getGitCommit();
|
||||
const epVersion = getEpVersion();
|
||||
const gitCommit = settings.getGitCommit();
|
||||
const epVersion = settings.getEpVersion();
|
||||
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins-info.html', {
|
||||
gitCommit,
|
||||
|
|
|
@ -4,7 +4,7 @@ const eejs = require('../../eejs');
|
|||
const fsp = require('fs').promises;
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
const plugins = require('../../../static/js/pluginfw/plugins');
|
||||
import {reloadSettings, settings} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
|
||||
exports.expressCreateServer = (hookName:string, {app}:any) => {
|
||||
app.get('/admin/settings', (req:any, res:any) => {
|
||||
|
@ -44,7 +44,7 @@ exports.socketio = (hookName:string, {io}:any) => {
|
|||
|
||||
socket.on('restartServer', async () => {
|
||||
console.log('Admin request to restart server through a socket on /admin/settings');
|
||||
reloadSettings();
|
||||
settings.reloadSettings();
|
||||
await plugins.update();
|
||||
await hooks.aCallAll('loadSettings', {settings});
|
||||
await hooks.aCallAll('restartServer');
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import {ArgsExpressType} from "../../types/ArgsExpressType";
|
||||
|
||||
const hasPadAccess = require('../../padaccess');
|
||||
import {exportAvailable, settings} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
const exportHandler = require('../../handler/ExportHandler');
|
||||
const importHandler = require('../../handler/ImportHandler');
|
||||
const padManager = require('../../db/PadManager');
|
||||
|
@ -35,7 +35,7 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
|
|||
}
|
||||
|
||||
// if abiword is disabled, and this is a format we only support with abiword, output a message
|
||||
if (exportAvailable() === 'no' &&
|
||||
if (settings.exportAvailable() === 'no' &&
|
||||
['odt', 'pdf', 'doc'].indexOf(req.params.type) !== -1) {
|
||||
console.error(`Impossible to export pad "${req.params.pad}" in ${req.params.type} format.` +
|
||||
' There is no converter configured');
|
||||
|
|
|
@ -24,7 +24,7 @@ const cloneDeep = require('lodash.clonedeep');
|
|||
const createHTTPError = require('http-errors');
|
||||
|
||||
const apiHandler = require('../../handler/APIHandler');
|
||||
import {settings} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
|
||||
const log4js = require('log4js');
|
||||
const logger = log4js.getLogger('API');
|
||||
|
|
|
@ -6,7 +6,7 @@ const events = require('events');
|
|||
const express = require('../express');
|
||||
const log4js = require('log4js');
|
||||
const proxyaddr = require('proxy-addr');
|
||||
import {settings} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
import {Server} from 'socket.io'
|
||||
const socketIORouter = require('../../handler/SocketIORouter');
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
|
|
|
@ -6,7 +6,7 @@ const fs = require('fs');
|
|||
const fsp = fs.promises;
|
||||
const toolbar = require('../../utils/toolbar');
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
import {getEpVersion, root, settings} from '../../utils/Settings';
|
||||
import settings from '../../utils/Settings';
|
||||
const util = require('util');
|
||||
const webaccess = require('./webaccess');
|
||||
|
||||
|
@ -17,7 +17,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
res.set('Content-Type', 'application/health+json');
|
||||
res.json({
|
||||
status: 'pass',
|
||||
releaseId: getEpVersion(),
|
||||
releaseId: settings.getEpVersion(),
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -31,11 +31,11 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
|
||||
app.get('/robots.txt', (req, res) => {
|
||||
let filePath =
|
||||
path.join(root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
|
||||
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
|
||||
res.sendFile(filePath, (err) => {
|
||||
// there is no custom robots.txt, send the default robots.txt which dissallows all
|
||||
if (err) {
|
||||
filePath = path.join(root, 'src', 'static', 'robots.txt');
|
||||
filePath = path.join(settings.root, 'src', 'static', 'robots.txt');
|
||||
res.sendFile(filePath);
|
||||
}
|
||||
});
|
||||
|
@ -54,9 +54,9 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
|
||||
|
||||
const fns = [
|
||||
...(settings.favicon ? [path.resolve(root, settings.favicon)] : []),
|
||||
path.join(root, 'src', 'static', 'skins', settings.skinName, 'favicon.ico'),
|
||||
path.join(root, 'src', 'static', 'favicon.ico'),
|
||||
...(settings.favicon ? [path.resolve(settings.root, settings.favicon)] : []),
|
||||
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'favicon.ico'),
|
||||
path.join(settings.root, 'src', 'static', 'favicon.ico'),
|
||||
];
|
||||
for (const fn of fns) {
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,7 @@ const fs = require('fs').promises;
|
|||
const minify = require('../../utils/Minify');
|
||||
const path = require('path');
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
import {root, settings} from '../../utils/Settings';
|
||||
import {settings} from '../../utils/Settings';
|
||||
const CachingMiddleware = require('../../utils/caching_middleware');
|
||||
const Yajsml = require('etherpad-yajsml');
|
||||
|
||||
|
@ -18,7 +18,7 @@ const getTar = async () => {
|
|||
return `ep_etherpad-lite/static/js/${path}`;
|
||||
}
|
||||
};
|
||||
const tarJson = await fs.readFile(path.join(root, 'src/node/utils/tar.json'), 'utf8');
|
||||
const tarJson = await fs.readFile(path.join(settings.root, 'src/node/utils/tar.json'), 'utf8');
|
||||
const tar = {};
|
||||
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) {
|
||||
// @ts-ignore
|
||||
|
|
|
@ -4,7 +4,7 @@ const path = require('path');
|
|||
const fsp = require('fs').promises;
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
const sanitizePathname = require('../../utils/sanitizePathname');
|
||||
import {root, settings} from '../../utils/Settings';
|
||||
import {settings} from '../../utils/Settings';
|
||||
|
||||
// Returns all *.js files under specDir (recursively) as relative paths to specDir, using '/'
|
||||
// instead of path.sep to separate pathname components.
|
||||
|
@ -57,7 +57,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
})().catch((err) => next(err || new Error(err)));
|
||||
});
|
||||
|
||||
const rootTestFolder = path.join(root, 'src/tests/frontend/');
|
||||
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
||||
|
||||
app.get('/tests/frontend/index.html', (req, res) => {
|
||||
res.redirect(['./', ...req.url.split('?').slice(1)].join('?'));
|
||||
|
|
|
@ -9,7 +9,7 @@ const path = require('path');
|
|||
const _ = require('underscore');
|
||||
const pluginDefs = require('../../static/js/pluginfw/plugin_defs.js');
|
||||
const existsSync = require('../utils/path_exists');
|
||||
import {settings, root} from '../utils/Settings';
|
||||
import {settings} from '../utils/Settings';
|
||||
|
||||
// returns all existing messages merged together and grouped by langcode
|
||||
// {es: {"foo": "string"}, en:...}
|
||||
|
@ -40,7 +40,7 @@ const getAllLocales = () => {
|
|||
};
|
||||
|
||||
// add core supported languages first
|
||||
extractLangs(path.join(root, 'src/locales'));
|
||||
extractLangs(path.join(settings.root, 'src/locales'));
|
||||
|
||||
// add plugins languages (if any)
|
||||
for (const {package: {path: pluginPath}} of Object.values<I18nPluginDefs>(pluginDefs.plugins)) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export type SettingsObj = {
|
||||
root: string;
|
||||
settingsFilename: string;
|
||||
credentialsFilename: string;
|
||||
title: string;
|
||||
|
@ -111,4 +112,14 @@ export type SettingsObj = {
|
|||
enableAdminUITests: boolean;
|
||||
lowerCasePadIds: boolean;
|
||||
randomVersionString: string;
|
||||
getEpVersion: ()=>string;
|
||||
abiwordAvailable: ()=>string;
|
||||
sofficeAvailable: ()=>string;
|
||||
exportAvailable: ()=>string;
|
||||
getGitCommit: ()=>string;
|
||||
storeSettings: (newSettings: SettingsObj)=>void;
|
||||
coerceValue: (stringVal: string)=> string | number | boolean | null | undefined;
|
||||
lookupEnvironmentVariables: (settings: SettingsObj)=>SettingsObj;
|
||||
parseSettings: (settingsFilename: string, isSettings: boolean) => any;
|
||||
reloadSettings: ()=>void;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {root, settings} from './Settings';
|
||||
import {settings} from './Settings';
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const plugins = require('../../static/js/pluginfw/plugin_defs');
|
||||
|
@ -33,7 +33,7 @@ const sanitizePathname = require('./sanitizePathname');
|
|||
|
||||
const logger = log4js.getLogger('Minify');
|
||||
|
||||
const ROOT_DIR = path.join(root, 'src/static/');
|
||||
const ROOT_DIR = path.join(settings.root, 'src/static/');
|
||||
|
||||
const threadsPool = new Threads.Pool(() => Threads.spawn(new Threads.Worker('./MinifyWorker')), 2);
|
||||
|
||||
|
|
|
@ -78,9 +78,9 @@ const initLogging = (config: any) => {
|
|||
initLogging(defaultLogConfig(defaultLogLevel));
|
||||
|
||||
|
||||
export const root = absolutePaths.findEtherpadRoot()
|
||||
|
||||
const root = absolutePaths.findEtherpadRoot();
|
||||
export const settings: SettingsObj = {
|
||||
root: absolutePaths.findEtherpadRoot(),
|
||||
settingsFilename: absolutePaths.makeAbsolute(argv.settings || 'settings.json'),
|
||||
credentialsFilename: absolutePaths.makeAbsolute(argv.credentials || 'credentials.json'),
|
||||
/**
|
||||
|
@ -403,35 +403,27 @@ export const settings: SettingsObj = {
|
|||
* e.g. /p/EtHeRpAd to /p/etherpad
|
||||
*/
|
||||
lowerCasePadIds: false,
|
||||
randomVersionString: randomString(4)
|
||||
}
|
||||
|
||||
/* Root path of the installation */
|
||||
logger.info('All relative paths will be interpreted relative to the identified ' +
|
||||
`Etherpad base dir: ${root}`);
|
||||
|
||||
|
||||
|
||||
// checks if abiword is avaiable
|
||||
export const abiwordAvailable = () => {
|
||||
randomVersionString: randomString(4),
|
||||
// Return etherpad version from package.json
|
||||
getEpVersion:()=>require('../../package.json').version,
|
||||
// checks if abiword is avaiable
|
||||
abiwordAvailable: () => {
|
||||
if (settings.abiword != null) {
|
||||
return os.type().indexOf('Windows') !== -1 ? 'withoutPDF' : 'yes';
|
||||
} else {
|
||||
return 'no';
|
||||
}
|
||||
};
|
||||
|
||||
export const sofficeAvailable = () => {
|
||||
},
|
||||
sofficeAvailable: () => {
|
||||
if (settings.soffice != null) {
|
||||
return os.type().indexOf('Windows') !== -1 ? 'withoutPDF' : 'yes';
|
||||
} else {
|
||||
return 'no';
|
||||
}
|
||||
};
|
||||
|
||||
export const exportAvailable = () => {
|
||||
const abiword = abiwordAvailable();
|
||||
const soffice = sofficeAvailable();
|
||||
},
|
||||
exportAvailable: () => {
|
||||
const abiword = settings.abiwordAvailable();
|
||||
const soffice = settings.sofficeAvailable();
|
||||
|
||||
if (abiword === 'no' && soffice === 'no') {
|
||||
return 'no';
|
||||
|
@ -441,10 +433,9 @@ export const exportAvailable = () => {
|
|||
} else {
|
||||
return 'yes';
|
||||
}
|
||||
};
|
||||
|
||||
// Provide git version if available
|
||||
export const getGitCommit = () => {
|
||||
},
|
||||
// Provide git version if available
|
||||
getGitCommit: () => {
|
||||
let version = '';
|
||||
try {
|
||||
let rootPath = root;
|
||||
|
@ -466,19 +457,15 @@ export const getGitCommit = () => {
|
|||
logger.warn(`Can't get git version for server header\n${e.message}`);
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
// Return etherpad version from package.json
|
||||
export const getEpVersion = () => require('../../package.json').version;
|
||||
|
||||
/**
|
||||
},
|
||||
/**
|
||||
* Receives a settingsObj and, if the property name is a valid configuration
|
||||
* item, stores it in the module's exported properties via a side effect.
|
||||
*
|
||||
* This code refactors a previous version that copied & pasted the same code for
|
||||
* both "settings.json" and "credentials.json".
|
||||
*/
|
||||
const storeSettings = (settingsObj: MapArrayType<any>) => {
|
||||
storeSettings: (settingsObj: MapArrayType<any>) => {
|
||||
for (const i of Object.keys(settingsObj || {})) {
|
||||
if (nonSettings.includes(i)) {
|
||||
logger.warn(`Ignoring setting: '${i}'`);
|
||||
|
@ -506,9 +493,8 @@ const storeSettings = (settingsObj: MapArrayType<any>) => {
|
|||
logger.warn(`Unknown Setting: '${i}'. This setting doesn't exist or it was removed`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
},
|
||||
/*
|
||||
* If stringValue is a numeric string, or its value is "true" or "false", coerce
|
||||
* them to appropriate JS types. Otherwise return stringValue as-is.
|
||||
*
|
||||
|
@ -519,8 +505,8 @@ const storeSettings = (settingsObj: MapArrayType<any>) => {
|
|||
* If the user wants a variable to be null by default, he'll have to use the
|
||||
* short syntax "${ABIWORD}", and not "${ABIWORD:null}": the latter would result
|
||||
* in the literal string "null", instead.
|
||||
*/
|
||||
const coerceValue = (stringValue: string) => {
|
||||
* */
|
||||
coerceValue: (stringValue: string) => {
|
||||
// cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
|
||||
// @ts-ignore
|
||||
const isNumeric = !isNaN(stringValue) && !isNaN(parseFloat(stringValue) && isFinite(stringValue));
|
||||
|
@ -543,9 +529,13 @@ const coerceValue = (stringValue: string) => {
|
|||
default:
|
||||
return stringValue;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Takes a javascript object containing Etherpad's configuration, and returns
|
||||
* another object, in which all the string properties whose value is of the form
|
||||
* "${ENV_VAR}" or "${ENV_VAR:default_value}" got their value replaced with the
|
||||
|
@ -581,7 +571,7 @@ const coerceValue = (stringValue: string) => {
|
|||
*
|
||||
* see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter
|
||||
*/
|
||||
const lookupEnvironmentVariables = (obj: object) => {
|
||||
lookupEnvironmentVariables: (obj: object) => {
|
||||
const stringifiedAndReplaced = JSON.stringify(obj, (key, value) => {
|
||||
/*
|
||||
* the first invocation of replacer() is with an empty key. Just go on, or
|
||||
|
@ -641,7 +631,7 @@ const lookupEnvironmentVariables = (obj: object) => {
|
|||
logger.debug(`Environment variable "${envVarName}" not found for ` +
|
||||
`configuration key "${key}". Falling back to default value.`);
|
||||
|
||||
return coerceValue(defaultValue);
|
||||
return settings.coerceValue(defaultValue);
|
||||
}
|
||||
|
||||
// envVarName contained some value.
|
||||
|
@ -653,13 +643,14 @@ const lookupEnvironmentVariables = (obj: object) => {
|
|||
logger.debug(
|
||||
`Configuration key "${key}" will be read from environment variable "${envVarName}"`);
|
||||
|
||||
return coerceValue(envVarValue!);
|
||||
return settings.coerceValue(envVarValue!);
|
||||
});
|
||||
|
||||
return JSON.parse(stringifiedAndReplaced);
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* - reads the JSON configuration file settingsFilename from disk
|
||||
* - strips the comments
|
||||
* - replaces environment variables calling lookupEnvironmentVariables()
|
||||
|
@ -667,7 +658,7 @@ const lookupEnvironmentVariables = (obj: object) => {
|
|||
*
|
||||
* The isSettings variable only controls the error logging.
|
||||
*/
|
||||
export const parseSettings = (settingsFilename: string, isSettings: boolean) => {
|
||||
parseSettings: (settingsFilename: string, isSettings: boolean) => {
|
||||
let settingsStr = '';
|
||||
|
||||
let settingsType, notFoundMessage, notFoundFunction;
|
||||
|
@ -699,22 +690,19 @@ export const parseSettings = (settingsFilename: string, isSettings: boolean) =>
|
|||
|
||||
logger.info(`${settingsType} loaded from: ${settingsFilename}`);
|
||||
|
||||
return lookupEnvironmentVariables(settings);
|
||||
return settings.lookupEnvironmentVariables(settings);
|
||||
} catch (e: any) {
|
||||
logger.error(`There was an error processing your ${settingsType} ` +
|
||||
`file from ${settingsFilename}: ${e.message}`);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
export let randomVersionString: string | undefined
|
||||
|
||||
export const reloadSettings = () => {
|
||||
const settingsParsed = parseSettings(settings.settingsFilename, true);
|
||||
const credentials = parseSettings(settings.credentialsFilename, false);
|
||||
storeSettings(settingsParsed);
|
||||
storeSettings(credentials);
|
||||
},
|
||||
reloadSettings:() => {
|
||||
const settingsParsed = settings.parseSettings(settings.settingsFilename, true);
|
||||
const credentials = settings.parseSettings(settings.credentialsFilename, false);
|
||||
settings.storeSettings(settingsParsed);
|
||||
settings.storeSettings(credentials);
|
||||
|
||||
// Init logging config
|
||||
settings.logconfig = defaultLogConfig(settings.loglevel ? settings.loglevel : defaultLogLevel);
|
||||
|
@ -842,14 +830,16 @@ export const reloadSettings = () => {
|
|||
* ACHTUNG: this may prevent caching HTTP proxies to work
|
||||
* TODO: remove the "?v=randomstring" parameter, and replace with hashed filenames instead
|
||||
*/
|
||||
randomVersionString = randomString(4);
|
||||
logger.info(`Random string used for versioning assets: ${randomVersionString}`);
|
||||
};
|
||||
logger.info(`Random string used for versioning assets: ${settings.randomVersionString}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const exportedForTestingOnly = {
|
||||
parseSettings,
|
||||
};
|
||||
/* Root path of the installation */
|
||||
logger.info('All relative paths will be interpreted relative to the identified ' +
|
||||
`Etherpad base dir: ${root}`);
|
||||
|
||||
// initially load settings
|
||||
reloadSettings();
|
||||
settings.reloadSettings
|
||||
|
||||
|
||||
export default settings
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
const semver = require('semver');
|
||||
import {getEpVersion, settings} from './Settings';
|
||||
import {settings} from './Settings';
|
||||
const axios = require('axios');
|
||||
const headers = {
|
||||
'User-Agent': 'Etherpad/' + getEpVersion(),
|
||||
'User-Agent': 'Etherpad/' + settings.getEpVersion(),
|
||||
}
|
||||
|
||||
type Infos = {
|
||||
|
@ -45,7 +45,7 @@ exports.getLatestVersion = () => {
|
|||
exports.needsUpdate = async (cb: Function) => {
|
||||
await loadEtherpadInformations()
|
||||
.then((info:Infos) => {
|
||||
if (semver.gt(info.latestVersion, getEpVersion())) {
|
||||
if (semver.gt(info.latestVersion, settings.getEpVersion())) {
|
||||
if (cb) return cb(true);
|
||||
}
|
||||
}).catch((err: Error) => {
|
||||
|
|
|
@ -21,7 +21,7 @@ const fs = require('fs');
|
|||
const fsp = fs.promises;
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
import {root} from './Settings';
|
||||
import {settings} from './Settings';
|
||||
const existsSync = require('./path_exists');
|
||||
const util = require('util');
|
||||
|
||||
|
@ -40,7 +40,7 @@ const util = require('util');
|
|||
const _crypto = require('crypto');
|
||||
|
||||
|
||||
let CACHE_DIR = path.join(root, 'var/');
|
||||
let CACHE_DIR = path.join(settings.root, 'var/');
|
||||
CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined;
|
||||
|
||||
type Headers = {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {ChildProcess} from "node:child_process";
|
|||
import {PromiseWithStd} from "../types/PromiseWithStd";
|
||||
import {Readable} from "node:stream";
|
||||
|
||||
import {root} from "./Settings";
|
||||
import {settings} from "./Settings";
|
||||
|
||||
import spawn from 'cross-spawn';
|
||||
import log4js from 'log4js';
|
||||
|
@ -77,7 +77,7 @@ const logLines = (readable: undefined | Readable | null, logLineFn: (arg0: (stri
|
|||
module.exports = exports = (args: string[], opts:any = {}) => {
|
||||
logger.debug(`Executing command: ${args.join(' ')}`);
|
||||
|
||||
opts = {cwd: root, ...opts};
|
||||
opts = {cwd: settings.root, ...opts};
|
||||
logger.debug(`cwd: ${opts.cwd}`);
|
||||
|
||||
// Log stdout and stderr by default.
|
||||
|
@ -112,8 +112,8 @@ module.exports = exports = (args: string[], opts:any = {}) => {
|
|||
opts.env = {
|
||||
...env, // Copy env to avoid modifying process.env or the caller's supplied env.
|
||||
[pathVarName]: [
|
||||
path.join(root, 'src', 'node_modules', '.bin'),
|
||||
path.join(root, 'node_modules', '.bin'),
|
||||
path.join(settings.root, 'src', 'node_modules', '.bin'),
|
||||
path.join(settings.root, 'node_modules', '.bin'),
|
||||
...(PATH ? PATH.split(path.delimiter) : []),
|
||||
].join(path.delimiter),
|
||||
};
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
"@types/formidable": "^3.4.5",
|
||||
"@types/jsonminify": "^0.4.3",
|
||||
"@types/node": "^20.11.19",
|
||||
"@types/resolve": "^1.20.6",
|
||||
"@types/underscore": "^1.11.15",
|
||||
"cypress": "^13.6.4",
|
||||
"eslint": "^8.56.0",
|
||||
|
|
|
@ -4,7 +4,7 @@ const log4js = require('log4js');
|
|||
const plugins = require('./plugins');
|
||||
const hooks = require('./hooks');
|
||||
const runCmd = require('../../../node/utils/run_cmd');
|
||||
import {getEpVersion, reloadSettings, root, settings} from '../../../node/utils/Settings';
|
||||
import {settings} from '../../../node/utils/Settings';
|
||||
const axios = require('axios');
|
||||
const {PluginManager} = require('live-plugin-manager-pnpm');
|
||||
const {promises: fs} = require('fs');
|
||||
|
@ -14,18 +14,18 @@ const logger = log4js.getLogger('plugins');
|
|||
|
||||
exports.manager = new PluginManager();
|
||||
|
||||
const installedPluginsPath = path.join(root, 'var/installed_plugins.json');
|
||||
const installedPluginsPath = path.join(settings.root, 'var/installed_plugins.json');
|
||||
|
||||
const onAllTasksFinished = async () => {
|
||||
await plugins.update();
|
||||
await persistInstalledPlugins();
|
||||
reloadSettings();
|
||||
settings.reloadSettings();
|
||||
await hooks.aCallAll('loadSettings', {settings});
|
||||
await hooks.aCallAll('restartServer');
|
||||
};
|
||||
|
||||
const headers = {
|
||||
'User-Agent': `Etherpad/${getEpVersion()}`,
|
||||
'User-Agent': `Etherpad/${settings.getEpVersion()}`,
|
||||
};
|
||||
|
||||
let tasks = 0;
|
||||
|
|
|
@ -9,7 +9,7 @@ const tsort = require('./tsort');
|
|||
const pluginUtils = require('./shared');
|
||||
const defs = require('./plugin_defs');
|
||||
const {manager} = require('./installer');
|
||||
import {getEpVersion, root, settings} from "../../../node/utils/Settings";
|
||||
import {settings} from "../../../node/utils/Settings";
|
||||
|
||||
const logger = log4js.getLogger('plugins');
|
||||
|
||||
|
@ -121,9 +121,9 @@ exports.getPackages = async () => {
|
|||
|
||||
newDependencies['ep_etherpad-lite'] = {
|
||||
name: 'ep_etherpad-lite',
|
||||
version: getEpVersion(),
|
||||
path: path.join(root, 'node_modules/ep_etherpad-lite'),
|
||||
realPath: path.join(root, 'src'),
|
||||
version: settings.getEpVersion(),
|
||||
path: path.join(settings.root, 'node_modules/ep_etherpad-lite'),
|
||||
realPath: path.join(settings.root, 'src'),
|
||||
};
|
||||
|
||||
return newDependencies;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings").settings
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings")
|
||||
%>
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings").settings
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings")
|
||||
, langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
|
||||
, pluginUtils = require('ep_etherpad-lite/static/js/pluginfw/shared')
|
||||
;
|
||||
|
@ -455,10 +455,10 @@
|
|||
<!-- Bootstrap page -->
|
||||
<script type="text/javascript">
|
||||
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
|
||||
var clientVars = {
|
||||
const clientVars = {
|
||||
// This is needed to fetch /pluginfw/plugin-definitions.json, which happens before the
|
||||
// server sends the CLIENT_VARS message.
|
||||
randomVersionString: <%-JSON.stringify(settings.randomVersionString)%>,
|
||||
randomVersionString: <;%-JSON.stringify(settings.randomVersionString)%>,
|
||||
};
|
||||
(function () {
|
||||
var pathComponents = location.pathname.split('/');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings").settings
|
||||
var settings = require("ep_etherpad-lite/node/utils/Settings")
|
||||
, langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
|
||||
%>
|
||||
<!doctype html>
|
||||
|
|
|
@ -5,7 +5,7 @@ const common = require('../common');
|
|||
const fs = require('fs');
|
||||
const fsp = fs.promises;
|
||||
const path = require('path');
|
||||
import {root, settings} from '../../../node/utils/Settings'
|
||||
import {settings} from '../../../node/utils/Settings'
|
||||
const superagent = require('superagent');
|
||||
|
||||
describe(__filename, function () {
|
||||
|
@ -19,13 +19,13 @@ describe(__filename, function () {
|
|||
before(async function () {
|
||||
agent = await common.init();
|
||||
wantCustomIcon = await fsp.readFile(path.join(__dirname, 'favicon-test-custom.png'));
|
||||
wantDefaultIcon = await fsp.readFile(path.join(root, 'src', 'static', 'favicon.ico'));
|
||||
wantDefaultIcon = await fsp.readFile(path.join(settings.root, 'src', 'static', 'favicon.ico'));
|
||||
wantSkinIcon = await fsp.readFile(path.join(__dirname, 'favicon-test-skin.png'));
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
backupSettings = {...settings};
|
||||
skinDir = await fsp.mkdtemp(path.join(root, 'src', 'static', 'skins', 'test-'));
|
||||
skinDir = await fsp.mkdtemp(path.join(settings.root, 'src', 'static', 'skins', 'test-'));
|
||||
settings.skinName = path.basename(skinDir);
|
||||
});
|
||||
|
||||
|
@ -43,7 +43,7 @@ describe(__filename, function () {
|
|||
|
||||
it('uses custom favicon if set (relative pathname)', async function () {
|
||||
settings.favicon =
|
||||
path.relative(root, path.join(__dirname, 'favicon-test-custom.png'));
|
||||
path.relative(settings.root, path.join(__dirname, 'favicon-test-custom.png'));
|
||||
assert(!path.isAbsolute(settings.favicon));
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const assert = require('assert').strict;
|
||||
const common = require('../common');
|
||||
import * as settings from '../../../node/utils/Settings';
|
||||
import settings from '../../../node/utils/Settings';
|
||||
const superagent = require('superagent');
|
||||
|
||||
describe(__filename, function () {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert').strict;
|
||||
import {parseSettings} from '../../../node/utils/Settings';
|
||||
import settings from '../../../node/utils/Settings';
|
||||
const path = require('path');
|
||||
const process = require('process');
|
||||
|
||||
|
@ -21,7 +21,7 @@ describe(__filename, function () {
|
|||
before(async function () {
|
||||
for (const tc of envVarSubstTestCases) process.env[tc.var] = tc.val;
|
||||
delete process.env.UNSET_VAR;
|
||||
settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
settings = settings.parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert(settings != null);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
import * as settings from '../../../node/utils/Settings';
|
||||
import settings from '../../../node/utils/Settings';
|
||||
|
||||
describe(__filename, function () {
|
||||
this.timeout(30000);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const assert = require('assert').strict;
|
||||
const common = require('../common');
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
import * as settings from '../../../node/utils/Settings';
|
||||
import settings from '../../../node/utils/Settings';
|
||||
|
||||
describe(__filename, function () {
|
||||
this.timeout(30000);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue