1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Install, uninstall and update the Services module. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Implementation of hook_schema(). |
---|
9 | */ |
---|
10 | function services_schema() { |
---|
11 | $schema = array(); |
---|
12 | |
---|
13 | $schema['services_endpoint'] = array( |
---|
14 | 'description' => 'Stores endpoint information for services', |
---|
15 | 'fields' => array( |
---|
16 | 'eid' => array( |
---|
17 | 'type' => 'serial', |
---|
18 | 'description' => 'Primary ID field for the table. Not used for anything except internal lookups.', |
---|
19 | 'unsigned' => TRUE, |
---|
20 | 'not null' => TRUE, |
---|
21 | 'no export' => TRUE, |
---|
22 | ), |
---|
23 | 'name' => array( |
---|
24 | 'description' => 'The name of the endpoint.', |
---|
25 | 'type' => 'varchar', |
---|
26 | 'length' => 255, |
---|
27 | 'not null' => TRUE, |
---|
28 | ), |
---|
29 | 'server' => array( |
---|
30 | 'description' => 'The name of the server used in this endpoint.', |
---|
31 | 'type' => 'varchar', |
---|
32 | 'length' => 32, |
---|
33 | 'not null' => TRUE, |
---|
34 | ), |
---|
35 | 'path' => array( |
---|
36 | 'description' => 'The path to the endpoint for this server.', |
---|
37 | 'type' => 'varchar', |
---|
38 | 'length' => 255, |
---|
39 | 'not null' => TRUE, |
---|
40 | ), |
---|
41 | 'authentication' => array( |
---|
42 | 'description' => 'The authentication settings for the endpoint.', |
---|
43 | 'type' => 'text', |
---|
44 | 'size' => 'big', |
---|
45 | 'not null' => TRUE, |
---|
46 | 'serialize' => TRUE, |
---|
47 | 'object default' => array(), |
---|
48 | ), |
---|
49 | 'server_settings' => array( |
---|
50 | 'description' => 'The server settings for the endpoint.', |
---|
51 | 'type' => 'blob', |
---|
52 | 'size' => 'big', |
---|
53 | 'not null' => TRUE, |
---|
54 | 'serialize' => TRUE |
---|
55 | ), |
---|
56 | 'resources' => array( |
---|
57 | 'description' => 'Information about the resources exposed in this endpoint.', |
---|
58 | 'type' => 'text', |
---|
59 | 'size' => 'big', |
---|
60 | 'not null' => TRUE, |
---|
61 | 'serialize' => TRUE, |
---|
62 | 'object default' => array(), |
---|
63 | ), |
---|
64 | 'debug' => array( |
---|
65 | 'description' => 'Set the endpoint in debug mode.', |
---|
66 | 'type' => 'int', |
---|
67 | 'length' => 2, |
---|
68 | 'not null' => TRUE, |
---|
69 | 'default' => 0 |
---|
70 | ), |
---|
71 | ), |
---|
72 | 'primary key' => array('eid'), |
---|
73 | 'unique keys' => array( |
---|
74 | 'name' => array('name'), |
---|
75 | ), |
---|
76 | 'export' => array( |
---|
77 | 'key' => 'name', |
---|
78 | 'identifier' => 'endpoint', |
---|
79 | 'primary key' => 'name', |
---|
80 | 'api' => array( |
---|
81 | 'owner' => 'services', |
---|
82 | 'api' => 'services', |
---|
83 | 'minimum_version' => 3, |
---|
84 | 'current_version' => 3, |
---|
85 | ), |
---|
86 | ), |
---|
87 | ); |
---|
88 | |
---|
89 | return $schema; |
---|
90 | } |
---|
91 | /** |
---|
92 | * Implements hook_requirements(). |
---|
93 | */ |
---|
94 | function services_requirements($phase) { |
---|
95 | $requirements = array(); |
---|
96 | $t = get_t(); |
---|
97 | // Warn users of the possible threat. |
---|
98 | if ($phase == 'runtime') { |
---|
99 | // If rest_server is enabled, make sure it's from Services core. |
---|
100 | if (module_exists('rest_server')) { |
---|
101 | $rest_path = drupal_get_path('module', 'rest_server'); |
---|
102 | $core_path = drupal_get_path('module', 'services'). '/servers/rest_server'; |
---|
103 | if ($rest_path !== $core_path) { |
---|
104 | $requirements['services_rest_server_compatibility'] = array( |
---|
105 | 'description' => $t('The enabled version of Rest Server is not from Services core. Uninstall then remove the old Rest Server module from'). ' '. $rest_path. ' '. t('to utilize Services core Rest Server'), |
---|
106 | 'severity' => REQUIREMENT_ERROR, |
---|
107 | 'title' => 'Services Rest Server Compatibility', |
---|
108 | ); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | //Pull endpoints that do not have services authentication enabled |
---|
113 | $result = db_query("SELECT * FROM {services_endpoint} AS se WHERE se.authentication NOT LIKE '%s'", '%services%'); |
---|
114 | $items = array(); |
---|
115 | $has_endpoint = FALSE; |
---|
116 | while ($endpoint = db_fetch_object($result)) { |
---|
117 | $has_endpoint = TRUE; |
---|
118 | $items[] = l($endpoint->name, 'admin/build/services/list/'. $endpoint->name); |
---|
119 | } |
---|
120 | // theme the endpoints list |
---|
121 | $endpoints = ''; |
---|
122 | if (!empty($items)) { |
---|
123 | $endpoints = theme('item_list', array('items' => $items)); |
---|
124 | } |
---|
125 | // Only display the list if we have at least one endpoint without services authentication. |
---|
126 | if (count($items)) { |
---|
127 | $requirements['services'] = array( |
---|
128 | 'description' => $t('Services authentication mechanism has not been enabled for the following endpoints. Requests to these endpoints will always be anonymous.'), |
---|
129 | 'severity' => REQUIREMENT_ERROR, |
---|
130 | 'value' => $endpoints, |
---|
131 | 'title' => 'Services Authentication Mechanism', |
---|
132 | ); |
---|
133 | } |
---|
134 | else { |
---|
135 | $requirements['services'] = array( |
---|
136 | 'severity' => REQUIREMENT_OK, |
---|
137 | 'value' => 'Enabled for all Endpoints', |
---|
138 | 'title' => 'Services Authentication Mechanism', |
---|
139 | ); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | return $requirements; |
---|
144 | } |
---|
145 | /** |
---|
146 | * Implementation of hook_install(). |
---|
147 | */ |
---|
148 | function services_install() { |
---|
149 | drupal_install_schema('services'); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Implementation of hook_uninstall(). |
---|
154 | */ |
---|
155 | function services_uninstall() { |
---|
156 | drupal_uninstall_schema('services'); |
---|
157 | $ret = array(); |
---|
158 | |
---|
159 | // Drop legacy tables |
---|
160 | $legacy_tables = array('services_keys', 'services_timestamp_nonce'); |
---|
161 | foreach ($legacy_tables as $table) { |
---|
162 | if (db_table_exists($table)) { |
---|
163 | db_drop_table($ret, $table); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | variable_del('services_use_key'); |
---|
168 | variable_del('services_use_sessid'); |
---|
169 | variable_del('services_auth_module'); |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * Implementation of hook_update(). |
---|
174 | * |
---|
175 | * Create the nonce table |
---|
176 | */ |
---|
177 | function services_update_6001() { |
---|
178 | $schema['services_timestamp_nonce'] = array( |
---|
179 | 'description' => 'Stores timestamp against nonce for repeat attacks.', |
---|
180 | 'fields' => array( |
---|
181 | 'timestamp' => array( |
---|
182 | 'description' => 'The timestamp used with the Nonce.', |
---|
183 | 'type' => 'varchar', |
---|
184 | 'length' => 32, |
---|
185 | 'not null' => TRUE, |
---|
186 | 'default' => '' |
---|
187 | ), |
---|
188 | 'nonce' => array( |
---|
189 | 'description' => 'The random string used on the request.', |
---|
190 | 'type' => 'varchar', |
---|
191 | 'length' => 32, |
---|
192 | 'not null' => TRUE, |
---|
193 | 'default' => '' |
---|
194 | ), |
---|
195 | 'domain' => array( |
---|
196 | 'description' => 'The domain that submitted the request.', |
---|
197 | 'type' => 'varchar', |
---|
198 | 'length' => 255, |
---|
199 | 'not null' => TRUE, |
---|
200 | 'default' => '' |
---|
201 | ), |
---|
202 | ), |
---|
203 | 'indexes' => array( |
---|
204 | 'timestamp' => array('timestamp'), |
---|
205 | ), |
---|
206 | 'primary key' => array('nonce'), |
---|
207 | ); |
---|
208 | $update = array(); |
---|
209 | db_create_table($update, 'services_timestamp_nonce', $schema['services_timestamp_nonce']); |
---|
210 | return $update; |
---|
211 | } |
---|
212 | |
---|
213 | function services_update_6002() { |
---|
214 | $ret = array(); |
---|
215 | menu_rebuild(); |
---|
216 | return $ret; |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Update 6300 adds the concept of endpoints which is a way to expose a |
---|
221 | * specific server using a specific authentication method, with the full set |
---|
222 | * or a subset of the installed services. |
---|
223 | * |
---|
224 | * This is a major change from the way services worked before: then all |
---|
225 | * installed servers exposed all installed services and only one |
---|
226 | * authentication method could be used for all servers. The endpoint was also |
---|
227 | * non-configurable and was always 'services/[server path]'. |
---|
228 | * |
---|
229 | * As with most major changes, this is a _breaking_ update, in the sense that |
---|
230 | * you will need to reconfigure services. If you have clients that expect the |
---|
231 | * endpoint to remain the same you can easily set up a endpoint that exposes |
---|
232 | * your server/authentication method/services set on the old |
---|
233 | * 'services/[server path]' path. |
---|
234 | */ |
---|
235 | function services_update_6300() { |
---|
236 | $ret = array(); |
---|
237 | |
---|
238 | db_create_table($ret, 'services_endpoint', array( |
---|
239 | 'description' => 'Stores endpoint information for services', |
---|
240 | 'export' => array( |
---|
241 | 'identifier' => 'endpoint', |
---|
242 | 'export callback' => 'services_endpoint_export', |
---|
243 | 'list callback' => 'services_endpoint_list', |
---|
244 | ), |
---|
245 | 'fields' => array( |
---|
246 | 'eid' => array( |
---|
247 | 'type' => 'serial', |
---|
248 | 'description' => 'Primary ID field for the table. Not used for anything except internal lookups.', |
---|
249 | 'unsigned' => TRUE, |
---|
250 | 'not null' => TRUE, |
---|
251 | 'no export' => TRUE, |
---|
252 | ), |
---|
253 | 'name' => array( |
---|
254 | 'description' => 'The name of the endpoint.', |
---|
255 | 'type' => 'varchar', |
---|
256 | 'length' => 255, |
---|
257 | 'not null' => TRUE, |
---|
258 | ), |
---|
259 | 'title' => array( |
---|
260 | 'description' => 'The title of the endpoint.', |
---|
261 | 'type' => 'varchar', |
---|
262 | 'length' => 255, |
---|
263 | 'not null' => TRUE, |
---|
264 | ), |
---|
265 | 'server' => array( |
---|
266 | 'description' => 'The name of the server used in this endpoint.', |
---|
267 | 'type' => 'varchar', |
---|
268 | 'length' => 32, |
---|
269 | 'not null' => TRUE, |
---|
270 | ), |
---|
271 | 'path' => array( |
---|
272 | 'description' => 'The path to the endpoint for this server.', |
---|
273 | 'type' => 'varchar', |
---|
274 | 'length' => 255, |
---|
275 | 'not null' => TRUE, |
---|
276 | ), |
---|
277 | 'authentication' => array( |
---|
278 | 'description' => 'The authentication modules used in this endpoint.', |
---|
279 | 'type' => 'text', |
---|
280 | 'size' => 'big', |
---|
281 | 'not null' => TRUE, |
---|
282 | 'serialize' => TRUE, |
---|
283 | 'object default' => array(), |
---|
284 | ), |
---|
285 | 'resources' => array( |
---|
286 | 'description' => 'Information about the resources exposed in this endpoint.', |
---|
287 | 'type' => 'text', |
---|
288 | 'size' => 'big', |
---|
289 | 'not null' => TRUE, |
---|
290 | 'serialize' => TRUE, |
---|
291 | 'object default' => array(), |
---|
292 | ), |
---|
293 | ), |
---|
294 | 'primary key' => array('eid'), |
---|
295 | 'unique keys' => array( |
---|
296 | 'name' => array('name'), |
---|
297 | ), |
---|
298 | )); |
---|
299 | |
---|
300 | // Remove the auth_module variable as this won't be handled on a global basis anymore |
---|
301 | variable_del('services_auth_module'); |
---|
302 | |
---|
303 | return $ret; |
---|
304 | } |
---|
305 | |
---|
306 | /** |
---|
307 | * Update 6301 adds debugging to each endopint to facilitate easier development |
---|
308 | */ |
---|
309 | function services_update_6301() { |
---|
310 | $ret = array(); |
---|
311 | db_add_field($ret, 'services_endpoint', 'debug', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); |
---|
312 | db_add_field($ret, 'services_endpoint', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 1)); |
---|
313 | return $ret; |
---|
314 | } |
---|
315 | |
---|
316 | function services_update_6302() { |
---|
317 | $ret = array(); |
---|
318 | db_drop_field($ret, 'services_endpoint', 'status'); |
---|
319 | return $ret; |
---|
320 | } |
---|
321 | |
---|
322 | /** |
---|
323 | * Update 6303 adds the possibility to configure server settings on a per-endpoint basis. |
---|
324 | * and sets upgrades all new servers to have at least services session enabled. |
---|
325 | */ |
---|
326 | function services_update_6303() { |
---|
327 | $ret = array(); |
---|
328 | // Add the new server settings field. |
---|
329 | $new_field = array( |
---|
330 | 'description' => 'The server settings for the endpoint.', |
---|
331 | 'type' => 'blob', |
---|
332 | 'size' => 'big', |
---|
333 | 'not null' => TRUE, |
---|
334 | 'serialize' => TRUE |
---|
335 | ); |
---|
336 | db_add_field($ret, 'services_endpoint', 'server_settings', $new_field); |
---|
337 | return $ret; |
---|
338 | } |
---|
339 | /** |
---|
340 | * Update 6304 removes title functionality as it is no longer used. |
---|
341 | */ |
---|
342 | function services_update_6304() { |
---|
343 | $ret = array(); |
---|
344 | db_drop_field($ret, 'services_endpoint', 'title'); |
---|
345 | return $ret; |
---|
346 | } |
---|