git subrepo clone https://github.com/mailcow/mailcow-dockerized.git mailcow/src/mailcow-dockerized
subrepo: subdir: "mailcow/src/mailcow-dockerized"
merged: "a832becb"
upstream: origin: "https://github.com/mailcow/mailcow-dockerized.git"
branch: "master"
commit: "a832becb"
git-subrepo: version: "0.4.3"
origin: "???"
commit: "???"
Change-Id: If5be2d621a211e164c9b6577adaa7884449f16b5
diff --git a/mailcow/src/mailcow-dockerized/data/web/inc/lib/vendor/robthree/twofactorauth/lib/Providers/Time/HttpTimeProvider.php b/mailcow/src/mailcow-dockerized/data/web/inc/lib/vendor/robthree/twofactorauth/lib/Providers/Time/HttpTimeProvider.php
new file mode 100644
index 0000000..8e7806e
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/web/inc/lib/vendor/robthree/twofactorauth/lib/Providers/Time/HttpTimeProvider.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace RobThree\Auth\Providers\Time;
+
+/**
+ * Takes the time from any webserver by doing a HEAD request on the specified URL and extracting the 'Date:' header
+ */
+class HttpTimeProvider implements ITimeProvider
+{
+ public $url;
+ public $options;
+ public $expectedtimeformat;
+
+ function __construct($url = 'https://google.com', $expectedtimeformat = 'D, d M Y H:i:s O+', array $options = null)
+ {
+ $this->url = $url;
+ $this->expectedtimeformat = $expectedtimeformat;
+ $this->options = $options;
+ if ($this->options === null) {
+ $this->options = array(
+ 'http' => array(
+ 'method' => 'HEAD',
+ 'follow_location' => false,
+ 'ignore_errors' => true,
+ 'max_redirects' => 0,
+ 'request_fulluri' => true,
+ 'header' => array(
+ 'Connection: close',
+ 'User-agent: TwoFactorAuth HttpTimeProvider (https://github.com/RobThree/TwoFactorAuth)',
+ 'Cache-Control: no-cache'
+ )
+ )
+ );
+ }
+ }
+
+ public function getTime() {
+ try {
+ $context = stream_context_create($this->options);
+ $fd = fopen($this->url, 'rb', false, $context);
+ $headers = stream_get_meta_data($fd);
+ fclose($fd);
+
+ foreach ($headers['wrapper_data'] as $h) {
+ if (strcasecmp(substr($h, 0, 5), 'Date:') === 0)
+ return \DateTime::createFromFormat($this->expectedtimeformat, trim(substr($h,5)))->getTimestamp();
+ }
+ throw new \TimeException(sprintf('Unable to retrieve time from %s (Invalid or no "Date:" header found)', $this->url));
+ }
+ catch (Exception $ex) {
+ throw new \TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->url, $ex->getMessage()));
+ }
+ }
+}
\ No newline at end of file