From 307c379fa8d5a3554b3d98fd0e977011190b07c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 25 Jul 2022 12:18:06 +0200 Subject: [PATCH] Add validation for GenerateExternalAccounts Add a migration to change the accounts group column to 64 chars Update the dependencies Bump the package number --- .../Commands/GenerateExternalAccounts.php | 39 ++++++++++++++++++- flexiapi/composer.lock | 26 ++++++------- ...hange_group_length_from_accounts_table.php | 27 +++++++++++++ flexisip-account-manager.spec | 2 +- 4 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 flexiapi/database/migrations/2022_07_25_095147_change_group_length_from_accounts_table.php diff --git a/flexiapi/app/Console/Commands/GenerateExternalAccounts.php b/flexiapi/app/Console/Commands/GenerateExternalAccounts.php index 01509dc..145ed38 100644 --- a/flexiapi/app/Console/Commands/GenerateExternalAccounts.php +++ b/flexiapi/app/Console/Commands/GenerateExternalAccounts.php @@ -4,8 +4,11 @@ namespace App\Console\Commands; use App\Account; use App\Password; +use App\Rules\NoUppercase; + use Carbon\Carbon; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; class GenerateExternalAccounts extends Command @@ -21,6 +24,40 @@ class GenerateExternalAccounts extends Command public function handle() { + $validator = Validator::make([ + 'amount' => $this->argument('amount'), + 'group' => $this->argument('group'), + ], [ + 'amount' => ['required', 'integer'], + 'group' => ['required', 'alpha-dash', new NoUppercase] + ]); + + if ($validator->fails()) { + $this->info('External accounts no created:'); + + foreach ($validator->errors()->all() as $error) { + $this->error($error); + } + + return 1; + } + + $groups = Account::distinct('group') + ->whereNotNull('group') + ->get('group') + ->pluck('group') + ->toArray(); + + if (!in_array($this->argument('group'), $groups)) { + $this->info('Existing groups: '.implode(',', $groups)); + + if (!$this->confirm('You are creating a new group of External Account, are you sure?', false)) + { + $this->info('Creation aborted'); + return 0; + } + } + $accounts = collect(); $passwords = collect(); $algorithm = 'SHA-256'; @@ -29,7 +66,7 @@ class GenerateExternalAccounts extends Command while ($i < $this->argument('amount')) { $account = new Account; - $account->username = $this->argument('group') . '_' . Str::random(6); + $account->username = Str::random(12); $account->domain = config('app.sip_domain'); $account->activated = 1; $account->ip_address = '127.0.0.1'; diff --git a/flexiapi/composer.lock b/flexiapi/composer.lock index a6369fd..f3003da 100644 --- a/flexiapi/composer.lock +++ b/flexiapi/composer.lock @@ -1468,16 +1468,16 @@ }, { "name": "laravel/framework", - "version": "v8.83.19", + "version": "v8.83.22", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "4264f2ee12330bdb1be050998f58ba7271236395" + "reference": "96aecced5126d48e277e5339193c376fe82b6565" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/4264f2ee12330bdb1be050998f58ba7271236395", - "reference": "4264f2ee12330bdb1be050998f58ba7271236395", + "url": "https://api.github.com/repos/laravel/framework/zipball/96aecced5126d48e277e5339193c376fe82b6565", + "reference": "96aecced5126d48e277e5339193c376fe82b6565", "shasum": "" }, "require": { @@ -1637,7 +1637,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-07-13T13:23:09+00:00" + "time": "2022-07-22T14:16:24+00:00" }, { "name": "laravel/serializable-closure", @@ -2083,16 +2083,16 @@ }, { "name": "monolog/monolog", - "version": "2.7.0", + "version": "2.8.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "5579edf28aee1190a798bfa5be8bc16c563bd524" + "reference": "720488632c590286b88b80e62aa3d3d551ad4a50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/5579edf28aee1190a798bfa5be8bc16c563bd524", - "reference": "5579edf28aee1190a798bfa5be8bc16c563bd524", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/720488632c590286b88b80e62aa3d3d551ad4a50", + "reference": "720488632c590286b88b80e62aa3d3d551ad4a50", "shasum": "" }, "require": { @@ -2112,11 +2112,10 @@ "guzzlehttp/psr7": "^2.2", "mongodb/mongodb": "^1.8", "php-amqplib/php-amqplib": "~2.4 || ^3", - "php-console/php-console": "^3.1.3", "phpspec/prophecy": "^1.15", "phpstan/phpstan": "^0.12.91", "phpunit/phpunit": "^8.5.14", - "predis/predis": "^1.1", + "predis/predis": "^1.1 || ^2.0", "rollbar/rollbar": "^1.3 || ^2 || ^3", "ruflin/elastica": "^7", "swiftmailer/swiftmailer": "^5.3|^6.0", @@ -2136,7 +2135,6 @@ "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)", "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", - "php-console/php-console": "Allow sending log messages to Google Chrome", "rollbar/rollbar": "Allow sending log messages to Rollbar", "ruflin/elastica": "Allow sending log messages to an Elastic Search server" }, @@ -2171,7 +2169,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/2.7.0" + "source": "https://github.com/Seldaek/monolog/tree/2.8.0" }, "funding": [ { @@ -2183,7 +2181,7 @@ "type": "tidelift" } ], - "time": "2022-06-09T08:59:12+00:00" + "time": "2022-07-24T11:55:47+00:00" }, { "name": "nesbot/carbon", diff --git a/flexiapi/database/migrations/2022_07_25_095147_change_group_length_from_accounts_table.php b/flexiapi/database/migrations/2022_07_25_095147_change_group_length_from_accounts_table.php new file mode 100644 index 0000000..d4d3089 --- /dev/null +++ b/flexiapi/database/migrations/2022_07_25_095147_change_group_length_from_accounts_table.php @@ -0,0 +1,27 @@ +string('group', 64)->change(); + } + }); + } + + public function down() + { + Schema::table('accounts', function (Blueprint $table) { + if (DB::getDriverName() !== 'sqlite') { + $table->string('group', 16)->change(); + } + }); + } +} diff --git a/flexisip-account-manager.spec b/flexisip-account-manager.spec index bbd71a9..a0dbdd7 100644 --- a/flexisip-account-manager.spec +++ b/flexisip-account-manager.spec @@ -8,7 +8,7 @@ #%define _datadir %{_datarootdir} #%define _docdir %{_datadir}/doc -%define build_number 145 +%define build_number 146 %define var_dir /var/opt/belledonne-communications %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager