1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Pascal Clémot <[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\Signal\GatewayConfig as SignalConfig; |
29
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway; |
30
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\GatewayConfig as SMSConfig; |
31
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig; |
32
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig; |
33
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
34
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
35
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
36
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
37
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
38
|
|
|
use Symfony\Component\Console\Question\Question; |
|
|
|
|
39
|
|
|
|
40
|
|
|
class Configure extends Command { |
41
|
|
|
|
42
|
|
|
/** @var SignalGateway */ |
43
|
|
|
private $signalGateway; |
44
|
|
|
|
45
|
|
|
/** @var SMSGateway */ |
46
|
|
|
private $smsGateway; |
47
|
|
|
|
48
|
|
|
/** @var TelegramGateway */ |
49
|
|
|
private $telegramGateway; |
50
|
|
|
|
51
|
|
|
public function __construct(SignalGateway $signalGateway, |
52
|
|
|
SMSGateway $smsGateway, |
53
|
|
|
TelegramGateway $telegramGateway) { |
54
|
|
|
parent::__construct('twofactorauth:gateway:configure'); |
55
|
|
|
$this->signalGateway = $signalGateway; |
56
|
|
|
$this->smsGateway = $smsGateway; |
57
|
|
|
$this->telegramGateway = $telegramGateway; |
58
|
|
|
|
59
|
|
|
$this->addArgument( |
60
|
|
|
'gateway', |
61
|
|
|
InputArgument::REQUIRED, |
62
|
|
|
'The identifier (e.g. phone number) of the recipient' |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
67
|
|
|
$gatewayName = $input->getArgument('gateway'); |
68
|
|
|
|
69
|
|
|
/** @var IGateway $gateway */ |
70
|
|
|
$gateway = null; |
|
|
|
|
71
|
|
|
switch ($gatewayName) { |
72
|
|
|
case 'signal': |
73
|
|
|
$this->configureSignal($input, $output); |
74
|
|
|
break; |
75
|
|
|
case 'sms': |
76
|
|
|
$this->configureSms($input, $output); |
77
|
|
|
break; |
78
|
|
|
case 'telegram': |
79
|
|
|
$this->configureTelegram($input, $output); |
80
|
|
|
break; |
81
|
|
|
default: |
82
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
private function configureSignal(InputInterface $input, OutputInterface $output) { |
88
|
|
|
$helper = $this->getHelper('question'); |
89
|
|
|
$urlQuestion = new Question('Please enter the URL of the Signal gateway (leave blank to use default): ', 'http://localhost:5000'); |
90
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
91
|
|
|
$output->writeln("Using $url."); |
92
|
|
|
|
93
|
|
|
/** @var SignalConfig $config */ |
94
|
|
|
$config = $this->signalGateway->getConfig(); |
95
|
|
|
|
96
|
|
|
$config->setUrl($url); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function configureSms(InputInterface $input, OutputInterface $output) { |
100
|
|
|
$helper = $this->getHelper('question'); |
101
|
|
|
$providerQuestion = new Question('Please choose a SMS provider (websms, playsms): ', 'websms'); |
102
|
|
|
$provider = $helper->ask($input, $output, $providerQuestion); |
103
|
|
|
|
104
|
|
|
/** @var SMSConfig $config */ |
105
|
|
|
$config = $this->smsGateway->getConfig(); |
106
|
|
|
switch ($provider) { |
107
|
|
|
case 'websms': |
108
|
|
|
$config->setProvider($provider); |
109
|
|
|
/** @var WebSmsConfig $providerConfig */ |
110
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
111
|
|
|
|
112
|
|
|
$usernameQuestion = new Question('Please enter your websms.de username: '); |
113
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
114
|
|
|
$passwordQuestion = new Question('Please enter your websms.de password: '); |
115
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
116
|
|
|
|
117
|
|
|
$providerConfig->setUser($username); |
118
|
|
|
$providerConfig->setPassword($password); |
119
|
|
|
|
120
|
|
|
break; |
121
|
|
|
case 'playsms': |
122
|
|
|
$config->setProvider($provider); |
123
|
|
|
/** @var PlaySMSConfig $providerConfig */ |
124
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
125
|
|
|
|
126
|
|
|
$urlQuestion = new Question('Please enter your PlaySMS URL: '); |
127
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
128
|
|
|
$usernameQuestion = new Question('Please enter your PlaySMS username: '); |
129
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
130
|
|
|
$passwordQuestion = new Question('Please enter your PlaySMS password: '); |
131
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
132
|
|
|
|
133
|
|
|
$providerConfig->setUrl($url); |
134
|
|
|
$providerConfig->setUser($username); |
135
|
|
|
$providerConfig->setPassword($password); |
136
|
|
|
|
137
|
|
|
break; |
138
|
|
|
default: |
139
|
|
|
$output->writeln("Invalid provider $provider"); |
140
|
|
|
break; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function configureTelegram(InputInterface $input, OutputInterface $output) { |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
} |
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