🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,4 @@
composer.phar
composer.lock
vendor
coverage
@@ -0,0 +1,40 @@
checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
filter:
paths: [src/*]
excluded_paths: [tests/*]
coding_style:
php: { }
build:
tests:
override:
-
command: 'vendor/bin/phpunit -c phpunit.xml'
coverage:
file: 'coverage/coverage-clover.xml'
format: 'clover'
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
tests: true
tools:
external_code_coverage: true
@@ -0,0 +1,37 @@
dist: trusty
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false
## Cache composer
cache:
directories:
- $HOME/.composer/cache
install:
- |
if [[ "$TRAVIS_PHP_VERSION" == 'nightly' ]]; then
travis_retry composer update --ignore-platform-reqs --no-interaction --prefer-dist
else
yes '' | pecl install imagick
travis_retry composer update --no-interaction --prefer-dist
fi
script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
after_script:
- |
if [[ "$TRAVIS_PHP_VERSION" == '7.4' ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
@@ -0,0 +1,26 @@
## Change Log
## [2.0.1] - 2020-10-17
### Removed
- Support for Bacon QRCode 1.x
## [2.0.0] - 2020-10-16
### Changed
- Add support for SVG QRCodes
- No need to install the Imagick extension
- Allow users to define their on QRCode service renderer
- Breaking change: beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes: [BaconQrCode](https://github.com/Bacon/BaconQrCode): renders PNG by default, but requires the Imagick PHP extension. [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode): renders SVG by default and don't require the Imagick PHP extension.
- Add PHP 8.0 compatibility
## [1.0.2] - 2018-10-10
### Changed
- Dropped support for PHP 5.4 & PHP 5.5
- Test QRCode by decoding it
## [1.0.1] - 2018-10-10
### Added
- Add support for more image renderer back ends
## [1.0.0] - 2018-10-06
### Added
- Package created
@@ -0,0 +1,7 @@
Copyright 2014-2018 Phil, Antonio Carlos Ribeiro and All Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,149 @@
# Google2FA QRCode
<p align="center">
<a href="https://packagist.org/packages/pragmarx/google2fa-qrcode"><img alt="Latest Stable Version" src="https://img.shields.io/packagist/v/pragmarx/google2fa-qrcode.svg?style=flat-square"></a>
<a href="LICENSE.md"><img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
<a href="https://scrutinizer-ci.com/g/antonioribeiro/google2fa/?branch=master"><img alt="Code Quality" src="https://img.shields.io/scrutinizer/g/antonioribeiro/google2fa.svg?style=flat-square"></a>
<a href="https://travis-ci.org/antonioribeiro/google2fa"><img alt="Build" src="https://img.shields.io/travis/antonioribeiro/google2fa.svg?style=flat-square"></a>
</p>
<p align="center">
<a href="https://packagist.org/packages/pragmarx/google2fa-qrcode"><img alt="Downloads" src="https://img.shields.io/packagist/dt/pragmarx/google2fa-qrcode.svg?style=flat-square"></a>
<a href="https://scrutinizer-ci.com/g/antonioribeiro/google2fa/?branch=master"><img alt="Coverage" src="https://img.shields.io/scrutinizer/coverage/g/antonioribeiro/google2fa.svg?style=flat-square"></a>
<a href="https://styleci.io/repos/24296182"><img alt="StyleCI" src="https://styleci.io/repos/24296182/shield"></a>
<a href="https://travis-ci.org/antonioribeiro/google2fa"><img alt="PHP" src="https://img.shields.io/badge/PHP-5.4%20--%207.3-brightgreen.svg?style=flat-square"></a>
</p>
### QRCode For Google2FA
This is package is [Goole2FA](https://github.com/antonioribeiro/google2fa) integrated with a QRCode generator, providing an easy way to plot QRCode for your two factor authentication. For documentation related to Google2FA, please check the [documentation of the main package](https://github.com/antonioribeiro/google2fa).
## Requirements
- PHP 5.4+
## Installing
Use Composer to install it:
```
composer require pragmarx/google2fa-qrcode
```
## Using It
### Instantiate it directly
```php
use PragmaRX\Google2FAQRCode\Google2FA;
$google2fa = new Google2FA();
return $google2fa->generateSecretKey();
```
## Generating QRCodes
The securer way of creating QRCode is to do it yourself or using a library. First you have to install the BaconQrCode package, as stated above, then you just have to generate the inline string using:
```php
$inlineUrl = $google2fa->getQRCodeInline(
$companyName,
$companyEmail,
$secretKey
);
```
And use it in your blade template this way:
```html
<img src="{{ $inlineUrl }}">
```
```php
$secretKey = $google2fa->generateSecretKey(16, $userId);
```
## Show the QR Code to your user, via Google Apis
It's insecure to use it via Google Apis, so you have to enable it before using it.
```php
$google2fa->setAllowInsecureCallToGoogleApis(true);
$google2fa_url = $google2fa->getQRCodeGoogleUrl(
'YourCompany',
$user->email,
$user->google2fa_secret
);
/// and in your view:
<img src="{{ $google2fa_url }}" alt="">
```
And they should see and scan the QR code to their applications:
![QRCode](https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FPragmaRX%3Aacr%2Bpragmarx%40antoniocarlosribeiro.com%3Fsecret%3DADUMJO5634NPDEKW%26issuer%3DPragmaRX)
And to verify, you just have to:
```php
$secret = $request->input('secret');
$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);
```
## Replacing the QRCode rendering service
If you want to use a different service, you just have to
```php
$google2fa->setQrcodeService(new YourService())
->getQRCodeInline(
$companyName,
$companyEmail,
$secretKey
);
```
## Built-in QRCode rendering services
Beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes:
- [BaconQrCode](https://github.com/Bacon/BaconQrCode): renders PNG by default, but requires the Imagick PHP extension. You can configure it to use different backends, but you'll have to instantiate it yourself.
- [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode): renders SVG by default and don't require the Imagick PHP extension, but can also generate other formats, which may require Imagick.
## Using a diffent image backend
```php
$google2fa->setQrcodeService(
new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
)
);
// or
$google2fa = new Google2FA(
new Bacon(
new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
)
);
```
## Tests
The package tests were written with [PHPUnit](https://phpunit.de/).
## Authors
- [Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)
- [All Contributors](https://github.com/antonioribeiro/google2fa/graphs/contributors)
## License
Google2FAQRCode is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.
## Contributing
Pull requests and issues are more than welcome.
@@ -0,0 +1,41 @@
{
"name": "pragmarx/google2fa-qrcode",
"description": "QR Code package for Google2FA",
"keywords": ["authentication", "two factor authentication", "google2fa", "2fa", "QRCode", "qr code"],
"license": "MIT",
"authors": [
{
"name": "Antonio Carlos Ribeiro",
"email": "acr@antoniocarlosribeiro.com",
"role": "Creator & Designer"
}
],
"require": {
"php": ">=7.1",
"pragmarx/google2fa": ">=4.0"
},
"require-dev": {
"phpunit/phpunit": "~4|~5|~6|~7|~8|~9",
"khanamiryan/qrcode-detector-decoder": "^1.0",
"bacon/bacon-qr-code": "^2.0",
"chillerlan/php-qrcode": "^1.0|^2.0|^3.0|^4.0"
},
"autoload": {
"psr-4": {
"PragmaRX\\Google2FAQRCode\\": "src/",
"PragmaRX\\Google2FAQRCode\\Tests\\": "tests/"
}
},
"suggest": {
"bacon/bacon-qr-code": "For QR Code generation, requires imagick",
"chillerlan/php-qrcode": "For QR Code generation"
},
"extra": {
"component": "package",
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="coverage/" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="coverage/coverage-clover.xml" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
</logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude></exclude>
</whitelist>
</filter>
</phpunit>
@@ -0,0 +1,9 @@
<?php
namespace PragmaRX\Google2FAQRCode\Exceptions;
use Exception;
class MissingQrCodeServiceException extends Exception
{
}
@@ -0,0 +1,113 @@
<?php
namespace PragmaRX\Google2FAQRCode;
use BaconQrCode\Writer;
use BaconQrCode\Renderer\Image\Png;
use BaconQrCode\Renderer\ImageRenderer;
use PragmaRX\Google2FAQRCode\QRCode\Bacon;
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;
use BaconQrCode\Renderer\Image\RendererInterface;
use BaconQrCode\Writer as BaconQrCodeWriter;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use PragmaRX\Google2FA\Google2FA as Google2FAPackage;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
use PragmaRX\Google2FAQRCode\Exceptions\MissingQrCodeServiceException;
class Google2FA extends Google2FAPackage
{
/**
* @var ImageBackEndInterface|RendererInterface|null $imageBackEnd
*/
protected $qrCodeService;
/**
* Google2FA constructor.
*
* @param QRCodeServiceContract|null $qrCodeService
* @param ImageBackEndInterface|RendererInterface|null $imageBackEnd
*/
public function __construct($qrCodeService = null, $imageBackEnd = null)
{
$this->setQrCodeService(
empty($qrCodeService)
? $this->qrCodeServiceFactory($imageBackEnd)
: $qrCodeService
);
}
/**
* Generates a QR code data url to display inline.
*
* @param string $company
* @param string $holder
* @param string $secret
* @param int $size
* @param string $encoding Default to UTF-8
*
* @return string
*/
public function getQRCodeInline(
$company,
$holder,
$secret,
$size = 200,
$encoding = 'utf-8'
) {
if (empty($this->getQrCodeService())) {
throw new MissingQrCodeServiceException(
'You need to install a service package or assign yourself the service to be used.'
);
}
return $this->qrCodeService->getQRCodeInline(
$this->getQRCodeUrl($company, $holder, $secret),
$size,
$encoding
);
}
/**
* Service setter
*
* @return \PragmaRX\Google2FAQRCode\QRCode\QRCodeServiceContract
*/
public function getQrCodeService()
{
return $this->qrCodeService;
}
/**
* Service setter
*
* @return self
*/
public function setQrCodeService($service)
{
$this->qrCodeService = $service;
return $this;
}
/**
* Create the QR Code service instance
*
* @return \PragmaRX\Google2FAQRCode\QRCode\QRCodeServiceContract
*/
public function qrCodeServiceFactory($imageBackEnd = null)
{
if (
class_exists('BaconQrCode\Writer') &&
class_exists('BaconQrCode\Renderer\ImageRenderer')
) {
return new Bacon($imageBackEnd);
}
if (class_exists('chillerlan\QRCode\QRCode')) {
return new Chillerlan();
}
return null;
}
}
@@ -0,0 +1,97 @@
<?php
namespace PragmaRX\Google2FAQRCode\QRCode;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Writer as BaconQrCodeWriter;
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
use BaconQrCode\Renderer\Image\ImageBackEndInterface;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
class Bacon implements QRCodeServiceContract
{
/**
* @var ImageBackEndInterface|RendererInterface|null $imageBackEnd
*/
protected $imageBackEnd;
/**
* Google2FA constructor.
*
* @param ImageBackEndInterface|RendererInterface|null $imageBackEnd
*/
public function __construct($imageBackEnd = null)
{
$this->imageBackEnd = $imageBackEnd;
}
/**
* Generates a QR code data url to display inline.
*
* @param string $string
* @param int $size
* @param string $encoding Default to UTF-8
*
* @return string
*/
public function getQRCodeInline($string, $size = 200, $encoding = 'utf-8')
{
$renderer = new ImageRenderer(
(new RendererStyle($size))->withSize($size),
$this->getImageBackEnd()
);
$bacon = new Writer($renderer);
$data = $bacon->writeString($string, $encoding);
if ($this->getImageBackEnd() instanceof ImagickImageBackEnd) {
return 'data:image/png;base64,' . base64_encode($data);
}
return $data;
}
/**
* Check if Imagick is available
*
* @return int
*/
public function imagickIsAvailable()
{
return extension_loaded('imagick');
}
/**
* Get image backend
*
* @return ImageRenderer
*/
public function getImageBackend()
{
if (empty($this->imageBackEnd)) {
$this->imageBackEnd = !$this->imagickIsAvailable()
? new SvgImageBackEnd()
: new ImagickImageBackEnd();
}
$this->setImageBackEnd($this->imageBackEnd);
return $this->imageBackEnd;
}
/**
* Set image backend
*
* @param $imageBackEnd
* @return $this
*/
public function setImageBackend($imageBackEnd)
{
$this->imageBackEnd = $imageBackEnd;
return $this;
}
}
@@ -0,0 +1,80 @@
<?php
namespace PragmaRX\Google2FAQRCode\QRCode;
use Illuminate\Support\Str;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use BaconQrCode\Writer as BaconQrCodeWriter;
class Chillerlan implements QRCodeServiceContract
{
protected $options = [];
/**
* Get QRCode options.
*
* @param int $size
* @return \chillerlan\QRCode\QROptions
*/
protected function getOptions()
{
$options = new QROptions($this->buildOptionsArray());
return $options;
}
/**
* Set QRCode options.
*
* @param array $options
* @return self
*/
protected function setOptions($options)
{
$this->options = $options;
return $this;
}
/**
* Build the options array
*
* @param null $size
* @return array
*/
public function buildOptionsArray($size = null)
{
$defaults = [
'version' => QRCode::VERSION_AUTO,
'outputType' => QRCode::OUTPUT_MARKUP_SVG,
'eccLevel' => QRCode::ECC_L,
];
return array_merge($defaults, $this->options);
}
/**
* Generates a QR code data url to display inline.
*
* @param string $string
* @param int $size
* @param string $encoding Default to UTF-8
*
* @return string
*/
public function getQRCodeInline($string, $size = null, $encoding = null)
{
$renderer = new QRCode($this->getOptions());
$header = "data:image/svg+xml;base64,";
$image = $renderer->render($string);
if (strncmp($image, $header, strlen($header)) === 0) {
return $image;
}
return $header . base64_encode($image);
}
}
@@ -0,0 +1,17 @@
<?php
namespace PragmaRX\Google2FAQRCode\QRCode;
interface QRCodeServiceContract
{
/**
* Generates a QR code data url to display inline.
*
* @param string $string
* @param int $size
* @param string $encoding Default to UTF-8
*
* @return string
*/
public function getQRCodeInline($string, $size = 200, $encoding = 'utf-8');
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,89 @@
<?php
namespace PragmaRX\Google2FAQRCode\Tests;
use PragmaRX\Google2FAQRCode\QRCode\Bacon;
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\Image\Png;
use PHPUnit\Framework\TestCase;
use PragmaRX\Google2FAQRCode\Google2FA;
use Zxing\QrReader;
use PragmaRX\Google2FAQRCode\Exceptions\MissingQrCodeServiceException;
class Google2FATest extends TestCase
{
const EMAIL = 'acr+pragmarx@antoniocarlosribeiro.com';
const OTP_URL = 'otpauth://totp/PragmaRX:acr+pragmarx@antoniocarlosribeiro.com?secret=ADUMJO5634NPDEKW&issuer=PragmaRX&algorithm=SHA1&digits=6&period=30';
public function setUp(): void
{
$this->google2fa = new Google2FA();
}
public function readQRCode($data)
{
[, $data] = explode(';', $data);
[, $data] = explode(',', $data);
return rawurldecode(
(new QrReader(
base64_decode($data),
QrReader::SOURCE_TYPE_BLOB
))->text()
);
}
public function testQrcodeServiceMissing()
{
$this->expectException(MissingQrCodeServiceException::class);
$this->google2fa->setQrcodeService(null);
$this->getQrCode();
}
public function testQrcodeInlineBacon()
{
if (!(new Bacon())->imagickIsAvailable()) {
$this->assertTrue(true);
return;
}
$this->google2fa->setQrcodeService(new Bacon());
$this->assertEquals(
static::OTP_URL,
$this->readQRCode($this->getQRCode())
);
$google2fa = new Google2FA(null, new Bacon(new \BaconQrCode\Renderer\Image\SvgImageBackEnd()));
$this->assertEquals(
static::OTP_URL,
$this->readQRCode($this->getQRCode())
);
}
public function testQrcodeInlineChillerlan()
{
$this->google2fa->setQrcodeService(new Chillerlan());
$this->assertStringStartsWith(
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj',
$this->getQRCode()
);
}
public function getQrCode()
{
return $this->google2fa->getQRCodeInline(
'PragmaRX',
static::EMAIL,
Constants::SECRET
);
}
}
@@ -0,0 +1,42 @@
<?php
/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__ . '/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Set The Default Timezone
|--------------------------------------------------------------------------
|
| Here we will set the default timezone for PHP. PHP is notoriously mean
| if the timezone is not explicitly set. This will be used by each of
| the PHP date and date-time functions throughout the application.
|
*/
date_default_timezone_set('UTC');
function d($args)
{
foreach ($args as $arg) {
var_dump($arg);
}
}
function dd()
{
d(func_get_args());
die();
}