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