mirror of
https://github.com/LdesignMedia/moodle-availability_ipaddress.git
synced 2026-05-17 05:48:41 +02:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc43dbdf0b | ||
|
|
3ba695cb97 | ||
|
|
020dac34ba | ||
|
|
0468b49b6a | ||
|
|
aba5912e50 | ||
|
|
fbe446e53b | ||
|
|
e7e711b67b | ||
|
|
1785ee947a | ||
|
|
86dbd31b2e | ||
|
|
f1190518b8 | ||
|
|
8eb790f800 | ||
|
|
6c92077941 | ||
|
|
dc0a3aeb43 |
214
.eslintrc
Normal file
214
.eslintrc
Normal file
@@ -0,0 +1,214 @@
|
||||
{
|
||||
'plugins': [
|
||||
'promise',
|
||||
],
|
||||
'env': {
|
||||
'browser': true,
|
||||
'amd': true
|
||||
},
|
||||
'globals': {
|
||||
'M': true,
|
||||
'Y': true
|
||||
},
|
||||
'rules': {
|
||||
// See http://eslint.org/docs/rules/ for all rules and explanations of all
|
||||
// rules.
|
||||
|
||||
// === Possible Errors ===
|
||||
'comma-dangle': 'off',
|
||||
'no-compare-neg-zero': 'error',
|
||||
'no-cond-assign': 'error',
|
||||
'no-console': 'error',
|
||||
'no-constant-condition': 'error',
|
||||
'no-control-regex': 'error',
|
||||
'no-debugger': 'error',
|
||||
'no-dupe-args': 'error',
|
||||
'no-dupe-keys': 'error',
|
||||
'no-duplicate-case': 'error',
|
||||
'no-empty': 'warn',
|
||||
'no-empty-character-class': 'error',
|
||||
'no-ex-assign': 'error',
|
||||
'no-extra-boolean-cast': 'error',
|
||||
'no-extra-parens': 'off',
|
||||
'no-extra-semi': 'error',
|
||||
'no-func-assign': 'error',
|
||||
'no-inner-declarations': 'error',
|
||||
'no-invalid-regexp': 'error',
|
||||
'no-irregular-whitespace': 'error',
|
||||
'no-obj-calls': 'error',
|
||||
'no-prototype-builtins': 'off',
|
||||
'no-regex-spaces': 'error',
|
||||
'no-sparse-arrays': 'error',
|
||||
'no-unexpected-multiline': 'error',
|
||||
'no-unreachable': 'warn',
|
||||
'no-unsafe-finally': 'error',
|
||||
'no-unsafe-negation': 'error',
|
||||
'use-isnan': 'error',
|
||||
'valid-jsdoc': ['warn', { 'requireReturn': false, 'requireParamDescription': false, 'requireReturnDescription': false }],
|
||||
'valid-typeof': 'error',
|
||||
|
||||
// === Best Practices ===
|
||||
// (these mostly match our jshint config)
|
||||
'array-callback-return': 'warn',
|
||||
'block-scoped-var': 'warn',
|
||||
'complexity': 'warn',
|
||||
'consistent-return': 'warn',
|
||||
'curly': 'error',
|
||||
'dot-notation': 'warn',
|
||||
'no-alert': 'warn',
|
||||
'no-caller': 'error',
|
||||
'no-case-declarations': 'error',
|
||||
'no-div-regex': 'error',
|
||||
'no-empty-pattern': 'error',
|
||||
'no-empty-function': 'warn',
|
||||
'no-eq-null': 'error',
|
||||
'no-eval': 'error',
|
||||
'no-extend-native': 'error',
|
||||
'no-extra-bind': 'warn',
|
||||
'no-fallthrough': 'error',
|
||||
'no-floating-decimal': 'warn',
|
||||
'no-global-assign': 'warn',
|
||||
'no-implied-eval': 'error',
|
||||
'no-invalid-this': 'error',
|
||||
'no-iterator': 'error',
|
||||
'no-labels': 'error',
|
||||
'no-loop-func': 'error',
|
||||
'no-multi-spaces': 'warn',
|
||||
'no-multi-str': 'error',
|
||||
'no-new-func': 'error',
|
||||
'no-new-wrappers': 'error',
|
||||
'no-octal': 'error',
|
||||
'no-octal-escape': 'error',
|
||||
'no-proto': 'error',
|
||||
'no-redeclare': 'warn',
|
||||
'no-return-assign': 'error',
|
||||
'no-script-url': 'error',
|
||||
'no-self-assign': 'error',
|
||||
'no-self-compare': 'error',
|
||||
'no-sequences': 'warn',
|
||||
'no-throw-literal': 'warn',
|
||||
'no-unmodified-loop-condition': 'error',
|
||||
'no-unused-expressions': 'error',
|
||||
'no-unused-labels': 'error',
|
||||
'no-useless-call': 'warn',
|
||||
'no-useless-escape': 'warn',
|
||||
'no-with': 'error',
|
||||
'wrap-iife': ['error', 'any'],
|
||||
|
||||
// === Variables ===
|
||||
'no-delete-var': 'error',
|
||||
'no-undef': 'error',
|
||||
'no-undef-init': 'error',
|
||||
'no-unused-vars': ['error', { 'caughtErrors': 'none' }],
|
||||
|
||||
// === Stylistic Issues ===
|
||||
'array-bracket-spacing': 'warn',
|
||||
'block-spacing': 'warn',
|
||||
'brace-style': ['warn', '1tbs'],
|
||||
'camelcase': 'warn',
|
||||
'capitalized-comments': ['warn', 'always', { 'ignoreConsecutiveComments': true }],
|
||||
'comma-spacing': ['warn', { 'before': false, 'after': true }],
|
||||
'comma-style': ['warn', 'last'],
|
||||
'computed-property-spacing': 'error',
|
||||
'consistent-this': 'off',
|
||||
'eol-last': 'off',
|
||||
'func-call-spacing': ['warn', 'never'],
|
||||
'func-names': 'off',
|
||||
'func-style': 'off',
|
||||
// indent currently not doing well with our wrapping style, so disabled.
|
||||
'indent': ['off', 4, { 'SwitchCase': 1 }],
|
||||
'key-spacing': ['warn', { 'beforeColon': false, 'afterColon': true, 'mode': minimum }],
|
||||
'keyword-spacing': 'warn',
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'lines-around-comment': 'off',
|
||||
'max-len': ['error', 132],
|
||||
'max-lines': 'off',
|
||||
'max-depth': 'warn',
|
||||
'max-nested-callbacks': ['warn', 5],
|
||||
'max-params': 'off',
|
||||
'max-statements': 'off',
|
||||
'max-statements-per-line': ['warn', { max: 2 }],
|
||||
'new-cap': ['warn', { 'properties': false }],
|
||||
'new-parens': 'warn',
|
||||
'newline-after-var': 'off',
|
||||
'newline-before-return': 'off',
|
||||
'newline-per-chained-call': 'off',
|
||||
'no-array-constructor': 'off',
|
||||
'no-bitwise': 'error',
|
||||
'no-continue': 'off',
|
||||
'no-inline-comments': 'off',
|
||||
'no-lonely-if': 'off',
|
||||
'no-mixed-operators': 'off',
|
||||
'no-mixed-spaces-and-tabs': 'error',
|
||||
'no-multiple-empty-lines': 'warn',
|
||||
'no-negated-condition': 'off',
|
||||
'no-nested-ternary': 'warn',
|
||||
'no-new-object': 'off',
|
||||
'no-plusplus': 'off',
|
||||
'no-tabs': 'error',
|
||||
'no-ternary': 'off',
|
||||
'no-trailing-spaces': 'error',
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-unneeded-ternary': 'off',
|
||||
'no-whitespace-before-property': 'warn',
|
||||
'object-curly-newline': 'off',
|
||||
'object-curly-spacing': 'warn',
|
||||
'object-property-newline': 'off',
|
||||
'one-var': 'off',
|
||||
'one-var-declaration-per-line': ['warn', 'initializations'],
|
||||
'operator-assignment': 'off',
|
||||
'operator-linebreak': 'off',
|
||||
'padded-blocks': 'off',
|
||||
'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
|
||||
'quotes': 'off',
|
||||
'require-jsdoc': 'warn',
|
||||
'semi': 'error',
|
||||
'semi-spacing': ['warn', {'before': false, 'after': true}],
|
||||
'sort-vars': 'off',
|
||||
'space-before-blocks': 'warn',
|
||||
'space-before-function-paren': ['warn', 'never'],
|
||||
'space-in-parens': 'warn',
|
||||
'space-infix-ops': 'warn',
|
||||
'space-unary-ops': 'warn',
|
||||
'spaced-comment': 'warn',
|
||||
'unicode-bom': 'error',
|
||||
'wrap-regex': 'off',
|
||||
|
||||
// === Promises ===
|
||||
'promise/always-return': 'warn',
|
||||
'promise/no-return-wrap': 'warn',
|
||||
'promise/param-names': 'warn',
|
||||
'promise/catch-or-return': ['warn', {terminationMethod: ['catch', 'fail']}],
|
||||
'promise/no-native': 'warn',
|
||||
'promise/no-promise-in-callback': 'warn',
|
||||
'promise/no-callback-in-promise': 'warn',
|
||||
'promise/avoid-new': 'warn',
|
||||
|
||||
// === Deprecations ===
|
||||
"no-restricted-properties": ['warn', {
|
||||
'object': 'M',
|
||||
'property': 'str',
|
||||
'message': 'Use AMD module "core/str" or M.util.get_string()'
|
||||
}],
|
||||
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ["**/yui/src/**/*.js"],
|
||||
// Disable some rules which we can't safely define for YUI rollups.
|
||||
rules: {
|
||||
'no-undef': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'no-unused-expressions': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ["**/amd/src/*.js"],
|
||||
// Check AMD with some slightly stricter rules.
|
||||
rules: {
|
||||
'no-unused-vars': 'error',
|
||||
'no-implicit-globals': 'error'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: [MFreakNL]
|
||||
54
.travis.yml
54
.travis.yml
@@ -1,56 +1,62 @@
|
||||
language: php
|
||||
|
||||
# Workaround for fixing that Selenium server is not running and therefore javascript Behat tests are not working:
|
||||
# https://github.com/moodlerooms/moodle-plugin-ci/issues/70
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
addons:
|
||||
firefox: "47.0.1"
|
||||
hosts:
|
||||
- moodle.test
|
||||
firefox: "35.0.1"
|
||||
postgresql: "9.4"
|
||||
apt:
|
||||
packages:
|
||||
- openjdk-8-jre-headless
|
||||
- oracle-java9-installer
|
||||
- oracle-java9-set-default
|
||||
- redis-server
|
||||
|
||||
services:
|
||||
- redis-server
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
- $HOME/.npm
|
||||
|
||||
php:
|
||||
# PHP 5.6 gives errors because of the provider.php needs to be PHP7
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
env:
|
||||
global:
|
||||
- MOODLE_BRANCH=MOODLE_32_STABLE
|
||||
- MOODLE_BRANCH=MOODLE_35_STABLE
|
||||
- MOODLE_BRANCH=MOODLE_36_STABLE
|
||||
matrix:
|
||||
- DB=pgsql
|
||||
- DB=mysqli
|
||||
- IGNORE_PATHS=vendor,source
|
||||
- IGNORE_NAMES=*.txt,*.md
|
||||
|
||||
# Alternate tests with MySQL and PostgreSQL
|
||||
matrix:
|
||||
include:
|
||||
# PHP 7.0
|
||||
- php: 7.0
|
||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
|
||||
- php: 7.2
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
|
||||
- php: 7.2
|
||||
env: DB=pgsql MOODLE_BRANCH=master
|
||||
|
||||
before_install:
|
||||
- phpenv config-rm xdebug.ini
|
||||
- nvm install 8.9
|
||||
- nvm use 8.9
|
||||
- cd ../..
|
||||
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
|
||||
- nvm install 8.9;
|
||||
nvm use 8.9;
|
||||
composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2;
|
||||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
||||
|
||||
install:
|
||||
- moodle-plugin-ci add-plugin moodlehq/moodle-local_moodlecheck
|
||||
- moodle-plugin-ci install
|
||||
- moodle-plugin-ci install -vvv
|
||||
- echo '$CFG->cookiesecure = false;' >> moodle/config.php
|
||||
|
||||
script:
|
||||
- php moodle/local/moodlecheck/cli/moodlecheck.php --path=availability/condition/ipaddress --format=text
|
||||
- moodle-plugin-ci validate
|
||||
- moodle-plugin-ci phplint
|
||||
- moodle-plugin-ci phpcpd
|
||||
- moodle-plugin-ci phpmd
|
||||
- moodle-plugin-ci codechecker
|
||||
- moodle-plugin-ci validate
|
||||
- moodle-plugin-ci savepoints
|
||||
- moodle-plugin-ci mustache
|
||||
- moodle-plugin-ci grunt
|
||||
- moodle-plugin-ci grunt || false
|
||||
- moodle-plugin-ci phpunit
|
||||
- moodle-plugin-ci behat
|
||||
@@ -10,6 +10,8 @@ Restrict access to any activity by ip-address. Most activities don't support thi
|
||||
|
||||
[](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress)
|
||||
|
||||

|
||||
|
||||
## List of features
|
||||
- Supports comma separate list of ip-addresses
|
||||
- Subnet support, eg 192.168.1.0/24
|
||||
@@ -22,6 +24,9 @@ Restrict access to any activity by ip-address. Most activities don't support thi
|
||||
3. Go to Site Administrator > Notification
|
||||
4. Install the plugin
|
||||
|
||||
## TODO
|
||||
- Behat tests ip validation
|
||||
|
||||
## Security
|
||||
|
||||
If you discover any security related issues, please email [luuk@MFreak.nl](mailto:luuk@MFreak.nl) instead of using the issue tracker.
|
||||
|
||||
48
classes/privacy/provider.php
Normal file
48
classes/privacy/provider.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for availability_ipaddress.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @package availability_ipaddress
|
||||
* @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
|
||||
* @author Luuk Verhoeven
|
||||
**/
|
||||
|
||||
namespace availability_ipaddress\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for availability_ipaddress implementing null_provider.
|
||||
*
|
||||
* @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
return 'privacy:metadata';
|
||||
}
|
||||
}
|
||||
@@ -33,3 +33,6 @@ $string['js:ipaddress'] = 'Require network address';
|
||||
|
||||
// Errors.
|
||||
$string['error_ipaddress'] = 'Incorrect ip-address/subnet format';
|
||||
|
||||
// Privacy provider.
|
||||
$string['privacy:metadata'] = 'The restriction by activity ipaddress plugin does not store any personal data.';
|
||||
@@ -27,7 +27,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'availability_ipaddress';
|
||||
$plugin->version = 2019051500;
|
||||
$plugin->release = 'v3.5.0';
|
||||
$plugin->version = 2020061500;
|
||||
$plugin->release = '3.9.0';
|
||||
$plugin->requires = 2016120500;
|
||||
$plugin->maturity = MATURITY_BETA;
|
||||
@@ -19,19 +19,17 @@ M.availability_ipaddress = M.availability_ipaddress || {};
|
||||
// Advanced ip-address regex for validating.
|
||||
M.availability_ipaddress.v4 = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9]' +
|
||||
'[0-9]|[1-9][0-9]|[0-9])){3}';
|
||||
M.availability_ipaddress.v6 = '((?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|:[0-9a-fA-F]{1,4}|:)' +
|
||||
'|(?:[0-9a-fA-F]{1,4}:){5}(?::(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,2}|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:' +
|
||||
'(:[0-9a-fA-F]{1,4}){0,1}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,3}|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(:[0-9a-fA-F]{1,4}){0,2}:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(:[0-9a-fA-F]{1,4}){1,4}|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(:[0-9a-fA-F]{1,4}){0,3}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|' +
|
||||
'[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,5}|:)|' +
|
||||
'(?:[0-9a-fA-F]{1,4}:){1}(?:(:[0-9a-fA-F]{1,4}){0,4}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.' +
|
||||
'(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,6}|:)|(?::((?::[0-9a-fA-F]{1,4}){0,5}' +
|
||||
':(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(?::[0-9a-fA-F]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?';
|
||||
M.availability_ipaddress.v6 = "^((?:[a-fA-F\\d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9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,6}|:)|(?::" +
|
||||
"((?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}" +
|
||||
"|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?";
|
||||
|
||||
/**
|
||||
* @class M.availability_ipaddress.form
|
||||
@@ -47,7 +45,7 @@ M.availability_ipaddress.form = Y.Object(M.core_availability.plugin);
|
||||
*/
|
||||
M.availability_ipaddress.form.initInner = function() {
|
||||
"use strict";
|
||||
Y.log('M.availability_ipaddress');
|
||||
Y.log('M.availability_ipaddress 1.10');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -55,27 +53,29 @@ M.availability_ipaddress.form.initInner = function() {
|
||||
* dot or comma).
|
||||
*
|
||||
* @method getValue
|
||||
* @param {string} field
|
||||
* @param {object} node
|
||||
* @return {Number|String} Value of field as number or string if not valid
|
||||
*/
|
||||
M.availability_ipaddress.form.getValue = function(field, node) {
|
||||
"use strict";
|
||||
// Get field value.
|
||||
var value = node.one('input[name=' + field + ']').get('value');
|
||||
Y.log('ip_address:', value);
|
||||
Y.log('ip_address:' + value);
|
||||
|
||||
// If it is not a valid positive number, return false.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value)) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value)) {
|
||||
Y.log('Valid ip-address');
|
||||
return value;
|
||||
}
|
||||
|
||||
Y.log('getValue failed:', value);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* getNode
|
||||
* @param json
|
||||
* Get node
|
||||
*
|
||||
* @param {object} json
|
||||
* @returns {*}
|
||||
*/
|
||||
M.availability_ipaddress.form.getNode = function(json) {
|
||||
@@ -112,38 +112,53 @@ M.availability_ipaddress.form.getNode = function(json) {
|
||||
};
|
||||
|
||||
/**
|
||||
* validate_ipaddress
|
||||
* Validate ipaddresses
|
||||
*
|
||||
* @param {string[]} ipaddresses
|
||||
* @returns {boolean}
|
||||
*/
|
||||
M.availability_ipaddress.validate_ipaddress = function(ipaddresses) {
|
||||
M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
'use strict';
|
||||
|
||||
Y.log(ipaddresses);
|
||||
ipaddresses = ipaddresses.split(',');
|
||||
for (var i in ipaddresses) {
|
||||
|
||||
// Test normal ip format.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4, ")|(?:").concat(M.availability_ipaddress.v6, ")"), "g")
|
||||
// Strict ipv4 check.
|
||||
if (new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv6');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Test subnet with a regex.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")"), "g")
|
||||
if (new RegExp("^(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])|(1\\*)", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")?\\/gm"))
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct subnet');
|
||||
continue;
|
||||
}
|
||||
|
||||
Y.log('Incorrect ip', ipaddresses[i]);
|
||||
Y.log('Incorrect ip');
|
||||
return false;
|
||||
}
|
||||
|
||||
Y.log('Valid ipaddresses', ipaddresses);
|
||||
Y.log('Valid ipaddresses');
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* FillValue
|
||||
*
|
||||
* @param {object} value
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
// This function gets passed the node (from above) and a value
|
||||
// object. Within that object, it must set up the correct values
|
||||
@@ -153,13 +168,18 @@ M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
value.ipaddresses = this.getValue('ipaddresses', node);
|
||||
};
|
||||
|
||||
/**
|
||||
* FillErrors
|
||||
* @param {object} errors
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillErrors = function(errors, node) {
|
||||
"use strict";
|
||||
var value = {};
|
||||
this.fillValue(value, node);
|
||||
|
||||
// Basic ipaddresses checks.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value.ipaddresses) === false) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value.ipaddresses) === false) {
|
||||
errors.push('availability_ipaddress:error_ipaddress');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
YUI.add("moodle-availability_ipaddress-form",function(e,t){M.availability_ipaddress=M.availability_ipaddress||{},M.availability_ipaddress.v4="(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}",M.availability_ipaddress.v6="((?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|:[0-9a-fA-F]{1,4}|:)|(?:[0-9a-fA-F]{1,4}:){5}(?::(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,2}|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:(:[0-9a-fA-F]{1,4}){0,1}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,3}|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(:[0-9a-fA-F]{1,4}){0,2}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,4}|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(:[0-9a-fA-F]{1,4}){0,3}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,5}|:)|(?:[0-9a-fA-F]{1,4}:){1}(?:(:[0-9a-fA-F]{1,4}){0,4}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,6}|:)|(?::((?::[0-9a-fA-F]{1,4}){0,5}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(?::[0-9a-fA-F]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?",M.availability_ipaddress.form=e.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){"use strict";},M.availability_ipaddress.form.getValue=function(e,t){"use strict";var n=t.one("input[name="+e+"]").get("value");return M.availability_ipaddress.validate_ipaddress(n)?n:n},M.availability_ipaddress.form.getNode=function(t){"use strict";var n,r,i,s;return s="ipaddresses"+M.availability_ipaddress.form.instId,M.availability_ipaddress.form.instId+=1,n="",n+='<span class="availability-group"><label for="'+s+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",n+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+s+'">',r=e.Node.create('<span class="form-inline">'+n+"</span>"),t.ipaddresses!==undefined&&r.one("input[name=ipaddresses]").set("value",t.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,i=e.one(".availability-field"),i.delegate("valuechange",function(){M.core_availability.form.update()},".availability_ipaddress input[name=ipaddresses]")),r},M.availability_ipaddress.validate_ipaddress=function(e){"use strict";e=e.split(",");for(var t in e){if((new RegExp("(?:".concat(M.availability_ipaddress.v4,")|(?:").concat(M.availability_ipaddress.v6,")"),"g")).test(e[t]))continue;if((new RegExp("(?:".concat(M.availability_ipaddress.v4+"\\/(3[0-2]|[12]?[0-9])",")|(?:").concat(M.availability_ipaddress.v6+"\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])",")"),"g")).test(e[t]))continue;return!1}return!0},M.availability_ipaddress.form.fillValue=function(e,t){e.ipaddresses=this.getValue("ipaddresses",t)},M.availability_ipaddress.form.fillErrors=function(e,t){"use strict";var n={};this.fillValue(n,t),M.availability_ipaddress.validate_ipaddress(n.ipaddresses)===!1&&e.push("availability_ipaddress:error_ipaddress")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]});
|
||||
YUI.add("moodle-availability_ipaddress-form",function(e,t){M.availability_ipaddress=M.availability_ipaddress||{},M.availability_ipaddress.v4="(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.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\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,6}|:)|(?::((?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?",M.availability_ipaddress.form=e.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){"use strict";},M.availability_ipaddress.form.getValue=function(e,t){"use strict";var n=t.one("input[name="+e+"]").get("value");return M.availability_ipaddress.validateIpaddress(n)?n:n},M.availability_ipaddress.form.getNode=function(t){"use strict";var n,r,i,s;return s="ipaddresses"+M.availability_ipaddress.form.instId,M.availability_ipaddress.form.instId+=1,n="",n+='<span class="availability-group"><label for="'+s+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",n+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+s+'">',r=e.Node.create('<span class="form-inline">'+n+"</span>"),t.ipaddresses!==undefined&&r.one("input[name=ipaddresses]").set("value",t.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,i=e.one(".availability-field"),i.delegate("valuechange",function(){M.core_availability.form.update()},".availability_ipaddress input[name=ipaddresses]")),r},M.availability_ipaddress.validateIpaddress=function(e){"use strict";e=e.split(",");for(var t in e){if((new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm)).test(e[t]))continue;if((new RegExp(M.availability_ipaddress.v6)).test(e[t]))continue;if((new RegExp("^(?:".concat(M.availability_ipaddress.v4+"\\/(3[0-2]|[12]?[0-9])|(1\\*)",")|(?:").concat(M.availability_ipaddress.v6+"\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])",")?\\/gm"))).test(e[t]))continue;return!1}return!0},M.availability_ipaddress.form.fillValue=function(e,t){e.ipaddresses=this.getValue("ipaddresses",t)},M.availability_ipaddress.form.fillErrors=function(e,t){"use strict";var n={};this.fillValue(n,t),M.availability_ipaddress.validateIpaddress(n.ipaddresses)===!1&&e.push("availability_ipaddress:error_ipaddress")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]});
|
||||
|
||||
@@ -19,19 +19,17 @@ M.availability_ipaddress = M.availability_ipaddress || {};
|
||||
// Advanced ip-address regex for validating.
|
||||
M.availability_ipaddress.v4 = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9]' +
|
||||
'[0-9]|[1-9][0-9]|[0-9])){3}';
|
||||
M.availability_ipaddress.v6 = '((?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|:[0-9a-fA-F]{1,4}|:)' +
|
||||
'|(?:[0-9a-fA-F]{1,4}:){5}(?::(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,2}|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:' +
|
||||
'(:[0-9a-fA-F]{1,4}){0,1}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,3}|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(:[0-9a-fA-F]{1,4}){0,2}:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(:[0-9a-fA-F]{1,4}){1,4}|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(:[0-9a-fA-F]{1,4}){0,3}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|' +
|
||||
'[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,5}|:)|' +
|
||||
'(?:[0-9a-fA-F]{1,4}:){1}(?:(:[0-9a-fA-F]{1,4}){0,4}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.' +
|
||||
'(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,6}|:)|(?::((?::[0-9a-fA-F]{1,4}){0,5}' +
|
||||
':(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(?::[0-9a-fA-F]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?';
|
||||
M.availability_ipaddress.v6 = "^((?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]" +
|
||||
"\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}"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)))(%[0-9a-zA-Z]{1,})?";
|
||||
|
||||
/**
|
||||
* @class M.availability_ipaddress.form
|
||||
@@ -54,6 +52,8 @@ M.availability_ipaddress.form.initInner = function() {
|
||||
* dot or comma).
|
||||
*
|
||||
* @method getValue
|
||||
* @param {string} field
|
||||
* @param {object} node
|
||||
* @return {Number|String} Value of field as number or string if not valid
|
||||
*/
|
||||
M.availability_ipaddress.form.getValue = function(field, node) {
|
||||
@@ -62,7 +62,7 @@ M.availability_ipaddress.form.getValue = function(field, node) {
|
||||
var value = node.one('input[name=' + field + ']').get('value');
|
||||
|
||||
// If it is not a valid positive number, return false.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value)) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -70,8 +70,9 @@ M.availability_ipaddress.form.getValue = function(field, node) {
|
||||
};
|
||||
|
||||
/**
|
||||
* getNode
|
||||
* @param json
|
||||
* Get node
|
||||
*
|
||||
* @param {object} json
|
||||
* @returns {*}
|
||||
*/
|
||||
M.availability_ipaddress.form.getNode = function(json) {
|
||||
@@ -108,26 +109,31 @@ M.availability_ipaddress.form.getNode = function(json) {
|
||||
};
|
||||
|
||||
/**
|
||||
* validate_ipaddress
|
||||
* Validate ipaddresses
|
||||
*
|
||||
* @param {string[]} ipaddresses
|
||||
* @returns {boolean}
|
||||
*/
|
||||
M.availability_ipaddress.validate_ipaddress = function(ipaddresses) {
|
||||
M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
'use strict';
|
||||
|
||||
ipaddresses = ipaddresses.split(',');
|
||||
for (var i in ipaddresses) {
|
||||
|
||||
// Test normal ip format.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4, ")|(?:").concat(M.availability_ipaddress.v6, ")"), "g")
|
||||
// Strict ipv4 check.
|
||||
if (new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Test subnet with a regex.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")"), "g")
|
||||
if (new RegExp("^(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])|(1\\*)", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")?\\/gm"))
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
}
|
||||
@@ -138,6 +144,12 @@ M.availability_ipaddress.validate_ipaddress = function(ipaddresses) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* FillValue
|
||||
*
|
||||
* @param {object} value
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
// This function gets passed the node (from above) and a value
|
||||
// object. Within that object, it must set up the correct values
|
||||
@@ -147,13 +159,18 @@ M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
value.ipaddresses = this.getValue('ipaddresses', node);
|
||||
};
|
||||
|
||||
/**
|
||||
* FillErrors
|
||||
* @param {object} errors
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillErrors = function(errors, node) {
|
||||
"use strict";
|
||||
var value = {};
|
||||
this.fillValue(value, node);
|
||||
|
||||
// Basic ipaddresses checks.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value.ipaddresses) === false) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value.ipaddresses) === false) {
|
||||
errors.push('availability_ipaddress:error_ipaddress');
|
||||
}
|
||||
};
|
||||
|
||||
76
yui/src/form/js/form.js
vendored
76
yui/src/form/js/form.js
vendored
@@ -17,19 +17,17 @@ M.availability_ipaddress = M.availability_ipaddress || {};
|
||||
// Advanced ip-address regex for validating.
|
||||
M.availability_ipaddress.v4 = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9]' +
|
||||
'[0-9]|[1-9][0-9]|[0-9])){3}';
|
||||
M.availability_ipaddress.v6 = '((?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|:[0-9a-fA-F]{1,4}|:)' +
|
||||
'|(?:[0-9a-fA-F]{1,4}:){5}(?::(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,2}|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:' +
|
||||
'(:[0-9a-fA-F]{1,4}){0,1}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]' +
|
||||
'|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,3}|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(:[0-9a-fA-F]{1,4}){0,2}:(?:25[0-5]|2[0-4]' +
|
||||
'[0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(:[0-9a-fA-F]{1,4}){1,4}|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(:[0-9a-fA-F]{1,4}){0,3}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|' +
|
||||
'[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,5}|:)|' +
|
||||
'(?:[0-9a-fA-F]{1,4}:){1}(?:(:[0-9a-fA-F]{1,4}){0,4}:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.' +
|
||||
'(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(:[0-9a-fA-F]{1,4}){1,6}|:)|(?::((?::[0-9a-fA-F]{1,4}){0,5}' +
|
||||
':(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|' +
|
||||
'(?::[0-9a-fA-F]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?';
|
||||
M.availability_ipaddress.v6 = "^((?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]" +
|
||||
"\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}" +
|
||||
"(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4})" +
|
||||
"{1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(:[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]" +
|
||||
"|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(:[a-fA-F\\d]{1,4}){0,2}:" +
|
||||
"(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,4}|:)|" +
|
||||
"(?:[a-fA-F\\d]{1,4}:){2}(?:(:[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]" +
|
||||
"\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(:[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]" +
|
||||
"|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,6}|:)|(?::" +
|
||||
"((?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}" +
|
||||
"|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?";
|
||||
|
||||
/**
|
||||
* @class M.availability_ipaddress.form
|
||||
@@ -45,7 +43,7 @@ M.availability_ipaddress.form = Y.Object(M.core_availability.plugin);
|
||||
*/
|
||||
M.availability_ipaddress.form.initInner = function() {
|
||||
"use strict";
|
||||
Y.log('M.availability_ipaddress');
|
||||
Y.log('M.availability_ipaddress 1.10');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -53,27 +51,29 @@ M.availability_ipaddress.form.initInner = function() {
|
||||
* dot or comma).
|
||||
*
|
||||
* @method getValue
|
||||
* @param {string} field
|
||||
* @param {object} node
|
||||
* @return {Number|String} Value of field as number or string if not valid
|
||||
*/
|
||||
M.availability_ipaddress.form.getValue = function(field, node) {
|
||||
"use strict";
|
||||
// Get field value.
|
||||
var value = node.one('input[name=' + field + ']').get('value');
|
||||
Y.log('ip_address:', value);
|
||||
Y.log('ip_address:' + value);
|
||||
|
||||
// If it is not a valid positive number, return false.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value)) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value)) {
|
||||
Y.log('Valid ip-address');
|
||||
return value;
|
||||
}
|
||||
|
||||
Y.log('getValue failed:', value);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* getNode
|
||||
* @param json
|
||||
* Get node
|
||||
*
|
||||
* @param {object} json
|
||||
* @returns {*}
|
||||
*/
|
||||
M.availability_ipaddress.form.getNode = function(json) {
|
||||
@@ -110,38 +110,53 @@ M.availability_ipaddress.form.getNode = function(json) {
|
||||
};
|
||||
|
||||
/**
|
||||
* validate_ipaddress
|
||||
* Validate ipaddresses
|
||||
*
|
||||
* @param {string[]} ipaddresses
|
||||
* @returns {boolean}
|
||||
*/
|
||||
M.availability_ipaddress.validate_ipaddress = function(ipaddresses) {
|
||||
M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
'use strict';
|
||||
|
||||
Y.log(ipaddresses);
|
||||
ipaddresses = ipaddresses.split(',');
|
||||
for (var i in ipaddresses) {
|
||||
|
||||
// Test normal ip format.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4, ")|(?:").concat(M.availability_ipaddress.v6, ")"), "g")
|
||||
// Strict ipv4 check.
|
||||
if (new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv6');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Test subnet with a regex.
|
||||
if (new RegExp("(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")"), "g")
|
||||
if (new RegExp("^(?:".concat(M.availability_ipaddress.v4 + "\\/(3[0-2]|[12]?[0-9])|(1\\*)", ")|(?:")
|
||||
.concat(M.availability_ipaddress.v6 + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])", ")?\\/gm"))
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct subnet');
|
||||
continue;
|
||||
}
|
||||
|
||||
Y.log('Incorrect ip', ipaddresses[i]);
|
||||
Y.log('Incorrect ip');
|
||||
return false;
|
||||
}
|
||||
|
||||
Y.log('Valid ipaddresses', ipaddresses);
|
||||
Y.log('Valid ipaddresses');
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* FillValue
|
||||
*
|
||||
* @param {object} value
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
// This function gets passed the node (from above) and a value
|
||||
// object. Within that object, it must set up the correct values
|
||||
@@ -151,13 +166,18 @@ M.availability_ipaddress.form.fillValue = function(value, node) {
|
||||
value.ipaddresses = this.getValue('ipaddresses', node);
|
||||
};
|
||||
|
||||
/**
|
||||
* FillErrors
|
||||
* @param {object} errors
|
||||
* @param {object} node
|
||||
*/
|
||||
M.availability_ipaddress.form.fillErrors = function(errors, node) {
|
||||
"use strict";
|
||||
var value = {};
|
||||
this.fillValue(value, node);
|
||||
|
||||
// Basic ipaddresses checks.
|
||||
if (M.availability_ipaddress.validate_ipaddress(value.ipaddresses) === false) {
|
||||
if (M.availability_ipaddress.validateIpaddress(value.ipaddresses) === false) {
|
||||
errors.push('availability_ipaddress:error_ipaddress');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user