more options for limits to increase length of subject, name, email, etc

merge-requests/208/head
fatchan 4 years ago
parent 17d64c7795
commit 53144641c4
  1. 23
      configs/main.js.example
  2. 17
      controllers/forms/actions.js
  3. 3
      controllers/forms/appeal.js
  4. 16
      controllers/forms/boardsettings.js
  5. 14
      controllers/forms/create.js
  6. 13
      controllers/forms/globalactions.js
  7. 20
      controllers/forms/makepost.js
  8. 8
      views/includes/postform.pug
  9. 2
      views/includes/subjectfield.pug
  10. 6
      views/pages/create.pug
  11. 8
      views/pages/managesettings.pug

@ -166,11 +166,24 @@ module.exports = {
bannerFilesSize: { //in bytes, 10MB default
max: 10485760
},
messageLength: { //max length of a post mesage field
/* NOTE: postFilesSize and bannerFilesSize counts in bytes the amount of total data in form submission including
other fields like message, name, etc. Therefore a very long message would reduce the space left for files very slightly.
To counteract this, consider increasing postFilesSize and bannerFilesSize beyond your desired max filesize by a small margin */
max: 4000
/* NOTE: postFilesSize and bannerFilesSize counts in bytes the amount of total data in form submission including
other fields like message, name, etc. Therefore a very long message would reduce the space left for files very slightly.
To counteract this, consider increasing postFilesSize and bannerFilesSize beyond your desired max filesize by a small margin */
fieldLength: { //max length of fields in some forms
//post form
name: 100,
email: 100,
subject: 100,
postpassword: 100,
message: 4000,
//reports/post actions
report_reason: 100,
ban_reason: 100,
log_message: 100,
//board creation
uri: 50,
boardname: 50,
description: 100,
},
customCss: {
enabled: true, //allow custom css by board owners

@ -1,6 +1,7 @@
'use strict';
const { Posts } = require(__dirname+'/../../db/')
, { globalLimits } = require(__dirname+'/../../configs/main.js')
, actionHandler = require(__dirname+'/../../models/forms/actionhandler.js')
, actionChecker = require(__dirname+'/../../helpers/checks/actionchecker.js');
@ -47,17 +48,17 @@ module.exports = async (req, res, next) => {
}
//check that actions are valid
if (req.body.postpassword && req.body.postpassword.length > 50) {
errors.push('Password must be 50 characters or less');
if (req.body.postpassword && req.body.postpassword.length > globalLimits.fieldLength.postpassword) {
errors.push(`Password must be ${globalLimits.fieldLength.postpassword} characters or less`);
}
if (req.body.report_reason && req.body.report_reason.length > 50) {
errors.push('Report must be 50 characters or less');
if (req.body.report_reason && req.body.report_reason.length > globalLimits.fieldLength.report_reason) {
errors.push(`Report must be ${globalLimits.fieldLength.report_reason} characters or less`);
}
if (req.body.ban_reason && req.body.ban_reason.length > 50) {
errors.push('Ban reason must be 50 characters or less');
if (req.body.ban_reason && req.body.ban_reason.length > globalLimits.fieldLength.ban_reason) {
errors.push(`Ban reason must be ${globalLimits.fieldLength.ban_reason} characters or less`);
}
if (req.body.log_message && req.body.log_message.length > 50) {
errors.push('Modlog must be 50 characters or less');
if (req.body.log_message && req.body.log_message.length > globalLimits.fieldLength.log_message) {
errors.push(`Modlog message must be ${globalLimits.fieldLength.log_message} characters or less`);
}
if ((req.body.report || req.body.global_report) && (!req.body.report_reason || req.body.report_reason.length === 0)) {
errors.push('Reports must have a reason');

@ -1,6 +1,7 @@
'use strict';
const appealBans = require(__dirname+'/../../models/forms/appeal.js')
, { globalLimits } = require(__dirname+'/../../configs/main.js')
, { Bans } = require(__dirname+'/../../db');
module.exports = async (req, res, next) => {
@ -12,7 +13,7 @@ module.exports = async (req, res, next) => {
if (!req.body.message || req.body.message.length === 0) {
errors.push('Appeals must include a message');
}
if (req.body.message.length > 2000) {
if (req.body.message.length > globalLimits.fieldLength.message) {
errors.push('Appeal message must be 2000 characters or less');
}

@ -68,31 +68,31 @@ module.exports = async (req, res, next) => {
}
//make sure existing min/max message dont conflict
const minThread = Math.min(globalLimits.messageLength.max, res.locals.board.settings.maxThreadMessageLength) || globalLimits.messageLength.max;
const minThread = Math.min(globalLimits.fieldLength.message, res.locals.board.settings.maxThreadMessageLength) || globalLimits.fieldLength.message;
if (typeof req.body.min_thread_message_length === 'number'
&& (req.body.min_thread_message_length < 0
|| req.body.min_thread_message_length > minThread)) {
errors.push(`Min thread message length must be 0-${globalLimits.messageLength.max} and not more than "Max Thread Message Length" (currently ${res.locals.board.settings.maxThreadMessageLength})`);
errors.push(`Min thread message length must be 0-${globalLimits.fieldLength.message} and not more than "Max Thread Message Length" (currently ${res.locals.board.settings.maxThreadMessageLength})`);
}
const minReply = Math.min(globalLimits.messageLength.max, res.locals.board.settings.maxReplyMessageLength) || globalLimits.messageLength.max;
const minReply = Math.min(globalLimits.fieldLength.message, res.locals.board.settings.maxReplyMessageLength) || globalLimits.fieldLength.message;
if (typeof req.body.min_reply_message_length === 'number'
&& (req.body.min_reply_message_length < 0
|| req.body.min_reply_message_length > minReply)) {
errors.push(`Min reply message length must be 0-${globalLimits.messageLength.max} and not more than "Max Reply Message Length" (currently ${res.locals.board.settings.maxReplyMessageLength})`);
errors.push(`Min reply message length must be 0-${globalLimits.fieldLength.message} and not more than "Max Reply Message Length" (currently ${res.locals.board.settings.maxReplyMessageLength})`);
}
if (typeof req.body.max_thread_message_length === 'number'
&& (req.body.max_thread_message_length < 0
|| req.body.max_thread_message_length > globalLimits.messageLength.max
|| req.body.max_thread_message_length > globalLimits.fieldLength.message
|| (req.body.max_thread_message_length
&& req.body.max_thread_message_length < res.locals.board.settings.minThreadMessageLength))) {
errors.push(`Max thread message length must be 0-${globalLimits.messageLength.max} and not less than "Min Thread Message Length" (currently ${res.locals.board.settings.minThreadMessageLength})`);
errors.push(`Max thread message length must be 0-${globalLimits.fieldLength.message} and not less than "Min Thread Message Length" (currently ${res.locals.board.settings.minThreadMessageLength})`);
}
if (typeof req.body.max_reply_message_length === 'number'
&& (req.body.max_reply_message_length < 0
|| req.body.max_reply_message_length > globalLimits.messageLength.max
|| req.body.max_reply_message_length > globalLimits.fieldLength.message
|| (req.body.max_reply_message_length
&& req.body.max_reply_message_length < res.locals.board.settings.minReplyMessageLength))) {
errors.push(`Max reply message length must be 0-${globalLimits.messageLength.max} and not less than "Min Reply Message Length" (currently ${res.locals.board.settings.minReplyMessageLength})`);
errors.push(`Max reply message length must be 0-${globalLimits.fieldLength.message} and not less than "Min Reply Message Length" (currently ${res.locals.board.settings.minReplyMessageLength})`);
}
if (typeof req.body.captcha_mode === 'number' && (req.body.captcha_mode < 0 || req.body.captcha_mode > 2)) {

@ -1,7 +1,7 @@
'use strict';
const createBoard = require(__dirname+'/../../models/forms/create.js')
, { enableUserBoards } = require(__dirname+'/../../configs/main.js')
, { enableUserBoards, globalLimits } = require(__dirname+'/../../configs/main.js')
, alphaNumericRegex = require(__dirname+'/../../helpers/checks/alphanumregex.js')
module.exports = async (req, res, next) => {
@ -30,18 +30,18 @@ module.exports = async (req, res, next) => {
//other validation
if (req.body.uri) {
if (req.body.uri.length > 50) {
errors.push('URI must be 50 characters or less');
if (req.body.uri.length > globalLimits.fieldLength.uri) {
errors.push(`URI must be ${globalLimits.fieldLength.uri} characters or less`);
}
if (alphaNumericRegex.test(req.body.uri) !== true) {
errors.push('URI must contain a-z 0-9 only');
}
}
if (req.body.name && req.body.name.length > 50) {
errors.push('Name must be 50 characters or less');
if (req.body.name && req.body.name.length > globalLimits.fieldLength.boardname) {
errors.push(`Name must be ${globalLimits.fieldLength.boardname} characters or less`);
}
if (req.body.description && req.body.description.length > 50) {
errors.push('Description must be 50 characters or less');
if (req.body.description && req.body.description.length > globalLimits.fieldLength.description) {
errors.push(`Description must be ${globalLimits.fieldLength.description} characters or less`);
}
if (errors.length > 0) {

@ -1,6 +1,7 @@
'use strict';
const { Posts } = require(__dirname+'/../../db/')
, { globalLimits } = require(__dirname+'/../../configs/main.js')
, actionHandler = require(__dirname+'/../../models/forms/actionhandler.js')
, actionChecker = require(__dirname+'/../../helpers/checks/actionchecker.js');
@ -32,14 +33,14 @@ module.exports = async (req, res, next) => {
}
//check that actions are valid
if (req.body.postpassword && req.body.postpassword.length > 50) {
errors.push('Password must be 50 characters or less');
if (req.body.postpassword && req.body.postpassword.length > globalLimits.fieldLength.postpassword) {
errors.push(`Password must be ${globalLimits.fieldLength.postpassword} characters or less`);
}
if (req.body.ban_reason && req.body.ban_reason.length > 50) {
errors.push('Ban reason must be 50 characters or less');
if (req.body.ban_reason && req.body.ban_reason.length > globalLimits.fieldLength.ban_reason) {
errors.push(`Ban reason must be ${globalLimits.fieldLength.ban_reason} characters or less`);
}
if (req.body.log_message && req.body.log_message.length > 50) {
errors.push('Modlog must be 50 characters or less');
if (req.body.log_message && req.body.log_message.length > globalLimits.fieldLength.log_message) {
errors.push(`Modlog message must be ${globalLimits.fieldLength.log_message} characters or less`);
}
//return the errors

@ -38,8 +38,8 @@ module.exports = async (req, res, next) => {
}
}
if (req.body.message) {
if (req.body.message.length > globalLimits.messageLength.max) {
errors.push(`Message must be ${globalLimits.messageLength.max} characters or less`);
if (req.body.message.length > globalLimits.fieldLength.message) {
errors.push(`Message must be ${globalLimits.fieldLength.message} characters or less`);
} else if (!req.body.thread
&& res.locals.board.settings.maxThreadMessageLength
&& req.body.message.length > res.locals.board.settings.maxThreadMessageLength) {
@ -56,17 +56,17 @@ module.exports = async (req, res, next) => {
}
// subject, email, name, password limited length
if (req.body.name && req.body.name.length > 50) {
errors.push('Name must be 50 characters or less');
if (req.body.postpassword && req.body.postpassword.length > globalLimits.fieldLength.postpassword) {
errors.push(`Password must be ${globalLimits.fieldLength.postpassword} characters or less`);
}
if (req.body.subject && req.body.subject.length > 50) {
errors.push('Subject must be 50 characters or less');
if (req.body.name && req.body.name.length > globalLimits.fieldLength.name) {
errors.push(`Name must be ${globalLimits.fieldLength.name} characters or less`);
}
if (req.body.email && req.body.email.length > 50) {
errors.push('Email must be 50 characters or less');
if (req.body.subject && req.body.subject.length > globalLimits.fieldLength.subject) {
errors.push(`Subject must be ${globalLimits.fieldLength.subject} characters or less`);
}
if (req.body.postpassword && req.body.postpassword.length > 50) {
errors.push('Password must be 50 characters or less');
if (req.body.email && req.body.email.length > globalLimits.fieldLength.email) {
errors.push(`Email must be ${globalLimits.fieldLength.email} characters or less`);
}
if (errors.length > 0) {

@ -17,11 +17,11 @@ section.form-wrapper.flex-center
else
section.row
.label Name
input.mr-1(type='text', name='name', placeholder=board.settings.defaultName autocomplete='off' maxlength='50')
input.mr-1(type='text', name='name', placeholder=board.settings.defaultName maxlength=globalLimits.fieldLength.name)
a.close.postform-style(href='#!') X
section.row
.label Email
input(type='text', name='email', autocomplete='off' maxlength='50')
input(type='text', name='email', autocomplete='off' maxlength=globalLimits.fieldLength.email)
include ./subjectfield.pug
section.row
.label
@ -29,7 +29,7 @@ section.form-wrapper.flex-center
if messageRequired
span.required *
- const minLength = (isThread ? board.settings.minReplyMessageLength : board.settings.minThreadMessageLength) || 0;
- const maxLength = Math.min((isThread ? board.settings.maxReplyMessageLength : board.settings.maxThreadMessageLength), globalLimits.messageLength.max) || globalLimits.messageLength.max;
- const maxLength = Math.min((isThread ? board.settings.maxReplyMessageLength : board.settings.maxThreadMessageLength), globalLimits.fieldLength.message) || globalLimits.fieldLength.message;
textarea#message(name='message', rows='5', autocomplete='off' minlength=minLength maxlength=maxLength required=messageRequired)
if board.settings.maxFiles > 0
- const maxFiles = board.settings.maxFiles;
@ -52,7 +52,7 @@ section.form-wrapper.flex-center
if board.settings.userPostSpoiler || board.settings.userPostDelete || board.settings.userPostUnlink
section.row
.label Password
input(type='password', name='postpassword', autocomplete='off' placeholder='password to delete/spoiler/unlink later' maxlength='50')
input(type='password', name='postpassword' placeholder='password to delete/spoiler/unlink later' maxlength=globalLimits.fieldLength.postpassword)
if (board.settings.captchaMode === 1 && !isThread) || board.settings.captchaMode === 2
section.row
.label

@ -4,4 +4,4 @@ if !isThread || (!board.settings.disableReplySubject && !board.settings.forceAno
span Subject
if subjectRequired
span.required *
input(type='text', name='subject', autocomplete='off' maxlength='50' required=subjectRequired)
input(type='text', name='subject', autocomplete='off' maxlength=globalLimits.fieldLength.subject required=subjectRequired)

@ -10,13 +10,13 @@ block content
form.form-post(action='/forms/create' method='POST')
.row
.label URI e.g. /uri/
input(type='text', name='uri', maxlength='50' pattern='[a-zA-Z0-9]+' required title='alphanumeric only')
input(type='text', name='uri', maxlength=globalLimits.fieldLength.uri pattern='[a-zA-Z0-9]+' required title='alphanumeric only')
.row
.label Name
input(type='text', name='name', maxlength='50' required)
input(type='text', name='name', maxlength=globalLimits.fieldLength.boardname required)
.row
.label Description
input(type='text', name='description', maxlength='50' required)
input(type='text', name='description', maxlength=globalLimits.fieldLength.description required)
.row
.label Tags
textarea(name='tags' placeholder='newline separated, max 10')

@ -131,16 +131,16 @@ block content
input(type='checkbox', name='disable_reply_subject', value='true' checked=board.settings.disableReplySubject)
.row
.label Min Thread Message Length
input(type='number' name='min_thread_message_length' value=board.settings.minThreadMessageLength max=globalLimits.messageLength.max)
input(type='number' name='min_thread_message_length' value=board.settings.minThreadMessageLength max=globalLimits.fieldLength.message)
.row
.label Min Reply Message Length
input(type='number' name='min_reply_message_length' value=board.settings.minReplyMessageLength max=globalLimits.messageLength.max)
input(type='number' name='min_reply_message_length' value=board.settings.minReplyMessageLength max=globalLimits.fieldLength.message)
.row
.label Max Thread Message Length
input(type='number' name='max_thread_message_length' value=board.settings.maxThreadMessageLength max=globalLimits.messageLength.max)
input(type='number' name='max_thread_message_length' value=board.settings.maxThreadMessageLength max=globalLimits.fieldLength.message)
.row
.label Max Reply Message Length
input(type='number' name='max_reply_message_length' value=board.settings.maxReplyMessageLength max=globalLimits.messageLength.max)
input(type='number' name='max_reply_message_length' value=board.settings.maxReplyMessageLength max=globalLimits.fieldLength.message)
.row
.label Thread Limit
input(type='number' name='thread_limit' value=board.settings.threadLimit min=globalLimits.threadLimit.min max=globalLimits.threadLimit.max)

Loading…
Cancel
Save