-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (70 loc) · 2 KB
/
index.js
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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
const bans = [];
const validPins = ["0725", "1926"];
// Serve PIN entry page
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/pin.html');
});
// Validate PIN
app.post('/validate-pin', (req, res) => {
const { pin } = req.body;
if (validPins.includes(pin)) {
res.sendFile(__dirname + '/public/index.html');
} else {
res.send('Invalid PIN. Please go back and try again.');
}
});
// Handle ban request
app.post('/ban', (req, res) => {
const { username, banType, reason, customReason } = req.body;
const finalReason = reason === 'Custom' ? customReason : reason;
if (username && banType && finalReason) {
bans.push({ username, banType, reason: finalReason, date: new Date() });
res.send(`
<html>
<body>
<h1>User ${username} has been ${banType === 'temporary' ? 'temporarily' : 'permanently'} banned for: ${finalReason}.</h1>
<h2>✅ Ban Successful</h2>
<a href="/">Go back</a>
</body>
</html>
`);
} else {
res.send('All fields are required.');
}
});
// Handle unban request
app.post('/unban', (req, res) => {
const { username } = req.body;
if (username) {
const index = bans.findIndex(ban => ban.username === username);
if (index !== -1) {
bans.splice(index, 1);
res.send(`
<html>
<body>
<h1>User ${username} has been unbanned.</h1>
<h2>✅ Unban Successful</h2>
<a href="/unban.html">Go back</a>
</body>
</html>
`);
} else {
res.send('User not found in ban list.');
}
} else {
res.send('Username is required.');
}
});
// Endpoint to retrieve list of bans (optional)
app.get('/bans', (req, res) => {
res.json(bans);
});
// Start the server
app.listen(3000, () => {
console.log('Server is running on port 3000');
});