Completed
Push — master ( af0580...b1b084 )
by Ghazi
18:31
created

BigBlueButton::getMeetings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
namespace BigBlueButton;
20
21
use BigBlueButton\Core\ApiMethod;
22
use BigBlueButton\Parameters\CreateMeetingParameters;
23
use BigBlueButton\Parameters\DeleteRecordingsParameters;
24
use BigBlueButton\Parameters\EndMeetingParameters;
25
use BigBlueButton\Parameters\GetMeetingInfoParameters;
26
use BigBlueButton\Parameters\GetRecordingsParameters;
27
use BigBlueButton\Parameters\IsMeetingRunningParameters;
28
use BigBlueButton\Parameters\JoinMeetingParameters;
29
use BigBlueButton\Parameters\PublishRecordingsParameters;
30
use BigBlueButton\Parameters\UpdateRecordingsParameters;
31
use BigBlueButton\Responses\ApiVersionResponse;
32
use BigBlueButton\Responses\CreateMeetingResponse;
33
use BigBlueButton\Responses\DeleteRecordingsResponse;
34
use BigBlueButton\Responses\EndMeetingResponse;
35
use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
36
use BigBlueButton\Responses\GetMeetingInfoResponse;
37
use BigBlueButton\Responses\GetMeetingsResponse;
38
use BigBlueButton\Responses\GetRecordingsResponse;
39
use BigBlueButton\Responses\IsMeetingRunningResponse;
40
use BigBlueButton\Responses\JoinMeetingResponse;
41
use BigBlueButton\Responses\PublishRecordingsResponse;
42
use BigBlueButton\Responses\SetConfigXMLResponse;
43
use BigBlueButton\Responses\UpdateRecordingsResponse;
44
use BigBlueButton\Util\UrlBuilder;
45
use SimpleXMLElement;
46
47
/**
48
 * Class BigBlueButton
49
 * @package BigBlueButton
50
 */
51
class BigBlueButton
52
{
53
    protected $securitySecret;
54
    protected $bbbServerBaseUrl;
55
    protected $urlBuilder;
56
57
    public function __construct()
58
    {
59
        // Keeping backward compatibility with older deployed versions
60
        $this->securitySecret   = (getenv('BBB_SECURITY_SALT') === false) ? getenv('BBB_SECRET') : $this->securitySecret   = getenv('BBB_SECURITY_SALT');
61
        $this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL');
62
        $this->urlBuilder       = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl);
63
    }
64
65
    /**
66
     * @return ApiVersionResponse
67
     *
68
     * @throws \RuntimeException
69
     */
70
    public function getApiVersion()
71
    {
72
        $xml = $this->processXmlResponse($this->urlBuilder->buildUrl());
73
74
        return new ApiVersionResponse($xml);
75
    }
76
77
    /* __________________ BBB ADMINISTRATION METHODS _________________ */
78
    /* The methods in the following section support the following categories of the BBB API:
79
    -- create
80
    -- getDefaultConfigXML
81
    -- join
82
    -- end
83
    */
84
85
    /**
86
     * @param  CreateMeetingParameters $createMeetingParams
87
     * @return string
88
     */
89
    public function getCreateMeetingUrl($createMeetingParams)
90
    {
91
        return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
92
    }
93
94
    /**
95
     * @param  CreateMeetingParameters $createMeetingParams
96
     * @return CreateMeetingResponse
97
     * @throws \RuntimeException
98
     */
99
    public function createMeeting($createMeetingParams)
100
    {
101
        $xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
0 ignored issues
show
Security Bug introduced by
It seems like $createMeetingParams->getPresentationsAsXML() targeting BigBlueButton\Parameters...getPresentationsAsXML() can also be of type false; however, BigBlueButton\BigBlueButton::processXmlResponse() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
102
103
        return new CreateMeetingResponse($xml);
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getDefaultConfigXMLUrl()
110
    {
111
        return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML);
112
    }
113
114
    /**
115
     * @return GetDefaultConfigXMLResponse
116
     * @throws \RuntimeException
117
     */
118
    public function getDefaultConfigXML()
119
    {
120
        $xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl());
121
122
        return new GetDefaultConfigXMLResponse($xml);
123
    }
124
125
    /**
126
     * @return string
127
     */
128
    public function setConfigXMLUrl()
129
    {
130
        return $this->urlBuilder->buildUrl(ApiMethod::SET_CONFIG_XML, '', false);
131
    }
132
133
    /**
134
     * @param  $setConfigXMLParams
135
     * @return SetConfigXMLResponse
136
     * @throws \RuntimeException
137
     */
138
    public function setConfigXML($setConfigXMLParams)
139
    {
140
        $setConfigXMLPayload = $this->urlBuilder->buildQs(ApiMethod::SET_CONFIG_XML, $setConfigXMLParams->getHTTPQuery());
141
142
        $xml = $this->processXmlResponse($this->setConfigXMLUrl(), $setConfigXMLPayload, 'application/x-www-form-urlencoded');
143
144
        return new SetConfigXMLResponse($xml);
145
    }
146
147
    /**
148
     * @param $joinMeetingParams JoinMeetingParameters
149
     *
150
     * @return string
151
     */
152
    public function getJoinMeetingURL($joinMeetingParams)
153
    {
154
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
155
    }
156
157
    /**
158
     * @param $joinMeetingParams JoinMeetingParameters
159
     *
160
     * @return JoinMeetingResponse
161
     * @throws \RuntimeException
162
     */
163
    public function joinMeeting($joinMeetingParams)
164
    {
165
        $xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
166
167
        return new JoinMeetingResponse($xml);
168
    }
169
170
    /**
171
     * @param $endParams EndMeetingParameters
172
     *
173
     * @return string
174
     */
175
    public function getEndMeetingURL($endParams)
176
    {
177
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
178
    }
179
180
    /**
181
     * @param $endParams EndMeetingParameters
182
     *
183
     * @return EndMeetingResponse
184
     * @throws \RuntimeException
185
     * */
186
    public function endMeeting($endParams)
187
    {
188
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
189
190
        return new EndMeetingResponse($xml);
191
    }
192
193
    /* __________________ BBB MONITORING METHODS _________________ */
194
    /* The methods in the following section support the following categories of the BBB API:
195
    -- isMeetingRunning
196
    -- getMeetings
197
    -- getMeetingInfo
198
    */
199
200
    /**
201
     * @param $meetingParams IsMeetingRunningParameters
202
     * @return string
203
     */
204
    public function getIsMeetingRunningUrl($meetingParams)
205
    {
206
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
207
    }
208
209
    /**
210
     * @param $meetingParams
211
     * @return IsMeetingRunningResponse
212
     * @throws \RuntimeException
213
     */
214
    public function isMeetingRunning($meetingParams)
215
    {
216
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
217
218
        return new IsMeetingRunningResponse($xml);
219
    }
220
221
    /**
222
     * @return string
223
     */
224
    public function getMeetingsUrl()
225
    {
226
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
227
    }
228
229
    /**
230
     * @return GetMeetingsResponse
231
     * @throws \RuntimeException
232
     */
233
    public function getMeetings()
234
    {
235
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
236
237
        return new GetMeetingsResponse($xml);
238
    }
239
240
    /**
241
     * @param $meetingParams GetMeetingInfoParameters
242
     * @return string
243
     */
244
    public function getMeetingInfoUrl($meetingParams)
245
    {
246
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
247
    }
248
249
    /**
250
     * @param $meetingParams GetMeetingInfoParameters
251
     * @return GetMeetingInfoResponse
252
     * @throws \RuntimeException
253
     */
254
    public function getMeetingInfo($meetingParams)
255
    {
256
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
257
258
        return new GetMeetingInfoResponse($xml);
259
    }
260
261
    /* __________________ BBB RECORDING METHODS _________________ */
262
    /* The methods in the following section support the following categories of the BBB API:
263
    -- getRecordings
264
    -- publishRecordings
265
    -- deleteRecordings
266
    */
267
268
    /**
269
     * @param $recordingsParams GetRecordingsParameters
270
     * @return string
271
     */
272
    public function getRecordingsUrl($recordingsParams)
273
    {
274
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
275
    }
276
277
    /**
278
     * @param $recordingParams
279
     * @return GetRecordingsResponse
280
     * @throws \RuntimeException
281
     */
282
    public function getRecordings($recordingParams)
283
    {
284
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
285
286
        return new GetRecordingsResponse($xml);
287
    }
288
289
    /**
290
     * @param $recordingParams PublishRecordingsParameters
291
     * @return string
292
     */
293
    public function getPublishRecordingsUrl($recordingParams)
294
    {
295
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
296
    }
297
298
    /**
299
     * @param $recordingParams PublishRecordingsParameters
300
     * @return PublishRecordingsResponse
301
     * @throws \RuntimeException
302
     */
303
    public function publishRecordings($recordingParams)
304
    {
305
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
306
307
        return new PublishRecordingsResponse($xml);
308
    }
309
310
    /**
311
     * @param $recordingParams DeleteRecordingsParameters
312
     * @return string
313
     */
314
    public function getDeleteRecordingsUrl($recordingParams)
315
    {
316
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
317
    }
318
319
    /**
320
     * @param $recordingParams DeleteRecordingsParameters
321
     * @return DeleteRecordingsResponse
322
     * @throws \RuntimeException
323
     */
324
    public function deleteRecordings($recordingParams)
325
    {
326
        $xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
327
328
        return new DeleteRecordingsResponse($xml);
329
    }
330
331
    /**
332
     * @param $recordingParams UpdateRecordingsParameters
333
     * @return string
334
     */
335
    public function getUpdateRecordingsUrl($recordingParams)
336
    {
337
        return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
338
    }
339
340
    /**
341
     * @param $recordingParams UpdateRecordingsParameters
342
     * @return UpdateRecordingsResponse
343
     * @throws \RuntimeException
344
     */
345
    public function updateRecordings($recordingParams)
346
    {
347
        $xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
348
349
        return new UpdateRecordingsResponse($xml);
350
    }
351
352
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
353
354
    /**
355
     * A private utility method used by other public methods to process XML responses.
356
     *
357
     * @param  string            $url
358
     * @param  string            $payload
359
     * @param  string            $contentType
360
     * @return SimpleXMLElement
361
     * @throws \RuntimeException
362
     */
363
    private function processXmlResponse($url, $payload = '', $contentType = 'application/xml')
364
    {
365
        if (extension_loaded('curl')) {
366
            $ch = curl_init();
367
            if (!$ch) {
368
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
369
            }
370
            $timeout = 10;
371
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
372
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
373
            curl_setopt($ch, CURLOPT_URL, $url);
374
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
375
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
376
            if (!empty($payload)) {
377
                curl_setopt($ch, CURLOPT_HEADER, 0);
378
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
379
                curl_setopt($ch, CURLOPT_POST, 1);
380
                curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
381
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
382
                    'Content-type: ' . $contentType,
383
                    'Content-length: ' . mb_strlen($payload),
384
                ]);
385
            }
386
            $data = curl_exec($ch);
387
            if ($data === false) {
388
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
389
            }
390
            curl_close($ch);
391
392
            return new SimpleXMLElement($data);
393
        } else {
394
            throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');
395
        }
396
    }
397
}
398