Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/mnet/trustedhosts.php
Go to the documentation of this file.
00001 <?php
00002     // Allows the admin to configure services for remote hosts
00003 
00004     require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
00005     require_once($CFG->libdir.'/adminlib.php');
00006     include_once($CFG->dirroot.'/mnet/lib.php');
00007 
00008     require_login();
00009     admin_externalpage_setup('trustedhosts');
00010 
00011     $context = get_context_instance(CONTEXT_SYSTEM);
00012 
00013     require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
00014 
00015     if (!extension_loaded('openssl')) {
00016         echo $OUTPUT->header();
00017         print_error('requiresopenssl', 'mnet', '', NULL, true);
00018     }
00019 
00020     $site = get_site();
00021 
00022     $trusted_hosts = '';//array();
00023     $old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
00024     if (!empty($old_trusted_hosts)) {
00025         $old_trusted_hosts =  explode(',', $old_trusted_hosts);
00026     } else {
00027         $old_trusted_hosts = array();
00028     }
00029 
00030     $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
00031     $in_range = false;
00032     if (!empty($test_ip_address)) {
00033         foreach($old_trusted_hosts as $host) {
00034             if (address_in_subnet($test_ip_address, $host)) {
00035                 $in_range = true;
00036                 $validated_by = $host;
00037                 break;
00038             }
00039         }
00040     }
00041 
00043     if (($form = data_submitted()) && confirm_sesskey()) {
00044         $hostlist = preg_split("/[\s,]+/", $form->hostlist);
00045         foreach($hostlist as $host) {
00046             list($address, $mask) = explode('/', $host.'/');
00047             if (empty($address)) continue;
00048             if (strlen($mask) == 0) $mask = 32;
00049             $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
00050             unset($address, $mask);
00051         }
00052         set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
00053     } elseif (!empty($old_trusted_hosts)) {
00054         foreach($old_trusted_hosts as $host) {
00055             list($address, $mask) = explode('/', $host.'/');
00056             if (empty($address)) continue;
00057             if (strlen($mask) == 0) $mask = 32;
00058             $trusted_hosts .= trim($address).'/'.trim($mask)."\n";
00059             unset($address, $mask);
00060         }
00061     }
00062 
00063     include('./trustedhosts.html');
 All Data Structures Namespaces Files Functions Variables Enumerations