diff --git a/public/assets/js/flags.js b/public/assets/js/flags.js index f6eca07..19fefcc 100644 --- a/public/assets/js/flags.js +++ b/public/assets/js/flags.js @@ -1,3 +1,10 @@ +fetch('/api/v1/info') + .then(response => response.json()) + .then(data => { + window.flags = data.reasonFlags; + }) + .catch(error => console.error('Error fetching flags:', error)); + /** * Adds a flag to the current flags. * @param {number} flags - The current set of flags. @@ -80,4 +87,4 @@ function getSetFlags(flags, flagDefinitions) { return Object.keys(flagDefinitions).filter(flagName => (flags & flagDefinitions[flagName]) !== 0 ); -} +} \ No newline at end of file diff --git a/public/lookup/index.html b/public/lookup/index.html new file mode 100644 index 0000000..ee549cc --- /dev/null +++ b/public/lookup/index.html @@ -0,0 +1,60 @@ + + + + + + + UBS Ban Lookup + + +
+
+
+
+
+

Ban Lookup

+ +
+
+ + +
+
+ + +
+ +
+
+
+
+

Results

+ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/lookup/lookup.js b/public/lookup/lookup.js new file mode 100644 index 0000000..c9ea8fa --- /dev/null +++ b/public/lookup/lookup.js @@ -0,0 +1,53 @@ +document.getElementById('lookupForm').addEventListener('submit', async function (event) { + event.preventDefault(); + + const lookupType = document.getElementById('lookupType').value; + const lookupId = document.getElementById('lookupId').value; + const messageElement = document.getElementById('message'); + const resultsTable = document.getElementById('resultsTable'); + const resultsTableBody = resultsTable.querySelector('tbody'); + resultsTableBody.innerHTML = ''; // Clear previous results + + try { + const response = await fetch(`/api/v1/ban/${lookupType}/${lookupId}`); + const data = await response.json(); + + if (response.ok) { + messageElement.style.display = 'block'; + messageElement.className = 'alert alert-success'; + messageElement.textContent = "Success!"; + resultsTable.style.display = 'table'; + data.forEach(result => { + const row = document.createElement('tr'); + const banTimestamp = new Date(result.banTimestamp).toLocaleString(); + const expiresTimestamp = result.expiresTimestamp ? new Date(result.expiresTimestamp).toLocaleString() : 'Never'; + const reasonsFlagNames = getSetFlags(result.reasonsFlag, window.flags).join(', '); + row.innerHTML = ` + ${result.id} + ${result.robloxId || 'N/A'} + ${result.discordId || 'N/A'} + ${result.robloxUsername || 'N/A'} + ${result.discordUsername || 'N/A'} + ${result.reasonShort || 'N/A'} + ${result.reasonLong || 'N/A'} + ${reasonsFlagNames} + ${result.moderator || 'N/A'} + ${banTimestamp} + + ${expiresTimestamp} + + `; + resultsTableBody.appendChild(row); + }); + } else { + messageElement.style.display = 'block'; + messageElement.className = 'alert alert-danger'; + messageElement.textContent = data.error || 'An error occurred'; + } + } catch (error) { + messageElement.style.display = 'block'; + messageElement.className = 'alert alert-danger'; + messageElement.textContent = 'An error occurred while fetching the data'; + console.error(error) + } +}); \ No newline at end of file diff --git a/routes/api.js b/routes/api.js index cab2541..26f0eea 100644 --- a/routes/api.js +++ b/routes/api.js @@ -120,6 +120,36 @@ router.get("/v1/ban/discord/:uid", async (req, res) => { } }) +router.get("/v1/ban/id/:id", async (req, res) => { + if (!req.params.id) return res.status(400).json({error: "Specify ban ID!"}); + try { + // Get a connection from the pool + const connection = await pool.getConnection(); + + try { + // Execute the query to fetch all rows from the `bans` table + const rows = await connection.query('SELECT * FROM bans WHERE id = ?', [req.params.id]); + // Convert all timestamps into epoch + rows.forEach(row => { + row.expiresTimestamp = row.expiresTimestamp ? new Date(`${row.expiresTimestamp}Z`).getTime() : null + row.banTimestamp = row.banTimestamp ? new Date(`${row.banTimestamp}`).getTime() : null + row.valid = row.expiresTimestamp ? new Date(row.expiresTimestamp) > new Date() : true + }); + + // Send the results as a JSON response + res.json(rows); + } finally { + // Release the connection back to the pool + connection.release(); + } + } catch (err) { + console.error('Error fetching bans:', err); + + // Respond with a 500 Internal Server Error status if something goes wrong + res.status(500).json({ error: 'An error occurred while fetching the bans.' }); + } +}); + router.get("/v1/info", (req,res) => { res.json({ commit_hash: execSync('git rev-parse HEAD').toString().trim(),