Skip to content

Commit

Permalink
Add Cegedim.Cloud's vortext platform support
Browse files Browse the repository at this point in the history
Signed-off-by: LEROUGE Pierre <[email protected]>
  • Loading branch information
pierre-lerouge committed Nov 30, 2023
1 parent ed687c0 commit 575dd5d
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 1 deletion.
23 changes: 23 additions & 0 deletions doc/Admin Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,26 @@ occ twofactorauth:gateway:configure sms
[User Documentation]: https://nextcloud-twofactor-gateway.readthedocs.io/en/latest/User%20Documentation/
[mod_rest]: https://modules.prosody.im/mod_rest.html
[mod_post_msg]: https://modules.prosody.im/mod_post_msg


### Cegedim.Cloud
URL: https://vortext.cloud.cegedim.com/
Stability: Experimental

Use the SMS gateway provided by Vortext for sending SMS.

1. First create an user password through an ITCare request : https://itcare.cegedim.cloud/messages

2. Interactive admin configuration:
```bash
occ twofactorauth:gateway:configure sms
```

* Choose the `cegedimcloud` SMS provider.
* Choose the endpoint connexion.
* Enter successively the application key, the application secret, the consumer key, the account, and the sender.

5. Try to send a test with
```bash
occ twofactorauth:gateway:test <uid> sms <receiver>
```
22 changes: 21 additions & 1 deletion lib/Command/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\OvhConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\CegedimVortextConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SerwerSMSConfig;
Expand Down Expand Up @@ -124,7 +125,7 @@ private function configureSignal(InputInterface $input, OutputInterface $output)
private function configureSms(InputInterface $input, OutputInterface $output) {
$helper = $this->getHelper('question');

$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');
$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');
$provider = $helper->ask($input, $output, $providerQuestion);

/** @var SMSConfig $config */
Expand Down Expand Up @@ -433,7 +434,26 @@ private function configureSms(InputInterface $input, OutputInterface $output) {
$providerConfig->setToken($token);
$providerConfig->setSender($sender);
break;
case 'cegedimcloud':
$config->setProvider($provider);

/** @var CegedimVortextConfig $providerConfig */
$providerConfig = $config->getProvider()->getConfig();

$endpointQ = new Question('Please enter the endpoint to use (eb4): ');
$endpoint = $helper->ask($input, $output, $endpointQ);

$usernameQ = new Question('Please enter your username: ');
$appUsername = $helper->ask($input, $output, $usernameQ);

$passwordQ = new Question('Please enter your password: ');
$appPassword = $helper->ask($input, $output, $passwordQ);

$providerConfig->setEndpoint($endpoint);
$providerConfig->setUsername($appUsername);
$providerConfig->setPassword($appPassword);
break;

default:
$output->writeln("Invalid provider $provider");
break;
Expand Down
109 changes: 109 additions & 0 deletions lib/Service/Gateway/SMS/Provider/CegedimVortext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

/**
* @author Pierre LEROUGE <[email protected]>
*
* Nextcloud - Two-factor Gateway for Vortext
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;

use Exception;
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
use OCA\TwoFactorGateway\Exception\InvalidSmsProviderException;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;

class CegedimVortext implements IProvider {
public const PROVIDER_ID = 'cegedim.cloud';

/** @var IClient */
private $client;

/** @var CegedimVortextConfig */
private $config;

/**
* Url to communicate with Vortext API
*
* @var array
*/
private $endpoints = [
'eb4' => 'https://vortext.cloud.cegedim.com'
];

/**
* Array of the 3 needed parameters to connect to the API
* @var array
*/
private $attrs = [
'user' => null,
'password' => null,
'endpoint' => null
];


public function __construct(IClientService $clientService,
CegedimVortextConfig $config) {
$this->client = $clientService->newClient();
$this->config = $config;
}

/**
* @param string $identifier
* @param string $message
*
* @throws SmsTransmissionException
*/
public function send(string $identifier, string $message) {
$config = $this->getConfig();
$endpoint = $config->getEndpoint();
$this->attrs['user'] = $config->getUsername();
$this->attrs['password'] = $config->getPassword();
$this->attrs['endpoint'] = $config->getEndpoint();
if (!isset($this->endpoints[$endpoint])) {
throw new InvalidSmsProviderException("Endpoint $endpoint not found");
}
$this->attrs['endpoint'] = $this->endpoints[$endpoint];

$content = [
"message"=> $message,
"phoneNumber"=> $identifier,
];
$body = json_encode($content);

$response = $this->client->post(
$this->attrs['endpoint']."/sms",[
'json' => $content,
'auth' => [$this->attrs['user'],$this->attrs['password']]
]
);
$resultPostJob = json_decode($response->getBody(),true);

if (strlen($resultPostJob["messageId"]) === 0) {
throw new SmsTransmissionException("Bad receiver $identifier");
}
}

/**
* @return CegedimVortextConfig
*/
public function getConfig(): IProviderConfig {
return $this->config;
}
}
88 changes: 88 additions & 0 deletions lib/Service/Gateway/SMS/Provider/CegedimVortextConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

/**
* @author Pierre LEROUGE <[email protected]>
*
* Nextcloud - Two-factor Gateway for Vortext
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;

use function array_intersect;
use OCA\TwoFactorGateway\AppInfo\Application;
use OCA\TwoFactorGateway\Exception\ConfigurationException;
use OCP\IConfig;

class CegedimVortextConfig implements IProviderConfig {

const expected = [
'cegedimvortext_username',
'cegedimvortext_password',
'cegedimvortext_endpoint'
];

/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
$this->config = $config;
}

private function getOrFail(string $key): string {
$val = $this->config->getAppValue(Application::APP_ID, $key, null);
if (is_null($val)) {
throw new ConfigurationException();
}
return $val;
}

public function getUsername(): string {
return $this->getOrFail('cegedimvortext_username');
}

public function getPassword(): string {
return $this->getOrFail('cegedimvortext_password');
}

public function getEndpoint(): string {
return $this->getOrFail('cegedimvortext_endpoint');
}

public function setUsername(string $appKey) {
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_username', $appKey);
}

public function setPassword(string $appSecret) {
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_password', $appSecret);
}

public function setEndpoint(string $endpoint) {
$this->config->setAppValue(Application::APP_ID, 'cegedimvortext_endpoint', $endpoint);
}

public function isComplete(): bool {
$set = $this->config->getAppKeys(Application::APP_ID);
return count(array_intersect($set, self::expected)) === count(self::expected);
}

public function remove() {
foreach(self::expected as $key) {
$this->config->deleteAppValue(Application::APP_ID, $key);
}
}
}
2 changes: 2 additions & 0 deletions lib/Service/Gateway/SMS/Provider/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function getProvider(string $id): IProvider {
return $this->container->query(SerwerSMS::class);
case SMSApi::PROVIDER_ID:
return $this->container->query(SMSApi::class);
case CegedimVortext::PROVIDER_ID:
return $this->container->query(CegedimVortext::class);
default:
throw new InvalidSmsProviderException("Provider <$id> does not exist");
}
Expand Down

0 comments on commit 575dd5d

Please sign in to comment.