Merge branch 'MDL-62010-master' of git://github.com/cescobedo/moodle
[moodle.git] / admin / mnet / trustedhosts.php
blobcbbbfa353cc1e29c2f674d66dfd6b2911072569b
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 require_login();
9 admin_externalpage_setup('trustedhosts');
11 $context = context_system::instance();
13 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
15 if (!extension_loaded('openssl')) {
16 echo $OUTPUT->header();
17 print_error('requiresopenssl', 'mnet', '', NULL, true);
20 $site = get_site();
22 $trusted_hosts = '';//array();
23 $old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
24 if (!empty($old_trusted_hosts)) {
25 $old_trusted_hosts = explode(',', $old_trusted_hosts);
26 } else {
27 $old_trusted_hosts = array();
30 $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
31 $in_range = false;
32 if (!empty($test_ip_address)) {
33 foreach($old_trusted_hosts as $host) {
34 if (address_in_subnet($test_ip_address, $host)) {
35 $in_range = true;
36 $validated_by = $host;
37 break;
42 /// If data submitted, process and store
43 if (($form = data_submitted()) && confirm_sesskey()) {
44 $hostlist = preg_split("/[\s,]+/", $form->hostlist);
45 foreach($hostlist as $host) {
46 list($address, $mask) = explode('/', $host.'/');
47 if (empty($address)) continue;
48 if (strlen($mask) == 0) $mask = 32;
49 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
50 unset($address, $mask);
52 set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
53 } elseif (!empty($old_trusted_hosts)) {
54 foreach($old_trusted_hosts as $host) {
55 list($address, $mask) = explode('/', $host.'/');
56 if (empty($address)) continue;
57 if (strlen($mask) == 0) $mask = 32;
58 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
59 unset($address, $mask);
63 include('./trustedhosts.html');