|
@@ -22,6 +22,7 @@ use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
+use Illuminate\Support\Str;
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
use OTPHP\Factory;
|
|
|
use OTPHP\HOTP;
|
|
@@ -30,7 +31,6 @@ use ParagonIE\ConstantTime\Base32;
|
|
|
use Spatie\EloquentSortable\Sortable;
|
|
|
use Spatie\EloquentSortable\SortableTrait;
|
|
|
use SteamTotp\SteamTotp;
|
|
|
-use Illuminate\Support\Str;
|
|
|
|
|
|
class TwoFAccount extends Model implements Sortable
|
|
|
{
|
|
@@ -144,13 +144,13 @@ class TwoFAccount extends Model implements Sortable
|
|
|
parent::boot();
|
|
|
|
|
|
static::saving(function (TwoFAccount $twofaccount) {
|
|
|
- if (!$twofaccount->legacy_uri) {
|
|
|
+ if (! $twofaccount->legacy_uri) {
|
|
|
$twofaccount->legacy_uri = $twofaccount->getURI();
|
|
|
}
|
|
|
- if ($twofaccount->otp_type == TwoFAccount::TOTP && !$twofaccount->period) {
|
|
|
+ if ($twofaccount->otp_type == TwoFAccount::TOTP && ! $twofaccount->period) {
|
|
|
$twofaccount->period = TwoFAccount::DEFAULT_PERIOD;
|
|
|
}
|
|
|
- if ($twofaccount->otp_type == TwoFAccount::HOTP && !$twofaccount->counter) {
|
|
|
+ if ($twofaccount->otp_type == TwoFAccount::HOTP && ! $twofaccount->counter) {
|
|
|
$twofaccount->counter = TwoFAccount::DEFAULT_COUNTER;
|
|
|
}
|
|
|
});
|
|
@@ -255,7 +255,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
*/
|
|
|
public function setDigitsAttribute($value)
|
|
|
{
|
|
|
- $this->attributes['digits'] = !$value ? 6 : $value;
|
|
|
+ $this->attributes['digits'] = ! $value ? 6 : $value;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -266,7 +266,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
*/
|
|
|
public function setAlgorithmAttribute($value)
|
|
|
{
|
|
|
- $this->attributes['algorithm'] = !$value ? self::SHA1 : strtolower($value);
|
|
|
+ $this->attributes['algorithm'] = ! $value ? self::SHA1 : strtolower($value);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -277,7 +277,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
*/
|
|
|
public function setPeriodAttribute($value)
|
|
|
{
|
|
|
- $this->attributes['period'] = !$value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value;
|
|
|
+ $this->attributes['period'] = ! $value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -376,7 +376,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
$this->enforceAsSteam();
|
|
|
}
|
|
|
|
|
|
- if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
|
|
|
+ if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) {
|
|
|
$this->icon = $this->getDefaultIcon();
|
|
|
}
|
|
|
|
|
@@ -403,7 +403,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
|
|
|
// As loadFromProvisioningUri() accept URI without label (nor account nor service) we check
|
|
|
// that the account is set
|
|
|
- if (!$this->generator->getLabel()) {
|
|
|
+ if (! $this->generator->getLabel()) {
|
|
|
Log::error('URI passed to fillWithURI() must contain a label');
|
|
|
|
|
|
throw ValidationException::withMessages([
|
|
@@ -428,7 +428,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
self::setIcon($this->generator->getParameter('image'));
|
|
|
}
|
|
|
|
|
|
- if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
|
|
|
+ if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) {
|
|
|
$this->icon = $this->getDefaultIcon();
|
|
|
}
|
|
|
|
|
@@ -440,7 +440,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
/**
|
|
|
* Compare 2 TwoFAccounts
|
|
|
*/
|
|
|
- public function equals(self $other): bool
|
|
|
+ public function equals(self $other) : bool
|
|
|
{
|
|
|
return $this->service === $other->service &&
|
|
|
$this->account === $other->account &&
|
|
@@ -456,7 +456,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
/**
|
|
|
* Sets model attributes to STEAM values
|
|
|
*/
|
|
|
- private function enforceAsSteam(): void
|
|
|
+ private function enforceAsSteam() : void
|
|
|
{
|
|
|
$this->otp_type = self::STEAM_TOTP;
|
|
|
$this->digits = 5;
|
|
@@ -479,7 +479,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
/**
|
|
|
* Returns an otpauth URI built with model attribute values
|
|
|
*/
|
|
|
- public function getURI(): string
|
|
|
+ public function getURI() : string
|
|
|
{
|
|
|
$this->initGenerator();
|
|
|
|
|
@@ -492,7 +492,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
* @throws UnsupportedOtpTypeException The defined OTP type is not supported
|
|
|
* @throws InvalidOtpParameterException One OTP parameter is invalid
|
|
|
*/
|
|
|
- private function initGenerator(): void
|
|
|
+ private function initGenerator() : void
|
|
|
{
|
|
|
try {
|
|
|
switch ($this->otp_type) {
|
|
@@ -538,11 +538,11 @@ class TwoFAccount extends Model implements Sortable
|
|
|
|
|
|
/**
|
|
|
* Store and set the provided icon
|
|
|
- *
|
|
|
+ *
|
|
|
* @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $data
|
|
|
* @param string|null $extension The resource extension, without the dot
|
|
|
*/
|
|
|
- public function setIcon($data, $extension = null): void
|
|
|
+ public function setIcon($data, $extension = null) : void
|
|
|
{
|
|
|
$isRemoteData = Str::startsWith($data, ['http://', 'https://']) && Validator::make(
|
|
|
[$data],
|
|
@@ -565,7 +565,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
* @param string $extension The file extension, without the dot
|
|
|
* @return string|null The filename of the stored icon or null if the operation fails
|
|
|
*/
|
|
|
- private function storeFileDataAsIcon($content, $extension): string|null
|
|
|
+ private function storeFileDataAsIcon($content, $extension) : string|null
|
|
|
{
|
|
|
$filename = self::getUniqueFilename($extension);
|
|
|
|
|
@@ -582,14 +582,13 @@ class TwoFAccount extends Model implements Sortable
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Generate a unique filename
|
|
|
*
|
|
|
* @param string $extension
|
|
|
* @return string The filename
|
|
|
*/
|
|
|
- private function getUniqueFilename(string $extension): string
|
|
|
+ private function getUniqueFilename(string $extension) : string
|
|
|
{
|
|
|
return Str::random(40) . '.' . $extension;
|
|
|
}
|
|
@@ -601,7 +600,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
* @param string $disk
|
|
|
* @return bool
|
|
|
*/
|
|
|
- private function isValidIcon($filename, $disk): bool
|
|
|
+ private function isValidIcon($filename, $disk) : bool
|
|
|
{
|
|
|
return in_array(Storage::disk($disk)->mimeType($filename), [
|
|
|
'image/png',
|
|
@@ -609,7 +608,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
'image/webp',
|
|
|
'image/bmp',
|
|
|
'image/x-ms-bmp',
|
|
|
- 'image/svg+xml'
|
|
|
+ 'image/svg+xml',
|
|
|
]) && (Storage::disk($disk)->mimeType($filename) !== 'image/svg+xml' ? getimagesize(Storage::disk($disk)->path($filename)) : true);
|
|
|
}
|
|
|
|
|
@@ -618,7 +617,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
*
|
|
|
* @return string|null The filename of the stored icon or null if the operation fails
|
|
|
*/
|
|
|
- private function storeRemoteImageAsIcon(string $url): string|null
|
|
|
+ private function storeRemoteImageAsIcon(string $url) : string|null
|
|
|
{
|
|
|
try {
|
|
|
$path_parts = pathinfo($url);
|
|
@@ -672,7 +671,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
/**
|
|
|
* Returns an acceptable value
|
|
|
*/
|
|
|
- private function decryptOrReturn(mixed $value): mixed
|
|
|
+ private function decryptOrReturn(mixed $value) : mixed
|
|
|
{
|
|
|
// Decipher when needed
|
|
|
if (Settings::get('useEncryption') && $value) {
|
|
@@ -689,7 +688,7 @@ class TwoFAccount extends Model implements Sortable
|
|
|
/**
|
|
|
* Encrypt a value
|
|
|
*/
|
|
|
- private function encryptOrReturn(mixed $value): mixed
|
|
|
+ private function encryptOrReturn(mixed $value) : mixed
|
|
|
{
|
|
|
// should be replaced by laravel 8 attribute encryption casting
|
|
|
return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;
|