source: admin/WebConsole/includes/restfunctions.php

lgromero-new-oglive
Last change on this file was ee47fac, checked in by Natalia Serrano <natalia.serrano@…>, 16 months ago

Fix permissions of certificate files, refs #134

  • Property mode set to 100644
File size: 17.0 KB
Line 
1
2<?php
3
4include_once (__DIR__ . '/../../etc/php-vars.php');
5
6define('GET', 1);
7define('POST', 2);
8define('CUSTOM', 3);
9
10define('OG_REST_CMD_CLIENTS', 'clients');
11define('OG_REST_CMD_WOL', 'wol');
12define('OG_REST_CMD_SESSION', 'session');
13define('OG_REST_CMD_RUN', 'shell/run');
14define('OG_REST_CMD_OUTPUT', 'shell/output');
15define('OG_REST_CMD_POWEROFF', 'poweroff');
16define('OG_REST_CMD_REBOOT', 'reboot');
17define('OG_REST_CMD_STOP', 'stop');
18define('OG_REST_CMD_REFRESH', 'refresh');
19define('OG_REST_CMD_HARDWARE', 'hardware');
20define('OG_REST_CMD_SOFTWARE', 'software');
21define('OG_REST_CMD_CREATE_IMAGE', 'image/create');
22define('OG_REST_CMD_RESTORE_IMAGE', 'image/restore');
23define('OG_REST_CMD_SETUP', 'setup');
24define('OG_REST_CMD_CREATE_BASIC_IMAGE', 'image/create/basic');
25define('OG_REST_CMD_CREATE_INCREMENTAL_IMAGE', 'image/create/incremental');
26define('OG_REST_CMD_RESTORE_BASIC_IMAGE', 'image/restore/basic');
27define('OG_REST_CMD_RESTORE_INCREMENTAL_IMAGE', 'image/restore/incremental');
28define('OG_REST_CMD_RUN_SCHEDULE', 'run/schedule');
29
30define('OG_REST_PARAM_CLIENTS', 'clients');
31define('OG_REST_PARAM_ADDR', 'addr');
32define('OG_REST_PARAM_MAC', 'mac');
33define('OG_REST_PARAM_DISK', 'disk');
34define('OG_REST_PARAM_PART', 'partition');
35define('OG_REST_PARAM_RUN', 'run');
36define('OG_REST_PARAM_TYPE', 'type');
37define('OG_REST_PARAM_STATE', 'state');
38define('OG_REST_PARAM_NAME', 'name');
39define('OG_REST_PARAM_REPOS', 'repository');
40define('OG_REST_PARAM_ID', 'id');
41define('OG_REST_PARAM_CODE', 'code');
42define('OG_REST_PARAM_PROFILE', 'profile');
43define('OG_REST_PARAM_CACHE', 'cache');
44define('OG_REST_PARAM_CACHE_SIZE', 'cache_size');
45define('OG_REST_PARAM_FILE_SYSTEM', 'filesystem');
46define('OG_REST_PARAM_SIZE', 'size');
47define('OG_REST_PARAM_FORMAT', 'format');
48define('OG_REST_PARAM_PARTITION_SETUP', 'partition_setup');
49define('OG_REST_PARAM_SYNC_PARAMS', 'sync_params');
50define('OG_REST_PARAM_SYNC', 'sync');
51define('OG_REST_PARAM_DIFF', 'diff');
52define('OG_REST_PARAM_REMOVE', 'remove');
53define('OG_REST_PARAM_COMPRESS', 'compress');
54define('OG_REST_PARAM_CLEANUP', 'cleanup');
55define('OG_REST_PARAM_CLEANUP_CACHE', 'cleanup_cache');
56define('OG_REST_PARAM_REMOVE_DST', 'remove_dst');
57define('OG_REST_PARAM_PATH', 'path');
58define('OG_REST_PARAM_DIFF_ID', 'diff_id');
59define('OG_REST_PARAM_DIFF_NAME', 'diff_name');
60define('OG_REST_PARAM_METHOD', 'method');
61define('OG_REST_PARAM_ECHO', 'echo');
62
63$conf_file = parse_ini_file(__DIR__ . '/../../etc/ogAdmServer.cfg');
64define('OG_REST_API_TOKEN', 'Authorization: ' . $conf_file['APITOKEN']);
65
66function common_request($command, $type, $data = null) {
67
68        $json = json_encode($data);
69
70        $service_url = OG_REST_URL.$command;
71
72        $curl = curl_init($service_url);
73        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
74        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
75                OG_REST_API_TOKEN,
76        ));
77        curl_setopt ($curl, CURLOPT_SSLCERT, __DIR__ . '/../../etc/ssl/WebConsole.crt.pem');
78        curl_setopt ($curl, CURLOPT_SSLKEY,  __DIR__ . '/../../etc/ssl/WebConsole.key.pem');
79
80        switch ($type) {
81                default:
82                case GET:
83                        break;
84                case POST:
85                        curl_setopt($curl, CURLOPT_POST, true);
86                        curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
87        }
88
89        $curl_response = curl_exec($curl);
90        $info = curl_getinfo($curl);
91        $error = curl_error ($curl);
92
93        if ($curl_response === false || $info['http_code'] != 200) {
94                syslog(LOG_ERR, 'error occured during curl exec. Additional info: ' . $error . "\n" . print_r($info, TRUE));
95                return 0;
96        }
97
98        curl_close($curl);
99
100        syslog(LOG_INFO, 'response '.$command.' ok!');
101
102        return json_decode($curl_response, true);
103}
104
105
106function shell($case, $string_ips, $command) {
107
108        $ips = explode(';',$string_ips);
109
110        switch ($case) {
111                case 3:
112                        $command = substr($command, 4);
113                        $data = array(OG_REST_PARAM_CLIENTS => $ips,
114                                      OG_REST_PARAM_RUN => $command,
115                                      OG_REST_PARAM_ECHO => false);
116                        $command = OG_REST_CMD_RUN;
117                        break;
118                case 1:
119                        $data = array(OG_REST_PARAM_CLIENTS => $ips,
120                                      OG_REST_PARAM_RUN => $command,
121                                      OG_REST_PARAM_ECHO => true);
122                        $command = OG_REST_CMD_RUN;
123                        break;
124                default:
125                case 2:
126                        $data = array(OG_REST_PARAM_CLIENTS => $ips);
127                        $command = OG_REST_CMD_OUTPUT;
128        }
129
130        $result = common_request($command, POST,
131                $data)[OG_REST_PARAM_CLIENTS][0]['output'];
132
133        return (is_null($result) ? '1' : $result);
134}
135
136function clients($case, $ips) {
137
138        switch ($case) {
139                case 1:
140                        $type = POST;
141                        $data = array(OG_REST_PARAM_CLIENTS => $ips);
142                        break;
143                case 2:
144                        $type = GET;
145                        $data = null;
146                        break;
147        }
148
149        $result = common_request(OG_REST_CMD_CLIENTS, $type, $data);
150
151        $trama_notificacion = "";
152        if (isset($result[OG_REST_PARAM_CLIENTS])) {
153                foreach ($result[OG_REST_PARAM_CLIENTS] as $client) {
154                        $trama_notificacion .= $client[OG_REST_PARAM_ADDR].'/'.
155                                $client[OG_REST_PARAM_STATE].';';
156                }
157        }
158
159        return $trama_notificacion;
160}
161
162function wol($type_wol, $macs, $ips) {
163
164        switch ($type_wol) {
165                default:
166                case 1:
167                        $wol = 'broadcast';
168                        break;
169                case 2:
170                        $wol = 'unicast';
171        }
172
173        $clients = array();
174
175        for($i=0; $i<count($macs); $i++) {
176                $clients[] = array(OG_REST_PARAM_ADDR => $ips[$i],
177                        OG_REST_PARAM_MAC => $macs[$i]);
178        }
179
180        $data = array(OG_REST_PARAM_TYPE => $wol,
181                OG_REST_PARAM_CLIENTS => $clients);
182
183        common_request(OG_REST_CMD_WOL, POST, $data);
184}
185
186function session($string_ips, $params) {
187
188        preg_match_all('!\d{1}!', $params, $matches);
189
190        $ips = explode(';',$string_ips);
191        $disk = $matches[0][0];
192        $part = $matches[0][1];
193
194        $data = array(OG_REST_PARAM_CLIENTS => $ips,
195                OG_REST_PARAM_DISK => $disk, OG_REST_PARAM_PART => $part);
196
197        common_request(OG_REST_CMD_SESSION, POST, $data);
198}
199
200function create_image($string_ips, $params) {
201
202        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
203
204        $ips = explode(';',$string_ips);
205        $disk = $matches[0][0];
206        $part = $matches[0][1];
207        $code = $matches[0][2];
208        $id = $matches[0][3];
209        $name = $matches[0][4];
210        $repos = $matches[0][5];
211
212        $data = array(OG_REST_PARAM_CLIENTS => $ips,
213                OG_REST_PARAM_DISK => $disk,
214                OG_REST_PARAM_PART => $part,
215                OG_REST_PARAM_CODE => $code,
216                OG_REST_PARAM_ID => $id,
217                OG_REST_PARAM_NAME => $name,
218                OG_REST_PARAM_REPOS => $repos);
219
220        common_request(OG_REST_CMD_CREATE_IMAGE, POST, $data);
221}
222
223function restore_image($string_ips, $params) {
224
225        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
226
227        $ips = explode(';',$string_ips);
228        $disk = $matches[0][0];
229        $part = $matches[0][1];
230        $image_id = $matches[0][2];
231        $name = $matches[0][3];
232        $repos = $matches[0][4];
233        $profile = $matches[0][5];
234        $type = $matches[0][6];
235
236        $data = array(OG_REST_PARAM_DISK => $disk, OG_REST_PARAM_PART => $part,
237                OG_REST_PARAM_ID => $image_id, OG_REST_PARAM_NAME => $name,
238                OG_REST_PARAM_REPOS => $repos,
239                OG_REST_PARAM_PROFILE => $profile,
240                OG_REST_PARAM_TYPE => $type,
241                OG_REST_PARAM_CLIENTS => $ips);
242
243        common_request(OG_REST_CMD_RESTORE_IMAGE, POST, $data);
244}
245
246function create_basic_image($string_ips, $params) {
247
248        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
249
250        $ips = explode(';',$string_ips);
251        $disk = $matches[0][0];
252        $part = $matches[0][1];
253        $code = $matches[0][2];
254        $image_id = $matches[0][3];
255        $name = $matches[0][4];
256        $repos = $matches[0][5];
257
258        $sync = $matches[0][7]; // Syncronization method
259
260        $diff = $matches[0][8]; // Send the whole file if there are differences
261        $remove = $matches[0][9]; // Delete files at destination that are not at source
262        $compress = $matches[0][10]; // Compress before sending
263
264        $cleanup = $matches[0][11]; // Delete image before creating it
265        $cache = $matches[0][12]; // Copy image to cache
266        $cleanup_cache = $matches[0][13]; // Delete image from cache before copying
267        $remove_dst = $matches[0][14]; // Dont delete files in destination
268
269        $data = array(OG_REST_PARAM_CLIENTS => $ips,
270                OG_REST_PARAM_DISK => $disk,
271                OG_REST_PARAM_PART => $part,
272                OG_REST_PARAM_CODE => $code,
273                OG_REST_PARAM_ID => $image_id,
274                OG_REST_PARAM_NAME => $name,
275                OG_REST_PARAM_REPOS => $repos,
276                OG_REST_PARAM_SYNC_PARAMS => array(
277                        OG_REST_PARAM_SYNC => $sync,
278                        OG_REST_PARAM_DIFF => $diff,
279                        OG_REST_PARAM_REMOVE => $remove,
280                        OG_REST_PARAM_COMPRESS => $compress,
281                        OG_REST_PARAM_CLEANUP => $cleanup,
282                        OG_REST_PARAM_CACHE => $cache,
283                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
284                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
285                )
286        );
287
288        common_request(OG_REST_CMD_CREATE_BASIC_IMAGE, POST, $data);
289}
290
291function create_incremental_image($string_ips, $params) {
292
293        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
294
295        $ips = explode(';',$string_ips);
296        $disk = $matches[0][0];
297        $part = $matches[0][1];
298        $id = $matches[0][2];
299        $name = $matches[0][3];
300        $repos = $matches[0][4];
301        $diff_id = $matches[0][5];
302        $diff_name = $matches[0][6];
303        $path = $matches[0][7];
304        $sync = $matches[0][8];
305        $diff = $matches[0][9];
306        $remove = $matches[0][10];
307        $compress = $matches[0][11];
308        $cleanup = $matches[0][12];
309        $cache = $matches[0][13];
310        $cleanup_cache = $matches[0][14];
311        $remove_dst = $matches[0][15];
312
313        $data = array(OG_REST_PARAM_CLIENTS => $ips,
314                OG_REST_PARAM_DISK => $disk,
315                OG_REST_PARAM_PART => $part,
316                OG_REST_PARAM_ID => $id,
317                OG_REST_PARAM_NAME => $name,
318                OG_REST_PARAM_REPOS => $repos,
319                OG_REST_PARAM_SYNC_PARAMS => array(
320                        OG_REST_PARAM_SYNC => $sync,
321                        OG_REST_PARAM_PATH => $path,
322                        OG_REST_PARAM_DIFF => $diff,
323                        OG_REST_PARAM_DIFF_ID => $diff_id,
324                        OG_REST_PARAM_DIFF_NAME => $diff_name,
325                        OG_REST_PARAM_REMOVE => $remove,
326                        OG_REST_PARAM_COMPRESS => $compress,
327                        OG_REST_PARAM_CLEANUP => $cleanup,
328                        OG_REST_PARAM_CACHE => $cache,
329                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
330                        OG_REST_PARAM_REMOVE_DST => $remove_dst)
331        );
332
333        common_request(OG_REST_CMD_CREATE_INCREMENTAL_IMAGE, POST, $data);
334}
335
336function restore_basic_image($string_ips, $params) {
337
338        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
339
340        $ips = explode(';',$string_ips);
341        $disk = $matches[0][0];
342        $part = $matches[0][1];
343        $image_id = $matches[0][2];
344        $name = $matches[0][3];
345        $repos = $matches[0][4];
346        $profile = $matches[0][5];
347
348        $path = $matches[0][6];
349        $method = $matches[0][7];
350        $sync = $matches[0][8]; // Syncronization method
351
352        $type = $matches[0][9];
353
354        $diff = $matches[0][10]; // Send the whole file if there are differences
355        $remove = $matches[0][11]; // Delete files at destination that are not at source
356        $compress = $matches[0][12]; // Compress before sending
357
358        $cleanup = $matches[0][13]; // Delete image before creating it
359        $cache = $matches[0][14]; // Copy image to cache
360        $cleanup_cache = $matches[0][15]; // Delete image from cache before copying
361        $remove_dst = $matches[0][16]; // Dont delete files in destination
362
363        $data = array(OG_REST_PARAM_CLIENTS => $ips,
364                OG_REST_PARAM_DISK => $disk,
365                OG_REST_PARAM_PART => $part,
366                OG_REST_PARAM_ID => $image_id,
367                OG_REST_PARAM_NAME => $name,
368                OG_REST_PARAM_REPOS => $repos,
369                OG_REST_PARAM_PROFILE => $profile,
370                OG_REST_PARAM_TYPE => $type,
371                OG_REST_PARAM_SYNC_PARAMS => array(
372                        OG_REST_PARAM_PATH => $path,
373                        OG_REST_PARAM_METHOD => $method,
374                        OG_REST_PARAM_SYNC => $sync,
375                        OG_REST_PARAM_DIFF => $diff,
376                        OG_REST_PARAM_REMOVE => $remove,
377                        OG_REST_PARAM_COMPRESS => $compress,
378                        OG_REST_PARAM_CLEANUP => $cleanup,
379                        OG_REST_PARAM_CACHE => $cache,
380                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
381                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
382                )
383        );
384
385        common_request(OG_REST_CMD_RESTORE_BASIC_IMAGE, POST, $data);
386}
387
388function restore_incremental_image($string_ips, $params) {
389
390        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
391
392        $ips = explode(';',$string_ips);
393        $disk = $matches[0][0];
394        $part = $matches[0][1];
395        $image_id = $matches[0][2];
396        $name = $matches[0][3];
397        $repos = $matches[0][4];
398        $profile = $matches[0][5];
399        $diff_id = $matches[0][6];
400        $diff_name = $matches[0][7];
401        $path = $matches[0][8];
402        $method = $matches[0][9];
403        $sync = $matches[0][10];
404        $type = $matches[0][11];
405        $diff = $matches[0][12];
406        $remove = $matches[0][13];
407        $compress = $matches[0][14];
408        $cleanup = $matches[0][15];
409        $cache = $matches[0][16];
410        $cleanup_cache = $matches[0][17];
411        $remove_dst = $matches[0][18];
412
413        $data = array(OG_REST_PARAM_CLIENTS => $ips,
414                OG_REST_PARAM_DISK => $disk,
415                OG_REST_PARAM_PART => $part,
416                OG_REST_PARAM_ID => $image_id,
417                OG_REST_PARAM_NAME => $name,
418                OG_REST_PARAM_REPOS => $repos,
419                OG_REST_PARAM_PROFILE => $profile,
420                OG_REST_PARAM_TYPE => $type,
421                OG_REST_PARAM_SYNC_PARAMS => array(
422                        OG_REST_PARAM_DIFF_ID => $diff_id,
423                        OG_REST_PARAM_DIFF_NAME => $diff_name,
424                        OG_REST_PARAM_PATH => $path,
425                        OG_REST_PARAM_METHOD => $method,
426                        OG_REST_PARAM_SYNC => $sync,
427                        OG_REST_PARAM_DIFF => $diff,
428                        OG_REST_PARAM_REMOVE => $remove,
429                        OG_REST_PARAM_COMPRESS => $compress,
430                        OG_REST_PARAM_CLEANUP => $cleanup,
431                        OG_REST_PARAM_CACHE => $cache,
432                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
433                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
434                )
435        );
436
437        common_request(OG_REST_CMD_RESTORE_INCREMENTAL_IMAGE, POST, $data);
438}
439
440function poweroff($string_ips) {
441
442        $ips = explode(';',$string_ips);
443
444        $data = array(OG_REST_PARAM_CLIENTS => $ips);
445
446        common_request(OG_REST_CMD_POWEROFF, POST, $data);
447}
448
449function reboot($string_ips) {
450
451        $ips = explode(';',$string_ips);
452
453        $data = array(OG_REST_PARAM_CLIENTS => $ips);
454
455        common_request(OG_REST_CMD_REBOOT, POST, $data);
456}
457
458function stop($string_ips) {
459
460        $ips = explode(';',$string_ips);
461
462        $data = array(OG_REST_PARAM_CLIENTS => $ips);
463
464        common_request(OG_REST_CMD_STOP, POST, $data);
465}
466
467function refresh($string_ips) {
468
469        $ips = explode(';',$string_ips);
470
471        $data = array(OG_REST_PARAM_CLIENTS => $ips);
472
473        common_request(OG_REST_CMD_REFRESH, POST, $data);
474}
475
476function hardware($string_ips) {
477
478        $ips = explode(';',$string_ips);
479
480        $data = array(OG_REST_PARAM_CLIENTS => $ips);
481
482        common_request(OG_REST_CMD_HARDWARE, POST, $data);
483}
484
485function software($string_ips, $params) {
486
487        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
488
489        $ips = explode(';',$string_ips);
490        $disk = $matches[0][0];
491        $part = $matches[0][1];
492
493        $data = array(OG_REST_PARAM_CLIENTS => $ips,
494                OG_REST_PARAM_DISK => $disk,
495                OG_REST_PARAM_PART => $part);
496
497        common_request(OG_REST_CMD_SOFTWARE, POST, $data);
498}
499
500function setup($string_ips, $params) {
501
502        preg_match_all('/(?<=\=)(?!dis)(.*?)((?=\*)|(?=\r)|(?=\!)|(?=\%))/',
503                $params, $matches);
504
505        $ips = explode(';',$string_ips);
506        $disk = $matches[0][0];
507        $cache = $matches[0][2];
508        $cache_size = $matches[0][3];
509        $partition_number = array();
510        $partition_code = array();
511        $file_system = array();
512        $part_size = array();
513        $format = array();
514        for ($x = 0; $x < 4; $x++) {
515                $partition_number[$x] = $matches[0][4 + 5 * $x];
516                $partition_code[$x] = $matches[0][5 + 5 * $x];
517                $file_system[$x] = $matches[0][6 + 5 * $x];
518                $part_size[$x] = $matches[0][7 + 5 * $x];
519                $format[$x] = $matches[0][8 + 5 * $x];
520        }
521
522        $data = array(
523                OG_REST_PARAM_CLIENTS => $ips,
524                OG_REST_PARAM_DISK => $disk,
525                OG_REST_PARAM_CACHE => $cache,
526                OG_REST_PARAM_CACHE_SIZE => $cache_size,
527                OG_REST_PARAM_PARTITION_SETUP => array()
528        );
529
530        for ($i = 0; $i < sizeof($partition_number); $i++) {
531                $partition_setup = array(
532                        OG_REST_PARAM_PART => $partition_number[$i],
533                        OG_REST_PARAM_CODE => $partition_code[$i],
534                        OG_REST_PARAM_FILE_SYSTEM => $file_system[$i],
535                        OG_REST_PARAM_SIZE => $part_size[$i],
536                        OG_REST_PARAM_FORMAT => $format[$i]
537                );
538                array_push($data[OG_REST_PARAM_PARTITION_SETUP], $partition_setup);
539        }
540
541        common_request(OG_REST_CMD_SETUP, POST, $data);
542}
543
544function run_schedule($string_ips) {
545        $ips = explode(';',$string_ips);
546        $data = array(OG_REST_PARAM_CLIENTS => $ips);
547        common_request(OG_REST_CMD_RUN_SCHEDULE, POST, $data);
548}
549
550/*
551 * @function multiRequest.
552 * @param    URLs array (may include header and POST data), cURL options array.
553 * @return   Array of arrays with JSON requests and response codes.
554 * @warning  Default options: does not verifying certificate, connection timeout 200 ms.
555 * @Date     2015-10-14
556 */
557function multiRequest($data, $options=array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT_MS => 500)) {
558 
559  // array of curl handles
560  $curly = array();
561  // Data to be returned (response data and code)
562  $result = array();
563 
564  // multi handle
565  $mh = curl_multi_init();
566 
567  // loop through $data and create curl handles
568  // then add them to the multi-handle
569  foreach ($data as $id => $d) {
570 
571
572    $curly[$id] = curl_init();
573 
574    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
575    curl_setopt($curly[$id], CURLOPT_URL, $url);
576    // HTTP headers?
577    if (is_array($d) && !empty($d['header'])) {
578       curl_setopt($curly[$id], CURLOPT_HTTPHEADER, $d['header']);
579    } else {
580       curl_setopt($curly[$id], CURLOPT_HEADER, 0);
581    }
582    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
583 
584    // post?
585    if (is_array($d)) {
586      if (!empty($d['post'])) {
587        curl_setopt($curly[$id], CURLOPT_POST, 1);
588        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
589      }
590    }
591
592    // extra options?
593    if (!empty($options)) {
594      curl_setopt_array($curly[$id], $options);
595    }
596 
597    curl_multi_add_handle($mh, $curly[$id]);
598  }
599 
600  // execute the handles
601  $running = null;
602  do {
603    curl_multi_exec($mh, $running);
604  } while($running > 0);
605 
606 
607  // Get content and HTTP code, and remove handles
608  foreach($curly as $id => $c) {
609    $result[$id]['data'] = curl_multi_getcontent($c);
610    $result[$id]['code'] = curl_getinfo($c, CURLINFO_HTTP_CODE);
611    curl_multi_remove_handle($mh, $c);
612  }
613
614 // all done
615  curl_multi_close($mh);
616 
617  return $result;
618}
619
Note: See TracBrowser for help on using the repository browser.