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:
authorFabian Zihlmann <fabian.zihlmann@mybica.ch>2019-01-08 04:55:18 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-01-08 16:58:01 +0300
commit6989b2d6bc30fbf98caaebd32fe61da8d1c1daae (patch)
tree5c32def270088d1075627e306f742b825715908d /lib/Service
parentba5777a9e2dbfb43b87ee9b34221700f7d12a633 (diff)
Add eCall SMS provider
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/Gateway/SMS/Provider/EcallSMS.php81
-rw-r--r--lib/Service/Gateway/SMS/Provider/EcallSMSConfig.php82
-rw-r--r--lib/Service/Gateway/SMS/Provider/ProviderFactory.php2
3 files changed, 165 insertions, 0 deletions
diff --git a/lib/Service/Gateway/SMS/Provider/EcallSMS.php b/lib/Service/Gateway/SMS/Provider/EcallSMS.php
new file mode 100644
index 0000000..e6bd083
--- /dev/null
+++ b/lib/Service/Gateway/SMS/Provider/EcallSMS.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Fabian Zihlmann <fabian.zihlmann@mybica.ch>
+ *
+ * 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 EcallSMS implements IProvider {
+
+ const PROVIDER_ID = 'ecallsms';
+
+ /** @var IClient */
+ private $client;
+
+ /** @var EcallSMSConfig */
+ private $config;
+
+ public function __construct(IClientService $clientService,
+ EcallSMSConfig $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();
+ $user = $config->getUser();
+ $password = $config->getPassword();
+ $senderId = $config->getSenderId();
+ try {
+ $this->client->get('https://www.ecall.ch/ecallurl/ecallurl.ASP', [
+ 'query' => [
+ 'WCI' => 'Interface',
+ 'Function' => 'SendPage',
+ 'AccountName' => $user,
+ 'AccountPassword' => $password,
+ 'Callback' => $senderId,
+ 'Address' => $identifier,
+ 'Message' => $message,
+ ],
+ ]);
+ } catch (Exception $ex) {
+ throw new SmsTransmissionException();
+ }
+ }
+
+ /**
+ * @return EcallSMSConfig
+ */
+ public function getConfig(): IProviderConfig {
+ return $this->config;
+ }
+}
diff --git a/lib/Service/Gateway/SMS/Provider/EcallSMSConfig.php b/lib/Service/Gateway/SMS/Provider/EcallSMSConfig.php
new file mode 100644
index 0000000..990ae07
--- /dev/null
+++ b/lib/Service/Gateway/SMS/Provider/EcallSMSConfig.php
@@ -0,0 +1,82 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Fabian Zihlmann <fabian.zihlmann@mybica.ch>
+ *
+ * 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 function array_intersect;
+use OCA\TwoFactorGateway\AppInfo\Application;
+use OCA\TwoFactorGateway\Exception\ConfigurationException;
+use OCP\IConfig;
+
+class EcallSMSConfig implements IProviderConfig {
+
+ /** @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 getUser(): string {
+ return $this->getOrFail('ecallsms_username');
+ }
+
+ public function setUser(string $user) {
+ $this->config->setAppValue(Application::APP_NAME, 'ecallsms_username', $user);
+ }
+
+ public function getPassword(): string {
+ return $this->getOrFail('ecallsms_password');
+ }
+
+ public function setPassword(string $password) {
+ $this->config->setAppValue(Application::APP_NAME, 'ecallsms_password', $password);
+ }
+
+ public function getSenderId(): string {
+ return $this->getOrFail('ecallsms_senderid');
+ }
+
+ public function setSenderId(string $senderid) {
+ $this->config->setAppValue(Application::APP_NAME, 'ecallsms_senderid', $senderid);
+ }
+
+ public function isComplete(): bool {
+ $set = $this->config->getAppKeys(Application::APP_NAME);
+ $expected = [
+ 'ecallsms_username',
+ 'ecallsms_password',
+ 'ecallsms_senderid',
+ ];
+ return count(array_intersect($set, $expected)) === count($expected);
+ }
+
+}
diff --git a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
index 06369ce..5bf171e 100644
--- a/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
+++ b/lib/Service/Gateway/SMS/Provider/ProviderFactory.php
@@ -45,6 +45,8 @@ class ProviderFactory {
return $this->container->query(WebSms::class);
case ClockworkSMS::PROVIDER_ID:
return $this->container->query(ClockworkSMS::class);
+ case EcallSMS::PROVIDER_ID:
+ return $this->container->query(EcallSMS::class);
default:
throw new InvalidSmsProviderException("Provider <$id> does not exist");
}