@@ -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 | * @author Christoph Wurst <[email protected]> |
@@ -70,7 +70,7 @@ |
||
70 | 70 | |
71 | 71 | $responseData = json_decode($response->getBody(), true); |
72 | 72 | |
73 | - if ($responseData['success'] !== true) { |
|
73 | + if ($responseData[ 'success' ] !== true) { |
|
74 | 74 | throw new SmsTransmissionException(); |
75 | 75 | } |
76 | 76 | } catch (Exception $ex) { |
@@ -85,18 +85,18 @@ discard block |
||
85 | 85 | $sender = $config->getSender(); |
86 | 86 | $smsAccount = $config->getAccount(); |
87 | 87 | |
88 | - $this->attrs['AK'] = $config->getApplicationKey(); |
|
89 | - $this->attrs['AS'] = $config->getApplicationSecret(); |
|
90 | - $this->attrs['CK'] = $config->getConsumerKey(); |
|
91 | - if (!isset($this->endpoints[$endpoint])) { |
|
88 | + $this->attrs[ 'AK' ] = $config->getApplicationKey(); |
|
89 | + $this->attrs[ 'AS' ] = $config->getApplicationSecret(); |
|
90 | + $this->attrs[ 'CK' ] = $config->getConsumerKey(); |
|
91 | + if (!isset($this->endpoints[ $endpoint ])) { |
|
92 | 92 | throw new InvalidSmsProviderException("Endpoint $endpoint not found"); |
93 | 93 | } |
94 | - $this->attrs['endpoint'] = $this->endpoints[$endpoint]; |
|
94 | + $this->attrs[ 'endpoint' ] = $this->endpoints[ $endpoint ]; |
|
95 | 95 | |
96 | 96 | $this->getTimeDelta(); |
97 | 97 | |
98 | - $header = $this->getHeader('GET', $this->attrs['endpoint'].'/sms'); |
|
99 | - $response = $this->client->get($this->attrs['endpoint'].'/sms', [ |
|
98 | + $header = $this->getHeader('GET', $this->attrs[ 'endpoint' ].'/sms'); |
|
99 | + $response = $this->client->get($this->attrs[ 'endpoint' ].'/sms', [ |
|
100 | 100 | 'headers' => $header, |
101 | 101 | ]); |
102 | 102 | $smsServices = json_decode($response->getBody(), true); |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | ]; |
124 | 124 | $body = json_encode($content); |
125 | 125 | |
126 | - $header = $this->getHeader('POST', $this->attrs['endpoint']."/sms/$smsAccount/jobs", $body); |
|
127 | - $response = $this->client->post($this->attrs['endpoint']."/sms/$smsAccount/jobs", [ |
|
126 | + $header = $this->getHeader('POST', $this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", $body); |
|
127 | + $response = $this->client->post($this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", [ |
|
128 | 128 | 'headers' => $header, |
129 | 129 | 'json' => $content, |
130 | 130 | ]); |
131 | 131 | $resultPostJob = json_decode($response->getBody(), true); |
132 | 132 | |
133 | - if (count($resultPostJob["validReceivers"]) === 0) { |
|
133 | + if (count($resultPostJob[ "validReceivers" ]) === 0) { |
|
134 | 134 | throw new SmsTransmissionException("Bad receiver $identifier"); |
135 | 135 | } |
136 | 136 | } |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | * @throws InvalidSmsProviderException |
148 | 148 | */ |
149 | 149 | private function getTimeDelta() { |
150 | - if (!isset($this->attrs['timedelta'])) { |
|
151 | - if (!isset($this->attrs['endpoint'])) { |
|
150 | + if (!isset($this->attrs[ 'timedelta' ])) { |
|
151 | + if (!isset($this->attrs[ 'endpoint' ])) { |
|
152 | 152 | throw new InvalidSmsProviderException('Need to set the endpoint'); |
153 | 153 | } |
154 | 154 | try { |
155 | - $response = $this->client->get($this->attrs['endpoint'].'/auth/time'); |
|
156 | - $serverTimestamp = (int)$response->getBody(); |
|
157 | - $this->attrs['timedelta'] = $serverTimestamp - time(); |
|
155 | + $response = $this->client->get($this->attrs[ 'endpoint' ].'/auth/time'); |
|
156 | + $serverTimestamp = (int) $response->getBody(); |
|
157 | + $this->attrs[ 'timedelta' ] = $serverTimestamp - time(); |
|
158 | 158 | } catch (Exception $ex) { |
159 | 159 | throw new InvalidSmsProviderException('Unable to calculate time delta:'.$ex->getMessage()); |
160 | 160 | } |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @return array $header Contains the data for the request need by OVH |
170 | 170 | */ |
171 | 171 | private function getHeader($method, $query, $body = '') { |
172 | - $timestamp = time() + $this->attrs['timedelta']; |
|
173 | - $prehash = $this->attrs['AS'].'+'.$this->attrs['CK'].'+'.$method.'+'.$query.'+'.$body.'+'.$timestamp; |
|
172 | + $timestamp = time() + $this->attrs[ 'timedelta' ]; |
|
173 | + $prehash = $this->attrs[ 'AS' ].'+'.$this->attrs[ 'CK' ].'+'.$method.'+'.$query.'+'.$body.'+'.$timestamp; |
|
174 | 174 | $header = [ |
175 | 175 | 'Content-Type' => 'application/json; charset=utf-8', |
176 | - 'X-Ovh-Application' => $this->attrs['AK'], |
|
176 | + 'X-Ovh-Application' => $this->attrs[ 'AK' ], |
|
177 | 177 | 'X-Ovh-Timestamp' => $timestamp, |
178 | 178 | 'X-Ovh-Signature' => '$1$'.sha1($prehash), |
179 | - 'X-Ovh-Consumer' => $this->attrs['CK'], |
|
179 | + 'X-Ovh-Consumer' => $this->attrs[ 'CK' ], |
|
180 | 180 | ]; |
181 | 181 | return $header; |
182 | 182 | } |
@@ -2,4 +2,4 @@ |
||
2 | 2 | script('twofactor_gateway', 'build'); |
3 | 3 | ?> |
4 | 4 | |
5 | -<div id="twofactor-gateway-<?php print_unescaped($_['gateway']) ?>"></div> |
|
5 | +<div id="twofactor-gateway-<?php print_unescaped($_[ 'gateway' ]) ?>"></div> |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | $url = 'https://api.smsapi.com/sms.do'; |
57 | 57 | |
58 | 58 | $params = array( |
59 | - 'to' => $identifier, //destination number |
|
60 | - 'from' => $sender, //sendername made in https://ssl.smsapi.com/sms_settings/sendernames |
|
61 | - 'message' => $message, //message content |
|
62 | - 'format' => 'json', //get response in json format |
|
59 | + 'to' => $identifier, //destination number |
|
60 | + 'from' => $sender, //sendername made in https://ssl.smsapi.com/sms_settings/sendernames |
|
61 | + 'message' => $message, //message content |
|
62 | + 'format' => 'json', //get response in json format |
|
63 | 63 | ); |
64 | 64 | |
65 | 65 | try { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | curl_close($c); |
81 | 81 | $responseData = json_decode($content->getBody(), true); |
82 | 82 | |
83 | - if ($responseData['count'] !== 1) { |
|
83 | + if ($responseData[ 'count' ] !== 1) { |
|
84 | 84 | throw new SmsTransmissionException(); |
85 | 85 | } |
86 | 86 | } catch (Exception $ex) { |
@@ -58,13 +58,13 @@ |
||
58 | 58 | |
59 | 59 | protected function execute(InputInterface $input, OutputInterface $output) { |
60 | 60 | $signalConfigured = $this->signalGateway->getConfig()->isComplete(); |
61 | - $output->writeln('Signal gateway: ' . ($signalConfigured ? 'configured' : 'not configured')); |
|
61 | + $output->writeln('Signal gateway: '.($signalConfigured ? 'configured' : 'not configured')); |
|
62 | 62 | $smsConfigured = $this->smsGateway->getConfig()->isComplete(); |
63 | - $output->writeln('SMS gateway: ' . ($smsConfigured ? 'configured' : 'not configured')); |
|
63 | + $output->writeln('SMS gateway: '.($smsConfigured ? 'configured' : 'not configured')); |
|
64 | 64 | $telegramConfigured = $this->telegramGateway->getConfig()->isComplete(); |
65 | - $output->writeln('Telegram gateway: ' . ($telegramConfigured ? 'configured' : 'not configured')); |
|
65 | + $output->writeln('Telegram gateway: '.($telegramConfigured ? 'configured' : 'not configured')); |
|
66 | 66 | $xmppConfigured = $this->xmppGateway->getConfig()->isComplete(); |
67 | - $output->writeln('XMPP gateway: ' . ($xmppConfigured ? 'configured' : 'not configured')); |
|
67 | + $output->writeln('XMPP gateway: '.($xmppConfigured ? 'configured' : 'not configured')); |
|
68 | 68 | return 0; |
69 | 69 | } |
70 | 70 | } |
@@ -464,7 +464,7 @@ |
||
464 | 464 | } elseif (substr_count($sender, '@') !== 1) { |
465 | 465 | $output->writeln("XMPP-JID not valid!"); |
466 | 466 | } else { |
467 | - $username = explode('@', $sender)[0]; |
|
467 | + $username = explode('@', $sender)[ 0 ]; |
|
468 | 468 | } |
469 | 469 | endwhile; |
470 | 470 | $output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
@@ -72,24 +72,24 @@ discard block |
||
72 | 72 | $client = $this->clientService->newClient(); |
73 | 73 | // determine type of gateway |
74 | 74 | $response = $client->post( |
75 | - $this->config->getUrl() . '/api/v1/rpc', |
|
75 | + $this->config->getUrl().'/api/v1/rpc', |
|
76 | 76 | [ |
77 | 77 | 'http_errors' => false, |
78 | 78 | 'json' => [ |
79 | 79 | 'jsonrpc' => '2.0', |
80 | 80 | 'method' => 'version', |
81 | - 'id' => 'version_' . $this->timeFactory->getTime(), |
|
81 | + 'id' => 'version_'.$this->timeFactory->getTime(), |
|
82 | 82 | ], |
83 | 83 | ]); |
84 | 84 | if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) { |
85 | 85 | // native signal-cli JSON RPC. The 201 "created" is probably a bug. |
86 | 86 | $response = $response = $client->post( |
87 | - $this->config->getUrl() . '/api/v1/rpc', |
|
87 | + $this->config->getUrl().'/api/v1/rpc', |
|
88 | 88 | [ |
89 | 89 | 'json' => [ |
90 | 90 | 'jsonrpc' => '2.0', |
91 | 91 | 'method' => 'send', |
92 | - 'id' => 'code_' . $this->timeFactory->getTime(), |
|
92 | + 'id' => 'code_'.$this->timeFactory->getTime(), |
|
93 | 93 | 'params' => [ |
94 | 94 | 'recipient' => $identifier, |
95 | 95 | 'message' => $message, |
@@ -100,12 +100,12 @@ discard block |
||
100 | 100 | $body = $response->getBody(); |
101 | 101 | $json = json_decode($body, true); |
102 | 102 | $statusCode = $response->getStatusCode(); |
103 | - if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) { |
|
103 | + if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) { |
|
104 | 104 | throw new SmsTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
105 | 105 | } |
106 | 106 | } else { |
107 | 107 | $response = $client->get( |
108 | - $this->config->getUrl() . '/v1/about', |
|
108 | + $this->config->getUrl().'/v1/about', |
|
109 | 109 | [ |
110 | 110 | 'http_errors' => false, |
111 | 111 | ], |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | // https://bbernhard.github.io/signal-cli-rest-api/ |
118 | 118 | $body = $response->getBody(); |
119 | 119 | $json = json_decode($body, true); |
120 | - $versions = $json['versions'] || []; |
|
120 | + $versions = $json[ 'versions' ] || [ ]; |
|
121 | 121 | if (is_array($versions) && in_array('v2', $versions)) { |
122 | 122 | $response = $client->post( |
123 | - $this->config->getUrl() . '/v2/send', |
|
123 | + $this->config->getUrl().'/v2/send', |
|
124 | 124 | [ |
125 | 125 | 'json' => [ |
126 | 126 | 'recipients' => $identifier, |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ); |
132 | 132 | } else { |
133 | 133 | $response = $client->post( |
134 | - $this->config->getUrl() . '/v1/send/' . $identifier, |
|
134 | + $this->config->getUrl().'/v1/send/'.$identifier, |
|
135 | 135 | [ |
136 | 136 | 'json' => [ 'message' => $message ], |
137 | 137 | ] |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | $body = $response->getBody(); |
141 | 141 | $json = json_decode($body, true); |
142 | 142 | $statusCode = $response->getStatusCode(); |
143 | - if ($statusCode !== 201 || is_null($json) || !is_array($json) || (!isset($json['timestamps']) && !isset($json['timestamp']))) { |
|
143 | + if ($statusCode !== 201 || is_null($json) || !is_array($json) || (!isset($json[ 'timestamps' ]) && !isset($json[ 'timestamp' ]))) { |
|
144 | 144 | throw new SmsTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
145 | 145 | } |
146 | 146 | } else { |
147 | 147 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
148 | 148 | $response = $client->post( |
149 | - $this->config->getUrl() . '/v1/send/' . $identifier, |
|
149 | + $this->config->getUrl().'/v1/send/'.$identifier, |
|
150 | 150 | [ |
151 | 151 | 'body' => [ |
152 | 152 | 'to' => $identifier, |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $json = json_decode($body, true); |
160 | 160 | $statusCode = $response->getStatusCode(); |
161 | 161 | |
162 | - if ($statusCode !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
162 | + if ($statusCode !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
163 | 163 | throw new SmsTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
164 | 164 | } |
165 | 165 | } |