-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoip_tokens.install
140 lines (133 loc) · 3.53 KB
/
geoip_tokens.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @file
* Install, update and uninstall functions for this module.
*/
/**
* Implements hook_schema().
*/
function geoip_tokens_schema() {
$schema['geoip_tokens_cache'] = array(
'description' => 'The base table for caching results for geoip_tokens.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'anon_ip' => array(
'description' => 'Anonymized IP of this record.',
'type' => 'varchar',
'length' => 96,
'not null' => TRUE,
'default' => '',
),
'country_code' => array(
'description' => 'Country code of this record, usually two letters.',
'type' => 'varchar',
'length' => 8,
'not null' => FALSE,
),
'latitude' => array(
'description' => 'Latitude coordinates',
'type' => 'varchar',
'length' => 36,
'not null' => TRUE,
),
'longitude' => array(
'description' => 'Longitude coordinates',
'type' => 'varchar',
'length' => 36,
'not null' => TRUE,
),
'timezone' => array(
'description' => 'Timezone for these coordinates',
'type' => 'varchar',
'length' => 36,
'not null' => FALSE,
),
'provider' => array(
'description' => 'The provider this record has been fetched from',
'type' => 'varchar',
'length' => 80,
'not null' => FALSE,
),
'created' => array(
'description' => 'Unix timestamp when this record was created',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
'indexes' => array(
'anon_ip' => array('anon_ip'),
'created' => array('created'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function geoip_tokens_install() {
$new_token = backdrop_random_key();
state_set('geoip_tokens_request_token', $new_token);
state_set('geoip_tokens_request_token_refreshed', REQUEST_TIME);
}
/**
* Implements hook_uninstall().
*/
function geoip_tokens_uninstall() {
state_del('geoip_tokens_request_token');
state_del('geoip_tokens_request_token_refreshed');
}
/**
* Add more providers to config
*/
function geoip_tokens_update_1000() {
$new_providers = array(
'freegeoip.app' => 'freegeoip.app',
'freegeoip.live' => 'freegeoip.live',
'geoiplookup.io' => 'geoiplookup.io',
);
$config = config('geoip_tokens.settings');
$current_providers = $config->get('providers');
$current_providers += $new_providers;
$config->set('providers', $current_providers);
$config->save();
}
/**
* Remove closed down freegeoip.app service.
*/
function geoip_tokens_update_1001() {
$config = config('geoip_tokens.settings');
$current_providers = $config->get('providers');
unset($current_providers['freegeoip.app']);
$config->set('providers', $current_providers);
$config->save();
}
/**
* Replace closed down or broken services.
*/
function geoip_tokens_update_1002() {
$old = array(
'freegeoip.live',
'geoiplookup.io',
);
$new = array(
'geoip.cdnservice.eu',
'ipwhois.io',
);
$config = config('geoip_tokens.settings');
$current_providers = $config->get('providers');
foreach ($old as $provider) {
unset($current_providers[$provider]);
}
foreach ($new as $provider) {
$current_providers[$provider] = $provider;
}
$config->set('providers', $current_providers);
$config->save();
}