Search moodle.org's
Developer Documentation

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
  • Differences Between: [Versions 310 and 34] [Versions 310 and 35] [Versions 34 and 310] [Versions 35 and 310]

       1  <?php
       2      // Allows the admin to configure services for remote hosts
       3  
       4      require(__DIR__.'/../../config.php');
       5      require_once($CFG->libdir.'/adminlib.php');
       6      include_once($CFG->dirroot.'/mnet/lib.php');
       7  
       8      admin_externalpage_setup('trustedhosts');
       9  
      10  
      11      if (!extension_loaded('openssl')) {
      12          echo $OUTPUT->header();
      13          print_error('requiresopenssl', 'mnet', '', NULL, true);
      14      }
      15  
      16      $site = get_site();
      17  
      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();
      24      }
      25  
      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;
      34              }
      35          }
      36      }
      37  
      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);
      47          }
      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);
      56          }
      57      }
      58  
      59      include('./trustedhosts.html');