translation calls in a bunch of middleware, code change pass ing new arg to name handler in makepost/editpost, and sync translation keys

indiachan-spamvector
Thomas Lynch 1 year ago
parent dc27f9216c
commit 32066e3f47
  1. 2
      lib/captcha/captcha.js
  2. 2
      lib/locale/locale.js
  3. 12
      lib/middleware/captcha/blockbypass.js
  4. 4
      lib/middleware/captcha/verify.js
  5. 12
      lib/middleware/file/filemiddlewares.js
  6. 8
      lib/middleware/input/paramconverter.js
  7. 4
      lib/middleware/ip/dnsbl.js
  8. 5
      lib/middleware/ip/processip.js
  9. 4
      lib/middleware/misc/referrercheck.js
  10. 12
      lib/middleware/permission/haspermsmiddleware.js
  11. 19
      lib/post/name.js
  12. 18
      locales/en.json
  13. 1263
      locales/fr.json
  14. 19
      locales/pt.json
  15. 11
      models/forms/editpost.js
  16. 11
      models/forms/makepost.js

@ -73,6 +73,7 @@ module.exports = async (captchaInput, captchaId) => {
body: form,
}).then(res => res.json());
} catch (e) {
console.error(e);
throw 'Captcha error occurred';
}
if (!recaptchaResponse || !recaptchaResponse.success) {
@ -92,6 +93,7 @@ module.exports = async (captchaInput, captchaId) => {
body: form,
}).then(res => res.json());
} catch (e) {
console.error(e);
throw 'Captcha error occurred';
}
if (!hcaptchaResponse || !hcaptchaResponse.success) {

@ -6,7 +6,7 @@ const i18n = require('i18n')
i18n.configure({
directory: path.join(__dirname, '/../../locales'),
locales: ['en', 'pt'],
//locales: ['en', 'pt', 'fr'],
defaultLocale: 'en',
retryInDefaultLocale: false,
updateFiles: false, //holy FUCK why is that an option

@ -25,12 +25,12 @@ module.exports = {
if (!res.locals.solvedCaptcha && (!bypassId || bypassId.length !== 24)) {
deleteTempFiles(req).catch(console.error);
return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden',
'message': 'Please complete a block bypass to continue',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('Please complete a block bypass to continue'),
'frame': '/bypass_minimal.html',
'link': {
'href': '/bypass.html',
'text': 'Get block bypass',
'text': res.locals.__('Get block bypass'),
},
});
}
@ -69,12 +69,12 @@ module.exports = {
deleteTempFiles(req).catch(console.error);
res.clearCookie('bypassid');
return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden',
'message': 'Block bypass expired or exceeded max uses',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('Block bypass expired or exceeded max uses'),
'frame': '/bypass_minimal.html',
'link': {
'href': '/bypass.html',
'text': 'Get block bypass',
'text': res.locals.__('Get block bypass'),
},
});

@ -38,8 +38,8 @@ module.exports = async (req, res, next) => {
}
const page = (req.body.minimal || req.path === '/blockbypass' ? 'bypass' : 'message');
return dynamicResponse(req, res, 403, page, {
'title': 'Forbidden',
'message': err,
'title': res.locals.__('Forbidden'),
'message': res.locals.__(err),
'redirect': req.headers.referer,
});
}

@ -14,8 +14,8 @@ const { debugLogs } = require(__dirname+'/../../../configs/secrets.js')
}
, missingExtensionLimitFunction = (req, res) => {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad Request',
'message': 'Missing file extensions',
'title': res.locals.__('Bad Request'),
'message': res.locals.__('Missing file extensions'),
'redirect': req.headers.referer
});
}
@ -26,10 +26,12 @@ const { debugLogs } = require(__dirname+'/../../../configs/secrets.js')
const fileNumLimit = globalLimits[`${fileType}Files`];
const fileNumLimitFunction = (req, res) => {
const isPostform = req.path.endsWith('/post') || req.path.endsWith('/modpost');
const message = (isPostform && res.locals.board)
? res.locals.__(`Max files per post ${res.locals.board.settings.maxFiles < globalLimits.postFiles.max ? 'on this board ' : ''}is %s`, res.locals.board.settings.maxFiles)
: res.locals.__(`Max files per request is %s`, fileNumLimit.max);
return dynamicResponse(req, res, 400, 'message', {
'title': 'Too many files',
'message': (isPostform && res.locals.board) ? `Max files per post ${res.locals.board.settings.maxFiles < globalLimits.postFiles.max ? 'on this board ' : ''}is ${res.locals.board.settings.maxFiles}`
: `Max files per request is ${fileNumLimit.max}`,
'title': res.locals.__('Too many files'),
'message': message,
'redirect': req.headers.referer
});
};

@ -39,8 +39,8 @@ module.exports = (options) => {
const val = req.body[key];
if (!allowedArrays.includes(key) && Array.isArray(val)) {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad request',
'message': 'Malformed input'
'title': res.locals.__('Bad request'),
'message': res.locals.__('Malformed input'),
});
} else if (allowedArrays.includes(key) && !Array.isArray(val)) {
req.body[key] = makeArrayIfSingle(req.body[key]); //convert to arrays with single item for simpler case batch handling later
@ -134,8 +134,8 @@ module.exports = (options) => {
}
} catch (e) {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad request',
'message': 'Malformed input'
'title': res.locals.__('Bad request'),
'message': res.locals.__('Malformed input'),
});
}

@ -30,8 +30,8 @@ module.exports = async (req, res, next) => {
//otherwise dnsbl cant be bypassed
deleteTempFiles(req).catch(console.error);
return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden',
'message': 'Your request was blocked because your IP address is listed on a blacklist.',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('Your request was blocked because your IP address is listed on a blacklist.'),
'redirect': req.headers.referer || '/',
});
}

@ -51,10 +51,11 @@ module.exports = (req, res, next) => {
};
next();
} catch(e) {
//should never get here
console.error('Ip parse failed', e);
return res.status(400).render('message', {
'title': 'Bad request',
'message': 'Malformed IP' //should never get here
'title': res.locals.__('Bad request'),
'message': res.locals.__('Malformed IP'),
});
}

@ -25,8 +25,8 @@ module.exports = (req, res, next) => {
}
if (refererCheck === true && (!req.headers.referer || !validReferer)) {
return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden',
'message': 'Invalid or missing "Referer" header. Are you posting from the correct URL?'
'title': res.locals.__('Forbidden'),
'message': res.locals.__('Invalid or missing "Referer" header. Are you posting from the correct URL?'),
});
}
next();

@ -11,8 +11,8 @@ module.exports = {
return cache.one[requiredPermission] || (cache.one[requiredPermission] = function(req, res, next) {
if (!res.locals.permissions.get(requiredPermission)) {
return res.status(403).render('message', {
'title': 'Forbidden',
'message': 'No Permission',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('No Permission'),
'redirect': req.headers.referer || '/',
});
}
@ -25,8 +25,8 @@ module.exports = {
return cache.all[requiredPermissions] || (cache.all[requiredPermissions] = function(req, res, next) {
if (!res.locals.permissions.hasAll(...requiredPermissions)) {
return res.status(403).render('message', {
'title': 'Forbidden',
'message': 'No Permission',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('No Permission'),
'redirect': req.headers.referer || '/',
});
}
@ -39,8 +39,8 @@ module.exports = {
return cache.any[requiredPermissions] || (cache.any[requiredPermissions] = function(req, res, next) {
if (!res.locals.permissions.hasAny(...requiredPermissions)) {
return res.status(403).render('message', {
'title': 'Forbidden',
'message': 'No Permission',
'title': res.locals.__('Forbidden'),
'message': res.locals.__('No Permission'),
'redirect': req.headers.referer || '/',
});
}

@ -3,18 +3,17 @@
const { getInsecureTrip, getSecureTrip } = require(__dirname+'/tripcode.js')
, { Permissions } = require(__dirname+'/../permission/permissions.js')
, nameRegex = /^(?<name>[^#].*?)?(?:(?<tripcode>##(?<strip>[^ ].*?)|#(?<itrip>[^#].*?)))?(?<capcode>##(?<capcodetext> .*?)?)?$/
, staffLevels = ['Admin', 'Global Staff', 'Board Owner', 'Board Mod']
, staffLevelsRegex = new RegExp(`(${staffLevels.join('|')})+`, 'igm');
, staffLevels = ['Admin', 'Global Staff', 'Board Owner', 'Board Staff'];
module.exports = async (inputName, permissions, boardSettings, boardOwner, boardStaff, username) => {
module.exports = async (inputName, permissions, boardSettings, boardOwner, boardStaff, username, __) => {
const { forceAnon, defaultName } = boardSettings;
const isBoardOwner = username === boardOwner; //why not just check staffboards and ownedboards?
const staffUsernames = Object.keys(boardStaff);
const isBoardMod = staffUsernames.includes(username);
const staffPermissions = [permissions.get(Permissions.ROOT),
permissions.get(Permissions.MANAGE_GLOBAL_GENERAL),
isBoardOwner, isBoardMod];
const staffPermissions = [permissions.get(Permissions.ROOT), permissions.get(Permissions.MANAGE_GLOBAL_GENERAL), isBoardOwner, isBoardMod];
const langStaffLevels = staffLevels.map(l => __(l));
const staffLevelsRegex = new RegExp(`(${langStaffLevels.join('|')})+`, 'igm');
let name = defaultName;
let tripcode = null;
@ -51,18 +50,18 @@ module.exports = async (inputName, permissions, boardSettings, boardOwner, board
const { staffLevelDirect, staffLevelFallback } = staffPermissions.reduce((acc, sp, i) => {
if (sp === true) {
if (!acc.staffLevelFallback) {
acc.staffLevelFallback = staffLevels[i];
acc.staffLevelFallback = langStaffLevels[i];
}
if (!acc.staffLevelDirect && capcodeInput.toLowerCase().startsWith(staffLevels[i].toLowerCase())) {
acc.staffLevelDirect = staffLevels[i];
acc.staffLevelDirect = langStaffLevels[i];
}
}
return acc;
}, { 'staffLevelDirect': null, 'staffLevelFallback': null });
//we still get the same fallbacks as before, its just more annoying without the direct permlevel mapping
const staffLevel = staffLevelDirect ||
(isBoardOwner ? staffLevels[2]
: isBoardMod ? staffLevels[3]
(isBoardOwner ? langStaffLevels[2]
: isBoardMod ? langStaffLevels[3]
: staffLevelFallback);
capcode = staffLevel;
if (capcodeInput && capcodeInput.toLowerCase() !== staffLevel.toLowerCase()) {

@ -1,5 +1,6 @@
{
".html name": ".html name",
"'Malformed IP": "'Malformed IP",
"(You)": "(You)",
"(You)s": "(You)s",
"%s characters": {
@ -153,6 +154,7 @@
"Bans & Appeals": "Bans & Appeals",
"Bans currently in place against your IP": "Bans currently in place against your IP",
"Block Bypass": "Block Bypass",
"Block bypass expired or exceeded max uses": "Block bypass expired or exceeded max uses",
"Blur": "Blur",
"Board": "Board",
"Board List": "Board List",
@ -183,6 +185,9 @@
"Cache": "Cache",
"Canvas height in pixels": "Canvas height in pixels",
"Canvas width in pixels": "Canvas width in pixels",
"Captcha config error": "Captcha config error",
"Captcha error occurred": "Captcha error occurred",
"Captcha expired": "Captcha expired",
"Captcha text": "Captcha text",
"Catalog": "Catalog",
"Catalog View": "Catalog View",
@ -297,6 +302,7 @@
"Flags that can be applied to posts if custom flags are enabled in board settings": "Flags that can be applied to posts if custom flags are enabled in board settings",
"Flow": "Flow",
"focus to load captcha": "focus to load captcha",
"Forbidden": "Forbidden",
"Fortune": "Fortune",
"Full control of the board, equivalent to the BO. Can delete and/or transfer the board. Can only be given by somebody else with \"Board Owner\" permission. Use with caution!": "Full control of the board, equivalent to the BO. Can delete and/or transfer the board. Can only be given by somebody else with \"Board Owner\" permission. Use with caution!",
"Full control. Use with caution!": "Full control. Use with caution!",
@ -305,6 +311,7 @@
"General board staff permission. Access mod index, catalog, recent posts and reports. Ability to submit mod actions. Bypass board-specific bans and post filters.": "General board staff permission. Access mod index, catalog, recent posts and reports. Ability to submit mod actions. Bypass board-specific bans and post filters.",
"General global staff permission. Access to recent posts and reports. Ability to submit global actions.": "General global staff permission. Access to recent posts and reports. Ability to submit global actions.",
"Geographic Flag": "Geographic Flag",
"Get block bypass": "Get block bypass",
"Global": "Global",
"Global Ban Poster": "Global Ban Poster",
"Global Ban Reporters": "Global Ban Reporters",
@ -339,11 +346,13 @@
"Import": "Import",
"Import/Export Settings": "Import/Export Settings",
"Include Default Boards": "Include Default Boards",
"Incorrect captcha answer": "Incorrect captcha answer",
"Index": "Index",
"Index View": "Index View",
"Inline Monospace": "Inline Monospace",
"Internal server error": "Internal server error",
"Invalid dimensions.": "Invalid dimensions.",
"Invalid or missing \"Referer\" header. Are you posting from the correct URL?": "Invalid or missing \"Referer\" header. Are you posting from the correct URL?",
"IP": "IP",
"IP/Hash": "IP/Hash",
"IP/ID": "IP/ID",
@ -376,6 +385,7 @@
"Lokinet SNApp": "Lokinet SNApp",
"Loop audio/video": "Loop audio/video",
"Make links clickable": "Make links clickable",
"Malformed input": "Malformed input",
"Manage": "Manage",
"Manage Custom Pages": "Manage Custom Pages",
"Manage News": "Manage News",
@ -387,9 +397,13 @@
"one": "Max %s file",
"other": "Max %s files"
},
"Max files per post is %s": "Max files per post is %s",
"Max files per post on this board is %s": "Max files per post on this board is %s",
"Max files per request is %s": "Max files per request is %s",
"Merge layers": "Merge layers",
"Merge selected layers?": "Merge selected layers?",
"Message": "Message",
"Missing file extensions": "Missing file extensions",
"Mod Catalog": "Mod Catalog",
"Mod Index": "Mod Index",
"Mod View": "Mod View",
@ -417,6 +431,7 @@
"No Filters": "No Filters",
"No Logs.": "No Logs.",
"No news.": "No news.",
"No Permission": "No Permission",
"No posts.": "No posts.",
"No reports.": "No reports.",
"No results.": "No results.",
@ -457,6 +472,7 @@
"Pipette": "Pipette",
"Play": "Play",
"Playlist": "Playlist",
"Please complete a block bypass to continue": "Please complete a block bypass to continue",
"Please enable JavaScript to solve the captcha.": "Please enable JavaScript to solve the captcha.",
"Popularity": "Popularity",
"Post Filters": "Post Filters",
@ -571,6 +587,7 @@
"Toggle Lock": "Toggle Lock",
"Toggle visibility": "Toggle visibility",
"Tone": "Tone",
"Too many files": "Too many files",
"Tor Hidden Service": "Tor Hidden Service",
"total": "total",
"Two Factor Authentication Setup": "Two Factor Authentication Setup",
@ -621,6 +638,7 @@
"You own": "You own",
"You will be redirected shortly.": "You will be redirected shortly.",
"Your post was blocked by a word filter": "Your post was blocked by a word filter",
"Your request was blocked because your IP address is listed on a blacklist.": "Your request was blocked because your IP address is listed on a blacklist.",
"Your upload was too large": "Your upload was too large",
"Zoom": "Zoom"
}

File diff suppressed because it is too large Load Diff

@ -1,5 +1,6 @@
{
".html name": ".html nome",
"'Malformed IP": "'Malformed IP",
"(You)": "(You)",
"(You)s": "(You)s",
"%s characters": {
@ -138,6 +139,7 @@
},
"Assets": "Assets",
"Attempting to reconnect...": "A ligar...",
"Bad request": "Bad request",
"Ban Duration": "Duração Ban",
"Ban duration e.g. 7d": "Duração do ban e.g. 7d",
"Ban Poster": "Banir Utilizador",
@ -152,6 +154,7 @@
"Bans & Appeals": "Bans & Recursos",
"Bans currently in place against your IP": "Bans colocados no teu IP",
"Block Bypass": "Bypass",
"Block bypass expired or exceeded max uses": "Block bypass expired or exceeded max uses",
"Blur": "Desfoque",
"Board": "Tábua",
"Board List": "Tábuas",
@ -182,6 +185,9 @@
"Cache": "Cache",
"Canvas height in pixels": "Altura da tela em pixeis",
"Canvas width in pixels": "Largura da tela em pixeis",
"Captcha config error": "Captcha config error",
"Captcha error occurred": "Captcha error occurred",
"Captcha expired": "Captcha expired",
"Captcha text": "Código captcha",
"Catalog": "Catálogo",
"Catalog View": "Catálogo",
@ -296,6 +302,7 @@
"Flags that can be applied to posts if custom flags are enabled in board settings": "O especial pode ser mostrado na publicação se custom flags estiver ativado nas opções da tábua",
"Flow": "Fluidez",
"focus to load captcha": "Seleciona para carregar captcha",
"Forbidden": "Forbidden",
"Fortune": "Fortune",
"Full control of the board, equivalent to the BO. Can delete and/or transfer the board. Can only be given by somebody else with \"Board Owner\" permission. Use with caution!": "Full control of the board, equivalent to the BO. Can delete and/or transfer the board. Can only be given by somebody else with \"Board Owner\" permission. Use with caution!",
"Full control. Use with caution!": "Full control. Use with caution!",
@ -304,6 +311,7 @@
"General board staff permission. Access mod index, catalog, recent posts and reports. Ability to submit mod actions. Bypass board-specific bans and post filters.": "General board staff permission. Access mod index, catalog, recent posts and reports. Ability to submit mod actions. Bypass board-specific bans and post filters.",
"General global staff permission. Access to recent posts and reports. Ability to submit global actions.": "General global staff permission. Access to recent posts and reports. Ability to submit global actions.",
"Geographic Flag": "Bandeira Geográfica",
"Get block bypass": "Get block bypass",
"Global": "Global",
"Global Ban Poster": "Banir Globalmente Utilizador",
"Global Ban Reporters": "Global Ban Reporters",
@ -338,11 +346,13 @@
"Import": "Importar",
"Import/Export Settings": "Importar/Exportar Opções",
"Include Default Boards": "Incluir tábuas default",
"Incorrect captcha answer": "Incorrect captcha answer",
"Index": "Index",
"Index View": "Index",
"Inline Monospace": "Inline Monospace",
"Internal server error": "Erro interno do servidor",
"Invalid dimensions.": "Dimensões invalidas.",
"Invalid or missing \"Referer\" header. Are you posting from the correct URL?": "Invalid or missing \"Referer\" header. Are you posting from the correct URL?",
"IP": "IP",
"IP/Hash": "IP/Hash",
"IP/ID": "IP/ID",
@ -375,6 +385,7 @@
"Lokinet SNApp": "Lokinet SNApp",
"Loop audio/video": "Loop áudio/vídeo",
"Make links clickable": "Make links clickable",
"Malformed input": "Malformed input",
"Manage": "Gerir",
"Manage Custom Pages": "Gerir Páginas",
"Manage News": "Manage News",
@ -386,9 +397,13 @@
"one": "Máx %s",
"other": "Máx %s"
},
"Max files per post is %s": "Max files per post is %s",
"Max files per post on this board is %s": "Max files per post on this board is %s",
"Max files per request is %s": "Max files per request is %s",
"Merge layers": "Fundir camadas",
"Merge selected layers?": "Fundir camadas selecionadas?",
"Message": "Mensagem",
"Missing file extensions": "Missing file extensions",
"Mod Catalog": "Mod Catálogo",
"Mod Index": "Mod Index",
"Mod View": "Mod View",
@ -416,6 +431,7 @@
"No Filters": "Sem Filtros",
"No Logs.": "No Logs.",
"No news.": "Sem notícias.",
"No Permission": "No Permission",
"No posts.": "Sem publicações.",
"No reports.": "Sem denúncias.",
"No results.": "No results.",
@ -456,6 +472,7 @@
"Pipette": "Pipeta",
"Play": "Reproduzir",
"Playlist": "Playlist",
"Please complete a block bypass to continue": "Please complete a block bypass to continue",
"Please enable JavaScript to solve the captcha.": "Necessita JavaScript.",
"Popularity": "Popularidade",
"Post Filters": "Filtros",
@ -570,6 +587,7 @@
"Toggle Lock": "Trancar",
"Toggle visibility": "Alterar visibilidade",
"Tone": "Matiz",
"Too many files": "Too many files",
"Tor Hidden Service": "Tor Hidden Service",
"total": "total",
"Two Factor Authentication Setup": "Configuração 2FA",
@ -620,6 +638,7 @@
"You own": "Que administras",
"You will be redirected shortly.": "Vais ser redirecionado em breve",
"Your post was blocked by a word filter": "Your post was blocked by a word filter",
"Your request was blocked because your IP address is listed on a blacklist.": "Your request was blocked because your IP address is listed on a blacklist.",
"Your upload was too large": "Your upload was too large",
"Zoom": "Zoom"
}

@ -50,8 +50,15 @@ todo: handle some more situations
messageHash = createHash('sha256').update(noQuoteMessage).digest('base64');
}
//new name, trip and cap
const { name, tripcode, capcode } = await nameHandler(req.body.name, res.locals.permissions,
board.settings, board.owner, board.staff, res.locals.user ? res.locals.user.username : null);
const { name, tripcode, capcode } = await nameHandler(
req.body.name,
res.locals.permissions,
board.settings,
board.owner,
board.staff,
res.locals.user ? res.locals.user.username : null,
res.locals.__
);
//new message and quotes
const nomarkup = prepareMarkdown(req.body.message, false);
const { message, quotes, crossquotes } = await messageHandler(nomarkup, req.body.board, post.thread, res.locals.permissions);

@ -403,8 +403,15 @@ module.exports = async (req, res) => {
let subject = (!isStaffOrGlobal && req.body.thread && disableReplySubject) ? null : req.body.subject;
//get name, trip and cap
const { name, tripcode, capcode } = await nameHandler(req.body.name, res.locals.permissions,
res.locals.board.settings, res.locals.board.owner, res.locals.board.staff, res.locals.user ? res.locals.user.username : null);
const { name, tripcode, capcode } = await nameHandler(
req.body.name,
res.locals.permissions,
res.locals.board.settings,
res.locals.board.owner,
res.locals.board.staff,
res.locals.user ? res.locals.user.username : null,
res.locals.__
);
//get message, quotes and crossquote array
const nomarkup = prepareMarkdown(req.body.message, true);
const { message, quotes, crossquotes } = await messageHandler(nomarkup, req.params.board, req.body.thread, res.locals.permissions);

Loading…
Cancel
Save