function smart_ip_admin_settings_validate in Smart IP 6
Same name and namespace in other branches
- 6.2 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
- 7.2 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
- 7 includes/smart_ip.admin.inc \smart_ip_admin_settings_validate()
1 string reference to 'smart_ip_admin_settings_validate'
- smart_ip_admin_settings in includes/
smart_ip.admin.inc - Smart IP administration settings.
File
- includes/
smart_ip.admin.inc, line 269 - Admin interface callbacks/handlers to configure Smart IP.
Code
function smart_ip_admin_settings_validate($form, &$form_state) {
if ($form_state['values']['smart_ip_source'] == 'mod_geoip' && !isset($_SERVER['GEOIP_COUNTRY_NAME'])) {
form_set_error('smart_ip_source', t("Maxmind's Apache module mod_geoip is not installed in your server."));
}
if ($form_state['values']['smart_ip_source'] == 'x_header' && !isset($_SERVER['HTTP_X_GEOIP_COUNTRY'])) {
form_set_error('smart_ip_source', t('Your server does not support X-header GeoIP functionality.'));
}
if ($form_state['values']['smart_ip_source'] == 'ipinfodb_service' && empty($form_state['values']['smart_ip_ipinfodb_key'])) {
form_set_error('smart_ip_ipinfodb_key', t('Please provide IPInfoDB key.'));
}
$ipinfodb_key = variable_get('smart_ip_ipinfodb_key', '');
if ($form_state['values']['smart_ip_ipinfodb_key'] != $ipinfodb_key) {
variable_set('smart_ip_correct_ipinfodb_key', FALSE);
}
if ($form_state['values']['smart_ip_source'] == 'ip2location_bin') {
if (empty($form_state['values']['smart_ip_ip2location_bin_path'])) {
form_set_error('smart_ip_ip2location_bin_path', t('Please provide IP2Location binary file path.'));
}
if (!empty($form_state['values']['smart_ip_ip2location_bin_path'])) {
// Check IP2Location binary file path if valid
if (!is_file($form_state['values']['smart_ip_ip2location_bin_path'])) {
form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file path is not valid.'));
}
else {
// Check IP2Location binary file if valid
try {
module_load_include('inc', 'smart_ip', 'includes/IP2Location');
$location_data = new IP2Location($form_state['values']['smart_ip_ip2location_bin_path'], IP2Location::FILE_IO);
$record = $location_data
->lookup('8.8.8.8', IP2Location::ALL);
if (empty($record->ipNumber)) {
form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file is not valid or corrupted.'));
}
} catch (Exception $error) {
form_set_error('smart_ip_ip2location_bin_path', t('The IP2Location binary file is not valid or corrupted.'));
}
}
}
}
if ($form_state['values']['smart_ip_source'] == 'maxmindgeoip_service' && empty($form_state['values']['smart_ip_maxmind_key'])) {
form_set_error('smart_ip_maxmind_key', t('Please provide Maxmind GeoIP developer key.'));
}
}