Skip to content

Commit

Permalink
get_config() callers in new MNET code switched to expect a single val…
Browse files Browse the repository at this point in the history
…ue returned

Again, this simplifies the logic in a few places.
  • Loading branch information
martinlanghoff committed Jan 16, 2007
1 parent 1fd471a commit c9fa3ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
11 changes: 8 additions & 3 deletions admin/mnet/trustedhosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions mnet/xmlrpc/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand Down
11 changes: 6 additions & 5 deletions mnet/xmlrpc/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c9fa3ee

Please sign in to comment.