mirror of
https://github.com/LdesignMedia/moodle-availability_ipaddress.git
synced 2026-05-17 05:48:41 +02:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d56173f6b8 | ||
|
|
c9b5e6cb7d | ||
|
|
fcfa4eb773 | ||
|
|
b98a63e1f4 | ||
|
|
a836731b24 | ||
|
|
c2f5e7e22c | ||
|
|
761d643479 | ||
|
|
5ef0c811c0 | ||
|
|
6633439651 | ||
|
|
4b4fced58b | ||
|
|
8ae54193d2 | ||
|
|
26bbc1cbdb | ||
|
|
5d615ddb24 | ||
|
|
5e2566fbba | ||
|
|
96c93c4096 | ||
|
|
d302aa626a | ||
|
|
787dba81f0 |
133
.github/workflows/ci.yml
vendored
133
.github/workflows/ci.yml
vendored
@@ -1,123 +1,18 @@
|
||||
name: Moodle Plugin CI
|
||||
# .github/workflows/ci.yml
|
||||
name: ci
|
||||
|
||||
on: [ push, pull_request ]
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:10
|
||||
env:
|
||||
POSTGRES_USER: 'postgres'
|
||||
POSTGRES_HOST_AUTH_METHOD: 'trust'
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
|
||||
mariadb:
|
||||
image: mariadb:10.5
|
||||
env:
|
||||
MYSQL_USER: 'root'
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- php: '7.4'
|
||||
moodle-branch: 'MOODLE_311_STABLE'
|
||||
database: pgsql
|
||||
- php: '7.4'
|
||||
moodle-branch: 'MOODLE_310_STABLE'
|
||||
database: mariadb
|
||||
- php: '7.3'
|
||||
moodle-branch: 'MOODLE_39_STABLE'
|
||||
database: pgsql
|
||||
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: plugin
|
||||
|
||||
- name: Setup PHP ${{ matrix.php }}
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: ${{ matrix.extensions }}
|
||||
ini-values: max_input_vars=5000
|
||||
coverage: none
|
||||
|
||||
- name: Initialise moodle-plugin-ci
|
||||
run: |
|
||||
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
|
||||
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
|
||||
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
|
||||
sudo locale-gen en_AU.UTF-8
|
||||
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
|
||||
|
||||
- name: Install moodle-plugin-ci
|
||||
run: |
|
||||
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
|
||||
env:
|
||||
DB: ${{ matrix.database }}
|
||||
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
|
||||
|
||||
- name: PHP Lint
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phplint
|
||||
|
||||
- name: PHP Copy/Paste Detector
|
||||
continue-on-error: true # This step will show errors but will not fail
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpcpd
|
||||
|
||||
- name: PHP Mess Detector
|
||||
continue-on-error: true # This step will show errors but will not fail
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpmd
|
||||
|
||||
- name: Moodle Code Checker
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci codechecker --max-warnings 0
|
||||
|
||||
- name: Moodle PHPDoc Checker
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpdoc
|
||||
|
||||
- name: Validating
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci validate
|
||||
|
||||
- name: Check upgrade savepoints
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci savepoints
|
||||
|
||||
- name: Mustache Lint
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci mustache
|
||||
|
||||
- name: Grunt
|
||||
continue-on-error: true # This step will show errors but will not fail
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci grunt --max-lint-warnings 0
|
||||
|
||||
- name: PHPUnit tests
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpunit
|
||||
|
||||
- name: Core privacy tests
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
cd moodle
|
||||
php admin/tool/phpunit/cli/init.php
|
||||
vendor/bin/phpunit --fail-on-risky --disallow-test-output -v --filter tool_dataprivacy_metadata_registry_testcase
|
||||
vendor/bin/phpunit --fail-on-risky --disallow-test-output -v --filter provider_testcase
|
||||
|
||||
- name: Behat features
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci behat --profile chrome
|
||||
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
|
||||
secrets:
|
||||
# Required if you plan to publish (uncomment the below)
|
||||
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}
|
||||
with:
|
||||
# Grunt fails due to CSS styling, when needing an !important statement.
|
||||
disable_grunt: false
|
||||
disable_phpunit: true
|
||||
disable_release : false
|
||||
release_branches: main
|
||||
min_php : 7.4
|
||||
66
.github/workflows/moodle-release.yml
vendored
66
.github/workflows/moodle-release.yml
vendored
@@ -1,66 +0,0 @@
|
||||
#
|
||||
# Whenever a new tag is pushed, add the tagged version
|
||||
# to the Moodle Plugins directory at https://moodle.org/plugins
|
||||
#
|
||||
# revision: 2021070201
|
||||
#
|
||||
name: Releasing in the Plugins directory
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Tag to be released'
|
||||
required: true
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
release-at-moodle-org:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
PLUGIN: availability_ipaddress
|
||||
CURL: curl -s
|
||||
ENDPOINT: https://moodle.org/webservice/rest/server.php
|
||||
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }}
|
||||
FUNCTION: local_plugins_add_version
|
||||
|
||||
steps:
|
||||
- name: Call the service function
|
||||
id: add-version
|
||||
run: |
|
||||
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
|
||||
TAGNAME="${{ github.event.inputs.tag }}"
|
||||
elif [[ $GITHUB_REF = refs/tags/* ]]; then
|
||||
TAGNAME="${GITHUB_REF##*/}"
|
||||
fi
|
||||
if [[ -z "${TAGNAME}" ]]; then
|
||||
echo "No tag name has been provided!"
|
||||
exit 1
|
||||
fi
|
||||
ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
|
||||
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
|
||||
--data-urlencode "wsfunction=${FUNCTION}" \
|
||||
--data-urlencode "moodlewsrestformat=json" \
|
||||
--data-urlencode "frankenstyle=${PLUGIN}" \
|
||||
--data-urlencode "zipurl=${ZIPURL}" \
|
||||
--data-urlencode "vcssystem=git" \
|
||||
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
|
||||
--data-urlencode "vcstag=${TAGNAME}" \
|
||||
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
|
||||
--data-urlencode "altdownloadurl=${ZIPURL}")
|
||||
echo "::set-output name=response::${RESPONSE}"
|
||||
|
||||
- name: Evaluate the response
|
||||
id: evaluate-response
|
||||
env:
|
||||
RESPONSE: ${{ steps.add-version.outputs.response }}
|
||||
run: |
|
||||
jq <<< ${RESPONSE}
|
||||
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null
|
||||
39
README.md
39
README.md
@@ -1,24 +1,24 @@
|
||||
## Moodle - availability ip address plugin
|
||||
Restrict access to any activity by ip-address. This plugin can be used to make any chosen activity unavailable based on the user's IP.
|
||||
|
||||
Enhance activity security by restricting access based on IP address. This plugin allows you to control the availability of any chosen
|
||||
activity, making it accessible only to users from specified IP addresses.
|
||||
|
||||
## Author
|
||||

|
||||

|
||||
|
||||
* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/)
|
||||
* Min. required: Moodle 3.5.x
|
||||
* Supports PHP: 7.2
|
||||
* Author: Luuk Verhoeven, [ldesignmedia.nl](https://ldesignmedia.nl/)
|
||||
* Min. required: Moodle 4.0
|
||||
* Supports PHP: 7.4
|
||||
|
||||
[](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress)
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## List of features
|
||||
- Supports comma separate list of ip-addresses
|
||||
@@ -32,7 +32,6 @@ Restrict access to any activity by ip-address. This plugin can be used to make a
|
||||
3. Go to Site Administrator > Notification
|
||||
4. Install the plugin
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
1. Add or edit an activity in a Moodle course.
|
||||
@@ -47,7 +46,7 @@ Restrict access to any activity by ip-address. This plugin can be used to make a
|
||||
|
||||
## Security
|
||||
|
||||
If you discover any security related issues, please email [luuk@MFreak.nl](mailto:luuk@MFreak.nl) instead of using the issue tracker.
|
||||
If you discover any security related issues, please email [luuk@ldesignmedia.nl](mailto:luuk@ldesignmedia.nl) instead of using the issue tracker.
|
||||
|
||||
## License
|
||||
|
||||
@@ -59,6 +58,8 @@ Contributions are welcome and will be fully credited. We accept contributions vi
|
||||
|
||||
## Changelog
|
||||
|
||||
- 2025040400 Tested on Moodle 4.5
|
||||
- 2024072000 Tested on Moodle 4.4
|
||||
- 2022021100 Thanks for adding ip-range support @[juacas](https://github.com/juacas)
|
||||
- 2022052800 Fixed the [issue 6](https://github.com/MFreakNL/moodle-availability_ipaddress/issues/6) @[hamzatamyachte](https://github.com/hamzatamyachte)
|
||||
- 2022052800 Fixed the [issue 6](https://github.com/ldesignmediaNL/moodle-availability_ipaddress/issues/6) @[hamzatamyachte](https://github.com/hamzatamyachte)
|
||||
- 2022052801 Test in Moodle 4.0 @[hamzatamyachte](https://github.com/hamzatamyachte)
|
||||
|
||||
@@ -40,7 +40,7 @@ class condition extends \core_availability\condition {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $ipaddresses = '';
|
||||
protected string $ipaddresses = '';
|
||||
|
||||
/**
|
||||
* condition constructor.
|
||||
@@ -73,11 +73,11 @@ class condition extends \core_availability\condition {
|
||||
* @param bool $grabthelot Performance hint: if true, caches information
|
||||
* required for all course-modules, to make the front page and similar
|
||||
* pages work more quickly (works only for current user)
|
||||
* @param int $userid User ID to check availability for
|
||||
* @param int $userid User ID to check availability for
|
||||
*
|
||||
* @return bool True if available
|
||||
*/
|
||||
public function is_available($not, info $info, $grabthelot, $userid) : bool {
|
||||
public function is_available($not, info $info, $grabthelot, $userid): bool {
|
||||
|
||||
if (empty($this->ipaddresses)) {
|
||||
return !$not;
|
||||
@@ -112,11 +112,9 @@ class condition extends \core_availability\condition {
|
||||
* @param bool $not Set true if we are inverting the condition
|
||||
* @param info $info Item we're checking
|
||||
*
|
||||
* @return string Information string (for admin) about all restrictions on
|
||||
* this item
|
||||
* @throws \coding_exception
|
||||
* @return string Information string (for admin) about all restrictions on this item
|
||||
*/
|
||||
public function get_description($full, $not, info $info) : string {
|
||||
public function get_description($full, $not, info $info): string {
|
||||
return get_string('require_condition', 'availability_ipaddress', getremoteaddr());
|
||||
}
|
||||
|
||||
@@ -126,7 +124,7 @@ class condition extends \core_availability\condition {
|
||||
*
|
||||
* @return string Text representation of parameters
|
||||
*/
|
||||
protected function get_debug_string() : string {
|
||||
protected function get_debug_string(): string {
|
||||
return !empty($this->ipaddresses) ? 'ipaddresses ON' : 'ipaddresses OFF';
|
||||
}
|
||||
|
||||
@@ -140,43 +138,23 @@ class condition extends \core_availability\condition {
|
||||
*
|
||||
* @return \stdClass Object representing condition
|
||||
*/
|
||||
public static function get_json($ipaddresses) : \stdClass {
|
||||
return (object)[
|
||||
public static function get_json(string $ipaddresses): \stdClass {
|
||||
return (object) [
|
||||
'type' => 'ipaddress',
|
||||
'ipaddresses' => $ipaddresses,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ip-address is valid
|
||||
*
|
||||
* @param string $ipaddresses
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_valid_ipaddresses($ipaddresses) : bool {
|
||||
$ipaddresses = implode(',', $ipaddresses);
|
||||
foreach ($ipaddresses as $ipaddress) {
|
||||
if ( is_ip_address($ipaddress) === false &&
|
||||
is_ipv4_range($ipaddress) === false &&
|
||||
is_ipv6_range($ipaddress) === false ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves tree data back to a structure object.
|
||||
*
|
||||
* @return \stdClass Structure object (ready to be made into JSON format)
|
||||
*/
|
||||
public function save() : \stdClass {
|
||||
return (object)[
|
||||
public function save(): \stdClass {
|
||||
return (object) [
|
||||
'type' => 'ipaddress',
|
||||
'ipaddresses' => $this->ipaddresses,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,11 @@ class frontend extends \core_availability\frontend {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_javascript_strings() : array {
|
||||
protected function get_javascript_strings(): array {
|
||||
return [
|
||||
'js:ipaddress',
|
||||
'error_ipaddress',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ class provider implements \core_privacy\local\metadata\null_provider {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
public static function get_reason(): string {
|
||||
return 'privacy:metadata';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
6
environment.xml
Normal file
6
environment.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<COMPATIBILITY_MATRIX>
|
||||
<PLUGIN name="availability_ipaddress">
|
||||
<PHP version="7.4" level="required"/>
|
||||
</PLUGIN>
|
||||
</COMPATIBILITY_MATRIX>
|
||||
@@ -23,16 +23,17 @@
|
||||
* @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
|
||||
* @author Luuk Verhoeven
|
||||
**/
|
||||
$string['pluginname'] = 'IP address';
|
||||
$string['title'] = 'IP address';
|
||||
$string['description'] = 'Restrict access by ip-address or subnet';
|
||||
$string['require_condition'] = 'Matching ip-address/subnet. (Your IP:{$a})';
|
||||
|
||||
// Javascript strings.
|
||||
$string['js:ipaddress'] = 'Require network address';
|
||||
$string['pluginname'] = 'IP address';
|
||||
$string['description'] = 'Restrict access by ip-address or subnet';
|
||||
$string['title'] = 'IP address';
|
||||
$string['require_condition'] = 'Matching ip-address/subnet. (Your IP:{$a})';
|
||||
|
||||
// Errors.
|
||||
$string['error_ipaddress'] = 'Incorrect ip-address/subnet format';
|
||||
|
||||
// Javascript strings.
|
||||
$string['js:ipaddress'] = 'Require network address';
|
||||
|
||||
// Privacy provider.
|
||||
$string['privacy:metadata'] = 'The restriction by activity ipaddress plugin does not store any personal data.';
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'availability_ipaddress';
|
||||
$plugin->version = 2022052801;
|
||||
$plugin->release = '3.11.2';
|
||||
$plugin->version = 2025040401;
|
||||
$plugin->release = '4.5.1';
|
||||
$plugin->requires = 2016120500;
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->supported = [400, 405];
|
||||
|
||||
@@ -130,11 +130,19 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
Y.log('Correct ipv4');
|
||||
continue;
|
||||
}
|
||||
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}-([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4 range.');
|
||||
continue;
|
||||
|
||||
var ipv4Regex = 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}-' +
|
||||
'([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$',
|
||||
'gm'
|
||||
);
|
||||
|
||||
if (ipv4Regex.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4 range.');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv6');
|
||||
|
||||
@@ -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="^((?:[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,})?",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(/^(?: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}-([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$/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"]});
|
||||
YUI.add("moodle-availability_ipaddress-form",function(e,d){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="^((?:[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,})?",M.availability_ipaddress.form=e.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){},M.availability_ipaddress.form.getValue=function(d,a){"use strict";d=a.one("input[name="+d+"]").get("value");return M.availability_ipaddress.validateIpaddress(d),d},M.availability_ipaddress.form.getNode=function(d){"use strict";var a,i="ipaddresses"+M.availability_ipaddress.form.instId;return M.availability_ipaddress.form.instId+=1,a="",a+='<span class="availability-group"><label for="'+i+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",i=e.Node.create('<span class="form-inline">'+(a+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+i+'">')+"</span>"),d.ipaddresses!==undefined&&i.one("input[name=ipaddresses]").set("value",d.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,e.one(".availability-field").delegate("valuechange",function(){M.core_availability.form.update()},".availability_ipaddress input[name=ipaddresses]")),i},M.availability_ipaddress.validateIpaddress=function(d){"use strict";for(var a in d=d.split(","))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(d[a])||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}-([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$","gm").test(d[a])||new RegExp(M.availability_ipaddress.v6).test(d[a])||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(d[a])))return!1;return!0},M.availability_ipaddress.form.fillValue=function(d,a){d.ipaddresses=this.getValue("ipaddresses",a)},M.availability_ipaddress.form.fillErrors=function(d,a){"use strict";var i={};this.fillValue(i,a),!1===M.availability_ipaddress.validateIpaddress(i.ipaddresses)&&d.push("availability_ipaddress:error_ipaddress")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]});
|
||||
@@ -125,10 +125,18 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
}
|
||||
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}-([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
|
||||
var ipv4Regex = 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}-' +
|
||||
'([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$',
|
||||
'gm'
|
||||
);
|
||||
|
||||
if (ipv4Regex.test(ipaddresses[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
continue;
|
||||
|
||||
16
yui/src/form/js/form.js
vendored
16
yui/src/form/js/form.js
vendored
@@ -128,11 +128,19 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
|
||||
Y.log('Correct ipv4');
|
||||
continue;
|
||||
}
|
||||
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}-([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$/gm)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4 range.');
|
||||
continue;
|
||||
|
||||
var ipv4Regex = 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}-' +
|
||||
'([0-1]?[0-9]?[0-9]?|2[0-4][0-9]|25[0-5]){1}$',
|
||||
'gm'
|
||||
);
|
||||
|
||||
if (ipv4Regex.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv4 range.');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (new RegExp(M.availability_ipaddress.v6)
|
||||
.test(ipaddresses[i])) {
|
||||
Y.log('Correct ipv6');
|
||||
|
||||
Reference in New Issue
Block a user