-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
229 lines (210 loc) · 11.8 KB
/
dashboard.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('config.php'); // Include the database configuration to connect to the database
include "functions.php";
include "header.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container-boxed mt-4">
<h3>Dashboard</h3>
<hr>
<?php if (isset($success_message)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php echo htmlspecialchars($success_message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php elseif (isset($error_message)): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?php echo htmlspecialchars($error_message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php if ($showUpdateCard): ?>
<div class="card mb-4 border-warning">
<div class="card-header bg-warning text-dark">
<i class="bi bi-exclamation-circle"></i> <strong>Password Rotation </strong>
</div>
<div class="card-body">
<?php foreach ($credentials as $credential): ?>
<?php
$daysOld = calculateDaysOld($credential['updated_at']); // Correct column name used here
$isOld = $daysOld > 90; // Only show credentials older than 90 days
?>
<?php if ($isOld): ?>
<div class="d-flex justify-content-between align-items-center mb-3">
<div>
<strong><?php echo htmlspecialchars($credential['name']); ?></strong> -
<span><?php echo $credential['updated_at'] !== null ? htmlspecialchars((new DateTime($credential['updated_at']))->format('d.m.Y - H:i:s')) : 'N/A'; ?></span>
-
<span class="text-muted"><?php echo $daysOld; ?> days old</span>
<span class="badge bg-warning text-dark">
<i class="bi bi-exclamation-triangle"></i> Needs Update
</span>
</div>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#editCredentialModal"
data-id="<?php echo $credential['credential_id']; ?>"
data-name="<?php echo htmlspecialchars($credential['name']); ?>"
data-username="<?php echo htmlspecialchars($credential['username']); ?>"
data-password="<?php echo htmlspecialchars($credential['password']); ?>"
data-otp="<?php echo htmlspecialchars($credential['otp']); ?>"
data-url="<?php echo htmlspecialchars($credential['url']); ?>"
onclick="populateEditModal(this)">
<i class="bi bi-pencil-square"></i> Update
</button>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<div class="card-footer text-danger">
<i class="bi bi-shield-lock"></i> <strong>Recommendation:</strong> If your passwords have not been updated in over 90 days, consider changing them for security reasons.
</div>
</div>
<?php endif; ?>
<div class="row mb-4">
<div class="col-12 col-md-6 d-flex align-items-center mb-3 mb-md-0">
<span class="badge bg-secondary py-2 px-3 me-2">
<?php echo count($credentials); ?>
</span>
<form method="GET" action="dashboard.php" class="d-flex align-items-center w-100">
<input type="text" name="search" class="form-control me-2" placeholder="Search password..." value="<?php echo htmlspecialchars($search); ?>">
<button type="submit" class="btn btn-primary">Go</button>
</form>
</div>
<div class="col-12 col-md-6 d-flex justify-content-end">
<button class="btn btn-outline-success me-2" id="exportCsv" onclick="exportToCSV()">
<i class="bi bi-file-earmark-excel"></i> Export CSV
</button>
<button class="btn btn-primary" id="addCredentials" data-bs-toggle="modal" data-bs-target="#addCredentialModal">
<i class="bi bi-plus-circle"></i> Add Credentials
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle table-modern table-bordered">
<thead class="table-dark">
<tr>
<th class="text-start">Name</th>
<th>URL</th>
<th>Username</th>
<th>Password</th>
<th>OTP / 2FA Owner</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="credentialTable">
<?php foreach ($credentials as $credential): ?>
<tr>
<td class="text-start"><strong><?php echo htmlspecialchars($credential['name']); ?></strong></td>
<td>
<button class="btn btn-sm btn-outline-primary"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="<?php echo htmlspecialchars($credential['url']); ?>"
onclick="window.open('<?php echo htmlspecialchars($credential['url']); ?>', '_blank')">
<i class="fas fa-external-link-alt"></i>
</button>
<button class="btn btn-sm btn-outline-secondary btn-copy"
onclick="copyToClipboard(this, '<?php echo htmlspecialchars($credential['url']); ?>')">
<i class="fa fa-clipboard"></i>
</button>
</td>
<td>
<?php echo htmlspecialchars($credential['username']); ?>
<button class="btn btn-sm btn-outline-secondary btn-copy" onclick="copyToClipboard(this, '<?php echo htmlspecialchars($credential['username']); ?>')">
<i class="fa fa-clipboard"></i>
</button>
</td>
<td>
<div class="d-flex align-items-center justify-content-center">
<input type="password" value="<?php echo htmlspecialchars($credential['password']); ?>" class="form-control w-auto" readonly>
<button class="btn btn-sm btn-outline-secondary ms-2" onclick="togglePassword(this)">
<i class="fa fa-eye"></i>
</button>
<button class="btn btn-sm btn-outline-secondary btn-copy ms-2" onclick="copyToClipboard(this, '<?php echo htmlspecialchars($credential['password']); ?>')">
<i class="fa fa-clipboard"></i>
</button>
</div>
</td>
<td><?php echo htmlspecialchars($credential['otp']); ?></td>
<td>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
<i class="fa fa-ellipsis-h"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#editCredentialModal"
data-id="<?php echo $credential['credential_id']; ?>"
data-name="<?php echo htmlspecialchars($credential['name']); ?>"
data-username="<?php echo htmlspecialchars($credential['username']); ?>"
data-password="<?php echo htmlspecialchars($credential['password']); ?>"
data-otp="<?php echo htmlspecialchars($credential['otp']); ?>"
data-url="<?php echo htmlspecialchars($credential['url']); ?>"
onclick="populateEditModal(this)">
<i class="fa fa-edit"></i> Edit
</a>
</li>
<?php if ($credential['user_id'] == $user_id || in_array($role, ['admin', 'manager'])): ?>
<li>
<a class="dropdown-item text-danger" href="#" data-bs-toggle="modal" data-bs-target="#deleteCredentialModal"
onclick="setDeleteCredentialInfo(<?php echo $credential['credential_id']; ?>, '<?php echo htmlspecialchars($credential['name']); ?>')">
<i class="fa fa-trash"></i> Delete
</a>
</li>
<?php endif; ?>
<li><hr class="dropdown-divider"></li>
<li>
<small class="dropdown-item">
<i class="fa fa-user"></i> By: <span class="text-muted"> <?php echo htmlspecialchars($credential['first_name']) . ' ' . htmlspecialchars($credential['second_name']); ?></span><br>
<i class="fa fa-calendar"></i>
<span class="text-muted"> <?php echo $credential['created_at'] !== null ? htmlspecialchars((new DateTime($credential['created_at']))->format('d.m.Y - H:i:s')) : 'N/A'; ?> </span>
</small>
</li>
</ul>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<nav class="d-flex justify-content-end">
<ul class="pagination">
<?php if ($page > 1): ?>
<li class="page-item">
<a class="page-link" href="dashboard.php?page=<?php echo $page - 1; ?>&search=<?php echo htmlspecialchars($search); ?>">
« Previous
</a>
</li>
<?php endif; ?>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
<a class="page-link" href="dashboard.php?page=<?php echo $i; ?>&search=<?php echo htmlspecialchars($search); ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor; ?>
<?php if ($page < $totalPages): ?>
<li class="page-item">
<a class="page-link" href="dashboard.php?page=<?php echo $page + 1; ?>&search=<?php echo htmlspecialchars($search); ?>">
Next »
</a>
</li>
<?php endif; ?>
</ul>
</nav>
</div>
</div>
<?php include_once ".footer.php"; ?>
<?php include_once "modal_add_key.php"; include_once "modal_delete_key.php"; include_once "modal_edit_key.php"; ?>
</body>
</html>