Permalink
Browse files

admin/mnet/peers: Allow admins to manually update a remote server's p…

…ublic

key


Author: Donal McMullan <donal@catalyst.net.nz>
  • Loading branch information...
1 parent a9308ed commit e2d4f75c4011ba3c087cb0f219fa7eaafa466808 martinlanghoff committed Jan 4, 2007
Showing with 50 additions and 47 deletions.
  1. +24 −31 admin/mnet/mnet_review.html
  2. +13 −7 admin/mnet/peers.php
  3. +13 −9 mnet/environment.php
View
55 admin/mnet/mnet_review.html
@@ -23,7 +23,7 @@
<input type="hidden" name="step" value="commit" />
<input type="hidden" name="last_connect_time" value="<?php echo $mnet_peer->last_connect_time; ?>" />
<input type="hidden" name="id" value="<?php echo isset($mnet_peer->id)? $mnet_peer->id : '0' ; ?>" />
-<table cellpadding="9" cellspacing="0" >
+<table cellpadding="9" cellspacing="0" width="635">
<tr>
<td align="right" valign="top" nowrap><?php print_string('site'); ?>:</td>
@@ -43,34 +43,37 @@
helpbutton("publickey", get_string('publickey', 'mnet'), "mnet", true, true);
?></td>
<?php
+
+
+
if (isset($mnet_peer->deleted) && $mnet_peer->deleted > 0) {
$key = mnet_get_public_key($mnet_peer->wwwroot);
$mnet_peer->public_key = clean_param($key, PARAM_PEM);
+}
?>
<td valign="top">
- <?php
- if (empty($mnet_peer->public_key)) {
- notice(get_string('invalidpubkey', 'mnet'));
- }
- ?>
- <textarea rows="17" cols="65" name="public_key" style="font-size: 8px;"><?php echo $mnet_peer->public_key; ?></textarea></td>
+ <?php
+ if (empty($mnet_peer->public_key)) {
+ print_string('nopubkey', 'mnet');
+ }
+ ?><br>
+ <textarea rows="17" cols="65" name="public_key" style="font-size: 8px;"><?php echo $mnet_peer->public_key; ?></textarea>
+ </td>
</tr>
<?php
-} else {
+
+if(!empty($currentkey)):
?>
- <td valign="top">
- <?php
- if (empty($mnet_peer->public_key)) {
- p(get_string('invalidpubkey', 'mnet'));
- }
- ?>
- <pre style="font-size: 8px;">
- <?php echo $mnet_peer->public_key; ?>
- </pre></td>
-</tr>
+ <tr>
+ <td align="right" valign="top" nowrap></td>
+ <td valign="top"><?php print_string('keymismatch', 'mnet'); ?></td>
+ </tr>
+ <tr>
+ <td align="right" valign="top" nowrap><?php print_string('currentkey', 'mnet'); ?>:</td>
+ <td valign="top"><pre style="font-size: 8px;"><?php echo $currentkey;?></pre></td>
+ </tr>
<?php
-}
-
+endif;
if (isset($mnet_peer->id) && $mnet_peer->id > 0):
?>
@@ -79,13 +82,6 @@
<td valign="top"><?php echo ($mnet_peer->last_connect_time == 0)? get_string('never','mnet') : date('H:i:s d/m/Y',$mnet_peer->last_connect_time);?></td>
</tr>
<?php
-if (isset($mnet_peer->transport) && $mnet_peer->transport > 0):
-?>
- <tr>
- <td align="right" valign="top" nowrap><?php print_string('current_transport', 'mnet'); ?>:</td>
- <td valign="top"><?php echo mnet_get_transport_name($mnet_peer->transport);?></td>
- </tr>
-<?php
endif;
if (isset($mnet_peer->deleted) && $mnet_peer->deleted > 0):
@@ -100,8 +96,6 @@
<?php
endif;
-endif;
-
if (isset($mnet_peer->ip_address) && '' != $mnet_peer->ip_address):
?>
<tr>
@@ -119,9 +113,8 @@
<td></td>
<td><input type="submit" value="<?php print_string("savechanges"); ?>" /></td>
</tr>
+</table>
<?php
-
-echo ' </table>';
print_simple_box_end();
admin_externalpage_print_footer($adminroot);
?>
View
20 admin/mnet/peers.php
@@ -56,10 +56,11 @@
$mnet_peer->set_id($form->id);
} else {
// PARAM_URL requires a genuine TLD (I think) This breaks my testing
- $temp_wwwroot = $form->wwwroot; //clean_param($form->wwwroot, PARAM_URL);
+ $temp_wwwroot = clean_param($form->wwwroot, PARAM_URL);
if ($temp_wwwroot !== $form->wwwroot) {
- trigger_error("We now parse the wwwroot with PARAM_URL");
- error('Invalid URL parameter.', 'peers.php');
+ trigger_error("We now parse the wwwroot with PARAM_URL. Your URL will need to have a valid TLD, etc.");
+ error(get_string("invalidurl", 'mnet'),'peers.php');
+ exit;
}
unset($temp_wwwroot);
$mnet_peer->bootstrap($form->wwwroot);
@@ -77,24 +78,27 @@
if (isset($form->public_key)) {
$form->public_key = clean_param($form->public_key, PARAM_PEM);
if (empty($form->public_key)) {
- // Public key was not in a correct format
+ error(get_string("invalidpubkey", 'mnet'),'peers.php?step=update&hostid='.$mnet_peer->id);
+ exit;
} else {
$oldkey = $mnet_peer->public_key;
$mnet_peer->public_key = $form->public_key;
$mnet_peer->public_key_expires = $mnet_peer->check_common_name($form->public_key);
if ($mnet_peer->public_key_expires == false) {
$mnet_peer->public_key == $oldkey;
+ error(get_string("invalidpubkey", 'mnet'),'peers.php?step=update&hostid='.$mnet_peer->id);
+ exit;
}
}
}
-
+
// PREVENT DUPLICATE RECORDS ///////////////////////////////////////////
if ('input' == $form->step) {
if ( isset($mnet_peer->id) && $mnet_peer->id > 0 ) {
- error(get_string("hostexists ".$mnet_peer->id, 'mnet', $mnet_peer->id),'peers.php?step=update&hostid='.$mnet_peer->id);
+ error(get_string("hostexists", 'mnet', $mnet_peer->id),'peers.php?step=update&hostid='.$mnet_peer->id);
}
}
-
+
if ('input' == $form->step) {
include('./mnet_review.html');
} elseif ('commit' == $form->step) {
@@ -109,6 +113,8 @@
} elseif (is_int($hostid)) {
$mnet_peer = new mnet_peer();
$mnet_peer->set_id($hostid);
+ $currentkey = mnet_get_public_key($mnet_peer->wwwroot);
+ if($currentkey == $mnet_peer->public_key) unset($currentkey);
$form = new stdClass();
if ($hostid != $CFG->mnet_all_hosts_id) {
include('./mnet_review.html');
View
22 mnet/environment.php
@@ -120,19 +120,23 @@ function get_keypair() {
set_config('openssl_history', serialize($openssl_history), 'mnet');
// 3. Generate fresh keys
- $this->keypair = array();
- $this->keypair = mnet_generate_keypair();
- $this->public_key = $this->keypair['certificate'];
- $details = openssl_x509_parse($this->public_key);
- $this->public_key_expires = $details['validTo_time_t'];
-
- set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet');
-
- update_record('mnet_host', $this);
+ $this->replace_keys();
}
return true;
}
+ function replace_keys() {
+ $this->keypair = array();
+ $this->keypair = mnet_generate_keypair();
+ $this->public_key = $this->keypair['certificate'];
+ $details = openssl_x509_parse($this->public_key);
+ $this->public_key_expires = $details['validTo_time_t'];
+
+ set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet');
+
+ update_record('mnet_host', $this);
+ }
+
function get_private_key() {
if (empty($this->keypair)) $this->get_keypair();
if (isset($this->keypair['privatekey'])) return $this->keypair['privatekey'];

0 comments on commit e2d4f75

Please sign in to comment.