Permalink
Browse files

mnet/environment: Fixup to make proper use of Moodle dml functions

Author: Donal McMullan <donal@catalyst.net.nz>
  • Loading branch information...
1 parent 13c9d7e commit f32689ad4b2739bf79d6f6d1408e05545d0d6390 martinlanghoff committed Jan 4, 2007
Showing with 22 additions and 25 deletions.
  1. +22 −25 mnet/environment.php
View
@@ -15,6 +15,7 @@ class mnet_environment {
var $last_connect_time = 0;
var $last_log_id = 0;
var $keypair = array();
+ var $deleted = 0;
function mnet_environment() {
return true;
@@ -25,38 +26,29 @@ function init() {
// Bootstrap the object data on first load.
if (empty($CFG->mnet_localhost_id) ) {
- $this->get_keypair();
-
- $hostobject = new stdClass();
- $hostobject->wwwroot = $CFG->wwwroot;
- $hostobject->ip_address = $_SERVER['SERVER_ADDR'];
- $hostobject->public_key = $this->keypair['certificate'];
- $hostobject->public_key_expires = '';
- $hostobject->last_connect_time = '0';
- $hostobject->last_log_id = '0';
- $hostobject->deleted = 0;
-
- $this->id = insert_record('mnet_host',$hostobject, true);
- $temparr = (array)get_object_vars($hostobject);
-
- foreach($temparr as $key => $value) {
- $this->$key = $value;
- }
-
- unset($temparr, $hostobject);
+ $this->wwwroot = $CFG->wwwroot;
+ $this->ip_address = $_SERVER['SERVER_ADDR'];
+ $this->id = insert_record('mnet_host', $this, true);
set_config('mnet_localhost_id', $this->id);
- $CFG->mnet_localhost_id = $this->id;
+ $this->get_keypair();
} else {
$hostobject = get_record('mnet_host','id', $CFG->mnet_localhost_id);
- $temparr = (array)get_object_vars($hostobject);
-
- foreach($temparr as $key => $value) {
- $this->$key = $value;
+ if(is_object($hostobject)) {
+ $temparr = get_object_vars($hostobject);
+ foreach(get_object_vars($temparr) as $key => $value) {
+ $this->$key = $value;
+ }
+ unset($hostobject, $temparr);
+ } else {
+ return false;
}
- unset($temparr, $hostobject);
+ // Unless this is an install/upgrade, generate the SSL keys.
+ if(empty($this->public_key)) {
+ $this->get_keypair();
+ }
}
// We need to set up a record that represents 'all hosts'. Any rights
@@ -87,6 +79,11 @@ function get_keypair() {
$this->keypair['publickey'] = openssl_pkey_get_public($this->keypair['certificate']);
} else {
$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'];
+
+ update_record('mnet_host', $this);
}
return true;
}

0 comments on commit f32689a

Please sign in to comment.