Skip to content

Commit 67d6285

Browse files
Add Cegedim.Cloud's vortext platform support
1 parent ed687c0 commit 67d6285

File tree

5 files changed

+243
-1
lines changed

5 files changed

+243
-1
lines changed

doc/Admin Documentation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,26 @@ occ twofactorauth:gateway:configure sms
275275
[User Documentation]: https://nextcloud-twofactor-gateway.readthedocs.io/en/latest/User%20Documentation/
276276
[mod_rest]: https://modules.prosody.im/mod_rest.html
277277
[mod_post_msg]: https://modules.prosody.im/mod_post_msg
278+
279+
280+
### Cegedim.Cloud
281+
URL: https://vortext.cloud.cegedim.com/
282+
Stability: Experimental
283+
284+
Use the SMS gateway provided by Vortext for sending SMS.
285+
286+
1. First create an user password through an ITCare request : https://itcare.cegedim.cloud/messages
287+
288+
2. Interactive admin configuration:
289+
```bash
290+
occ twofactorauth:gateway:configure sms
291+
```
292+
293+
* Choose the `cegedimcloud` SMS provider.
294+
* Choose the endpoint connexion.
295+
* Enter successively the application key, the application secret, the consumer key, the account, and the sender.
296+
297+
5. Try to send a test with
298+
```bash
299+
occ twofactorauth:gateway:test <uid> sms <receiver>
300+
```

lib/Command/Configure.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig;
3636
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config;
3737
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\OvhConfig;
38+
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\CegedimVortextConfig;
3839
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig;
3940
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig;
4041
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SerwerSMSConfig;
@@ -124,7 +125,7 @@ private function configureSignal(InputInterface $input, OutputInterface $output)
124125
private function configureSms(InputInterface $input, OutputInterface $output) {
125126
$helper = $this->getHelper('question');
126127

127-
$providerQuestion = new Question('Please choose a SMS provider (sipgate, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clickatellportal, clicksend, serwersms, smsglobal, smsapi.com): ', 'websms');
128+
$providerQuestion = new Question('Please choose a SMS provider (sipgate, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clickatellportal, clicksend, serwersms, smsglobal, smsapi.com, cegedim.cloud): ', 'websms');
128129
$provider = $helper->ask($input, $output, $providerQuestion);
129130

130131
/** @var SMSConfig $config */
@@ -433,7 +434,26 @@ private function configureSms(InputInterface $input, OutputInterface $output) {
433434
$providerConfig->setToken($token);
434435
$providerConfig->setSender($sender);
435436
break;
437+
case 'cegedimcloud':
438+
$config->setProvider($provider);
439+
440+
/** @var CegedimVortextConfig $providerConfig */
441+
$providerConfig = $config->getProvider()->getConfig();
442+
443+
$endpointQ = new Question('Please enter the endpoint to use (eb4): ');
444+
$endpoint = $helper->ask($input, $output, $endpointQ);
436445

446+
$usernameQ = new Question('Please enter your username: ');
447+
$appUsername = $helper->ask($input, $output, $usernameQ);
448+
449+
$passwordQ = new Question('Please enter your password: ');
450+
$appPassword = $helper->ask($input, $output, $passwordQ);
451+
452+
$providerConfig->setEndpoint($endpoint);
453+
$providerConfig->setUsername($appUsername);
454+
$providerConfig->setPassword($appPassword);
455+
break;
456+
437457
default:
438458
$output->writeln("Invalid provider $provider");
439459
break;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Pierre LEROUGE <[email protected]>
7+
*
8+
* Nextcloud - Two-factor Gateway for Vortext
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 Exception;
27+
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
28+
use OCA\TwoFactorGateway\Exception\InvalidSmsProviderException;
29+
use OCP\Http\Client\IClient;
30+
use OCP\Http\Client\IClientService;
31+
32+
class CegedimVortext implements IProvider {
33+
public const PROVIDER_ID = 'cegedim.cloud';
34+
35+
/** @var IClient */
36+
private $client;
37+
38+
/** @var CegedimVortextConfig */
39+
private $config;
40+
41+
/**
42+
* Url to communicate with Vortext API
43+
*
44+
* @var array
45+
*/
46+
private $endpoints = [
47+
'eb4' => 'https://vortext.cloud.cegedim.com'
48+
];
49+
50+
/**
51+
* Array of the 3 needed parameters to connect to the API
52+
* @var array
53+
*/
54+
private $attrs = [
55+
'user' => null,
56+
'password' => null,
57+
'endpoint' => null
58+
];
59+
60+
61+
public function __construct(IClientService $clientService,
62+
CegedimVortextConfig $config) {
63+
$this->client = $clientService->newClient();
64+
$this->config = $config;
65+
}
66+
67+
/**
68+
* @param string $identifier
69+
* @param string $message
70+
*
71+
* @throws SmsTransmissionException
72+
*/
73+
public function send(string $identifier, string $message) {
74+
$config = $this->getConfig();
75+
$endpoint = $config->getEndpoint();
76+
$this->attrs['user'] = $config->getUsername();
77+
$this->attrs['password'] = $config->getPassword();
78+
$this->attrs['endpoint'] = $config->getEndpoint();
79+
if (!isset($this->endpoints[$endpoint])) {
80+
throw new InvalidSmsProviderException("Endpoint $endpoint not found");
81+
}
82+
$this->attrs['endpoint'] = $this->endpoints[$endpoint];
83+
84+
$content = [
85+
"message"=> $message,
86+
"phoneNumber"=> $identifier,
87+
];
88+
$body = json_encode($content);
89+
90+
$response = $this->client->post(
91+
$this->attrs['endpoint']."/sms",[
92+
'json' => $content,
93+
'auth' => [$this->attrs['user'],$this->attrs['password']]
94+
]
95+
);
96+
$resultPostJob = json_decode($response->getBody(),true);
97+
98+
if (strlen($resultPostJob["messageId"]) === 0) {
99+
throw new SmsTransmissionException("Bad receiver $identifier");
100+
}
101+
}
102+
103+
/**
104+
* @return CegedimVortextConfig
105+
*/
106+
public function getConfig(): IProviderConfig {
107+
return $this->config;
108+
}
109+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Pierre LEROUGE <[email protected]>
7+
*
8+
* Nextcloud - Two-factor Gateway for Vortext
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 CegedimVortextConfig implements IProviderConfig {
32+
33+
const expected = [
34+
'cegedimvortext_username',
35+
'cegedimvortext_password',
36+
'cegedimvortext_endpoint'
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_ID, $key, null);
48+
if (is_null($val)) {
49+
throw new ConfigurationException();
50+
}
51+
return $val;
52+
}
53+
54+
public function getUsername(): string {
55+
return $this->getOrFail('cegedimvortext_username');
56+
}
57+
58+
public function getPassword(): string {
59+
return $this->getOrFail('cegedimvortext_password');
60+
}
61+
62+
public function getEndpoint(): string {
63+
return $this->getOrFail('cegedimvortext_endpoint');
64+
}
65+
66+
public function setUsername(string $appKey) {
67+
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_username', $appKey);
68+
}
69+
70+
public function setPassword(string $appSecret) {
71+
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_password', $appSecret);
72+
}
73+
74+
public function setEndpoint(string $endpoint) {
75+
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_endpoint', $endpoint);
76+
}
77+
78+
public function isComplete(): bool {
79+
$set = $this->config->getAppKeys(Application::APP_ID);
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_ID, $key);
86+
}
87+
}
88+
}

lib/Service/Gateway/SMS/Provider/ProviderFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public function getProvider(string $id): IProvider {
7373
return $this->container->query(SerwerSMS::class);
7474
case SMSApi::PROVIDER_ID:
7575
return $this->container->query(SMSApi::class);
76+
case CegedimVortext::PROVIDER_ID:
77+
return $this->container->query(CegedimVortext::class);
7678
default:
7779
throw new InvalidSmsProviderException("Provider <$id> does not exist");
7880
}

0 commit comments

Comments
 (0)