chore(core): Added bare TCP access
All checks were successful
Docker Build and Push for Main Branch / docker (push) Successful in 11m31s
All checks were successful
Docker Build and Push for Main Branch / docker (push) Successful in 11m31s
This commit is contained in:
68
commands.js
Normal file
68
commands.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const services = [
|
||||
{ name: 'Dev Workspaces', url: 'https://coder.phorge.fr' },
|
||||
{ name: 'Monitoring', url: 'https://monitoring.phorge.fr' },
|
||||
{ name: 'Status page', url: 'https://status.phorge.fr/status' },
|
||||
{ name: 'Git', url: 'https://git.phorge.fr' },
|
||||
{ name: 'IaaS', url: 'https://iaas.phorge.fr' },
|
||||
];
|
||||
|
||||
const commands = [
|
||||
{
|
||||
names: ['/services'],
|
||||
description: 'Displays available services',
|
||||
execute: (socket) => {
|
||||
socket.write('Available services:\r\n');
|
||||
for (const service of services) {
|
||||
socket.write(`- ${service.name}: ${service.url}\r\n`);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
names: ['/help', 'help'],
|
||||
description: 'Displays command help',
|
||||
execute: (socket) => {
|
||||
socket.write('Available commands:\r\n');
|
||||
for (const command of commands) {
|
||||
socket.write(`- ${command.names[0]}: ${command.description}\r\n`);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
names: ['/exit', 'quit'],
|
||||
description: 'Exits the terminal session',
|
||||
execute: (socket) => {
|
||||
socket.write('Goodbye.\r\n');
|
||||
socket.end();
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const resolveCommand = (input) => {
|
||||
const normalized = input.trim().toLowerCase();
|
||||
return commands.find((command) => command.names.includes(normalized));
|
||||
};
|
||||
|
||||
const handleCommand = (socket, input) => {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) {
|
||||
socket.write('phorge> ');
|
||||
return;
|
||||
}
|
||||
|
||||
const command = resolveCommand(trimmed);
|
||||
if (command) {
|
||||
command.execute(socket);
|
||||
if (command.names.includes('/exit') || command.names.includes('quit')) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
socket.write(`Unknown command : ${trimmed}\r\n`);
|
||||
socket.write('Type /help for assistance.\r\n');
|
||||
}
|
||||
|
||||
socket.write('phorge> ');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
handleCommand,
|
||||
};
|
||||
Reference in New Issue
Block a user