|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Christoph Wurst <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* Nextcloud - Two-factor Gateway |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\TwoFactorGateway\Command; |
|
25
|
|
|
|
|
26
|
|
|
use InvalidArgumentException; |
|
27
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\IGateway; |
|
28
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway; |
|
29
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway; |
|
30
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
|
31
|
|
|
use OCP\IUserManager; |
|
32
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
33
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
|
|
34
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
|
|
35
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
class Test extends Command { |
|
38
|
|
|
|
|
39
|
|
|
/** @var SignalGateway */ |
|
40
|
|
|
private $signalGateway; |
|
41
|
|
|
|
|
42
|
|
|
/** @var SMSGateway */ |
|
43
|
|
|
private $smsGateway; |
|
44
|
|
|
|
|
45
|
|
|
/** @var TelegramGateway */ |
|
46
|
|
|
private $telegramGateway; |
|
47
|
|
|
|
|
48
|
|
|
/** @var IUserManager */ |
|
49
|
|
|
private $userManager; |
|
50
|
|
|
|
|
51
|
|
|
public function __construct(SignalGateway $signalGateway, |
|
52
|
|
|
SMSGateway $smsGateway, |
|
53
|
|
|
TelegramGateway $telegramGateway, |
|
54
|
|
|
IUserManager $userManager) { |
|
55
|
|
|
parent::__construct('twofactorauth:gateway:test'); |
|
56
|
|
|
$this->signalGateway = $signalGateway; |
|
57
|
|
|
$this->smsGateway = $smsGateway; |
|
58
|
|
|
$this->telegramGateway = $telegramGateway; |
|
59
|
|
|
$this->userManager = $userManager; |
|
60
|
|
|
|
|
61
|
|
|
$this->addArgument( |
|
62
|
|
|
'uid', |
|
63
|
|
|
InputArgument::REQUIRED, |
|
64
|
|
|
'The user id' |
|
65
|
|
|
); |
|
66
|
|
|
$this->addArgument( |
|
67
|
|
|
'gateway', |
|
68
|
|
|
InputArgument::REQUIRED, |
|
69
|
|
|
'The identifier (e.g. phone number) of the recipient' |
|
70
|
|
|
); |
|
71
|
|
|
$this->addArgument( |
|
72
|
|
|
'identifier', |
|
73
|
|
|
InputArgument::REQUIRED, |
|
74
|
|
|
'The identifier (e.g. phone number) of the recipient' |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
79
|
|
|
$uid = $input->getArgument('uid'); |
|
80
|
|
|
$user = $this->userManager->get($uid); |
|
81
|
|
|
if (is_null($user)) { |
|
82
|
|
|
$output->writeln("<error>Invalid UID</error>"); |
|
83
|
|
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
$gatewayName = $input->getArgument('gateway'); |
|
86
|
|
|
$identifier = $input->getArgument('identifier'); |
|
87
|
|
|
|
|
88
|
|
|
/** @var IGateway $gateway */ |
|
89
|
|
|
$gateway = null; |
|
90
|
|
|
switch ($gatewayName) { |
|
91
|
|
|
case 'signal': |
|
92
|
|
|
$gateway = $this->signalGateway; |
|
93
|
|
|
break; |
|
94
|
|
|
case 'sms': |
|
95
|
|
|
$gateway = $this->smsGateway; |
|
96
|
|
|
break; |
|
97
|
|
|
case 'telegram': |
|
98
|
|
|
$gateway = $this->telegramGateway; |
|
99
|
|
|
break; |
|
100
|
|
|
default: |
|
101
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
|
102
|
|
|
return; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$gateway->send($user, $identifier, 'Test'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths