Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  
   3      // Allows the admin to configure mnet stuff
   4  
   5      require(__DIR__.'/../../config.php');
   6      require_once($CFG->libdir.'/adminlib.php');
   7      include_once($CFG->dirroot.'/mnet/lib.php');
   8  
   9      admin_externalpage_setup('net');
  10  
  11      $context = context_system::instance();
  12  
  13  
  14      $site = get_site();
  15      $mnet = get_mnet_environment();
  16  
  17      if (!extension_loaded('openssl')) {
  18          echo $OUTPUT->header();
  19          set_config('mnet_dispatcher_mode', 'off');
  20          print_error('requiresopenssl', 'mnet');
  21      }
  22  
  23      if (!function_exists('curl_init') ) {
  24          echo $OUTPUT->header();
  25          set_config('mnet_dispatcher_mode', 'off');
  26          print_error('nocurl', 'mnet');
  27      }
  28  
  29      if (!isset($CFG->mnet_dispatcher_mode)) {
  30          set_config('mnet_dispatcher_mode', 'off');
  31      }
  32  
  33  /// If data submitted, process and store
  34      if (($form = data_submitted()) && confirm_sesskey()) {
  35          if (!empty($form->submit) && $form->submit == get_string('savechanges')) {
  36              if (in_array($form->mode, array("off", "strict", "dangerous"))) {
  37                  if (set_config('mnet_dispatcher_mode', $form->mode)) {
  38                      redirect('index.php', get_string('changessaved'));
  39                  } else {
  40                      print_error('invalidaction', '', 'index.php');
  41                  }
  42              }
  43          } elseif (!empty($form->submit) && $form->submit == get_string('delete')) {
  44              $mnet->get_private_key();
  45              $SESSION->mnet_confirm_delete_key = md5(sha1($mnet->keypair['keypair_PEM'])).':'.time();
  46  
  47              $formcontinue = new single_button(new moodle_url('index.php', array('confirm' => md5($mnet->public_key))), get_string('yes'));
  48              $formcancel = new single_button(new moodle_url('index.php', array()), get_string('no'));
  49              echo $OUTPUT->confirm(get_string("deletekeycheck", "mnet"), $formcontinue, $formcancel);
  50              exit;
  51          } else {
  52              // We're deleting
  53  
  54  
  55              if (!isset($SESSION->mnet_confirm_delete_key)) {
  56                  // fail - you're being attacked?
  57              }
  58  
  59              $key = '';
  60              $time = '';
  61              @list($key, $time) = explode(':',$SESSION->mnet_confirm_delete_key);
  62              $mnet->get_private_key();
  63  
  64              if($time < time() - 60) {
  65                  // fail - you're out of time.
  66                  print_error ('deleteoutoftime', 'mnet', 'index.php');
  67                  exit;
  68              }
  69  
  70              if ($key != md5(sha1($mnet->keypair['keypair_PEM']))) {
  71                  // fail - you're being attacked?
  72                  print_error ('deletewrongkeyvalue', 'mnet', 'index.php');
  73                  exit;
  74              }
  75  
  76              $mnet->replace_keys();
  77              redirect('index.php', get_string('keydeleted','mnet'));
  78              exit;
  79          }
  80      }
  81      $hosts = $DB->get_records_select('mnet_host', "id <> ? AND deleted = 0", array($CFG->mnet_localhost_id), 'wwwroot ASC');
  82  
  83      echo $OUTPUT->header();
  84  ?>
  85  <form method="post" action="index.php">
  86      <table align="center" width="635" class="generaltable" border="0" cellpadding="5" cellspacing="0">
  87          <tr>
  88              <td  class="generalboxcontent">
  89              <table cellpadding="9" cellspacing="0" >
  90                  <tr valign="top">
  91                      <td colspan="2" class="header"><?php print_string('aboutyourhost', 'mnet'); ?></td>
  92                  </tr>
  93                  <tr valign="top">
  94                      <td align="right"><?php print_string('publickey', 'mnet'); ?>:</td>
  95                      <td><pre><?php echo $mnet->public_key; ?></pre></td>
  96                  </tr>
  97                  <tr valign="top">
  98                      <td align="right"><?php print_string('expires', 'mnet'); ?>:</td>
  99                      <td><?php echo userdate($mnet->public_key_expires); ?></td>
 100                  </tr>
 101              </table>
 102              </td>
 103          </tr>
 104      </table>
 105  </form>
 106  <form method="post" action="index.php">
 107      <table align="center" width="635" class="generaltable" border="0" cellpadding="5" cellspacing="0">
 108          <tr>
 109              <td  class="generalboxcontent">
 110              <table cellpadding="9" cellspacing="0" >
 111                  <tr valign="top">
 112                      <td colspan="2" class="header"><?php print_string('expireyourkey', 'mnet'); ?></td>
 113                  </tr>
 114                  <tr valign="top">
 115                      <td colspan="2"><?php print_string('expireyourkeyexplain', 'mnet'); ?></td>
 116                  </tr>
 117                  <tr valign="top">
 118                      <td align="left" width="10" nowrap="nowrap"><?php print_string('expireyourkey', 'mnet'); ?></td>
 119                      <td align="left"><input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
 120                          <input type="hidden" name="deleteKey" value="" />
 121                          <input type="submit" name="submit" value="<?php print_string('delete'); ?>" />
 122                      </td>
 123                  </tr>
 124              </table>
 125              </td>
 126          </tr>
 127      </table>
 128  </form>
 129  
 130  <?php
 131  echo $OUTPUT->footer();