Merge branch 'MDL-79920-main' of https://github.com/davewoloszyn/moodle
[moodle.git] / admin / mnet / trustedhosts.php
blobc72ed8c841f3a0292de9763c10fa7c4f6996d7c0
1 <?php
2 // Allows the admin to configure services for remote hosts
4 require(__DIR__.'/../../config.php');
5 require_once($CFG->libdir.'/adminlib.php');
6 include_once($CFG->dirroot.'/mnet/lib.php');
8 admin_externalpage_setup('trustedhosts');
11 if (!extension_loaded('openssl')) {
12 echo $OUTPUT->header();
13 throw new \moodle_exception('requiresopenssl', 'mnet', '', null, true);
16 $site = get_site();
18 $trusted_hosts = '';//array();
19 $old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
20 if (!empty($old_trusted_hosts)) {
21 $old_trusted_hosts = explode(',', $old_trusted_hosts);
22 } else {
23 $old_trusted_hosts = array();
26 $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
27 $in_range = false;
28 if (!empty($test_ip_address)) {
29 foreach($old_trusted_hosts as $host) {
30 if (address_in_subnet($test_ip_address, $host)) {
31 $in_range = true;
32 $validated_by = $host;
33 break;
38 /// If data submitted, process and store
39 if (($form = data_submitted()) && confirm_sesskey()) {
40 $hostlist = preg_split("/[\s,]+/", $form->hostlist);
41 foreach($hostlist as $host) {
42 list($address, $mask) = explode('/', $host.'/');
43 if (empty($address)) continue;
44 if (strlen($mask) == 0) $mask = 32;
45 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
46 unset($address, $mask);
48 set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
49 } elseif (!empty($old_trusted_hosts)) {
50 foreach($old_trusted_hosts as $host) {
51 list($address, $mask) = explode('/', $host.'/');
52 if (empty($address)) continue;
53 if (strlen($mask) == 0) $mask = 32;
54 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
55 unset($address, $mask);
59 include('./trustedhosts.html');