Fixes bug MDL-8234, "New groups code & AS keyword"
[moodle-pu.git] / admin / mnet / index.php
blobcad87c35a7e46eb40f3e9abd0852eb0e2dabc744
1 <?PHP // $Id$
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 $adminroot = admin_get_root();
11 admin_externalpage_setup('net', $adminroot);
13 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
15 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
18 if (!extension_loaded('openssl')) {
19 admin_externalpage_print_header($adminroot);
20 set_config('mnet_dispatcher_mode', 'off');
21 print_error('requiresopenssl', 'mnet', '', NULL, true);
24 if (!$site = get_site()) {
25 admin_externalpage_print_header($adminroot);
26 set_config('mnet_dispatcher_mode', 'off');
27 print_error('nosite', '', '', NULL, true);
30 if (!function_exists('curl_init') ) {
31 admin_externalpage_print_header($adminroot);
32 set_config('mnet_dispatcher_mode', 'off');
33 print_error('nocurl', 'mnet', '', NULL, true);
36 if (!isset($CFG->mnet_dispatcher_mode)) {
37 set_config('mnet_dispatcher_mode', 'off');
40 /// If data submitted, process and store
41 if (($form = data_submitted()) && confirm_sesskey()) {
42 if (!empty($form->submit) && $form->submit == get_string('savechanges')) {
43 if (in_array($form->mode, array("off", "strict", "promiscuous"))) {
44 if (set_config('mnet_dispatcher_mode', $form->mode)) {
45 redirect('index.php', get_string('changessaved'));
46 } else {
47 error('Invalid action parameter.', 'index.php');
50 } elseif (!empty($form->submit) && $form->submit == get_string('delete')) {
51 $MNET->get_private_key();
52 $_SESSION['mnet_confirm_delete_key'] = md5(sha1($MNET->keypair['keypair_PEM'])).':'.time();
53 notice_yesno(get_string("deletekeycheck", "mnet"),
54 "index.php?sesskey=$USER->sesskey&amp;confirm=".md5($MNET->public_key),
55 "index.php",
56 array('sesskey' => $USER->sesskey),
57 NULL,
58 'post',
59 'get');
60 exit;
61 } else {
62 // We're deleting
65 if (!isset($_SESSION['mnet_confirm_delete_key'])) {
66 // fail - you're being attacked?
69 $key = '';
70 $time = '';
71 @list($key, $time) = explode(':',$_SESSION['mnet_confirm_delete_key']);
72 $MNET->get_private_key();
74 if($time < time() - 60) {
75 // fail - you're out of time.
76 print_error ('deleteoutoftime', 'mnet', 'index.php');
77 exit;
80 if ($key != md5(sha1($MNET->keypair['keypair_PEM']))) {
81 // fail - you're being attacked?
82 print_error ('deletewrongkeyvalue', 'mnet', 'index.php');
83 exit;
86 $MNET->replace_keys();
87 redirect('index.php', get_string('keydeleted','mnet'));
88 exit;
91 $hosts = get_records_select('mnet_host', " id != '{$CFG->mnet_localhost_id}' AND deleted = '0' ",'wwwroot ASC' );
93 admin_externalpage_print_header($adminroot);
95 <center>
96 <form method="post" action="index.php">
97 <table align="center" width="635" class="generalbox" border="0" cellpadding="5" cellspacing="0">
98 <tr>
99 <td class="generalboxcontent">
100 <table cellpadding="9" cellspacing="0" >
101 <tr valign="top">
102 <td colspan="2" class="header" cellpadding="0"><?php print_string('aboutyourhost', 'mnet'); ?></td>
103 </tr>
104 <tr valign="top">
105 <td align="right"><?php print_string('publickey', 'mnet'); ?>:</td>
106 <td><pre><?php echo $MNET->public_key; ?></pre></td>
107 </tr>
108 <tr valign="top">
109 <td align="right"><?php print_string('expires', 'mnet'); ?>:</td>
110 <td><?php echo userdate($MNET->public_key_expires); ?></td>
111 </tr>
112 <tr valign="top">
113 <td align="right"><?php print_string('net', 'mnet'); ?>:</td>
114 <td><input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
115 <input type="radio" name="mode" value="off" <?php echo ("off" == $CFG->mnet_dispatcher_mode)? 'checked="true"' : '' ?> /> <?php print_string('off', 'mnet'); ?> <br />
116 <input type="radio" name="mode" value="strict" <?php echo ("strict" == $CFG->mnet_dispatcher_mode)? 'checked="true"' : '' ?> /> <?php print_string('on', 'mnet'); ?><br />
117 <input type="submit" name="submit" value="<?php print_string('savechanges'); ?>" />
118 </td>
119 </tr>
120 </table>
121 </td>
122 </tr>
123 </table>
124 </form>
125 <form method="post" action="index.php">
126 <table align="center" width="635" class="generalbox" border="0" cellpadding="5" cellspacing="0">
127 <tr>
128 <td class="generalboxcontent">
129 <table cellpadding="9" cellspacing="0" >
130 <tr valign="top">
131 <td colspan="2" class="header" cellpadding="0"><?php print_string('expireyourkey', 'mnet'); ?></td>
132 </tr>
133 <tr valign="top">
134 <td colspan="2" cellpadding="0"><?php print_string('expireyourkeyexplain', 'mnet'); ?></td>
135 </tr>
136 <tr valign="top">
137 <td align="left" width="10" nowrap="nowrap"><?php print_string('expireyourkey', 'mnet'); ?></td>
138 <td align="left"><input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
139 <input type="hidden" name="deleteKey" value="" />
140 <input type="submit" name="submit" value="<?php print_string('delete'); ?>" />
141 </td>
142 </tr>
143 </table>
144 </td>
145 </tr>
146 </table>
147 </form>
148 </center>
150 <?php
151 admin_externalpage_print_footer($adminroot);