67 lines
3.2 KiB
PHP
67 lines
3.2 KiB
PHP
<?php
|
|
|
|
// Read-only access inventory. Never prints passwords, hashes, keys or cookies.
|
|
$mode = $argv[1] ?? '';
|
|
$root = $mode === 'compras-main' || $mode === 'compras-payables' ? 'C:/laragon/www/compras' : 'C:/laragon/www/sgf-tempo';
|
|
if (! in_array($mode, ['sgf-main', 'compras-main', 'sgf-product', 'sgf-budget', 'sgf-payables', 'compras-payables'], true)) {
|
|
throw new LogicException('Unknown instance');
|
|
}
|
|
$manifest = null;
|
|
if (str_ends_with($mode, '-payables')) {
|
|
$host = str_starts_with($mode, 'compras') ? 'compras' : 'sgf';
|
|
$settings = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-'.$host.'.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
$manifest = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-'.$host.'-access.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
} elseif ($mode === 'sgf-budget') {
|
|
$settings = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/budget-demo.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
} elseif ($mode === 'sgf-product') {
|
|
$settings = ['APP_ENV' => 'browser-testing'];
|
|
$manifest = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/browser-fixture.json'), true, 64, JSON_THROW_ON_ERROR);
|
|
} else {
|
|
$settings = [];
|
|
}
|
|
foreach ($settings as $k => $v) {
|
|
putenv($k.'='.$v);
|
|
$_ENV[$k] = $_SERVER[$k] = $v;
|
|
}
|
|
require $root.'/vendor/autoload.php';
|
|
$app = require $root.'/bootstrap/app.php';
|
|
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
$db = \Illuminate\Support\Facades\DB::connection();
|
|
$db->beginTransaction();
|
|
try {
|
|
if ($db->getDriverName() === 'pgsql') {
|
|
$db->statement('SET TRANSACTION READ ONLY');
|
|
}
|
|
$accounts = [];
|
|
foreach (\App\Models\User::query()->orderBy('id')->get() as $u) {
|
|
$record = ['id' => $u->id, 'email' => $u->email, 'verified' => (bool) $u->email_verified_at];
|
|
if (str_contains($u->email, '@example.test')) {
|
|
$record['synthetic'] = true;
|
|
$candidate = null;
|
|
if (isset($manifest['accounts'])) {
|
|
foreach ($manifest['accounts'] as $role => $a) {
|
|
if ($a['email'] === $u->email) {
|
|
$record['role'] = $role;
|
|
$candidate = $a['password'];
|
|
}
|
|
}
|
|
} elseif (isset($manifest['password'])) {
|
|
$candidate = $manifest['password'];
|
|
}
|
|
if ($candidate !== null) {
|
|
$record['stored_demo_credential_matches'] = \Illuminate\Support\Facades\Hash::check($candidate, $u->password);
|
|
}
|
|
}
|
|
if (isset($u->tenant_id)) {
|
|
$record['tenant_id'] = (int) $u->tenant_id;
|
|
}
|
|
$accounts[] = $record;
|
|
}
|
|
echo json_encode(['instance' => $mode, 'environment' => app()->environment(), 'database' => $db->getDatabaseName(),
|
|
'effective_database' => $db->getDriverName() === 'pgsql' ? $db->selectOne('select current_database() as d')->d : $db->getDatabaseName(),
|
|
'session_cookie' => config('session.cookie'), 'session_domain' => config('session.domain'),
|
|
'accounts' => $accounts, 'read_only' => true], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR).PHP_EOL;
|
|
} finally {
|
|
$db->rollBack();
|
|
}
|