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();
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'));
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();
57 // If no/cancel then redirect back to the network setting page.
58 if (!isset($form->confirm
)) {
60 new moodle_url('/admin/mnet/index.php'),
61 get_string('keydeletedcancelled', 'mnet'),
63 \core\output\notification
::NOTIFY_SUCCESS
67 if (!isset($SESSION->mnet_confirm_delete_key
)) {
68 // fail - you're being attacked?
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.
79 new moodle_url('/admin/mnet/index.php'),
80 get_string('deleteoutoftime', 'mnet'),
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');
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">
103 <td
class="generalboxcontent">
104 <table cellpadding
="9" cellspacing
="0" >
106 <td colspan
="2" class="header"><?php
print_string('aboutyourhost', 'mnet'); ?
></td
>
109 <td align
="right"><?php
print_string('publickey', 'mnet'); ?
>:</td
>
110 <td
><pre
><?php
echo $mnet->public_key
; ?
></pre
></td
>
113 <td align
="right"><?php
print_string('expires', 'mnet'); ?
>:</td
>
114 <td
><?php
echo userdate($mnet->public_key_expires
); ?
></td
>
121 <form method
="post" action
="index.php">
122 <table align
="center" width
="635" class="generaltable" border
="0" cellpadding
="5" cellspacing
="0">
124 <td
class="generalboxcontent">
125 <table cellpadding
="9" cellspacing
="0" >
127 <td colspan
="2" class="header"><?php
print_string('expireyourkey', 'mnet'); ?
></td
>
130 <td colspan
="2"><?php
print_string('expireyourkeyexplain', 'mnet'); ?
></td
>
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'); ?>" />
146 echo $OUTPUT->footer();