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