View source
<?php
function smart_ip_requirements($phase = 'runtime') {
$requirements = array();
if ($phase == 'runtime') {
$correct_key = variable_set('smart_ip_correct_ipinfodb_key', FALSE);
if (!$correct_key) {
$smart_ip_source = variable_get('smart_ip_source', 'ipinfodb_service');
if ($smart_ip_source == 'ipinfodb_service') {
$ipinfodb_key = variable_get('smart_ip_ipinfodb_key', '');
if (empty($ipinfodb_key)) {
$requirements['smart_ip'] = array(
'title' => 'IPInfoDB API key',
'severity' => REQUIREMENT_ERROR,
'value' => t('Not configured'),
'description' => t('The IPInfoDB API key is not configured yet. Visit Smart IP settings !page.', array(
'!page' => l(t('page'), 'admin/settings/smart_ip'),
)),
);
}
else {
$response = drupal_http_request(smart_ip_get_ipinfodb_url($ipinfodb_key, '127.0.0.1'));
$stat = (array) json_decode($response->data);
if ($stat['Status'] == 'MISSING API KEY' || $stat['Status'] == 'INVALID API KEY') {
$requirements['smart_ip'] = array(
'title' => 'IPInfoDB API key',
'severity' => REQUIREMENT_ERROR,
'value' => t('Invalid'),
'description' => t('The IPInfoDB API key is invalid. Visit Smart IP settings !page.', array(
'!page' => l(t('page'), 'admin/settings/smart_ip'),
)),
);
}
else {
variable_set('smart_ip_correct_ipinfodb_key', TRUE);
}
}
}
}
}
return $requirements;
}
function smart_ip_schema_definition_array() {
return array(
'description' => 'Association between IP range and Geo location',
'fields' => array(
'geoip_id' => array(
'description' => 'ID assigned by maxmind',
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
),
'ip_ref' => array(
'description' => 'Lowest IP Address in Range',
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
),
'country_code' => array(
'description' => 'ISO 3166 2-Character Country Code',
'type' => 'varchar',
'length' => 3,
'not null' => TRUE,
),
'region' => array(
'description' => '2-Character Region Code',
'type' => 'varchar',
'length' => 3,
'not null' => FALSE,
),
'city' => array(
'description' => 'Name of city targeted by the coordinates',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'zip' => array(
'description' => 'Postal code of targeted by the coordinates',
'type' => 'varchar',
'length' => 8,
'not null' => FALSE,
),
'latitude' => array(
'description' => 'Latitude',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
),
'longitude' => array(
'description' => 'Longitude',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
),
),
'primary key' => array(
'ip_ref',
),
'indexes' => array(
'geoip_id' => array(
'geoip_id',
),
),
);
}
function smart_ip_schema() {
$schema['smart_ip'] = smart_ip_schema_definition_array();
$schema['cache_smart_ip'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_smart_ip']['description'] = 'Cache table for storing temporary data during Smart IP database update.';
return $schema;
}
function smart_ip_install() {
drupal_install_schema('smart_ip');
variable_set('smart_ip_correct_ipinfodb_key', FALSE);
variable_set('smart_ip_get_zip_done', FALSE);
variable_set('smart_ip_extract_zip_done', FALSE);
variable_set('smart_ip_store_location_csv_done', FALSE);
variable_set('smart_ip_db_update_busy', FALSE);
variable_set('smart_ip_location_csv_pointer', 0);
variable_set('smart_ip_location_csv_last_pointer', 0);
variable_set('smart_ip_blocks_csv_pointer', 0);
variable_set('smart_ip_blocks_csv_last_pointer', 0);
variable_set('smart_ip_roles_to_geolocate', array(
DRUPAL_AUTHENTICATED_RID,
));
}
function smart_ip_update_6000() {
if (variable_get('smart_ip_save_user_location', TRUE)) {
variable_set('smart_ip_roles_to_geolocate', array(
DRUPAL_AUTHENTICATED_RID,
));
}
else {
variable_set('smart_ip_roles_to_geolocate', array());
}
variable_del('smart_ip_save_user_location');
}
function smart_ip_update_6001() {
if (variable_get('smart_ip_use_ipinfodb_service', FALSE)) {
variable_set('smart_ip_source', 'ipinfodb_service');
}
elseif (variable_get('smart_ip_auto_update', FALSE)) {
variable_set('smart_ip_source', 'local_db');
}
variable_del('smart_ip_use_ipinfodb_service');
}
function smart_ip_update_6002() {
if (variable_get('smart_ip_maxmind_service', 'country') == 'city') {
variable_set('smart_ip_maxmind_service', 'city_isp_org');
}
}
function smart_ip_uninstall() {
drupal_uninstall_schema('smart_ip');
variable_del('smart_ip_source');
variable_del('smart_ip_ip2location_bin_path');
variable_del('smart_ip_maxmind_service');
variable_del('smart_ip_maxmind_key');
variable_del('smart_ip_use_ipinfodb_api_version');
variable_del('smart_ip_correct_ipinfodb_key');
variable_del('smart_ip_ipinfodb_key');
variable_del('smart_ip_get_zip_done');
variable_del('smart_ip_extract_zip_done');
variable_del('smart_ip_store_location_csv_done');
variable_del('smart_ip_db_update_busy');
variable_del('smart_ip_db_update_busy_timeout');
variable_del('smart_ip_indicator_last_ip');
variable_del('smart_ip_location_csv_pointer');
variable_del('smart_ip_location_csv_last_pointer');
variable_del('smart_ip_blocks_csv_pointer');
variable_del('smart_ip_blocks_csv_last_pointer');
variable_del('smart_ip_auto_update');
variable_del('smart_ip_last_update');
variable_del('smart_ip_debug');
variable_del('smart_ip_test_ip_address');
variable_del('smart_ip_roles_to_geolocate');
}