Merge branch 'MDL-81063-main' of https://github.com/andrewnicols/moodle
[moodle.git] / admin / mnet / index.php
blob360e092f6762b979887f31cd09709384001df9c6
1 <?php
3 // Allows the admin to configure mnet stuff
5 require(__DIR__.'/../../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
7 include_once($CFG->dirroot.'/mnet/lib.php');
9 admin_externalpage_setup('net');
11 $context = context_system::instance();
14 $site = get_site();
15 $mnet = get_mnet_environment();
17 if (!extension_loaded('openssl')) {
18 echo $OUTPUT->header();
19 set_config('mnet_dispatcher_mode', 'off');
20 throw new \moodle_exception('requiresopenssl', 'mnet');
23 if (!function_exists('curl_init') ) {
24 echo $OUTPUT->header();
25 set_config('mnet_dispatcher_mode', 'off');
26 throw new \moodle_exception('nocurl', 'mnet');
29 if (!isset($CFG->mnet_dispatcher_mode)) {
30 set_config('mnet_dispatcher_mode', 'off');
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');
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();
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'));
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
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
67 if (!isset($SESSION->mnet_confirm_delete_key)) {
68 // fail - you're being attacked?
71 $key = '';
72 $time = '';
73 @list($key, $time) = explode(':',$SESSION->mnet_confirm_delete_key);
74 $mnet->get_private_key();
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
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;
92 $mnet->replace_keys();
93 redirect('index.php', get_string('keydeleted','mnet'));
96 $hosts = $DB->get_records_select('mnet_host', "id <> ? AND deleted = 0", array($CFG->mnet_localhost_id), 'wwwroot ASC');
98 echo $OUTPUT->header();
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>
145 <?php
146 echo $OUTPUT->footer();