Working, but incomplete
This commit is contained in:
54
activate/index.php
Normal file
54
activate/index.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
$setupFlag = '/var/lib/vaultwarden/.setup-complete';
|
||||
$envFile = '/var/lib/vaultwarden/.env.user';
|
||||
|
||||
if (file_exists($setupFlag)) {
|
||||
header('Location: /admin');
|
||||
exit;
|
||||
}
|
||||
|
||||
function generateToken($length = 64): string {
|
||||
return bin2hex(random_bytes($length / 2));
|
||||
}
|
||||
|
||||
// Generate token and secure hash
|
||||
$adminToken = generateToken();
|
||||
$hashedToken = password_hash($adminToken, PASSWORD_ARGON2ID);
|
||||
|
||||
// Write to .env.user
|
||||
$envVars = [ "ADMIN_TOKEN='{$hashedToken}'" ];
|
||||
$writeSuccess = file_put_contents($envFile, implode("\n", $envVars) . "\n");
|
||||
|
||||
if ($writeSuccess) {
|
||||
touch($setupFlag);
|
||||
chown($envFile, 'www-data');
|
||||
chmod($envFile, 0640);
|
||||
exec('systemctl restart vaultwarden.service');
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vaultwarden Setup Complete</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 2em; background: #f2f2f2; color: #222; }
|
||||
.container { background: #fff; padding: 2em; border-radius: 8px; max-width: 600px; margin: 0 auto; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
|
||||
code { background: #eee; padding: 0.2em 0.4em; border-radius: 4px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Vaultwarden Setup Complete</h1>
|
||||
<?php if ($writeSuccess && $hashedToken): ?>
|
||||
<p><strong>Your admin token has been generated and securely hashed. Please copy and store this token:</strong></p>
|
||||
<p><code><?= htmlspecialchars($adminToken) ?></code></p>
|
||||
<p>To access the Vaultwarden admin interface, click below:</p>
|
||||
<p><a href="/admin">Open Admin Panel</a></p>
|
||||
<p><em>Note: If you ever need to reset this setup, delete <code>/opt/vaultwarden/.setup-complete</code> and reload this page.</em></p>
|
||||
<?php else: ?>
|
||||
<p><strong>Error:</strong> Unable to generate or save the admin token. Please check permissions or disk space.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user