1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Kim Syversen <[email protected]> |
7
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\Drivers; |
11
|
|
|
|
12
|
|
|
use Exception; |
13
|
|
|
use OCA\TwoFactorGateway\Exception\MessageTransmissionException; |
14
|
|
|
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\AProvider; |
15
|
|
|
use OCA\TwoFactorGateway\Provider\FieldDefinition; |
16
|
|
|
use OCA\TwoFactorGateway\Provider\Settings; |
17
|
|
|
use OCP\Http\Client\IClient; |
18
|
|
|
use OCP\Http\Client\IClientService; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @method string getUrl() |
22
|
|
|
* @method static setUrl(string $url) |
23
|
|
|
* @method string getUser() |
24
|
|
|
* @method static setUser(string $user) |
25
|
|
|
* @method string getPassword() |
26
|
|
|
* @method static setPassword(string $password) |
27
|
|
|
* @method string getServiceid() |
28
|
|
|
* @method static setServiceid(string $serviceid) |
29
|
|
|
*/ |
30
|
|
|
class PuzzelSMS extends AProvider { |
31
|
|
|
private IClient $client; |
32
|
|
|
|
33
|
1 |
|
public function __construct( |
34
|
|
|
IClientService $clientService, |
35
|
|
|
) { |
36
|
1 |
|
$this->client = $clientService->newClient(); |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
public function createSettings(): Settings { |
40
|
1 |
|
return new Settings( |
41
|
1 |
|
id: 'puzzel', |
42
|
1 |
|
name: 'Puzzel SMS', |
43
|
1 |
|
fields: [ |
44
|
1 |
|
new FieldDefinition( |
45
|
1 |
|
field: 'url', |
46
|
1 |
|
prompt: 'Please enter your PuzzelSMS URL:', |
47
|
1 |
|
), |
48
|
1 |
|
new FieldDefinition( |
49
|
1 |
|
field: 'user', |
50
|
1 |
|
prompt: 'Please enter your PuzzelSMS username:', |
51
|
1 |
|
), |
52
|
1 |
|
new FieldDefinition( |
53
|
1 |
|
field: 'password', |
54
|
1 |
|
prompt: 'Please enter your PuzzelSMS password:', |
55
|
1 |
|
), |
56
|
1 |
|
new FieldDefinition( |
57
|
1 |
|
field: 'serviceid', |
58
|
1 |
|
prompt: 'Please enter your PuzzelSMS service ID:', |
59
|
1 |
|
), |
60
|
1 |
|
] |
61
|
1 |
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
#[\Override] |
65
|
|
|
public function send(string $identifier, string $message) { |
66
|
|
|
try { |
67
|
|
|
$this->client->get( |
68
|
|
|
$this->getUrl(), |
69
|
|
|
[ |
70
|
|
|
'query' => [ |
71
|
|
|
'username' => $this->getUser(), |
72
|
|
|
'password' => $this->getPassword(), |
73
|
|
|
'message[0].recipient' => '+' . $identifier, |
74
|
|
|
'message[0].content' => $message, |
75
|
|
|
'serviceId' => $this->getServiceid(), |
76
|
|
|
], |
77
|
|
|
] |
78
|
|
|
); |
79
|
|
|
} catch (Exception $ex) { |
80
|
|
|
throw new MessageTransmissionException(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|