<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>
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):
?>
<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):
<?php
endif;
-endif;
-
if (isset($mnet_peer->ip_address) && '' != $mnet_peer->ip_address):
?>
<tr>
<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);
?>
$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);
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) {
} 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');
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'];