33 Commits
3.10 ... 5.0.0

Author SHA1 Message Date
Luuk Verhoeven
26669e73f1 Merge pull request #11 from LdesignMedia/86c3hkgy9-update-moodle-50
Update #86c3hkgy9 - Update Moodle Version 50
2025-05-27 14:43:41 +02:00
Jan Choroś
e7e5cbe91d Update #86c3hkgy9 - Update Moodle Version 50 2025-05-22 15:35:21 +02:00
Luuk Verhoeven
d56173f6b8 Update version.php 2025-04-04 10:21:42 +02:00
Luuk Verhoeven
c9b5e6cb7d Merge pull request #10 from LdesignMedia/86c2xmcmw-upgrade-45
86c2xmcmw upgrade 45
2025-04-04 10:17:52 +02:00
Luuk Verhoeven
fcfa4eb773 Delete .github/workflows/AppScan.yml 2025-04-04 10:17:17 +02:00
Nihaal Shaikh
b98a63e1f4 Update #86c2xmcmw - readme and version file updated 2025-04-04 09:25:26 +02:00
Nihaal Shaikh
a836731b24 Update #86c2xmcmw - upgraded plugin to M45 2025-04-04 09:19:36 +02:00
Luuk Verhoeven
c2f5e7e22c Update language file for phpcs 2024-07-20 22:54:06 +02:00
Luuk Verhoeven
761d643479 Update version 2024-07-20 22:22:05 +02:00
Luuk Verhoeven
5ef0c811c0 Update remove sonar cloud 2024-07-20 22:14:31 +02:00
Luuk Verhoeven
6633439651 Update RegExp to not exceed 132 characters 2024-07-20 22:12:54 +02:00
Luuk Verhoeven
4b4fced58b Add auto release 2024-07-20 15:08:33 +02:00
Luuk Verhoeven
8ae54193d2 Update code and environment checks 2024-07-20 15:01:12 +02:00
Luuk Verhoeven
26bbc1cbdb Add CI workflows 2023-09-26 13:41:32 +02:00
Luuk Verhoeven
5d615ddb24 Add CI workflows 2023-09-26 13:31:05 +02:00
Luuk Verhoeven
5e2566fbba Add CI workflows 2023-09-26 13:25:29 +02:00
Luuk Verhoeven
96c93c4096 Add CI workflows 2023-09-26 13:24:54 +02:00
Luuk Verhoeven
d302aa626a Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.github/workflows/ci.yml
2023-09-26 13:23:32 +02:00
Luuk Verhoeven
787dba81f0 Add CI workflows 2023-09-26 13:23:17 +02:00
Luuk Verhoeven
f24ef270a5 Update version.php 2022-06-04 11:08:38 +02:00
Luuk Verhoeven
0e7ec99338 Merge pull request #7 from MFreakNL/#2am8vvp_test_moodle4
Moodle 4.0 release
2022-05-30 23:31:11 +02:00
Hamza Tamyachte
3b489f3406 Add Moodle 4.0 Support 2022-05-30 14:36:35 +02:00
Hamza Tamyachte
84ea4a9165 Add Moodle 4.0 Support 2022-05-30 11:38:27 +02:00
Vincent Cornelis
9d6f7e51b9 Add changelog 2022-02-14 15:24:32 +01:00
Vincent Cornelis
855f8fecaa Update condition.php
indentation fix
2022-02-11 17:48:54 +01:00
Vincent Cornelis
30459042d7 Update version.php
Bumped version number
2022-02-11 17:42:18 +01:00
Vincent Cornelis
a6b22c06e3 Merge pull request #5 from juacas/master
Support ipv4 ranges. Issue #4
2022-02-11 17:40:14 +01:00
Juan Pablo de Castro (UVa)
e44acd4a7f Support ipv4 ranges. 2022-02-01 08:41:47 +00:00
Vincent Cornelis
4754b1e03e Merge branch 'moodle-release' 2021-12-15 11:26:29 +01:00
Vincent Cornelis
54ac7002d8 bumped versionnumber 2021-12-15 11:26:08 +01:00
Vincent Cornelis
5d25933dfb bumped versionnumber 2021-12-09 13:54:49 +01:00
Vincent Cornelis
28f6d4603b added end-of-lines 2021-12-09 13:42:54 +01:00
Vincent Cornelis
527831df6b add github workflow moodle-release 2021-12-09 13:38:46 +01:00
14 changed files with 123 additions and 124 deletions

18
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
# .github/workflows/ci.yml
name: ci
on: [push, pull_request]
jobs:
test:
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

View File

@@ -1,50 +0,0 @@
language: php
addons:
postgresql: "9.6"
services:
- mysql
- postgresql
- docker
cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm
php:
- 7.2
- 7.4
env:
global:
- MOODLE_BRANCH=MOODLE_310_STABLE
matrix:
- DB=pgsql
- DB=mysqli
before_install:
- phpenv config-rm xdebug.ini
- nvm install 14 # moodle-plugin-ci still uses 8.9, but Moodle core switched to 14 in MDL-66109.
- nvm use 14
- cd ../..
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci dev-master
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
#- docker run -d -p 127.0.0.1:4444:4444 --net=host -v /dev/shm:/dev/shm selenium/standalone-chrome:3
install:
- moodle-plugin-ci install
script:
- 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 phpdoc
- moodle-plugin-ci phpunit
#- moodle-plugin-ci behat --profile chrome --dump

View File

@@ -1,24 +1,26 @@
## Moodle - availability ip address plugin ## 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
![MFreak.nl](http://MFreak.nl/logo_small.png) ![MFreak.nl](https://MFreak.nl/logo_small.png)
* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/) * Author: Luuk Verhoeven, [ldesignmedia.nl](https://ldesignmedia.nl/)
* Min. required: Moodle 3.5.x * Min. required: Moodle 4.0
* Supports PHP: 7.2 * Supports PHP: 7.4
[![Build Status](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress.svg?branch=master)](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress) ![Moodle400](https://img.shields.io/badge/moodle-4.0-brightgreen.svg?logo=moodle)
![Moodle35](https://img.shields.io/badge/moodle-3.5-brightgreen.svg) ![Moodle401](https://img.shields.io/badge/moodle-4.1-brightgreen.svg?logo=moodle)
![Moodle36](https://img.shields.io/badge/moodle-3.6-brightgreen.svg) ![Moodle402](https://img.shields.io/badge/moodle-4.2-brightgreen.svg?logo=moodle)
![Moodle37](https://img.shields.io/badge/moodle-3.7-brightgreen.svg) ![Moodle403](https://img.shields.io/badge/moodle-4.3-brightgreen.svg?logo=moodle)
![Moodle38](https://img.shields.io/badge/moodle-3.8-brightgreen.svg) ![Moodle404](https://img.shields.io/badge/moodle-4.4-brightgreen.svg?logo=moodle)
![Moodle39](https://img.shields.io/badge/moodle-3.9-brightgreen.svg) ![Moodle405](https://img.shields.io/badge/moodle-4.5-brightgreen.svg?logo=moodle)
![Moodle310](https://img.shields.io/badge/moodle-3.10-brightgreen.svg) ![Moodle500](https://img.shields.io/badge/moodle-5.0-brightgreen.svg?logo=moodle)
![PHP7.2](https://img.shields.io/badge/PHP-7.2-brightgreen.svg)
![Screenshot](https://moodle.org/pluginfile.php/50/local_plugins/plugin_screenshots/2292/2019-05-15_11-01-39.png) ![PHP7.4](https://img.shields.io/badge/PHP-7.4-brightgreen.svg?logo=php)
![PHP8.0](https://img.shields.io/badge/PHP-8.0-brightgreen.svg?logo=php)
![PHP8.1](https://img.shields.io/badge/PHP-8.1-brightgreen.svg?logo=php)
![PHP8.2](https://img.shields.io/badge/PHP-8.2-brightgreen.svg?logo=php)
## List of features ## List of features
- Supports comma separate list of ip-addresses - Supports comma separate list of ip-addresses
@@ -32,7 +34,6 @@ Restrict access to any activity by ip-address. This plugin can be used to make a
3. Go to Site Administrator > Notification 3. Go to Site Administrator > Notification
4. Install the plugin 4. Install the plugin
## Usage ## Usage
1. Add or edit an activity in a Moodle course. 1. Add or edit an activity in a Moodle course.
@@ -47,7 +48,7 @@ Restrict access to any activity by ip-address. This plugin can be used to make a
## Security ## 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 ## License
@@ -56,3 +57,11 @@ The GNU GENERAL PUBLIC LICENSE. Please see [License File](LICENSE) for more info
## Contributing ## Contributing
Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github. Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.
## 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/ldesignmediaNL/moodle-availability_ipaddress/issues/6) @[hamzatamyachte](https://github.com/hamzatamyachte)
- 2022052801 Test in Moodle 4.0 @[hamzatamyachte](https://github.com/hamzatamyachte)

View File

@@ -28,8 +28,6 @@ namespace availability_ipaddress;
use core_availability\info; use core_availability\info;
defined('MOODLE_INTERNAL') || die;
/** /**
* Class condition * Class condition
* *
@@ -42,7 +40,7 @@ class condition extends \core_availability\condition {
/** /**
* @var string * @var string
*/ */
protected $ipaddresses = ''; protected string $ipaddresses = '';
/** /**
* condition constructor. * condition constructor.
@@ -75,22 +73,22 @@ class condition extends \core_availability\condition {
* @param bool $grabthelot Performance hint: if true, caches information * @param bool $grabthelot Performance hint: if true, caches information
* required for all course-modules, to make the front page and similar * required for all course-modules, to make the front page and similar
* pages work more quickly (works only for current user) * 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 * @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)) { if (empty($this->ipaddresses)) {
return true; return !$not;
} }
// Check if ip-address matches. // Check if ip-address matches.
if (address_in_subnet(getremoteaddr(), trim($this->ipaddresses))) { if (address_in_subnet(getremoteaddr(), trim($this->ipaddresses))) {
return true; return !$not;
} }
return false; return $not;
} }
/** /**
@@ -114,12 +112,10 @@ class condition extends \core_availability\condition {
* @param bool $not Set true if we are inverting the condition * @param bool $not Set true if we are inverting the condition
* @param info $info Item we're checking * @param info $info Item we're checking
* *
* @return string Information string (for admin) about all restrictions on * @return string Information string (for admin) about all restrictions on this item
* this item
* @throws \coding_exception
*/ */
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'); return get_string('require_condition', 'availability_ipaddress', getremoteaddr());
} }
/** /**
@@ -128,7 +124,7 @@ class condition extends \core_availability\condition {
* *
* @return string Text representation of parameters * @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'; return !empty($this->ipaddresses) ? 'ipaddresses ON' : 'ipaddresses OFF';
} }
@@ -142,41 +138,23 @@ class condition extends \core_availability\condition {
* *
* @return \stdClass Object representing condition * @return \stdClass Object representing condition
*/ */
public static function get_json($ipaddresses) : \stdClass { public static function get_json(string $ipaddresses): \stdClass {
return (object)[ return (object) [
'type' => 'ipaddress', 'type' => 'ipaddress',
'ipaddresses' => $ipaddresses, '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 (!filter_var($ipaddress, FILTER_VALIDATE_IP)) {
return false;
}
}
return true;
}
/** /**
* Saves tree data back to a structure object. * Saves tree data back to a structure object.
* *
* @return \stdClass Structure object (ready to be made into JSON format) * @return \stdClass Structure object (ready to be made into JSON format)
*/ */
public function save() : \stdClass { public function save(): \stdClass {
return (object)[ return (object) [
'type' => 'ipaddress', 'type' => 'ipaddress',
'ipaddresses' => $this->ipaddresses, 'ipaddresses' => $this->ipaddresses,
]; ];
} }
}
}

View File

@@ -25,7 +25,6 @@
**/ **/
namespace availability_ipaddress; namespace availability_ipaddress;
defined('MOODLE_INTERNAL') || die;
/** /**
* Class frontend * Class frontend
@@ -41,10 +40,11 @@ class frontend extends \core_availability\frontend {
* *
* @return array * @return array
*/ */
protected function get_javascript_strings() : array { protected function get_javascript_strings(): array {
return [ return [
'js:ipaddress', 'js:ipaddress',
'error_ipaddress', 'error_ipaddress',
]; ];
} }
}
}

View File

@@ -26,8 +26,6 @@
namespace availability_ipaddress\privacy; namespace availability_ipaddress\privacy;
defined('MOODLE_INTERNAL') || die();
/** /**
* Privacy Subsystem for availability_ipaddress implementing null_provider. * Privacy Subsystem for availability_ipaddress implementing null_provider.
* *
@@ -42,7 +40,8 @@ class provider implements \core_privacy\local\metadata\null_provider {
* *
* @return string * @return string
*/ */
public static function get_reason() : string { public static function get_reason(): string {
return 'privacy:metadata'; return 'privacy:metadata';
} }
} }

6
environment.xml Normal file
View 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>

View File

@@ -23,16 +23,17 @@
* @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author 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';
// Javascript strings. $string['pluginname'] = 'IP address';
$string['js:ipaddress'] = 'Require network 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. // Errors.
$string['error_ipaddress'] = 'Incorrect ip-address/subnet format'; $string['error_ipaddress'] = 'Incorrect ip-address/subnet format';
// Javascript strings.
$string['js:ipaddress'] = 'Require network address';
// Privacy provider. // Privacy provider.
$string['privacy:metadata'] = 'The restriction by activity ipaddress plugin does not store any personal data.'; $string['privacy:metadata'] = 'The restriction by activity ipaddress plugin does not store any personal data.';

View File

@@ -27,7 +27,8 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'availability_ipaddress'; $plugin->component = 'availability_ipaddress';
$plugin->version = 2020111800; $plugin->version = 2025052100;
$plugin->release = '3.10.0'; $plugin->release = '5.0.0';
$plugin->requires = 2016120500; $plugin->requires = 2016120500;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->supported = [400, 500];

View File

@@ -131,6 +131,18 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
continue; 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) if (new RegExp(M.availability_ipaddress.v6)
.test(ipaddresses[i])) { .test(ipaddresses[i])) {
Y.log('Correct ipv6'); Y.log('Correct ipv6');
@@ -184,4 +196,5 @@ M.availability_ipaddress.form.fillErrors = function(errors, node) {
} }
}; };
}, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]}); }, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});

View File

@@ -1 +1 @@
YUI.add("moodle-availability_ipaddress-form",function(s,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=s.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){},M.availability_ipaddress.form.getValue=function(d,a){"use strict";var i=a.one("input[name="+d+"]").get("value");return M.availability_ipaddress.validateIpaddress(i),i},M.availability_ipaddress.form.getNode=function(d){"use strict";var a,i,e;return e="ipaddresses"+M.availability_ipaddress.form.instId,M.availability_ipaddress.form.instId+=1,a="",a+='<span class="availability-group"><label for="'+e+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",a+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+e+'">',i=s.Node.create('<span class="form-inline">'+a+"</span>"),d.ipaddresses!==undefined&&i.one("input[name=ipaddresses]").set("value",d.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,s.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(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"]}); 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"]});

View File

@@ -126,6 +126,17 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
continue; 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) if (new RegExp(M.availability_ipaddress.v6)
.test(ipaddresses[i])) { .test(ipaddresses[i])) {
continue; continue;
@@ -175,4 +186,5 @@ M.availability_ipaddress.form.fillErrors = function(errors, node) {
} }
}; };
}, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]}); }, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});

View File

@@ -129,6 +129,18 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
continue; 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) if (new RegExp(M.availability_ipaddress.v6)
.test(ipaddresses[i])) { .test(ipaddresses[i])) {
Y.log('Correct ipv6'); Y.log('Correct ipv6');
@@ -180,4 +192,4 @@ M.availability_ipaddress.form.fillErrors = function(errors, node) {
if (M.availability_ipaddress.validateIpaddress(value.ipaddresses) === false) { if (M.availability_ipaddress.validateIpaddress(value.ipaddresses) === false) {
errors.push('availability_ipaddress:error_ipaddress'); errors.push('availability_ipaddress:error_ipaddress');
} }
}; };

View File

@@ -7,4 +7,4 @@
"moodle-core_availability-form" "moodle-core_availability-form"
] ]
} }
} }