Permalink
Browse files

get_config() callers in new MNET code switched to expect a single val…

…ue returned

Again, this simplifies the logic in a few places.
  • Loading branch information...
martinlanghoff
martinlanghoff committed Jan 16, 2007
1 parent 1fd471a commit c9fa3eee9b33b3f5d20bd76bca7c5bfd8db64acd
Showing with 22 additions and 17 deletions.
  1. +8 −3 admin/mnet/trustedhosts.php
  2. +8 −9 mnet/xmlrpc/client.php
  3. +6 −5 mnet/xmlrpc/server.php
@@ -25,11 +25,16 @@
$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;
@@ -54,8 +59,8 @@
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;
View
@@ -204,12 +204,13 @@ function send($mnet_peer) {
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);
@@ -247,15 +248,13 @@ function send($mnet_peer) {
$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';
View
@@ -145,12 +145,13 @@ function mnet_server_strip_wrappers($HTTP_RAW_POST_DATA) {
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);

0 comments on commit c9fa3ee

Please sign in to comment.