1 | // ******************************************************************************************************** |
---|
2 | // Cliernte: ogAdmClient |
---|
3 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
---|
4 | // Fecha Creación: Marzo-2010 |
---|
5 | // Fecha Última modificación: Abril-2010 |
---|
6 | // Nombre del fichero: ogAdmClient.c |
---|
7 | // Descripción :Este fichero implementa el cliente general del sistema |
---|
8 | // ******************************************************************************************************** |
---|
9 | #include "ogAdmClient.h" |
---|
10 | #include "ogAdmLib.c" |
---|
11 | //________________________________________________________________________________________________________ |
---|
12 | // Función: tomaConfiguracion |
---|
13 | // |
---|
14 | // Descripción: |
---|
15 | // Lee el fichero de configuración del servicio |
---|
16 | // Parámetros: |
---|
17 | // filecfg : Ruta completa al fichero de configuración |
---|
18 | // Devuelve: |
---|
19 | // TRUE: Si el proceso es correcto |
---|
20 | // FALSE: En caso de ocurrir algún error |
---|
21 | //________________________________________________________________________________________________________ |
---|
22 | BOOLEAN tomaConfiguracion(char* filecfg) |
---|
23 | { |
---|
24 | char modulo[] = "tomaConfiguracion()"; |
---|
25 | |
---|
26 | if (filecfg == NULL || strlen(filecfg) == 0) { |
---|
27 | errorLog(modulo, 1, FALSE); // Fichero de configuración del cliente vacío |
---|
28 | return (FALSE); |
---|
29 | } |
---|
30 | FILE *fcfg; |
---|
31 | int lSize; |
---|
32 | char * buffer, *lineas[MAXPRM], *dualparametro[2]; |
---|
33 | int i, numlin, resul; |
---|
34 | |
---|
35 | fcfg = fopen(filecfg, "rt"); |
---|
36 | if (fcfg == NULL) { |
---|
37 | errorLog(modulo, 2, FALSE); // No existe fichero de configuración del cliente |
---|
38 | return (FALSE); |
---|
39 | } |
---|
40 | |
---|
41 | fseek(fcfg, 0, SEEK_END); |
---|
42 | lSize = ftell(fcfg); // Obtiene tamaño del fichero. |
---|
43 | rewind(fcfg); |
---|
44 | buffer = (char*) reservaMemoria(lSize+1); // Toma memoria para el buffer de lectura. |
---|
45 | if (buffer == NULL) { // No hay memoria suficiente para el buffer |
---|
46 | errorLog(modulo, 3, FALSE); |
---|
47 | return (FALSE); |
---|
48 | } |
---|
49 | lSize=fread(buffer, 1, lSize, fcfg); // Lee contenido del fichero |
---|
50 | buffer[lSize]=CHARNULL; |
---|
51 | fclose(fcfg); |
---|
52 | |
---|
53 | /* Inicializar variables globales */ |
---|
54 | servidoradm[0]=CHARNULL; |
---|
55 | puerto[0] = CHARNULL; |
---|
56 | pathinterface[0]=CHARNULL; |
---|
57 | urlmenu[0]=CHARNULL; |
---|
58 | urlmsg[0]=CHARNULL; |
---|
59 | |
---|
60 | numlin = splitCadena(lineas, buffer, '\n'); |
---|
61 | for (i = 0; i < numlin; i++) { |
---|
62 | splitCadena(dualparametro, lineas[i], '='); |
---|
63 | |
---|
64 | resul = strcmp(StrToUpper(dualparametro[0]), "SERVIDORADM"); |
---|
65 | if (resul == 0) |
---|
66 | strcpy(servidoradm, dualparametro[1]); |
---|
67 | |
---|
68 | resul = strcmp(StrToUpper(dualparametro[0]), "PUERTO"); |
---|
69 | if (resul == 0) |
---|
70 | strcpy(puerto, dualparametro[1]); |
---|
71 | |
---|
72 | resul = strcmp(StrToUpper(dualparametro[0]), "PATHINTERFACE"); |
---|
73 | if (resul == 0) |
---|
74 | strcpy(pathinterface, dualparametro[1]); |
---|
75 | |
---|
76 | resul = strcmp(StrToUpper(dualparametro[0]), "URLMENU"); |
---|
77 | if (resul == 0) |
---|
78 | strcpy(urlmenu, dualparametro[1]); |
---|
79 | |
---|
80 | resul = strcmp(StrToUpper(dualparametro[0]), "URLMSG"); |
---|
81 | if (resul == 0) |
---|
82 | strcpy(urlmsg, dualparametro[1]); |
---|
83 | } |
---|
84 | |
---|
85 | if (servidoradm[0] == CHARNULL) { |
---|
86 | liberaMemoria(buffer); |
---|
87 | errorLog(modulo,4, FALSE); // Falta parámetro SERVIDORADM |
---|
88 | return (FALSE); |
---|
89 | } |
---|
90 | |
---|
91 | if (puerto[0] == CHARNULL) { |
---|
92 | liberaMemoria(buffer); |
---|
93 | errorLog(modulo,5, FALSE); // Falta parámetro PUERTO |
---|
94 | return (FALSE); |
---|
95 | } |
---|
96 | if (pathinterface[0] == CHARNULL) { |
---|
97 | liberaMemoria(buffer); |
---|
98 | errorLog(modulo,56, FALSE); // Falta parámetro PATHINTERFACE |
---|
99 | return (FALSE); |
---|
100 | } |
---|
101 | |
---|
102 | if (urlmenu[0] == CHARNULL) { |
---|
103 | liberaMemoria(buffer); |
---|
104 | errorLog(modulo,89, FALSE); // Falta parámetro URLMENU |
---|
105 | return (FALSE); |
---|
106 | } |
---|
107 | if (urlmsg[0] == CHARNULL) { |
---|
108 | liberaMemoria(buffer); |
---|
109 | errorLog(modulo,90, FALSE); // Falta parámetro URLMSG |
---|
110 | return (FALSE); |
---|
111 | } |
---|
112 | liberaMemoria(buffer); |
---|
113 | return (TRUE); |
---|
114 | } |
---|
115 | //______________________________________________________________________________________________________ |
---|
116 | // Función: FinterfaceAdmin |
---|
117 | // |
---|
118 | // Descripción: |
---|
119 | // Esta función es la puerta de comunicación entre el módulo de administración y el motor de clonación. |
---|
120 | // La Aplicación de administración utiliza una interface para ejecutar funciones del motor de clonación; |
---|
121 | // esta interface llamará a la API del motor con lo que cambiando el comportamiento de esta interface |
---|
122 | // podremos hacer llamadas a otras API de clonación y de esta manera probar distintos motores. |
---|
123 | // |
---|
124 | // Parámetros: |
---|
125 | // - script: Nombre del módulo,función o script de la interface |
---|
126 | // - parametros: Parámetros que se le pasarán a la interface |
---|
127 | // - salida: Recoge la salida que genera la llamada a la interface |
---|
128 | |
---|
129 | // Devuelve: |
---|
130 | // Código de error de la ejecución al módulo , función o script de la interface |
---|
131 | // |
---|
132 | // Especificaciones: |
---|
133 | // El parámetro salida recoge la salida desde un fichero que se genera en la ejecución del script siempre que |
---|
134 | // sea distinto de NULL, esto es, si al llamar a la función este parámetro es NULL no se recogerá dicha salida. |
---|
135 | // Este fichero tiene una ubicación fija: /tmp/_retinterface |
---|
136 | //______________________________________________________________________________________________________ |
---|
137 | |
---|
138 | int FinterfaceAdmin( char *script,char* parametros,char* salida) |
---|
139 | { |
---|
140 | FILE *f; |
---|
141 | int lSize,nargs,i,resul; |
---|
142 | char msglog[LONSTD],*argumentos[MAXARGS]; |
---|
143 | char modulo[] = "FinterfaceAdmin()"; |
---|
144 | |
---|
145 | |
---|
146 | if (ndebug>= DEBUG_MEDIO) { |
---|
147 | sprintf(msglog, "%s:%s", tbMensajes[8], script); |
---|
148 | infoDebug(msglog); |
---|
149 | } |
---|
150 | |
---|
151 | /* Crea matriz de los argumentos */ |
---|
152 | nargs=splitCadena(argumentos,parametros,32); |
---|
153 | for(i=nargs;i<MAXARGS;i++){ |
---|
154 | argumentos[i]=NULL; |
---|
155 | } |
---|
156 | |
---|
157 | /* Muestra matriz de los argumentos */ |
---|
158 | for(i=0;i<nargs;i++){ |
---|
159 | if (ndebug>= DEBUG_ALTO) { |
---|
160 | sprintf(msglog, "%s: #%d-%s", tbMensajes[9],i+1,argumentos[i]); |
---|
161 | infoDebug(msglog); |
---|
162 | } |
---|
163 | } |
---|
164 | /* Elimina fichero de retorno */ |
---|
165 | if(salida!=(char*)NULL){ |
---|
166 | f = fopen("/tmp/_retinterface_","w" ); |
---|
167 | if (f==NULL){ // Error de eliminación |
---|
168 | scriptLog(modulo,10); |
---|
169 | resul=8; |
---|
170 | scriptLog(modulo,resul); |
---|
171 | return(resul); |
---|
172 | } |
---|
173 | fclose(f); |
---|
174 | } |
---|
175 | /* Compone linea de comando */ |
---|
176 | if(parametros){ |
---|
177 | strcat(script," "); |
---|
178 | strcat(script,parametros); |
---|
179 | } |
---|
180 | /* LLamada función interface */ |
---|
181 | resul=system(script); |
---|
182 | if(resul){ |
---|
183 | scriptLog(modulo,10); |
---|
184 | scriptLog(modulo,resul); |
---|
185 | return(resul); |
---|
186 | } |
---|
187 | /* Lee fichero de retorno */ |
---|
188 | if(salida!=(char*)NULL){ |
---|
189 | f = fopen("/tmp/_retinterface_","rb" ); |
---|
190 | if (f==NULL){ // Error de apertura |
---|
191 | scriptLog(modulo,10); |
---|
192 | resul=9; |
---|
193 | scriptLog(modulo,resul); |
---|
194 | return(resul); |
---|
195 | } |
---|
196 | else{ |
---|
197 | fseek (f ,0,SEEK_END); // Obtiene tamaño del fichero. |
---|
198 | lSize = ftell (f); |
---|
199 | rewind (f); |
---|
200 | if(lSize>LONGITUD_SCRIPTSALIDA){ |
---|
201 | scriptLog(modulo,10); |
---|
202 | resul=11; |
---|
203 | scriptLog(modulo,resul); |
---|
204 | return(resul); |
---|
205 | } |
---|
206 | fread (salida,1,lSize,f); // Lee contenido del fichero |
---|
207 | rTrim(salida); |
---|
208 | fclose(f); |
---|
209 | } |
---|
210 | } |
---|
211 | /* Muestra información de retorno */ |
---|
212 | if(salida!=(char*)NULL){ |
---|
213 | if(ndebug>2){ |
---|
214 | sprintf(msglog,"Información devuelta %s",salida); |
---|
215 | infoDebug(msglog); |
---|
216 | } |
---|
217 | } |
---|
218 | return(resul); |
---|
219 | } |
---|
220 | //______________________________________________________________________________________________________ |
---|
221 | // Función: interfaceAdmin |
---|
222 | // |
---|
223 | // Descripción: |
---|
224 | // Esta función es la puerta de comunicación entre el módulo de administración y el motor de clonación. |
---|
225 | // La Aplicación de administración utiliza una interface para ejecutar funciones del motor de clonación; |
---|
226 | // esta interface llamará a la API del motor con lo que cambiando el comportamiento de esta interface |
---|
227 | // podremos hacer llamadas a otras API de clonación y de esta manera probar distintos motores. |
---|
228 | // |
---|
229 | // Parámetros: |
---|
230 | // - script: Nombre del módulo,función o script de la interface |
---|
231 | // - parametros: Parámetros que se le pasarán a la interface |
---|
232 | // - salida: Recoge la salida que genera la llamada a la interface |
---|
233 | |
---|
234 | // Devuelve: |
---|
235 | // Código de error de la ejecución al módulo , función o script de la interface |
---|
236 | // |
---|
237 | // Especificaciones: |
---|
238 | // El parámetro salida recoge la salida desde el procedimiento hijo que se genera en la ejecución de éste |
---|
239 | // siempre que sea distinto de NULL, esto es, si al llamar a la función este parámetro es NULL no se |
---|
240 | // recogerá dicha salida. |
---|
241 | //______________________________________________________________________________________________________ |
---|
242 | |
---|
243 | int interfaceAdmin( char *script,char* parametros,char* salida) |
---|
244 | { |
---|
245 | int descr[2]; /* Descriptores de E y S de la turbería */ |
---|
246 | int bytesleidos; /* Bytes leidos en el mensaje */ |
---|
247 | int estado; |
---|
248 | pid_t pid; |
---|
249 | char buffer[LONBLK]; // Buffer de lectura de fichero |
---|
250 | pipe (descr); |
---|
251 | int i,nargs,resul; |
---|
252 | int lon; // Longitud de cadena |
---|
253 | char msglog[LONSUC]; // Mensaje de registro de sucesos |
---|
254 | char *argumentos[MAXARGS]; |
---|
255 | char modulo[] = "interfaceAdmin()"; |
---|
256 | if (ndebug>= DEBUG_MEDIO) { |
---|
257 | sprintf(msglog, "%s:%s", tbMensajes[8], script); |
---|
258 | infoDebug(msglog); |
---|
259 | } |
---|
260 | |
---|
261 | /* Crea matriz de los argumentos */ |
---|
262 | nargs=splitCadena(argumentos,parametros,32); |
---|
263 | for(i=nargs;i<MAXARGS;i++){ |
---|
264 | argumentos[i]=NULL; |
---|
265 | } |
---|
266 | /* Muestra matriz de los argumentos */ |
---|
267 | for(i=1;i<nargs;i++){ |
---|
268 | if (ndebug>= DEBUG_ALTO) { |
---|
269 | // Truncar la cadena si es mayor que el tamaño de la línea de log. |
---|
270 | sprintf(msglog, "%s: #%d-", tbMensajes[9], i+1); |
---|
271 | lon = strlen (msglog); |
---|
272 | if (lon + strlen (argumentos[i]) < LONSUC) { |
---|
273 | strcat (msglog, argumentos[i]); |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | strncat (msglog, argumentos[i], LONSUC - lon - 4); |
---|
278 | strcat (msglog, "..."); |
---|
279 | } |
---|
280 | infoDebug(msglog); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | if((pid=fork())==0) |
---|
285 | { |
---|
286 | //_______________________________________________________________ |
---|
287 | |
---|
288 | /* Proceso hijo que ejecuta la función de interface */ |
---|
289 | |
---|
290 | close (descr[LEER]); |
---|
291 | dup2 (descr[ESCRIBIR], 1); |
---|
292 | close (descr[ESCRIBIR]); |
---|
293 | resul=execv(script,argumentos); |
---|
294 | //resul=execlp (script, script, argumentos[0],argumentos[1],NULL); |
---|
295 | exit(resul); |
---|
296 | |
---|
297 | /* Fin de proceso hijo */ |
---|
298 | //_______________________________________________________________ |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | //_______________________________________________________________ |
---|
303 | |
---|
304 | /* Proceso padre que espera la ejecución del hijo */ |
---|
305 | |
---|
306 | if (pid ==-1){ // Error en la creación del proceso hijo |
---|
307 | scriptLog(modulo,10); |
---|
308 | resul=13; |
---|
309 | scriptLog(modulo,resul); |
---|
310 | return(resul); |
---|
311 | } |
---|
312 | close (descr[ESCRIBIR]); |
---|
313 | bytesleidos = read (descr[LEER], buffer, LONBLK-1); |
---|
314 | while(bytesleidos>0){ |
---|
315 | if(salida!=(char*)NULL){ // Si se solicita retorno de información... |
---|
316 | buffer[bytesleidos]='\0'; |
---|
317 | // Error si se supera el tamaño máximo de cadena de salida. |
---|
318 | if(strlen(buffer)+strlen(salida)>LONGITUD_SCRIPTSALIDA){ |
---|
319 | scriptLog(modulo,10); |
---|
320 | resul=11; |
---|
321 | scriptLog(modulo,resul); |
---|
322 | return(resul); |
---|
323 | } |
---|
324 | rTrim(buffer); |
---|
325 | strcat(salida,buffer); |
---|
326 | } |
---|
327 | bytesleidos = read (descr[LEER], buffer, LONBLK-1); |
---|
328 | } |
---|
329 | close (descr[LEER]); |
---|
330 | //kill(pid,SIGQUIT); |
---|
331 | waitpid(pid,&estado,0); |
---|
332 | resul=WEXITSTATUS(estado); |
---|
333 | if(resul){ |
---|
334 | scriptLog(modulo,10); |
---|
335 | scriptLog(modulo,resul); |
---|
336 | return(resul); |
---|
337 | } |
---|
338 | /* Fin de proceso padre */ |
---|
339 | //_______________________________________________________________ |
---|
340 | } |
---|
341 | |
---|
342 | /* Muestra información de retorno */ |
---|
343 | if(salida!=(char*)NULL){ |
---|
344 | if(ndebug>2){ |
---|
345 | // Truncar la cadena si es mayor que el tamaño de la línea de log. |
---|
346 | strcpy(msglog,"Informacion devuelta "); |
---|
347 | lon = strlen (msglog); |
---|
348 | if (lon + strlen (salida) < LONSUC) { |
---|
349 | strcat (msglog, salida); |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | strncat (msglog, salida, LONSUC-lon-4); |
---|
354 | strcat (msglog, "..."); |
---|
355 | } |
---|
356 | infoDebug(msglog); |
---|
357 | } |
---|
358 | } |
---|
359 | return(resul); |
---|
360 | } |
---|
361 | //______________________________________________________________________________________________________ |
---|
362 | // Función: scriptLog |
---|
363 | // |
---|
364 | // Descripción: |
---|
365 | // Registra los sucesos de errores de scripts en el fichero de log |
---|
366 | // Parametros: |
---|
367 | // - modulo: Módulo donde se produjo el error |
---|
368 | // - coderr : Código del mensaje de error del script |
---|
369 | //______________________________________________________________________________________________________ |
---|
370 | void scriptLog(const char *modulo,int coderr) |
---|
371 | { |
---|
372 | char msglog[LONSUC]; |
---|
373 | |
---|
374 | if(coderr<MAXERRORSCRIPT) |
---|
375 | errorInfo(modulo,tbErroresScripts[coderr]); // Se ha producido algún error registrado |
---|
376 | else{ |
---|
377 | sprintf(msglog,"%s: %d",tbErroresScripts[MAXERRORSCRIPT],coderr); |
---|
378 | errorInfo(modulo,msglog); |
---|
379 | } |
---|
380 | } |
---|
381 | //______________________________________________________________________________________________________ |
---|
382 | // Función: TomaIPlocal |
---|
383 | // |
---|
384 | // Descripción: |
---|
385 | // Recupera la IP local |
---|
386 | // Parámetros: |
---|
387 | // Ninguno |
---|
388 | // Devuelve: |
---|
389 | // TRUE: Si el proceso es correcto |
---|
390 | // FALSE: En caso de ocurrir algún error |
---|
391 | // Especificaciones: |
---|
392 | // En caso de no encontrar la IP o generarse algún error la IP local sería 0.0.0.0 |
---|
393 | //______________________________________________________________________________________________________ |
---|
394 | BOOLEAN tomaIPlocal() |
---|
395 | { |
---|
396 | char modulo[] = "tomaIPlocal()"; |
---|
397 | |
---|
398 | // Para debug |
---|
399 | //strcpy(IPlocal,"10.1.15.203"); |
---|
400 | //return(TRUE); |
---|
401 | |
---|
402 | sprintf(interface,"%s/getIpAddress",pathinterface); |
---|
403 | herror=interfaceAdmin(interface,NULL,IPlocal); |
---|
404 | if(herror){ |
---|
405 | errorLog(modulo,85,FALSE); |
---|
406 | return(FALSE); |
---|
407 | } |
---|
408 | return(TRUE); |
---|
409 | } |
---|
410 | //______________________________________________________________________________________________________ |
---|
411 | // Función: cuestionCache |
---|
412 | // |
---|
413 | // Descripción: |
---|
414 | // Procesa la cache en caso de existir. |
---|
415 | // Parámetros: |
---|
416 | // tam : Tamaño de la cache |
---|
417 | // Devuelve: |
---|
418 | // TRUE: Si el proceso es correcto |
---|
419 | // FALSE: En caso de ocurrir algún error |
---|
420 | //______________________________________________________________________________________________________ |
---|
421 | BOOLEAN cuestionCache(char* tam) |
---|
422 | { |
---|
423 | return(TRUE); |
---|
424 | //>>>>>>>>>>>>>>>>>>>>>>>>>> |
---|
425 | char msglog[LONSTD]; |
---|
426 | char modulo[] = "cuestionCache()"; |
---|
427 | |
---|
428 | sprintf(interface,"%s/%s",pathinterface,"procesaCache"); |
---|
429 | sprintf(parametros,"%s %s","procesaCache",tam); |
---|
430 | |
---|
431 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
432 | if(herror){ |
---|
433 | sprintf(msglog,"%s",tbErrores[88]); |
---|
434 | errorInfo(modulo,msglog); |
---|
435 | return(FALSE); |
---|
436 | } |
---|
437 | |
---|
438 | return(TRUE); |
---|
439 | } |
---|
440 | //______________________________________________________________________________________________________ |
---|
441 | // Función: cargaPaginaWeb |
---|
442 | // |
---|
443 | // Descripción: |
---|
444 | // Muestra una pégina web usando el browser |
---|
445 | // Parámetros: |
---|
446 | // urp: Dirección url de la página |
---|
447 | // Devuelve: |
---|
448 | // TRUE: Si el proceso es correcto |
---|
449 | // FALSE: En caso de ocurrir algún error |
---|
450 | // ________________________________________________________________________________________________________ |
---|
451 | int cargaPaginaWeb(char *url) |
---|
452 | { |
---|
453 | int resul=0; |
---|
454 | char* argumentos[4]; |
---|
455 | char modulo[] = "cargaPaginaWeb()"; |
---|
456 | |
---|
457 | if(pidbash>0) |
---|
458 | kill(pidbash,SIGQUIT); // Destruye el proceso hijo del proceso bash si existiera una conmutación |
---|
459 | |
---|
460 | if(pidbrowser>0) |
---|
461 | kill(pidbrowser,SIGQUIT); // Destruye el proceso hijo anterior y se queda sólo el actual |
---|
462 | |
---|
463 | sprintf(interface,"/opt/opengnsys/bin/browser"); |
---|
464 | sprintf(parametros,"browser -qws %s",url); |
---|
465 | |
---|
466 | splitCadena(argumentos,parametros,' '); // Crea matriz de los argumentos del scripts |
---|
467 | argumentos[3]=NULL; |
---|
468 | if((pidbrowser=fork())==0){ |
---|
469 | /* Proceso hijo que ejecuta el script */ |
---|
470 | resul=execv(interface,argumentos); |
---|
471 | exit(resul); |
---|
472 | } |
---|
473 | else { |
---|
474 | if (pidbrowser ==-1){ |
---|
475 | scriptLog(modulo,10); |
---|
476 | resul=13; |
---|
477 | scriptLog(modulo,resul); |
---|
478 | return(resul); |
---|
479 | } |
---|
480 | } |
---|
481 | return(resul); |
---|
482 | } |
---|
483 | //________________________________________________________________________________________________________ |
---|
484 | // Función: muestraMenu |
---|
485 | // |
---|
486 | // Descripción: |
---|
487 | // Muestra el menu inicial del cliente |
---|
488 | // Parámetros: |
---|
489 | // Ninguno |
---|
490 | // Devuelve: |
---|
491 | // TRUE: Si el proceso es correcto |
---|
492 | // FALSE: En caso de ocurrir algún error |
---|
493 | //________________________________________________________________________________________________________ |
---|
494 | void muestraMenu() |
---|
495 | { |
---|
496 | cargaPaginaWeb(urlmenu); |
---|
497 | } |
---|
498 | //______________________________________________________________________________________________________ |
---|
499 | // Función: muestraMensaje |
---|
500 | // |
---|
501 | // Descripción: |
---|
502 | // Muestra un mensaje en pantalla |
---|
503 | // Parámetros: |
---|
504 | // - idx: Indice del mensaje |
---|
505 | // - msg: Descripción Mensaje |
---|
506 | // ________________________________________________________________________________________________________ |
---|
507 | void muestraMensaje(int idx,char*msg) |
---|
508 | { |
---|
509 | char *msgpan,url[250]; |
---|
510 | |
---|
511 | if(msg){ |
---|
512 | msgpan=URLEncode(msg); |
---|
513 | sprintf(url,"%s?msg=%s",urlmsg,msgpan); // Url de la página de mensajes |
---|
514 | liberaMemoria(msgpan); |
---|
515 | } |
---|
516 | else |
---|
517 | sprintf(url,"%s?idx=%d",urlmsg,idx); // Url de la página de mensajes |
---|
518 | cargaPaginaWeb(url); |
---|
519 | } |
---|
520 | //______________________________________________________________________________________________________ |
---|
521 | // Función: InclusionCliente |
---|
522 | // Descripción: |
---|
523 | // Abre una sesión en el servidor de administración y registra al cliente en el sistema |
---|
524 | // Parámetros: |
---|
525 | // Ninguno |
---|
526 | // Devuelve: |
---|
527 | // TRUE: Si el proceso es correcto |
---|
528 | // FALSE: En caso de ocurrir algún error |
---|
529 | //______________________________________________________________________________________________________ |
---|
530 | BOOLEAN inclusionCliente(TRAMA* ptrTrama) |
---|
531 | { |
---|
532 | int lon; // Longitud de cadena |
---|
533 | char msglog[LONSUC]; // Mensaje de registro de sucesos |
---|
534 | char *cfg; // Datos de configuración |
---|
535 | SOCKET socket_c; |
---|
536 | char modulo[] = "inclusionCliente()"; |
---|
537 | |
---|
538 | cfg=LeeConfiguracion(); |
---|
539 | |
---|
540 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
541 | errorLog(modulo,36,FALSE); |
---|
542 | errorLog(modulo,37,FALSE); |
---|
543 | return(FALSE); |
---|
544 | } |
---|
545 | if (ndebug>= DEBUG_ALTO) { |
---|
546 | // Truncar la cadena si es mayor que el tamaño de la línea de log. |
---|
547 | sprintf(msglog, "%s", tbMensajes[14]); |
---|
548 | lon = strlen (msglog); |
---|
549 | if (lon + strlen (cfg) < LONSUC) { |
---|
550 | strcat (msglog, cfg); |
---|
551 | } |
---|
552 | else |
---|
553 | { |
---|
554 | strncat (msglog, cfg, LONSUC - lon - 4); |
---|
555 | strcat (msglog, "..."); |
---|
556 | } |
---|
557 | infoDebug(msglog); |
---|
558 | } |
---|
559 | initParametros(ptrTrama,0); |
---|
560 | lon=sprintf(ptrTrama->parametros,"nfn=InclusionCliente\r"); // Nombre de la función a ejecutar en el servidor |
---|
561 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
562 | liberaMemoria(cfg); |
---|
563 | |
---|
564 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
565 | errorLog(modulo,37,FALSE); |
---|
566 | return(FALSE); |
---|
567 | } |
---|
568 | ptrTrama=recibeMensaje(&socket_c); |
---|
569 | if(!ptrTrama){ |
---|
570 | errorLog(modulo,45,FALSE); |
---|
571 | return(FALSE); |
---|
572 | } |
---|
573 | |
---|
574 | close(socket_c); |
---|
575 | |
---|
576 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
577 | errorLog(modulo,39,FALSE); |
---|
578 | return(FALSE); |
---|
579 | } |
---|
580 | |
---|
581 | return(TRUE); |
---|
582 | } |
---|
583 | //______________________________________________________________________________________________________ |
---|
584 | // Función: RESPUESTA_InclusionCliente |
---|
585 | // |
---|
586 | // Descripción: |
---|
587 | // Respuesta del servidor de administración a la petición de inicio |
---|
588 | // enviando los datos identificativos del cliente y otras configuraciones |
---|
589 | // Parámetros: |
---|
590 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
591 | // Devuelve: |
---|
592 | // TRUE: Si el proceso es correcto |
---|
593 | // FALSE: En caso de ocurrir algún error |
---|
594 | //______________________________________________________________________________________________________ |
---|
595 | BOOLEAN RESPUESTA_InclusionCliente(TRAMA* ptrTrama) |
---|
596 | { |
---|
597 | char* res; |
---|
598 | char modulo[] = "RESPUESTA_InclusionCliente()"; |
---|
599 | |
---|
600 | res=copiaParametro("res",ptrTrama); // Resultado del proceso de inclusión |
---|
601 | if(atoi(res)==0){ // Error en el proceso de inclusión |
---|
602 | liberaMemoria(res); |
---|
603 | errorLog(modulo,41,FALSE); |
---|
604 | return (FALSE); |
---|
605 | } |
---|
606 | liberaMemoria(res); |
---|
607 | |
---|
608 | idordenador=copiaParametro("ido",ptrTrama); // Identificador del ordenador |
---|
609 | nombreordenador=copiaParametro("npc",ptrTrama); // Nombre del ordenador |
---|
610 | cache=copiaParametro("che",ptrTrama); // Tamaño de la caché reservada al cliente |
---|
611 | idproautoexec=copiaParametro("exe",ptrTrama); // Procedimento de inicio (Autoexec) |
---|
612 | idcentro=copiaParametro("idc",ptrTrama); // Identificador de la Unidad Organizativa |
---|
613 | idaula=copiaParametro("ida",ptrTrama); // Identificador del aula |
---|
614 | |
---|
615 | if(idordenador==NULL || nombreordenador==NULL){ |
---|
616 | errorLog(modulo,40,FALSE); |
---|
617 | return (FALSE); |
---|
618 | } |
---|
619 | return(TRUE); |
---|
620 | } |
---|
621 | //______________________________________________________________________________________________________ |
---|
622 | // |
---|
623 | // Función: LeeConfiguracion |
---|
624 | // Descripción: |
---|
625 | // Abre una sesión en el servidor de administración y registra al cliente en el sistema |
---|
626 | // Parámetros: |
---|
627 | // Ninguno |
---|
628 | // Devuelve: |
---|
629 | // TRUE: Si el proceso es correcto |
---|
630 | // FALSE: En caso de ocurrir algún error |
---|
631 | //______________________________________________________________________________________________________ |
---|
632 | |
---|
633 | char* LeeConfiguracion() |
---|
634 | { |
---|
635 | char* parametroscfg; |
---|
636 | char modulo[] = "LeeConfiguracion()"; |
---|
637 | |
---|
638 | // Reservar memoria para los datos de cofiguración. |
---|
639 | parametroscfg=(char*)reservaMemoria(LONGITUD_SCRIPTSALIDA); |
---|
640 | if(!parametroscfg){ |
---|
641 | errorLog(modulo,3,FALSE); |
---|
642 | return(NULL); |
---|
643 | } |
---|
644 | // Ejecutar script y obtener datos. |
---|
645 | sprintf(interface,"%s/%s",pathinterface,"getConfiguration"); |
---|
646 | herror=interfaceAdmin(interface,NULL,parametroscfg); |
---|
647 | |
---|
648 | if(herror){ // No se puede recuperar la configuración del cliente |
---|
649 | liberaMemoria(parametroscfg); |
---|
650 | errorLog(modulo,36,FALSE); |
---|
651 | return(NULL); |
---|
652 | } |
---|
653 | return(parametroscfg); |
---|
654 | } |
---|
655 | //________________________________________________________________________________________________________ |
---|
656 | // Función: autoexecCliente |
---|
657 | // |
---|
658 | // Descripción: |
---|
659 | // Solicita procedimiento de autoexec para el cliebnte |
---|
660 | // Parámetros: |
---|
661 | // Ninguno |
---|
662 | // Devuelve: |
---|
663 | // TRUE: Si el proceso es correcto |
---|
664 | // FALSE: En caso de ocurrir algún error |
---|
665 | //________________________________________________________________________________________________________ |
---|
666 | BOOLEAN autoexecCliente(TRAMA* ptrTrama) |
---|
667 | { |
---|
668 | int lon; |
---|
669 | SOCKET socket_c; |
---|
670 | char modulo[] = "autoexecCliente()"; |
---|
671 | |
---|
672 | initParametros(ptrTrama,0); |
---|
673 | lon=sprintf(ptrTrama->parametros,"nfn=AutoexecCliente\rexe=%s\r",idproautoexec); |
---|
674 | |
---|
675 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
676 | errorLog(modulo,42,FALSE); |
---|
677 | return(FALSE); |
---|
678 | } |
---|
679 | ptrTrama=recibeMensaje(&socket_c); |
---|
680 | if(!ptrTrama){ |
---|
681 | errorLog(modulo,45,FALSE); |
---|
682 | return(FALSE); |
---|
683 | } |
---|
684 | |
---|
685 | close(socket_c); |
---|
686 | |
---|
687 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
688 | errorLog(modulo,39,FALSE); |
---|
689 | return(FALSE); |
---|
690 | } |
---|
691 | |
---|
692 | return(TRUE); |
---|
693 | } |
---|
694 | //________________________________________________________________________________________________________ |
---|
695 | // Función: autoexecCliente |
---|
696 | // |
---|
697 | // Descripción: |
---|
698 | // Ejecuta un script de autoexec personalizado en todos los inicios para el cliente |
---|
699 | // Parámetros: |
---|
700 | // Ninguno |
---|
701 | // Devuelve: |
---|
702 | // TRUE: Si el proceso es correcto |
---|
703 | // FALSE: En caso de ocurrir algún error |
---|
704 | //________________________________________________________________________________________________________ |
---|
705 | BOOLEAN RESPUESTA_AutoexecCliente(TRAMA* ptrTrama) |
---|
706 | { |
---|
707 | SOCKET socket_c; |
---|
708 | char *res,*nfl; |
---|
709 | char modulo[] = "RESPUESTA_AutoexecCliente()"; |
---|
710 | |
---|
711 | res=copiaParametro("res",ptrTrama); |
---|
712 | if(atoi(res)==0){ // Error en el proceso de autoexec |
---|
713 | liberaMemoria(res); |
---|
714 | return (FALSE); |
---|
715 | } |
---|
716 | liberaMemoria(res); |
---|
717 | |
---|
718 | nfl=copiaParametro("nfl",ptrTrama); |
---|
719 | initParametros(ptrTrama,0); |
---|
720 | sprintf(ptrTrama->parametros,"nfn=enviaArchivo\rnfl=%s\r",nfl); |
---|
721 | liberaMemoria(nfl); |
---|
722 | |
---|
723 | /* Envía petición */ |
---|
724 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
725 | errorLog(modulo,42,FALSE); |
---|
726 | return(FALSE); |
---|
727 | } |
---|
728 | /* Nombre del archivo destino (local)*/ |
---|
729 | char fileautoexec[LONPRM]; |
---|
730 | sprintf(fileautoexec,"/tmp/_autoexec_%s",IPlocal); |
---|
731 | |
---|
732 | /* Recibe archivo */ |
---|
733 | if(!recArchivo(&socket_c,fileautoexec)){ |
---|
734 | errorLog(modulo,58, FALSE); |
---|
735 | close(socket_c); |
---|
736 | return(FALSE); |
---|
737 | } |
---|
738 | |
---|
739 | close(socket_c); |
---|
740 | |
---|
741 | /* Ejecuta archivo */ |
---|
742 | ejecutaArchivo(fileautoexec,ptrTrama); |
---|
743 | return(TRUE); |
---|
744 | } |
---|
745 | //______________________________________________________________________________________________________ |
---|
746 | // Función: comandosPendientes |
---|
747 | // |
---|
748 | // Descripción: |
---|
749 | // Búsqueda de acciones pendientes en el servidor de administración |
---|
750 | // Parámetros: |
---|
751 | // Ninguno |
---|
752 | // Devuelve: |
---|
753 | // TRUE: Si el proceso es correcto |
---|
754 | // FALSE: En caso de ocurrir algún error |
---|
755 | //______________________________________________________________________________________________________ |
---|
756 | BOOLEAN comandosPendientes(TRAMA* ptrTrama) |
---|
757 | { |
---|
758 | SOCKET socket_c; |
---|
759 | char modulo[] = "comandosPendientes()"; |
---|
760 | |
---|
761 | CMDPTES=TRUE; |
---|
762 | initParametros(ptrTrama,0); |
---|
763 | |
---|
764 | while(CMDPTES){ |
---|
765 | sprintf(ptrTrama->parametros,"nfn=ComandosPendientes\r"); |
---|
766 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
767 | errorLog(modulo,42,FALSE); |
---|
768 | return(FALSE); |
---|
769 | } |
---|
770 | ptrTrama=recibeMensaje(&socket_c); |
---|
771 | if(!ptrTrama){ |
---|
772 | errorLog(modulo,45,FALSE); |
---|
773 | return(FALSE); |
---|
774 | } |
---|
775 | |
---|
776 | close(socket_c); |
---|
777 | |
---|
778 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
779 | errorLog(modulo,39,FALSE); |
---|
780 | return(FALSE); |
---|
781 | } |
---|
782 | } |
---|
783 | return(TRUE); |
---|
784 | } |
---|
785 | //______________________________________________________________________________________________________ |
---|
786 | // Función: NoComandosPtes |
---|
787 | // |
---|
788 | // Descripción: |
---|
789 | // Conmuta el switch de los comandos pendientes y lo pone a false |
---|
790 | // Parámetros: |
---|
791 | // - ptrTrama: contenido del mensaje |
---|
792 | // Devuelve: |
---|
793 | // TRUE siempre |
---|
794 | // Especificaciones: |
---|
795 | // Cuando se ejecuta esta función se sale del bucle que recupera los comandos pendientes en el |
---|
796 | // servidor y el cliente pasa a a estar disponible para recibir comandos desde el éste. |
---|
797 | //______________________________________________________________________________________________________ |
---|
798 | BOOLEAN NoComandosPtes(TRAMA* ptrTrama) |
---|
799 | { |
---|
800 | CMDPTES=FALSE; // Corta el bucle de comandos pendientes |
---|
801 | return(TRUE); |
---|
802 | } |
---|
803 | //______________________________________________________________________________________________________ |
---|
804 | // Función: ProcesaComandos |
---|
805 | // |
---|
806 | // Descripción: |
---|
807 | // Espera comando desde el Servidor de Administración para ejecutarlos |
---|
808 | // Parámetros: |
---|
809 | // Ninguno |
---|
810 | // Devuelve: |
---|
811 | // TRUE: Si el proceso es correcto |
---|
812 | // FALSE: En caso de ocurrir algún error |
---|
813 | // ________________________________________________________________________________________________________ |
---|
814 | void procesaComandos(TRAMA* ptrTrama) |
---|
815 | { |
---|
816 | int lon; |
---|
817 | SOCKET socket_c; |
---|
818 | char modulo[] = "procesaComandos()"; |
---|
819 | |
---|
820 | initParametros(ptrTrama,0); |
---|
821 | while(TRUE){ |
---|
822 | lon=sprintf(ptrTrama->parametros,"nfn=DisponibilidadComandos\r"); |
---|
823 | lon+=sprintf(ptrTrama->parametros+lon,"tpc=%s\r",CLIENTE_OPENGNSYS); // Activar disponibilidad |
---|
824 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_INFORMACION)){ |
---|
825 | errorLog(modulo,43,FALSE); |
---|
826 | return; |
---|
827 | } |
---|
828 | infoLog(19); // Disponibilidad de cliente activada |
---|
829 | ptrTrama=recibeMensaje(&socket_c); |
---|
830 | if(!ptrTrama){ |
---|
831 | errorLog(modulo,46,FALSE); |
---|
832 | return; |
---|
833 | } |
---|
834 | |
---|
835 | close(socket_c); |
---|
836 | |
---|
837 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
838 | errorLog(modulo,39,FALSE); |
---|
839 | return; |
---|
840 | } |
---|
841 | if(!comandosPendientes(ptrTrama)){ |
---|
842 | errorLog(modulo,42,FALSE); |
---|
843 | } |
---|
844 | } |
---|
845 | } |
---|
846 | //______________________________________________________________________________________________________ |
---|
847 | // Función: Actualizar |
---|
848 | // |
---|
849 | // Descripción: |
---|
850 | // Actualiza los datos de un ordenador como si volviera a solicitar la entrada |
---|
851 | // en el sistema al servidor de administración |
---|
852 | // Parámetros: |
---|
853 | // ptrTrama: contenido del mensajede |
---|
854 | // Devuelve: |
---|
855 | // TRUE: Si el proceso es correcto |
---|
856 | // FALSE: En caso de ocurrir algún error |
---|
857 | //______________________________________________________________________________________________________ |
---|
858 | BOOLEAN Actualizar(TRAMA* ptrTrama) |
---|
859 | { |
---|
860 | char msglog[LONSTD]; // Mensaje de log |
---|
861 | char *cfg; // Cadena de datos de configuración |
---|
862 | int lon; // Longitud de cadena |
---|
863 | char modulo[] = "Actualizar()"; |
---|
864 | |
---|
865 | if (ndebug>=DEBUG_MAXIMO) { |
---|
866 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
867 | infoDebug(msglog); |
---|
868 | } |
---|
869 | muestraMensaje(1,NULL); |
---|
870 | if(!comandosPendientes(ptrTrama)){ |
---|
871 | errorLog(modulo,84,FALSE); |
---|
872 | return(FALSE); |
---|
873 | } |
---|
874 | |
---|
875 | cfg=LeeConfiguracion(); |
---|
876 | herror=0; |
---|
877 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
878 | errorLog(modulo,36,FALSE); |
---|
879 | herror=3; |
---|
880 | } |
---|
881 | // Envia Configuracion al servidor |
---|
882 | initParametros(ptrTrama,0); |
---|
883 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Configurar"); |
---|
884 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
885 | respuestaEjecucionComando(ptrTrama,herror,0); |
---|
886 | |
---|
887 | muestraMenu(); |
---|
888 | |
---|
889 | return(TRUE); |
---|
890 | } |
---|
891 | //______________________________________________________________________________________________________ |
---|
892 | // Función: Purgar |
---|
893 | // |
---|
894 | // Descripción: |
---|
895 | // Detiene la ejecución del browser |
---|
896 | // Parámetros: |
---|
897 | // ptrTrama: contenido del mensajede |
---|
898 | // Devuelve: |
---|
899 | // TRUE: Si el proceso es correcto |
---|
900 | // FALSE: En caso de ocurrir algún error |
---|
901 | //______________________________________________________________________________________________________ |
---|
902 | int Purgar(TRAMA* ptrTrama) |
---|
903 | { |
---|
904 | int resul=0; |
---|
905 | char modulo[] = "Purgar()"; |
---|
906 | |
---|
907 | if(pidbrowser>0) |
---|
908 | kill(pidbrowser,SIGQUIT); // Destruye el proceso hijo anterior y se queda sólo el actual |
---|
909 | |
---|
910 | if(pidbash>0) |
---|
911 | kill(pidbash,SIGQUIT); // Destruye el proceso hijo del proceso bash si existiera una conmutación |
---|
912 | |
---|
913 | sprintf(interface,"/opt/opengnsys/bin/bash"); |
---|
914 | if((pidbash=fork())==0){ |
---|
915 | /* Proceso hijo que ejecuta el script */ |
---|
916 | resul=execv(interface,NULL); |
---|
917 | exit(resul); |
---|
918 | } |
---|
919 | else { |
---|
920 | if (pidbash ==-1){ |
---|
921 | scriptLog(modulo,10); |
---|
922 | resul=13; |
---|
923 | scriptLog(modulo,resul); |
---|
924 | return(resul); |
---|
925 | } |
---|
926 | } |
---|
927 | exit(EXIT_SUCCESS); |
---|
928 | } |
---|
929 | //______________________________________________________________________________________________________ |
---|
930 | // Función: Sondeo |
---|
931 | // |
---|
932 | // Descripción: |
---|
933 | // Envía al servidor una confirmación de que está dentro del sistema |
---|
934 | // Parámetros: |
---|
935 | // ptrTrama: contenido del mensajede |
---|
936 | // Devuelve: |
---|
937 | // TRUE: Si el proceso es correcto |
---|
938 | // FALSE: En caso de ocurrir algún error |
---|
939 | //______________________________________________________________________________________________________ |
---|
940 | BOOLEAN Sondeo(TRAMA* ptrTrama) |
---|
941 | { |
---|
942 | return(TRUE); |
---|
943 | } |
---|
944 | //______________________________________________________________________________________________________ |
---|
945 | // Función: ConsolaRemota |
---|
946 | // |
---|
947 | // Descripción: |
---|
948 | // Ejecuta un comando de la Shell y envia el eco al servidor (Consola remota) |
---|
949 | // Parámetros: |
---|
950 | // ptrTrama: contenido del mensaje |
---|
951 | // Devuelve: |
---|
952 | // TRUE: Si el proceso es correcto |
---|
953 | // FALSE: En caso de ocurrir algún error |
---|
954 | //______________________________________________________________________________________________________ |
---|
955 | BOOLEAN ConsolaRemota(TRAMA* ptrTrama) |
---|
956 | { |
---|
957 | SOCKET socket_c; |
---|
958 | char *nfn,*scp,*aux,ecosrc[LONPRM],ecodst[LONPRM],msglog[LONSTD];; |
---|
959 | char modulo[] = "ConsolaRemota()"; |
---|
960 | |
---|
961 | /* Nombre del archivo de script */ |
---|
962 | char filescript[LONPRM]; |
---|
963 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
964 | |
---|
965 | aux=copiaParametro("scp",ptrTrama); |
---|
966 | scp=URLDecode(aux); |
---|
967 | escribeArchivo(filescript,scp); |
---|
968 | liberaMemoria(aux); |
---|
969 | liberaMemoria(scp); |
---|
970 | |
---|
971 | nfn=copiaParametro("nfn",ptrTrama); |
---|
972 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
973 | sprintf(ecosrc,"/tmp/_econsola_%s",IPlocal); |
---|
974 | sprintf(parametros,"%s %s %s",nfn,filescript,ecosrc); |
---|
975 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
976 | if(herror){ |
---|
977 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
978 | errorInfo(modulo,msglog); |
---|
979 | } |
---|
980 | else{ |
---|
981 | /* Envía fichero de inventario al servidor */ |
---|
982 | sprintf(ecodst,"/tmp/_Seconsola_%s",IPlocal); // Nombre que tendra el archivo en el Servidor |
---|
983 | initParametros(ptrTrama,0); |
---|
984 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",ecodst); |
---|
985 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
986 | errorLog(modulo,42,FALSE); |
---|
987 | return(FALSE); |
---|
988 | } |
---|
989 | /* Espera señal para comenzar el envío */ |
---|
990 | liberaMemoria(ptrTrama); |
---|
991 | recibeFlag(&socket_c,ptrTrama); |
---|
992 | /* Envía archivo */ |
---|
993 | if(!sendArchivo(&socket_c,ecosrc)){ |
---|
994 | errorLog(modulo,57, FALSE); |
---|
995 | herror=12; // Error de envío de fichero por la red |
---|
996 | } |
---|
997 | close(socket_c); |
---|
998 | } |
---|
999 | liberaMemoria(nfn); |
---|
1000 | return(TRUE); |
---|
1001 | } |
---|
1002 | //_____________________________________________________________________________________________________ |
---|
1003 | // Función: Comando |
---|
1004 | // |
---|
1005 | // Descripción: |
---|
1006 | // COmando personalizado enviado desde el servidor |
---|
1007 | // Parámetros: |
---|
1008 | // ptrTrama: contenido del mensaje |
---|
1009 | // Devuelve: |
---|
1010 | // TRUE: Si el proceso es correcto |
---|
1011 | // FALSE: En caso de ocurrir algún error |
---|
1012 | //_____________________________________________________________________________________________________ |
---|
1013 | BOOLEAN Comando(TRAMA* ptrTrama) |
---|
1014 | { |
---|
1015 | int lon; |
---|
1016 | char *ids,*nfn,msglog[LONSTD]; |
---|
1017 | char modulo[] = "Comando()"; |
---|
1018 | |
---|
1019 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1020 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1021 | infoDebug(msglog); |
---|
1022 | } |
---|
1023 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1024 | ids=copiaParametro("ids",ptrTrama); |
---|
1025 | |
---|
1026 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1027 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
1028 | if(herror){ |
---|
1029 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1030 | errorInfo(modulo,msglog); |
---|
1031 | } |
---|
1032 | /* Envia respuesta de ejecucución del comando */ |
---|
1033 | initParametros(ptrTrama,0); |
---|
1034 | lon=sprintf(ptrTrama->parametros,"nfn=RESPUESTA_%s\r",nfn); |
---|
1035 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1036 | liberaMemoria(nfn); |
---|
1037 | liberaMemoria(ids); |
---|
1038 | return(TRUE); |
---|
1039 | } |
---|
1040 | //_____________________________________________________________________________________________________ |
---|
1041 | // Función: Arrancar |
---|
1042 | // |
---|
1043 | // Descripción: |
---|
1044 | // Responde a un comando de encendido por la red |
---|
1045 | // Parámetros: |
---|
1046 | // ptrTrama: contenido del mensaje |
---|
1047 | // Devuelve: |
---|
1048 | // TRUE: Si el proceso es correcto |
---|
1049 | // FALSE: En caso de ocurrir algún error |
---|
1050 | //_____________________________________________________________________________________________________ |
---|
1051 | BOOLEAN Arrancar(TRAMA* ptrTrama) |
---|
1052 | { |
---|
1053 | int lon; |
---|
1054 | char *ids,msglog[LONSTD]; |
---|
1055 | char modulo[] = "Arrancar()"; |
---|
1056 | |
---|
1057 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1058 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1059 | infoDebug(msglog); |
---|
1060 | } |
---|
1061 | |
---|
1062 | ids=copiaParametro("ids",ptrTrama); |
---|
1063 | |
---|
1064 | /* Envia respuesta de ejecucución del script */ |
---|
1065 | initParametros(ptrTrama,0); |
---|
1066 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Arrancar"); |
---|
1067 | lon+=sprintf(ptrTrama->parametros+lon,"tpc=%s\r",CLIENTE_OPENGNSYS); |
---|
1068 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
1069 | liberaMemoria(ids); |
---|
1070 | return(TRUE); |
---|
1071 | } |
---|
1072 | //_____________________________________________________________________________________________________ |
---|
1073 | // Función: Apagar |
---|
1074 | // |
---|
1075 | // Descripción: |
---|
1076 | // Apaga el cliente |
---|
1077 | // Parámetros: |
---|
1078 | // ptrTrama: contenido del mensaje |
---|
1079 | // Devuelve: |
---|
1080 | // TRUE: Si el proceso es correcto |
---|
1081 | // FALSE: En caso de ocurrir algún error |
---|
1082 | //_____________________________________________________________________________________________________ |
---|
1083 | BOOLEAN Apagar(TRAMA* ptrTrama) |
---|
1084 | { |
---|
1085 | int lon; |
---|
1086 | char *ids,*nfn,msglog[LONSTD]; |
---|
1087 | char modulo[] = "Apagar()"; |
---|
1088 | |
---|
1089 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1090 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1091 | infoDebug(msglog); |
---|
1092 | } |
---|
1093 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1094 | ids=copiaParametro("ids",ptrTrama); |
---|
1095 | |
---|
1096 | initParametros(ptrTrama,0); |
---|
1097 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Apagar"); |
---|
1098 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
1099 | |
---|
1100 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1101 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
1102 | if(herror){ |
---|
1103 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1104 | liberaMemoria(nfn); |
---|
1105 | liberaMemoria(ids); |
---|
1106 | errorInfo(modulo,msglog); |
---|
1107 | return(FALSE); |
---|
1108 | } |
---|
1109 | liberaMemoria(nfn); |
---|
1110 | liberaMemoria(ids); |
---|
1111 | return(TRUE); |
---|
1112 | } |
---|
1113 | //_____________________________________________________________________________________________________ |
---|
1114 | // Función: Reiniciar |
---|
1115 | // |
---|
1116 | // Descripción: |
---|
1117 | // Apaga el cliente |
---|
1118 | // Parámetros: |
---|
1119 | // ptrTrama: contenido del mensaje |
---|
1120 | // Devuelve: |
---|
1121 | // TRUE: Si el proceso es correcto |
---|
1122 | // FALSE: En caso de ocurrir algún error |
---|
1123 | //_____________________________________________________________________________________________________ |
---|
1124 | BOOLEAN Reiniciar(TRAMA* ptrTrama) |
---|
1125 | { |
---|
1126 | int lon; |
---|
1127 | char *nfn,*ids,msglog[LONSTD]; |
---|
1128 | char modulo[] = "Reiniciar()"; |
---|
1129 | |
---|
1130 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1131 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1132 | infoDebug(msglog); |
---|
1133 | } |
---|
1134 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1135 | ids=copiaParametro("ids",ptrTrama); |
---|
1136 | |
---|
1137 | initParametros(ptrTrama,0); |
---|
1138 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Reiniciar"); |
---|
1139 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
1140 | |
---|
1141 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1142 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
1143 | if(herror){ |
---|
1144 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1145 | liberaMemoria(nfn); |
---|
1146 | liberaMemoria(ids); |
---|
1147 | errorInfo(modulo,msglog); |
---|
1148 | return(FALSE); |
---|
1149 | } |
---|
1150 | liberaMemoria(nfn); |
---|
1151 | liberaMemoria(ids); |
---|
1152 | return(TRUE); |
---|
1153 | } |
---|
1154 | //_____________________________________________________________________________________________________ |
---|
1155 | // Función: IniciarSesion |
---|
1156 | // |
---|
1157 | // Descripción: |
---|
1158 | // Inicia sesión en el Sistema Operativo de una de las particiones |
---|
1159 | // Parámetros: |
---|
1160 | // ptrTrama: contenido del mensaje |
---|
1161 | // Devuelve: |
---|
1162 | // TRUE: Si el proceso es correcto |
---|
1163 | // FALSE: En caso de ocurrir algún error |
---|
1164 | //_____________________________________________________________________________________________________ |
---|
1165 | BOOLEAN IniciarSesion(TRAMA* ptrTrama) |
---|
1166 | { |
---|
1167 | int lon; |
---|
1168 | char *nfn,*ids,*disk,*par,msglog[LONSTD]; |
---|
1169 | char modulo[] = "IniciarSesion()"; |
---|
1170 | |
---|
1171 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1172 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1173 | infoDebug(msglog); |
---|
1174 | } |
---|
1175 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1176 | ids=copiaParametro("ids",ptrTrama); |
---|
1177 | disk=copiaParametro("dsk",ptrTrama); |
---|
1178 | par=copiaParametro("par",ptrTrama); |
---|
1179 | |
---|
1180 | initParametros(ptrTrama,0); |
---|
1181 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_IniciarSesion"); |
---|
1182 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
1183 | liberaMemoria(ids); |
---|
1184 | |
---|
1185 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1186 | sprintf(parametros,"%s %s %s",nfn,disk,par); |
---|
1187 | liberaMemoria(par); |
---|
1188 | |
---|
1189 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1190 | |
---|
1191 | if(herror){ |
---|
1192 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1193 | liberaMemoria(nfn); |
---|
1194 | errorInfo(modulo,msglog); |
---|
1195 | return(FALSE); |
---|
1196 | } |
---|
1197 | liberaMemoria(nfn); |
---|
1198 | return(TRUE); |
---|
1199 | } |
---|
1200 | //______________________________________________________________________________________________________ |
---|
1201 | // Función: CrearImagen |
---|
1202 | // |
---|
1203 | // Descripción: |
---|
1204 | // Crea una imagen de una partición |
---|
1205 | // Parámetros: |
---|
1206 | // ptrTrama: contenido del mensaje |
---|
1207 | // Devuelve: |
---|
1208 | // TRUE: Si el proceso es correcto |
---|
1209 | // FALSE: En caso de ocurrir algún error |
---|
1210 | //______________________________________________________________________________________________________ |
---|
1211 | BOOLEAN CrearImagen(TRAMA* ptrTrama) |
---|
1212 | { |
---|
1213 | int lon; |
---|
1214 | char *nfn,*dsk,*par,*cpt,*idi,*ipr,*nci,*ids,msglog[LONSTD]; |
---|
1215 | char modulo[] = "CrearImagen()"; |
---|
1216 | |
---|
1217 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1218 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1219 | infoDebug(msglog); |
---|
1220 | } |
---|
1221 | |
---|
1222 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
1223 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
1224 | cpt=copiaParametro("cpt",ptrTrama); // Código de la partición |
---|
1225 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
1226 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
1227 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
1228 | |
---|
1229 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1230 | ids=copiaParametro("ids",ptrTrama); |
---|
1231 | muestraMensaje(7,NULL); |
---|
1232 | |
---|
1233 | if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
1234 | muestraMensaje(2,NULL); |
---|
1235 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1236 | sprintf(parametros,"%s %s %s %s %s",nfn,dsk,par,nci,ipr); |
---|
1237 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1238 | if(herror){ |
---|
1239 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1240 | errorInfo(modulo,msglog); |
---|
1241 | muestraMensaje(10,NULL); |
---|
1242 | } |
---|
1243 | else |
---|
1244 | muestraMensaje(9,NULL); |
---|
1245 | } |
---|
1246 | else{ |
---|
1247 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1248 | errorInfo(modulo,msglog); |
---|
1249 | } |
---|
1250 | |
---|
1251 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1252 | initParametros(ptrTrama,0); |
---|
1253 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearImagen"); |
---|
1254 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
1255 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición de donde se creó |
---|
1256 | lon+=sprintf(ptrTrama->parametros+lon,"cpt=%s\r",cpt); // Tipo o código de partición |
---|
1257 | lon+=sprintf(ptrTrama->parametros+lon,"ipr=%s\r",ipr); // Ip del repositorio donde se alojó |
---|
1258 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1259 | |
---|
1260 | liberaMemoria(dsk); |
---|
1261 | liberaMemoria(par); |
---|
1262 | liberaMemoria(cpt); |
---|
1263 | liberaMemoria(idi); |
---|
1264 | liberaMemoria(nci); |
---|
1265 | liberaMemoria(ipr); |
---|
1266 | liberaMemoria(nfn); |
---|
1267 | liberaMemoria(ids); |
---|
1268 | |
---|
1269 | muestraMenu(); |
---|
1270 | |
---|
1271 | return(TRUE); |
---|
1272 | } |
---|
1273 | //______________________________________________________________________________________________________ |
---|
1274 | // Función: CrearImagenBasica |
---|
1275 | // |
---|
1276 | // Descripción: |
---|
1277 | // Crea una imagen básica a traverś dela sincronización |
---|
1278 | // Parámetros: |
---|
1279 | // ptrTrama: contenido del mensaje |
---|
1280 | // |
---|
1281 | // FDevuelve: |
---|
1282 | // TRUE: Si el proceso es correcto |
---|
1283 | // FALSE: En caso de ocurrir algún error |
---|
1284 | //______________________________________________________________________________________________________ |
---|
1285 | BOOLEAN CrearImagenBasica(TRAMA* ptrTrama) |
---|
1286 | { |
---|
1287 | int lon; |
---|
1288 | char *nfn,*dsk,*par,*cpt,*idi,*nci,*rti,*ipr,*msy,*whl,*eli,*cmp,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
1289 | char modulo[] = "CrearImagenBasica()"; |
---|
1290 | |
---|
1291 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1292 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1293 | infoDebug(msglog); |
---|
1294 | } |
---|
1295 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1296 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
1297 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
1298 | cpt=copiaParametro("cpt",ptrTrama); // Tipo de partición |
---|
1299 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
1300 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
1301 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
1302 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
1303 | |
---|
1304 | msy=copiaParametro("msy",ptrTrama); // Método de sincronización |
---|
1305 | |
---|
1306 | whl=copiaParametro("whl",ptrTrama); // Envío del fichero completo si hay diferencias |
---|
1307 | eli=copiaParametro("eli",ptrTrama); // Elimiar archivos en destino que no estén en origen |
---|
1308 | cmp=copiaParametro("cmp",ptrTrama); // Comprimir antes de enviar |
---|
1309 | |
---|
1310 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
1311 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
1312 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
1313 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
1314 | |
---|
1315 | //muestraMensaje(7,NULL); // Creando Inventario Software |
---|
1316 | //if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
1317 | muestraMensaje(30,NULL);// Creando Imagen Básica, por favor espere... |
---|
1318 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1319 | sprintf(parametros,"%s %s %s %s %s %s%s%s %s%s%s%s %s %s",nfn,dsk,par,nci,ipr,whl,eli,cmp,bpi,cpc,bpc,nba,msy,rti); |
---|
1320 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1321 | if(herror){ |
---|
1322 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1323 | errorInfo(modulo,msglog); |
---|
1324 | muestraMensaje(29,NULL);// Ha habido algún error en el proceso de creación de imagen básica |
---|
1325 | } |
---|
1326 | else |
---|
1327 | muestraMensaje(28,NULL);// El proceso de creación de imagen básica ha terminado correctamente |
---|
1328 | //} |
---|
1329 | //else{ |
---|
1330 | // sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1331 | // errorInfo(modulo,msglog); |
---|
1332 | //} |
---|
1333 | |
---|
1334 | ids=copiaParametro("ids",ptrTrama); // Identificador de la sesión |
---|
1335 | |
---|
1336 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1337 | initParametros(ptrTrama,0); |
---|
1338 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearImagenBasica"); |
---|
1339 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
1340 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición de donde se creó |
---|
1341 | lon+=sprintf(ptrTrama->parametros+lon,"cpt=%s\r",cpt); // Tipo o código de partición |
---|
1342 | lon+=sprintf(ptrTrama->parametros+lon,"ipr=%s\r",ipr); // Ip del repositorio donde se alojó |
---|
1343 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1344 | |
---|
1345 | liberaMemoria(nfn); |
---|
1346 | liberaMemoria(dsk); |
---|
1347 | liberaMemoria(par); |
---|
1348 | liberaMemoria(cpt); |
---|
1349 | liberaMemoria(idi); |
---|
1350 | liberaMemoria(nci); |
---|
1351 | liberaMemoria(rti); |
---|
1352 | liberaMemoria(ipr); |
---|
1353 | |
---|
1354 | liberaMemoria(msy); |
---|
1355 | |
---|
1356 | liberaMemoria(whl); |
---|
1357 | liberaMemoria(eli); |
---|
1358 | liberaMemoria(cmp); |
---|
1359 | |
---|
1360 | liberaMemoria(bpi); |
---|
1361 | liberaMemoria(cpc); |
---|
1362 | liberaMemoria(bpc); |
---|
1363 | liberaMemoria(nba); |
---|
1364 | liberaMemoria(ids); |
---|
1365 | |
---|
1366 | muestraMenu(); |
---|
1367 | |
---|
1368 | return(TRUE); |
---|
1369 | } |
---|
1370 | //______________________________________________________________________________________________________ |
---|
1371 | // Función: CrearSoftIncremental |
---|
1372 | // |
---|
1373 | // Descripción: |
---|
1374 | // Crea una software incremental comparando una partición con una imagen básica |
---|
1375 | // Parámetros: |
---|
1376 | // ptrTrama: contenido del mensaje |
---|
1377 | // |
---|
1378 | // Devuelve: |
---|
1379 | // TRUE: Si el proceso es correcto |
---|
1380 | // FALSE: En caso de ocurrir algún error |
---|
1381 | //______________________________________________________________________________________________________ |
---|
1382 | BOOLEAN CrearSoftIncremental(TRAMA* ptrTrama) |
---|
1383 | { |
---|
1384 | int lon; |
---|
1385 | char *nfn,*dsk,*par,*idi,*idf,*ipr,*nci,*rti,*ncf,*whl,*eli,*cmp,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
1386 | char modulo[] = "CrearSoftIncremental()"; |
---|
1387 | |
---|
1388 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1389 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1390 | infoDebug(msglog); |
---|
1391 | } |
---|
1392 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1393 | |
---|
1394 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
1395 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
1396 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
1397 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
1398 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
1399 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
1400 | idf=copiaParametro("idf",ptrTrama); // Identificador de la imagen diferencial |
---|
1401 | ncf=copiaParametro("ncf",ptrTrama); // Nombre canónico de la imagen diferencial |
---|
1402 | |
---|
1403 | whl=copiaParametro("whl",ptrTrama); // Envío del fichero completo si hay diferencias |
---|
1404 | eli=copiaParametro("eli",ptrTrama); // Elimiar archivos en destino que no estén en origen |
---|
1405 | cmp=copiaParametro("cmp",ptrTrama); // Comprimir antes de enviar |
---|
1406 | |
---|
1407 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
1408 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
1409 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
1410 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
1411 | |
---|
1412 | // muestraMensaje(7,NULL); // Creando Inventario Software |
---|
1413 | // if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
1414 | muestraMensaje(25,NULL);// Creando Imagen Incremental, por favor espere... |
---|
1415 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1416 | sprintf(parametros,"%s %s %s %s %s %s %s%s%s %s%s%s%s %s",nfn,dsk,par,nci,ipr,ncf,whl,eli,cmp,bpi,cpc,bpc,nba,rti); |
---|
1417 | |
---|
1418 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1419 | if(herror){ |
---|
1420 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1421 | errorInfo(modulo,msglog); |
---|
1422 | muestraMensaje(27,NULL);// Ha habido algún error en el proceso de creación de imagen básica |
---|
1423 | } |
---|
1424 | else |
---|
1425 | muestraMensaje(26,NULL);// El proceso de creación de imagen básica ha terminado correctamente |
---|
1426 | // } |
---|
1427 | // else{ |
---|
1428 | // sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1429 | // errorInfo(modulo,msglog); |
---|
1430 | // } |
---|
1431 | |
---|
1432 | ids=copiaParametro("ids",ptrTrama); // Identificador de la sesión |
---|
1433 | |
---|
1434 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1435 | initParametros(ptrTrama,0); |
---|
1436 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearSoftIncremental"); |
---|
1437 | lon+=sprintf(ptrTrama->parametros+lon,"idf=%s\r",idf); // Identificador de la imagen incremental |
---|
1438 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
1439 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1440 | |
---|
1441 | liberaMemoria(nfn); |
---|
1442 | liberaMemoria(dsk); |
---|
1443 | liberaMemoria(par); |
---|
1444 | liberaMemoria(idi); |
---|
1445 | liberaMemoria(nci); |
---|
1446 | liberaMemoria(rti); |
---|
1447 | liberaMemoria(ipr); |
---|
1448 | liberaMemoria(idf); |
---|
1449 | liberaMemoria(ncf); |
---|
1450 | liberaMemoria(whl); |
---|
1451 | liberaMemoria(eli); |
---|
1452 | liberaMemoria(cmp); |
---|
1453 | liberaMemoria(bpi); |
---|
1454 | liberaMemoria(cpc); |
---|
1455 | liberaMemoria(bpc); |
---|
1456 | liberaMemoria(nba); |
---|
1457 | liberaMemoria(ids); |
---|
1458 | |
---|
1459 | muestraMenu(); |
---|
1460 | |
---|
1461 | return(TRUE); |
---|
1462 | } |
---|
1463 | //______________________________________________________________________________________________________ |
---|
1464 | // Función: RestaurarImagen |
---|
1465 | // |
---|
1466 | // Descripción: |
---|
1467 | // Restaura una imagen en una partición |
---|
1468 | // Parámetros: |
---|
1469 | // ptrTrama: contenido del mensaje |
---|
1470 | // Devuelve: |
---|
1471 | // TRUE: Si el proceso es correcto |
---|
1472 | // FALSE: En bpccaso de ocurrir algún error |
---|
1473 | //______________________________________________________________________________________________________ |
---|
1474 | BOOLEAN RestaurarImagen(TRAMA* ptrTrama) |
---|
1475 | { |
---|
1476 | int lon; |
---|
1477 | char *nfn,*dsk,*par,*idi,*ipr,*ifs,*nci,*ids,*ptc,msglog[LONSTD]; |
---|
1478 | char modulo[] = "RestaurarImagen()"; |
---|
1479 | |
---|
1480 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1481 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1482 | infoDebug(msglog); |
---|
1483 | } |
---|
1484 | |
---|
1485 | dsk=copiaParametro("dsk",ptrTrama); |
---|
1486 | par=copiaParametro("par",ptrTrama); |
---|
1487 | idi=copiaParametro("idi",ptrTrama); |
---|
1488 | ipr=copiaParametro("ipr",ptrTrama); |
---|
1489 | nci=copiaParametro("nci",ptrTrama); |
---|
1490 | ifs=copiaParametro("ifs",ptrTrama); |
---|
1491 | ptc=copiaParametro("ptc",ptrTrama); |
---|
1492 | |
---|
1493 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1494 | ids=copiaParametro("ids",ptrTrama); |
---|
1495 | muestraMensaje(3,NULL); |
---|
1496 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1497 | sprintf(parametros,"%s %s %s %s %s %s",nfn,dsk,par,nci,ipr,ptc); |
---|
1498 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1499 | if(herror){ |
---|
1500 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1501 | errorInfo(modulo,msglog); |
---|
1502 | muestraMensaje(12,NULL); |
---|
1503 | } |
---|
1504 | else |
---|
1505 | muestraMensaje(11,NULL); |
---|
1506 | |
---|
1507 | |
---|
1508 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1509 | initParametros(ptrTrama,0); |
---|
1510 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarImagen"); |
---|
1511 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
1512 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
1513 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
1514 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1515 | |
---|
1516 | liberaMemoria(nfn); |
---|
1517 | liberaMemoria(dsk); |
---|
1518 | liberaMemoria(par); |
---|
1519 | liberaMemoria(idi); |
---|
1520 | liberaMemoria(nci); |
---|
1521 | liberaMemoria(ipr); |
---|
1522 | liberaMemoria(ifs); |
---|
1523 | liberaMemoria(ptc); |
---|
1524 | liberaMemoria(ids); |
---|
1525 | |
---|
1526 | muestraMenu(); |
---|
1527 | |
---|
1528 | return(TRUE); |
---|
1529 | } |
---|
1530 | //______________________________________________________________________________________________________ |
---|
1531 | // Función: RestaurarImagenBasica |
---|
1532 | // |
---|
1533 | // Descripción: |
---|
1534 | // Restaura una imagen básica en una partición |
---|
1535 | // Parámetros: |
---|
1536 | // ptrTrama: contenido del mensaje |
---|
1537 | // Devuelve: |
---|
1538 | // TRUE: Si el proceso es correcto |
---|
1539 | // FALSE: En caso de ocurrir algún error |
---|
1540 | //______________________________________________________________________________________________________ |
---|
1541 | BOOLEAN RestaurarImagenBasica(TRAMA* ptrTrama) |
---|
1542 | { |
---|
1543 | int lon; |
---|
1544 | char *nfn,*dsk,*par,*idi,*ipr,*met,*nci,*rti,*ifs,*whl,*eli,*cmp,*tpt,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
1545 | char modulo[] = "RestaurarImagenBasica()"; |
---|
1546 | |
---|
1547 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1548 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1549 | infoDebug(msglog); |
---|
1550 | } |
---|
1551 | dsk=copiaParametro("dsk",ptrTrama); |
---|
1552 | par=copiaParametro("par",ptrTrama); |
---|
1553 | idi=copiaParametro("idi",ptrTrama); |
---|
1554 | ipr=copiaParametro("ipr",ptrTrama); |
---|
1555 | met=copiaParametro("met",ptrTrama); // Método de clonación 0= desde caché 1= desde repositorio |
---|
1556 | nci=copiaParametro("nci",ptrTrama); |
---|
1557 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
1558 | ifs=copiaParametro("ifs",ptrTrama); |
---|
1559 | |
---|
1560 | tpt=copiaParametro("tpt",ptrTrama); // Tipo de trasnmisión unicast o multicast |
---|
1561 | |
---|
1562 | whl=copiaParametro("whl",ptrTrama); // Envío del fichero completo si hay diferencias |
---|
1563 | eli=copiaParametro("eli",ptrTrama); // Elimiar archivos en destino que no estén en origen |
---|
1564 | cmp=copiaParametro("cmp",ptrTrama); // Comprimir antes de enviar |
---|
1565 | |
---|
1566 | |
---|
1567 | |
---|
1568 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
1569 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
1570 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
1571 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
1572 | |
---|
1573 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1574 | ids=copiaParametro("ids",ptrTrama); |
---|
1575 | muestraMensaje(31,NULL); |
---|
1576 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1577 | sprintf(parametros,"%s %s %s %s %s %s %s%s%s %s%s%s%s %s %s",nfn,dsk,par,nci,ipr,tpt,whl,eli,cmp,bpi,cpc,bpc,nba,met,rti); |
---|
1578 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1579 | if(herror){ |
---|
1580 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1581 | errorInfo(modulo,msglog); |
---|
1582 | muestraMensaje(33,NULL); |
---|
1583 | } |
---|
1584 | else |
---|
1585 | muestraMensaje(32,NULL); |
---|
1586 | |
---|
1587 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1588 | initParametros(ptrTrama,0); |
---|
1589 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarImagenBasica"); |
---|
1590 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
1591 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
1592 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
1593 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1594 | |
---|
1595 | liberaMemoria(nfn); |
---|
1596 | liberaMemoria(dsk); |
---|
1597 | liberaMemoria(par); |
---|
1598 | liberaMemoria(idi); |
---|
1599 | liberaMemoria(nci); |
---|
1600 | liberaMemoria(rti); |
---|
1601 | liberaMemoria(ifs); |
---|
1602 | liberaMemoria(ipr); |
---|
1603 | liberaMemoria(met); |
---|
1604 | |
---|
1605 | liberaMemoria(tpt); |
---|
1606 | |
---|
1607 | liberaMemoria(whl); |
---|
1608 | liberaMemoria(eli); |
---|
1609 | liberaMemoria(cmp); |
---|
1610 | |
---|
1611 | liberaMemoria(bpi); |
---|
1612 | liberaMemoria(cpc); |
---|
1613 | liberaMemoria(bpc); |
---|
1614 | liberaMemoria(nba); |
---|
1615 | liberaMemoria(ids); |
---|
1616 | |
---|
1617 | muestraMenu(); |
---|
1618 | |
---|
1619 | return(TRUE); |
---|
1620 | } |
---|
1621 | //______________________________________________________________________________________________________ |
---|
1622 | // Función: RestaurarSoftIncremental |
---|
1623 | // |
---|
1624 | // Descripción: |
---|
1625 | // Restaura software incremental en una partición |
---|
1626 | // Parámetros: |
---|
1627 | // ptrTrama: contenido del mensaje |
---|
1628 | // Devuelve: |
---|
1629 | // TRUE: Si el proceso es correcto |
---|
1630 | // FALSE: En caso de ocurrir algún error |
---|
1631 | //______________________________________________________________________________________________________ |
---|
1632 | BOOLEAN RestaurarSoftIncremental(TRAMA* ptrTrama) |
---|
1633 | { |
---|
1634 | int lon; |
---|
1635 | char *nfn,*dsk,*par,*idi,*ipr,*met,*ifs,*nci,*rti,*idf,*ncf,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
1636 | char modulo[] = "RestaurarSoftIncremental()"; |
---|
1637 | |
---|
1638 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1639 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1640 | infoDebug(msglog); |
---|
1641 | } |
---|
1642 | dsk=copiaParametro("dsk",ptrTrama); |
---|
1643 | par=copiaParametro("par",ptrTrama); |
---|
1644 | idi=copiaParametro("idi",ptrTrama); |
---|
1645 | idf=copiaParametro("idf",ptrTrama); |
---|
1646 | ipr=copiaParametro("ipr",ptrTrama); |
---|
1647 | met=copiaParametro("met",ptrTrama); // Método de clonación 0= desde caché 1= desde repositorio |
---|
1648 | ifs=copiaParametro("ifs",ptrTrama); |
---|
1649 | nci=copiaParametro("nci",ptrTrama); |
---|
1650 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
1651 | ncf=copiaParametro("ncf",ptrTrama); |
---|
1652 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
1653 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
1654 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
1655 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
1656 | |
---|
1657 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1658 | ids=copiaParametro("ids",ptrTrama); |
---|
1659 | muestraMensaje(31,NULL); |
---|
1660 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1661 | sprintf(parametros,"%s %s %s %s %s %s %s%s%s%s %s %s",nfn,dsk,par,nci,ipr,ncf,bpi,cpc,bpc,nba,met,rti); |
---|
1662 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1663 | if(herror){ |
---|
1664 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1665 | errorInfo(modulo,msglog); |
---|
1666 | muestraMensaje(35,NULL); |
---|
1667 | } |
---|
1668 | else |
---|
1669 | muestraMensaje(34,NULL); |
---|
1670 | |
---|
1671 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1672 | initParametros(ptrTrama,0); |
---|
1673 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarSoftIncremental"); |
---|
1674 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idf); // Identificador de la imagen incremental (Forzada a idi) |
---|
1675 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
1676 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
1677 | |
---|
1678 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1679 | |
---|
1680 | liberaMemoria(nfn); |
---|
1681 | liberaMemoria(dsk); |
---|
1682 | liberaMemoria(par); |
---|
1683 | liberaMemoria(idi); |
---|
1684 | liberaMemoria(idf); |
---|
1685 | liberaMemoria(nci); |
---|
1686 | liberaMemoria(rti); |
---|
1687 | liberaMemoria(ncf); |
---|
1688 | liberaMemoria(ifs); |
---|
1689 | liberaMemoria(ipr); |
---|
1690 | liberaMemoria(met); |
---|
1691 | liberaMemoria(bpi); |
---|
1692 | liberaMemoria(cpc); |
---|
1693 | liberaMemoria(bpc); |
---|
1694 | liberaMemoria(nba); |
---|
1695 | liberaMemoria(ids); |
---|
1696 | |
---|
1697 | muestraMenu(); |
---|
1698 | |
---|
1699 | return(TRUE); |
---|
1700 | } |
---|
1701 | //______________________________________________________________________________________________________ |
---|
1702 | // Función: Configurar |
---|
1703 | // |
---|
1704 | // Descripción: |
---|
1705 | // Configura la tabla de particiones y formatea |
---|
1706 | // Parámetros: |
---|
1707 | // ptrTrama: contenido del mensaje |
---|
1708 | // Devuelve: |
---|
1709 | // TRUE: Si el proceso es correcto |
---|
1710 | // FALSE: En caso de ocurrir algún error |
---|
1711 | //______________________________________________________________________________________________________ |
---|
1712 | BOOLEAN Configurar(TRAMA* ptrTrama) |
---|
1713 | { |
---|
1714 | int lon; |
---|
1715 | char *nfn,*dsk,*cfg,*ids,msglog[LONSTD]; |
---|
1716 | char modulo[] = "Configurar()"; |
---|
1717 | |
---|
1718 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1719 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1720 | infoDebug(msglog); |
---|
1721 | } |
---|
1722 | |
---|
1723 | dsk=copiaParametro("dsk",ptrTrama); |
---|
1724 | cfg=copiaParametro("cfg",ptrTrama); |
---|
1725 | /* Sustituir caracteres */ |
---|
1726 | sustituir(cfg,'\n','$'); |
---|
1727 | sustituir(cfg,'\t','#'); |
---|
1728 | |
---|
1729 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1730 | ids=copiaParametro("ids",ptrTrama); |
---|
1731 | muestraMensaje(4,NULL); |
---|
1732 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1733 | sprintf(parametros,"%s %s %s",nfn,dsk,cfg); |
---|
1734 | |
---|
1735 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1736 | if(herror){ |
---|
1737 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1738 | errorInfo(modulo,msglog); |
---|
1739 | muestraMensaje(13,NULL); |
---|
1740 | } |
---|
1741 | else |
---|
1742 | muestraMensaje(14,NULL); |
---|
1743 | |
---|
1744 | cfg=LeeConfiguracion(); |
---|
1745 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
1746 | errorLog(modulo,36,FALSE); |
---|
1747 | return(FALSE); |
---|
1748 | } |
---|
1749 | |
---|
1750 | /* Envia respuesta de ejecución del comando*/ |
---|
1751 | initParametros(ptrTrama,0); |
---|
1752 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Configurar"); |
---|
1753 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
1754 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1755 | |
---|
1756 | liberaMemoria(dsk); |
---|
1757 | liberaMemoria(cfg); |
---|
1758 | liberaMemoria(nfn); |
---|
1759 | liberaMemoria(ids); |
---|
1760 | |
---|
1761 | muestraMenu(); |
---|
1762 | |
---|
1763 | return(TRUE); |
---|
1764 | } |
---|
1765 | // ________________________________________________________________________________________________________ |
---|
1766 | // Función: InventarioHardware |
---|
1767 | // |
---|
1768 | // Descripción: |
---|
1769 | // Envia al servidor el nombre del archivo de inventario de su hardware para posteriormente |
---|
1770 | // esperar que éste lo solicite y enviarlo por la red. |
---|
1771 | // Parámetros: |
---|
1772 | // ptrTrama: contenido del mensaje |
---|
1773 | // Devuelve: |
---|
1774 | // TRUE: Si el proceso es correcto |
---|
1775 | // FALSE: En caso de ocurrir algún error |
---|
1776 | //______________________________________________________________________________________________________ |
---|
1777 | BOOLEAN InventarioHardware(TRAMA* ptrTrama) |
---|
1778 | { |
---|
1779 | int lon; |
---|
1780 | SOCKET socket_c; |
---|
1781 | char *nfn,*ids,msglog[LONSTD],hrdsrc[LONPRM],hrddst[LONPRM]; |
---|
1782 | char modulo[] = "InventarioHardware()"; |
---|
1783 | |
---|
1784 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1785 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1786 | infoDebug(msglog); |
---|
1787 | } |
---|
1788 | |
---|
1789 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1790 | ids=copiaParametro("ids",ptrTrama); |
---|
1791 | muestraMensaje(6,NULL); |
---|
1792 | |
---|
1793 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1794 | sprintf(hrdsrc,"/tmp/Chrd-%s",IPlocal); // Nombre que tendra el archivo de inventario |
---|
1795 | sprintf(parametros,"%s %s",nfn,hrdsrc); |
---|
1796 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1797 | if(herror){ |
---|
1798 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1799 | errorInfo(modulo,msglog); |
---|
1800 | muestraMensaje(18,NULL); |
---|
1801 | } |
---|
1802 | else{ |
---|
1803 | /* Envía fichero de inventario al servidor */ |
---|
1804 | sprintf(hrddst,"/tmp/Shrd-%s",IPlocal); // Nombre que tendra el archivo en el Servidor |
---|
1805 | initParametros(ptrTrama,0); |
---|
1806 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",hrddst); |
---|
1807 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
1808 | liberaMemoria(nfn); |
---|
1809 | liberaMemoria(ids); |
---|
1810 | errorLog(modulo,42,FALSE); |
---|
1811 | return(FALSE); |
---|
1812 | } |
---|
1813 | /* Espera señal para comenzar el envío */ |
---|
1814 | liberaMemoria(ptrTrama); |
---|
1815 | recibeFlag(&socket_c,ptrTrama); |
---|
1816 | /* Envía archivo */ |
---|
1817 | if(!sendArchivo(&socket_c,hrdsrc)){ |
---|
1818 | errorLog(modulo,57, FALSE); |
---|
1819 | herror=12; // Error de envío de fichero por la red |
---|
1820 | } |
---|
1821 | close(socket_c); |
---|
1822 | muestraMensaje(17,NULL); |
---|
1823 | } |
---|
1824 | |
---|
1825 | /* Envia respuesta de ejecución de la función de interface */ |
---|
1826 | initParametros(ptrTrama,0); |
---|
1827 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioHardware"); |
---|
1828 | lon+=sprintf(ptrTrama->parametros+lon,"hrd=%s\r",hrddst); |
---|
1829 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1830 | liberaMemoria(nfn); |
---|
1831 | liberaMemoria(ids); |
---|
1832 | |
---|
1833 | muestraMenu(); |
---|
1834 | |
---|
1835 | return(TRUE); |
---|
1836 | } |
---|
1837 | // ________________________________________________________________________________________________________ |
---|
1838 | // Función: InventarioSoftware |
---|
1839 | // |
---|
1840 | // Descripción: |
---|
1841 | // Crea el inventario software de un sistema operativo instalado en una partición. |
---|
1842 | // Parámetros: |
---|
1843 | // ptrTrama: contenido del mensaje |
---|
1844 | // Devuelve: |
---|
1845 | // TRUE: Si el proceso es correcto |
---|
1846 | // FALSE: En caso de ocurrir algún error |
---|
1847 | //______________________________________________________________________________________________________ |
---|
1848 | BOOLEAN InventarioSoftware(TRAMA* ptrTrama) |
---|
1849 | { |
---|
1850 | char *nfn,*ids,msglog[LONSTD]; |
---|
1851 | char modulo[] = "InventarioSoftware()"; |
---|
1852 | |
---|
1853 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1854 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1855 | infoDebug(msglog); |
---|
1856 | } |
---|
1857 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1858 | ids=copiaParametro("ids",ptrTrama); |
---|
1859 | muestraMensaje(7,NULL); |
---|
1860 | InventariandoSoftware(ptrTrama,TRUE,nfn); |
---|
1861 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1862 | liberaMemoria(nfn); |
---|
1863 | liberaMemoria(ids); |
---|
1864 | muestraMenu(); |
---|
1865 | return(TRUE); |
---|
1866 | } |
---|
1867 | // ________________________________________________________________________________________________________ |
---|
1868 | // |
---|
1869 | // Función: InventariandoSoftware |
---|
1870 | // |
---|
1871 | // Descripción: |
---|
1872 | // Envia al servidor el nombre del archivo de inventario de su software para posteriormente |
---|
1873 | // esperar que éste lo solicite y enviarlo por la red. |
---|
1874 | // Parámetros: |
---|
1875 | // ptrTrama: contenido del mensaje |
---|
1876 | // sw: switch que indica si la función es llamada por el comando InventarioSoftware(true) o CrearImagen(false) |
---|
1877 | // nfn: Nombre de la función del Interface que implementa el comando |
---|
1878 | // Devuelve: |
---|
1879 | // TRUE: Si el proceso es correcto |
---|
1880 | // FALSE: En caso de ocurrir algún error |
---|
1881 | //______________________________________________________________________________________________________ |
---|
1882 | BOOLEAN InventariandoSoftware(TRAMA* ptrTrama,BOOLEAN sw,char *nfn) |
---|
1883 | { |
---|
1884 | int lon; |
---|
1885 | SOCKET socket_c; |
---|
1886 | char *dsk,*par,msglog[LONSTD],sftsrc[LONPRM],sftdst[LONPRM]; |
---|
1887 | char modulo[] = "InventariandoSoftware()"; |
---|
1888 | |
---|
1889 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
1890 | par=copiaParametro("par",ptrTrama); |
---|
1891 | |
---|
1892 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1893 | sprintf(sftsrc,"/tmp/CSft-%s-%s",IPlocal,par); // Nombre que tendra el archivo de inventario |
---|
1894 | sprintf(parametros,"%s %s %s %s",nfn,dsk,par,sftsrc); |
---|
1895 | |
---|
1896 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1897 | herror=0; |
---|
1898 | if(herror){ |
---|
1899 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1900 | errorInfo(modulo,msglog); |
---|
1901 | muestraMensaje(20,NULL); |
---|
1902 | } |
---|
1903 | else{ |
---|
1904 | /* Envía fichero de inventario al servidor */ |
---|
1905 | sprintf(sftdst,"/tmp/Ssft-%s-%s",IPlocal,par); // Nombre que tendra el archivo en el Servidor |
---|
1906 | initParametros(ptrTrama,0); |
---|
1907 | |
---|
1908 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",sftdst); |
---|
1909 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
1910 | errorLog(modulo,42,FALSE); |
---|
1911 | liberaMemoria(dsk); |
---|
1912 | liberaMemoria(par); |
---|
1913 | return(FALSE); |
---|
1914 | } |
---|
1915 | /* Espera señal para comenzar el envío */ |
---|
1916 | liberaMemoria(ptrTrama); |
---|
1917 | if(!recibeFlag(&socket_c,ptrTrama)){ |
---|
1918 | errorLog(modulo,17,FALSE); |
---|
1919 | } |
---|
1920 | /* Envía archivo */ |
---|
1921 | if(!sendArchivo(&socket_c,sftsrc)){ |
---|
1922 | errorLog(modulo,57, FALSE); |
---|
1923 | herror=12; // Error de envío de fichero por la red |
---|
1924 | } |
---|
1925 | close(socket_c); |
---|
1926 | muestraMensaje(19,NULL); |
---|
1927 | } |
---|
1928 | initParametros(ptrTrama,0); |
---|
1929 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioSoftware"); |
---|
1930 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); |
---|
1931 | lon+=sprintf(ptrTrama->parametros+lon,"sft=%s\r",sftdst); |
---|
1932 | if(!sw) |
---|
1933 | respuestaEjecucionComando(ptrTrama,herror,"0"); |
---|
1934 | |
---|
1935 | liberaMemoria(dsk); |
---|
1936 | liberaMemoria(par); |
---|
1937 | return(TRUE); |
---|
1938 | } |
---|
1939 | // ________________________________________________________________________________________________________ |
---|
1940 | // Función: EjecutarScript |
---|
1941 | // |
---|
1942 | // Descripción: |
---|
1943 | // Ejecuta código de script |
---|
1944 | // Parámetros: |
---|
1945 | // ptrTrama: contenido del mensaje |
---|
1946 | // Devuelve: |
---|
1947 | // TRUE: Si el proceso es correcto |
---|
1948 | // FALSE: En caso de ocurrir algún error |
---|
1949 | //______________________________________________________________________________________________________ |
---|
1950 | BOOLEAN EjecutarScript(TRAMA* ptrTrama) |
---|
1951 | { |
---|
1952 | int lon; |
---|
1953 | char *nfn,*aux,*ids,*scp,*cfg,msglog[LONSTD]; |
---|
1954 | char modulo[] = "EjecutarScript()"; |
---|
1955 | |
---|
1956 | if (ndebug>=DEBUG_MAXIMO) { |
---|
1957 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
1958 | infoDebug(msglog); |
---|
1959 | } |
---|
1960 | aux=copiaParametro("scp",ptrTrama); |
---|
1961 | scp=URLDecode(aux); |
---|
1962 | muestraMensaje(8,NULL); |
---|
1963 | /* Nombre del archivo de script */ |
---|
1964 | char filescript[LONPRM]; |
---|
1965 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
1966 | escribeArchivo(filescript,scp); |
---|
1967 | nfn=copiaParametro("nfn",ptrTrama); |
---|
1968 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
1969 | sprintf(parametros,"%s %s",nfn,filescript); |
---|
1970 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
1971 | if(herror){ |
---|
1972 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
1973 | errorInfo(modulo,msglog); |
---|
1974 | muestraMensaje(21,NULL); |
---|
1975 | } |
---|
1976 | else |
---|
1977 | muestraMensaje(22,NULL); |
---|
1978 | |
---|
1979 | // Toma configuración de particiones |
---|
1980 | cfg=LeeConfiguracion(); |
---|
1981 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
1982 | errorLog(modulo,36,FALSE); |
---|
1983 | herror=36; |
---|
1984 | } |
---|
1985 | |
---|
1986 | ids=copiaParametro("ids",ptrTrama); |
---|
1987 | |
---|
1988 | //herror=ejecutarCodigoBash(scp); |
---|
1989 | initParametros(ptrTrama,0); |
---|
1990 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_EjecutarScript"); |
---|
1991 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
1992 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
1993 | |
---|
1994 | liberaMemoria(nfn); |
---|
1995 | liberaMemoria(ids); |
---|
1996 | liberaMemoria(aux); |
---|
1997 | liberaMemoria(scp); |
---|
1998 | liberaMemoria(cfg); |
---|
1999 | |
---|
2000 | muestraMenu(); |
---|
2001 | |
---|
2002 | return(TRUE); |
---|
2003 | } |
---|
2004 | //______________________________________________________________________________________________________ |
---|
2005 | // Función: respuestaEjecucionComando |
---|
2006 | // |
---|
2007 | // Descripción: |
---|
2008 | // Envia una respuesta a una ejecucion de comando al servidor de Administración |
---|
2009 | // Parámetros: |
---|
2010 | // - ptrTrama: contenido del mensaje |
---|
2011 | // - res: Resultado de la ejecución (Código de error devuelto por el script ejecutado) |
---|
2012 | // - ids: Identificador de la sesion (En caso de no haber seguimiento es NULO) |
---|
2013 | // Devuelve: |
---|
2014 | // TRUE: Si el proceso es correcto |
---|
2015 | // FALSE: En caso de ocurrir algún error |
---|
2016 | // ________________________________________________________________________________________________________ |
---|
2017 | BOOLEAN respuestaEjecucionComando(TRAMA* ptrTrama,int res,char *ids) |
---|
2018 | { |
---|
2019 | int lon; |
---|
2020 | SOCKET socket_c; |
---|
2021 | char modulo[] = "respuestaEjecucionComando()"; |
---|
2022 | |
---|
2023 | lon=strlen(ptrTrama->parametros); |
---|
2024 | if(ids){ // Existe seguimiento |
---|
2025 | lon+=sprintf(ptrTrama->parametros+lon,"ids=%s\r",ids); // Añade identificador de la sesión |
---|
2026 | } |
---|
2027 | if (res==0){ // Resultado satisfactorio |
---|
2028 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","1"); |
---|
2029 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",""); |
---|
2030 | } |
---|
2031 | else{ // Algún error |
---|
2032 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","2"); |
---|
2033 | if(res>MAXERRORSCRIPT) |
---|
2034 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s (Error de script:%d)\r",tbErroresScripts[0],res);// Descripción del error |
---|
2035 | else |
---|
2036 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",tbErroresScripts[res]);// Descripción del error |
---|
2037 | } |
---|
2038 | if(!(enviaMensajeServidor(&socket_c,ptrTrama,MSG_NOTIFICACION))){ |
---|
2039 | errorLog(modulo,44,FALSE); |
---|
2040 | return(FALSE); |
---|
2041 | } |
---|
2042 | |
---|
2043 | close(socket_c); |
---|
2044 | return(TRUE); |
---|
2045 | } |
---|
2046 | // ________________________________________________________________________________________________________ |
---|
2047 | // Función: gestionaTrama |
---|
2048 | // |
---|
2049 | // Descripción: |
---|
2050 | // Procesa las tramas recibidas. |
---|
2051 | // Parametros: |
---|
2052 | // ptrTrama: contenido del mensaje |
---|
2053 | // Devuelve: |
---|
2054 | // TRUE: Si el proceso es correcto |
---|
2055 | // FALSE: En caso de ocurrir algún error |
---|
2056 | // ________________________________________________________________________________________________________ |
---|
2057 | BOOLEAN gestionaTrama(TRAMA *ptrTrama) |
---|
2058 | { |
---|
2059 | int i, res; |
---|
2060 | char *nfn; |
---|
2061 | char modulo[] = "gestionaTrama()"; |
---|
2062 | |
---|
2063 | INTROaFINCAD(ptrTrama); |
---|
2064 | nfn = copiaParametro("nfn", ptrTrama); // Toma nombre de función |
---|
2065 | for (i = 0; i < MAXIMAS_FUNCIONES; i++) { // Recorre funciones que procesan las tramas |
---|
2066 | res = strcmp(tbfuncionesClient[i].nf, nfn); |
---|
2067 | if (res == 0) { // Encontrada la función que procesa el mensaje |
---|
2068 | liberaMemoria(nfn); |
---|
2069 | return(tbfuncionesClient[i].fptr(ptrTrama)); // Invoca la función |
---|
2070 | } |
---|
2071 | } |
---|
2072 | |
---|
2073 | liberaMemoria(nfn); |
---|
2074 | |
---|
2075 | /* Sólo puede ser un comando personalizado |
---|
2076 | if (ptrTrama->tipo==MSG_COMANDO) |
---|
2077 | return(Comando(ptrTrama)); |
---|
2078 | */ |
---|
2079 | errorLog(modulo, 18, FALSE); |
---|
2080 | return (FALSE); |
---|
2081 | } |
---|
2082 | //________________________________________________________________________________________________________ |
---|
2083 | // Función: ejecutaArchivo |
---|
2084 | // |
---|
2085 | // Descripción: |
---|
2086 | // Ejecuta los comando contenido en un archivo (cada comando y sus parametros separados por un |
---|
2087 | // salto de linea. |
---|
2088 | // Parámetros: |
---|
2089 | // filecmd: Nombre del archivo de comandos |
---|
2090 | // ptrTrama: Puntero a una estructura TRAMA usada en las comunicaciones por red (No debe ser NULL) |
---|
2091 | // Devuelve: |
---|
2092 | // TRUE: Si el proceso es correcto |
---|
2093 | // FALSE: En caso de ocurrir algún error |
---|
2094 | //________________________________________________________________________________________________________ |
---|
2095 | BOOLEAN ejecutaArchivo(char* filecmd,TRAMA *ptrTrama) |
---|
2096 | { |
---|
2097 | char* buffer,*lineas[MAXIMAS_LINEAS]; |
---|
2098 | int i,numlin; |
---|
2099 | char modulo[] = "ejecutaArchivo()"; |
---|
2100 | |
---|
2101 | buffer=leeArchivo(filecmd); |
---|
2102 | if(buffer){ |
---|
2103 | numlin = splitCadena(lineas, buffer, '@'); |
---|
2104 | initParametros(ptrTrama,0); |
---|
2105 | for (i = 0; i < numlin; i++) { |
---|
2106 | if(strlen(lineas[i])>0){ |
---|
2107 | strcpy(ptrTrama->parametros,lineas[i]); |
---|
2108 | strcat(ptrTrama->parametros,"\rMCDJ@"); // Fin de trama |
---|
2109 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
2110 | errorLog(modulo,39,FALSE); |
---|
2111 | //return(FALSE); |
---|
2112 | } |
---|
2113 | } |
---|
2114 | } |
---|
2115 | } |
---|
2116 | liberaMemoria(buffer); |
---|
2117 | return(TRUE); |
---|
2118 | } |
---|
2119 | //______________________________________________________________________________________________________ |
---|
2120 | // Función: enviaMensajeServidor |
---|
2121 | // |
---|
2122 | // Descripción: |
---|
2123 | // Envia un mensaje al servidor de Administración |
---|
2124 | // Parámetros: |
---|
2125 | // - socket_c: (Salida) Socket utilizado para el envío |
---|
2126 | // - ptrTrama: contenido del mensaje |
---|
2127 | // - tipo: Tipo de mensaje |
---|
2128 | // C=Comando, N=Respuesta a un comando, P=Peticion,R=Respuesta a una petición, I=Informacion |
---|
2129 | // Devuelve: |
---|
2130 | // TRUE: Si el proceso es correcto |
---|
2131 | // FALSE: En caso de ocurrir algún error |
---|
2132 | // ________________________________________________________________________________________________________ |
---|
2133 | BOOLEAN enviaMensajeServidor(SOCKET *socket_c,TRAMA *ptrTrama,char tipo) |
---|
2134 | { |
---|
2135 | int lon; |
---|
2136 | char modulo[] = "enviaMensajeServidor()"; |
---|
2137 | |
---|
2138 | *socket_c=abreConexion(); |
---|
2139 | if(*socket_c==INVALID_SOCKET){ |
---|
2140 | errorLog(modulo,38,FALSE); // Error de conexión con el servidor |
---|
2141 | return(FALSE); |
---|
2142 | } |
---|
2143 | ptrTrama->arroba='@'; // Cabecera de la trama |
---|
2144 | strncpy(ptrTrama->identificador,"JMMLCAMDJ_MCDJ",14); // identificador de la trama |
---|
2145 | ptrTrama->tipo=tipo; // Tipo de mensaje |
---|
2146 | lon=strlen(ptrTrama->parametros); // Compone la trama |
---|
2147 | lon+=sprintf(ptrTrama->parametros+lon,"iph=%s\r",IPlocal); // Ip del ordenador |
---|
2148 | lon+=sprintf(ptrTrama->parametros+lon,"ido=%s\r",idordenador); // Identificador del ordenador |
---|
2149 | lon+=sprintf(ptrTrama->parametros+lon,"npc=%s\r",nombreordenador); // Nombre del ordenador |
---|
2150 | lon+=sprintf(ptrTrama->parametros+lon,"idc=%s\r",idcentro); // Identificador del centro |
---|
2151 | lon+=sprintf(ptrTrama->parametros+lon,"ida=%s\r",idaula); // Identificador del aula |
---|
2152 | |
---|
2153 | if (!mandaTrama(socket_c,ptrTrama)) { |
---|
2154 | errorLog(modulo,26,FALSE); |
---|
2155 | return (FALSE); |
---|
2156 | } |
---|
2157 | return(TRUE); |
---|
2158 | } |
---|
2159 | // ******************************************************************************************************** |
---|
2160 | // PROGRAMA PRINCIPAL (CLIENTE) |
---|
2161 | // ******************************************************************************************************** |
---|
2162 | int main(int argc, char *argv[]) |
---|
2163 | { |
---|
2164 | TRAMA *ptrTrama; |
---|
2165 | char modulo[] = "main()"; |
---|
2166 | |
---|
2167 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA)); |
---|
2168 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas |
---|
2169 | errorLog(modulo, 3, FALSE); |
---|
2170 | exit(EXIT_FAILURE); |
---|
2171 | } |
---|
2172 | /*-------------------------------------------------------------------------------------------------------- |
---|
2173 | Validación de parámetros de ejecución y fichero de configuración |
---|
2174 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2175 | if (!validacionParametros(argc, argv,3)) // Valida parámetros de ejecución |
---|
2176 | exit(EXIT_FAILURE); |
---|
2177 | |
---|
2178 | if (!tomaConfiguracion(szPathFileCfg)) // Toma parametros de configuración |
---|
2179 | exit(EXIT_FAILURE); |
---|
2180 | /*-------------------------------------------------------------------------------------------------------- |
---|
2181 | Carga catálogo de funciones que procesan las tramas |
---|
2182 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2183 | int cf = 0; |
---|
2184 | |
---|
2185 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_AutoexecCliente"); |
---|
2186 | tbfuncionesClient[cf++].fptr = &RESPUESTA_AutoexecCliente; |
---|
2187 | |
---|
2188 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_InclusionCliente"); |
---|
2189 | tbfuncionesClient[cf++].fptr = &RESPUESTA_InclusionCliente; |
---|
2190 | |
---|
2191 | strcpy(tbfuncionesClient[cf].nf, "NoComandosPtes"); |
---|
2192 | tbfuncionesClient[cf++].fptr = &NoComandosPtes; |
---|
2193 | |
---|
2194 | strcpy(tbfuncionesClient[cf].nf, "Actualizar"); |
---|
2195 | tbfuncionesClient[cf++].fptr = &Actualizar; |
---|
2196 | |
---|
2197 | strcpy(tbfuncionesClient[cf].nf, "Purgar"); |
---|
2198 | tbfuncionesClient[cf++].fptr = &Purgar; |
---|
2199 | |
---|
2200 | strcpy(tbfuncionesClient[cf].nf, "ConsolaRemota"); |
---|
2201 | tbfuncionesClient[cf++].fptr = &ConsolaRemota; |
---|
2202 | |
---|
2203 | strcpy(tbfuncionesClient[cf].nf, "Sondeo"); |
---|
2204 | tbfuncionesClient[cf++].fptr = &Sondeo; |
---|
2205 | |
---|
2206 | strcpy(tbfuncionesClient[cf].nf, "Arrancar"); |
---|
2207 | tbfuncionesClient[cf++].fptr = &Arrancar; |
---|
2208 | |
---|
2209 | strcpy(tbfuncionesClient[cf].nf, "Apagar"); |
---|
2210 | tbfuncionesClient[cf++].fptr = &Apagar; |
---|
2211 | |
---|
2212 | strcpy(tbfuncionesClient[cf].nf, "Reiniciar"); |
---|
2213 | tbfuncionesClient[cf++].fptr = &Reiniciar; |
---|
2214 | |
---|
2215 | strcpy(tbfuncionesClient[cf].nf, "IniciarSesion"); |
---|
2216 | tbfuncionesClient[cf++].fptr = &IniciarSesion; |
---|
2217 | |
---|
2218 | strcpy(tbfuncionesClient[cf].nf, "CrearImagen"); |
---|
2219 | tbfuncionesClient[cf++].fptr = &CrearImagen; |
---|
2220 | |
---|
2221 | strcpy(tbfuncionesClient[cf].nf, "CrearImagenBasica"); |
---|
2222 | tbfuncionesClient[cf++].fptr = &CrearImagenBasica; |
---|
2223 | |
---|
2224 | strcpy(tbfuncionesClient[cf].nf, "CrearSoftIncremental"); |
---|
2225 | tbfuncionesClient[cf++].fptr = &CrearSoftIncremental; |
---|
2226 | |
---|
2227 | strcpy(tbfuncionesClient[cf].nf, "RestaurarImagen"); |
---|
2228 | tbfuncionesClient[cf++].fptr = &RestaurarImagen; |
---|
2229 | |
---|
2230 | strcpy(tbfuncionesClient[cf].nf, "RestaurarImagenBasica"); |
---|
2231 | tbfuncionesClient[cf++].fptr = &RestaurarImagenBasica; |
---|
2232 | |
---|
2233 | strcpy(tbfuncionesClient[cf].nf, "RestaurarSoftIncremental"); |
---|
2234 | tbfuncionesClient[cf++].fptr = &RestaurarSoftIncremental; |
---|
2235 | |
---|
2236 | |
---|
2237 | strcpy(tbfuncionesClient[cf].nf, "Configurar"); |
---|
2238 | tbfuncionesClient[cf++].fptr = &Configurar; |
---|
2239 | |
---|
2240 | strcpy(tbfuncionesClient[cf].nf, "EjecutarScript"); |
---|
2241 | tbfuncionesClient[cf++].fptr = &EjecutarScript; |
---|
2242 | |
---|
2243 | strcpy(tbfuncionesClient[cf].nf, "InventarioHardware"); |
---|
2244 | tbfuncionesClient[cf++].fptr = &InventarioHardware; |
---|
2245 | |
---|
2246 | strcpy(tbfuncionesClient[cf].nf, "InventarioSoftware"); |
---|
2247 | tbfuncionesClient[cf++].fptr = &InventarioSoftware; |
---|
2248 | |
---|
2249 | /*-------------------------------------------------------------------------------------------------------- |
---|
2250 | Toma dirección IP del cliente |
---|
2251 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2252 | if(!tomaIPlocal()){ // Error al recuperar la IP local |
---|
2253 | errorLog(modulo,0,FALSE); |
---|
2254 | exit(EXIT_FAILURE); |
---|
2255 | } |
---|
2256 | /*-------------------------------------------------------------------------------------------------------- |
---|
2257 | Inicio de sesión |
---|
2258 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2259 | infoLog(1); // Inicio de sesión |
---|
2260 | infoLog(3); // Abriendo sesión en el servidor de Administración; |
---|
2261 | /*-------------------------------------------------------------------------------------------------------- |
---|
2262 | Inclusión del cliente en el sistema |
---|
2263 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2264 | if(!inclusionCliente(ptrTrama)){ // Ha habido algún problema al abrir sesión |
---|
2265 | errorLog(modulo,0,FALSE); |
---|
2266 | exit(EXIT_FAILURE); |
---|
2267 | } |
---|
2268 | infoLog(4); // Cliente iniciado |
---|
2269 | |
---|
2270 | /*-------------------------------------------------------------------------------------------------------- |
---|
2271 | Procesamiento de la cache |
---|
2272 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2273 | infoLog(23); // Abriendo sesión en el servidor de Administración; |
---|
2274 | if(!cuestionCache(cache)){ |
---|
2275 | errorLog(modulo,0,FALSE); |
---|
2276 | exit(EXIT_FAILURE); |
---|
2277 | } |
---|
2278 | /*-------------------------------------------------------------------------------------------------------- |
---|
2279 | Ejecución del autoexec |
---|
2280 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2281 | if(atoi(idproautoexec)>0){ // Ejecución de procedimiento Autoexec |
---|
2282 | infoLog(5); |
---|
2283 | if(!autoexecCliente(ptrTrama)){ // Ejecución fichero autoexec |
---|
2284 | errorLog(modulo,0,FALSE); |
---|
2285 | exit(EXIT_FAILURE); |
---|
2286 | } |
---|
2287 | } |
---|
2288 | /*-------------------------------------------------------------------------------------------------------- |
---|
2289 | Comandos pendientes |
---|
2290 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2291 | infoLog(6); // Procesa comandos pendientes |
---|
2292 | if(!comandosPendientes(ptrTrama)){ // Ejecución de acciones pendientes |
---|
2293 | errorLog(modulo,0,FALSE); |
---|
2294 | exit(EXIT_FAILURE); |
---|
2295 | } |
---|
2296 | infoLog(7); // Acciones pendientes procesadas |
---|
2297 | /*-------------------------------------------------------------------------------------------------------- |
---|
2298 | Bucle de recepción de comandos |
---|
2299 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2300 | muestraMenu(); |
---|
2301 | procesaComandos(ptrTrama); // Bucle para procesar comandos interactivos |
---|
2302 | /*-------------------------------------------------------------------------------------------------------- |
---|
2303 | Fin de la sesión |
---|
2304 | ---------------------------------------------------------------------------------------------------------*/ |
---|
2305 | exit(EXIT_SUCCESS); |
---|
2306 | } |
---|