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