Again, this simplifies the logic in a few places.
$trusted_hosts = '';//array();
$old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
+ if (!empty($old_trusted_hosts)) {
+ $old_trusted_hosts = explode(',', $old_trusted_hosts);
+ } else {
+ $old_trusted_hosts = array();
+ }
$test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
$in_range = false;
if (!empty($test_ip_address)) {
- foreach(explode(',', $old_trusted_hosts->value) as $host) {
+ foreach($old_trusted_hosts as $host) {
list($network, $mask) = explode('/', $host.'/');
if (empty($network)) continue;
if (strlen($mask) == 0) $mask = 32;
unset($address, $mask);
}
set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
- } elseif (!empty($old_trusted_hosts->value)) {
- foreach(explode(',', $old_trusted_hosts->value) as $host) {
+ } elseif (!empty($old_trusted_hosts)) {
+ foreach($old_trusted_hosts as $host) {
list($address, $mask) = explode('/', $host.'/');
if (empty($address)) continue;
if (strlen($mask) == 0) $mask = 32;
if (!$isOpen) {
// Decryption failed... let's try our archived keys
- $result = get_config('mnet', 'openssl_history');
- if(empty($result)) {
- set_config('openssl_history', serialize(array()), 'mnet');
- $result = get_config('mnet', 'openssl_history');
+ $openssl_history = get_config('mnet', 'openssl_history');
+ if(empty($openssl_history)) {
+ $openssl_history = array();
+ set_config('openssl_history', serialize($openssl_history), 'mnet');
+ } else {
+ $openssl_history = unserialize($result);
}
- $openssl_history = unserialize($result->value);
foreach($openssl_history as $keyset) {
$keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
$isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);
$remote_timestamp = $sig_parser->remote_timestamp - $hysteresis;
$time_offset = $remote_timestamp - $timestamp_send;
if ($time_offset > 0) {
- $result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'drift_threshold');
- if(empty($result)) {
+ $threshold = get_config('mnet', 'drift_threshold');
+ if(empty($threshold)) {
// We decided 15 seconds was a pretty good arbitrary threshold
// for time-drift between servers, but you can customize this in
// the config_plugins table. It's not advised though.
set_config('drift_threshold', 15, 'mnet');
$threshold = 15;
- } else {
- $threshold = $result;
}
if ($time_offset > $threshold) {
$this->error[] = 'Time gap with '.$mnet_peer->name.' ('.$time_offset.' seconds) is greater than the permitted maximum of '.$threshold.' seconds';
if (!$isOpen) {
// Decryption failed... let's try our archived keys
- $result = get_config('mnet', 'openssl_history');
- if(empty($result)) {
- set_config('openssl_history', serialize(array()), 'mnet');
- $result = get_config('mnet', 'openssl_history');
+ $openssl_history = get_config('mnet', 'openssl_history');
+ if(empty($openssl_history)) {
+ $openssl_history = array();
+ set_config('openssl_history', serialize($openssl_history), 'mnet');
+ } else {
+ $openssl_history = unserialize($result);
}
- $openssl_history = unserialize($result->value);
foreach($openssl_history as $keyset) {
$keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
$isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);