2 // Allows the admin to configure services for remote hosts
4 require_once(dirname(dirname(dirname(__FILE__
))) . '/config.php');
5 require_once($CFG->libdir
.'/adminlib.php');
6 include_once($CFG->dirroot
.'/mnet/lib.php');
9 admin_externalpage_setup('trustedhosts');
11 $context = get_context_instance(CONTEXT_SYSTEM
);
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);
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);
27 $old_trusted_hosts = array();
30 $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST
);
32 if (!empty($test_ip_address)) {
33 foreach($old_trusted_hosts as $host) {
34 if (address_in_subnet($test_ip_address, $host)) {
36 $validated_by = $host;
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');