You are here

function _account_sync_sync_in_deny in Account Sync 7.2

Same name and namespace in other branches
  1. 6 account_sync.receiver.inc \_account_sync_sync_in_deny()

Check a any cases that should trigger us to deny the sync.

1 call to _account_sync_sync_in_deny()
account_sync_update_user in ./account_sync.receiver.inc
XMLRPC callback to update the user account on /this/ drupal site.

File

./account_sync.receiver.inc, line 174
Handler for receiving and updating user account data.

Code

function _account_sync_sync_in_deny($server_key, $category) {
  $message = NULL;

  // Check that account sync is enable and that some roles have been setup.
  if (!variable_get('account_sync_in_enabled', FALSE) || !account_sync_allowed_roles()) {
    $message = array(
      WATCHDOG_ERROR,
      'Account sync not allowed',
    );
    watchdog('account_sync', 'Remote server attempted to sync accounts, but sync-in is currently disabled.', array(), WATCHDOG_NOTICE);
  }
  elseif ($server_key != variable_get('account_sync_server_key', '')) {
    $message = array(
      WATCHDOG_ERROR,
      'Invalid server key',
    );
    watchdog('account_sync', 'Remote server passed invalid key when attempting to sync accounts.', array(), WATCHDOG_NOTICE);
  }
  else {

    // Check ip addresses.
    $sender_ip = ip_address();
    $ip_setting = variable_get('account_sync_ip_restriction', 0);
    $ips = array();
    foreach (explode("\n", variable_get('account_sync_ips', array())) as $ip) {
      $ips[] = trim($ip);
    }
    if ($ip_setting == 0 && in_array($sender_ip, $ips) || $ip_setting == 1 && !in_array($sender_ip, $ips)) {
      $message = array(
        WATCHDOG_ERROR,
        'This IP is not permitted access to sync to this site.',
      );
      watchdog('account_sync', 'Remote server (%ip) attempted to update an account but that IP is not permitted to update accounts on this site.', array(
        '%ip' => $sender_ip,
      ), WATCHDOG_NOTICE);
    }
  }
  return $message;
}