Completed
Pull Request — master (#18)
by Jesus
02:13
created

BigBlueButton::setConfigXMLUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016 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\SetConfigXMLParameters;
31
use BigBlueButton\Parameters\UpdateRecordingsParameters;
32
use BigBlueButton\Responses\ApiVersionResponse;
33
use BigBlueButton\Responses\CreateMeetingResponse;
34
use BigBlueButton\Responses\DeleteRecordingsResponse;
35
use BigBlueButton\Responses\EndMeetingResponse;
36
use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
37
use BigBlueButton\Responses\GetMeetingInfoResponse;
38
use BigBlueButton\Responses\GetMeetingsResponse;
39
use BigBlueButton\Responses\GetRecordingsResponse;
40
use BigBlueButton\Responses\IsMeetingRunningResponse;
41
use BigBlueButton\Responses\JoinMeetingResponse;
42
use BigBlueButton\Responses\PublishRecordingsResponse;
43
use BigBlueButton\Responses\SetConfigXMLResponse;
44
use BigBlueButton\Responses\UpdateRecordingsResponse;
45
use BigBlueButton\Util\UrlBuilder;
46
use SimpleXMLElement;
47
48
/**
49
 * Class BigBlueButton
50
 * @package BigBlueButton
51
 */
52
class BigBlueButton
53
{
54
    private $securitySalt;
55
    private $bbbServerBaseUrl;
56
    private $urlBuilder;
57
58
    public function __construct()
59
    {
60
        $this->securitySalt     = getenv('BBB_SECURITY_SALT');
61
        $this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL');
62
        $this->urlBuilder       = new UrlBuilder($this->securitySalt, $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
     * @return SetConfigXMLResponse
135
     * @throws \RuntimeException
136
     */
137
    public function setConfigXML($setConfigXMLParams)
138
    {
139
        $setConfigXMLPayload = $this->urlBuilder->buildQs(ApiMethod::SET_CONFIG_XML, $setConfigXMLParams->getHTTPQuery());
140
141
        $xml = $this->processXmlResponse($this->setConfigXMLUrl(), $setConfigXMLPayload, 'application/x-www-form-urlencoded');
142
143
        return new SetConfigXMLResponse($xml);
144
    }
145
146
    /**
147
     * @param $joinMeetingParams JoinMeetingParameters
148
     *
149
     * @return string
150
     */
151
    public function getJoinMeetingURL($joinMeetingParams)
152
    {
153
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
154
    }
155
156
    /**
157
     * @param $joinMeetingParams JoinMeetingParameters
158
     *
159
     * @return JoinMeetingResponse
160
     * @throws \RuntimeException
161
     */
162
    public function joinMeeting($joinMeetingParams)
163
    {
164
        $xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
165
166
        return new JoinMeetingResponse($xml);
167
    }
168
169
    /**
170
     * @param $endParams EndMeetingParameters
171
     *
172
     * @return string
173
     */
174
    public function getEndMeetingURL($endParams)
175
    {
176
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
177
    }
178
179
    /**
180
     * @param $endParams EndMeetingParameters
181
     *
182
     * @return EndMeetingResponse
183
     * @throws \RuntimeException
184
     * */
185
    public function endMeeting($endParams)
186
    {
187
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
188
189
        return new EndMeetingResponse($xml);
190
    }
191
192
    /* __________________ BBB MONITORING METHODS _________________ */
193
    /* The methods in the following section support the following categories of the BBB API:
194
    -- isMeetingRunning
195
    -- getMeetings
196
    -- getMeetingInfo
197
    */
198
199
    /**
200
     * @param $meetingParams IsMeetingRunningParameters
201
     * @return string
202
     */
203
    public function getIsMeetingRunningUrl($meetingParams)
204
    {
205
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
206
    }
207
208
    /**
209
     * @param $meetingParams
210
     * @return IsMeetingRunningResponse
211
     * @throws \RuntimeException
212
     */
213
    public function isMeetingRunning($meetingParams)
214
    {
215
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
216
217
        return new IsMeetingRunningResponse($xml);
218
    }
219
220
    /**
221
     * @return string
222
     */
223
    public function getMeetingsUrl()
224
    {
225
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
226
    }
227
228
    /**
229
     * @return GetMeetingsResponse
230
     * @throws \RuntimeException
231
     */
232
    public function getMeetings()
233
    {
234
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
235
236
        return new GetMeetingsResponse($xml);
237
    }
238
239
    /**
240
     * @param $meetingParams GetMeetingInfoParameters
241
     * @return string
242
     */
243
    public function getMeetingInfoUrl($meetingParams)
244
    {
245
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
246
    }
247
248
    /**
249
     * @param $meetingParams GetMeetingInfoParameters
250
     * @return GetMeetingInfoResponse
251
     * @throws \RuntimeException
252
     */
253
    public function getMeetingInfo($meetingParams)
254
    {
255
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
256
257
        return new GetMeetingInfoResponse($xml);
258
    }
259
260
    /* __________________ BBB RECORDING METHODS _________________ */
261
    /* The methods in the following section support the following categories of the BBB API:
262
    -- getRecordings
263
    -- publishRecordings
264
    -- deleteRecordings
265
    */
266
267
    /**
268
     * @param $recordingsParams GetRecordingsParameters
269
     * @return string
270
     */
271
    public function getRecordingsUrl($recordingsParams)
272
    {
273
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
274
    }
275
276
    /**
277
     * @param $recordingParams
278
     * @return GetRecordingsResponse
279
     * @throws \RuntimeException
280
     */
281
    public function getRecordings($recordingParams)
282
    {
283
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
284
285
        return new GetRecordingsResponse($xml);
286
    }
287
288
    /**
289
     * @param $recordingParams PublishRecordingsParameters
290
     * @return string
291
     */
292
    public function getPublishRecordingsUrl($recordingParams)
293
    {
294
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
295
    }
296
297
    /**
298
     * @param $recordingParams PublishRecordingsParameters
299
     * @return PublishRecordingsResponse
300
     * @throws \RuntimeException
301
     */
302
    public function publishRecordings($recordingParams)
303
    {
304
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
305
306
        return new PublishRecordingsResponse($xml);
307
    }
308
309
    /**
310
     * @param $recordingParams DeleteRecordingsParameters
311
     * @return string
312
     */
313
    public function getDeleteRecordingsUrl($recordingParams)
314
    {
315
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
316
    }
317
318
    /**
319
     * @param $recordingParams DeleteRecordingsParameters
320
     * @return DeleteRecordingsResponse
321
     * @throws \RuntimeException
322
     */
323
    public function deleteRecordings($recordingParams)
324
    {
325
        $xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
326
327
        return new DeleteRecordingsResponse($xml);
328
    }
329
330
    /**
331
     * @param $recordingParams UpdateRecordingsParameters
332
     * @return string
333
     */
334
    public function getUpdateRecordingsUrl($recordingParams)
335
    {
336
        return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
337
    }
338
339
    /**
340
     * @param $recordingParams UpdateRecordingsParameters
341
     * @return UpdateRecordingsResponse
342
     * @throws \RuntimeException
343
     */
344
    public function updateRecordings($recordingParams)
345
    {
346
        $xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
347
348
        return new UpdateRecordingsResponse($xml);
349
    }
350
351
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
352
353
    /**
354
     * A private utility method used by other public methods to process XML responses.
355
     *
356
     * @param  string            $url
357
     * @param  string            $xml
358
     * @return SimpleXMLElement
359
     * @throws \RuntimeException
360
     */
361
    private function processXmlResponse($url, $xml = "", $contentType = "application/xml")
362
    {
363
        if (extension_loaded('curl')) {
364
            $ch = curl_init();
365
            if (!$ch) {
366
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
367
            }
368
            $timeout = 10;
369
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
370
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
371
            curl_setopt($ch, CURLOPT_URL, $url);
372
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
373
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
374
            if ($xml != "") {
375
                curl_setopt($ch, CURLOPT_HEADER, 0);
376
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
377
                curl_setopt($ch, CURLOPT_POST, 1);
378
                curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
379
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
380
                    'Content-type: ' . $contentType,
381
                    'Content-length: ' . strlen($xml),
382
                ]);
383
            }
384
            $data = curl_exec($ch);
385
            if ($data === false) {
386
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
387
            }
388
            curl_close($ch);
389
390
            return new SimpleXMLElement($data);
391
        } else if ($xml != "") {
392
            throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');
393
        } else {
394
            $previous = libxml_use_internal_errors(true);
0 ignored issues
show
Unused Code introduced by
$previous is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
395
            try {
396
                $response = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
397
398
                return new SimpleXMLElement($response);
399
            } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class BigBlueButton\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
400
                throw new \RuntimeException('Failover curl error: ' . $e->getMessage());
401
            }
402
        }
403
    }
404
}
405