Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Configure.php « Command « lib - github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d6330a42e6bc4aa9052a5b94dee2b5c1461343a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php

declare(strict_types=1);

/**
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 *
 * Nextcloud - Two-factor Gateway
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\TwoFactorGateway\Command;

use OCA\TwoFactorGateway\Service\Gateway\IGateway;
use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway;
use OCA\TwoFactorGateway\Service\Gateway\Signal\GatewayConfig as SignalConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway;
use OCA\TwoFactorGateway\Service\Gateway\SMS\GatewayConfig as SMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickSendConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClockworkSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\EcallSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PlaySMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SMSGlobalConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\Sms77IoConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\OvhConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SipGateConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\PuzzelSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\HuaweiE3531Config;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SpryngSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ClickatellCentralConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\VoipbusterConfig;
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\SerwerSMSConfig;
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway;
use OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig as TelegramConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;

class Configure extends Command {

	/** @var SignalGateway */
	private $signalGateway;

	/** @var SMSGateway */
	private $smsGateway;

	/** @var TelegramGateway */
	private $telegramGateway;

	public function __construct(SignalGateway $signalGateway,
								SMSGateway $smsGateway,
								TelegramGateway $telegramGateway) {
		parent::__construct('twofactorauth:gateway:configure');
		$this->signalGateway = $signalGateway;
		$this->smsGateway = $smsGateway;
		$this->telegramGateway = $telegramGateway;

		$this->addArgument(
			'gateway',
			InputArgument::REQUIRED,
			'The name of the gateway, e.g. sms, signal, telegram, etc.'
		);
	}

	protected function execute(InputInterface $input, OutputInterface $output) {
		$gatewayName = $input->getArgument('gateway');

		/** @var IGateway $gateway */
		$gateway = null;
		switch ($gatewayName) {
			case 'signal':
				$this->configureSignal($input, $output);
				return 0;
			case 'sms':
				$this->configureSms($input, $output);
				return 0;
			case 'telegram':
				$this->configureTelegram($input, $output);
				return 0;
			default:
				$output->writeln("<error>Invalid gateway $gatewayName</error>");
				return;
		}
	}

	private function configureSignal(InputInterface $input, OutputInterface $output) {
		$helper = $this->getHelper('question');
		$urlQuestion = new Question('Please enter the URL of the Signal gateway (leave blank to use default): ', 'http://localhost:5000');
		$url = $helper->ask($input, $output, $urlQuestion);
		$output->writeln("Using $url.");

		/** @var SignalConfig $config */
		$config = $this->signalGateway->getConfig();

		$config->setUrl($url);
	}

	private function configureSms(InputInterface $input, OutputInterface $output) {
		$helper = $this->getHelper('question');

		$providerQuestion = new Question('Please choose a SMS provider (sipgate, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clicksend, serwersms, smsglobal): ', 'websms');
		$provider = $helper->ask($input, $output, $providerQuestion);

		/** @var SMSConfig $config */
		$config = $this->smsGateway->getConfig();
		switch ($provider) {
			case 'websms':
				$config->setProvider($provider);
				/** @var WebSmsConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$usernameQuestion = new Question('Please enter your websms.de username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$passwordQuestion = new Question('Please enter your websms.de password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);

				break;
			case 'sipgate':
				$config->setProvider($provider);
				/** @var SipGateConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$tokenIdQuestion = new Question('Please enter your sipgate token-id: ');
				$tokenId = $helper->ask($input, $output, $tokenIdQuestion);
				$accessTokenQuestion = new Question('Please enter your sipgate access token: ');
				$accessToken = $helper->ask($input, $output, $accessTokenQuestion);
				$webSmsExtensionQuestion = new Question('Please enter your sipgate web-sms extension: ');
				$webSmsExtension = $helper->ask($input, $output, $webSmsExtensionQuestion);

				$providerConfig->setTokenId($tokenId);
				$providerConfig->setAccessToken($accessToken);
				$providerConfig->setWebSmsExtension($webSmsExtension);

				break;
			case 'playsms':
				$config->setProvider($provider);
				/** @var PlaySMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$urlQuestion = new Question('Please enter your PlaySMS URL: ');
				$url = $helper->ask($input, $output, $urlQuestion);
				$usernameQuestion = new Question('Please enter your PlaySMS username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$passwordQuestion = new Question('Please enter your PlaySMS password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$providerConfig->setUrl($url);
				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);

				break;
			case 'clockworksms':
				$config->setProvider($provider);
				/** @var ClockworkSMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$apitokenQuestion = new Question('Please enter your clockworksms api token: ');
				$apitoken = $helper->ask($input, $output, $apitokenQuestion);

				$providerConfig->setApiToken($apitoken);

				break;
			case 'puzzelsms':
				$config->setProvider($provider);

				/** @var PuzzelSMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$urlQuestion = new Question('Please enter your PuzzelSMS URL: ');
				$url = $helper->ask($input, $output, $urlQuestion);

				$usernameQuestion = new Question('Please enter your PuzzelSMS username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);

				$passwordQuestion = new Question('Please enter your PuzzelSMS password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$serviceQuestion = new Question('Please enter your PuzzelSMS service ID: ');
				$serviceId = $helper->ask($input, $output, $serviceQuestion);

				$providerConfig->setUrl($url);
				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);
				$providerConfig->setServiceId($serviceId);
				break;
			case 'ecallsms':
				$config->setProvider($provider);
				/** @var EcallSMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$usernameQuestion = new Question('Please enter your eCall.ch username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$passwordQuestion = new Question('Please enter your eCall.ch password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);
				$senderIdQuestion = new Question('Please enter your eCall.ch sender ID: ');
				$senderId = $helper->ask($input, $output, $senderIdQuestion);

				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);
				$providerConfig->setSenderId($senderId);
				break;

			case 'voipms':
				$config->setProvider($provider);

				/** @var VoipMsConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$usernameQuestion = new Question('Please enter your VoIP.ms API username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);

				$passwordQuestion = new Question('Please enter your VoIP.ms API password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$didQuestion = new Question('Please enter your VoIP.ms DID: ');
				$did = $helper->ask($input, $output, $didQuestion);

				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);
				$providerConfig->setDid($did);
				break;

			case 'voipbuster':
				$config->setProvider($provider);

				/** @var VoipbusterConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$usernameQuestion = new Question('Please enter your Voipbuster API username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);

				$passwordQuestion = new Question('Please enter your Voipbuster API password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$didQuestion = new Question('Please enter your Voipbuster DID: ');
				$did = $helper->ask($input, $output, $didQuestion);

				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);
				$providerConfig->setDid($did);
				break;

			case 'huawei_e3531':
				$config->setProvider($provider);
				/** @var HuaweiE3531Config $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$urlQuestion = new Question('Please enter the base URL of the Huawei E3531 stick: ', 'http://192.168.8.1/api');
				$url = $helper->ask($input, $output, $urlQuestion);

				$providerConfig->setUrl($url);
				break;

			case 'spryng':
				$config->setProvider($provider);
				/** @var SpryngSMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$apitokenQuestion = new Question('Please enter your Spryng api token: ');
				$apitoken = $helper->ask($input, $output, $apitokenQuestion);

				$providerConfig->setApiToken($apitoken);

				break;

			case 'sms77io':
				$config->setProvider($provider);
				/** @var Sms77IoConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$apiKeyQuestion = new Question('Please enter your sms77.io API key: ');
				$apiKey = $helper->ask($input, $output, $apiKeyQuestion);

				$providerConfig->setApiKey($apiKey);
				break;

			case 'ovh':
				$config->setProvider($provider);

				/** @var OvhConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$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): ');
				$endpoint = $helper->ask($input, $output, $endpointQ);

				$appKeyQ = new Question('Please enter your application key: ');
				$appKey = $helper->ask($input, $output, $appKeyQ);

				$appSecretQ = new Question('Please enter your application secret: ');
				$appSecret = $helper->ask($input, $output, $appSecretQ);

				$consumerKeyQ = new Question('Please enter your consumer key: ');
				$consumerKey = $helper->ask($input, $output, $consumerKeyQ);

				$accountQ = new Question('Please enter your account (sms-*****): ');
				$account = $helper->ask($input, $output, $accountQ);

				$senderQ = new Question('Please enter your sender: ');
				$sender = $helper->ask($input, $output, $senderQ);

				$providerConfig->setApplicationKey($appKey);
				$providerConfig->setApplicationSecret($appSecret);
				$providerConfig->setConsumerKey($consumerKey);
				$providerConfig->setEndpoint($endpoint);
				$providerConfig->setAccount($account);
				$providerConfig->setSender($sender);
				break;

			case 'clickatellcentral':
				$config->setProvider($provider);
				/** @var ClickatellCentralConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$apiQuestion = new Question('Please enter your central.clickatell.com API-ID: ');
				$api = $helper->ask($input, $output, $apiQuestion);
				$usernameQuestion = new Question('Please enter your central.clickatell.com username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$passwordQuestion = new Question('Please enter your central.clickatell.com password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$providerConfig->setApi($api);
				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);
				break;

			case 'clicksend':
				$config->setProvider($provider);
				/** @var ClickSendConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$usernameQuestion = new Question('Please enter your clicksend.com username: ');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$apiKeyQuestion = new Question('Please enter your clicksend.com API Key (or, if subuser, the password): ');
				$apiKey = $helper->ask($input, $output, $apiKeyQuestion);

				$providerConfig->setUser($username);
				$providerConfig->setApiKey($apiKey);

				break;
			case 'smsglobal':
				$config->setProvider($provider);
				/** @var SMSGlobalConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$urlproposal='https://api.smsglobal.com/http-api.php';
				$urlQuestion = new Question('Please enter your SMSGlobal http-api:',$urlproposal);
				$url = $helper->ask($input, $output, $urlQuestion);
				$usernameQuestion = new Question('Please enter your SMSGlobal username (for http-api):');
				$username = $helper->ask($input, $output, $usernameQuestion);
				$passwordQuestion = new Question('Please enter your SMSGlobal password: (for http-api):');
				$password = $helper->ask($input, $output, $passwordQuestion);

				$providerConfig->setUrl($url);
				$providerConfig->setUser($username);
				$providerConfig->setPassword($password);

				break;

			case 'serwersms':
				$config->setProvider($provider);
				/** @var SerwerSMSConfig $providerConfig */
				$providerConfig = $config->getProvider()->getConfig();

				$loginQuestion = new Question('Please enter your SerwerSMS.pl API login: ');
				$login = $helper->ask($input, $output, $loginQuestion);
				$passwordQuestion = new Question('Please enter your SerwerSMS.pl API password: ');
				$password = $helper->ask($input, $output, $passwordQuestion);
				$senderQuestion = new Question('Please enter your SerwerSMS.pl sender name: ');
				$sender = $helper->ask($input, $output, $senderQuestion);

				$providerConfig->setLogin($login);
				$providerConfig->setPassword($password);
				$providerConfig->setSender($sender);

				break;

			default:
				$output->writeln("Invalid provider $provider");
				break;
		}
		return 0;
	}

	private function configureTelegram(InputInterface $input, OutputInterface $output) {
		$helper = $this->getHelper('question');
		$tokenQuestion = new Question('Please enter your Telegram bot token: ');
		$token = $helper->ask($input, $output, $tokenQuestion);
		$output->writeln("Using $token.");

		/** @var TelegramConfig $config */
		$config = $this->telegramGateway->getConfig();

		$config->setBotToken($token);
	}
}