mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-23 00:33:18 +01:00
Add icon import from Aegis migration data
This commit is contained in:
parent
1af32ecbf4
commit
eb05d39210
@ -8,6 +8,8 @@
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Exceptions\InvalidMigrationDataException;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Helpers\Helpers;
|
||||
|
||||
class AegisMigrator extends Migrator
|
||||
{
|
||||
@ -47,7 +49,7 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
}
|
||||
|
||||
foreach ($json['db']['entries'] as $key => $otp_parameters) {
|
||||
// Storage::put('file.jpg', $contents);
|
||||
|
||||
$parameters = array();
|
||||
$parameters['otp_type'] = $otp_parameters['type'] == 'steam' ? TwoFAccount::STEAM_TOTP : $otp_parameters['type'];
|
||||
$parameters['service'] = $otp_parameters['issuer'];
|
||||
@ -58,6 +60,41 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
$parameters['counter'] = $otp_parameters['info']['counter'] ?? null;
|
||||
$parameters['period'] = $otp_parameters['info']['period'] ?? null;
|
||||
|
||||
try {
|
||||
// Aegis supports 3 image extensions for icons
|
||||
// (see https://github.com/beemdevelopment/Aegis/blob/3c10b234ea70715776a09e3d200cb6e806a43f83/docs/iconpacks.md)
|
||||
|
||||
if (Arr::has($otp_parameters, 'icon') && Arr::has($otp_parameters, 'icon_mime')) {
|
||||
switch ($otp_parameters['icon_mime']) {
|
||||
case 'image/svg+xml':
|
||||
$extension = 'svg';
|
||||
break;
|
||||
|
||||
case 'image/png':
|
||||
$extension = 'png';
|
||||
break;
|
||||
|
||||
case 'image/jpeg':
|
||||
$extension = 'jpg';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception();
|
||||
break;
|
||||
}
|
||||
|
||||
$filename = Helpers::getUniqueFilename($extension);
|
||||
|
||||
if (Storage::disk('icons')->put($filename, base64_decode($otp_parameters['icon']))) {
|
||||
$parameters['icon'] = $filename;
|
||||
Log::info(sprintf('Image %s successfully stored for import', $filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Exception) {
|
||||
// we do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
$twofaccounts[$key] = new TwoFAccount;
|
||||
$twofaccounts[$key]->fillWithOtpParameters($parameters);
|
||||
|
Loading…
Reference in New Issue
Block a user