@@ -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 | } |
@@ -63,25 +63,25 @@ discard block |
||
| 63 | 63 | public function send(IUser $user, string $identifier, string $message) { |
| 64 | 64 | $client = $this->clientService->newClient(); |
| 65 | 65 | // determine type of gateway |
| 66 | - $response = $client->get($this->config->getUrl() . '/v1/about'); |
|
| 66 | + $response = $client->get($this->config->getUrl().'/v1/about'); |
|
| 67 | 67 | if ($response->getStatusCode() === 200) { |
| 68 | 68 | // New style gateway https://gitlab.com/morph027/signal-cli-dbus-rest-api |
| 69 | 69 | $response = $client->post( |
| 70 | - $this->config->getUrl() . '/v1/send/' . $identifier, |
|
| 70 | + $this->config->getUrl().'/v1/send/'.$identifier, |
|
| 71 | 71 | [ |
| 72 | 72 | 'json' => [ 'message' => $message ], |
| 73 | 73 | ] |
| 74 | 74 | ); |
| 75 | 75 | $body = $response->getBody(); |
| 76 | 76 | $json = json_decode($body, true); |
| 77 | - if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
| 77 | + if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
| 78 | 78 | $status = $response->getStatusCode(); |
| 79 | 79 | throw new SmsTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 80 | 80 | } |
| 81 | 81 | } else { |
| 82 | 82 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
| 83 | 83 | $response = $client->post( |
| 84 | - $this->config->getUrl() . '/v1/send/' . $identifier, |
|
| 84 | + $this->config->getUrl().'/v1/send/'.$identifier, |
|
| 85 | 85 | [ |
| 86 | 86 | 'body' => [ |
| 87 | 87 | 'to' => $identifier, |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $body = $response->getBody(); |
| 94 | 94 | $json = json_decode($body, true); |
| 95 | 95 | |
| 96 | - if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
| 96 | + if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
| 97 | 97 | $status = $response->getStatusCode(); |
| 98 | 98 | throw new SmsTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 99 | 99 | } |
@@ -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."); |