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 OCA\TwoFactorGateway\Service\Gateway\IGateway; |
27
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway; |
28
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway; |
29
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
30
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\XMPP\Gateway as XMPPGateway; |
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 XMPPGateway */ |
49
|
|
|
private $xmppGateway; |
50
|
|
|
|
51
|
|
|
/** @var IUserManager */ |
52
|
|
|
private $userManager; |
53
|
|
|
|
54
|
|
|
public function __construct(SignalGateway $signalGateway, |
55
|
|
|
SMSGateway $smsGateway, |
56
|
|
|
TelegramGateway $telegramGateway, |
57
|
|
|
XMPPGateway $xmppGateway, |
58
|
|
|
IUserManager $userManager) { |
59
|
|
|
parent::__construct('twofactorauth:gateway:test'); |
60
|
|
|
$this->signalGateway = $signalGateway; |
61
|
|
|
$this->smsGateway = $smsGateway; |
62
|
|
|
$this->telegramGateway = $telegramGateway; |
63
|
|
|
$this->xmppGateway = $xmppGateway; |
64
|
|
|
$this->userManager = $userManager; |
65
|
|
|
|
66
|
|
|
$this->addArgument( |
67
|
|
|
'uid', |
68
|
|
|
InputArgument::REQUIRED, |
69
|
|
|
'The user id' |
70
|
|
|
); |
71
|
|
|
$this->addArgument( |
72
|
|
|
'gateway', |
73
|
|
|
InputArgument::REQUIRED, |
74
|
|
|
'The name of the gateway, e.g. sms, signal, telegram, xmpp, etc.' |
75
|
|
|
); |
76
|
|
|
$this->addArgument( |
77
|
|
|
'identifier', |
78
|
|
|
InputArgument::REQUIRED, |
79
|
|
|
'The identifier of the recipient , e.g. phone number, user id, etc.' |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
84
|
|
|
$uid = $input->getArgument('uid'); |
85
|
|
|
$user = $this->userManager->get($uid); |
86
|
|
|
if (is_null($user)) { |
87
|
|
|
$output->writeln("<error>Invalid UID</error>"); |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
$gatewayName = $input->getArgument('gateway'); |
91
|
|
|
$identifier = $input->getArgument('identifier'); |
92
|
|
|
|
93
|
|
|
/** @var IGateway $gateway */ |
94
|
|
|
$gateway = null; |
95
|
|
|
switch ($gatewayName) { |
96
|
|
|
case 'signal': |
97
|
|
|
$gateway = $this->signalGateway; |
98
|
|
|
break; |
99
|
|
|
case 'sms': |
100
|
|
|
$gateway = $this->smsGateway; |
101
|
|
|
break; |
102
|
|
|
case 'telegram': |
103
|
|
|
$gateway = $this->telegramGateway; |
104
|
|
|
break; |
105
|
|
|
case 'xmpp': |
106
|
|
|
$gateway = $this->xmppGateway; |
107
|
|
|
break; |
108
|
|
|
default: |
109
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
110
|
|
|
return; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$gateway->send($user, $identifier, 'Test'); |
114
|
|
|
return 0; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
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