@@ -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> |
@@ -62,36 +62,36 @@ |
||
62 | 62 | $this->config->setAppValue(Application::APP_ID, 'xmpp_sender', $sender); |
63 | 63 | } |
64 | 64 | |
65 | - public function getPassword(): string { |
|
66 | - return $this->getOrFail('xmpp_password'); |
|
67 | - } |
|
68 | - |
|
69 | - public function setPassword(string $password) { |
|
70 | - $this->config->setAppValue(Application::APP_ID, 'xmpp_password', $password); |
|
71 | - } |
|
72 | - |
|
73 | - public function getServer(): string { |
|
74 | - return $this->getOrFail('xmpp_server'); |
|
75 | - } |
|
76 | - |
|
77 | - public function setServer(string $server) { |
|
78 | - $this->config->setAppValue(Application::APP_ID, 'xmpp_server', $server); |
|
79 | - } |
|
80 | - |
|
81 | - public function getUsername(): string { |
|
82 | - return $this->getOrFail('xmpp_username'); |
|
83 | - } |
|
84 | - |
|
85 | - public function setUsername(string $username) { |
|
86 | - $this->config->setAppValue(Application::APP_ID, 'xmpp_username', $username); |
|
87 | - } |
|
88 | - public function getMethod(): string { |
|
89 | - return $this->getOrFail('xmpp_method'); |
|
90 | - } |
|
91 | - |
|
92 | - public function setMethod(string $method) { |
|
93 | - $this->config->setAppValue(Application::APP_ID, 'xmpp_method', $method); |
|
94 | - } |
|
65 | + public function getPassword(): string { |
|
66 | + return $this->getOrFail('xmpp_password'); |
|
67 | + } |
|
68 | + |
|
69 | + public function setPassword(string $password) { |
|
70 | + $this->config->setAppValue(Application::APP_ID, 'xmpp_password', $password); |
|
71 | + } |
|
72 | + |
|
73 | + public function getServer(): string { |
|
74 | + return $this->getOrFail('xmpp_server'); |
|
75 | + } |
|
76 | + |
|
77 | + public function setServer(string $server) { |
|
78 | + $this->config->setAppValue(Application::APP_ID, 'xmpp_server', $server); |
|
79 | + } |
|
80 | + |
|
81 | + public function getUsername(): string { |
|
82 | + return $this->getOrFail('xmpp_username'); |
|
83 | + } |
|
84 | + |
|
85 | + public function setUsername(string $username) { |
|
86 | + $this->config->setAppValue(Application::APP_ID, 'xmpp_username', $username); |
|
87 | + } |
|
88 | + public function getMethod(): string { |
|
89 | + return $this->getOrFail('xmpp_method'); |
|
90 | + } |
|
91 | + |
|
92 | + public function setMethod(string $method) { |
|
93 | + $this->config->setAppValue(Application::APP_ID, 'xmpp_method', $method); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | public function isComplete(): bool { |
97 | 97 | $set = $this->config->getAppKeys(Application::APP_ID); |
@@ -68,16 +68,16 @@ discard block |
||
68 | 68 | public function send(IUser $user, string $identifier, string $message) { |
69 | 69 | $this->logger->debug("sending xmpp message to $identifier, message: $message"); |
70 | 70 | |
71 | - $sender = $this->gatewayConfig->getSender(); |
|
72 | - $password = $this->gatewayConfig->getPassword(); |
|
73 | - $server = $this->gatewayConfig->getServer(); |
|
71 | + $sender = $this->gatewayConfig->getSender(); |
|
72 | + $password = $this->gatewayConfig->getPassword(); |
|
73 | + $server = $this->gatewayConfig->getServer(); |
|
74 | 74 | $method = $this->gatewayConfig->getMethod(); |
75 | 75 | $user = $this->gatewayConfig->getUsername(); |
76 | 76 | $url = $server.$identifier; |
77 | 77 | |
78 | - if ($method === "1") { |
|
78 | + if ($method === "1") { |
|
79 | 79 | $from = $user; |
80 | - } |
|
80 | + } |
|
81 | 81 | if ($method === "2") { |
82 | 82 | $from = $sender; |
83 | 83 | } |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | |
86 | 86 | try { |
87 | 87 | $ch = curl_init(); |
88 | - curl_setopt($ch, CURLOPT_URL, $url ); |
|
89 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); |
|
90 | - curl_setopt($ch, CURLOPT_POST, 1 ); |
|
91 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $message ); |
|
92 | - curl_setopt($ch, CURLOPT_USERPWD, $from.":".$password ); |
|
93 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); |
|
88 | + curl_setopt($ch, CURLOPT_URL, $url ); |
|
89 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); |
|
90 | + curl_setopt($ch, CURLOPT_POST, 1 ); |
|
91 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $message ); |
|
92 | + curl_setopt($ch, CURLOPT_USERPWD, $from.":".$password ); |
|
93 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); |
|
94 | 94 | $result = curl_exec($ch); |
95 | - curl_close($ch); |
|
96 | - $this->logger->debug("XMPP message to $identifier sent"); |
|
95 | + curl_close($ch); |
|
96 | + $this->logger->debug("XMPP message to $identifier sent"); |
|
97 | 97 | } catch (Exception $ex) { |
98 | 98 | throw new SmsTransmissionException(); |
99 | 99 | } |
@@ -85,12 +85,12 @@ |
||
85 | 85 | |
86 | 86 | try { |
87 | 87 | $ch = curl_init(); |
88 | - curl_setopt($ch, CURLOPT_URL, $url ); |
|
89 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); |
|
90 | - curl_setopt($ch, CURLOPT_POST, 1 ); |
|
91 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $message ); |
|
92 | - curl_setopt($ch, CURLOPT_USERPWD, $from.":".$password ); |
|
93 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); |
|
88 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
89 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
90 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
91 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $message); |
|
92 | + curl_setopt($ch, CURLOPT_USERPWD, $from.":".$password); |
|
93 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); |
|
94 | 94 | $result = curl_exec($ch); |
95 | 95 | curl_close($ch); |
96 | 96 | $this->logger->debug("XMPP message to $identifier sent"); |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | /** @var TelegramGateway */ |
41 | 41 | private $telegramGateway; |
42 | 42 | |
43 | - /** @var XMPPGateway */ |
|
44 | - private $xmppGateway; |
|
43 | + /** @var XMPPGateway */ |
|
44 | + private $xmppGateway; |
|
45 | 45 | |
46 | 46 | public function __construct(SignalGateway $signalGateway, |
47 | 47 | SMSGateway $smsGateway, |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $this->signalGateway = $signalGateway; |
51 | 51 | $this->smsGateway = $smsGateway; |
52 | 52 | $this->telegramGateway = $telegramGateway; |
53 | - $this->xmppGateway = $xmppGateway; |
|
53 | + $this->xmppGateway = $xmppGateway; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function getGateway(string $name): IGateway { |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | return $this->smsGateway; |
62 | 62 | case 'telegram': |
63 | 63 | return $this->telegramGateway; |
64 | - case 'xmpp': |
|
65 | - return $this->xmppGateway; |
|
64 | + case 'xmpp': |
|
65 | + return $this->xmppGateway; |
|
66 | 66 | default: |
67 | 67 | throw new Exception("Invalid gateway <$name>"); |
68 | 68 | } |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | /** @var TelegramGateway */ |
45 | 45 | private $telegramGateway; |
46 | 46 | |
47 | - /** @var XMPPGateway */ |
|
48 | - private $xmppGateway; |
|
47 | + /** @var XMPPGateway */ |
|
48 | + private $xmppGateway; |
|
49 | 49 | |
50 | 50 | public function __construct(SignalGateway $signalGateway, |
51 | 51 | SMSGateway $smsGateway, |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | case 'telegram': |
80 | 80 | $gateway = $this->telegramGateway; |
81 | 81 | break; |
82 | - case 'xmpp': |
|
83 | - $gateway = $this->xmppGateway; |
|
84 | - break; |
|
82 | + case 'xmpp': |
|
83 | + $gateway = $this->xmppGateway; |
|
84 | + break; |
|
85 | 85 | default: |
86 | 86 | $output->writeln("<error>Invalid gateway $gatewayName</error>"); |
87 | 87 | return 1; |