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:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2018-08-21 19:28:36 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2018-08-21 19:28:36 +0300
commitf2fab19e78cf10c6b16ca1f48775c9d88f12bb47 (patch)
tree326950b9db42fb2548fcb52a3f054a893b6feae4
parentefdc89dd6fd07b7c221f0ccc47e186085c1043c1 (diff)
Add command to check configuration of gateways
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--appinfo/info.xml3
-rw-r--r--lib/Command/Status.php62
-rw-r--r--lib/Provider/SmsProvider.php4
-rw-r--r--lib/Service/Gateway/SMS/Gateway.php (renamed from lib/Service/Gateway/SMS/SMS.php)8
-rw-r--r--lib/Service/Gateway/SMS/GatewayConfig.php (renamed from lib/Service/Gateway/SMS/SMSConfig.php)2
-rw-r--r--lib/Service/Gateway/Signal/Gateway.php7
-rw-r--r--lib/Service/Gateway/Signal/GatewayConfig.php35
-rw-r--r--lib/Service/Gateway/Telegram/Gateway.php14
-rw-r--r--lib/Service/Gateway/Telegram/GatewayConfig.php62
9 files changed, 184 insertions, 13 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 0bbb654..8fb6595 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -22,6 +22,9 @@
<two-factor-providers>
<provider>OCA\TwoFactorGateway\Provider\SmsProvider</provider>
</two-factor-providers>
+ <commands>
+ <command>OCA\TwoFactorGateway\Command\Status</command>
+ </commands>
<settings>
<personal>OCA\TwoFactorGateway\Settings\PersonalSettings</personal>
</settings>
diff --git a/lib/Command/Status.php b/lib/Command/Status.php
new file mode 100644
index 0000000..c6c32e7
--- /dev/null
+++ b/lib/Command/Status.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Pascal Clémot <pascal.clemot@free.fr>
+ *
+ * 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\Command;
+
+use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway;
+use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway;
+use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Status extends Command {
+
+ /** @var SignalGateway */
+ private $signalGateway;
+
+ /** @var SMSGateway */
+ private $smsGateway;
+
+ /** @var TelegramGateway */
+ private $telegramGateway;
+
+ public function __construct(SignalGateway $signalGateway,
+ SMSGateway $smsGateway,
+ TelegramGateway $telegramGateway) {
+ parent::__construct('twofactorauth:gateway:status');
+ $this->signalGateway = $signalGateway;
+ $this->smsGateway = $smsGateway;
+ $this->telegramGateway = $telegramGateway;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $signalConfigured = $this->signalGateway->getConfig()->isComplete();
+ $output->writeln('Signal gateway: ' . ($signalConfigured ? 'configured' : 'not configured'));
+ $smsConfigured = $this->smsGateway->getConfig()->isComplete();
+ $output->writeln('SMS gateway: ' . ($smsConfigured ? 'configured' : 'not configured'));
+ $telegramConfigured = $this->telegramGateway->getConfig()->isComplete();
+ $output->writeln('Telegram gateway: ' . ($telegramConfigured ? 'configured' : 'not configured'));
+ }
+
+} \ No newline at end of file
diff --git a/lib/Provider/SmsProvider.php b/lib/Provider/SmsProvider.php
index 12fec2f..dea399c 100644
--- a/lib/Provider/SmsProvider.php
+++ b/lib/Provider/SmsProvider.php
@@ -26,7 +26,7 @@ namespace OCA\TwoFactorGateway\Provider;
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
use OCA\TwoFactorGateway\PhoneNumberMask;
use OCA\TwoFactorGateway\Service\Gateway\IGateway;
-use OCA\TwoFactorGateway\Service\Gateway\SMS\SMS;
+use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway;
use OCA\TwoFactorGateway\Service\StateStorage;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IL10N;
@@ -58,7 +58,7 @@ class SmsProvider implements IProvider {
/** @var IL10N */
private $l10n;
- public function __construct(SMS $smsGateway,
+ public function __construct(Gateway $smsGateway,
StateStorage $stateStorage,
ISession $session,
ISecureRandom $secureRandom,
diff --git a/lib/Service/Gateway/SMS/SMS.php b/lib/Service/Gateway/SMS/Gateway.php
index 8a36011..323e8d0 100644
--- a/lib/Service/Gateway/SMS/SMS.php
+++ b/lib/Service/Gateway/SMS/Gateway.php
@@ -28,12 +28,12 @@ use OCA\TwoFactorGateway\Service\Gateway\IGateway;
use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig;
use OCP\IUser;
-class SMS implements IGateway {
+class Gateway implements IGateway {
- /** @var SMSConfig */
+ /** @var GatewayConfig */
private $config;
- public function __construct(SMSConfig $config) {
+ public function __construct(GatewayConfig $config) {
$this->config = $config;
}
@@ -61,7 +61,7 @@ class SMS implements IGateway {
/**
* Get the gateway-specific configuration
*
- * @return SMSConfig
+ * @return GatewayConfig
*/
public function getConfig(): IGatewayConfig {
return $this->config;
diff --git a/lib/Service/Gateway/SMS/SMSConfig.php b/lib/Service/Gateway/SMS/GatewayConfig.php
index 4e3da11..ffaff71 100644
--- a/lib/Service/Gateway/SMS/SMSConfig.php
+++ b/lib/Service/Gateway/SMS/GatewayConfig.php
@@ -30,7 +30,7 @@ use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\IProvider;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ProviderFactory;
use OCP\IConfig;
-class SMSConfig implements IGatewayConfig {
+class GatewayConfig implements IGatewayConfig {
/** @var IConfig */
private $config;
diff --git a/lib/Service/Gateway/Signal/Gateway.php b/lib/Service/Gateway/Signal/Gateway.php
index f87f37d..821aa0d 100644
--- a/lib/Service/Gateway/Signal/Gateway.php
+++ b/lib/Service/Gateway/Signal/Gateway.php
@@ -40,12 +40,17 @@ class Gateway implements IGateway {
/** @var IClientService */
private $clientService;
+ /** @var GatewayConfig */
+ private $config;
+
/** @var ILogger */
private $logger;
public function __construct(IClientService $clientService,
+ GatewayConfig $config,
ILogger $logger) {
$this->clientService = $clientService;
+ $this->config = $config;
$this->logger = $logger;
}
@@ -92,7 +97,7 @@ class Gateway implements IGateway {
* @return IGatewayConfig
*/
public function getConfig(): IGatewayConfig {
- // TODO: Implement getConfig() method.
+ return $this->config;
}
}
diff --git a/lib/Service/Gateway/Signal/GatewayConfig.php b/lib/Service/Gateway/Signal/GatewayConfig.php
new file mode 100644
index 0000000..27d76d8
--- /dev/null
+++ b/lib/Service/Gateway/Signal/GatewayConfig.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Pascal Clémot <pascal.clemot@free.fr>
+ *
+ * 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\Signal;
+
+use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig;
+
+class GatewayConfig implements IGatewayConfig {
+
+ public function isComplete(): bool {
+ // TODO: https://github.com/nextcloud/twofactor_gateway/issues/84
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/lib/Service/Gateway/Telegram/Gateway.php b/lib/Service/Gateway/Telegram/Gateway.php
index 0a6b326..77ac483 100644
--- a/lib/Service/Gateway/Telegram/Gateway.php
+++ b/lib/Service/Gateway/Telegram/Gateway.php
@@ -41,12 +41,17 @@ class Gateway implements IGateway {
/** @var IClient */
private $client;
+ /** @var GatewayConfig */
+ private $gatewayConfig;
+
/** @var IConfig */
private $config;
public function __construct(IClientService $clientService,
+ GatewayConfig $gatewayConfig,
IConfig $config) {
$this->client = $clientService->newClient();
+ $this->gatewayConfig = $gatewayConfig;
$this->config = $config;
}
@@ -58,11 +63,10 @@ class Gateway implements IGateway {
* @throws SmsTransmissionException
*/
public function send(IUser $user, string $identifier, string $message) {
- $token = $this->config->getAppValue('twofactor_gateway', 'telegram_bot_token', null);
- // TODO: token missing handling
+ $botToken = $this->gatewayConfig->getBotToken();
- $api = new Api($token);
- $chatId = $this->getChatId($user, $api, (int)$idenfier);
+ $api = new Api($botToken);
+ $chatId = $this->getChatId($user, $api, (int)$identifier);
$api->sendMessage([
'chat_id' => $chatId,
@@ -109,6 +113,6 @@ class Gateway implements IGateway {
* @return IGatewayConfig
*/
public function getConfig(): IGatewayConfig {
- // TODO: Implement getConfig() method.
+ return $this->gatewayConfig;
}
}
diff --git a/lib/Service/Gateway/Telegram/GatewayConfig.php b/lib/Service/Gateway/Telegram/GatewayConfig.php
new file mode 100644
index 0000000..d75bbbe
--- /dev/null
+++ b/lib/Service/Gateway/Telegram/GatewayConfig.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Telegram;
+
+use OCA\TwoFactorGateway\AppInfo\Application;
+use OCA\TwoFactorGateway\Exception\ConfigurationException;
+use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig;
+use OCP\IConfig;
+
+class GatewayConfig implements IGatewayConfig {
+
+ /** @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 getBotToken(): string {
+ return $this->getOrFail('telegram_bot_token');
+ }
+
+ public function isComplete(): bool {
+ $set = $this->config->getAppKeys(Application::APP_NAME);
+ $expected = [
+ 'telegram_bot_token',
+ ];
+ return count(array_intersect($set, $expected)) === count($expected);
+ }
+
+} \ No newline at end of file