function _services_ipauth_authenticate_call in Services IP Authentication 7
Same name and namespace in other branches
- 6 services_ipauth.inc \_services_ipauth_authenticate_call()
Authenticate call.
See also
services_ipauth_services_authentication_info()
1 string reference to '_services_ipauth_authenticate_call'
- services_ipauth_services_authentication_info in ./
services_ipauth.module - Implementation of hook_services_authentication().
File
- ./
services_ipauth.inc, line 13 - Provides callbacks for the IP Authentication module.
Code
function _services_ipauth_authenticate_call($settings) {
// Get remote IP address.
$current_ip = ip_address();
// Prepare list of user defined addresses and ranges.
$ip_ranges = array_filter($settings['services_ipauth_addresses'], 'services_ipauth_is_ip_range');
$ip_addresses = array_diff($settings['services_ipauth_addresses'], $ip_ranges);
// Check whether filtering method is Deny.
$filtering_method_deny = $settings['services_ipauth_type'] == SERVICES_IPAUTH_TYPE_DENY;
// Check whether the current ip is in the list.
$ip_address_in_list = in_array($current_ip, $ip_addresses);
$ip_address_in_range = FALSE;
// Don't need to check range if the ip is already in the listed ips.
if (!$ip_address_in_list) {
foreach ($ip_ranges as $ip_range) {
if (services_ipauth_ip_is_in_range($current_ip, $ip_range)) {
$ip_address_in_range = TRUE;
break;
}
}
}
$ip_match = $ip_address_in_list || $ip_address_in_range;
// Deny access if the ip address is in the list and we use Deny method,
// or if the ip address is not in the list and we use Allow method.
if ($ip_match && $filtering_method_deny || !$filtering_method_deny && !$ip_match) {
return t('IP address access denied.');
}
}