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