@@ -2,4 +2,4 @@ |
||
| 2 | 2 | script('twofactor_gateway', 'build/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> |
|
@@ -10,8 +10,8 @@ |
||
| 10 | 10 | autofocus |
| 11 | 11 | autocomplete="off" |
| 12 | 12 | autocapitalize="off" |
| 13 | - value="<?php echo isset($_['secret']) ? $_['secret'] : '' ?>" |
|
| 13 | + value="<?php echo isset($_[ 'secret' ]) ? $_[ 'secret' ] : '' ?>" |
|
| 14 | 14 | placeholder="<?php p($l->t('Authentication code')) ?>"> |
| 15 | 15 | <input type="submit" class="confirm-inline icon-confirm" value=""> |
| 16 | - <p><?php p($l->t('An access code has been sent to %s', [$_['phone']])); ?></p> |
|
| 16 | + <p><?php p($l->t('An access code has been sent to %s', [ $_[ 'phone' ] ])); ?></p> |
|
| 17 | 17 | </form> |
@@ -29,12 +29,12 @@ |
||
| 29 | 29 | use OCP\AppFramework\Bootstrap\IBootstrap; |
| 30 | 30 | use OCP\AppFramework\Bootstrap\IRegistrationContext; |
| 31 | 31 | |
| 32 | -include_once __DIR__ . '/../../vendor/autoload.php'; |
|
| 32 | +include_once __DIR__.'/../../vendor/autoload.php'; |
|
| 33 | 33 | |
| 34 | 34 | class Application extends App implements IBootstrap { |
| 35 | 35 | public const APP_ID = 'twofactor_gateway'; |
| 36 | 36 | |
| 37 | - public function __construct(array $urlParams = []) { |
|
| 37 | + public function __construct(array $urlParams = [ ]) { |
|
| 38 | 38 | parent::__construct(self::APP_ID, $urlParams); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -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]> |
@@ -110,7 +110,7 @@ |
||
| 110 | 110 | return new JSONResponse(null, Http::STATUS_BAD_REQUEST); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - return new JSONResponse([]); |
|
| 113 | + return new JSONResponse([ ]); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | private const expected = [ |
| 32 | 32 | 'sipgate_token_id', |
| 33 | 33 | 'sipgate_access_token', |
| 34 | - 'sipgate_web_sms_extension', |
|
| 34 | + 'sipgate_web_sms_extension', |
|
| 35 | 35 | ]; |
| 36 | 36 | |
| 37 | 37 | /** @var IConfig */ |
@@ -85,21 +85,21 @@ 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 | - $smsServices = json_decode($response->getBody(),true); |
|
| 102 | + $smsServices = json_decode($response->getBody(), true); |
|
| 103 | 103 | |
| 104 | 104 | $smsAccountFound = false; |
| 105 | 105 | foreach ($smsServices as $smsService) { |
@@ -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 | - $resultPostJob = json_decode($response->getBody(),true); |
|
| 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 | } |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @param string $body JSON encoded body content for the POST request |
| 169 | 169 | * @return array $header Contains the data for the request need by OVH |
| 170 | 170 | */ |
| 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; |
|
| 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; |
|
| 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 | } |
@@ -56,13 +56,13 @@ |
||
| 56 | 56 | try { |
| 57 | 57 | $this->client->post('https://api.websms.com/rest/smsmessaging/text', [ |
| 58 | 58 | 'headers' => [ |
| 59 | - 'Authorization' => 'Basic ' . base64_encode("$user:$password"), |
|
| 59 | + 'Authorization' => 'Basic '.base64_encode("$user:$password"), |
|
| 60 | 60 | 'Content-Type' => 'application/json', |
| 61 | 61 | ], |
| 62 | 62 | 'json' => [ |
| 63 | 63 | 'messageContent' => $message, |
| 64 | 64 | 'test' => false, |
| 65 | - 'recipientAddressList' => [$identifier], |
|
| 65 | + 'recipientAddressList' => [ $identifier ], |
|
| 66 | 66 | ], |
| 67 | 67 | ]); |
| 68 | 68 | } catch (Exception $ex) { |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | try { |
| 59 | 59 | $this->client->post('https://api.sipgate.com/v2/sessions/sms', [ |
| 60 | 60 | 'headers' => [ |
| 61 | - 'Authorization' => 'Basic ' . base64_encode("$tokenId:$accessToken"), |
|
| 61 | + 'Authorization' => 'Basic '.base64_encode("$tokenId:$accessToken"), |
|
| 62 | 62 | 'Content-Type' => 'application/json', |
| 63 | 63 | 'Accept' => 'application/json', |
| 64 | 64 | ], |