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\ClockworkSMSConfig; |
32
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig; |
33
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig; |
34
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig; |
35
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig; |
36
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config; |
37
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SpryngSMSConfig; |
38
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
39
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig as TelegramConfig; |
40
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
41
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
42
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
43
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
44
|
|
|
use Symfony\Component\Console\Question\Question; |
|
|
|
|
45
|
|
|
|
46
|
|
|
class Configure extends Command { |
47
|
|
|
|
48
|
|
|
/** @var SignalGateway */ |
49
|
|
|
private $signalGateway; |
50
|
|
|
|
51
|
|
|
/** @var SMSGateway */ |
52
|
|
|
private $smsGateway; |
53
|
|
|
|
54
|
|
|
/** @var TelegramGateway */ |
55
|
|
|
private $telegramGateway; |
56
|
|
|
|
57
|
|
|
public function __construct(SignalGateway $signalGateway, |
58
|
|
|
SMSGateway $smsGateway, |
59
|
|
|
TelegramGateway $telegramGateway) { |
60
|
|
|
parent::__construct('twofactorauth:gateway:configure'); |
61
|
|
|
$this->signalGateway = $signalGateway; |
62
|
|
|
$this->smsGateway = $smsGateway; |
63
|
|
|
$this->telegramGateway = $telegramGateway; |
64
|
|
|
|
65
|
|
|
$this->addArgument( |
66
|
|
|
'gateway', |
67
|
|
|
InputArgument::REQUIRED, |
68
|
|
|
'The name of the gateway, e.g. sms, signal, telegram, etc.' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
73
|
|
|
$gatewayName = $input->getArgument('gateway'); |
74
|
|
|
|
75
|
|
|
/** @var IGateway $gateway */ |
76
|
|
|
$gateway = null; |
|
|
|
|
77
|
|
|
switch ($gatewayName) { |
78
|
|
|
case 'signal': |
79
|
|
|
$this->configureSignal($input, $output); |
80
|
|
|
break; |
81
|
|
|
case 'sms': |
82
|
|
|
$this->configureSms($input, $output); |
83
|
|
|
break; |
84
|
|
|
case 'telegram': |
85
|
|
|
$this->configureTelegram($input, $output); |
86
|
|
|
break; |
87
|
|
|
default: |
88
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function configureSignal(InputInterface $input, OutputInterface $output) { |
94
|
|
|
$helper = $this->getHelper('question'); |
95
|
|
|
$urlQuestion = new Question('Please enter the URL of the Signal gateway (leave blank to use default): ', 'http://localhost:5000'); |
96
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
97
|
|
|
$output->writeln("Using $url."); |
98
|
|
|
|
99
|
|
|
/** @var SignalConfig $config */ |
100
|
|
|
$config = $this->signalGateway->getConfig(); |
101
|
|
|
|
102
|
|
|
$config->setUrl($url); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
private function configureSms(InputInterface $input, OutputInterface $output) { |
106
|
|
|
$helper = $this->getHelper('question'); |
107
|
|
|
$providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, huawei_e3531, spryng): ', 'websms'); |
108
|
|
|
$provider = $helper->ask($input, $output, $providerQuestion); |
109
|
|
|
|
110
|
|
|
/** @var SMSConfig $config */ |
111
|
|
|
$config = $this->smsGateway->getConfig(); |
112
|
|
|
switch ($provider) { |
113
|
|
|
case 'websms': |
114
|
|
|
$config->setProvider($provider); |
115
|
|
|
/** @var WebSmsConfig $providerConfig */ |
116
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
117
|
|
|
|
118
|
|
|
$usernameQuestion = new Question('Please enter your websms.de username: '); |
119
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
120
|
|
|
$passwordQuestion = new Question('Please enter your websms.de password: '); |
121
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
122
|
|
|
|
123
|
|
|
$providerConfig->setUser($username); |
124
|
|
|
$providerConfig->setPassword($password); |
125
|
|
|
|
126
|
|
|
break; |
127
|
|
|
case 'playsms': |
128
|
|
|
$config->setProvider($provider); |
129
|
|
|
/** @var PlaySMSConfig $providerConfig */ |
130
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
131
|
|
|
|
132
|
|
|
$urlQuestion = new Question('Please enter your PlaySMS URL: '); |
133
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
134
|
|
|
$usernameQuestion = new Question('Please enter your PlaySMS username: '); |
135
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
136
|
|
|
$passwordQuestion = new Question('Please enter your PlaySMS password: '); |
137
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
138
|
|
|
|
139
|
|
|
$providerConfig->setUrl($url); |
140
|
|
|
$providerConfig->setUser($username); |
141
|
|
|
$providerConfig->setPassword($password); |
142
|
|
|
|
143
|
|
|
break; |
144
|
|
|
case 'clockworksms': |
145
|
|
|
$config->setProvider($provider); |
146
|
|
|
/** @var ClockworkSMSConfig $providerConfig */ |
147
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
148
|
|
|
|
149
|
|
|
$apitokenQuestion = new Question('Please enter your clockworksms api token: '); |
150
|
|
|
$apitoken = $helper->ask($input, $output, $apitokenQuestion); |
151
|
|
|
|
152
|
|
|
$providerConfig->setApiToken($apitoken); |
153
|
|
|
|
154
|
|
|
break; |
155
|
|
|
case 'puzzelsms': |
156
|
|
|
$config->setProvider($provider); |
157
|
|
|
|
158
|
|
|
/** @var PuzzelSMSConfig $providerConfig */ |
159
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
160
|
|
|
|
161
|
|
|
$urlQuestion = new Question('Please enter your PuzzelSMS URL: '); |
162
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
163
|
|
|
|
164
|
|
|
$usernameQuestion = new Question('Please enter your PuzzelSMS username: '); |
165
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
166
|
|
|
|
167
|
|
|
$passwordQuestion = new Question('Please enter your PuzzelSMS password: '); |
168
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
169
|
|
|
|
170
|
|
|
$serviceQuestion = new Question('Please enter your PuzzelSMS service ID: '); |
171
|
|
|
$serviceId = $helper->ask($input, $output, $serviceQuestion); |
172
|
|
|
|
173
|
|
|
$providerConfig->setUrl($url); |
174
|
|
|
$providerConfig->setUser($username); |
175
|
|
|
$providerConfig->setPassword($password); |
176
|
|
|
$providerConfig->setServiceId($serviceId); |
177
|
|
|
break; |
178
|
|
|
case 'ecallsms': |
179
|
|
|
$config->setProvider($provider); |
180
|
|
|
/** @var EcallSMSConfig $providerConfig */ |
181
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
182
|
|
|
|
183
|
|
|
$usernameQuestion = new Question('Please enter your eCall.ch username: '); |
184
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
185
|
|
|
$passwordQuestion = new Question('Please enter your eCall.ch password: '); |
186
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
187
|
|
|
$senderIdQuestion = new Question('Please enter your eCall.ch sender ID: '); |
188
|
|
|
$senderId = $helper->ask($input, $output, $senderIdQuestion); |
189
|
|
|
|
190
|
|
|
$providerConfig->setUser($username); |
191
|
|
|
$providerConfig->setPassword($password); |
192
|
|
|
$providerConfig->setSenderId($senderId); |
193
|
|
|
break; |
194
|
|
|
|
195
|
|
|
case 'voipms': |
196
|
|
|
$config->setProvider($provider); |
197
|
|
|
|
198
|
|
|
/** @var VoipMsConfig $providerConfig */ |
199
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
200
|
|
|
|
201
|
|
|
$usernameQuestion = new Question('Please enter your VoIP.ms API username: '); |
202
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
203
|
|
|
|
204
|
|
|
$passwordQuestion = new Question('Please enter your VoIP.ms API password: '); |
205
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
206
|
|
|
|
207
|
|
|
$didQuestion = new Question('Please enter your VoIP.ms DID: '); |
208
|
|
|
$did = $helper->ask($input, $output, $didQuestion); |
209
|
|
|
|
210
|
|
|
$providerConfig->setUser($username); |
211
|
|
|
$providerConfig->setPassword($password); |
212
|
|
|
$providerConfig->setDid($did); |
213
|
|
|
break; |
214
|
|
|
|
215
|
|
|
case 'huawei_e3531': |
216
|
|
|
$config->setProvider($provider); |
217
|
|
|
/** @var HuaweiE3531Config $providerConfig */ |
218
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
219
|
|
|
|
220
|
|
|
$urlQuestion = new Question('Please enter the base URL of the Huawei E3531 stick: ', 'http://192.168.8.1/api'); |
221
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
222
|
|
|
|
223
|
|
|
$providerConfig->setUrl($url); |
224
|
|
|
break; |
225
|
|
|
|
226
|
|
|
case 'spryng': |
227
|
|
|
$config->setProvider($provider); |
228
|
|
|
/** @var SpryngSMSConfig $providerConfig */ |
229
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
230
|
|
|
|
231
|
|
|
$apitokenQuestion = new Question('Please enter your Spryng api token: '); |
232
|
|
|
$apitoken = $helper->ask($input, $output, $apitokenQuestion); |
233
|
|
|
|
234
|
|
|
$providerConfig->setApiToken($apitoken); |
235
|
|
|
|
236
|
|
|
break; |
237
|
|
|
|
238
|
|
|
default: |
239
|
|
|
$output->writeln("Invalid provider $provider"); |
240
|
|
|
break; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
private function configureTelegram(InputInterface $input, OutputInterface $output) { |
246
|
|
|
$helper = $this->getHelper('question'); |
247
|
|
|
$tokenQuestion = new Question('Please enter your Telegram bot token: '); |
248
|
|
|
$token = $helper->ask($input, $output, $tokenQuestion); |
249
|
|
|
$output->writeln("Using $token."); |
250
|
|
|
|
251
|
|
|
/** @var TelegramConfig $config */ |
252
|
|
|
$config = $this->telegramGateway->getConfig(); |
253
|
|
|
|
254
|
|
|
$config->setBotToken($token); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
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