Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-06-28 20:59:18 +0300
committerGitHub <noreply@github.com>2022-06-28 20:59:18 +0300
commit29894ad37669555aeef48136357f78978cab99ac (patch)
tree1acb1c15d38ac0c940f9a3a99dbbcef9a537f286
parent2479a1cd95ef6bf1e3be7bfee12540e59f10dec5 (diff)
parentfdd85bbec49144a5f1e60be1e939fd9cda5290f7 (diff)
Merge pull request #360 from froonix/feature/clickatell-2
Clickatell.com API (SMS Platform)
-rw-r--r--doc/Admin Documentation.md22
-rw-r--r--lib/Command/Configure.php36
-rw-r--r--lib/Service/Gateway/SMS/Provider/ClickatellPortal.php79
-rw-r--r--lib/Service/Gateway/SMS/Provider/ClickatellPortalConfig.php83
-rw-r--r--lib/Service/Gateway/SMS/Provider/ProviderFactory.php2
5 files changed, 213 insertions, 9 deletions
diff --git a/doc/Admin Documentation.md b/doc/Admin Documentation.md
index 47e24da..03b21b5 100644
--- a/doc/Admin Documentation.md
+++ b/doc/Admin Documentation.md
@@ -202,6 +202,28 @@ occ twofactorauth:gateway:configure sms
Select `clickatellcentral` and enter your API-ID, API username and API password.
+### Clickatell (SMS Platform)
+URL: https://portal.clickatell.com/
+Stability: Experimental
+
+Use new Clickatell.com API for sending SMS.
+
+* Login with your credencials at [portal.clickatell.com](https://portal.clickatell.com/)
+* Click at the button `Create new integration`
+ * API Type: HTTP
+ * Messaging type: One-way messaging
+ * Delivery type: Time Critical
+ * [Optional] Convert mobile numbers into international format: On
+ * [Optional] Protect my account from fraud: On
+* Save changes!
+
+Interactive admin configuration:
+```bash
+occ twofactorauth:gateway:configure sms
+```
+
+Select `clickatellportal` and enter your API-Key.
+
### ClickSend
URL: https://www.clicksend.com
Stability: Experimental
diff --git a/lib/Command/Configure.php b/lib/Command/Configure.php
index a67a203..d95bfa4 100644
--- a/lib/Command/Configure.php
+++ b/lib/Command/Configure.php
@@ -41,6 +41,7 @@ use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SpryngSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickatellCentralConfig;
+use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickatellPortalConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\VoipbusterConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SerwerSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway;
@@ -113,7 +114,7 @@ class Configure extends Command {
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, clicksend, serwersms, smsglobal): ', '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): ', 'websms');
$provider = $helper->ask($input, $output, $providerQuestion);
/** @var SMSConfig $config */
@@ -131,8 +132,8 @@ class Configure extends Command {
$providerConfig->setUser($username);
$providerConfig->setPassword($password);
-
break;
+
case 'sipgate':
$config->setProvider($provider);
/** @var SipGateConfig $providerConfig */
@@ -148,8 +149,8 @@ class Configure extends Command {
$providerConfig->setTokenId($tokenId);
$providerConfig->setAccessToken($accessToken);
$providerConfig->setWebSmsExtension($webSmsExtension);
-
break;
+
case 'playsms':
$config->setProvider($provider);
/** @var PlaySMSConfig $providerConfig */
@@ -165,8 +166,8 @@ class Configure extends Command {
$providerConfig->setUrl($url);
$providerConfig->setUser($username);
$providerConfig->setPassword($password);
-
break;
+
case 'clockworksms':
$config->setProvider($provider);
/** @var ClockworkSMSConfig $providerConfig */
@@ -176,8 +177,8 @@ class Configure extends Command {
$apitoken = $helper->ask($input, $output, $apitokenQuestion);
$providerConfig->setApiToken($apitoken);
-
break;
+
case 'puzzelsms':
$config->setProvider($provider);
@@ -201,6 +202,7 @@ class Configure extends Command {
$providerConfig->setPassword($password);
$providerConfig->setServiceId($serviceId);
break;
+
case 'ecallsms':
$config->setProvider($provider);
/** @var EcallSMSConfig $providerConfig */
@@ -278,7 +280,6 @@ class Configure extends Command {
$apitoken = $helper->ask($input, $output, $apitokenQuestion);
$providerConfig->setApiToken($apitoken);
-
break;
case 'sms77io':
@@ -341,6 +342,25 @@ class Configure extends Command {
$providerConfig->setPassword($password);
break;
+ case 'clickatellportal':
+ $config->setProvider($provider);
+ /** @var ClickatellPortalConfig $providerConfig */
+ $providerConfig = $config->getProvider()->getConfig();
+
+ $apiQuestion = new Question('Please enter your portal.clickatell.com API-Key: ');
+ $apiKey = $helper->ask($input, $output, $apiQuestion);
+ $fromQuestion = new Question('Please enter your sender number for two-way messaging. Leave it empty for one-way messaging: ');
+ $fromNumber = $helper->ask($input, $output, $fromQuestion);
+
+ $providerConfig->setApiKey($apiKey);
+
+ if (empty($fromNumber)) {
+ $providerConfig->deleteFromNumber();
+ } else {
+ $providerConfig->setFromNumber($fromNumber);
+ }
+ break;
+
case 'clicksend':
$config->setProvider($provider);
/** @var ClickSendConfig $providerConfig */
@@ -353,8 +373,8 @@ class Configure extends Command {
$providerConfig->setUser($username);
$providerConfig->setApiKey($apiKey);
-
break;
+
case 'smsglobal':
$config->setProvider($provider);
/** @var SMSGlobalConfig $providerConfig */
@@ -371,7 +391,6 @@ class Configure extends Command {
$providerConfig->setUrl($url);
$providerConfig->setUser($username);
$providerConfig->setPassword($password);
-
break;
case 'serwersms':
@@ -389,7 +408,6 @@ class Configure extends Command {
$providerConfig->setLogin($login);
$providerConfig->setPassword($password);
$providerConfig->setSender($sender);
-
break;
default:
diff --git a/lib/Service/Gateway/SMS/Provider/ClickatellPortal.php b/lib/Service/Gateway/SMS/Provider/ClickatellPortal.php
new file mode 100644
index 0000000..9c90da5
--- /dev/null
+++ b/lib/Service/Gateway/SMS/Provider/ClickatellPortal.php
@@ -0,0 +1,79 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christian Schrötter <cs@fnx.li>
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * Nextcloud - Two-factor Gateway
+ *
+ * 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 OCP\Http\Client\IClient;
+use OCP\Http\Client\IClientService;
+
+class ClickatellPortal implements IProvider {
+ public const PROVIDER_ID = 'clickatellportal';
+
+ /** @var IClient */
+ private $client;
+
+ /** @var ClickatellPortalConfig */
+ private $config;
+
+ public function __construct(IClientService $clientService,
+ ClickatellPortalConfig $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();
+ try {
+ $from = $config->getFromNumber();
+ $from = !is_null($from) ? sprintf('&from=%s', urlencode($from)) : '';
+ $response = $this->client->get(vsprintf('https://platform.clickatell.com/messages/http/send?apiKey=%s&to=%s&content=%s%s', [
+ urlencode($config->getApiKey()),
+ urlencode($identifier),
+ urlencode($message),
+ $from,
+ ]));
+ } catch (Exception $ex) {
+ throw new SmsTransmissionException();
+ }
+
+ if ($response->getStatusCode() !== 202) {
+ throw new SmsTransmissionException($response->getBody());
+ }
+ }
+
+ /**
+ * @return ClickatellPortalConfig
+ */
+ public function getConfig(): IProviderConfig {
+ return $this->config;
+ }
+}
diff --git a/lib/Service/Gateway/SMS/Provider/ClickatellPortalConfig.php b/lib/Service/Gateway/SMS/Provider/ClickatellPortalConfig.php
new file mode 100644
index 0000000..55d92b0
--- /dev/null
+++ b/lib/Service/Gateway/SMS/Provider/ClickatellPortalConfig.php
@@ -0,0 +1,83 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christian Schrötter <cs@fnx.li>
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author André Fondse <andre@hetnetwerk.org>
+ *
+ * Nextcloud - Two-factor Gateway for Telegram
+ *
+ * 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 OCA\TwoFactorGateway\AppInfo\Application;
+use OCA\TwoFactorGateway\Exception\ConfigurationException;
+use OCP\IConfig;
+
+class ClickatellPortalConfig implements IProviderConfig {
+ public const expected = [
+ 'clickatell_portal_apikey',
+ ];
+
+ /** @var IConfig */
+ private $config;
+
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+ private function getOrFail(string $key): string {
+ $val = $this->config->getAppValue(Application::APP_NAME, $key, null);
+ if (is_null($val)) {
+ throw new ConfigurationException();
+ }
+ return $val;
+ }
+
+ public function getApiKey(): string {
+ return $this->getOrFail('clickatell_portal_apikey');
+ }
+
+ public function setApiKey(string $apiKey) {
+ $this->config->setAppValue(Application::APP_NAME, 'clickatell_portal_apikey', $apiKey);
+ }
+
+ public function getFromNumber() /* ?string */
+ {
+ return $this->config->getAppValue(Application::APP_NAME, 'clickatell_portal_from', null);
+ }
+
+ public function setFromNumber(string $fromNumber) {
+ $this->config->setAppValue(Application::APP_NAME, 'clickatell_portal_from', $fromNumber);
+ }
+
+ public function deleteFromNumber() {
+ $this->config->deleteAppValue(Application::APP_NAME, 'clickatell_portal_from');
+ }
+
+ public function isComplete(): bool {
+ $set = $this->config->getAppKeys(Application::APP_NAME);
+ return count(array_intersect($set, self::expected)) === count(self::expected);
+ }
+
+ public function remove() {
+ foreach (self::expected as $key) {
+ $this->config->deleteAppValue(Application::APP_NAME, $key);
+ }
+ }
+}
diff --git a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
index b886284..9ae8dcd 100644
--- a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
+++ b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
@@ -65,6 +65,8 @@ class ProviderFactory {
return $this->container->query(SpryngSMS::class);
case ClickatellCentral::PROVIDER_ID:
return $this->container->query(ClickatellCentral::class);
+ case ClickatellPortal::PROVIDER_ID:
+ return $this->container->query(ClickatellPortal::class);
case ClickSend::PROVIDER_ID:
return $this->container->query(ClickSend::class);
case SerwerSMS::PROVIDER_ID: