]> git.mjollnir.org Git - moodle.git/commitdiff
admin/mnet/index: Allow admins to expire an SSL key
authormartinlanghoff <martinlanghoff>
Thu, 4 Jan 2007 03:37:42 +0000 (03:37 +0000)
committermartinlanghoff <martinlanghoff>
Thu, 4 Jan 2007 03:37:42 +0000 (03:37 +0000)
Author: Donal McMullan <donal@catalyst.net.nz>

admin/mnet/index.html
admin/mnet/index.php

index e87ce54cbc381585e3dd3ebb9971d1e2b6fa2c81..6a058961b1b349119154530856fe339b286925b4 100644 (file)
@@ -27,6 +27,29 @@ admin_externalpage_print_header($adminroot);
         </tr>
     </table>
 </form>
+<form method="post" action="index.php">
+    <table align="center" width="635" class="generalbox" border="0" cellpadding="5" cellspacing="0">
+        <tr>
+            <td  class="generalboxcontent">
+            <table cellpadding="9" cellspacing="0" >
+                <tr valign="top">
+                    <td colspan="2" class="header" cellpadding="0"><span><?php print_string('expireyourkey', 'mnet'); ?></span></td>
+                </tr>
+                <tr valign="top">
+                    <td colspan="2" cellpadding="0"><span><?php print_string('expireyourkeyexplain', 'mnet'); ?></span></td>
+                </tr>
+                <tr valign="top">
+                    <td align="left" width="10" nowrap><?php print_string('expireyourkey', 'mnet'); ?></td>
+                    <td align="left"><input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
+                        <input type="hidden" name="deleteKey" value="" />
+                        <input type="submit" name="submit" value="<?php print_string('delete'); ?>" />
+                    </td>
+                </tr>
+            </table>
+            </td>
+        </tr>
+    </table>
+</form>
 </center>
 <?php
 admin_externalpage_print_footer($adminroot);
index 9de415474de64a1cc1efd37dcf7a2587a9eaad40..04bac9fa122c5104d413d504495319168c3125e1 100644 (file)
 
 /// If data submitted, process and store
     if (($form = data_submitted()) && confirm_sesskey()) {
-        if (in_array($form->mode, array("off", "strict", "promiscuous"))) {
-            if (set_config('mnet_dispatcher_mode', $form->mode)) {
-                redirect('index.php', get_string('changessaved'));
-            } else {
-                error('Invalid action parameter.', 'index.php');
+        if (!empty($form->submit) && $form->submit == get_string('savechanges')) {
+            if (in_array($form->mode, array("off", "strict", "promiscuous"))) {
+                if (set_config('mnet_dispatcher_mode', $form->mode)) {
+                    redirect('index.php', get_string('changessaved'));
+                } else {
+                    error('Invalid action parameter.', 'index.php');
+                }
             }
+        } elseif (!empty($form->submit) && $form->submit == get_string('delete')) {
+            $MNET->get_private_key();
+            $_SESSION['mnet_confirm_delete_key'] = md5(sha1($MNET->keypair['keypair_PEM'])).':'.time();
+            notice_yesno(get_string("deletekeycheck", "mnet"),
+                                    "index.php?sesskey=$USER->sesskey&amp;confirm=".md5($MNET->public_key),
+                                    "index.php",
+                                     array('sesskey' => $USER->sesskey),
+                                     NULL,
+                                    'post',
+                                    'get');
+            exit;
+        } else {
+            // We're deleting
+            
+            
+            if (!isset($_SESSION['mnet_confirm_delete_key'])) {
+                // fail - you're being attacked?
+            }
+
+            $key = '';
+            $time = '';
+            @list($key, $time) = explode(':',$_SESSION['mnet_confirm_delete_key']);
+            $MNET->get_private_key();
+
+            if($time < time() - 60) {
+                // fail - you're out of time.
+                print_error ('deleteoutoftime', 'mnet', 'index.php');
+                exit;
+            }
+
+            if ($key != md5(sha1($MNET->keypair['keypair_PEM']))) {
+                // fail - you're being attacked?
+                print_error ('deletewrongkeyvalue', 'mnet', 'index.php');
+                exit;
+            }
+
+            $MNET->replace_keys();
+            redirect('index.php', get_string('keydeleted','mnet'));
+            exit;
         }
     }
     $hosts = get_records_select('mnet_host', " id != '{$CFG->mnet_localhost_id}' AND deleted = '0' ",'wwwroot ASC' );