Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomCZ committed Sep 24, 2023
1 parent f7fb493 commit 977838b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ function customLog(message) {

// Send formatted message to client
if (cleanMessage.includes('WARN')) {
io.emit('consoleLog', `<p class="text-amber-500 font-bold">⚠️ ` + cleanMessage + `</p>`);
io.emit('consoleLog', `<p class="text-amber-500 bg-amber-500/20 hover:bg-amber-500/30 font-bold">⚠️ ` + cleanMessage + `</p>`);
return
} else if (cleanMessage.includes('ERROR')) {
io.emit('consoleLog', `<p class="text-red-500 bg-red-500/20 hover:bg-red-500/30 font-bold">❌ ` + cleanMessage + `</p>`);
return
} else if (cleanMessage.includes('container@pterodactyl~')) {
io.emit('consoleLog', `<span>` + cleanMessage.replace('container@pterodactyl~', "<span class='text-sky-400 font-bold'>container@pterodactyl ~ </span>") + `</span>`);
Expand All @@ -28,21 +31,30 @@ function customLog(message) {
io.emit('consoleLog', `<p class="text-amber-500 font-bold">` + cleanMessage + `</p>`)
} else {
// Send message without special formatting
io.emit('consoleLog', `<p>` + cleanMessage + `</p>`);
io.emit('consoleLog', `<p class="hover:bg-slate-700">` + cleanMessage + `</p>`);
return
}
}

function escapeHtml(unsafe) {
return String(unsafe).replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}

app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.sendFile(__dirname + '/index.html');
});

// Pterodactyl config
// Config
const config = {
"panelUrl": "https://***",
"pterodactylUserApiKey": "***",
"serverUUID": "***"
"serverUUID": "***",
"port": "3000"
};

// ReadLine for the commands
Expand All @@ -61,8 +73,8 @@ io.on('connection', (socket) => {
});
});

http.listen(3000, () => {
console.log('Express is running on http://localhost:3000');
http.listen(config.port, () => {
console.log(`Express is running on http://localhost:` + config.port);
});

// Init
Expand Down Expand Up @@ -138,7 +150,8 @@ const prod = () => {

io.on('connection', (socket) => {
socket.on('command', (command) => {
recieveCommand = command.trim();
const escapedCommand = escapeHtml(command.trim())
recieveCommand = escapedCommand
customLog('<span class="text-sky-400 font-bold"">~ </span>' + recieveCommand);

connection.sendUTF(`{"event":"send command","args":["${recieveCommand}"]}`)
Expand Down

0 comments on commit 977838b

Please sign in to comment.