1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016-2023 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 <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace BigBlueButton\Util; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class UrlBuilder. |
25
|
|
|
*/ |
26
|
|
|
class UrlBuilder |
27
|
|
|
{ |
28
|
|
|
protected $hashingAlgorithm; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $securitySalt; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $bbbServerBaseUrl; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* UrlBuilder constructor. |
42
|
|
|
* |
43
|
|
|
* @param mixed $secret |
44
|
|
|
* @param mixed $serverBaseUrl |
45
|
|
|
* @param mixed $hashingAlgorithm |
46
|
|
|
*/ |
47
|
|
|
public function __construct($secret, $serverBaseUrl, $hashingAlgorithm) |
48
|
|
|
{ |
49
|
|
|
$this->securitySalt = $secret; |
50
|
|
|
$this->bbbServerBaseUrl = $serverBaseUrl; |
51
|
|
|
$this->hashingAlgorithm = $hashingAlgorithm; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets the hashing algorithm. |
56
|
|
|
*/ |
57
|
|
|
public function setHashingAlgorithm(string $hashingAlgorithm): void |
58
|
|
|
{ |
59
|
|
|
$this->hashingAlgorithm = $hashingAlgorithm; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Builds an API method URL that includes the url + params + its generated checksum. |
64
|
|
|
* |
65
|
|
|
* @param string $method |
66
|
|
|
* @param string $params |
67
|
|
|
* @param bool $append |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function buildUrl($method = '', $params = '', $append = true) |
72
|
|
|
{ |
73
|
|
|
return $this->bbbServerBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : ''); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Builds a query string for an API method URL that includes the params + its generated checksum. |
78
|
|
|
* |
79
|
|
|
* @param string $method |
80
|
|
|
* @param string $params |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function buildQs($method = '', $params = '') |
85
|
|
|
{ |
86
|
|
|
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->securitySalt); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|