[3ec149c] | 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) { |
---|
[4329e85] | 86 | liberaMemoria(buffer); |
---|
[3ec149c] | 87 | errorLog(modulo,4, FALSE); // Falta parámetro SERVIDORADM |
---|
| 88 | return (FALSE); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if (puerto[0] == CHARNULL) { |
---|
[4329e85] | 92 | liberaMemoria(buffer); |
---|
[3ec149c] | 93 | errorLog(modulo,5, FALSE); // Falta parámetro PUERTO |
---|
| 94 | return (FALSE); |
---|
| 95 | } |
---|
| 96 | if (pathinterface[0] == CHARNULL) { |
---|
[4329e85] | 97 | liberaMemoria(buffer); |
---|
[3ec149c] | 98 | errorLog(modulo,56, FALSE); // Falta parámetro PATHINTERFACE |
---|
| 99 | return (FALSE); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if (urlmenu[0] == CHARNULL) { |
---|
[4329e85] | 103 | liberaMemoria(buffer); |
---|
[3ec149c] | 104 | errorLog(modulo,89, FALSE); // Falta parámetro URLMENU |
---|
| 105 | return (FALSE); |
---|
| 106 | } |
---|
| 107 | if (urlmsg[0] == CHARNULL) { |
---|
[4329e85] | 108 | liberaMemoria(buffer); |
---|
[3ec149c] | 109 | errorLog(modulo,90, FALSE); // Falta parámetro URLMSG |
---|
| 110 | return (FALSE); |
---|
| 111 | } |
---|
[4329e85] | 112 | liberaMemoria(buffer); |
---|
[3ec149c] | 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; |
---|
[12a35e7] | 249 | char buffer[LONBLK]; // Buffer de lectura de fichero |
---|
[3ec149c] | 250 | pipe (descr); |
---|
| 251 | int i,nargs,resul; |
---|
[eb093a4] | 252 | int lon; // Longitud de cadena |
---|
| 253 | char msglog[LONSUC]; // Mensaje de registro de sucesos |
---|
[3eca7c1] | 254 | char *argumentos[MAXARGS]; |
---|
[3ec149c] | 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) { |
---|
[eb093a4] | 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 | { |
---|
[3a254b9] | 277 | strncat (msglog, argumentos[i], LONSUC - lon - 4); |
---|
[eb093a4] | 278 | strcat (msglog, "..."); |
---|
| 279 | } |
---|
[3ec149c] | 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]); |
---|
[3eca7c1] | 313 | bytesleidos = read (descr[LEER], buffer, LONBLK-1); |
---|
[3ec149c] | 314 | while(bytesleidos>0){ |
---|
| 315 | if(salida!=(char*)NULL){ // Si se solicita retorno de información... |
---|
| 316 | buffer[bytesleidos]='\0'; |
---|
[3eca7c1] | 317 | // Error si se supera el tamaño máximo de cadena de salida. |
---|
[3ec149c] | 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 | } |
---|
[3eca7c1] | 327 | bytesleidos = read (descr[LEER], buffer, LONBLK-1); |
---|
[3ec149c] | 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){ |
---|
[eb093a4] | 345 | // Truncar la cadena si es mayor que el tamaño de la línea de log. |
---|
[3eca7c1] | 346 | strcpy(msglog,"Informacion devuelta "); |
---|
[eb093a4] | 347 | lon = strlen (msglog); |
---|
| 348 | if (lon + strlen (salida) < LONSUC) { |
---|
| 349 | strcat (msglog, salida); |
---|
| 350 | } |
---|
| 351 | else |
---|
| 352 | { |
---|
[9ef26af] | 353 | strncat (msglog, salida, LONSUC-lon-4); |
---|
[eb093a4] | 354 | strcat (msglog, "..."); |
---|
[3eca7c1] | 355 | } |
---|
[3ec149c] | 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 | |
---|
[4329e85] | 398 | // Para debug |
---|
| 399 | //strcpy(IPlocal,"10.1.15.203"); |
---|
| 400 | //return(TRUE); |
---|
| 401 | |
---|
[3ec149c] | 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 | { |
---|
[4329e85] | 423 | return(TRUE); |
---|
| 424 | //>>>>>>>>>>>>>>>>>>>>>>>>>> |
---|
[3ec149c] | 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; |
---|
[2beed29] | 454 | char* argumentos[4]; |
---|
[3ec149c] | 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"); |
---|
[2beed29] | 464 | sprintf(parametros,"browser -qws %s",url); |
---|
[3ec149c] | 465 | |
---|
| 466 | splitCadena(argumentos,parametros,' '); // Crea matriz de los argumentos del scripts |
---|
[2beed29] | 467 | argumentos[3]=NULL; |
---|
[3ec149c] | 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 | { |
---|
[4329e85] | 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 | } |
---|
[3ec149c] | 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 | { |
---|
[eb093a4] | 532 | int lon; // Longitud de cadena |
---|
| 533 | char msglog[LONSUC]; // Mensaje de registro de sucesos |
---|
| 534 | char *cfg; // Datos de configuración |
---|
[3ec149c] | 535 | SOCKET socket_c; |
---|
| 536 | char modulo[] = "inclusionCliente()"; |
---|
| 537 | |
---|
[9ef26af] | 538 | cfg=LeeConfiguracion(); |
---|
| 539 | |
---|
[3ec149c] | 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) { |
---|
[eb093a4] | 546 | // Truncar la cadena si es mayor que el tamaño de la línea de log. |
---|
[9ef26af] | 547 | sprintf(msglog, "%s", tbMensajes[14]); |
---|
[eb093a4] | 548 | lon = strlen (msglog); |
---|
| 549 | if (lon + strlen (cfg) < LONSUC) { |
---|
| 550 | strcat (msglog, cfg); |
---|
| 551 | } |
---|
| 552 | else |
---|
| 553 | { |
---|
[3a254b9] | 554 | strncat (msglog, cfg, LONSUC - lon - 4); |
---|
[eb093a4] | 555 | strcat (msglog, "..."); |
---|
| 556 | } |
---|
[3ec149c] | 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 |
---|
[4329e85] | 562 | liberaMemoria(cfg); |
---|
| 563 | |
---|
[3ec149c] | 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 | } |
---|
[eeeb98a] | 573 | |
---|
[3ec149c] | 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 |
---|
[4329e85] | 602 | liberaMemoria(res); |
---|
[3ec149c] | 603 | errorLog(modulo,41,FALSE); |
---|
| 604 | return (FALSE); |
---|
| 605 | } |
---|
[4329e85] | 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 |
---|
[3ec149c] | 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 | |
---|
[b7728bd] | 633 | char* LeeConfiguracion() |
---|
[3ec149c] | 634 | { |
---|
| 635 | char* parametroscfg; |
---|
| 636 | char modulo[] = "LeeConfiguracion()"; |
---|
| 637 | |
---|
[b7728bd] | 638 | // Reservar memoria para los datos de cofiguración. |
---|
| 639 | parametroscfg=(char*)reservaMemoria(LONGITUD_SCRIPTSALIDA); |
---|
[3ec149c] | 640 | if(!parametroscfg){ |
---|
| 641 | errorLog(modulo,3,FALSE); |
---|
| 642 | return(NULL); |
---|
| 643 | } |
---|
[b7728bd] | 644 | // Ejecutar script y obtener datos. |
---|
[3ec149c] | 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 |
---|
[4329e85] | 649 | liberaMemoria(parametroscfg); |
---|
[3ec149c] | 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 |
---|
[4329e85] | 713 | liberaMemoria(res); |
---|
[3ec149c] | 714 | return (FALSE); |
---|
| 715 | } |
---|
[4329e85] | 716 | liberaMemoria(res); |
---|
| 717 | |
---|
[3ec149c] | 718 | nfl=copiaParametro("nfl",ptrTrama); |
---|
| 719 | initParametros(ptrTrama,0); |
---|
| 720 | sprintf(ptrTrama->parametros,"nfn=enviaArchivo\rnfl=%s\r",nfl); |
---|
[4329e85] | 721 | liberaMemoria(nfl); |
---|
| 722 | |
---|
[3ec149c] | 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 | } |
---|
[eeeb98a] | 775 | |
---|
[3ec149c] | 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 | { |
---|
[b7728bd] | 860 | char msglog[LONSTD]; // Mensaje de log |
---|
| 861 | char *cfg; // Cadena de datos de configuración |
---|
| 862 | int lon; // Longitud de cadena |
---|
[3ec149c] | 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 | } |
---|
[7224a0a] | 874 | |
---|
[b7728bd] | 875 | cfg=LeeConfiguracion(); |
---|
[7224a0a] | 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 | |
---|
[3ec149c] | 887 | muestraMenu(); |
---|
[7224a0a] | 888 | |
---|
[3ec149c] | 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; |
---|
[4329e85] | 958 | char *nfn,*scp,*aux,ecosrc[LONPRM],ecodst[LONPRM],msglog[LONSTD];; |
---|
[3ec149c] | 959 | char modulo[] = "ConsolaRemota()"; |
---|
| 960 | |
---|
| 961 | /* Nombre del archivo de script */ |
---|
| 962 | char filescript[LONPRM]; |
---|
| 963 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
[4329e85] | 964 | |
---|
| 965 | aux=copiaParametro("scp",ptrTrama); |
---|
| 966 | scp=URLDecode(aux); |
---|
[3ec149c] | 967 | escribeArchivo(filescript,scp); |
---|
[4329e85] | 968 | liberaMemoria(aux); |
---|
| 969 | liberaMemoria(scp); |
---|
| 970 | |
---|
| 971 | nfn=copiaParametro("nfn",ptrTrama); |
---|
[3ec149c] | 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 */ |
---|
[4329e85] | 990 | liberaMemoria(ptrTrama); |
---|
[3ec149c] | 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 | } |
---|
[4329e85] | 999 | liberaMemoria(nfn); |
---|
[3ec149c] | 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); |
---|
[4329e85] | 1036 | liberaMemoria(nfn); |
---|
| 1037 | liberaMemoria(ids); |
---|
[3ec149c] | 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); |
---|
[4329e85] | 1069 | liberaMemoria(ids); |
---|
[3ec149c] | 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); |
---|
[4329e85] | 1104 | liberaMemoria(nfn); |
---|
| 1105 | liberaMemoria(ids); |
---|
[3ec149c] | 1106 | errorInfo(modulo,msglog); |
---|
| 1107 | return(FALSE); |
---|
| 1108 | } |
---|
[4329e85] | 1109 | liberaMemoria(nfn); |
---|
| 1110 | liberaMemoria(ids); |
---|
[3ec149c] | 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); |
---|
[4329e85] | 1145 | liberaMemoria(nfn); |
---|
| 1146 | liberaMemoria(ids); |
---|
[3ec149c] | 1147 | errorInfo(modulo,msglog); |
---|
| 1148 | return(FALSE); |
---|
| 1149 | } |
---|
[4329e85] | 1150 | liberaMemoria(nfn); |
---|
| 1151 | liberaMemoria(ids); |
---|
[3ec149c] | 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,*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); |
---|
[179ccd2] | 1177 | par=copiaParametro("par",ptrTrama); |
---|
| 1178 | |
---|
[3ec149c] | 1179 | initParametros(ptrTrama,0); |
---|
| 1180 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_IniciarSesion"); |
---|
| 1181 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
[4329e85] | 1182 | liberaMemoria(ids); |
---|
[3ec149c] | 1183 | |
---|
| 1184 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1185 | sprintf(parametros,"%s %s",nfn,par); |
---|
[4329e85] | 1186 | liberaMemoria(par); |
---|
| 1187 | |
---|
[3ec149c] | 1188 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1189 | |
---|
| 1190 | if(herror){ |
---|
| 1191 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
[4329e85] | 1192 | liberaMemoria(nfn); |
---|
[3ec149c] | 1193 | errorInfo(modulo,msglog); |
---|
| 1194 | return(FALSE); |
---|
| 1195 | } |
---|
[4329e85] | 1196 | liberaMemoria(nfn); |
---|
[3ec149c] | 1197 | return(TRUE); |
---|
| 1198 | } |
---|
| 1199 | //______________________________________________________________________________________________________ |
---|
| 1200 | // Función: CrearImagen |
---|
| 1201 | // |
---|
| 1202 | // Descripción: |
---|
| 1203 | // Crea una imagen de una partición |
---|
| 1204 | // Parámetros: |
---|
| 1205 | // ptrTrama: contenido del mensaje |
---|
| 1206 | // Devuelve: |
---|
| 1207 | // TRUE: Si el proceso es correcto |
---|
| 1208 | // FALSE: En caso de ocurrir algún error |
---|
| 1209 | //______________________________________________________________________________________________________ |
---|
| 1210 | BOOLEAN CrearImagen(TRAMA* ptrTrama) |
---|
| 1211 | { |
---|
| 1212 | int lon; |
---|
| 1213 | char *nfn,*dsk,*par,*cpt,*idi,*ipr,*nci,*ids,msglog[LONSTD]; |
---|
| 1214 | char modulo[] = "CrearImagen()"; |
---|
| 1215 | |
---|
| 1216 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1217 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1218 | infoDebug(msglog); |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1222 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
| 1223 | cpt=copiaParametro("cpt",ptrTrama); // Código de la partición |
---|
| 1224 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
| 1225 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
| 1226 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
| 1227 | |
---|
| 1228 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1229 | ids=copiaParametro("ids",ptrTrama); |
---|
[eb9424f] | 1230 | muestraMensaje(7,NULL); |
---|
[4329e85] | 1231 | |
---|
[3ec149c] | 1232 | if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
| 1233 | muestraMensaje(2,NULL); |
---|
| 1234 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1235 | sprintf(parametros,"%s %s %s %s %s",nfn,dsk,par,nci,ipr); |
---|
| 1236 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1237 | if(herror){ |
---|
| 1238 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1239 | errorInfo(modulo,msglog); |
---|
| 1240 | muestraMensaje(10,NULL); |
---|
| 1241 | } |
---|
| 1242 | else |
---|
| 1243 | muestraMensaje(9,NULL); |
---|
| 1244 | } |
---|
| 1245 | else{ |
---|
| 1246 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1247 | errorInfo(modulo,msglog); |
---|
| 1248 | } |
---|
| 1249 | |
---|
| 1250 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1251 | initParametros(ptrTrama,0); |
---|
| 1252 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearImagen"); |
---|
| 1253 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1254 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición de donde se creó |
---|
| 1255 | lon+=sprintf(ptrTrama->parametros+lon,"cpt=%s\r",cpt); // Tipo o código de partición |
---|
| 1256 | lon+=sprintf(ptrTrama->parametros+lon,"ipr=%s\r",ipr); // Ip del repositorio donde se alojó |
---|
| 1257 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1258 | |
---|
| 1259 | liberaMemoria(dsk); |
---|
| 1260 | liberaMemoria(par); |
---|
| 1261 | liberaMemoria(cpt); |
---|
| 1262 | liberaMemoria(idi); |
---|
| 1263 | liberaMemoria(nci); |
---|
| 1264 | liberaMemoria(ipr); |
---|
| 1265 | liberaMemoria(nfn); |
---|
| 1266 | liberaMemoria(ids); |
---|
[380fe92] | 1267 | |
---|
| 1268 | muestraMenu(); |
---|
[4329e85] | 1269 | |
---|
| 1270 | return(TRUE); |
---|
| 1271 | } |
---|
| 1272 | //______________________________________________________________________________________________________ |
---|
| 1273 | // Función: CrearImagenBasica |
---|
| 1274 | // |
---|
| 1275 | // Descripción: |
---|
| 1276 | // Crea una imagen básica a traverś dela sincronización |
---|
| 1277 | // Parámetros: |
---|
| 1278 | // ptrTrama: contenido del mensaje |
---|
| 1279 | // |
---|
| 1280 | // FDevuelve: |
---|
| 1281 | // TRUE: Si el proceso es correcto |
---|
| 1282 | // FALSE: En caso de ocurrir algún error |
---|
| 1283 | //______________________________________________________________________________________________________ |
---|
| 1284 | BOOLEAN CrearImagenBasica(TRAMA* ptrTrama) |
---|
| 1285 | { |
---|
| 1286 | int lon; |
---|
[6a830ffa] | 1287 | char *nfn,*dsk,*par,*cpt,*idi,*nci,*rti,*ipr,*whl,*eli,*cmp,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
[4329e85] | 1288 | char modulo[] = "CrearImagenBasica()"; |
---|
| 1289 | |
---|
| 1290 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1291 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1292 | infoDebug(msglog); |
---|
| 1293 | } |
---|
| 1294 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1295 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1296 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
| 1297 | cpt=copiaParametro("cpt",ptrTrama); // Tipo de partición |
---|
| 1298 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
| 1299 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
| 1300 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
| 1301 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
[6a830ffa] | 1302 | |
---|
| 1303 | whl=copiaParametro("whl",ptrTrama); // Envío del fichero completo si hay diferencias |
---|
| 1304 | eli=copiaParametro("eli",ptrTrama); // Elimiar archivos en destino que no estén en origen |
---|
| 1305 | cmp=copiaParametro("cmp",ptrTrama); // Comprimir antes de enviar |
---|
| 1306 | |
---|
[4329e85] | 1307 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
| 1308 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
| 1309 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
| 1310 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
| 1311 | |
---|
| 1312 | //muestraMensaje(7,NULL); // Creando Inventario Software |
---|
| 1313 | //if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
| 1314 | muestraMensaje(30,NULL);// Creando Imagen Básica, por favor espere... |
---|
| 1315 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
[6a830ffa] | 1316 | sprintf(parametros,"%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,rti); |
---|
[4329e85] | 1317 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1318 | if(herror){ |
---|
| 1319 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1320 | errorInfo(modulo,msglog); |
---|
| 1321 | muestraMensaje(29,NULL);// Ha habido algún error en el proceso de creación de imagen básica |
---|
| 1322 | } |
---|
| 1323 | else |
---|
| 1324 | muestraMensaje(28,NULL);// El proceso de creación de imagen básica ha terminado correctamente |
---|
| 1325 | //} |
---|
| 1326 | //else{ |
---|
| 1327 | // sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1328 | // errorInfo(modulo,msglog); |
---|
| 1329 | //} |
---|
| 1330 | |
---|
| 1331 | ids=copiaParametro("ids",ptrTrama); // Identificador de la sesión |
---|
| 1332 | |
---|
| 1333 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1334 | initParametros(ptrTrama,0); |
---|
| 1335 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearImagenBasica"); |
---|
| 1336 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1337 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición de donde se creó |
---|
| 1338 | lon+=sprintf(ptrTrama->parametros+lon,"cpt=%s\r",cpt); // Tipo o código de partición |
---|
| 1339 | lon+=sprintf(ptrTrama->parametros+lon,"ipr=%s\r",ipr); // Ip del repositorio donde se alojó |
---|
| 1340 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1341 | |
---|
| 1342 | liberaMemoria(nfn); |
---|
| 1343 | liberaMemoria(dsk); |
---|
| 1344 | liberaMemoria(par); |
---|
| 1345 | liberaMemoria(cpt); |
---|
| 1346 | liberaMemoria(idi); |
---|
| 1347 | liberaMemoria(nci); |
---|
| 1348 | liberaMemoria(rti); |
---|
| 1349 | liberaMemoria(ipr); |
---|
| 1350 | liberaMemoria(bpi); |
---|
| 1351 | liberaMemoria(cpc); |
---|
| 1352 | liberaMemoria(bpc); |
---|
| 1353 | liberaMemoria(nba); |
---|
| 1354 | liberaMemoria(ids); |
---|
| 1355 | |
---|
[380fe92] | 1356 | muestraMenu(); |
---|
| 1357 | |
---|
[4329e85] | 1358 | return(TRUE); |
---|
| 1359 | } |
---|
| 1360 | //______________________________________________________________________________________________________ |
---|
| 1361 | // Función: CrearSoftIncremental |
---|
| 1362 | // |
---|
| 1363 | // Descripción: |
---|
| 1364 | // Crea una software incremental comparando una partición con una imagen básica |
---|
| 1365 | // Parámetros: |
---|
| 1366 | // ptrTrama: contenido del mensaje |
---|
| 1367 | // |
---|
| 1368 | // Devuelve: |
---|
| 1369 | // TRUE: Si el proceso es correcto |
---|
| 1370 | // FALSE: En caso de ocurrir algún error |
---|
| 1371 | //______________________________________________________________________________________________________ |
---|
| 1372 | BOOLEAN CrearSoftIncremental(TRAMA* ptrTrama) |
---|
| 1373 | { |
---|
| 1374 | int lon; |
---|
| 1375 | char *nfn,*dsk,*par,*idi,*idf,*ipr,*nci,*rti,*ncf,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
| 1376 | char modulo[] = "CrearSoftIncremental()"; |
---|
| 1377 | |
---|
| 1378 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1379 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1380 | infoDebug(msglog); |
---|
| 1381 | } |
---|
| 1382 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1383 | |
---|
| 1384 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1385 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
| 1386 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
| 1387 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
| 1388 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
| 1389 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
| 1390 | idf=copiaParametro("idf",ptrTrama); // Identificador de la imagen diferencial |
---|
| 1391 | ncf=copiaParametro("ncf",ptrTrama); // Nombre canónico de la imagen diferencial |
---|
| 1392 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
| 1393 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
| 1394 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
| 1395 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
| 1396 | |
---|
| 1397 | // muestraMensaje(7,NULL); // Creando Inventario Software |
---|
| 1398 | // if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
| 1399 | muestraMensaje(25,NULL);// Creando Imagen Incremental, por favor espere... |
---|
| 1400 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1401 | sprintf(parametros,"%s %s %s %s %s %s %s%s%s%s %s",nfn,dsk,par,nci,ipr,ncf,bpi,cpc,bpc,nba,rti); |
---|
| 1402 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1403 | if(herror){ |
---|
| 1404 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1405 | errorInfo(modulo,msglog); |
---|
| 1406 | muestraMensaje(27,NULL);// Ha habido algún error en el proceso de creación de imagen básica |
---|
| 1407 | } |
---|
| 1408 | else |
---|
| 1409 | muestraMensaje(26,NULL);// El proceso de creación de imagen básica ha terminado correctamente |
---|
| 1410 | // } |
---|
| 1411 | // else{ |
---|
| 1412 | // sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1413 | // errorInfo(modulo,msglog); |
---|
| 1414 | // } |
---|
| 1415 | |
---|
| 1416 | ids=copiaParametro("ids",ptrTrama); // Identificador de la sesión |
---|
| 1417 | |
---|
| 1418 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1419 | initParametros(ptrTrama,0); |
---|
| 1420 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearSoftIncremental"); |
---|
| 1421 | lon+=sprintf(ptrTrama->parametros+lon,"idf=%s\r",idf); // Identificador de la imagen incremental |
---|
| 1422 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
| 1423 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1424 | |
---|
| 1425 | liberaMemoria(nfn); |
---|
| 1426 | liberaMemoria(dsk); |
---|
| 1427 | liberaMemoria(par); |
---|
| 1428 | liberaMemoria(idi); |
---|
| 1429 | liberaMemoria(nci); |
---|
| 1430 | liberaMemoria(rti); |
---|
| 1431 | liberaMemoria(ipr); |
---|
| 1432 | liberaMemoria(idf); |
---|
| 1433 | liberaMemoria(ncf); |
---|
| 1434 | liberaMemoria(bpi); |
---|
| 1435 | liberaMemoria(cpc); |
---|
| 1436 | liberaMemoria(bpc); |
---|
| 1437 | liberaMemoria(nba); |
---|
| 1438 | liberaMemoria(ids); |
---|
| 1439 | |
---|
[380fe92] | 1440 | muestraMenu(); |
---|
| 1441 | |
---|
[3ec149c] | 1442 | return(TRUE); |
---|
| 1443 | } |
---|
| 1444 | //______________________________________________________________________________________________________ |
---|
| 1445 | // Función: RestaurarImagen |
---|
| 1446 | // |
---|
| 1447 | // Descripción: |
---|
| 1448 | // Restaura una imagen en una partición |
---|
| 1449 | // Parámetros: |
---|
| 1450 | // ptrTrama: contenido del mensaje |
---|
| 1451 | // Devuelve: |
---|
| 1452 | // TRUE: Si el proceso es correcto |
---|
[4329e85] | 1453 | // FALSE: En bpccaso de ocurrir algún error |
---|
[3ec149c] | 1454 | //______________________________________________________________________________________________________ |
---|
| 1455 | BOOLEAN RestaurarImagen(TRAMA* ptrTrama) |
---|
| 1456 | { |
---|
| 1457 | int lon; |
---|
| 1458 | char *nfn,*dsk,*par,*idi,*ipr,*ifs,*nci,*ids,*ptc,msglog[LONSTD]; |
---|
| 1459 | char modulo[] = "RestaurarImagen()"; |
---|
| 1460 | |
---|
| 1461 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1462 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1463 | infoDebug(msglog); |
---|
| 1464 | } |
---|
| 1465 | |
---|
| 1466 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1467 | par=copiaParametro("par",ptrTrama); |
---|
| 1468 | idi=copiaParametro("idi",ptrTrama); |
---|
| 1469 | ipr=copiaParametro("ipr",ptrTrama); |
---|
| 1470 | nci=copiaParametro("nci",ptrTrama); |
---|
| 1471 | ifs=copiaParametro("ifs",ptrTrama); |
---|
| 1472 | ptc=copiaParametro("ptc",ptrTrama); |
---|
| 1473 | |
---|
| 1474 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1475 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1476 | muestraMensaje(3,NULL); |
---|
| 1477 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
[eb9424f] | 1478 | sprintf(parametros,"%s %s %s %s %s %s",nfn,dsk,par,nci,ipr,ptc); |
---|
[3ec149c] | 1479 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1480 | if(herror){ |
---|
| 1481 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1482 | errorInfo(modulo,msglog); |
---|
| 1483 | muestraMensaje(12,NULL); |
---|
| 1484 | } |
---|
| 1485 | else |
---|
| 1486 | muestraMensaje(11,NULL); |
---|
| 1487 | |
---|
| 1488 | |
---|
| 1489 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1490 | initParametros(ptrTrama,0); |
---|
| 1491 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarImagen"); |
---|
| 1492 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1493 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
| 1494 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
| 1495 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1496 | |
---|
| 1497 | liberaMemoria(nfn); |
---|
| 1498 | liberaMemoria(dsk); |
---|
| 1499 | liberaMemoria(par); |
---|
| 1500 | liberaMemoria(idi); |
---|
| 1501 | liberaMemoria(nci); |
---|
| 1502 | liberaMemoria(ipr); |
---|
| 1503 | liberaMemoria(ifs); |
---|
| 1504 | liberaMemoria(ptc); |
---|
| 1505 | liberaMemoria(ids); |
---|
| 1506 | |
---|
[380fe92] | 1507 | muestraMenu(); |
---|
| 1508 | |
---|
[4329e85] | 1509 | return(TRUE); |
---|
| 1510 | } |
---|
| 1511 | //______________________________________________________________________________________________________ |
---|
| 1512 | // Función: RestaurarImagenBasica |
---|
| 1513 | // |
---|
| 1514 | // Descripción: |
---|
| 1515 | // Restaura una imagen básica en una partición |
---|
| 1516 | // Parámetros: |
---|
| 1517 | // ptrTrama: contenido del mensaje |
---|
| 1518 | // Devuelve: |
---|
| 1519 | // TRUE: Si el proceso es correcto |
---|
| 1520 | // FALSE: En caso de ocurrir algún error |
---|
| 1521 | //______________________________________________________________________________________________________ |
---|
| 1522 | BOOLEAN RestaurarImagenBasica(TRAMA* ptrTrama) |
---|
| 1523 | { |
---|
| 1524 | int lon; |
---|
| 1525 | char *nfn,*dsk,*par,*idi,*ipr,*met,*nci,*rti,*ifs,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
| 1526 | char modulo[] = "RestaurarImagenBasica()"; |
---|
| 1527 | |
---|
| 1528 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1529 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1530 | infoDebug(msglog); |
---|
| 1531 | } |
---|
| 1532 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1533 | par=copiaParametro("par",ptrTrama); |
---|
| 1534 | idi=copiaParametro("idi",ptrTrama); |
---|
| 1535 | ipr=copiaParametro("ipr",ptrTrama); |
---|
| 1536 | met=copiaParametro("met",ptrTrama); // Método de clonación 0= desde caché 1= desde repositorio |
---|
| 1537 | nci=copiaParametro("nci",ptrTrama); |
---|
| 1538 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
| 1539 | ifs=copiaParametro("ifs",ptrTrama); |
---|
| 1540 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
| 1541 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
| 1542 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
| 1543 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
| 1544 | |
---|
| 1545 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1546 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1547 | muestraMensaje(31,NULL); |
---|
| 1548 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1549 | sprintf(parametros,"%s %s %s %s %s %s%s%s%s %s %s",nfn,dsk,par,nci,ipr,bpi,cpc,bpc,nba,met,rti); |
---|
| 1550 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1551 | if(herror){ |
---|
| 1552 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1553 | errorInfo(modulo,msglog); |
---|
| 1554 | muestraMensaje(33,NULL); |
---|
| 1555 | } |
---|
| 1556 | else |
---|
| 1557 | muestraMensaje(32,NULL); |
---|
| 1558 | |
---|
| 1559 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1560 | initParametros(ptrTrama,0); |
---|
| 1561 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarImagenBasica"); |
---|
| 1562 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1563 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
| 1564 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
| 1565 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1566 | |
---|
| 1567 | liberaMemoria(nfn); |
---|
| 1568 | liberaMemoria(dsk); |
---|
| 1569 | liberaMemoria(par); |
---|
| 1570 | liberaMemoria(idi); |
---|
| 1571 | liberaMemoria(nci); |
---|
| 1572 | liberaMemoria(rti); |
---|
| 1573 | liberaMemoria(ifs); |
---|
| 1574 | liberaMemoria(ipr); |
---|
| 1575 | liberaMemoria(met); |
---|
| 1576 | liberaMemoria(bpi); |
---|
| 1577 | liberaMemoria(cpc); |
---|
| 1578 | liberaMemoria(bpc); |
---|
| 1579 | liberaMemoria(nba); |
---|
| 1580 | liberaMemoria(ids); |
---|
[380fe92] | 1581 | |
---|
| 1582 | muestraMenu(); |
---|
[4329e85] | 1583 | |
---|
| 1584 | return(TRUE); |
---|
| 1585 | } |
---|
| 1586 | //______________________________________________________________________________________________________ |
---|
| 1587 | // Función: RestaurarSoftIncremental |
---|
| 1588 | // |
---|
| 1589 | // Descripción: |
---|
| 1590 | // Restaura software incremental en una partición |
---|
| 1591 | // Parámetros: |
---|
| 1592 | // ptrTrama: contenido del mensaje |
---|
| 1593 | // Devuelve: |
---|
| 1594 | // TRUE: Si el proceso es correcto |
---|
| 1595 | // FALSE: En caso de ocurrir algún error |
---|
| 1596 | //______________________________________________________________________________________________________ |
---|
| 1597 | BOOLEAN RestaurarSoftIncremental(TRAMA* ptrTrama) |
---|
| 1598 | { |
---|
| 1599 | int lon; |
---|
| 1600 | char *nfn,*dsk,*par,*idi,*ipr,*met,*ifs,*nci,*rti,*idf,*ncf,*bpi,*cpc,*bpc,*nba,*ids,msglog[LONSTD]; |
---|
| 1601 | char modulo[] = "RestaurarSoftIncremental()"; |
---|
| 1602 | |
---|
| 1603 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1604 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1605 | infoDebug(msglog); |
---|
| 1606 | } |
---|
| 1607 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1608 | par=copiaParametro("par",ptrTrama); |
---|
| 1609 | idi=copiaParametro("idi",ptrTrama); |
---|
| 1610 | idf=copiaParametro("idf",ptrTrama); |
---|
| 1611 | ipr=copiaParametro("ipr",ptrTrama); |
---|
| 1612 | met=copiaParametro("met",ptrTrama); // Método de clonación 0= desde caché 1= desde repositorio |
---|
| 1613 | ifs=copiaParametro("ifs",ptrTrama); |
---|
| 1614 | nci=copiaParametro("nci",ptrTrama); |
---|
| 1615 | rti=copiaParametro("rti",ptrTrama); // Ruta de origen de la imagen |
---|
| 1616 | ncf=copiaParametro("ncf",ptrTrama); |
---|
| 1617 | bpi=copiaParametro("bpi",ptrTrama); // Borrar la imagen antes de crearla |
---|
| 1618 | cpc=copiaParametro("cpc",ptrTrama); // Copiar también imagen a la cache |
---|
| 1619 | bpc=copiaParametro("bpc",ptrTrama); // Borrarla de la cache antes de copiarla en ella |
---|
| 1620 | nba=copiaParametro("nba",ptrTrama); // No borrar archivos en destino |
---|
| 1621 | |
---|
| 1622 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1623 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1624 | muestraMensaje(31,NULL); |
---|
| 1625 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1626 | 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); |
---|
| 1627 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1628 | if(herror){ |
---|
| 1629 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1630 | errorInfo(modulo,msglog); |
---|
| 1631 | muestraMensaje(35,NULL); |
---|
| 1632 | } |
---|
| 1633 | else |
---|
| 1634 | muestraMensaje(34,NULL); |
---|
| 1635 | |
---|
| 1636 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1637 | initParametros(ptrTrama,0); |
---|
| 1638 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarSoftIncremental"); |
---|
| 1639 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idf); // Identificador de la imagen incremental (Forzada a idi) |
---|
| 1640 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
| 1641 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
| 1642 | |
---|
| 1643 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1644 | |
---|
| 1645 | liberaMemoria(nfn); |
---|
| 1646 | liberaMemoria(dsk); |
---|
| 1647 | liberaMemoria(par); |
---|
| 1648 | liberaMemoria(idi); |
---|
| 1649 | liberaMemoria(idf); |
---|
| 1650 | liberaMemoria(nci); |
---|
| 1651 | liberaMemoria(rti); |
---|
| 1652 | liberaMemoria(ncf); |
---|
| 1653 | liberaMemoria(ifs); |
---|
| 1654 | liberaMemoria(ipr); |
---|
| 1655 | liberaMemoria(met); |
---|
| 1656 | liberaMemoria(bpi); |
---|
| 1657 | liberaMemoria(cpc); |
---|
| 1658 | liberaMemoria(bpc); |
---|
| 1659 | liberaMemoria(nba); |
---|
| 1660 | liberaMemoria(ids); |
---|
| 1661 | |
---|
[380fe92] | 1662 | muestraMenu(); |
---|
| 1663 | |
---|
[3ec149c] | 1664 | return(TRUE); |
---|
| 1665 | } |
---|
| 1666 | //______________________________________________________________________________________________________ |
---|
| 1667 | // Función: Configurar |
---|
| 1668 | // |
---|
| 1669 | // Descripción: |
---|
| 1670 | // Configura la tabla de particiones y formatea |
---|
| 1671 | // Parámetros: |
---|
| 1672 | // ptrTrama: contenido del mensaje |
---|
| 1673 | // Devuelve: |
---|
| 1674 | // TRUE: Si el proceso es correcto |
---|
| 1675 | // FALSE: En caso de ocurrir algún error |
---|
| 1676 | //______________________________________________________________________________________________________ |
---|
| 1677 | BOOLEAN Configurar(TRAMA* ptrTrama) |
---|
| 1678 | { |
---|
| 1679 | int lon; |
---|
| 1680 | char *nfn,*dsk,*cfg,*ids,msglog[LONSTD]; |
---|
| 1681 | char modulo[] = "Configurar()"; |
---|
| 1682 | |
---|
| 1683 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1684 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1685 | infoDebug(msglog); |
---|
| 1686 | } |
---|
| 1687 | |
---|
| 1688 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1689 | cfg=copiaParametro("cfg",ptrTrama); |
---|
| 1690 | /* Sustituir caracteres */ |
---|
| 1691 | sustituir(cfg,'\n','$'); |
---|
| 1692 | sustituir(cfg,'\t','#'); |
---|
| 1693 | |
---|
| 1694 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1695 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1696 | muestraMensaje(4,NULL); |
---|
| 1697 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
[44912ec5] | 1698 | sprintf(parametros,"%s %s %s",nfn,dsk,cfg); |
---|
[3ec149c] | 1699 | |
---|
| 1700 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1701 | if(herror){ |
---|
| 1702 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1703 | errorInfo(modulo,msglog); |
---|
| 1704 | muestraMensaje(13,NULL); |
---|
| 1705 | } |
---|
| 1706 | else |
---|
| 1707 | muestraMensaje(14,NULL); |
---|
| 1708 | |
---|
[9ef26af] | 1709 | cfg=LeeConfiguracion(); |
---|
[3ec149c] | 1710 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
| 1711 | errorLog(modulo,36,FALSE); |
---|
| 1712 | return(FALSE); |
---|
| 1713 | } |
---|
| 1714 | |
---|
| 1715 | /* Envia respuesta de ejecución del comando*/ |
---|
| 1716 | initParametros(ptrTrama,0); |
---|
| 1717 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Configurar"); |
---|
[7224a0a] | 1718 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
[3ec149c] | 1719 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1720 | |
---|
| 1721 | liberaMemoria(dsk); |
---|
| 1722 | liberaMemoria(cfg); |
---|
| 1723 | liberaMemoria(nfn); |
---|
| 1724 | liberaMemoria(ids); |
---|
| 1725 | |
---|
[380fe92] | 1726 | muestraMenu(); |
---|
| 1727 | |
---|
[3ec149c] | 1728 | return(TRUE); |
---|
| 1729 | } |
---|
| 1730 | // ________________________________________________________________________________________________________ |
---|
| 1731 | // Función: InventarioHardware |
---|
| 1732 | // |
---|
| 1733 | // Descripción: |
---|
| 1734 | // Envia al servidor el nombre del archivo de inventario de su hardware para posteriormente |
---|
| 1735 | // esperar que éste lo solicite y enviarlo por la red. |
---|
| 1736 | // Parámetros: |
---|
| 1737 | // ptrTrama: contenido del mensaje |
---|
| 1738 | // Devuelve: |
---|
| 1739 | // TRUE: Si el proceso es correcto |
---|
| 1740 | // FALSE: En caso de ocurrir algún error |
---|
| 1741 | //______________________________________________________________________________________________________ |
---|
| 1742 | BOOLEAN InventarioHardware(TRAMA* ptrTrama) |
---|
| 1743 | { |
---|
| 1744 | int lon; |
---|
| 1745 | SOCKET socket_c; |
---|
| 1746 | char *nfn,*ids,msglog[LONSTD],hrdsrc[LONPRM],hrddst[LONPRM]; |
---|
| 1747 | char modulo[] = "InventarioHardware()"; |
---|
| 1748 | |
---|
| 1749 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1750 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1751 | infoDebug(msglog); |
---|
| 1752 | } |
---|
| 1753 | |
---|
| 1754 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1755 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1756 | muestraMensaje(6,NULL); |
---|
| 1757 | |
---|
| 1758 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1759 | sprintf(hrdsrc,"/tmp/Chrd-%s",IPlocal); // Nombre que tendra el archivo de inventario |
---|
| 1760 | sprintf(parametros,"%s %s",nfn,hrdsrc); |
---|
| 1761 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1762 | if(herror){ |
---|
| 1763 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1764 | errorInfo(modulo,msglog); |
---|
| 1765 | muestraMensaje(18,NULL); |
---|
| 1766 | } |
---|
| 1767 | else{ |
---|
| 1768 | /* Envía fichero de inventario al servidor */ |
---|
| 1769 | sprintf(hrddst,"/tmp/Shrd-%s",IPlocal); // Nombre que tendra el archivo en el Servidor |
---|
| 1770 | initParametros(ptrTrama,0); |
---|
| 1771 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",hrddst); |
---|
| 1772 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
[4329e85] | 1773 | liberaMemoria(nfn); |
---|
| 1774 | liberaMemoria(ids); |
---|
[3ec149c] | 1775 | errorLog(modulo,42,FALSE); |
---|
| 1776 | return(FALSE); |
---|
| 1777 | } |
---|
| 1778 | /* Espera señal para comenzar el envío */ |
---|
[4329e85] | 1779 | liberaMemoria(ptrTrama); |
---|
[3ec149c] | 1780 | recibeFlag(&socket_c,ptrTrama); |
---|
| 1781 | /* Envía archivo */ |
---|
| 1782 | if(!sendArchivo(&socket_c,hrdsrc)){ |
---|
| 1783 | errorLog(modulo,57, FALSE); |
---|
| 1784 | herror=12; // Error de envío de fichero por la red |
---|
| 1785 | } |
---|
| 1786 | close(socket_c); |
---|
| 1787 | muestraMensaje(17,NULL); |
---|
| 1788 | } |
---|
| 1789 | |
---|
| 1790 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1791 | initParametros(ptrTrama,0); |
---|
| 1792 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioHardware"); |
---|
| 1793 | lon+=sprintf(ptrTrama->parametros+lon,"hrd=%s\r",hrddst); |
---|
| 1794 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1795 | liberaMemoria(nfn); |
---|
[380fe92] | 1796 | liberaMemoria(ids); |
---|
| 1797 | |
---|
| 1798 | muestraMenu(); |
---|
| 1799 | |
---|
[3ec149c] | 1800 | return(TRUE); |
---|
| 1801 | } |
---|
| 1802 | // ________________________________________________________________________________________________________ |
---|
| 1803 | // Función: InventarioSoftware |
---|
| 1804 | // |
---|
| 1805 | // Descripción: |
---|
| 1806 | // Crea el inventario software de un sistema operativo instalado en una partición. |
---|
| 1807 | // Parámetros: |
---|
| 1808 | // ptrTrama: contenido del mensaje |
---|
| 1809 | // Devuelve: |
---|
| 1810 | // TRUE: Si el proceso es correcto |
---|
| 1811 | // FALSE: En caso de ocurrir algún error |
---|
| 1812 | //______________________________________________________________________________________________________ |
---|
| 1813 | BOOLEAN InventarioSoftware(TRAMA* ptrTrama) |
---|
| 1814 | { |
---|
| 1815 | char *nfn,*ids,msglog[LONSTD]; |
---|
| 1816 | char modulo[] = "InventarioSoftware()"; |
---|
| 1817 | |
---|
| 1818 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1819 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1820 | infoDebug(msglog); |
---|
| 1821 | } |
---|
| 1822 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1823 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1824 | muestraMensaje(7,NULL); |
---|
| 1825 | InventariandoSoftware(ptrTrama,TRUE,nfn); |
---|
| 1826 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1827 | liberaMemoria(nfn); |
---|
| 1828 | liberaMemoria(ids); |
---|
[3ec149c] | 1829 | muestraMenu(); |
---|
| 1830 | return(TRUE); |
---|
| 1831 | } |
---|
| 1832 | // ________________________________________________________________________________________________________ |
---|
| 1833 | // |
---|
| 1834 | // Función: InventariandoSoftware |
---|
| 1835 | // |
---|
| 1836 | // Descripción: |
---|
| 1837 | // Envia al servidor el nombre del archivo de inventario de su software para posteriormente |
---|
| 1838 | // esperar que éste lo solicite y enviarlo por la red. |
---|
| 1839 | // Parámetros: |
---|
| 1840 | // ptrTrama: contenido del mensaje |
---|
| 1841 | // sw: switch que indica si la función es llamada por el comando InventarioSoftware(true) o CrearImagen(false) |
---|
| 1842 | // nfn: Nombre de la función del Interface que implementa el comando |
---|
| 1843 | // Devuelve: |
---|
| 1844 | // TRUE: Si el proceso es correcto |
---|
| 1845 | // FALSE: En caso de ocurrir algún error |
---|
| 1846 | //______________________________________________________________________________________________________ |
---|
| 1847 | BOOLEAN InventariandoSoftware(TRAMA* ptrTrama,BOOLEAN sw,char *nfn) |
---|
| 1848 | { |
---|
| 1849 | int lon; |
---|
| 1850 | SOCKET socket_c; |
---|
| 1851 | char *dsk,*par,msglog[LONSTD],sftsrc[LONPRM],sftdst[LONPRM]; |
---|
| 1852 | char modulo[] = "InventariandoSoftware()"; |
---|
| 1853 | |
---|
| 1854 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1855 | par=copiaParametro("par",ptrTrama); |
---|
| 1856 | |
---|
| 1857 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1858 | sprintf(sftsrc,"/tmp/CSft-%s-%s",IPlocal,par); // Nombre que tendra el archivo de inventario |
---|
| 1859 | sprintf(parametros,"%s %s %s %s",nfn,dsk,par,sftsrc); |
---|
| 1860 | |
---|
| 1861 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1862 | herror=0; |
---|
| 1863 | if(herror){ |
---|
| 1864 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1865 | errorInfo(modulo,msglog); |
---|
| 1866 | muestraMensaje(20,NULL); |
---|
| 1867 | } |
---|
| 1868 | else{ |
---|
| 1869 | /* Envía fichero de inventario al servidor */ |
---|
| 1870 | sprintf(sftdst,"/tmp/Ssft-%s-%s",IPlocal,par); // Nombre que tendra el archivo en el Servidor |
---|
| 1871 | initParametros(ptrTrama,0); |
---|
| 1872 | |
---|
| 1873 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",sftdst); |
---|
| 1874 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
| 1875 | errorLog(modulo,42,FALSE); |
---|
[4329e85] | 1876 | liberaMemoria(dsk); |
---|
| 1877 | liberaMemoria(par); |
---|
[3ec149c] | 1878 | return(FALSE); |
---|
| 1879 | } |
---|
| 1880 | /* Espera señal para comenzar el envío */ |
---|
[4329e85] | 1881 | liberaMemoria(ptrTrama); |
---|
[3ec149c] | 1882 | if(!recibeFlag(&socket_c,ptrTrama)){ |
---|
| 1883 | errorLog(modulo,17,FALSE); |
---|
| 1884 | } |
---|
| 1885 | /* Envía archivo */ |
---|
| 1886 | if(!sendArchivo(&socket_c,sftsrc)){ |
---|
| 1887 | errorLog(modulo,57, FALSE); |
---|
| 1888 | herror=12; // Error de envío de fichero por la red |
---|
| 1889 | } |
---|
| 1890 | close(socket_c); |
---|
| 1891 | muestraMensaje(19,NULL); |
---|
| 1892 | } |
---|
| 1893 | initParametros(ptrTrama,0); |
---|
| 1894 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioSoftware"); |
---|
| 1895 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); |
---|
| 1896 | lon+=sprintf(ptrTrama->parametros+lon,"sft=%s\r",sftdst); |
---|
| 1897 | if(!sw) |
---|
| 1898 | respuestaEjecucionComando(ptrTrama,herror,"0"); |
---|
| 1899 | |
---|
[4329e85] | 1900 | liberaMemoria(dsk); |
---|
| 1901 | liberaMemoria(par); |
---|
[3ec149c] | 1902 | return(TRUE); |
---|
| 1903 | } |
---|
| 1904 | // ________________________________________________________________________________________________________ |
---|
| 1905 | // Función: EjecutarScript |
---|
| 1906 | // |
---|
| 1907 | // Descripción: |
---|
| 1908 | // Ejecuta código de script |
---|
| 1909 | // Parámetros: |
---|
| 1910 | // ptrTrama: contenido del mensaje |
---|
| 1911 | // Devuelve: |
---|
| 1912 | // TRUE: Si el proceso es correcto |
---|
| 1913 | // FALSE: En caso de ocurrir algún error |
---|
| 1914 | //______________________________________________________________________________________________________ |
---|
| 1915 | BOOLEAN EjecutarScript(TRAMA* ptrTrama) |
---|
| 1916 | { |
---|
| 1917 | int lon; |
---|
[7224a0a] | 1918 | char *nfn,*aux,*ids,*scp,*cfg,msglog[LONSTD]; |
---|
[3ec149c] | 1919 | char modulo[] = "EjecutarScript()"; |
---|
| 1920 | |
---|
| 1921 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1922 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1923 | infoDebug(msglog); |
---|
| 1924 | } |
---|
[4329e85] | 1925 | aux=copiaParametro("scp",ptrTrama); |
---|
| 1926 | scp=URLDecode(aux); |
---|
[3ec149c] | 1927 | muestraMensaje(8,NULL); |
---|
| 1928 | /* Nombre del archivo de script */ |
---|
| 1929 | char filescript[LONPRM]; |
---|
| 1930 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
| 1931 | escribeArchivo(filescript,scp); |
---|
[4329e85] | 1932 | nfn=copiaParametro("nfn",ptrTrama); |
---|
[3ec149c] | 1933 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1934 | sprintf(parametros,"%s %s",nfn,filescript); |
---|
| 1935 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1936 | if(herror){ |
---|
| 1937 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1938 | errorInfo(modulo,msglog); |
---|
| 1939 | muestraMensaje(21,NULL); |
---|
| 1940 | } |
---|
| 1941 | else |
---|
| 1942 | muestraMensaje(22,NULL); |
---|
[7224a0a] | 1943 | |
---|
| 1944 | // Toma configuración de particiones |
---|
[9ef26af] | 1945 | cfg=LeeConfiguracion(); |
---|
[7224a0a] | 1946 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
| 1947 | errorLog(modulo,36,FALSE); |
---|
| 1948 | herror=36; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1952 | |
---|
[3ec149c] | 1953 | //herror=ejecutarCodigoBash(scp); |
---|
| 1954 | initParametros(ptrTrama,0); |
---|
| 1955 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_EjecutarScript"); |
---|
[7224a0a] | 1956 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
[3ec149c] | 1957 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
[4329e85] | 1958 | |
---|
| 1959 | liberaMemoria(nfn); |
---|
| 1960 | liberaMemoria(ids); |
---|
| 1961 | liberaMemoria(aux); |
---|
[7224a0a] | 1962 | liberaMemoria(scp); |
---|
| 1963 | liberaMemoria(cfg); |
---|
[380fe92] | 1964 | |
---|
| 1965 | muestraMenu(); |
---|
| 1966 | |
---|
[3ec149c] | 1967 | return(TRUE); |
---|
| 1968 | } |
---|
| 1969 | //______________________________________________________________________________________________________ |
---|
| 1970 | // Función: respuestaEjecucionComando |
---|
| 1971 | // |
---|
| 1972 | // Descripción: |
---|
| 1973 | // Envia una respuesta a una ejecucion de comando al servidor de Administración |
---|
| 1974 | // Parámetros: |
---|
| 1975 | // - ptrTrama: contenido del mensaje |
---|
| 1976 | // - res: Resultado de la ejecución (Código de error devuelto por el script ejecutado) |
---|
| 1977 | // - ids: Identificador de la sesion (En caso de no haber seguimiento es NULO) |
---|
| 1978 | // Devuelve: |
---|
| 1979 | // TRUE: Si el proceso es correcto |
---|
| 1980 | // FALSE: En caso de ocurrir algún error |
---|
| 1981 | // ________________________________________________________________________________________________________ |
---|
| 1982 | BOOLEAN respuestaEjecucionComando(TRAMA* ptrTrama,int res,char *ids) |
---|
| 1983 | { |
---|
| 1984 | int lon; |
---|
| 1985 | SOCKET socket_c; |
---|
| 1986 | char modulo[] = "respuestaEjecucionComando()"; |
---|
| 1987 | |
---|
| 1988 | lon=strlen(ptrTrama->parametros); |
---|
| 1989 | if(ids){ // Existe seguimiento |
---|
| 1990 | lon+=sprintf(ptrTrama->parametros+lon,"ids=%s\r",ids); // Añade identificador de la sesión |
---|
| 1991 | } |
---|
| 1992 | if (res==0){ // Resultado satisfactorio |
---|
| 1993 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","1"); |
---|
| 1994 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",""); |
---|
| 1995 | } |
---|
| 1996 | else{ // Algún error |
---|
| 1997 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","2"); |
---|
| 1998 | if(res>MAXERRORSCRIPT) |
---|
[4329e85] | 1999 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s (Error de script:%d)\r",tbErroresScripts[0],res);// Descripción del error |
---|
[3ec149c] | 2000 | else |
---|
| 2001 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",tbErroresScripts[res]);// Descripción del error |
---|
| 2002 | } |
---|
| 2003 | if(!(enviaMensajeServidor(&socket_c,ptrTrama,MSG_NOTIFICACION))){ |
---|
| 2004 | errorLog(modulo,44,FALSE); |
---|
| 2005 | return(FALSE); |
---|
| 2006 | } |
---|
[eeeb98a] | 2007 | |
---|
[3ec149c] | 2008 | close(socket_c); |
---|
| 2009 | return(TRUE); |
---|
| 2010 | } |
---|
| 2011 | // ________________________________________________________________________________________________________ |
---|
| 2012 | // Función: gestionaTrama |
---|
| 2013 | // |
---|
| 2014 | // Descripción: |
---|
| 2015 | // Procesa las tramas recibidas. |
---|
| 2016 | // Parametros: |
---|
| 2017 | // ptrTrama: contenido del mensaje |
---|
| 2018 | // Devuelve: |
---|
| 2019 | // TRUE: Si el proceso es correcto |
---|
| 2020 | // FALSE: En caso de ocurrir algún error |
---|
| 2021 | // ________________________________________________________________________________________________________ |
---|
| 2022 | BOOLEAN gestionaTrama(TRAMA *ptrTrama) |
---|
| 2023 | { |
---|
| 2024 | int i, res; |
---|
| 2025 | char *nfn; |
---|
| 2026 | char modulo[] = "gestionaTrama()"; |
---|
| 2027 | |
---|
| 2028 | INTROaFINCAD(ptrTrama); |
---|
| 2029 | nfn = copiaParametro("nfn", ptrTrama); // Toma nombre de función |
---|
| 2030 | for (i = 0; i < MAXIMAS_FUNCIONES; i++) { // Recorre funciones que procesan las tramas |
---|
| 2031 | res = strcmp(tbfuncionesClient[i].nf, nfn); |
---|
| 2032 | if (res == 0) { // Encontrada la función que procesa el mensaje |
---|
[4329e85] | 2033 | liberaMemoria(nfn); |
---|
[3ec149c] | 2034 | return(tbfuncionesClient[i].fptr(ptrTrama)); // Invoca la función |
---|
| 2035 | } |
---|
| 2036 | } |
---|
[4329e85] | 2037 | |
---|
| 2038 | liberaMemoria(nfn); |
---|
| 2039 | |
---|
| 2040 | /* Sólo puede ser un comando personalizado |
---|
[3ec149c] | 2041 | if (ptrTrama->tipo==MSG_COMANDO) |
---|
| 2042 | return(Comando(ptrTrama)); |
---|
[4329e85] | 2043 | */ |
---|
[3ec149c] | 2044 | errorLog(modulo, 18, FALSE); |
---|
| 2045 | return (FALSE); |
---|
| 2046 | } |
---|
| 2047 | //________________________________________________________________________________________________________ |
---|
| 2048 | // Función: ejecutaArchivo |
---|
| 2049 | // |
---|
| 2050 | // Descripción: |
---|
| 2051 | // Ejecuta los comando contenido en un archivo (cada comando y sus parametros separados por un |
---|
| 2052 | // salto de linea. |
---|
| 2053 | // Parámetros: |
---|
| 2054 | // filecmd: Nombre del archivo de comandos |
---|
| 2055 | // ptrTrama: Puntero a una estructura TRAMA usada en las comunicaciones por red (No debe ser NULL) |
---|
| 2056 | // Devuelve: |
---|
| 2057 | // TRUE: Si el proceso es correcto |
---|
| 2058 | // FALSE: En caso de ocurrir algún error |
---|
| 2059 | //________________________________________________________________________________________________________ |
---|
| 2060 | BOOLEAN ejecutaArchivo(char* filecmd,TRAMA *ptrTrama) |
---|
| 2061 | { |
---|
| 2062 | char* buffer,*lineas[MAXIMAS_LINEAS]; |
---|
| 2063 | int i,numlin; |
---|
| 2064 | char modulo[] = "ejecutaArchivo()"; |
---|
| 2065 | |
---|
| 2066 | buffer=leeArchivo(filecmd); |
---|
| 2067 | if(buffer){ |
---|
| 2068 | numlin = splitCadena(lineas, buffer, '@'); |
---|
| 2069 | initParametros(ptrTrama,0); |
---|
| 2070 | for (i = 0; i < numlin; i++) { |
---|
| 2071 | if(strlen(lineas[i])>0){ |
---|
| 2072 | strcpy(ptrTrama->parametros,lineas[i]); |
---|
| 2073 | strcat(ptrTrama->parametros,"\rMCDJ@"); // Fin de trama |
---|
| 2074 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 2075 | errorLog(modulo,39,FALSE); |
---|
| 2076 | //return(FALSE); |
---|
| 2077 | } |
---|
| 2078 | } |
---|
| 2079 | } |
---|
| 2080 | } |
---|
[4329e85] | 2081 | liberaMemoria(buffer); |
---|
[3ec149c] | 2082 | return(TRUE); |
---|
| 2083 | } |
---|
| 2084 | //______________________________________________________________________________________________________ |
---|
| 2085 | // Función: enviaMensajeServidor |
---|
| 2086 | // |
---|
| 2087 | // Descripción: |
---|
| 2088 | // Envia un mensaje al servidor de Administración |
---|
| 2089 | // Parámetros: |
---|
| 2090 | // - socket_c: (Salida) Socket utilizado para el envío |
---|
| 2091 | // - ptrTrama: contenido del mensaje |
---|
| 2092 | // - tipo: Tipo de mensaje |
---|
| 2093 | // C=Comando, N=Respuesta a un comando, P=Peticion,R=Respuesta a una petición, I=Informacion |
---|
| 2094 | // Devuelve: |
---|
| 2095 | // TRUE: Si el proceso es correcto |
---|
| 2096 | // FALSE: En caso de ocurrir algún error |
---|
| 2097 | // ________________________________________________________________________________________________________ |
---|
| 2098 | BOOLEAN enviaMensajeServidor(SOCKET *socket_c,TRAMA *ptrTrama,char tipo) |
---|
| 2099 | { |
---|
| 2100 | int lon; |
---|
| 2101 | char modulo[] = "enviaMensajeServidor()"; |
---|
| 2102 | |
---|
| 2103 | *socket_c=abreConexion(); |
---|
| 2104 | if(*socket_c==INVALID_SOCKET){ |
---|
| 2105 | errorLog(modulo,38,FALSE); // Error de conexión con el servidor |
---|
| 2106 | return(FALSE); |
---|
| 2107 | } |
---|
| 2108 | ptrTrama->arroba='@'; // Cabecera de la trama |
---|
| 2109 | strncpy(ptrTrama->identificador,"JMMLCAMDJ_MCDJ",14); // identificador de la trama |
---|
| 2110 | ptrTrama->tipo=tipo; // Tipo de mensaje |
---|
| 2111 | lon=strlen(ptrTrama->parametros); // Compone la trama |
---|
| 2112 | lon+=sprintf(ptrTrama->parametros+lon,"iph=%s\r",IPlocal); // Ip del ordenador |
---|
| 2113 | lon+=sprintf(ptrTrama->parametros+lon,"ido=%s\r",idordenador); // Identificador del ordenador |
---|
| 2114 | lon+=sprintf(ptrTrama->parametros+lon,"npc=%s\r",nombreordenador); // Nombre del ordenador |
---|
| 2115 | lon+=sprintf(ptrTrama->parametros+lon,"idc=%s\r",idcentro); // Identificador del centro |
---|
| 2116 | lon+=sprintf(ptrTrama->parametros+lon,"ida=%s\r",idaula); // Identificador del aula |
---|
| 2117 | |
---|
| 2118 | if (!mandaTrama(socket_c,ptrTrama)) { |
---|
| 2119 | errorLog(modulo,26,FALSE); |
---|
| 2120 | return (FALSE); |
---|
| 2121 | } |
---|
| 2122 | return(TRUE); |
---|
| 2123 | } |
---|
| 2124 | // ******************************************************************************************************** |
---|
| 2125 | // PROGRAMA PRINCIPAL (CLIENTE) |
---|
| 2126 | // ******************************************************************************************************** |
---|
| 2127 | int main(int argc, char *argv[]) |
---|
| 2128 | { |
---|
| 2129 | TRAMA *ptrTrama; |
---|
| 2130 | char modulo[] = "main()"; |
---|
| 2131 | |
---|
| 2132 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA)); |
---|
| 2133 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas |
---|
| 2134 | errorLog(modulo, 3, FALSE); |
---|
| 2135 | exit(EXIT_FAILURE); |
---|
| 2136 | } |
---|
| 2137 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2138 | Validación de parámetros de ejecución y fichero de configuración |
---|
| 2139 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2140 | if (!validacionParametros(argc, argv,3)) // Valida parámetros de ejecución |
---|
| 2141 | exit(EXIT_FAILURE); |
---|
| 2142 | |
---|
| 2143 | if (!tomaConfiguracion(szPathFileCfg)) // Toma parametros de configuración |
---|
| 2144 | exit(EXIT_FAILURE); |
---|
| 2145 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2146 | Carga catálogo de funciones que procesan las tramas |
---|
| 2147 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2148 | int cf = 0; |
---|
| 2149 | |
---|
| 2150 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_AutoexecCliente"); |
---|
| 2151 | tbfuncionesClient[cf++].fptr = &RESPUESTA_AutoexecCliente; |
---|
| 2152 | |
---|
| 2153 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_InclusionCliente"); |
---|
| 2154 | tbfuncionesClient[cf++].fptr = &RESPUESTA_InclusionCliente; |
---|
| 2155 | |
---|
| 2156 | strcpy(tbfuncionesClient[cf].nf, "NoComandosPtes"); |
---|
| 2157 | tbfuncionesClient[cf++].fptr = &NoComandosPtes; |
---|
| 2158 | |
---|
| 2159 | strcpy(tbfuncionesClient[cf].nf, "Actualizar"); |
---|
| 2160 | tbfuncionesClient[cf++].fptr = &Actualizar; |
---|
| 2161 | |
---|
| 2162 | strcpy(tbfuncionesClient[cf].nf, "Purgar"); |
---|
| 2163 | tbfuncionesClient[cf++].fptr = &Purgar; |
---|
| 2164 | |
---|
| 2165 | strcpy(tbfuncionesClient[cf].nf, "ConsolaRemota"); |
---|
| 2166 | tbfuncionesClient[cf++].fptr = &ConsolaRemota; |
---|
| 2167 | |
---|
| 2168 | strcpy(tbfuncionesClient[cf].nf, "Sondeo"); |
---|
| 2169 | tbfuncionesClient[cf++].fptr = &Sondeo; |
---|
| 2170 | |
---|
| 2171 | strcpy(tbfuncionesClient[cf].nf, "Arrancar"); |
---|
| 2172 | tbfuncionesClient[cf++].fptr = &Arrancar; |
---|
| 2173 | |
---|
| 2174 | strcpy(tbfuncionesClient[cf].nf, "Apagar"); |
---|
| 2175 | tbfuncionesClient[cf++].fptr = &Apagar; |
---|
| 2176 | |
---|
| 2177 | strcpy(tbfuncionesClient[cf].nf, "Reiniciar"); |
---|
| 2178 | tbfuncionesClient[cf++].fptr = &Reiniciar; |
---|
| 2179 | |
---|
| 2180 | strcpy(tbfuncionesClient[cf].nf, "IniciarSesion"); |
---|
| 2181 | tbfuncionesClient[cf++].fptr = &IniciarSesion; |
---|
| 2182 | |
---|
| 2183 | strcpy(tbfuncionesClient[cf].nf, "CrearImagen"); |
---|
| 2184 | tbfuncionesClient[cf++].fptr = &CrearImagen; |
---|
| 2185 | |
---|
[4329e85] | 2186 | strcpy(tbfuncionesClient[cf].nf, "CrearImagenBasica"); |
---|
| 2187 | tbfuncionesClient[cf++].fptr = &CrearImagenBasica; |
---|
| 2188 | |
---|
| 2189 | strcpy(tbfuncionesClient[cf].nf, "CrearSoftIncremental"); |
---|
| 2190 | tbfuncionesClient[cf++].fptr = &CrearSoftIncremental; |
---|
| 2191 | |
---|
[3ec149c] | 2192 | strcpy(tbfuncionesClient[cf].nf, "RestaurarImagen"); |
---|
| 2193 | tbfuncionesClient[cf++].fptr = &RestaurarImagen; |
---|
| 2194 | |
---|
[4329e85] | 2195 | strcpy(tbfuncionesClient[cf].nf, "RestaurarImagenBasica"); |
---|
| 2196 | tbfuncionesClient[cf++].fptr = &RestaurarImagenBasica; |
---|
| 2197 | |
---|
| 2198 | strcpy(tbfuncionesClient[cf].nf, "RestaurarSoftIncremental"); |
---|
| 2199 | tbfuncionesClient[cf++].fptr = &RestaurarSoftIncremental; |
---|
| 2200 | |
---|
| 2201 | |
---|
[3ec149c] | 2202 | strcpy(tbfuncionesClient[cf].nf, "Configurar"); |
---|
| 2203 | tbfuncionesClient[cf++].fptr = &Configurar; |
---|
| 2204 | |
---|
| 2205 | strcpy(tbfuncionesClient[cf].nf, "EjecutarScript"); |
---|
| 2206 | tbfuncionesClient[cf++].fptr = &EjecutarScript; |
---|
| 2207 | |
---|
| 2208 | strcpy(tbfuncionesClient[cf].nf, "InventarioHardware"); |
---|
| 2209 | tbfuncionesClient[cf++].fptr = &InventarioHardware; |
---|
| 2210 | |
---|
| 2211 | strcpy(tbfuncionesClient[cf].nf, "InventarioSoftware"); |
---|
| 2212 | tbfuncionesClient[cf++].fptr = &InventarioSoftware; |
---|
| 2213 | |
---|
| 2214 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2215 | Toma dirección IP del cliente |
---|
| 2216 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2217 | if(!tomaIPlocal()){ // Error al recuperar la IP local |
---|
| 2218 | errorLog(modulo,0,FALSE); |
---|
| 2219 | exit(EXIT_FAILURE); |
---|
| 2220 | } |
---|
| 2221 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2222 | Inicio de sesión |
---|
| 2223 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2224 | infoLog(1); // Inicio de sesión |
---|
| 2225 | infoLog(3); // Abriendo sesión en el servidor de Administración; |
---|
| 2226 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2227 | Inclusión del cliente en el sistema |
---|
| 2228 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2229 | if(!inclusionCliente(ptrTrama)){ // Ha habido algún problema al abrir sesión |
---|
| 2230 | errorLog(modulo,0,FALSE); |
---|
| 2231 | exit(EXIT_FAILURE); |
---|
| 2232 | } |
---|
| 2233 | infoLog(4); // Cliente iniciado |
---|
| 2234 | |
---|
| 2235 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2236 | Procesamiento de la cache |
---|
| 2237 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2238 | infoLog(23); // Abriendo sesión en el servidor de Administración; |
---|
| 2239 | if(!cuestionCache(cache)){ |
---|
| 2240 | errorLog(modulo,0,FALSE); |
---|
| 2241 | exit(EXIT_FAILURE); |
---|
| 2242 | } |
---|
| 2243 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2244 | Ejecución del autoexec |
---|
| 2245 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2246 | if(atoi(idproautoexec)>0){ // Ejecución de procedimiento Autoexec |
---|
| 2247 | infoLog(5); |
---|
| 2248 | if(!autoexecCliente(ptrTrama)){ // Ejecución fichero autoexec |
---|
| 2249 | errorLog(modulo,0,FALSE); |
---|
| 2250 | exit(EXIT_FAILURE); |
---|
| 2251 | } |
---|
| 2252 | } |
---|
| 2253 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2254 | Comandos pendientes |
---|
| 2255 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2256 | infoLog(6); // Procesa comandos pendientes |
---|
| 2257 | if(!comandosPendientes(ptrTrama)){ // Ejecución de acciones pendientes |
---|
| 2258 | errorLog(modulo,0,FALSE); |
---|
| 2259 | exit(EXIT_FAILURE); |
---|
| 2260 | } |
---|
| 2261 | infoLog(7); // Acciones pendientes procesadas |
---|
| 2262 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2263 | Bucle de recepción de comandos |
---|
| 2264 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2265 | muestraMenu(); |
---|
| 2266 | procesaComandos(ptrTrama); // Bucle para procesar comandos interactivos |
---|
| 2267 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 2268 | Fin de la sesión |
---|
| 2269 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 2270 | exit(EXIT_SUCCESS); |
---|
| 2271 | } |
---|