diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f1b4e4..8093430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ v1.7 ---- - Fix FLEXIAPI-206 Upgrade to Laravel 10, PHP 8.1 minimum and bump all the related dependencies, drop Debian 11 Bullseye - Fix FLEXIAPI-220 Migrate SIP Domains to Spaces +- Fix GH-15 Add password import from CSV v1.6 ---- diff --git a/flexiapi/app/Http/Controllers/Admin/AccountImportController.php b/flexiapi/app/Http/Controllers/Admin/AccountImportController.php index a7132cc..01ce23a 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountImportController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountImportController.php @@ -20,6 +20,7 @@ namespace App\Http\Controllers\Admin; use App\Account; +use App\Password; use App\Http\Controllers\Controller; use Illuminate\Support\Collection; use Illuminate\Http\Request; @@ -166,7 +167,7 @@ class AccountImportController extends Controller $accounts = []; $now = \Carbon\Carbon::now(); - $admins = $phones = []; + $admins = $phones = $passwords = []; foreach ($lines as $line) { if ($line->role == 'admin') { @@ -177,6 +178,10 @@ class AccountImportController extends Controller $phones[$line->username] = $line->phone; } + if (!empty($line->password)) { + $passwords[$line->username] = $line->password; + } + array_push($accounts, [ 'username' => $line->username, 'domain' => $request->get('domain'), @@ -199,6 +204,31 @@ class AccountImportController extends Controller $account->admin = true; } + // Set passwords + + $passwordsToInsert = []; + + $passwordAccounts = Account::whereIn('username', array_keys($passwords)) + ->where('domain', $request->get('domain')) + ->get(); + + $algorithm = config('app.account_default_password_algorithm'); + + foreach ($passwordAccounts as $passwordAccount) { + array_push($passwordsToInsert, [ + 'account_id' => $passwordAccount->id, + 'password' => bchash( + $passwordAccount->username, + config('app.account_realm') ?? $request->get('domain'), + $passwords[$passwordAccount->username], + $algorithm + ), + 'algorithm' => $algorithm + ]); + } + + Password::insert($passwordsToInsert); + // Set admins accounts foreach ($phones as $username => $phone) { $account = Account::where('username', $username) diff --git a/flexiapi/public/accounts_example.csv b/flexiapi/public/accounts_example.csv index f23198d..b982405 100644 --- a/flexiapi/public/accounts_example.csv +++ b/flexiapi/public/accounts_example.csv @@ -1,4 +1,4 @@ Username,Password,Role,Status,Phone,Email john,number9,user,active,+12341234,john@lennon.com paul,a_day_in_the_life,admin,active,,paul@apple.com -ringo,allUneedIsL3ve,user,unactove,+123456,ringo@star.co.uk \ No newline at end of file +ringo,allUneedIsL3ve,user,unactive,+123456,ringo@star.co.uk \ No newline at end of file