diff options
Diffstat (limited to 'apps/workflowengine/src')
5 files changed, 46 insertions, 299 deletions
diff --git a/apps/workflowengine/src/components/Values/file.js b/apps/workflowengine/src/components/Values/file.js index fa6851cc5c2..2d8ca936391 100644 --- a/apps/workflowengine/src/components/Values/file.js +++ b/apps/workflowengine/src/components/Values/file.js @@ -20,16 +20,13 @@ * */ -import './../../legacy/filenameplugin' import './../../legacy/filesystemtagsplugin' -import './../../legacy/requestremoteaddressplugin' import './../../legacy/requesttimeplugin' import './../../legacy/requesturlplugin' import './../../legacy/requestuseragentplugin' import './../../legacy/usergroupmembershipplugin' import FileMimeType from './FileMimeType'; -import SizeValue from './SizeValue'; const FileChecks = Object.values(OCA.WorkflowEngine.Plugins).map((plugin) => { if (plugin.component) { @@ -47,6 +44,26 @@ const validateRegex = function(string) { return result !== null } +const validateIPv4 = function(string) { + var regexRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[1-2][0-9]|[1-9])$/ + var result = regexRegex.exec(string) + return result !== null +} + +const validateIPv6 = function(string) { + var regexRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9])$/ + var result = regexRegex.exec(string) + return result !== null +} + +const stringValidator = (check) => { + if (check.operator === 'matches' || check.operator === '!matches') { + return validateRegex(check.value) + } + return true +} + + FileChecks.push({ class: 'OCA\\WorkflowEngine\\Check\\FileName', name: t('workflowengine', 'File name'), @@ -62,12 +79,7 @@ FileChecks.push({ } return 'filename.txt' }, - validate: (check) => { - if (check.operator === 'matches' || check.operator === '!matches') { - return validateRegex(check.value) - } - return true - } + validate: stringValidator }) FileChecks.push({ @@ -91,7 +103,31 @@ FileChecks.push({ { operator: '!less', name: t('workflowengine', 'greater or equals') }, { operator: 'greater', name: t('workflowengine', 'greater') } ], - component: SizeValue + placeholder: (check) => '5 MB', + validate: (check) => check.value.match(/^[0-9]+[ ]?[kmgt]?b$/i) !== null +}) + +FileChecks.push({ + class: 'OCA\\WorkflowEngine\\Check\\RequestRemoteAddress', + name: t('workflowengine', 'Request remote address'), + operators: [ + { operator: 'matchesIPv4', name: t('workflowengine', 'matches IPv4') }, + { operator: '!matchesIPv4', name: t('workflowengine', 'does not match IPv4') }, + { operator: 'matchesIPv6', name: t('workflowengine', 'matches IPv6') }, + { operator: '!matchesIPv6', name: t('workflowengine', 'does not match IPv6') } + ], + placeholder: (check) => { + if (check.operator === 'matchesIPv6' || check.operator === '!matchesIPv6') { + return '::1/128'; + } + return '127.0.0.1/32' + }, + validate: (check) => { + if (check.operator === 'matchesIPv6' || check.operator === '!matchesIPv6') { + return validateIPv6(check.value) + } + return validateIPv4(check.value) + } }) export default FileChecks diff --git a/apps/workflowengine/src/legacy/filemimetypeplugin.js b/apps/workflowengine/src/legacy/filemimetypeplugin.js deleted file mode 100644 index e58bdec26d3..00000000000 --- a/apps/workflowengine/src/legacy/filemimetypeplugin.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -(function() { - - OCA.WorkflowEngine = OCA.WorkflowEngine || {} - OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {} - - OCA.WorkflowEngine.Plugins.FileMimeTypePlugin = { - getCheck: function() { - return { - class: 'OCA\\WorkflowEngine\\Check\\FileMimeType', - name: t('workflowengine', 'File MIME type'), - operators: [ - { operator: 'is', name: t('workflowengine', 'is') }, - { operator: '!is', name: t('workflowengine', 'is not') }, - { operator: 'matches', name: t('workflowengine', 'matches') }, - { operator: '!matches', name: t('workflowengine', 'does not match') } - ] - } - }, - render: function(element, check) { - if (check.class !== 'OCA\\WorkflowEngine\\Check\\FileMimeType') { - return - } - - var placeholder = 'text/plain' - if (check.operator === 'matches' || check.operator === '!matches') { - placeholder = '/^text\\/(plain|html)$/i' - - if (this._validateRegex(check.value)) { - $(element).removeClass('invalid-input') - } else { - $(element).addClass('invalid-input') - } - } - - $(element).css('width', '250px') - .attr('placeholder', placeholder) - .attr('title', t('workflowengine', 'Example: {placeholder}', { placeholder: placeholder })) - .addClass('has-tooltip') - .tooltip({ - placement: 'bottom' - }) - }, - - _validateRegex: function(string) { - var regexRegex = /^\/(.*)\/([gui]{0,3})$/ - var result = regexRegex.exec(string) - return result !== null - } - } -})() diff --git a/apps/workflowengine/src/legacy/filenameplugin.js b/apps/workflowengine/src/legacy/filenameplugin.js deleted file mode 100644 index 637e08ccbea..00000000000 --- a/apps/workflowengine/src/legacy/filenameplugin.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @copyright Copyright (c) 2018 Daniel Kesselberg <mail@danielkesselberg.de> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -(function() { - - OCA.WorkflowEngine = OCA.WorkflowEngine || {} - OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {} - - OCA.WorkflowEngine.Plugins.FileNamePlugin = { - getCheck: function() { - return { - class: 'OCA\\WorkflowEngine\\Check\\FileName', - name: t('workflowengine', 'File name'), - operators: [ - { operator: 'is', name: t('workflowengine', 'is') }, - { operator: '!is', name: t('workflowengine', 'is not') }, - { - operator: 'matches', - name: t('workflowengine', 'matches') - }, - { - operator: '!matches', - name: t('workflowengine', 'does not match') - } - ] - } - }, - render: function(element, check) { - if (check.class !== 'OCA\\WorkflowEngine\\Check\\FileName') { - return - } - - var placeholder = 'dummy.jpg' - if (check.operator === 'matches' || check.operator === '!matches') { - placeholder = '/^dummy-.+$/i' - - if (this._validateRegex(check.value)) { - $(element).removeClass('invalid-input') - } else { - $(element).addClass('invalid-input') - } - } - - $(element).css('width', '250px') - .attr('placeholder', placeholder) - .attr('title', t('workflowengine', 'Example: {placeholder}', { placeholder: placeholder })) - .addClass('has-tooltip') - .tooltip({ - placement: 'bottom' - }) - }, - - _validateRegex: function(string) { - var regexRegex = /^\/(.*)\/([gui]{0,3})$/ - var result = regexRegex.exec(string) - return result !== null - } - } -})() - -OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.FileNamePlugin) diff --git a/apps/workflowengine/src/legacy/filesizeplugin.js b/apps/workflowengine/src/legacy/filesizeplugin.js deleted file mode 100644 index fcb81bd3397..00000000000 --- a/apps/workflowengine/src/legacy/filesizeplugin.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -import SizeValue from './../components/Values/SizeValue' -(function() { - - OCA.WorkflowEngine = OCA.WorkflowEngine || {} - OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {} - - OCA.WorkflowEngine.Plugins.FileSizePlugin = { - getCheck: function() { - return { - class: 'OCA\\WorkflowEngine\\Check\\FileSize', - name: t('workflowengine', 'File size (upload)'), - operators: [ - { operator: 'less', name: t('workflowengine', 'less') }, - { operator: '!greater', name: t('workflowengine', 'less or equals') }, - { operator: '!less', name: t('workflowengine', 'greater or equals') }, - { operator: 'greater', name: t('workflowengine', 'greater') } - ] - } - }, - render: function(element, check) { - if (check.class !== 'OCA\\WorkflowEngine\\Check\\FileSize') { - return - } - - var placeholder = '12 MB' // Do not translate!!! - $(element).css('width', '250px') - .attr('placeholder', placeholder) - .attr('title', t('workflowengine', 'Example: {placeholder}', { placeholder: placeholder })) - .addClass('has-tooltip') - .tooltip({ - placement: 'bottom' - }) - }, - component: function() { - return SizeValue - } - } -})() - -OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.FileSizePlugin) diff --git a/apps/workflowengine/src/legacy/requestremoteaddressplugin.js b/apps/workflowengine/src/legacy/requestremoteaddressplugin.js deleted file mode 100644 index b6f7d02dd46..00000000000 --- a/apps/workflowengine/src/legacy/requestremoteaddressplugin.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -(function() { - - OCA.WorkflowEngine = OCA.WorkflowEngine || {} - OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {} - - OCA.WorkflowEngine.Plugins.RequestRemoteAddressPlugin = { - getCheck: function() { - return { - class: 'OCA\\WorkflowEngine\\Check\\RequestRemoteAddress', - name: t('workflowengine', 'Request remote address'), - operators: [ - { operator: 'matchesIPv4', name: t('workflowengine', 'matches IPv4') }, - { operator: '!matchesIPv4', name: t('workflowengine', 'does not match IPv4') }, - { operator: 'matchesIPv6', name: t('workflowengine', 'matches IPv6') }, - { operator: '!matchesIPv6', name: t('workflowengine', 'does not match IPv6') } - ] - } - }, - render: function(element, check) { - if (check.class !== 'OCA\\WorkflowEngine\\Check\\RequestRemoteAddress') { - return - } - - var placeholder = '127.0.0.1/32' // Do not translate!!! - if (check.operator === 'matchesIPv6' || check.operator === '!matchesIPv6') { - placeholder = '::1/128' // Do not translate!!! - if (this._validateIPv6(check.value)) { - $(element).removeClass('invalid-input') - } else { - $(element).addClass('invalid-input') - } - } else { - if (this._validateIPv4(check.value)) { - $(element).removeClass('invalid-input') - } else { - $(element).addClass('invalid-input') - } - } - - $(element).css('width', '300px') - .attr('placeholder', placeholder) - .attr('title', t('workflowengine', 'Example: {placeholder}', { placeholder: placeholder })) - .addClass('has-tooltip') - .tooltip({ - placement: 'bottom' - }) - }, - - _validateIPv4: function(string) { - var regexRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[1-2][0-9]|[1-9])$/ - var result = regexRegex.exec(string) - return result !== null - }, - - _validateIPv6: function(string) { - var regexRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9])$/ - var result = regexRegex.exec(string) - return result !== null - } - } -})() - -OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.RequestRemoteAddressPlugin) |