-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
vendor/robthree/twofactorauth/lib/Providers/Qr/ImageChartsQRCodeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace RobThree\Auth\Providers\Qr; | ||
|
||
// https://image-charts.com | ||
class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider | ||
{ | ||
public $errorcorrectionlevel; | ||
public $margin; | ||
|
||
function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 1) | ||
{ | ||
if (!is_bool($verifyssl)) | ||
throw new \QRException('VerifySSL must be bool'); | ||
|
||
$this->verifyssl = $verifyssl; | ||
|
||
$this->errorcorrectionlevel = $errorcorrectionlevel; | ||
$this->margin = $margin; | ||
} | ||
|
||
public function getMimeType() | ||
{ | ||
return 'image/png'; | ||
} | ||
|
||
public function getQRCodeImage($qrtext, $size) | ||
{ | ||
return $this->getContent($this->getUrl($qrtext, $size)); | ||
} | ||
|
||
public function getUrl($qrtext, $size) | ||
{ | ||
return 'https://image-charts.com/chart?cht=qr' | ||
. '&chs=' . ceil($size/2) . 'x' . ceil($size/2) | ||
. '&chld=' . $this->errorcorrectionlevel . '|' . $this->margin | ||
. '&chl=' . rawurlencode($qrtext); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
vendor/robthree/twofactorauth/lib/Providers/Time/NTPTimeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace RobThree\Auth\Providers\Time; | ||
|
||
/** | ||
* Takes the time from any NTP server | ||
*/ | ||
class NTPTimeProvider implements ITimeProvider | ||
{ | ||
public $host; | ||
public $port; | ||
public $timeout; | ||
|
||
function __construct($host = 'time.google.com', $port = 123, $timeout = 1) | ||
{ | ||
$this->host = $host; | ||
|
||
if (!is_int($port) || $port <= 0 || $port > 65535) | ||
throw new \TimeException('Port must be 0 < port < 65535'); | ||
$this->port = $port; | ||
|
||
if (!is_int($timeout) || $timeout < 0) | ||
throw new \TimeException('Timeout must be >= 0'); | ||
$this->timeout = $timeout; | ||
} | ||
|
||
public function getTime() { | ||
try { | ||
/* Create a socket and connect to NTP server */ | ||
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ['sec' => $this->timeout, 'usec' => 0]); | ||
socket_connect($sock, $this->host, $this->port); | ||
|
||
/* Send request */ | ||
$msg = "\010" . str_repeat("\0", 47); | ||
socket_send($sock, $msg, strlen($msg), 0); | ||
|
||
/* Receive response and close socket */ | ||
if (socket_recv($sock, $recv, 48, MSG_WAITALL) === false) | ||
throw new \Exception(socket_strerror(socket_last_error($sock))); | ||
socket_close($sock); | ||
|
||
/* Interpret response */ | ||
$data = unpack('N12', $recv); | ||
$timestamp = sprintf('%u', $data[9]); | ||
|
||
/* NTP is number of seconds since 0000 UT on 1 January 1900 Unix time is seconds since 0000 UT on 1 January 1970 */ | ||
return $timestamp - 2208988800; | ||
} | ||
catch (Exception $ex) { | ||
throw new \TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->host, $ex->getMessage())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./lib</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Empty file.