Completed
Push — master ( af5436...8c6da9 )
by Ghazi
17s queued 15s
created

UrlBuilder::getJoinMeetingURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
use BigBlueButton\Core\ApiMethod;
24
use BigBlueButton\Enum\HashingAlgorithm;
25
use BigBlueButton\Parameters\CreateMeetingParameters;
26
use BigBlueButton\Parameters\DeleteRecordingsParameters;
27
use BigBlueButton\Parameters\EndMeetingParameters;
28
use BigBlueButton\Parameters\GetMeetingInfoParameters;
29
use BigBlueButton\Parameters\GetRecordingsParameters;
30
use BigBlueButton\Parameters\GetRecordingTextTracksParameters;
31
use BigBlueButton\Parameters\HooksCreateParameters;
32
use BigBlueButton\Parameters\HooksDestroyParameters;
33
use BigBlueButton\Parameters\InsertDocumentParameters;
34
use BigBlueButton\Parameters\IsMeetingRunningParameters;
35
use BigBlueButton\Parameters\JoinMeetingParameters;
36
use BigBlueButton\Parameters\PublishRecordingsParameters;
37
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
38
use BigBlueButton\Parameters\UpdateRecordingsParameters;
39
40
class UrlBuilder
41
{
42
    /** @deprecated Property will be private soon. Use setter/getter instead. */
43
    protected string $hashingAlgorithm;
44
45
    private string $secret;
46
47
    private string $baseUrl;
48
49
    public function __construct(string $secret, string $baseUrl, string $hashingAlgorithm)
50
    {
51
        $this->setSecret($secret);
52
        $this->setBaseUrl($baseUrl);
53
        $this->setHashingAlgorithm($hashingAlgorithm);
54
    }
55
56
    // Getters & Setters
57
    public function setSecret(string $secret): self
58
    {
59
        $this->secret = $secret;
60
61
        return $this;
62
    }
63
64
    public function setBaseUrl(string $baseUrl): self
65
    {
66
        // add tailing dir-separator if missing
67
        if ('/' != mb_substr($baseUrl, -1)) {
68
            $baseUrl .= '/';
69
        }
70
71
        $this->baseUrl = $baseUrl;
72
73
        return $this;
74
    }
75
76
    public function setHashingAlgorithm(string $hashingAlgorithm): self
77
    {
78
        $this->hashingAlgorithm = $hashingAlgorithm;
0 ignored issues
show
Deprecated Code introduced by
The property BigBlueButton\Util\UrlBuilder::$hashingAlgorithm has been deprecated: Property will be private soon. Use setter/getter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

78
        /** @scrutinizer ignore-deprecated */ $this->hashingAlgorithm = $hashingAlgorithm;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
79
80
        return $this;
81
    }
82
83
    public function getHashingAlgorithm(): string
84
    {
85
        return $this->hashingAlgorithm;
0 ignored issues
show
Deprecated Code introduced by
The property BigBlueButton\Util\UrlBuilder::$hashingAlgorithm has been deprecated: Property will be private soon. Use setter/getter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

85
        return /** @scrutinizer ignore-deprecated */ $this->hashingAlgorithm;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
86
    }
87
88
    // Basic functions
89
90
    /**
91
     * Builds an API method URL that includes the url + params + its generated checksum.
92
     */
93
    public function buildUrl(string $method = '', string $params = '', bool $append = true): string
94
    {
95
        return $this->baseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
0 ignored issues
show
Deprecated Code introduced by
The function BigBlueButton\Util\UrlBuilder::buildQs() has been deprecated: Function only used internal. Function will be private soon. No replacement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

95
        return $this->baseUrl . 'api/' . $method . ($append ? '?' . /** @scrutinizer ignore-deprecated */ $this->buildQs($method, $params) : '');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
96
    }
97
98
    /**
99
     * Builds a query string for an API method URL that includes the params + its generated checksum.
100
     *
101
     * @deprecated Function only used internal. Function will be private soon. No replacement.
102
     */
103
    public function buildQs(string $method = '', string $params = ''): string
104
    {
105
        return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->secret);
0 ignored issues
show
Deprecated Code introduced by
The property BigBlueButton\Util\UrlBuilder::$hashingAlgorithm has been deprecated: Property will be private soon. Use setter/getter instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

105
        return $params . '&checksum=' . hash(/** @scrutinizer ignore-deprecated */ $this->hashingAlgorithm, $method . $params . $this->secret);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
106
    }
107
108
    // URL-Generators
109
    public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string
110
    {
111
        return $this->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
112
    }
113
114
    public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string
115
    {
116
        return $this->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
117
    }
118
119
    public function getEndMeetingURL(EndMeetingParameters $endParams): string
120
    {
121
        return $this->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
122
    }
123
124
    public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParameters): string
125
    {
126
        return $this->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParameters->getHTTPQuery());
127
    }
128
129
    public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string
130
    {
131
        return $this->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
132
    }
133
134
    public function getMeetingsUrl(): string
135
    {
136
        return $this->buildUrl(ApiMethod::GET_MEETINGS);
137
    }
138
139
    public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string
140
    {
141
        return $this->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
142
    }
143
144
    public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string
145
    {
146
        return $this->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
147
    }
148
149
    public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string
150
    {
151
        return $this->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
152
    }
153
154
    public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string
155
    {
156
        return $this->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
157
    }
158
159
    public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string
160
    {
161
        return $this->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
162
    }
163
164
    public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParameters): string
165
    {
166
        return $this->buildUrl(ApiMethod::GET_RECORDING_TEXT_TRACKS, $getRecordingTextTracksParameters->getHTTPQuery());
167
    }
168
169
    public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string
170
    {
171
        return $this->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
172
    }
173
174
    /**
175
     * BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
176
     * Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
177
     *
178
     * @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
179
     */
180
    public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
181
    {
182
        // store current hashing algorithm
183
        $hashingAlgorithm = $this->getHashingAlgorithm();
184
185
        // change hashing algorithm for hooks
186
        $this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
0 ignored issues
show
Deprecated Code introduced by
The function BigBlueButton\Util\UrlBu...hingAlgorithmForHooks() has been deprecated: This function will evolve in phases and will later disappear ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

186
        $this->setHashingAlgorithm(/** @scrutinizer ignore-deprecated */ $this->getHashingAlgorithmForHooks());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
187
188
        // build URL
189
        $url = $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
190
191
        // reset to 'normal' hashing algorithm
192
        $this->setHashingAlgorithm($hashingAlgorithm);
193
194
        return $url;
195
    }
196
197
    /**
198
     * BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
199
     * Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
200
     *
201
     * @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
202
     */
203
    public function getHooksListUrl(): string
204
    {
205
        // store current hashing algorithm
206
        $hashingAlgorithm = $this->getHashingAlgorithm();
207
208
        // change hashing algorithm for hooks
209
        $this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
0 ignored issues
show
Deprecated Code introduced by
The function BigBlueButton\Util\UrlBu...hingAlgorithmForHooks() has been deprecated: This function will evolve in phases and will later disappear ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

209
        $this->setHashingAlgorithm(/** @scrutinizer ignore-deprecated */ $this->getHashingAlgorithmForHooks());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
210
211
        // build URL
212
        $url = $this->buildUrl(ApiMethod::HOOKS_LIST);
213
214
        // reset to 'normal' hashing algorithm
215
        $this->setHashingAlgorithm($hashingAlgorithm);
216
217
        return $url;
218
    }
219
220
    /**
221
     * BBB-Server < 3.0 can only use SHA1 in the handling with hooks.
222
     * Please configure the HASH_ALGO_FOR_HOOKS environment variable in case SHA1 shall not be used.
223
     *
224
     * @see https://github.com/bigbluebutton/bbb-webhooks/issues/30
225
     */
226
    public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
227
    {
228
        // store current hashing algorithm
229
        $hashingAlgorithm = $this->getHashingAlgorithm();
230
231
        // change hashing algorithm for hooks
232
        $this->setHashingAlgorithm($this->getHashingAlgorithmForHooks());
0 ignored issues
show
Deprecated Code introduced by
The function BigBlueButton\Util\UrlBu...hingAlgorithmForHooks() has been deprecated: This function will evolve in phases and will later disappear ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

232
        $this->setHashingAlgorithm(/** @scrutinizer ignore-deprecated */ $this->getHashingAlgorithmForHooks());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
233
234
        // build URL
235
        $url = $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
236
237
        // reset to 'normal' hashing algorithm
238
        $this->setHashingAlgorithm($hashingAlgorithm);
239
240
        return $url;
241
    }
242
243
    /**
244
     *  This function defines the algorithm to be used for hooks.
245
     *
246
     *  This function will evolve in phases:
247
     *    - Phase 1: SHA1 as default                 (or superseded by environment-variable HASH_ALGO_FOR_HOOKS).
248
     *    - Phase 2: same algo everywhere as default (or superseded by environment-variable HASH_ALGO_FOR_HOOKS and which will trigger in this case a deprecation-warning).
249
     *    - Phase 3: removal of this function, adaptation of the other hook-functions in this class and remove the use of env-variable HASH_ALGO_FOR_HOOKS.
250
     *
251
     *  Background:
252
     *  BB-Server below 3.0 are using SHA1-algorithm for hooks only, but allow higher algorithms for
253
     *  other APIs. This is creating issues since the algorithm of choice is used in the urlBuilder-class
254
     *  for the hashing of the checksum. This is resulting in denied requests for hooks if the algorithm
255
     *  of choice is not SHA1.
256
     *  The current planning for BBB-Server 3.0 (and on) is to align the hashing algorithm for hooks with
257
     *  the rest of the system. Having this in mind two situations need to be covered:
258
     *    - BBB-Server <  3.0 ==> SHA1 is default for hooks (even rest is using other algorithm)
259
     *    - BBB-Server >= 3.0 ==> same algorithm everywhere (according to planning).
260
     *
261
     * @deprecated This function will evolve in phases and will later disappear
262
     */
263
    private function getHashingAlgorithmForHooks(): string
264
    {
265
        // ---------------------------------- phase 1 ----------------------------------
266
        // in case this env-variable is not set, SHA1 shall be used as default (phase 1)
267
        return getenv('HASH_ALGO_FOR_HOOKS') ?: HashingAlgorithm::SHA_1;
268
        // ---------------------------------- phase 1 ----------------------------------
269
270
        /* ---------------------------------- phase 2 ----------------------------------
271
         * if (getenv('HASH_ALGO_FOR_HOOKS')) {
272
         *   trigger_error('The environment variable HASH_ALGO_FOR_HOOKS will be removed soon. This will require you to run a BBB-Server 3.0 or higher!', E_USER_DEPRECATED);
273
         * }
274
         *
275
         * // in case this env-variable is not set, the 'normal' algorithm shall be used as default (phase 2)
276
         * return getenv('HASH_ALGO_FOR_HOOKS') ?: $this->getHashingAlgorithm();
277
         *
278
         * ---------------------------------- phase 2 ---------------------------------- */
279
    }
280
}
281