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\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\SMS\Provider\PuzzelSMSConfig; |
34
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
35
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig as TelegramConfig; |
36
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
37
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
38
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
39
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
40
|
|
|
use Symfony\Component\Console\Question\Question; |
|
|
|
|
41
|
|
|
|
42
|
|
|
class Configure extends Command { |
43
|
|
|
|
44
|
|
|
/** @var SignalGateway */ |
45
|
|
|
private $signalGateway; |
46
|
|
|
|
47
|
|
|
/** @var SMSGateway */ |
48
|
|
|
private $smsGateway; |
49
|
|
|
|
50
|
|
|
/** @var TelegramGateway */ |
51
|
|
|
private $telegramGateway; |
52
|
|
|
|
53
|
|
|
public function __construct(SignalGateway $signalGateway, |
54
|
|
|
SMSGateway $smsGateway, |
55
|
|
|
TelegramGateway $telegramGateway) { |
56
|
|
|
parent::__construct('twofactorauth:gateway:configure'); |
57
|
|
|
$this->signalGateway = $signalGateway; |
58
|
|
|
$this->smsGateway = $smsGateway; |
59
|
|
|
$this->telegramGateway = $telegramGateway; |
60
|
|
|
|
61
|
|
|
$this->addArgument( |
62
|
|
|
'gateway', |
63
|
|
|
InputArgument::REQUIRED, |
64
|
|
|
'The identifier (e.g. phone number) of the recipient' |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
69
|
|
|
$gatewayName = $input->getArgument('gateway'); |
70
|
|
|
|
71
|
|
|
/** @var IGateway $gateway */ |
72
|
|
|
$gateway = null; |
|
|
|
|
73
|
|
|
switch ($gatewayName) { |
74
|
|
|
case 'signal': |
75
|
|
|
$this->configureSignal($input, $output); |
76
|
|
|
break; |
77
|
|
|
case 'sms': |
78
|
|
|
$this->configureSms($input, $output); |
79
|
|
|
break; |
80
|
|
|
case 'telegram': |
81
|
|
|
$this->configureTelegram($input, $output); |
82
|
|
|
break; |
83
|
|
|
default: |
84
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function configureSignal(InputInterface $input, OutputInterface $output) { |
90
|
|
|
$helper = $this->getHelper('question'); |
91
|
|
|
$urlQuestion = new Question('Please enter the URL of the Signal gateway (leave blank to use default): ', 'http://localhost:5000'); |
92
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
93
|
|
|
$output->writeln("Using $url."); |
94
|
|
|
|
95
|
|
|
/** @var SignalConfig $config */ |
96
|
|
|
$config = $this->signalGateway->getConfig(); |
97
|
|
|
|
98
|
|
|
$config->setUrl($url); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function configureSms(InputInterface $input, OutputInterface $output) { |
102
|
|
|
$helper = $this->getHelper('question'); |
103
|
|
|
$providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, puzzelsms): ', 'websms'); |
104
|
|
|
$provider = $helper->ask($input, $output, $providerQuestion); |
105
|
|
|
|
106
|
|
|
/** @var SMSConfig $config */ |
107
|
|
|
$config = $this->smsGateway->getConfig(); |
108
|
|
|
switch ($provider) { |
109
|
|
|
case 'websms': |
110
|
|
|
$config->setProvider($provider); |
111
|
|
|
/** @var WebSmsConfig $providerConfig */ |
112
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
113
|
|
|
|
114
|
|
|
$usernameQuestion = new Question('Please enter your websms.de username: '); |
115
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
116
|
|
|
$passwordQuestion = new Question('Please enter your websms.de password: '); |
117
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
118
|
|
|
|
119
|
|
|
$providerConfig->setUser($username); |
120
|
|
|
$providerConfig->setPassword($password); |
121
|
|
|
|
122
|
|
|
break; |
123
|
|
|
case 'playsms': |
124
|
|
|
$config->setProvider($provider); |
125
|
|
|
/** @var PlaySMSConfig $providerConfig */ |
126
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
127
|
|
|
|
128
|
|
|
$urlQuestion = new Question('Please enter your PlaySMS URL: '); |
129
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
130
|
|
|
$usernameQuestion = new Question('Please enter your PlaySMS username: '); |
131
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
132
|
|
|
$passwordQuestion = new Question('Please enter your PlaySMS password: '); |
133
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
134
|
|
|
|
135
|
|
|
$providerConfig->setUrl($url); |
136
|
|
|
$providerConfig->setUser($username); |
137
|
|
|
$providerConfig->setPassword($password); |
138
|
|
|
|
139
|
|
|
break; |
140
|
|
|
case 'clockworksms': |
141
|
|
|
$config->setProvider($provider); |
142
|
|
|
/** @var ClockworkSmsConfig $providerConfig */ |
143
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
144
|
|
|
|
145
|
|
|
$apitokenQuestion = new Question('Please enter your clockworksms api token: '); |
146
|
|
|
$apitoken = $helper->ask($input, $output, $apitokenQuestion); |
147
|
|
|
|
148
|
|
|
$providerConfig->setApiToken($apitoken); |
149
|
|
|
|
150
|
|
|
break; |
151
|
|
|
case 'puzzelsms': |
152
|
|
|
$config->setProvider($provider); |
153
|
|
|
|
154
|
|
|
/** @var PuzzelSMSConfig $providerConfig */ |
155
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
156
|
|
|
|
157
|
|
|
$urlQuestion = new Question('Please enter your PuzzelSMS URL: '); |
158
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
159
|
|
|
|
160
|
|
|
$usernameQuestion = new Question('Please enter your PuzzelSMS username: '); |
161
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
162
|
|
|
|
163
|
|
|
$passwordQuestion = new Question('Please enter your PuzzelSMS password: '); |
164
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
165
|
|
|
|
166
|
|
|
$serviceQuestion = new Question('Please enter your PuzzelSMS service ID: '); |
167
|
|
|
$serviceId = $helper->ask($input, $output, $serviceQuestion); |
168
|
|
|
|
169
|
|
|
$providerConfig->setUrl($url); |
170
|
|
|
$providerConfig->setUser($username); |
171
|
|
|
$providerConfig->setPassword($password); |
172
|
|
|
$providerConfig->setServiceId($serviceId); |
173
|
|
|
break; |
174
|
|
|
|
175
|
|
|
default: |
176
|
|
|
$output->writeln("Invalid provider $provider"); |
177
|
|
|
break; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
private function configureTelegram(InputInterface $input, OutputInterface $output) { |
183
|
|
|
$helper = $this->getHelper('question'); |
184
|
|
|
$tokenQuestion = new Question('Please enter your Telegram bot token: '); |
185
|
|
|
$token = $helper->ask($input, $output, $tokenQuestion); |
186
|
|
|
$output->writeln("Using $token."); |
187
|
|
|
|
188
|
|
|
/** @var TelegramConfig $config */ |
189
|
|
|
$config = $this->telegramGateway->getConfig(); |
190
|
|
|
|
191
|
|
|
$config->setBotToken($token); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
} |
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