forked from kylebrowning/services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.install
261 lines (248 loc) · 8.19 KB
/
services.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
/**
* @file
* Install, uninstall and update the Services module.
*/
/**
* Implements hook_schema().
*/
function services_schema() {
$schema = array();
$schema['services_endpoint'] = array(
'description' => 'Stores endpoint information for services',
'fields' => array(
'eid' => array(
'type' => 'serial',
'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
'unsigned' => TRUE,
'not null' => TRUE,
'no export' => TRUE,
),
'name' => array(
'description' => 'The name of the endpoint.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'server' => array(
'description' => 'The name of the server used in this endpoint.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'path' => array(
'description' => 'The path to the endpoint for this server.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'authentication' => array(
'description' => 'The authentication settings for the endpoint.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'object default' => array(),
),
'server_settings' => array(
'description' => 'The server settings for the endpoint.',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE
),
'resources' => array(
'description' => 'Information about the resources exposed in this endpoint.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'object default' => array(),
),
'debug' => array(
'description' => 'Set the endpoint in debug mode.',
'type' => 'int',
'not null' => TRUE,
'default' => 0
),
),
'primary key' => array('eid'),
'unique keys' => array(
'name' => array('name'),
),
'export' => array(
'key' => 'name',
'identifier' => 'endpoint',
'primary key' => 'name',
'api' => array(
'owner' => 'services',
'api' => 'services',
'minimum_version' => 3,
'current_version' => 3,
),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function services_requirements($phase) {
$requirements = array();
$t = get_t();
// Warn users of the possible threat.
if ($phase == 'runtime') {
//Pull endpoints that do not have services authentication enabled
$result = db_query('SELECT * FROM {services_endpoint} AS se WHERE se.authentication NOT LIKE :services', array(':services' => '%services%'));
$items = array();
// Build our items array
foreach ($result as $endpoint) {
$items[] = l($endpoint->name, 'admin/structure/services/list/'. $endpoint->name .'/edit');
}
// theme the endpoints list
$endpoints = '';
if (!empty($items)) {
$endpoints = theme('item_list', array('items' => $items));
}
// Only display the list if we have at least one endpoint without services authentication.
if (count($items)) {
$requirements['services'] = array(
'description' => $t('Services authentication mechanism has not been enabled for the following endpoints. Requests to these endpoints will always be anonymous.'),
'severity' => REQUIREMENT_WARNING,
'value' => $endpoints,
'title' => 'Services Authentication Mechanism',
);
} else {
$requirements['services'] = array(
'severity' => REQUIREMENT_OK,
'value' => 'Enabled for all Endpoints',
'title' => 'Services Authentication Mechanism',
);
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function services_uninstall() {
$ret = array();
// Drop legacy tables
$legacy_tables = array('services_keys', 'services_timestamp_nonce');
foreach ($legacy_tables as $table) {
if (db_table_exists($table)) {
db_drop_table($ret, $table);
}
}
variable_del('services_use_key');
variable_del('services_use_sessid');
variable_del('services_debug');
variable_del('services_auth_module');
}
/**
* Update 7301 adds debugging to each endopint to facilitate easier development
*/
function services_update_7301() {
$table = 'services_endpoint';
foreach (array('debug' => 0, 'status' => 1) as $field => $value) {
if (!db_field_exists($table, $field)) {
db_add_field($table, $field, array('type' => 'int', 'not null' => TRUE, 'default' => $value));
}
}
}
/**
* Update 7302 restores the usage of Chaos tools to check for enable/disable-status
*/
function services_update_7302() {
$table = 'services_endpoint';
if (db_field_exists($table, 'status')) {
db_drop_field($table, 'status');
}
}
/**
* Update 7303 adds the possibility to configure server settings on a per-endpoint basis.
* and sets upgrades all new servers to have at least services session enabled.
*/
function services_update_7303() {
// Add the new server settings field.
if (!db_field_exists('services_endpoint', 'server_settings')) {
db_add_field('services_endpoint', 'server_settings', array(
'description' => 'The server settings for the endpoint.',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'initial' => '',
));
}
// Fetch all endpoints that currently exist
$result = db_select('services_endpoint', 'se')
->fields('se')
->execute()
->fetchAll();
// Loop through every endpoint and update the authentication section.
// Note, this will not remove previous authentication settings, it will
// only add to them.
foreach($result as $services_endpoint_object) {
$new_authentication = array(
'services' => 'services',
);
$unserial_endpoint_settings = unserialize($services_endpoint_object->authentication);
db_update('services_endpoint')
->fields(array('authentication' => serialize(array_merge($unserial_endpoint_settings, $new_authentication))))
->condition('eid', $services_endpoint_object->eid)
->execute();
}
}
/**
* Update 7304 removes the title as it is no longer used
*/
function services_update_7399() {
$table = 'services_endpoint';
if (db_field_exists($table, 'title')) {
db_drop_field($table, 'title');
}
}
/**
* Update 7400 reduces nesting in the way server settings are stored
*/
function services_update_7400() {
module_load_include('module','services');
$server_names = array_keys(services_get_servers());
foreach (services_endpoint_load_all() as $endpoint) {
$settings = $endpoint->server_settings;
if (!empty($settings)) {
if (in_array(key($settings), $server_names)) {
$settings = current($settings);
}
}
else {
$settings = array();
}
$endpoint->server_settings = $settings;
services_endpoint_save($endpoint);
}
}
/**
* Update 7401 Changes passwords of all users that were created/registered since (30 July, 2013)
* Read more here drupal.org node 2284449.
* Skip the user password change by setting the variable services_skip_security_update_7401 to TRUE.
* NOTE: This Overwrites password hashes using an invalid prefix which can never match a password hash during login.
* All affected users will have to request new one time login links to reset their passwords.
*/
function services_update_7401() {
// http://drupal.org/node/2284449.
// Update users created only after the bug has been introduced (30 July, 2013).
$skip_update = variable_get('services_skip_security_update_7401', FALSE);
if ($skip_update === FALSE) {
$affected_accounts = db_update('users')
->fields(array(
'pass' => "ZZZservices_security",
))
->condition('created', 1374278400, '>=')
->execute();
return t('@accounts user passwords have been reset.', array('@accounts' => $affected_accounts));
} else {
return t('Skipped security update 7401 due to variable services_skip_security_update_7401 being set to TRUE');
}
}