|
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\ClickSendConfig; |
|
32
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClockworkSMSConfig; |
|
33
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig; |
|
34
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig; |
|
35
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SMSGlobalConfig; |
|
36
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\Sms77IoConfig; |
|
37
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\OvhConfig; |
|
38
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig; |
|
39
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SipGateConfig; |
|
40
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig; |
|
41
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config; |
|
42
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SpryngSMSConfig; |
|
43
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickatellCentralConfig; |
|
44
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickatellPortalConfig; |
|
45
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\VoipbusterConfig; |
|
46
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SerwerSMSConfig; |
|
47
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
|
48
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig as TelegramConfig; |
|
49
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\XMPP\Gateway as XMPPGateway; |
|
50
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\XMPP\GatewayConfig as XMPPConfig; |
|
51
|
|
|
use Symfony\Component\Console\Command\Command; |
|
52
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
53
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
54
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
55
|
|
|
use Symfony\Component\Console\Question\Question; |
|
56
|
|
|
|
|
57
|
|
|
class Configure extends Command { |
|
58
|
|
|
|
|
59
|
|
|
/** @var SignalGateway */ |
|
60
|
|
|
private $signalGateway; |
|
61
|
|
|
|
|
62
|
|
|
/** @var SMSGateway */ |
|
63
|
|
|
private $smsGateway; |
|
64
|
|
|
|
|
65
|
|
|
/** @var TelegramGateway */ |
|
66
|
|
|
private $telegramGateway; |
|
67
|
|
|
|
|
68
|
|
|
/** @var XMPPGateway */ |
|
69
|
|
|
private $xmppGateway; |
|
70
|
|
|
|
|
71
|
|
|
public function __construct(SignalGateway $signalGateway, |
|
72
|
|
|
SMSGateway $smsGateway, |
|
73
|
|
|
TelegramGateway $telegramGateway, |
|
74
|
|
|
XMPPGateway $xmppGateway) { |
|
75
|
|
|
parent::__construct('twofactorauth:gateway:configure'); |
|
76
|
|
|
$this->signalGateway = $signalGateway; |
|
77
|
|
|
$this->smsGateway = $smsGateway; |
|
78
|
|
|
$this->telegramGateway = $telegramGateway; |
|
79
|
|
|
$this->xmppGateway = $xmppGateway; |
|
80
|
|
|
|
|
81
|
|
|
$this->addArgument( |
|
82
|
|
|
'gateway', |
|
83
|
|
|
InputArgument::REQUIRED, |
|
84
|
|
|
'The name of the gateway, e.g. sms, signal, telegram, xmpp, etc.' |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
89
|
|
|
$gatewayName = $input->getArgument('gateway'); |
|
90
|
|
|
|
|
91
|
|
|
/** @var IGateway $gateway */ |
|
92
|
|
|
$gateway = null; |
|
|
|
|
|
|
93
|
|
|
switch ($gatewayName) { |
|
94
|
|
|
case 'signal': |
|
95
|
|
|
$this->configureSignal($input, $output); |
|
96
|
|
|
return 0; |
|
97
|
|
|
case 'sms': |
|
98
|
|
|
$this->configureSms($input, $output); |
|
99
|
|
|
return 0; |
|
100
|
|
|
case 'telegram': |
|
101
|
|
|
$this->configureTelegram($input, $output); |
|
102
|
|
|
return 0; |
|
103
|
|
|
case 'xmpp': |
|
104
|
|
|
$this->configureXMPP($input, $output); |
|
105
|
|
|
return 0; |
|
106
|
|
|
default: |
|
107
|
|
|
$output->writeln("<error>Invalid gateway $gatewayName</error>"); |
|
108
|
|
|
return; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
private function configureSignal(InputInterface $input, OutputInterface $output) { |
|
113
|
|
|
$helper = $this->getHelper('question'); |
|
114
|
|
|
$urlQuestion = new Question('Please enter the URL of the Signal gateway (leave blank to use default): ', 'http://localhost:5000'); |
|
115
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
|
116
|
|
|
$output->writeln("Using $url."); |
|
117
|
|
|
|
|
118
|
|
|
/** @var SignalConfig $config */ |
|
119
|
|
|
$config = $this->signalGateway->getConfig(); |
|
120
|
|
|
|
|
121
|
|
|
$config->setUrl($url); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
private function configureSms(InputInterface $input, OutputInterface $output) { |
|
125
|
|
|
$helper = $this->getHelper('question'); |
|
126
|
|
|
|
|
127
|
|
|
$providerQuestion = new Question('Please choose a SMS provider (sipgate, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clickatellportal, clicksend, serwersms, smsglobal, smsapi.com): ', 'websms'); |
|
128
|
|
|
$provider = $helper->ask($input, $output, $providerQuestion); |
|
129
|
|
|
|
|
130
|
|
|
/** @var SMSConfig $config */ |
|
131
|
|
|
$config = $this->smsGateway->getConfig(); |
|
132
|
|
|
switch ($provider) { |
|
133
|
|
|
case 'websms': |
|
134
|
|
|
$config->setProvider($provider); |
|
135
|
|
|
/** @var WebSmsConfig $providerConfig */ |
|
136
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
137
|
|
|
|
|
138
|
|
|
$usernameQuestion = new Question('Please enter your websms.de username: '); |
|
139
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
140
|
|
|
$passwordQuestion = new Question('Please enter your websms.de password: '); |
|
141
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
142
|
|
|
|
|
143
|
|
|
$providerConfig->setUser($username); |
|
144
|
|
|
$providerConfig->setPassword($password); |
|
145
|
|
|
break; |
|
146
|
|
|
|
|
147
|
|
|
case 'sipgate': |
|
148
|
|
|
$config->setProvider($provider); |
|
149
|
|
|
/** @var SipGateConfig $providerConfig */ |
|
150
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
151
|
|
|
|
|
152
|
|
|
$tokenIdQuestion = new Question('Please enter your sipgate token-id: '); |
|
153
|
|
|
$tokenId = $helper->ask($input, $output, $tokenIdQuestion); |
|
154
|
|
|
$accessTokenQuestion = new Question('Please enter your sipgate access token: '); |
|
155
|
|
|
$accessToken = $helper->ask($input, $output, $accessTokenQuestion); |
|
156
|
|
|
$webSmsExtensionQuestion = new Question('Please enter your sipgate web-sms extension: '); |
|
157
|
|
|
$webSmsExtension = $helper->ask($input, $output, $webSmsExtensionQuestion); |
|
158
|
|
|
|
|
159
|
|
|
$providerConfig->setTokenId($tokenId); |
|
160
|
|
|
$providerConfig->setAccessToken($accessToken); |
|
161
|
|
|
$providerConfig->setWebSmsExtension($webSmsExtension); |
|
162
|
|
|
break; |
|
163
|
|
|
|
|
164
|
|
|
case 'playsms': |
|
165
|
|
|
$config->setProvider($provider); |
|
166
|
|
|
/** @var PlaySMSConfig $providerConfig */ |
|
167
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
168
|
|
|
|
|
169
|
|
|
$urlQuestion = new Question('Please enter your PlaySMS URL: '); |
|
170
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
|
171
|
|
|
$usernameQuestion = new Question('Please enter your PlaySMS username: '); |
|
172
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
173
|
|
|
$passwordQuestion = new Question('Please enter your PlaySMS password: '); |
|
174
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
175
|
|
|
|
|
176
|
|
|
$providerConfig->setUrl($url); |
|
177
|
|
|
$providerConfig->setUser($username); |
|
178
|
|
|
$providerConfig->setPassword($password); |
|
179
|
|
|
break; |
|
180
|
|
|
|
|
181
|
|
|
case 'clockworksms': |
|
182
|
|
|
$config->setProvider($provider); |
|
183
|
|
|
/** @var ClockworkSMSConfig $providerConfig */ |
|
184
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
185
|
|
|
|
|
186
|
|
|
$apitokenQuestion = new Question('Please enter your clockworksms api token: '); |
|
187
|
|
|
$apitoken = $helper->ask($input, $output, $apitokenQuestion); |
|
188
|
|
|
|
|
189
|
|
|
$providerConfig->setApiToken($apitoken); |
|
190
|
|
|
break; |
|
191
|
|
|
|
|
192
|
|
|
case 'puzzelsms': |
|
193
|
|
|
$config->setProvider($provider); |
|
194
|
|
|
|
|
195
|
|
|
/** @var PuzzelSMSConfig $providerConfig */ |
|
196
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
197
|
|
|
|
|
198
|
|
|
$urlQuestion = new Question('Please enter your PuzzelSMS URL: '); |
|
199
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
|
200
|
|
|
|
|
201
|
|
|
$usernameQuestion = new Question('Please enter your PuzzelSMS username: '); |
|
202
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
203
|
|
|
|
|
204
|
|
|
$passwordQuestion = new Question('Please enter your PuzzelSMS password: '); |
|
205
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
206
|
|
|
|
|
207
|
|
|
$serviceQuestion = new Question('Please enter your PuzzelSMS service ID: '); |
|
208
|
|
|
$serviceId = $helper->ask($input, $output, $serviceQuestion); |
|
209
|
|
|
|
|
210
|
|
|
$providerConfig->setUrl($url); |
|
211
|
|
|
$providerConfig->setUser($username); |
|
212
|
|
|
$providerConfig->setPassword($password); |
|
213
|
|
|
$providerConfig->setServiceId($serviceId); |
|
214
|
|
|
break; |
|
215
|
|
|
|
|
216
|
|
|
case 'ecallsms': |
|
217
|
|
|
$config->setProvider($provider); |
|
218
|
|
|
/** @var EcallSMSConfig $providerConfig */ |
|
219
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
220
|
|
|
|
|
221
|
|
|
$usernameQuestion = new Question('Please enter your eCall.ch username: '); |
|
222
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
223
|
|
|
$passwordQuestion = new Question('Please enter your eCall.ch password: '); |
|
224
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
225
|
|
|
$senderIdQuestion = new Question('Please enter your eCall.ch sender ID: '); |
|
226
|
|
|
$senderId = $helper->ask($input, $output, $senderIdQuestion); |
|
227
|
|
|
|
|
228
|
|
|
$providerConfig->setUser($username); |
|
229
|
|
|
$providerConfig->setPassword($password); |
|
230
|
|
|
$providerConfig->setSenderId($senderId); |
|
231
|
|
|
break; |
|
232
|
|
|
|
|
233
|
|
|
case 'voipms': |
|
234
|
|
|
$config->setProvider($provider); |
|
235
|
|
|
|
|
236
|
|
|
/** @var VoipMsConfig $providerConfig */ |
|
237
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
238
|
|
|
|
|
239
|
|
|
$usernameQuestion = new Question('Please enter your VoIP.ms API username: '); |
|
240
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
241
|
|
|
|
|
242
|
|
|
$passwordQuestion = new Question('Please enter your VoIP.ms API password: '); |
|
243
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
244
|
|
|
|
|
245
|
|
|
$didQuestion = new Question('Please enter your VoIP.ms DID: '); |
|
246
|
|
|
$did = $helper->ask($input, $output, $didQuestion); |
|
247
|
|
|
|
|
248
|
|
|
$providerConfig->setUser($username); |
|
249
|
|
|
$providerConfig->setPassword($password); |
|
250
|
|
|
$providerConfig->setDid($did); |
|
251
|
|
|
break; |
|
252
|
|
|
|
|
253
|
|
|
case 'voipbuster': |
|
254
|
|
|
$config->setProvider($provider); |
|
255
|
|
|
|
|
256
|
|
|
/** @var VoipbusterConfig $providerConfig */ |
|
257
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
258
|
|
|
|
|
259
|
|
|
$usernameQuestion = new Question('Please enter your Voipbuster API username: '); |
|
260
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
261
|
|
|
|
|
262
|
|
|
$passwordQuestion = new Question('Please enter your Voipbuster API password: '); |
|
263
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
264
|
|
|
|
|
265
|
|
|
$didQuestion = new Question('Please enter your Voipbuster DID: '); |
|
266
|
|
|
$did = $helper->ask($input, $output, $didQuestion); |
|
267
|
|
|
|
|
268
|
|
|
$providerConfig->setUser($username); |
|
269
|
|
|
$providerConfig->setPassword($password); |
|
270
|
|
|
$providerConfig->setDid($did); |
|
271
|
|
|
break; |
|
272
|
|
|
|
|
273
|
|
|
case 'huawei_e3531': |
|
274
|
|
|
$config->setProvider($provider); |
|
275
|
|
|
/** @var HuaweiE3531Config $providerConfig */ |
|
276
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
277
|
|
|
|
|
278
|
|
|
$urlQuestion = new Question('Please enter the base URL of the Huawei E3531 stick: ', 'http://192.168.8.1/api'); |
|
279
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
|
280
|
|
|
|
|
281
|
|
|
$providerConfig->setUrl($url); |
|
282
|
|
|
break; |
|
283
|
|
|
|
|
284
|
|
|
case 'spryng': |
|
285
|
|
|
$config->setProvider($provider); |
|
286
|
|
|
/** @var SpryngSMSConfig $providerConfig */ |
|
287
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
288
|
|
|
|
|
289
|
|
|
$apitokenQuestion = new Question('Please enter your Spryng api token: '); |
|
290
|
|
|
$apitoken = $helper->ask($input, $output, $apitokenQuestion); |
|
291
|
|
|
|
|
292
|
|
|
$providerConfig->setApiToken($apitoken); |
|
293
|
|
|
break; |
|
294
|
|
|
|
|
295
|
|
|
case 'sms77io': |
|
296
|
|
|
$config->setProvider($provider); |
|
297
|
|
|
/** @var Sms77IoConfig $providerConfig */ |
|
298
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
299
|
|
|
|
|
300
|
|
|
$apiKeyQuestion = new Question('Please enter your sms77.io API key: '); |
|
301
|
|
|
$apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
|
302
|
|
|
|
|
303
|
|
|
$providerConfig->setApiKey($apiKey); |
|
304
|
|
|
break; |
|
305
|
|
|
|
|
306
|
|
|
case 'ovh': |
|
307
|
|
|
$config->setProvider($provider); |
|
308
|
|
|
|
|
309
|
|
|
/** @var OvhConfig $providerConfig */ |
|
310
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
311
|
|
|
|
|
312
|
|
|
$endpointQ = new Question('Please enter the endpoint to use (ovh-eu, ovh-us, ovh-ca, soyoustart-eu, soyoustart-ca, kimsufi-eu, kimsufi-ca, runabove-ca): '); |
|
313
|
|
|
$endpoint = $helper->ask($input, $output, $endpointQ); |
|
314
|
|
|
|
|
315
|
|
|
$appKeyQ = new Question('Please enter your application key: '); |
|
316
|
|
|
$appKey = $helper->ask($input, $output, $appKeyQ); |
|
317
|
|
|
|
|
318
|
|
|
$appSecretQ = new Question('Please enter your application secret: '); |
|
319
|
|
|
$appSecret = $helper->ask($input, $output, $appSecretQ); |
|
320
|
|
|
|
|
321
|
|
|
$consumerKeyQ = new Question('Please enter your consumer key: '); |
|
322
|
|
|
$consumerKey = $helper->ask($input, $output, $consumerKeyQ); |
|
323
|
|
|
|
|
324
|
|
|
$accountQ = new Question('Please enter your account (sms-*****): '); |
|
325
|
|
|
$account = $helper->ask($input, $output, $accountQ); |
|
326
|
|
|
|
|
327
|
|
|
$senderQ = new Question('Please enter your sender: '); |
|
328
|
|
|
$sender = $helper->ask($input, $output, $senderQ); |
|
329
|
|
|
|
|
330
|
|
|
$providerConfig->setApplicationKey($appKey); |
|
331
|
|
|
$providerConfig->setApplicationSecret($appSecret); |
|
332
|
|
|
$providerConfig->setConsumerKey($consumerKey); |
|
333
|
|
|
$providerConfig->setEndpoint($endpoint); |
|
334
|
|
|
$providerConfig->setAccount($account); |
|
335
|
|
|
$providerConfig->setSender($sender); |
|
336
|
|
|
break; |
|
337
|
|
|
|
|
338
|
|
|
case 'clickatellcentral': |
|
339
|
|
|
$config->setProvider($provider); |
|
340
|
|
|
/** @var ClickatellCentralConfig $providerConfig */ |
|
341
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
342
|
|
|
|
|
343
|
|
|
$apiQuestion = new Question('Please enter your central.clickatell.com API-ID: '); |
|
344
|
|
|
$api = $helper->ask($input, $output, $apiQuestion); |
|
345
|
|
|
$usernameQuestion = new Question('Please enter your central.clickatell.com username: '); |
|
346
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
347
|
|
|
$passwordQuestion = new Question('Please enter your central.clickatell.com password: '); |
|
348
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
349
|
|
|
|
|
350
|
|
|
$providerConfig->setApi($api); |
|
351
|
|
|
$providerConfig->setUser($username); |
|
352
|
|
|
$providerConfig->setPassword($password); |
|
353
|
|
|
break; |
|
354
|
|
|
|
|
355
|
|
|
case 'clickatellportal': |
|
356
|
|
|
$config->setProvider($provider); |
|
357
|
|
|
/** @var ClickatellPortalConfig $providerConfig */ |
|
358
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
359
|
|
|
|
|
360
|
|
|
$apiQuestion = new Question('Please enter your portal.clickatell.com API-Key: '); |
|
361
|
|
|
$apiKey = $helper->ask($input, $output, $apiQuestion); |
|
362
|
|
|
$fromQuestion = new Question('Please enter your sender number for two-way messaging. Leave it empty for one-way messaging: '); |
|
363
|
|
|
$fromNumber = $helper->ask($input, $output, $fromQuestion); |
|
364
|
|
|
|
|
365
|
|
|
$providerConfig->setApiKey($apiKey); |
|
366
|
|
|
|
|
367
|
|
|
if (empty($fromNumber)) { |
|
368
|
|
|
$providerConfig->deleteFromNumber(); |
|
369
|
|
|
} else { |
|
370
|
|
|
$providerConfig->setFromNumber($fromNumber); |
|
371
|
|
|
} |
|
372
|
|
|
break; |
|
373
|
|
|
|
|
374
|
|
|
case 'clicksend': |
|
375
|
|
|
$config->setProvider($provider); |
|
376
|
|
|
/** @var ClickSendConfig $providerConfig */ |
|
377
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
378
|
|
|
|
|
379
|
|
|
$usernameQuestion = new Question('Please enter your clicksend.com username: '); |
|
380
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
381
|
|
|
$apiKeyQuestion = new Question('Please enter your clicksend.com API Key (or, if subuser, the password): '); |
|
382
|
|
|
$apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
|
383
|
|
|
|
|
384
|
|
|
$providerConfig->setUser($username); |
|
385
|
|
|
$providerConfig->setApiKey($apiKey); |
|
386
|
|
|
break; |
|
387
|
|
|
|
|
388
|
|
|
case 'smsglobal': |
|
389
|
|
|
$config->setProvider($provider); |
|
390
|
|
|
/** @var SMSGlobalConfig $providerConfig */ |
|
391
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
392
|
|
|
|
|
393
|
|
|
$urlproposal = 'https://api.smsglobal.com/http-api.php'; |
|
394
|
|
|
$urlQuestion = new Question('Please enter your SMSGlobal http-api:', $urlproposal); |
|
395
|
|
|
$url = $helper->ask($input, $output, $urlQuestion); |
|
396
|
|
|
$usernameQuestion = new Question('Please enter your SMSGlobal username (for http-api):'); |
|
397
|
|
|
$username = $helper->ask($input, $output, $usernameQuestion); |
|
398
|
|
|
$passwordQuestion = new Question('Please enter your SMSGlobal password: (for http-api):'); |
|
399
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
400
|
|
|
|
|
401
|
|
|
$providerConfig->setUrl($url); |
|
402
|
|
|
$providerConfig->setUser($username); |
|
403
|
|
|
$providerConfig->setPassword($password); |
|
404
|
|
|
break; |
|
405
|
|
|
|
|
406
|
|
|
case 'serwersms': |
|
407
|
|
|
$config->setProvider($provider); |
|
408
|
|
|
/** @var SerwerSMSConfig $providerConfig */ |
|
409
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
410
|
|
|
|
|
411
|
|
|
$loginQuestion = new Question('Please enter your SerwerSMS.pl API login: '); |
|
412
|
|
|
$login = $helper->ask($input, $output, $loginQuestion); |
|
413
|
|
|
$passwordQuestion = new Question('Please enter your SerwerSMS.pl API password: '); |
|
414
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
415
|
|
|
$senderQuestion = new Question('Please enter your SerwerSMS.pl sender name: '); |
|
416
|
|
|
$sender = $helper->ask($input, $output, $senderQuestion); |
|
417
|
|
|
|
|
418
|
|
|
$providerConfig->setLogin($login); |
|
419
|
|
|
$providerConfig->setPassword($password); |
|
420
|
|
|
$providerConfig->setSender($sender); |
|
421
|
|
|
break; |
|
422
|
|
|
|
|
423
|
|
|
case 'smsapi.com': |
|
424
|
|
|
$config->setProvider($provider); |
|
425
|
|
|
/** @var SerwerSMSConfig $providerConfig */ |
|
426
|
|
|
$providerConfig = $config->getProvider()->getConfig(); |
|
427
|
|
|
|
|
428
|
|
|
$tokenQuestion = new Question('Please enter your SMSApi.com API token: '); |
|
429
|
|
|
$token = $helper->ask($input, $output, $tokenQuestion); |
|
430
|
|
|
$senderQuestion = new Question('Please enter your SMSApi.com sender name: '); |
|
431
|
|
|
$sender = $helper->ask($input, $output, $senderQuestion); |
|
432
|
|
|
|
|
433
|
|
|
$providerConfig->setToken($token); |
|
|
|
|
|
|
434
|
|
|
$providerConfig->setSender($sender); |
|
435
|
|
|
break; |
|
436
|
|
|
|
|
437
|
|
|
default: |
|
438
|
|
|
$output->writeln("Invalid provider $provider"); |
|
439
|
|
|
break; |
|
440
|
|
|
} |
|
441
|
|
|
return 0; |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
private function configureTelegram(InputInterface $input, OutputInterface $output) { |
|
445
|
|
|
$helper = $this->getHelper('question'); |
|
446
|
|
|
$tokenQuestion = new Question('Please enter your Telegram bot token: '); |
|
447
|
|
|
$token = $helper->ask($input, $output, $tokenQuestion); |
|
448
|
|
|
$output->writeln("Using $token."); |
|
449
|
|
|
|
|
450
|
|
|
/** @var TelegramConfig $config */ |
|
451
|
|
|
$config = $this->telegramGateway->getConfig(); |
|
452
|
|
|
|
|
453
|
|
|
$config->setBotToken($token); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
private function configureXMPP(InputInterface $input, OutputInterface $output) { |
|
457
|
|
|
$helper = $this->getHelper('question'); |
|
458
|
|
|
$sender = ''; |
|
459
|
|
|
while (empty($sender) or substr_count($sender, '@') !== 1): |
|
460
|
|
|
$senderQuestion = new Question('Please enter your sender XMPP-JID: '); |
|
461
|
|
|
$sender = $helper->ask($input, $output, $senderQuestion); |
|
462
|
|
|
if (empty($sender)) { |
|
463
|
|
|
$output->writeln("XMPP-JID must not be empty!"); |
|
464
|
|
|
} elseif (substr_count($sender, '@') !== 1) { |
|
465
|
|
|
$output->writeln("XMPP-JID not valid!"); |
|
466
|
|
|
} else { |
|
467
|
|
|
$username = explode('@', $sender)[0]; |
|
468
|
|
|
} |
|
469
|
|
|
endwhile; |
|
470
|
|
|
$output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
|
|
|
|
|
|
471
|
|
|
$password = ''; |
|
472
|
|
|
while (empty($password)): |
|
473
|
|
|
$passwordQuestion = new Question('Please enter your sender XMPP password: '); |
|
474
|
|
|
$password = $helper->ask($input, $output, $passwordQuestion); |
|
475
|
|
|
if (empty($password)) { |
|
476
|
|
|
$output->writeln("Password must not be empty!"); |
|
477
|
|
|
} |
|
478
|
|
|
endwhile; |
|
479
|
|
|
$output->writeln("Password accepted."); |
|
480
|
|
|
$server = ''; |
|
481
|
|
|
while (empty($server)): |
|
482
|
|
|
$serverQuestion = new Question('Please enter full path to access REST/HTTP API: '); |
|
483
|
|
|
$server = $helper->ask($input, $output, $serverQuestion); |
|
484
|
|
|
if (empty($server)) { |
|
485
|
|
|
$output->writeln("API path must not be empty!"); |
|
486
|
|
|
} |
|
487
|
|
|
endwhile; |
|
488
|
|
|
$output->writeln("Using $server as full URL to access REST/HTTP API."); |
|
489
|
|
|
$method = 0; |
|
490
|
|
|
while (intval($method) < 1 or intval($method) > 2): |
|
491
|
|
|
echo "Please enter 1 or 2 for XMPP sending option:\n"; |
|
492
|
|
|
echo "(1) prosody with mod_rest\n"; |
|
493
|
|
|
echo "(2) prosody with mod_post_msg\n"; |
|
494
|
|
|
$methodQuestion = new Question('Your choice: '); |
|
495
|
|
|
$method = $helper->ask($input, $output, $methodQuestion); |
|
496
|
|
|
endwhile; |
|
497
|
|
|
if ($method === "1") { |
|
498
|
|
|
$output->writeln("Using prosody with mod_rest as XMPP sending option."); |
|
499
|
|
|
} elseif ($method === "2") { |
|
500
|
|
|
$output->writeln("Using prosody with mod_post_msg as XMPP sending option."); |
|
501
|
|
|
} |
|
502
|
|
|
$output->writeln("XMPP Admin Configuration finished."); |
|
503
|
|
|
|
|
504
|
|
|
/** @var XMPPConfig $config */ |
|
505
|
|
|
$config = $this->xmppGateway->getConfig(); |
|
506
|
|
|
|
|
507
|
|
|
$config->setSender($sender); |
|
508
|
|
|
$config->setPassword($password); |
|
509
|
|
|
$config->setServer($server); |
|
510
|
|
|
$config->setUsername($username); |
|
511
|
|
|
$config->setMethod($method); |
|
512
|
|
|
} |
|
513
|
|
|
} |
|
514
|
|
|
|