jerkjs 2.5.6 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +167 -79
  2. package/README.md +134 -146
  3. package/RESULTADOS_WAF.md +63 -0
  4. package/doc-2.5/ADMIN_EXTENSION_COMMANDS_MANUAL.md +261 -0
  5. package/doc-2.5/ADMIN_EXTENSION_HOOK_EXAMPLE.md +28 -0
  6. package/doc-2.5/ADMIN_EXTENSION_INTEGRATION_MANUAL.md +232 -0
  7. package/doc-2.5/CACHE_SYSTEM_MAP.md +206 -0
  8. package/doc-2.5/MANUAL_MODULOS_ADMIN.md +287 -0
  9. package/doc-2.5/QUEUE_CLI_MODULE_MANUAL.md +289 -0
  10. package/doc-2.5/QUEUE_SYSTEM_MANUAL.md +320 -0
  11. package/doc-2.5/ROUTE_CACHE_MODULE_MANUAL.md +205 -0
  12. package/doc-2.5/WAF_MODULE_MANUAL.md +229 -0
  13. package/index.js +19 -4
  14. package/jerk-admin-client/README.md +69 -0
  15. package/jerk-admin-client/package.json +23 -0
  16. package/jerk-admin-client.js +257 -0
  17. package/lib/admin/AdminExtension.js +491 -0
  18. package/lib/admin/ModuleLoader.js +77 -0
  19. package/lib/admin/config.js +21 -0
  20. package/lib/admin/modules/CacheModule.js +145 -0
  21. package/lib/admin/modules/ControllerGeneratorModule.js +414 -0
  22. package/lib/admin/modules/QueueManagementModule.js +265 -0
  23. package/lib/admin/modules/RouteCacheModule.js +227 -0
  24. package/lib/admin/modules/RouteManagerModule.js +468 -0
  25. package/lib/admin/modules/STATS_MODULE_README.md +113 -0
  26. package/lib/admin/modules/StatsModule.js +140 -0
  27. package/lib/admin/modules/SystemModule.js +140 -0
  28. package/lib/admin/modules/TimeModule.js +95 -0
  29. package/lib/admin/modules/ViewCacheStatsModule.js +92 -0
  30. package/lib/admin/modules/WAFModule.js +737 -0
  31. package/lib/cache/CacheHooks.js +141 -0
  32. package/lib/core/server.js +223 -77
  33. package/lib/middleware/firewall.js +112 -17
  34. package/lib/mvc/viewEngine.js +89 -5
  35. package/lib/queue/GlobalQueueStorage.js +38 -0
  36. package/lib/queue/QueueSystem.js +451 -0
  37. package/lib/queue/admin_example.js +114 -0
  38. package/lib/queue/example.js +268 -0
  39. package/lib/queue/integration.js +109 -0
  40. package/lib/router/RouteMatcher.js +242 -54
  41. package/lib/utils/globalStats.js +16 -0
  42. package/lib/utils/globalViewCacheInfo.js +16 -0
  43. package/lib/utils/globalWAFStats.js +54 -0
  44. package/package.json +2 -2
  45. package/test-colors.js +46 -0
  46. package/test-help-alias.js +31 -0
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Cliente CLI para interactuar con el servidor de administración de JERK Framework
5
+ * Permite reutilizar comandos y tiene autocompletado
6
+ */
7
+
8
+ const net = require('net');
9
+ const readline = require('readline');
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ // Configuración por defecto
14
+ const DEFAULT_HOST = 'localhost';
15
+ const DEFAULT_PORT = 9999;
16
+
17
+ // Historial de comandos
18
+ let commandHistory = [];
19
+ const HISTORY_FILE = path.join(require('os').homedir(), '.jerk_admin_history');
20
+
21
+ // Cargar historial de comandos si existe
22
+ if (fs.existsSync(HISTORY_FILE)) {
23
+ try {
24
+ const historyData = fs.readFileSync(HISTORY_FILE, 'utf8');
25
+ commandHistory = JSON.parse(historyData);
26
+ } catch (error) {
27
+ console.error('Error al cargar el historial:', error.message);
28
+ }
29
+ }
30
+
31
+ // Comandos conocidos para autocompletado
32
+ const knownCommands = [
33
+ 'help',
34
+ 'stats',
35
+ 'statistics',
36
+ 'requests',
37
+ 'endpoints',
38
+ 'routes',
39
+ 'active',
40
+ 'version',
41
+ 'status',
42
+ 'cache',
43
+ 'cache-stats',
44
+ 'cache-clear',
45
+ 'cache-info',
46
+ 'sysinfo',
47
+ 'system',
48
+ 'resources',
49
+ 'time',
50
+ 'date',
51
+ 'quit',
52
+ 'exit'
53
+ ];
54
+
55
+ // Función para guardar el historial
56
+ function saveHistory() {
57
+ try {
58
+ fs.writeFileSync(HISTORY_FILE, JSON.stringify(commandHistory, null, 2));
59
+ } catch (error) {
60
+ console.error('Error al guardar el historial:', error.message);
61
+ }
62
+ }
63
+
64
+ // Función para autocompletar comandos
65
+ function completer(line) {
66
+ const hits = knownCommands.filter(cmd => cmd.startsWith(line));
67
+ return [hits.length ? hits : knownCommands, line];
68
+ }
69
+
70
+ // Función para crear el cliente
71
+ function createClient(host = DEFAULT_HOST, port = DEFAULT_PORT) {
72
+ const client = new net.Socket();
73
+
74
+ // Conectar al servidor de administración
75
+ client.connect(port, host, () => {
76
+ console.log(`Conectado al servidor de administración en ${host}:${port}`);
77
+ console.log('Escribe "help" para ver los comandos disponibles o "quit" para salir\n');
78
+
79
+ // Configurar readline con autocompletado
80
+ const rl = readline.createInterface({
81
+ input: process.stdin,
82
+ output: process.stdout,
83
+ completer: completer,
84
+ history: commandHistory
85
+ });
86
+
87
+ // Mostrar historial de comandos recientes
88
+ if (commandHistory.length > 0) {
89
+ console.log(`Comandos recientes: ${commandHistory.slice(-5).join(', ')}\n`);
90
+ }
91
+
92
+ // Función para manejar la entrada del usuario
93
+ function handleInput() {
94
+ rl.question('> ', (input) => {
95
+ const command = input.trim();
96
+
97
+ if (command.toLowerCase() === 'quit' || command.toLowerCase() === 'exit') {
98
+ console.log('Desconectando del servidor...');
99
+ client.end();
100
+ rl.close();
101
+ saveHistory();
102
+ return;
103
+ }
104
+
105
+ if (command.toLowerCase() === 'history') {
106
+ console.log('Historial de comandos:');
107
+ commandHistory.forEach((cmd, index) => {
108
+ console.log(`${index + 1}. ${cmd}`);
109
+ });
110
+ handleInput();
111
+ return;
112
+ }
113
+
114
+ if (command.toLowerCase() === 'clear') {
115
+ console.clear();
116
+ handleInput();
117
+ return;
118
+ }
119
+
120
+ if (command.toLowerCase() === 'help-cli') {
121
+ console.log('\n--- Comandos del Cliente CLI ---');
122
+ console.log('help-cli - Muestra esta ayuda');
123
+ console.log('history - Muestra el historial de comandos');
124
+ console.log('clear - Limpia la pantalla');
125
+ console.log('re <número> - Reutiliza el comando número n del historial');
126
+ console.log('re <texto> - Reutiliza el último comando que contiene el texto');
127
+ console.log('-----------------------------\n');
128
+ handleInput();
129
+ return;
130
+ }
131
+
132
+ // Comando para reutilizar comandos del historial
133
+ if (command.toLowerCase().startsWith('re ')) {
134
+ const arg = command.substring(3).trim();
135
+
136
+ if (/^\d+$/.test(arg)) {
137
+ // Reutilizar por número
138
+ const index = parseInt(arg) - 1;
139
+ if (index >= 0 && index < commandHistory.length) {
140
+ const reusedCmd = commandHistory[index];
141
+ console.log(`Reutilizando comando: ${reusedCmd}`);
142
+ client.write(reusedCmd + '\n');
143
+ if (!commandHistory.includes(reusedCmd)) {
144
+ commandHistory.push(reusedCmd);
145
+ }
146
+ } else {
147
+ console.log(`Número de comando inválido: ${arg}`);
148
+ handleInput();
149
+ }
150
+ } else {
151
+ // Reutilizar por texto
152
+ const matchingCmd = commandHistory.reverse().find(cmd => cmd.includes(arg));
153
+ commandHistory.reverse(); // Restaurar orden original
154
+
155
+ if (matchingCmd) {
156
+ console.log(`Reutilizando comando: ${matchingCmd}`);
157
+ client.write(matchingCmd + '\n');
158
+ } else {
159
+ console.log(`No se encontró comando que contenga: ${arg}`);
160
+ handleInput();
161
+ }
162
+ }
163
+ } else if (command) {
164
+ // Enviar comando al servidor
165
+ client.write(command + '\n');
166
+
167
+ // Agregar al historial si no está repetido
168
+ if (!commandHistory.includes(command)) {
169
+ commandHistory.push(command);
170
+ // Mantener solo los últimos 100 comandos
171
+ if (commandHistory.length > 100) {
172
+ commandHistory = commandHistory.slice(-100);
173
+ }
174
+ }
175
+ }
176
+
177
+ handleInput();
178
+ });
179
+ }
180
+
181
+ // Iniciar la interacción
182
+ handleInput();
183
+ });
184
+
185
+ // Manejar datos recibidos del servidor
186
+ client.on('data', (data) => {
187
+ const output = data.toString();
188
+ process.stdout.write(output);
189
+
190
+ // Si la salida termina con el prompt, significa que el comando terminó
191
+ if (output.endsWith('> ')) {
192
+ // No hacer nada, dejar que readline continúe
193
+ }
194
+ });
195
+
196
+ // Manejar errores
197
+ client.on('error', (error) => {
198
+ console.error(`Error de conexión: ${error.message}`);
199
+ process.exit(1);
200
+ });
201
+
202
+ // Manejar cierre de conexión
203
+ client.on('close', () => {
204
+ console.log('\nConexión cerrada');
205
+ process.exit(0);
206
+ });
207
+ }
208
+
209
+ // Mostrar ayuda
210
+ function showHelp() {
211
+ console.log(`
212
+ Cliente CLI para JERK Framework Administration Server
213
+
214
+ Uso: node jerk-admin-client.js [opciones]
215
+
216
+ Opciones:
217
+ -h, --host HOST Host del servidor (por defecto: ${DEFAULT_HOST})
218
+ -p, --port PORT Puerto del servidor (por defecto: ${DEFAULT_PORT})
219
+ --help Mostrar esta ayuda
220
+
221
+ Comandos especiales del cliente:
222
+ history Mostrar historial de comandos
223
+ clear Limpiar la pantalla
224
+ re <número> Reutilizar comando por número
225
+ re <texto> Reutilizar último comando que contiene texto
226
+ help-cli Mostrar ayuda del cliente
227
+
228
+ Ejemplos:
229
+ node jerk-admin-client.js
230
+ node jerk-admin-client.js --host 127.0.0.1 --port 9999
231
+ `);
232
+ }
233
+
234
+ // Parsear argumentos
235
+ const args = process.argv.slice(2);
236
+ let host = DEFAULT_HOST;
237
+ let port = DEFAULT_PORT;
238
+
239
+ for (let i = 0; i < args.length; i++) {
240
+ if (args[i] === '--help' || args[i] === '-h') {
241
+ showHelp();
242
+ process.exit(0);
243
+ } else if (args[i] === '--host' || args[i] === '-h') {
244
+ host = args[++i];
245
+ } else if (args[i] === '--port' || args[i] === '-p') {
246
+ port = parseInt(args[++i]);
247
+ }
248
+ }
249
+
250
+ // Validar puerto
251
+ if (isNaN(port) || port <= 0 || port > 65535) {
252
+ console.error(`Puerto inválido: ${port}`);
253
+ process.exit(1);
254
+ }
255
+
256
+ // Iniciar el cliente
257
+ createClient(host, port);