diff options
-rw-r--r-- | appinfo/app.php | 21 | ||||
-rw-r--r-- | appinfo/info.xml | 1 | ||||
-rw-r--r-- | composer.lock | 83 | ||||
-rw-r--r-- | lib/Command/Test.php | 108 | ||||
-rw-r--r-- | lib/Service/Gateway/Signal/Gateway.php | 2 | ||||
-rw-r--r-- | lib/Service/Gateway/Telegram/Gateway.php | 3 |
6 files changed, 176 insertions, 42 deletions
diff --git a/appinfo/app.php b/appinfo/app.php new file mode 100644 index 0000000..6151a35 --- /dev/null +++ b/appinfo/app.php @@ -0,0 +1,21 @@ +<?php + +/** + * @author Christoph Wurst <christoph@winzerhof-wurst.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/> + * + */ +include_once __DIR__ . '/../vendor/autoload.php'; diff --git a/appinfo/info.xml b/appinfo/info.xml index 8fb6595..27ff9a3 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -24,6 +24,7 @@ </two-factor-providers> <commands> <command>OCA\TwoFactorGateway\Command\Status</command> + <command>OCA\TwoFactorGateway\Command\Test</command> </commands> <settings> <personal>OCA\TwoFactorGateway\Settings\PersonalSettings</personal> diff --git a/composer.lock b/composer.lock index 453f410..c52b952 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "92c0d4ef07e513c6cdc0679168ebc6f6", + "content-hash": "94af12097543679fd01990da4c35d94f", "packages": [ { "name": "christophwurst/nextcloud", - "version": "dev-master", + "version": "14.0.0-beta2", "source": { "type": "git", "url": "https://github.com/ChristophWurst/nextcloud_composer.git", - "reference": "4328f1856719cfcfe1bd0d9f7d25302856fcf620" + "reference": "8dc33a2dd909c8bca0a77de1dd6b996cebf92e7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/4328f1856719cfcfe1bd0d9f7d25302856fcf620", - "reference": "4328f1856719cfcfe1bd0d9f7d25302856fcf620", + "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/8dc33a2dd909c8bca0a77de1dd6b996cebf92e7e", + "reference": "8dc33a2dd909c8bca0a77de1dd6b996cebf92e7e", "shasum": "" }, "type": "library", @@ -37,7 +37,7 @@ } ], "description": "Composer package containing Nextcloud's public API (classes, interfaces)", - "time": "2018-08-02T15:28:13+00:00" + "time": "2018-08-07T05:05:28+00:00" }, { "name": "doctrine/inflector", @@ -289,7 +289,7 @@ }, { "name": "illuminate/contracts", - "version": "v5.5.40", + "version": "v5.5.41", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -333,16 +333,16 @@ }, { "name": "illuminate/support", - "version": "v5.5.40", + "version": "v5.5.41", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "5d2ccb17e526ad537bffc16abc1d516457ae5587" + "reference": "b93ddc422cf2b14e3d0237c775e5deb57d849bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/5d2ccb17e526ad537bffc16abc1d516457ae5587", - "reference": "5d2ccb17e526ad537bffc16abc1d516457ae5587", + "url": "https://api.github.com/repos/illuminate/support/zipball/b93ddc422cf2b14e3d0237c775e5deb57d849bd8", + "reference": "b93ddc422cf2b14e3d0237c775e5deb57d849bd8", "shasum": "" }, "require": { @@ -386,7 +386,7 @@ ], "description": "The Illuminate Support package.", "homepage": "https://laravel.com", - "time": "2018-03-10T15:44:32+00:00" + "time": "2018-06-08T13:45:23+00:00" }, { "name": "irazasyed/telegram-bot-sdk", @@ -511,16 +511,16 @@ }, { "name": "nesbot/carbon", - "version": "1.31.0", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "4dbe0e51d24a4c7e000999324d21fc25edbf7b05" + "reference": "55667c1007a99e82030874b1bb14d24d07108413" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4dbe0e51d24a4c7e000999324d21fc25edbf7b05", - "reference": "4dbe0e51d24a4c7e000999324d21fc25edbf7b05", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/55667c1007a99e82030874b1bb14d24d07108413", + "reference": "55667c1007a99e82030874b1bb14d24d07108413", "shasum": "" }, "require": { @@ -562,7 +562,7 @@ "datetime", "time" ], - "time": "2018-06-24T14:32:22+00:00" + "time": "2018-08-07T08:39:47+00:00" }, { "name": "psr/container", @@ -713,16 +713,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -734,7 +734,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -768,7 +768,7 @@ "portable", "shim" ], - "time": "2018-04-26T10:06:28+00:00" + "time": "2018-08-06T14:22:27+00:00" }, { "name": "symfony/translation", @@ -933,34 +933,39 @@ }, { "name": "facebook/webdriver", - "version": "1.5.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/facebook/php-webdriver.git", - "reference": "86b5ca2f67173c9d34340845dd690149c886a605" + "reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/86b5ca2f67173c9d34340845dd690149c886a605", - "reference": "86b5ca2f67173c9d34340845dd690149c886a605", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/bd8c740097eb9f2fc3735250fc1912bc811a954e", + "reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e", "shasum": "" }, "require": { "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", "ext-zip": "*", "php": "^5.6 || ~7.0", "symfony/process": "^2.8 || ^3.1 || ^4.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", - "guzzle/guzzle": "^3.4.1", - "php-coveralls/php-coveralls": "^1.0.2", + "jakub-onderka/php-parallel-lint": "^0.9.2", + "php-coveralls/php-coveralls": "^2.0", "php-mock/php-mock-phpunit": "^1.1", "phpunit/phpunit": "^5.7", "sebastian/environment": "^1.3.4 || ^2.0 || ^3.0", "squizlabs/php_codesniffer": "^2.6", "symfony/var-dumper": "^3.3 || ^4.0" }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, "type": "library", "extra": { "branch-alias": { @@ -984,7 +989,7 @@ "selenium", "webdriver" ], - "time": "2017-11-15T11:08:09+00:00" + "time": "2018-05-16T17:37:13+00:00" }, { "name": "myclabs/deep-copy", @@ -1185,33 +1190,33 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.5", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -1244,7 +1249,7 @@ "spy", "stub" ], - "time": "2018-02-19T10:16:54+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2307,7 +2312,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "christophwurst/nextcloud": 20 + "christophwurst/nextcloud": 10 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/lib/Command/Test.php b/lib/Command/Test.php new file mode 100644 index 0000000..fd336be --- /dev/null +++ b/lib/Command/Test.php @@ -0,0 +1,108 @@ +<?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 InvalidArgumentException; +use OCA\TwoFactorGateway\Service\Gateway\IGateway; +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 OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Test extends Command { + + /** @var SignalGateway */ + private $signalGateway; + + /** @var SMSGateway */ + private $smsGateway; + + /** @var TelegramGateway */ + private $telegramGateway; + + /** @var IUserManager */ + private $userManager; + + public function __construct(SignalGateway $signalGateway, + SMSGateway $smsGateway, + TelegramGateway $telegramGateway, + IUserManager $userManager) { + parent::__construct('twofactorauth:gateway:test'); + $this->signalGateway = $signalGateway; + $this->smsGateway = $smsGateway; + $this->telegramGateway = $telegramGateway; + $this->userManager = $userManager; + + $this->addArgument( + 'uid', + InputArgument::REQUIRED, + 'The user id' + ); + $this->addArgument( + 'gateway', + InputArgument::REQUIRED, + 'The identifier (e.g. phone number) of the recipient' + ); + $this->addArgument( + 'identifier', + InputArgument::REQUIRED, + 'The identifier (e.g. phone number) of the recipient' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $uid = $input->getArgument('uid'); + $user = $this->userManager->get($uid); + if (is_null($user)) { + $output->writeln("<error>Invalid UID</error>"); + return; + } + $gatewayName = $input->getArgument('gateway'); + $identifier = $input->getArgument('identifier'); + + /** @var IGateway $gateway */ + $gateway = null; + switch ($gatewayName) { + case 'signal': + $gateway = $this->signalGateway; + break; + case 'sms': + $gateway = $this->smsGateway; + break; + case 'telegram': + $gateway = $this->telegramGateway; + break; + default: + $output->writeln("<error>Invalid gateway $gatewayName</error>"); + return; + } + + $gateway->send($user, $identifier, 'Test'); + } + +}
\ No newline at end of file diff --git a/lib/Service/Gateway/Signal/Gateway.php b/lib/Service/Gateway/Signal/Gateway.php index 821aa0d..a716109 100644 --- a/lib/Service/Gateway/Signal/Gateway.php +++ b/lib/Service/Gateway/Signal/Gateway.php @@ -68,7 +68,7 @@ class Gateway implements IGateway { $client = $this->clientService->newClient(); $response = $client->post($endpoint, [ 'body' => [ - 'to' => $idenfier, + 'to' => $identifier, 'message' => $message, ], ]); diff --git a/lib/Service/Gateway/Telegram/Gateway.php b/lib/Service/Gateway/Telegram/Gateway.php index 77ac483..f8295ad 100644 --- a/lib/Service/Gateway/Telegram/Gateway.php +++ b/lib/Service/Gateway/Telegram/Gateway.php @@ -24,14 +24,12 @@ declare(strict_types=1); namespace OCA\TwoFactorGateway\Service\Gateway\Telegram; -use Exception; use OCA\TwoFactorGateway\Exception\SmsTransmissionException; use OCA\TwoFactorGateway\Service\Gateway\IGateway; use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\IL10N; use OCP\IUser; use Telegram\Bot\Api; use Telegram\Bot\Objects\Update; @@ -115,4 +113,5 @@ class Gateway implements IGateway { public function getConfig(): IGatewayConfig { return $this->gatewayConfig; } + } |