From ffc5e550ea36d2c43aa34dad26e7004642b933ac Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 9 Jul 2021 16:14:52 +0200 Subject: smsglobal added --- .../Gateway/SMS/Provider/ProviderFactory.php | 2 + lib/Service/Gateway/SMS/Provider/SMSGlobal.php | 84 +++++++++++++++++++++ .../Gateway/SMS/Provider/SMSGlobalConfig.php | 87 ++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 lib/Service/Gateway/SMS/Provider/SMSGlobal.php create mode 100644 lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php (limited to 'lib/Service/Gateway') diff --git a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php index 7977bde..cabef78 100644 --- a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php +++ b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php @@ -41,6 +41,8 @@ class ProviderFactory { return $this->container->query(PuzzelSMS::class); case PlaySMS::PROVIDER_ID: return $this->container->query(PlaySMS::class); + case SMSGlobal::PROVIDER_ID: + return $this->container->query(SMSGlobal::class); case WebSms::PROVIDER_ID: return $this->container->query(WebSms::class); case ClockworkSMS::PROVIDER_ID: diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php new file mode 100644 index 0000000..a6c19ef --- /dev/null +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php @@ -0,0 +1,84 @@ + + * + * 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 + * + */ + +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 SMSGlobal implements IProvider { + public const PROVIDER_ID = 'smsglobal'; + + /** @var IClient */ + private $client; + + /** @var SMSGlobalConfig */ + private $config; + + public function __construct(IClientService $clientService, + SMSGlobalConfig $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(); + $to=str_replace("+", "", $identifier); + + try { + $this->client->get( + $config->getUrl(), + [ + 'query' => [ + 'action' => 'sendsms', + 'user' => $config->getUser(), + 'password' => $config->getPassword(), + 'origin' => 'nextcloud', + 'from' => 'nextcloud', + 'to' => $to, + 'text' => $message, + 'clientcharset' => 'UTF-8', + 'detectcharset' => 1 + ], + ] + ); + } catch (Exception $ex) { + throw new SmsTransmissionException(); + } + } + + /** + * @return SMSGlobalConfig + */ + public function getConfig(): IProviderConfig { + return $this->config; + } +} diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php b/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php new file mode 100644 index 0000000..612a1d9 --- /dev/null +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php @@ -0,0 +1,87 @@ + + * + * 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 + * + */ + +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 SMSGlobalConfig implements IProviderConfig { + private const expected = [ + 'smsglobal_url', + 'smsglobal_user', + 'smsglobal_password', + ]; + + /** @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 getUrl(): string { + return $this->getOrFail('smsglobal_url'); + } + + public function setUrl(string $url) { + $this->config->setAppValue(Application::APP_NAME, 'smsglobal_url', $url); + } + + public function getUser(): string { + return $this->getOrFail('smsglobal_user'); + } + + public function setUser(string $user) { + $this->config->setAppValue(Application::APP_NAME, 'smsglobal_user', $user); + } + + public function getPassword(): string { + return $this->getOrFail('smsglobal_password'); + } + + public function setPassword(string $password) { + $this->config->setAppValue(Application::APP_NAME, 'smsglobal_password', $password); + } + + 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); + } + } +} -- cgit v1.2.3 From eb9a197c98338672ee84d16be1e6aab6c782270f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=B6chstetter?= Date: Tue, 27 Jul 2021 14:13:07 +0200 Subject: requested fixes --- lib/Service/Gateway/SMS/Provider/SMSGlobal.php | 4 ++-- lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/Service/Gateway') diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php index a6c19ef..c2b814d 100644 --- a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * @author Pascal Clémot + * @author Bosdla * * Nextcloud - Two-factor Gateway * @@ -51,7 +51,7 @@ class SMSGlobal implements IProvider { */ public function send(string $identifier, string $message) { $config = $this->getConfig(); - $to=str_replace("+", "", $identifier); + $to=str_replace("+", "", $identifier); try { $this->client->get( diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php b/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php index 612a1d9..597df28 100644 --- a/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobalConfig.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * @author Christoph Wurst + * @author Bosdla * * Nextcloud - Two-factor Gateway * -- cgit v1.2.3 From a38bd5b1210f1051910288bab2e71e6714e26814 Mon Sep 17 00:00:00 2001 From: Bosdla Date: Fri, 30 Jul 2021 08:44:31 +0200 Subject: to tab --- lib/Service/Gateway/SMS/Provider/SMSGlobal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Service/Gateway') diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php index c2b814d..22845f0 100644 --- a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php @@ -51,7 +51,7 @@ class SMSGlobal implements IProvider { */ public function send(string $identifier, string $message) { $config = $this->getConfig(); - $to=str_replace("+", "", $identifier); + $to=str_replace("+", "", $identifier); try { $this->client->get( -- cgit v1.2.3 From cef5fdff81e46ccc49a0e6fbf1cd848e67f6a124 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 6 May 2022 11:52:19 -0300 Subject: Create SMSGlobal.php --- lib/Service/Gateway/SMS/Provider/SMSGlobal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Service/Gateway') diff --git a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php index 22845f0..5543b29 100644 --- a/lib/Service/Gateway/SMS/Provider/SMSGlobal.php +++ b/lib/Service/Gateway/SMS/Provider/SMSGlobal.php @@ -51,7 +51,7 @@ class SMSGlobal implements IProvider { */ public function send(string $identifier, string $message) { $config = $this->getConfig(); - $to=str_replace("+", "", $identifier); + $to = str_replace("+", "", $identifier); try { $this->client->get( -- cgit v1.2.3