This commit is contained in:
Christopher Cookman 2025-09-01 02:28:20 -06:00
parent cd2a0b4b17
commit c6b5c66546

View file

@ -4,139 +4,136 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add ACL Entry</title> <title>Event Log Viewer</title>
<style> <style>
form#acl-edit-form { body {
max-width: 500px; font-family: Arial, sans-serif;
margin: 2em auto; background: #f7f7f7;
padding: 2em; margin: 0;
border: 1px solid #ccc; padding: 0;
}
.container {
/* max-width: 900px; */
margin: 40px auto;
background: #fff;
padding: 32px;
border-radius: 8px; border-radius: 8px;
background: #fafafa; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
} }
form#acl-edit-form div { h1 {
margin-bottom: 1em; text-align: center;
margin-bottom: 32px;
color: #333;
} }
form#acl-edit-form label { table {
display: block;
font-weight: 500;
margin-bottom: 0.3em;
}
form#acl-edit-form input[type="text"],
form#acl-edit-form input[type="date"] {
width: 100%; width: 100%;
padding: 0.5em; border-collapse: collapse;
border: 1px solid #bbb; margin-bottom: 16px;
border-radius: 4px;
box-sizing: border-box;
} }
form#acl-edit-form fieldset { th,
border: 1px solid #ddd; td {
border-radius: 4px; padding: 12px 8px;
padding: 1em; border-bottom: 1px solid #e0e0e0;
margin-bottom: 1em; text-align: left;
background: #f5f5f5;
} }
form#acl-edit-form legend { th {
font-weight: 600; background: #f0f0f0;
color: #444;
} }
form#acl-edit-form button[type="submit"] { tr:hover {
background: #1976d2; background: #f9f9f9;
color: #fff;
border: none;
padding: 0.7em 1.5em;
border-radius: 4px;
font-size: 1em;
cursor: pointer;
transition: background 0.2s;
}
form#acl-edit-form button[type="submit"]:hover {
background: #1565c0;
}
form#acl-edit-form input[type="checkbox"] {
margin-right: 0.5em;
} }
</style> </style>
<script>
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${location.host}${location.pathname}`;
const ws = new WebSocket(wsUrl);
ws.onmessage = function (event) {
// Handle incoming event log messages
// Example: append to a table or display in the UI
console.log('Event received:', event.data);
const tbody = document.querySelector('tbody');
const log = JSON.parse(event.data);
if (!log || log.EventType != 2 || log.Granted != 0) return; // Only allow denied swipes
const tr = document.createElement('tr');
tr.innerHTML = `
<td><input type="checkbox" /></td>
<td>${log.CardNumber}</td>
<td>${log.Controller}</td>
<td>${log.Door}</td>
<td>${new Date(log.Timestamp).toLocaleString()}</td>
<td>${log.Name || ''}</td>
<td><input type="date" value="${new Date().toISOString().slice(0, 10)}" /></td>
<td><input type="date" value="${new Date(Date.now() + 99 * 365.25 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)}" /></td>
<td>
<% for (const doorName of Object.keys(doorList)) { %>
<label>
<input type="checkbox" name="<%= doorName %>" checked />
<%= doorName %>
</label>
<% } %>
</td>
`;
tbody.insertBefore(tr, tbody.firstChild);
tr.style.background = 'orange';
setTimeout(() => {
let opacity = 1;
const fade = setInterval(() => {
opacity -= 0.05;
tr.style.background = `rgba(255,165,0,${opacity})`;
if (opacity <= 0.1) {
tr.style.background = '';
clearInterval(fade);
}
}, 40);
}, 0);
};
ws.onopen = function () {
console.log('WebSocket connection established');
};
ws.onclose = function () {
console.log('WebSocket connection closed');
};
ws.onerror = function (error) {
console.error('WebSocket error:', error);
};
</script>
</head> </head>
<body> <body>
<form id="acl-edit-form" method="patch" action="/acl"> <div class="container">
<div> <h1>Bulk Credential Adder</h1>
<label for="Name">Name:</label> <a href="/dashboard">Dashboard</a>
<input type="text" id="Name" name="Name" value="" required> <form action="/acl/bulk-add" method="post">
</div> <table>
<div> <thead>
<label for="CardNumber">Card Number:</label> <tr>
<input type="number" id="CardNumber" name="CardNumber" value="" required> <th>Select</th>
</div> <th>Credential</th>
<div> <th>Controller</th>
<label for="PIN">PIN:</label> <th>Door</th>
<input type="text" id="PIN" name="PIN" value=""> <th>Data</th>
</div> <th>Name</th>
<div> <th>Start Date</th>
<label for="StartDate">Start Date:</label> <th>End Date</th>
<input type="date" id="StartDate" name="StartDate" <th>Allowed Doors</th>
value="<%= new Date().toISOString().slice(0,10) %>" required> </tr>
</div> </thead>
<div> <tbody></tbody>
<label for="EndDate">End Date:</label> </table>
<input type="date" id="EndDate" name="EndDate" <button type="submit">Add Selected</button>
value="<%= new Date(Date.now() + 99*365.25*24*60*60*1000).toISOString().slice(0,10) %>" required>
</div>
<fieldset>
<legend>Doors</legend>
<% Object.keys(doorList).forEach(function(door) { %>
<div>
<label>
<input type="checkbox" name="doors[<%= door %>]" value="1" <% if (doorList[door] &&
doorList[door]==1) { %> checked <% } %> >
<%= door %>
<% doorList[door] %>
</label>
</div>
<% }) %>
</fieldset>
<button type="submit">Save</button>
</form> </form>
</div>
<script>
document.getElementById('acl-edit-form').addEventListener('submit', function (e) {
e.preventDefault();
const form = e.target;
const formData = new FormData(form);
const data = {
Name: formData.get('Name'),
CardNumber: formData.get('CardNumber'),
PIN: formData.get('PIN'),
StartDate: formData.get('StartDate'),
EndDate: formData.get('EndDate'),
doors: {}
};
<% Object.keys(doorList).forEach(function (door) { %>
data.doors['<%= door %>'] = formData.get('doors[<%= door %>]') ? 1 : 0;
<% }) %>
fetch(form.action, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(res => {
if (res.ok) window.location.href = '/acl';
else alert('Failed to update ACL entry');
}).catch(err => {
alert('Error: ' + err.message);
});
});
</script>
</body> </body>
</html> </html>