diff options
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | appinfo/info.xml | 3 | ||||
-rw-r--r-- | doc/Admin Documentation.md (renamed from doc/admin/README.md) | 0 | ||||
-rw-r--r-- | lib/Command/Configure.php | 15 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/ClockworkSMS.php | 80 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/ClockworkSMSConfig.php | 63 | ||||
-rw-r--r-- | lib/Service/Gateway/SMS/Provider/ProviderFactory.php | 2 |
7 files changed, 165 insertions, 3 deletions
@@ -5,12 +5,13 @@ A set of Nextcloud two-factor providers to send authentication codes via Signal, [![Build Status](https://travis-ci.org/nextcloud/twofactor_gateway.svg?branch=master)](https://travis-ci.org/nextcloud/twofactor_gateway) [![Code Coverage](https://scrutinizer-ci.com/g/nextcloud/twofactor_gateway/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/twofactor_gateway/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nextcloud/twofactor_gateway/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/twofactor_gateway/?branch=master) +[![Read the Docs](https://img.shields.io/readthedocs/nextcloud-twofactor-gateway.svg)](https://nextcloud-twofactor-gateway.readthedocs.io/en/latest/) ![](https://raw.githubusercontent.com/ChristophWurst/twofactor_gateway/ae08ce30abfa866c7c7a486d850d4be07b83d82d/screenshots/challenge.png) ## Supported Messaging Gateways This app uses external messaging gateways services for sending the code. See the -[admin documentation](/doc/admin) on how to configure the specific providers. +[admin documentation] on how to configure the specific providers. ## Login with external apps All modern applications communicating with Nextcloud now use Login flow so you @@ -20,3 +21,5 @@ limited to SMS-based authentication. Absent support for the Login flow, after enabling Two Factor SMS, your legacy applications will accept device passwords. To manage them, [see more here](https://docs.nextcloud.com/server/14/user_manual/session_management.html#managing-devices) + +[admin documentation]: https://nextcloud-twofactor-gateway.readthedocs.io/en/latest/Admin%20Documentation/
\ No newline at end of file diff --git a/appinfo/info.xml b/appinfo/info.xml index b1547d7..439bfad 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -9,6 +9,9 @@ <licence>agpl</licence> <author>Christoph Wurst</author> <namespace>TwoFactorGateway</namespace> + <documentation> + <admin>https://nextcloud-twofactor-gateway.readthedocs.io/en/latest/Admin%20Documentation/</admin> + </documentation> <category>security</category> <website>https://github.com/nextcloud/twofactor_gateway</website> <bugs>https://github.com/nextcloud/twofactor_gateway/issues</bugs> diff --git a/doc/admin/README.md b/doc/Admin Documentation.md index 0ef12dc..0ef12dc 100644 --- a/doc/admin/README.md +++ b/doc/Admin Documentation.md diff --git a/lib/Command/Configure.php b/lib/Command/Configure.php index b7c502c..07f16f1 100644 --- a/lib/Command/Configure.php +++ b/lib/Command/Configure.php @@ -99,7 +99,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): ', 'websms'); + $providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms): ', 'websms'); $provider = $helper->ask($input, $output, $providerQuestion); /** @var SMSConfig $config */ @@ -136,6 +136,17 @@ class Configure extends Command { $providerConfig->setPassword($password); break; + case 'clockworksms': + $config->setProvider($provider); + /** @var ClockworkSmsConfig $providerConfig */ + $providerConfig = $config->getProvider()->getConfig(); + + $apitokenQuestion = new Question('Please enter your clockworksms api token: '); + $apitoken = $helper->ask($input, $output, $apitokenQuestion); + + $providerConfig->setApiToken($apitoken); + + break; default: $output->writeln("Invalid provider $provider"); break; @@ -155,4 +166,4 @@ class Configure extends Command { $config->setBotToken($token); } -}
\ No newline at end of file +} diff --git a/lib/Service/Gateway/SMS/Provider/ClockworkSMS.php b/lib/Service/Gateway/SMS/Provider/ClockworkSMS.php new file mode 100644 index 0000000..51a8bfd --- /dev/null +++ b/lib/Service/Gateway/SMS/Provider/ClockworkSMS.php @@ -0,0 +1,80 @@ +<?php + +declare(strict_types=1); + +/** + * @author Mario Klug <mario.klug@sourcefactory.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; +use OCP\IConfig; + +class ClockworkSMS implements IProvider { + + const PROVIDER_ID = 'clockworksms'; + + /** @var IClient */ + private $client; + + /** @var ClockworkSMSConfig */ + private $config; + + public function __construct(IClientService $clientService, + ClockworkSMSConfig $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 { + $response = $this->client->get( + 'https://api.clockworksms.com/http/send.aspx', + [ + 'query' => [ + 'key' => $config->getApiToken(), + 'to' => $identifier, + 'content' => $message, + ], + ] + ); + } catch (Exception $ex) { + throw new SmsTransmissionException(); + } + } + + /** + * @return ClockworkSMSConfig + */ + public function getConfig(): IProviderConfig { + return $this->config; + } + +} diff --git a/lib/Service/Gateway/SMS/Provider/ClockworkSMSConfig.php b/lib/Service/Gateway/SMS/Provider/ClockworkSMSConfig.php new file mode 100644 index 0000000..cee9bfa --- /dev/null +++ b/lib/Service/Gateway/SMS/Provider/ClockworkSMSConfig.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); + +/** + * @author Mario Klug <mario.klug@sourcefactory.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 function array_intersect; +use OCA\TwoFactorGateway\AppInfo\Application; +use OCA\TwoFactorGateway\Exception\ConfigurationException; +use OCP\IConfig; + +class ClockworkSMSConfig 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 getApiToken(): string { + return $this->getOrFail('clockworksms_apitoken'); + } + + public function setApiToken(string $user) { + $this->config->setAppValue(Application::APP_NAME, 'clockworksms_apitoken', $user); + } + + public function isComplete(): bool { + $set = $this->config->getAppKeys(Application::APP_NAME); + $expected = [ + 'clockworksms_apitoken' + ]; + 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 588f384..49d2608 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(PlaySMS::class); case WebSms::PROVIDER_ID: return $this->container->query(WebSms::class); + case ClockworkSMS::PROVIDER_ID: + return $this->container->query(ClockworkSMS::class); default: throw new InvalidSmsProviderException("Provider <$id> does not exist"); } |