-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
107 lines (94 loc) · 2.45 KB
/
auth.php
File metadata and controls
107 lines (94 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Authentication Handler
*/
// Security: Prevent direct access
if (!defined('PANEL_ACCESS')) {
die('Direct access not permitted');
}
session_start();
/**
* Check if user is logged in
*/
function isLoggedIn() {
return isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true;
}
/**
* Login user
*/
function login($password) {
if ($password === ADMIN_PASSWORD) {
$_SESSION['authenticated'] = true;
$_SESSION['login_time'] = time();
$_SESSION['user_ip'] = $_SERVER['REMOTE_ADDR'];
return true;
}
return false;
}
/**
* Logout user
*/
function logout() {
session_destroy();
header('Location: index.php');
exit;
}
/**
* Require authentication
*/
function requireAuth() {
if (!isLoggedIn()) {
showLoginPage();
exit;
}
}
/**
* Show login page
*/
function showLoginPage() {
$error = '';
if (isset($_POST['login'])) {
if (login($_POST['password'])) {
header('Location: index.php');
exit;
} else {
$error = 'Invalid password';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo PANEL_TITLE; ?> - Login</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body class="login-page">
<div class="login-container">
<div class="login-header">
<h1>🖥️ <?php echo PANEL_TITLE; ?></h1>
<p>Server: <?php echo SERVER_IP; ?></p>
</div>
<?php if ($error): ?>
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST" class="login-form">
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required autofocus>
</div>
<button type="submit" name="login" class="btn btn-primary btn-block">Login</button>
</form>
<div class="login-footer">
<small>⚠️ Change default password in config.php</small>
</div>
</div>
</body>
</html>
<?php
}
// Handle logout
if (isset($_GET['logout'])) {
logout();
}