68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
$flagFile = '/opt/mediawiki/.setup-complete';
|
|
|
|
if (file_exists($flagFile)) {
|
|
echo "<h2>Setup already completed</h2><p>The admin password has already been set. To change it, use the MediaWiki user interface or maintenance tools.</p>";
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$password = $_POST['password'] ?? '';
|
|
$confirm = $_POST['confirm'] ?? '';
|
|
|
|
if ($password !== $confirm) {
|
|
$error = "Passwords do not match.";
|
|
} elseif (strlen($password) < 6) {
|
|
$error = "Password must be at least 6 characters.";
|
|
} else {
|
|
$safePassword = escapeshellarg($password);
|
|
$output = [];
|
|
$return = 0;
|
|
|
|
exec("php /var/www/html/maintenance/run.php changePassword --user=admin --password=$safePassword", $output, $return);
|
|
|
|
if ($return === 0) {
|
|
file_put_contents($flagFile, "Admin password set on " . date('c') . "\n");
|
|
echo "<h2>Success!</h2><p>The admin password has been updated. You can now log in and start using your wiki.</p>";
|
|
exit;
|
|
} else {
|
|
$error = "Failed to update password. Please check server permissions.";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Set Admin Password - MediaWiki Appliance</title>
|
|
<style>
|
|
body { font-family: sans-serif; margin: 2em; max-width: 500px; }
|
|
label { display: block; margin-top: 1em; }
|
|
input[type=password] { width: 100%; padding: 0.5em; }
|
|
input[type=submit] { margin-top: 1em; padding: 0.5em 1em; }
|
|
.error { color: red; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Set Admin Password</h1>
|
|
<p>This is a one-time setup page to secure your MediaWiki appliance. After submitting, this setup interface will be disabled.</p>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
<p class="error"><?= htmlspecialchars($error) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
<label>New Admin Password:
|
|
<input type="password" name="password" required>
|
|
</label>
|
|
|
|
<label>Confirm Password:
|
|
<input type="password" name="confirm" required>
|
|
</label>
|
|
|
|
<input type="submit" value="Set Password">
|
|
</form>
|
|
</body>
|
|
</html>
|