@@ -13,12 +13,12 @@ |
||
13 | 13 | |
14 | 14 | class Provider extends AProvider { |
15 | 15 | |
16 | - #[\Override] |
|
16 | + #[\Override ] |
|
17 | 17 | public function getDisplayName(): string { |
18 | 18 | return $this->l10n->t('XMPP verification'); |
19 | 19 | } |
20 | 20 | |
21 | - #[\Override] |
|
21 | + #[\Override ] |
|
22 | 22 | public function getDescription(): string { |
23 | 23 | return $this->l10n->t('Authenticate via XMPP'); |
24 | 24 | } |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | <p>Enter your JID (XMPP address) to receive your verification code below.</p> |
40 | 40 | HTML, |
41 | 41 | 'fields' => [ |
42 | - ['field' => 'sender', 'prompt' => 'Please enter your sender XMPP-JID:'], |
|
43 | - ['field' => 'password', 'prompt' => 'Please enter your sender XMPP password:'], |
|
44 | - ['field' => 'server', 'prompt' => 'Please enter full path to access REST/HTTP API:'], |
|
45 | - ['field' => 'username'], |
|
46 | - ['field' => 'method', 'prompt' => 'Please enter 1 or 2 for XMPP sending option:'], |
|
42 | + [ 'field' => 'sender', 'prompt' => 'Please enter your sender XMPP-JID:' ], |
|
43 | + [ 'field' => 'password', 'prompt' => 'Please enter your sender XMPP password:' ], |
|
44 | + [ 'field' => 'server', 'prompt' => 'Please enter full path to access REST/HTTP API:' ], |
|
45 | + [ 'field' => 'username' ], |
|
46 | + [ 'field' => 'method', 'prompt' => 'Please enter 1 or 2 for XMPP sending option:' ], |
|
47 | 47 | ], |
48 | 48 | ]; |
49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | parent::__construct($appConfig); |
55 | 55 | } |
56 | 56 | |
57 | - #[\Override] |
|
58 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void { |
|
57 | + #[\Override ] |
|
58 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void { |
|
59 | 59 | $this->logger->debug("sending xmpp message to $identifier, message: $message"); |
60 | 60 | |
61 | 61 | $sender = $this->getSender(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $server = $this->getServer(); |
64 | 64 | $method = $this->getMethod(); |
65 | 65 | $user = $this->getUsername(); |
66 | - $url = $server . $identifier; |
|
66 | + $url = $server.$identifier; |
|
67 | 67 | |
68 | 68 | if ($method === '1') { |
69 | 69 | $from = $user; |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
80 | 80 | curl_setopt($ch, CURLOPT_POST, 1); |
81 | 81 | curl_setopt($ch, CURLOPT_POSTFIELDS, $message); |
82 | - curl_setopt($ch, CURLOPT_USERPWD, $from . ':' . $password); |
|
83 | - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/plain']); |
|
82 | + curl_setopt($ch, CURLOPT_USERPWD, $from.':'.$password); |
|
83 | + curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/plain' ]); |
|
84 | 84 | $result = curl_exec($ch); |
85 | 85 | curl_close($ch); |
86 | 86 | $this->logger->debug("XMPP message to $identifier sent"); |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - #[\Override] |
|
92 | + #[\Override ] |
|
93 | 93 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
94 | 94 | $helper = new QuestionHelper(); |
95 | - $fields = self::SCHEMA['fields']; |
|
95 | + $fields = self::SCHEMA[ 'fields' ]; |
|
96 | 96 | $fields = array_combine(array_column($fields, 'field'), $fields); |
97 | 97 | $sender = ''; |
98 | 98 | while (empty($sender) or substr_count($sender, '@') !== 1) { |
99 | - $senderQuestion = new Question($fields['sender']['prompt'] . ' '); |
|
99 | + $senderQuestion = new Question($fields[ 'sender' ][ 'prompt' ].' '); |
|
100 | 100 | $sender = $helper->ask($input, $output, $senderQuestion); |
101 | 101 | if (empty($sender)) { |
102 | 102 | $output->writeln('XMPP-JID must not be empty!'); |
103 | 103 | } elseif (substr_count($sender, '@') !== 1) { |
104 | 104 | $output->writeln('XMPP-JID not valid!'); |
105 | 105 | } else { |
106 | - $username = explode('@', $sender)[0]; |
|
106 | + $username = explode('@', $sender)[ 0 ]; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | $output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
110 | 110 | $password = ''; |
111 | 111 | while (empty($password)) { |
112 | - $passwordQuestion = new Question($fields['password']['prompt'] . ' '); |
|
112 | + $passwordQuestion = new Question($fields[ 'password' ][ 'prompt' ].' '); |
|
113 | 113 | $password = $helper->ask($input, $output, $passwordQuestion); |
114 | 114 | if (empty($password)) { |
115 | 115 | $output->writeln('Password must not be empty!'); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $output->writeln('Password accepted.'); |
119 | 119 | $server = ''; |
120 | 120 | while (empty($server)) { |
121 | - $serverQuestion = new Question($fields['server']['prompt'] . ' '); |
|
121 | + $serverQuestion = new Question($fields[ 'server' ][ 'prompt' ].' '); |
|
122 | 122 | $server = $helper->ask($input, $output, $serverQuestion); |
123 | 123 | if (empty($server)) { |
124 | 124 | $output->writeln('API path must not be empty!'); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $output->writeln("Using $server as full URL to access REST/HTTP API."); |
128 | 128 | $method = 0; |
129 | 129 | while (intval($method) < 1 or intval($method) > 2) { |
130 | - echo $fields['method']['prompt'] . PHP_EOL; |
|
130 | + echo $fields[ 'method' ][ 'prompt' ].PHP_EOL; |
|
131 | 131 | echo "(1) prosody with mod_rest\n"; |
132 | 132 | echo "(2) prosody with mod_post_msg\n"; |
133 | 133 | $methodQuestion = new Question('Your choice: '); |
@@ -13,12 +13,12 @@ |
||
13 | 13 | |
14 | 14 | class Provider extends AProvider { |
15 | 15 | |
16 | - #[\Override] |
|
16 | + #[\Override ] |
|
17 | 17 | public function getDisplayName(): string { |
18 | 18 | return $this->l10n->t('WhatsApp verification'); |
19 | 19 | } |
20 | 20 | |
21 | - #[\Override] |
|
21 | + #[\Override ] |
|
22 | 22 | public function getDescription(): string { |
23 | 23 | return $this->l10n->t('Authenticate via WhatsApp'); |
24 | 24 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public const SCHEMA = [ |
39 | 39 | 'name' => 'WhatsApp', |
40 | 40 | 'fields' => [ |
41 | - ['field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:'], |
|
41 | + [ 'field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:' ], |
|
42 | 42 | ], |
43 | 43 | ]; |
44 | 44 | private string $instanceId; |
@@ -56,25 +56,25 @@ discard block |
||
56 | 56 | $this->client = $this->clientService->newClient(); |
57 | 57 | } |
58 | 58 | |
59 | - #[\Override] |
|
60 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void { |
|
61 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
59 | + #[\Override ] |
|
60 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void { |
|
61 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
62 | 62 | $this->logger->debug("sending whatsapp message to $identifier, message: $message"); |
63 | 63 | |
64 | 64 | $response = $this->getSessionStatus(); |
65 | 65 | if ($response !== 'CONNECTED') { |
66 | - throw new MessageTransmissionException('WhatsApp session is not connected. Current status: ' . $response); |
|
66 | + throw new MessageTransmissionException('WhatsApp session is not connected. Current status: '.$response); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $chatId = $this->getChatIdFromPhoneNumber($identifier); |
70 | 70 | |
71 | 71 | try { |
72 | - $response = $this->client->post($this->getBaseUrl() . '/client/sendMessage/' . $this->instanceId, [ |
|
72 | + $response = $this->client->post($this->getBaseUrl().'/client/sendMessage/'.$this->instanceId, [ |
|
73 | 73 | 'json' => [ |
74 | 74 | 'chatId' => $chatId, |
75 | 75 | 'contentType' => 'string', |
76 | 76 | 'content' => $message, |
77 | - 'options' => [], |
|
77 | + 'options' => [ ], |
|
78 | 78 | ], |
79 | 79 | ]); |
80 | 80 | } catch (\Exception $e) { |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | $this->logger->debug("whatsapp message to chat $identifier sent"); |
89 | 89 | } |
90 | 90 | |
91 | - #[\Override] |
|
91 | + #[\Override ] |
|
92 | 92 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
93 | 93 | $helper = new QuestionHelper(); |
94 | - $baseUrlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
94 | + $baseUrlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
95 | 95 | $this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion); |
96 | 96 | $this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/'); |
97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | return 1; |
101 | 101 | } |
102 | 102 | } catch (\Exception $e) { |
103 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
103 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $this->setBaseUrl($this->lazyBaseUrl); |
@@ -110,23 +110,23 @@ discard block |
||
110 | 110 | |
111 | 111 | private function getChatIdFromPhoneNumber(string $phoneNumber): string { |
112 | 112 | try { |
113 | - $response = $this->client->post($this->getBaseUrl() . '/client/getNumberId/' . $this->instanceId, [ |
|
113 | + $response = $this->client->post($this->getBaseUrl().'/client/getNumberId/'.$this->instanceId, [ |
|
114 | 114 | 'json' => [ |
115 | 115 | 'number' => preg_replace('/\D/', '', $phoneNumber), |
116 | 116 | ], |
117 | 117 | ]); |
118 | 118 | $json = $response->getBody(); |
119 | 119 | $data = json_decode($json, true); |
120 | - if (empty($data['result'])) { |
|
120 | + if (empty($data[ 'result' ])) { |
|
121 | 121 | throw new MessageTransmissionException('The phone number is not registered on WhatsApp.'); |
122 | 122 | } |
123 | - return $data['result']['_serialized']; |
|
123 | + return $data[ 'result' ][ '_serialized' ]; |
|
124 | 124 | } catch (ServerException $e) { |
125 | 125 | $content = $e->getResponse()?->getBody()?->getContents(); |
126 | 126 | if ($content === null) { |
127 | 127 | throw new MessageTransmissionException('Unknown error'); |
128 | 128 | } |
129 | - $errorMessage = json_decode($content, true)['error'] ?? 'Unknown error'; |
|
129 | + $errorMessage = json_decode($content, true)[ 'error' ] ?? 'Unknown error'; |
|
130 | 130 | throw new MessageTransmissionException($errorMessage); |
131 | 131 | } |
132 | 132 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | /** @var string */ |
143 | - $this->lazyBaseUrl = $this->__call(__FUNCTION__, []); |
|
143 | + $this->lazyBaseUrl = $this->__call(__FUNCTION__, [ ]); |
|
144 | 144 | return $this->lazyBaseUrl; |
145 | 145 | } |
146 | 146 | |
@@ -156,19 +156,19 @@ discard block |
||
156 | 156 | |
157 | 157 | $last = null; |
158 | 158 | while (true) { |
159 | - $response = $this->client->get($this->getBaseUrl() . '/session/qr/' . $this->instanceId); |
|
159 | + $response = $this->client->get($this->getBaseUrl().'/session/qr/'.$this->instanceId); |
|
160 | 160 | $json = $response->getBody(); |
161 | 161 | $data = json_decode($json, true); |
162 | - if ($data['success'] === false) { |
|
163 | - if ($data['message'] === 'qr code not ready or already scanned') { |
|
162 | + if ($data[ 'success' ] === false) { |
|
163 | + if ($data[ 'message' ] === 'qr code not ready or already scanned') { |
|
164 | 164 | $output->writeln('<error>Session not connected yet, waiting...</error>'); |
165 | 165 | sleep(2); |
166 | 166 | continue; |
167 | 167 | } |
168 | - $output->writeln('<error>' . $data['message'] . '</error>'); |
|
168 | + $output->writeln('<error>'.$data[ 'message' ].'</error>'); |
|
169 | 169 | return 1; |
170 | 170 | } |
171 | - $qrCodeContent = $data['qr']; |
|
171 | + $qrCodeContent = $data[ 'qr' ]; |
|
172 | 172 | |
173 | 173 | if ($qrCodeContent !== $last) { |
174 | 174 | $last = $qrCodeContent; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | } |
191 | 191 | |
192 | 192 | private function getSessionStatus(): string { |
193 | - $endpoint = $this->getBaseUrl() . '/session/status/' . $this->instanceId; |
|
193 | + $endpoint = $this->getBaseUrl().'/session/status/'.$this->instanceId; |
|
194 | 194 | |
195 | 195 | try { |
196 | 196 | $response = $this->client->get($endpoint); |
@@ -201,18 +201,18 @@ discard block |
||
201 | 201 | return 'not_connected'; |
202 | 202 | } |
203 | 203 | |
204 | - if (($responseData['success'] ?? null) === false) { |
|
205 | - $msg = $responseData['message'] ?? ''; |
|
206 | - return in_array($msg, ['session_not_found', 'session_not_connected'], true) |
|
204 | + if (($responseData[ 'success' ] ?? null) === false) { |
|
205 | + $msg = $responseData[ 'message' ] ?? ''; |
|
206 | + return in_array($msg, [ 'session_not_found', 'session_not_connected' ], true) |
|
207 | 207 | ? $msg |
208 | 208 | : 'not_connected'; |
209 | 209 | } |
210 | 210 | |
211 | - return (string)($responseData['state'] ?? 'not_connected'); |
|
211 | + return (string)($responseData[ 'state' ] ?? 'not_connected'); |
|
212 | 212 | } catch (ClientException $e) { |
213 | 213 | return 'not_connected'; |
214 | 214 | } catch (RequestException $e) { |
215 | - $this->logger->info('Could not connect to ' . $endpoint, ['exception' => $e]); |
|
215 | + $this->logger->info('Could not connect to '.$endpoint, [ 'exception' => $e ]); |
|
216 | 216 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
217 | 217 | } |
218 | 218 | } |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | } |
232 | 232 | |
233 | 233 | private function getSessionStart(): int { |
234 | - $endpoint = $this->getBaseUrl() . '/session/start/' . $this->instanceId; |
|
234 | + $endpoint = $this->getBaseUrl().'/session/start/'.$this->instanceId; |
|
235 | 235 | try { |
236 | 236 | $this->client->get($endpoint); |
237 | 237 | } catch (ClientException $e) { |
238 | 238 | return 1; |
239 | 239 | } catch (RequestException $e) { |
240 | - $this->logger->info('Could not connect to ' . $endpoint, [ |
|
240 | + $this->logger->info('Could not connect to '.$endpoint, [ |
|
241 | 241 | 'exception' => $e, |
242 | 242 | ]); |
243 | 243 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
@@ -13,12 +13,12 @@ |
||
13 | 13 | |
14 | 14 | class Provider extends AProvider { |
15 | 15 | |
16 | - #[\Override] |
|
16 | + #[\Override ] |
|
17 | 17 | public function getDisplayName(): string { |
18 | 18 | return $this->l10n->t('Telegram verification'); |
19 | 19 | } |
20 | 20 | |
21 | - #[\Override] |
|
21 | + #[\Override ] |
|
22 | 22 | public function getDescription(): string { |
23 | 23 | return $this->l10n->t('Authenticate via Telegram'); |
24 | 24 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | <p>Enter this ID to receive your verification code below.</p> |
40 | 40 | HTML, |
41 | 41 | 'fields' => [ |
42 | - ['field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:'], |
|
42 | + [ 'field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:' ], |
|
43 | 43 | ], |
44 | 44 | ]; |
45 | 45 | public function __construct( |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | parent::__construct($appConfig); |
51 | 51 | } |
52 | 52 | |
53 | - #[\Override] |
|
54 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void { |
|
55 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
53 | + #[\Override ] |
|
54 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void { |
|
55 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
56 | 56 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
57 | 57 | $botToken = $this->getBotToken(); |
58 | 58 | $this->logger->debug("telegram bot token: $botToken"); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | $this->logger->debug("telegram message to chat $identifier sent"); |
71 | 71 | } |
72 | 72 | |
73 | - #[\Override] |
|
73 | + #[\Override ] |
|
74 | 74 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
75 | 75 | $helper = new QuestionHelper(); |
76 | - $tokenQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
76 | + $tokenQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
77 | 77 | $token = $helper->ask($input, $output, $tokenQuestion); |
78 | 78 | $this->setBotToken($token); |
79 | 79 | $output->writeln("Using $token."); |
@@ -82,7 +82,7 @@ |
||
82 | 82 | return $this->verificationCode; |
83 | 83 | } |
84 | 84 | |
85 | - #[\Override] |
|
85 | + #[\Override ] |
|
86 | 86 | public function jsonSerialize(): mixed { |
87 | 87 | return [ |
88 | 88 | 'gatewayName' => $this->gatewayName, |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]> |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | parent::__construct('twofactorauth:gateway:status'); |
23 | 23 | } |
24 | 24 | |
25 | - #[\Override] |
|
25 | + #[\Override ] |
|
26 | 26 | protected function execute(InputInterface $input, OutputInterface $output) { |
27 | 27 | $fqcn = $this->gatewayFactory->getFqcnList(); |
28 | 28 | foreach ($fqcn as $fqcn) { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $gateway = $this->gatewayFactory->get($fqcn::getProviderId()); |
31 | 31 | $isConfigured = $gateway->isComplete(); |
32 | 32 | $settings = $gateway->getSettings(); |
33 | - $output->writeln($settings['name'] . ': ' . ($isConfigured ? 'configured' : 'not configured')); |
|
33 | + $output->writeln($settings[ 'name' ].': '.($isConfigured ? 'configured' : 'not configured')); |
|
34 | 34 | } |
35 | 35 | return 0; |
36 | 36 | } |