|
|
For security reason, we'll add a very simple authentication process to access install/index.php or install/tool.php
- // After line: define('IN_DISCUZ', true);
- // Tool mode authentication
- define('TOOL_MODE_PASSWORD', 'your_strong_password_here'); // Change this!
- $request_uri = $_SERVER['REQUEST_URI'];
- if (basename($request_uri) != 'index.php') {
- // This is tool mode, require authentication
- session_start();
-
- // Check if already authenticated
- if (!isset($_SESSION['tool_auth']) || $_SESSION['tool_auth'] !== true) {
- // Handle login form submission
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['tool_password'])) {
- if ($_POST['tool_password'] === TOOL_MODE_PASSWORD) {
- $_SESSION['tool_auth'] = true;
- // Redirect to remove POST data
- header('Location: ' . $_SERVER['REQUEST_URI']);
- exit;
- } else {
- $error = 'Invalid password!';
- }
- }
-
- // Show login form
- header('HTTP/1.0 403 Forbidden');
- echo '<!DOCTYPE html>
- <html>
- <head>
- <title>Tool Mode Authentication</title>
- <meta charset="utf-8">
- <style>
- body { font-family: Arial, sans-serif; background: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
- .login-box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 300px; }
- h2 { margin-top: 0; color: #333; }
- input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box; }
- button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }
- button:hover { background: #0056b3; }
- .error { color: red; margin-bottom: 10px; font-size: 14px; }
- </style>
- </head>
- <body>
- <div class="login-box">
- <h2>Tool Mode Access</h2>
- ' . (isset($error) ? '<div class="error">' . htmlspecialchars($error) . '</div>' : '') . '
- <form method="post">
- <input type="password" name="tool_password" placeholder="Enter tool password" autofocus>
- <button type="submit">Authenticate</button>
- </form>
- </div>
- </body>
- </html>';
- exit;
- }
- }
Copy Code
That'll protect your tool from black hat hackers |
|