1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Christian Schrötter <[email protected]> |
7
|
|
|
* @author Christoph Wurst <[email protected]> |
8
|
|
|
* @author André Fondse <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Nextcloud - Two-factor Gateway for Telegram |
11
|
|
|
* |
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
14
|
|
|
* as published by the Free Software Foundation. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider; |
27
|
|
|
|
28
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
29
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
30
|
|
|
use OCP\IConfig; |
31
|
|
|
|
32
|
|
|
class ClickatellPortalConfig implements IProviderConfig { |
33
|
|
|
public const expected = [ |
34
|
|
|
'clickatell_portal_apikey', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** @var IConfig */ |
38
|
|
|
private $config; |
39
|
|
|
|
40
|
|
|
public function __construct(IConfig $config) { |
41
|
|
|
$this->config = $config; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function getOrFail(string $key): string { |
45
|
|
|
$val = $this->config->getAppValue(Application::APP_NAME, $key, null); |
|
|
|
|
46
|
|
|
if (is_null($val)) { |
|
|
|
|
47
|
|
|
throw new ConfigurationException(); |
48
|
|
|
} |
49
|
|
|
return $val; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getApiKey(): string { |
53
|
|
|
return $this->getOrFail('clickatell_portal_apikey'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setApiKey(string $apiKey) { |
57
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'clickatell_portal_apikey', $apiKey); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getFromNumber() /* ?string */ |
61
|
|
|
{ |
62
|
|
|
return $this->config->getAppValue(Application::APP_NAME, 'clickatell_portal_from', null); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setFromNumber(string $fromNumber) { |
66
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'clickatell_portal_from', $fromNumber); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function deleteFromNumber() { |
70
|
|
|
$this->config->deleteAppValue(Application::APP_NAME, 'clickatell_portal_from'); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function isComplete(): bool { |
74
|
|
|
$set = $this->config->getAppKeys(Application::APP_NAME); |
|
|
|
|
75
|
|
|
return count(array_intersect($set, self::expected)) === count(self::expected); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function remove() { |
79
|
|
|
foreach (self::expected as $key) { |
80
|
|
|
$this->config->deleteAppValue(Application::APP_NAME, $key); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|