You are here

function _account_sync_sync_in_deny in Account Sync 6

Same name and namespace in other branches
  1. 7.2 account_sync.receiver.inc \_account_sync_sync_in_deny()
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 131
Handler inc for receiving and updating user account data.

Code

function _account_sync_sync_in_deny($server_key, $category) {
  $message = NULL;
  if ($category != 'account' && !in_array($category, _account_sync_get_profile_categories())) {
    $message = array(
      WATCHDOG_NOTICE,
      'Missing profile category @category',
      array(
        '@category' => $category,
      ),
    );
  }
  elseif (!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;
}