mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
- Consume an ExternalAccount on Account creation - Add a tombstone to an ExternalAccount to ensure non re-usage - Add related tests - Generalize Utils - Stop public registration when there is no ExternalAccounts left - Add GenerateExternalAccounts, ExportToExternalAccounts and ImportExternalAccounts console scripts - Provision the ExternalAccount using the depends_on/idkey pair
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Account;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ExportToExternalAccounts extends Command
|
|
{
|
|
protected $signature = 'accounts:export-to-externals {group} {--o|output=}';
|
|
|
|
protected $description = 'Export accounts from a group as external ones';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$accounts = Account::where('group', $this->argument('group'))
|
|
->with('passwords')
|
|
->get();
|
|
|
|
if ($accounts->count() == 0) {
|
|
$this->error('Nothing to export');
|
|
return;
|
|
}
|
|
|
|
$this->info('Exporting '.$accounts->count().' accounts');
|
|
|
|
$data = [];
|
|
|
|
foreach ($accounts as $account) {
|
|
array_push($data, [
|
|
'username' => $account->username,
|
|
'domain' => $account->domain,
|
|
'group' => $account->group,
|
|
'password' => $account->passwords->first()->password,
|
|
'algorithm' => $account->passwords->first()->algorithm,
|
|
]);
|
|
}
|
|
|
|
file_put_contents(
|
|
$this->option('output') ?? getcwd() . '/exported_accounts.json',
|
|
json_encode($data)
|
|
);
|
|
|
|
$this->info('Exported');
|
|
}
|
|
}
|