Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / mnet / trustedhosts.php
blob932e84a6a6c7c739617ccc4a2cfb74b2331f9324
1 <?php
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');
8 require_login();
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 admin_externalpage_print_header();
17 print_error('requiresopenssl', 'mnet', '', NULL, true);
20 if (!$site = get_site()) {
21 admin_externalpage_print_header();
22 print_error('nosite', '', '', NULL, true);
25 $trusted_hosts = '';//array();
26 $old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
27 if (!empty($old_trusted_hosts)) {
28 $old_trusted_hosts = explode(',', $old_trusted_hosts);
29 } else {
30 $old_trusted_hosts = array();
33 $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
34 $in_range = false;
35 if (!empty($test_ip_address)) {
36 foreach($old_trusted_hosts as $host) {
37 list($network, $mask) = explode('/', $host.'/');
38 if (empty($network)) continue;
39 if (strlen($mask) == 0) $mask = 32;
41 if (ip_in_range($test_ip_address, $network, $mask)) {
42 $in_range = true;
43 $validated_by = $network.'/'.$mask;
44 break;
49 /// If data submitted, process and store
50 if (($form = data_submitted()) && confirm_sesskey()) {
51 $hostlist = preg_split("/[\s,]+/", $form->hostlist);
52 foreach($hostlist as $host) {
53 list($address, $mask) = explode('/', $host.'/');
54 if (empty($address)) continue;
55 if (strlen($mask) == 0) $mask = 32;
56 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
57 unset($address, $mask);
59 set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
60 } elseif (!empty($old_trusted_hosts)) {
61 foreach($old_trusted_hosts as $host) {
62 list($address, $mask) = explode('/', $host.'/');
63 if (empty($address)) continue;
64 if (strlen($mask) == 0) $mask = 32;
65 $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
66 unset($address, $mask);
70 include('./trustedhosts.html');