Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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          throw new \moodle_exception('requiresopenssl', 'mnet');
  21      }
  22  
  23      if (!function_exists('curl_init') ) {
  24          echo $OUTPUT->header();
  25          set_config('mnet_dispatcher_mode', 'off');
  26          throw new \moodle_exception('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                      throw new \moodle_exception('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  
  50              echo $OUTPUT->header();
  51              echo $OUTPUT->confirm(get_string("deletekeycheck", "mnet"), $formcontinue, $formcancel);
  52              echo $OUTPUT->footer();
  53              exit;
  54          } else {
  55              // We're deleting
  56  
  57              // If no/cancel then redirect back to the network setting page.
  58              if (!isset($form->confirm)) {
  59                  redirect(
  60                      new moodle_url('/admin/mnet/index.php'),
  61                      get_string('keydeletedcancelled', 'mnet'),
  62                      null,
  63                      \core\output\notification::NOTIFY_SUCCESS
  64                  );
  65              }
  66  
  67              if (!isset($SESSION->mnet_confirm_delete_key)) {
  68                  // fail - you're being attacked?
  69              }
  70  
  71              $key = '';
  72              $time = '';
  73              @list($key, $time) = explode(':',$SESSION->mnet_confirm_delete_key);
  74              $mnet->get_private_key();
  75  
  76              if($time < time() - 60) {
  77                  // fail - you're out of time.
  78                  redirect(
  79                      new moodle_url('/admin/mnet/index.php'),
  80                      get_string('deleteoutoftime', 'mnet'),
  81                      null,
  82                      \core\output\notification::NOTIFY_WARNING
  83                  );
  84              }
  85  
  86              if ($key != md5(sha1($mnet->keypair['keypair_PEM']))) {
  87                  // fail - you're being attacked?
  88                  throw new \moodle_exception ('deletewrongkeyvalue', 'mnet', 'index.php');
  89                  exit;
  90              }
  91  
  92              $mnet->replace_keys();
  93              redirect('index.php', get_string('keydeleted','mnet'));
  94          }
  95      }
  96      $hosts = $DB->get_records_select('mnet_host', "id <> ? AND deleted = 0", array($CFG->mnet_localhost_id), 'wwwroot ASC');
  97  
  98      echo $OUTPUT->header();
  99  ?>
 100  <form method="post" action="index.php">
 101      <table align="center" width="635" class="generaltable" border="0" cellpadding="5" cellspacing="0">
 102          <tr>
 103              <td  class="generalboxcontent">
 104              <table cellpadding="9" cellspacing="0" >
 105                  <tr valign="top">
 106                      <td colspan="2" class="header"><?php print_string('aboutyourhost', 'mnet'); ?></td>
 107                  </tr>
 108                  <tr valign="top">
 109                      <td align="right"><?php print_string('publickey', 'mnet'); ?>:</td>
 110                      <td><pre><?php echo $mnet->public_key; ?></pre></td>
 111                  </tr>
 112                  <tr valign="top">
 113                      <td align="right"><?php print_string('expires', 'mnet'); ?>:</td>
 114                      <td><?php echo userdate($mnet->public_key_expires); ?></td>
 115                  </tr>
 116              </table>
 117              </td>
 118          </tr>
 119      </table>
 120  </form>
 121  <form method="post" action="index.php">
 122      <table align="center" width="635" class="generaltable" border="0" cellpadding="5" cellspacing="0">
 123          <tr>
 124              <td  class="generalboxcontent">
 125              <table cellpadding="9" cellspacing="0" >
 126                  <tr valign="top">
 127                      <td colspan="2" class="header"><?php print_string('expireyourkey', 'mnet'); ?></td>
 128                  </tr>
 129                  <tr valign="top">
 130                      <td colspan="2"><?php print_string('expireyourkeyexplain', 'mnet'); ?></td>
 131                  </tr>
 132                  <tr valign="top">
 133                      <td align="left" width="10" nowrap="nowrap"><?php print_string('expireyourkey', 'mnet'); ?></td>
 134                      <td align="left"><input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
 135                          <input type="hidden" name="deleteKey" value="" />
 136                          <input type="submit" name="submit" value="<?php print_string('delete'); ?>" />
 137                      </td>
 138                  </tr>
 139              </table>
 140              </td>
 141          </tr>
 142      </table>
 143  </form>
 144  
 145  <?php
 146  echo $OUTPUT->footer();