diff options
author | Francois Blackburn <fblackburn@wazo.community> | 2019-01-15 05:13:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 05:13:32 +0300 |
commit | d537a415cd059d42df29a7bbddcab764bb9721b8 (patch) | |
tree | e98f247e63fcdd9ad3139ccf79905377fd7971bc /lib | |
parent | d9020a1edfeae71ab8cc096e4c9682596084b565 (diff) | |
parent | d3327f89184b32dc04f71258d49380b53da48f8a (diff) |
Merge branch 'master' into voipms
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Command/Configure.php | 26 | ||||
-rw-r--r-- | lib/Command/Test.php | 6 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/EcallSMS.php | 81 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/EcallSMSConfig.php | 82 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/ProviderFactory.php | 2 |
5 files changed, 190 insertions, 7 deletions
diff --git a/lib/Command/Configure.php b/lib/Command/Configure.php index 413519c..b5913e1 100644 --- a/lib/Command/Configure.php +++ b/lib/Command/Configure.php @@ -28,6 +28,8 @@ use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway; use OCA\TwoFactorGateway\Service\Gateway\Signal\GatewayConfig as SignalConfig; use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway; use OCA\TwoFactorGateway\Service\Gateway\SMS\GatewayConfig as SMSConfig; +use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClockworkSMSConfig; +use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig; use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig; use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig; use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig; @@ -61,7 +63,7 @@ class Configure extends Command { $this->addArgument( 'gateway', InputArgument::REQUIRED, - 'The identifier (e.g. phone number) of the recipient' + 'The name of the gateway, e.g. sms, signal, telegram, etc.' ); } @@ -100,7 +102,7 @@ class Configure extends Command { private function configureSms(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); - $providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, puzzelsms, voipms): ', 'websms'); + $providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, puzzelsms, voipsms, ecallsms, voipms): ', 'websms'); $provider = $helper->ask($input, $output, $providerQuestion); /** @var SMSConfig $config */ @@ -139,7 +141,7 @@ class Configure extends Command { break; case 'clockworksms': $config->setProvider($provider); - /** @var ClockworkSmsConfig $providerConfig */ + /** @var ClockworkSMSConfig $providerConfig */ $providerConfig = $config->getProvider()->getConfig(); $apitokenQuestion = new Question('Please enter your clockworksms api token: '); @@ -171,6 +173,22 @@ class Configure extends Command { $providerConfig->setPassword($password); $providerConfig->setServiceId($serviceId); break; + case 'ecallsms': + $config->setProvider($provider); + /** @var EcallSMSConfig $providerConfig */ + $providerConfig = $config->getProvider()->getConfig(); + + $usernameQuestion = new Question('Please enter your eCall.ch username: '); + $username = $helper->ask($input, $output, $usernameQuestion); + $passwordQuestion = new Question('Please enter your eCall.ch password: '); + $password = $helper->ask($input, $output, $passwordQuestion); + $senderIdQuestion = new Question('Please enter your eCall.ch sender ID: '); + $senderId = $helper->ask($input, $output, $senderIdQuestion); + + $providerConfig->setUser($username); + $providerConfig->setPassword($password); + $providerConfig->setSenderId($senderId); + break; case 'voipms': $config->setProvider($provider); @@ -211,4 +229,4 @@ class Configure extends Command { $config->setBotToken($token); } -}
\ No newline at end of file +} diff --git a/lib/Command/Test.php b/lib/Command/Test.php index 0db20f2..21a624f 100644 --- a/lib/Command/Test.php +++ b/lib/Command/Test.php @@ -66,12 +66,12 @@ class Test extends Command { $this->addArgument( 'gateway', InputArgument::REQUIRED, - 'The identifier (e.g. phone number) of the recipient' + 'The name of the gateway, e.g. sms, signal, telegram, etc.' ); $this->addArgument( 'identifier', InputArgument::REQUIRED, - 'The identifier (e.g. phone number) of the recipient' + 'The identifier of the recipient , e.g. phone number, user id, etc.' ); } @@ -105,4 +105,4 @@ class Test extends Command { $gateway->send($user, $identifier, 'Test'); } -}
\ No newline at end of file +} 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 cb1a686..bcb39d3 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); case VoipMs::PROVIDER_ID: return $this->container->query(VoipMs::class); default: |