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