[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) { |
---|
| 86 | errorLog(modulo,4, FALSE); // Falta parámetro SERVIDORADM |
---|
| 87 | return (FALSE); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if (puerto[0] == CHARNULL) { |
---|
| 91 | errorLog(modulo,5, FALSE); // Falta parámetro PUERTO |
---|
| 92 | return (FALSE); |
---|
| 93 | } |
---|
| 94 | if (pathinterface[0] == CHARNULL) { |
---|
| 95 | errorLog(modulo,56, FALSE); // Falta parámetro PATHINTERFACE |
---|
| 96 | return (FALSE); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | if (urlmenu[0] == CHARNULL) { |
---|
| 100 | errorLog(modulo,89, FALSE); // Falta parámetro URLMENU |
---|
| 101 | return (FALSE); |
---|
| 102 | } |
---|
| 103 | if (urlmsg[0] == CHARNULL) { |
---|
| 104 | errorLog(modulo,90, FALSE); // Falta parámetro URLMSG |
---|
| 105 | return (FALSE); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | return (TRUE); |
---|
| 109 | } |
---|
| 110 | //______________________________________________________________________________________________________ |
---|
| 111 | // Función: FinterfaceAdmin |
---|
| 112 | // |
---|
| 113 | // Descripción: |
---|
| 114 | // Esta función es la puerta de comunicación entre el módulo de administración y el motor de clonación. |
---|
| 115 | // La Aplicación de administración utiliza una interface para ejecutar funciones del motor de clonación; |
---|
| 116 | // esta interface llamará a la API del motor con lo que cambiando el comportamiento de esta interface |
---|
| 117 | // podremos hacer llamadas a otras API de clonación y de esta manera probar distintos motores. |
---|
| 118 | // |
---|
| 119 | // Parámetros: |
---|
| 120 | // - script: Nombre del módulo,función o script de la interface |
---|
| 121 | // - parametros: Parámetros que se le pasarán a la interface |
---|
| 122 | // - salida: Recoge la salida que genera la llamada a la interface |
---|
| 123 | |
---|
| 124 | // Devuelve: |
---|
| 125 | // Código de error de la ejecución al módulo , función o script de la interface |
---|
| 126 | // |
---|
| 127 | // Especificaciones: |
---|
| 128 | // El parámetro salida recoge la salida desde un fichero que se genera en la ejecución del script siempre que |
---|
| 129 | // sea distinto de NULL, esto es, si al llamar a la función este parámetro es NULL no se recogerá dicha salida. |
---|
| 130 | // Este fichero tiene una ubicación fija: /tmp/_retinterface |
---|
| 131 | //______________________________________________________________________________________________________ |
---|
| 132 | |
---|
| 133 | int FinterfaceAdmin( char *script,char* parametros,char* salida) |
---|
| 134 | { |
---|
| 135 | FILE *f; |
---|
| 136 | int lSize,nargs,i,resul; |
---|
| 137 | char msglog[LONSTD],*argumentos[MAXARGS]; |
---|
| 138 | char modulo[] = "FinterfaceAdmin()"; |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | if (ndebug>= DEBUG_MEDIO) { |
---|
| 142 | sprintf(msglog, "%s:%s", tbMensajes[8], script); |
---|
| 143 | infoDebug(msglog); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | /* Crea matriz de los argumentos */ |
---|
| 147 | nargs=splitCadena(argumentos,parametros,32); |
---|
| 148 | for(i=nargs;i<MAXARGS;i++){ |
---|
| 149 | argumentos[i]=NULL; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /* Muestra matriz de los argumentos */ |
---|
| 153 | for(i=0;i<nargs;i++){ |
---|
| 154 | if (ndebug>= DEBUG_ALTO) { |
---|
| 155 | sprintf(msglog, "%s: #%d-%s", tbMensajes[9],i+1,argumentos[i]); |
---|
| 156 | infoDebug(msglog); |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | /* Elimina fichero de retorno */ |
---|
| 160 | if(salida!=(char*)NULL){ |
---|
| 161 | f = fopen("/tmp/_retinterface_","w" ); |
---|
| 162 | if (f==NULL){ // Error de eliminación |
---|
| 163 | scriptLog(modulo,10); |
---|
| 164 | resul=8; |
---|
| 165 | scriptLog(modulo,resul); |
---|
| 166 | return(resul); |
---|
| 167 | } |
---|
| 168 | fclose(f); |
---|
| 169 | } |
---|
| 170 | /* Compone linea de comando */ |
---|
| 171 | if(parametros){ |
---|
| 172 | strcat(script," "); |
---|
| 173 | strcat(script,parametros); |
---|
| 174 | } |
---|
| 175 | /* LLamada función interface */ |
---|
| 176 | resul=system(script); |
---|
| 177 | if(resul){ |
---|
| 178 | scriptLog(modulo,10); |
---|
| 179 | scriptLog(modulo,resul); |
---|
| 180 | return(resul); |
---|
| 181 | } |
---|
| 182 | /* Lee fichero de retorno */ |
---|
| 183 | if(salida!=(char*)NULL){ |
---|
| 184 | f = fopen("/tmp/_retinterface_","rb" ); |
---|
| 185 | if (f==NULL){ // Error de apertura |
---|
| 186 | scriptLog(modulo,10); |
---|
| 187 | resul=9; |
---|
| 188 | scriptLog(modulo,resul); |
---|
| 189 | return(resul); |
---|
| 190 | } |
---|
| 191 | else{ |
---|
| 192 | fseek (f ,0,SEEK_END); // Obtiene tamaño del fichero. |
---|
| 193 | lSize = ftell (f); |
---|
| 194 | rewind (f); |
---|
| 195 | if(lSize>LONGITUD_SCRIPTSALIDA){ |
---|
| 196 | scriptLog(modulo,10); |
---|
| 197 | resul=11; |
---|
| 198 | scriptLog(modulo,resul); |
---|
| 199 | return(resul); |
---|
| 200 | } |
---|
| 201 | fread (salida,1,lSize,f); // Lee contenido del fichero |
---|
| 202 | rTrim(salida); |
---|
| 203 | fclose(f); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | /* Muestra información de retorno */ |
---|
| 207 | if(salida!=(char*)NULL){ |
---|
| 208 | if(ndebug>2){ |
---|
| 209 | sprintf(msglog,"Información devuelta %s",salida); |
---|
| 210 | infoDebug(msglog); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | return(resul); |
---|
| 214 | } |
---|
| 215 | //______________________________________________________________________________________________________ |
---|
| 216 | // Función: interfaceAdmin |
---|
| 217 | // |
---|
| 218 | // Descripción: |
---|
| 219 | // Esta función es la puerta de comunicación entre el módulo de administración y el motor de clonación. |
---|
| 220 | // La Aplicación de administración utiliza una interface para ejecutar funciones del motor de clonación; |
---|
| 221 | // esta interface llamará a la API del motor con lo que cambiando el comportamiento de esta interface |
---|
| 222 | // podremos hacer llamadas a otras API de clonación y de esta manera probar distintos motores. |
---|
| 223 | // |
---|
| 224 | // Parámetros: |
---|
| 225 | // - script: Nombre del módulo,función o script de la interface |
---|
| 226 | // - parametros: Parámetros que se le pasarán a la interface |
---|
| 227 | // - salida: Recoge la salida que genera la llamada a la interface |
---|
| 228 | |
---|
| 229 | // Devuelve: |
---|
| 230 | // Código de error de la ejecución al módulo , función o script de la interface |
---|
| 231 | // |
---|
| 232 | // Especificaciones: |
---|
| 233 | // El parámetro salida recoge la salida desde el procedimiento hijo que se genera en la ejecución de éste |
---|
| 234 | // siempre que sea distinto de NULL, esto es, si al llamar a la función este parámetro es NULL no se |
---|
| 235 | // recogerá dicha salida. |
---|
| 236 | //______________________________________________________________________________________________________ |
---|
| 237 | |
---|
| 238 | int interfaceAdmin( char *script,char* parametros,char* salida) |
---|
| 239 | { |
---|
| 240 | int descr[2]; /* Descriptores de E y S de la turbería */ |
---|
| 241 | int bytesleidos; /* Bytes leidos en el mensaje */ |
---|
| 242 | int estado; |
---|
| 243 | pid_t pid; |
---|
| 244 | char buffer[LONGITUD_SCRIPTSALIDA]; |
---|
| 245 | pipe (descr); |
---|
| 246 | int i,nargs,resul; |
---|
| 247 | char msglog[LONSTD],*argumentos[MAXARGS]; |
---|
| 248 | char modulo[] = "interfaceAdmin()"; |
---|
| 249 | if (ndebug>= DEBUG_MEDIO) { |
---|
| 250 | sprintf(msglog, "%s:%s", tbMensajes[8], script); |
---|
| 251 | infoDebug(msglog); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | /* Crea matriz de los argumentos */ |
---|
| 255 | nargs=splitCadena(argumentos,parametros,32); |
---|
| 256 | for(i=nargs;i<MAXARGS;i++){ |
---|
| 257 | argumentos[i]=NULL; |
---|
| 258 | } |
---|
| 259 | /* Muestra matriz de los argumentos */ |
---|
| 260 | for(i=1;i<nargs;i++){ |
---|
| 261 | if (ndebug>= DEBUG_ALTO) { |
---|
| 262 | sprintf(msglog, "%s: #%d-%s", tbMensajes[9],i+1,argumentos[i]); |
---|
| 263 | infoDebug(msglog); |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | if((pid=fork())==0) |
---|
| 268 | { |
---|
| 269 | //_______________________________________________________________ |
---|
| 270 | |
---|
| 271 | /* Proceso hijo que ejecuta la función de interface */ |
---|
| 272 | |
---|
| 273 | close (descr[LEER]); |
---|
| 274 | dup2 (descr[ESCRIBIR], 1); |
---|
| 275 | close (descr[ESCRIBIR]); |
---|
| 276 | resul=execv(script,argumentos); |
---|
| 277 | //resul=execlp (script, script, argumentos[0],argumentos[1],NULL); |
---|
| 278 | exit(resul); |
---|
| 279 | |
---|
| 280 | /* Fin de proceso hijo */ |
---|
| 281 | //_______________________________________________________________ |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | //_______________________________________________________________ |
---|
| 286 | |
---|
| 287 | /* Proceso padre que espera la ejecución del hijo */ |
---|
| 288 | |
---|
| 289 | if (pid ==-1){ // Error en la creación del proceso hijo |
---|
| 290 | scriptLog(modulo,10); |
---|
| 291 | resul=13; |
---|
| 292 | scriptLog(modulo,resul); |
---|
| 293 | return(resul); |
---|
| 294 | } |
---|
| 295 | close (descr[ESCRIBIR]); |
---|
| 296 | bytesleidos = read (descr[LEER], buffer, LONGITUD_SCRIPTSALIDA-1); |
---|
| 297 | while(bytesleidos>0){ |
---|
| 298 | if(salida!=(char*)NULL){ // Si se solicita retorno de información... |
---|
| 299 | buffer[bytesleidos]='\0'; |
---|
| 300 | if(strlen(buffer)+strlen(salida)>LONGITUD_SCRIPTSALIDA){ |
---|
| 301 | scriptLog(modulo,10); |
---|
| 302 | resul=11; |
---|
| 303 | scriptLog(modulo,resul); |
---|
| 304 | return(resul); |
---|
| 305 | } |
---|
| 306 | rTrim(buffer); |
---|
| 307 | strcat(salida,buffer); |
---|
| 308 | |
---|
| 309 | } |
---|
| 310 | bytesleidos = read (descr[LEER], buffer, LONGITUD_SCRIPTSALIDA-1); |
---|
| 311 | } |
---|
| 312 | close (descr[LEER]); |
---|
| 313 | //kill(pid,SIGQUIT); |
---|
| 314 | waitpid(pid,&estado,0); |
---|
| 315 | resul=WEXITSTATUS(estado); |
---|
| 316 | if(resul){ |
---|
| 317 | scriptLog(modulo,10); |
---|
| 318 | scriptLog(modulo,resul); |
---|
| 319 | return(resul); |
---|
| 320 | } |
---|
| 321 | /* Fin de proceso padre */ |
---|
| 322 | //_______________________________________________________________ |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | /* Muestra información de retorno */ |
---|
| 326 | if(salida!=(char*)NULL){ |
---|
| 327 | if(ndebug>2){ |
---|
| 328 | sprintf(msglog,"Información devuelta %s",salida); |
---|
| 329 | infoDebug(msglog); |
---|
| 330 | } |
---|
| 331 | } |
---|
| 332 | return(resul); |
---|
| 333 | } |
---|
| 334 | //______________________________________________________________________________________________________ |
---|
| 335 | // Función: scriptLog |
---|
| 336 | // |
---|
| 337 | // Descripción: |
---|
| 338 | // Registra los sucesos de errores de scripts en el fichero de log |
---|
| 339 | // Parametros: |
---|
| 340 | // - modulo: Módulo donde se produjo el error |
---|
| 341 | // - coderr : Código del mensaje de error del script |
---|
| 342 | //______________________________________________________________________________________________________ |
---|
| 343 | void scriptLog(const char *modulo,int coderr) |
---|
| 344 | { |
---|
| 345 | char msglog[LONSUC]; |
---|
| 346 | |
---|
| 347 | if(coderr<MAXERRORSCRIPT) |
---|
| 348 | errorInfo(modulo,tbErroresScripts[coderr]); // Se ha producido algún error registrado |
---|
| 349 | else{ |
---|
| 350 | sprintf(msglog,"%s: %d",tbErroresScripts[MAXERRORSCRIPT],coderr); |
---|
| 351 | errorInfo(modulo,msglog); |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | //______________________________________________________________________________________________________ |
---|
| 355 | // Función: TomaIPlocal |
---|
| 356 | // |
---|
| 357 | // Descripción: |
---|
| 358 | // Recupera la IP local |
---|
| 359 | // Parámetros: |
---|
| 360 | // Ninguno |
---|
| 361 | // Devuelve: |
---|
| 362 | // TRUE: Si el proceso es correcto |
---|
| 363 | // FALSE: En caso de ocurrir algún error |
---|
| 364 | // Especificaciones: |
---|
| 365 | // En caso de no encontrar la IP o generarse algún error la IP local sería 0.0.0.0 |
---|
| 366 | //______________________________________________________________________________________________________ |
---|
| 367 | BOOLEAN tomaIPlocal() |
---|
| 368 | { |
---|
| 369 | char modulo[] = "tomaIPlocal()"; |
---|
| 370 | |
---|
| 371 | sprintf(interface,"%s/getIpAddress",pathinterface); |
---|
| 372 | herror=interfaceAdmin(interface,NULL,IPlocal); |
---|
| 373 | if(herror){ |
---|
| 374 | errorLog(modulo,85,FALSE); |
---|
| 375 | return(FALSE); |
---|
| 376 | } |
---|
| 377 | return(TRUE); |
---|
| 378 | } |
---|
| 379 | //______________________________________________________________________________________________________ |
---|
| 380 | // Función: cuestionCache |
---|
| 381 | // |
---|
| 382 | // Descripción: |
---|
| 383 | // Procesa la cache en caso de existir. |
---|
| 384 | // Parámetros: |
---|
| 385 | // tam : Tamaño de la cache |
---|
| 386 | // Devuelve: |
---|
| 387 | // TRUE: Si el proceso es correcto |
---|
| 388 | // FALSE: En caso de ocurrir algún error |
---|
| 389 | //______________________________________________________________________________________________________ |
---|
| 390 | BOOLEAN cuestionCache(char* tam) |
---|
| 391 | { |
---|
| 392 | char msglog[LONSTD]; |
---|
| 393 | char modulo[] = "cuestionCache()"; |
---|
| 394 | |
---|
| 395 | sprintf(interface,"%s/%s",pathinterface,"procesaCache"); |
---|
| 396 | sprintf(parametros,"%s %s","procesaCache",tam); |
---|
| 397 | |
---|
| 398 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 399 | if(herror){ |
---|
| 400 | sprintf(msglog,"%s",tbErrores[88]); |
---|
| 401 | errorInfo(modulo,msglog); |
---|
| 402 | return(FALSE); |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | return(TRUE); |
---|
| 406 | } |
---|
| 407 | //______________________________________________________________________________________________________ |
---|
| 408 | // Función: cargaPaginaWeb |
---|
| 409 | // |
---|
| 410 | // Descripción: |
---|
| 411 | // Muestra una pégina web usando el browser |
---|
| 412 | // Parámetros: |
---|
| 413 | // urp: Dirección url de la página |
---|
| 414 | // Devuelve: |
---|
| 415 | // TRUE: Si el proceso es correcto |
---|
| 416 | // FALSE: En caso de ocurrir algún error |
---|
| 417 | // ________________________________________________________________________________________________________ |
---|
| 418 | int cargaPaginaWeb(char *url) |
---|
| 419 | { |
---|
| 420 | int resul=0; |
---|
[2beed29] | 421 | char* argumentos[4]; |
---|
[3ec149c] | 422 | char modulo[] = "cargaPaginaWeb()"; |
---|
| 423 | |
---|
| 424 | if(pidbash>0) |
---|
| 425 | kill(pidbash,SIGQUIT); // Destruye el proceso hijo del proceso bash si existiera una conmutación |
---|
| 426 | |
---|
| 427 | if(pidbrowser>0) |
---|
| 428 | kill(pidbrowser,SIGQUIT); // Destruye el proceso hijo anterior y se queda sólo el actual |
---|
| 429 | |
---|
| 430 | sprintf(interface,"/opt/opengnsys/bin/browser"); |
---|
[2beed29] | 431 | sprintf(parametros,"browser -qws %s",url); |
---|
[3ec149c] | 432 | |
---|
| 433 | splitCadena(argumentos,parametros,' '); // Crea matriz de los argumentos del scripts |
---|
[2beed29] | 434 | argumentos[3]=NULL; |
---|
[3ec149c] | 435 | if((pidbrowser=fork())==0){ |
---|
| 436 | /* Proceso hijo que ejecuta el script */ |
---|
| 437 | resul=execv(interface,argumentos); |
---|
| 438 | exit(resul); |
---|
| 439 | } |
---|
| 440 | else { |
---|
| 441 | if (pidbrowser ==-1){ |
---|
| 442 | scriptLog(modulo,10); |
---|
| 443 | resul=13; |
---|
| 444 | scriptLog(modulo,resul); |
---|
| 445 | return(resul); |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | return(resul); |
---|
| 449 | } |
---|
| 450 | //________________________________________________________________________________________________________ |
---|
| 451 | // Función: muestraMenu |
---|
| 452 | // |
---|
| 453 | // Descripción: |
---|
| 454 | // Muestra el menu inicial del cliente |
---|
| 455 | // Parámetros: |
---|
| 456 | // Ninguno |
---|
| 457 | // Devuelve: |
---|
| 458 | // TRUE: Si el proceso es correcto |
---|
| 459 | // FALSE: En caso de ocurrir algún error |
---|
| 460 | //________________________________________________________________________________________________________ |
---|
| 461 | void muestraMenu() |
---|
| 462 | { |
---|
| 463 | cargaPaginaWeb(urlmenu); |
---|
| 464 | } |
---|
| 465 | //______________________________________________________________________________________________________ |
---|
| 466 | // Función: muestraMensaje |
---|
| 467 | // |
---|
| 468 | // Descripción: |
---|
| 469 | // Muestra un mensaje en pantalla |
---|
| 470 | // Parámetros: |
---|
| 471 | // - idx: Indice del mensaje |
---|
| 472 | // - msg: Descripción Mensaje |
---|
| 473 | // ________________________________________________________________________________________________________ |
---|
| 474 | void muestraMensaje(int idx,char*msg) |
---|
| 475 | { |
---|
| 476 | char url[250]; |
---|
| 477 | if(msg) |
---|
| 478 | sprintf(url,"%s?msg=%s",urlmsg,URLEncode(msg)); // Url de la página de mensajes |
---|
| 479 | else |
---|
| 480 | sprintf(url,"%s?idx=%d",urlmsg,idx); // Url de la página de mensajes |
---|
| 481 | cargaPaginaWeb(url); |
---|
| 482 | } |
---|
| 483 | //______________________________________________________________________________________________________ |
---|
| 484 | // Función: InclusionCliente |
---|
| 485 | // Descripción: |
---|
| 486 | // Abre una sesión en el servidor de administración y registra al cliente en el sistema |
---|
| 487 | // Parámetros: |
---|
| 488 | // Ninguno |
---|
| 489 | // Devuelve: |
---|
| 490 | // TRUE: Si el proceso es correcto |
---|
| 491 | // FALSE: En caso de ocurrir algún error |
---|
| 492 | //______________________________________________________________________________________________________ |
---|
| 493 | BOOLEAN inclusionCliente(TRAMA* ptrTrama) |
---|
| 494 | { |
---|
| 495 | int lon; |
---|
| 496 | char msglog[LONSTD],*cfg; |
---|
| 497 | SOCKET socket_c; |
---|
| 498 | char modulo[] = "inclusionCliente()"; |
---|
| 499 | |
---|
| 500 | char *dsk=(char*)reservaMemoria(2); |
---|
| 501 | sprintf(dsk,"1"); // Siempre el disco 1 |
---|
| 502 | |
---|
| 503 | cfg=LeeConfiguracion(dsk); |
---|
| 504 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
| 505 | errorLog(modulo,36,FALSE); |
---|
| 506 | errorLog(modulo,37,FALSE); |
---|
| 507 | return(FALSE); |
---|
| 508 | } |
---|
| 509 | if (ndebug>= DEBUG_ALTO) { |
---|
| 510 | sprintf(msglog, "%s:%s", tbMensajes[14],cfg); |
---|
| 511 | infoDebug(msglog); |
---|
| 512 | } |
---|
| 513 | initParametros(ptrTrama,0); |
---|
| 514 | lon=sprintf(ptrTrama->parametros,"nfn=InclusionCliente\r"); // Nombre de la función a ejecutar en el servidor |
---|
| 515 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Configuración de los Sistemas Operativos del cliente |
---|
| 516 | |
---|
| 517 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 518 | errorLog(modulo,37,FALSE); |
---|
| 519 | return(FALSE); |
---|
| 520 | } |
---|
| 521 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 522 | if(!ptrTrama){ |
---|
| 523 | errorLog(modulo,45,FALSE); |
---|
| 524 | return(FALSE); |
---|
| 525 | } |
---|
| 526 | close(socket_c); |
---|
| 527 | |
---|
| 528 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 529 | errorLog(modulo,39,FALSE); |
---|
| 530 | return(FALSE); |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | return(TRUE); |
---|
| 534 | } |
---|
| 535 | //______________________________________________________________________________________________________ |
---|
| 536 | // Función: RESPUESTA_InclusionCliente |
---|
| 537 | // |
---|
| 538 | // Descripción: |
---|
| 539 | // Respuesta del servidor de administración a la petición de inicio |
---|
| 540 | // enviando los datos identificativos del cliente y otras configuraciones |
---|
| 541 | // Parámetros: |
---|
| 542 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 543 | // Devuelve: |
---|
| 544 | // TRUE: Si el proceso es correcto |
---|
| 545 | // FALSE: En caso de ocurrir algún error |
---|
| 546 | //______________________________________________________________________________________________________ |
---|
| 547 | BOOLEAN RESPUESTA_InclusionCliente(TRAMA* ptrTrama) |
---|
| 548 | { |
---|
| 549 | char* res; |
---|
| 550 | char modulo[] = "RESPUESTA_InclusionCliente()"; |
---|
| 551 | |
---|
| 552 | res=copiaParametro("res",ptrTrama); // Resultado del proceso de inclusión |
---|
| 553 | if(atoi(res)==0){ // Error en el proceso de inclusión |
---|
| 554 | errorLog(modulo,41,FALSE); |
---|
| 555 | return (FALSE); |
---|
| 556 | } |
---|
| 557 | strcpy(idordenador,copiaParametro("ido",ptrTrama)); // Identificador del ordenador |
---|
| 558 | strcpy(nombreordenador,copiaParametro("npc",ptrTrama)); // Nombre del ordenador |
---|
| 559 | strcpy(cache,copiaParametro("che",ptrTrama)); // Tamaño de la caché reservada al cliente |
---|
| 560 | strcpy(idproautoexec,copiaParametro("exe",ptrTrama)); // Procedimento de inicio (Autoexec) |
---|
| 561 | strcpy(idcentro,copiaParametro("idc",ptrTrama)); // Identificador de la Unidad Organizativa |
---|
| 562 | strcpy(idaula,copiaParametro("ida",ptrTrama)); // Identificador de la Unidad Organizativa |
---|
| 563 | |
---|
| 564 | if(idordenador==NULL || nombreordenador==NULL){ |
---|
| 565 | errorLog(modulo,40,FALSE); |
---|
| 566 | return (FALSE); |
---|
| 567 | } |
---|
| 568 | return(TRUE); |
---|
| 569 | } |
---|
| 570 | //______________________________________________________________________________________________________ |
---|
| 571 | // |
---|
| 572 | // Función: LeeConfiguracion |
---|
| 573 | // Descripción: |
---|
| 574 | // Abre una sesión en el servidor de administración y registra al cliente en el sistema |
---|
| 575 | // Parámetros: |
---|
| 576 | // Ninguno |
---|
| 577 | // Devuelve: |
---|
| 578 | // TRUE: Si el proceso es correcto |
---|
| 579 | // FALSE: En caso de ocurrir algún error |
---|
| 580 | //______________________________________________________________________________________________________ |
---|
| 581 | |
---|
| 582 | char* LeeConfiguracion(char* dsk) |
---|
| 583 | { |
---|
| 584 | char* parametroscfg; |
---|
| 585 | char modulo[] = "LeeConfiguracion()"; |
---|
| 586 | |
---|
| 587 | parametroscfg=(char*)reservaMemoria(LONGITUD_PARAMETROS); |
---|
| 588 | if(!parametroscfg){ |
---|
| 589 | errorLog(modulo,3,FALSE); |
---|
| 590 | return(NULL); |
---|
| 591 | } |
---|
| 592 | sprintf(interface,"%s/%s",pathinterface,"getConfiguration"); |
---|
| 593 | herror=interfaceAdmin(interface,NULL,parametroscfg); |
---|
| 594 | |
---|
| 595 | if(herror){ // No se puede recuperar la configuración del cliente |
---|
| 596 | errorLog(modulo,36,FALSE); |
---|
| 597 | return(NULL); |
---|
| 598 | } |
---|
| 599 | return(parametroscfg); |
---|
| 600 | } |
---|
| 601 | //________________________________________________________________________________________________________ |
---|
| 602 | // Función: autoexecCliente |
---|
| 603 | // |
---|
| 604 | // Descripción: |
---|
| 605 | // Solicita procedimiento de autoexec para el cliebnte |
---|
| 606 | // Parámetros: |
---|
| 607 | // Ninguno |
---|
| 608 | // Devuelve: |
---|
| 609 | // TRUE: Si el proceso es correcto |
---|
| 610 | // FALSE: En caso de ocurrir algún error |
---|
| 611 | //________________________________________________________________________________________________________ |
---|
| 612 | BOOLEAN autoexecCliente(TRAMA* ptrTrama) |
---|
| 613 | { |
---|
| 614 | int lon; |
---|
| 615 | SOCKET socket_c; |
---|
| 616 | char modulo[] = "autoexecCliente()"; |
---|
| 617 | |
---|
| 618 | initParametros(ptrTrama,0); |
---|
| 619 | lon=sprintf(ptrTrama->parametros,"nfn=AutoexecCliente\rexe=%s\r",idproautoexec); |
---|
| 620 | |
---|
| 621 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 622 | errorLog(modulo,42,FALSE); |
---|
| 623 | return(FALSE); |
---|
| 624 | } |
---|
| 625 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 626 | if(!ptrTrama){ |
---|
| 627 | errorLog(modulo,45,FALSE); |
---|
| 628 | return(FALSE); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | close(socket_c); |
---|
| 632 | |
---|
| 633 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 634 | errorLog(modulo,39,FALSE); |
---|
| 635 | return(FALSE); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | return(TRUE); |
---|
| 639 | } |
---|
| 640 | //________________________________________________________________________________________________________ |
---|
| 641 | // Función: autoexecCliente |
---|
| 642 | // |
---|
| 643 | // Descripción: |
---|
| 644 | // Ejecuta un script de autoexec personalizado en todos los inicios para el cliente |
---|
| 645 | // Parámetros: |
---|
| 646 | // Ninguno |
---|
| 647 | // Devuelve: |
---|
| 648 | // TRUE: Si el proceso es correcto |
---|
| 649 | // FALSE: En caso de ocurrir algún error |
---|
| 650 | //________________________________________________________________________________________________________ |
---|
| 651 | BOOLEAN RESPUESTA_AutoexecCliente(TRAMA* ptrTrama) |
---|
| 652 | { |
---|
| 653 | SOCKET socket_c; |
---|
| 654 | char *res,*nfl; |
---|
| 655 | char modulo[] = "RESPUESTA_AutoexecCliente()"; |
---|
| 656 | |
---|
| 657 | res=copiaParametro("res",ptrTrama); |
---|
| 658 | if(atoi(res)==0){ // Error en el proceso de autoexec |
---|
| 659 | return (FALSE); |
---|
| 660 | } |
---|
| 661 | nfl=copiaParametro("nfl",ptrTrama); |
---|
| 662 | initParametros(ptrTrama,0); |
---|
| 663 | sprintf(ptrTrama->parametros,"nfn=enviaArchivo\rnfl=%s\r",nfl); |
---|
| 664 | /* Envía petición */ |
---|
| 665 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 666 | errorLog(modulo,42,FALSE); |
---|
| 667 | return(FALSE); |
---|
| 668 | } |
---|
| 669 | /* Nombre del archivo destino (local)*/ |
---|
| 670 | char fileautoexec[LONPRM]; |
---|
| 671 | sprintf(fileautoexec,"/tmp/_autoexec_%s",IPlocal); |
---|
| 672 | |
---|
| 673 | /* Recibe archivo */ |
---|
| 674 | if(!recArchivo(&socket_c,fileautoexec)){ |
---|
| 675 | errorLog(modulo,58, FALSE); |
---|
| 676 | close(socket_c); |
---|
| 677 | return(FALSE); |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | close(socket_c); |
---|
| 681 | |
---|
| 682 | /* Ejecuta archivo */ |
---|
| 683 | ejecutaArchivo(fileautoexec,ptrTrama); |
---|
| 684 | return(TRUE); |
---|
| 685 | } |
---|
| 686 | //______________________________________________________________________________________________________ |
---|
| 687 | // Función: comandosPendientes |
---|
| 688 | // |
---|
| 689 | // Descripción: |
---|
| 690 | // Búsqueda de acciones pendientes en el servidor de administración |
---|
| 691 | // Parámetros: |
---|
| 692 | // Ninguno |
---|
| 693 | // Devuelve: |
---|
| 694 | // TRUE: Si el proceso es correcto |
---|
| 695 | // FALSE: En caso de ocurrir algún error |
---|
| 696 | //______________________________________________________________________________________________________ |
---|
| 697 | BOOLEAN comandosPendientes(TRAMA* ptrTrama) |
---|
| 698 | { |
---|
| 699 | SOCKET socket_c; |
---|
| 700 | char modulo[] = "comandosPendientes()"; |
---|
| 701 | |
---|
| 702 | CMDPTES=TRUE; |
---|
| 703 | initParametros(ptrTrama,0); |
---|
| 704 | |
---|
| 705 | while(CMDPTES){ |
---|
| 706 | sprintf(ptrTrama->parametros,"nfn=ComandosPendientes\r"); |
---|
| 707 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 708 | errorLog(modulo,42,FALSE); |
---|
| 709 | return(FALSE); |
---|
| 710 | } |
---|
| 711 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 712 | if(!ptrTrama){ |
---|
| 713 | errorLog(modulo,45,FALSE); |
---|
| 714 | return(FALSE); |
---|
| 715 | } |
---|
| 716 | close(socket_c); |
---|
| 717 | |
---|
| 718 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 719 | errorLog(modulo,39,FALSE); |
---|
| 720 | return(FALSE); |
---|
| 721 | } |
---|
| 722 | } |
---|
| 723 | return(TRUE); |
---|
| 724 | } |
---|
| 725 | //______________________________________________________________________________________________________ |
---|
| 726 | // Función: NoComandosPtes |
---|
| 727 | // |
---|
| 728 | // Descripción: |
---|
| 729 | // Conmuta el switch de los comandos pendientes y lo pone a false |
---|
| 730 | // Parámetros: |
---|
| 731 | // - ptrTrama: contenido del mensaje |
---|
| 732 | // Devuelve: |
---|
| 733 | // TRUE siempre |
---|
| 734 | // Especificaciones: |
---|
| 735 | // Cuando se ejecuta esta función se sale del bucle que recupera los comandos pendientes en el |
---|
| 736 | // servidor y el cliente pasa a a estar disponible para recibir comandos desde el éste. |
---|
| 737 | //______________________________________________________________________________________________________ |
---|
| 738 | BOOLEAN NoComandosPtes(TRAMA* ptrTrama) |
---|
| 739 | { |
---|
| 740 | CMDPTES=FALSE; // Corta el bucle de comandos pendientes |
---|
| 741 | return(TRUE); |
---|
| 742 | } |
---|
| 743 | //______________________________________________________________________________________________________ |
---|
| 744 | // Función: ProcesaComandos |
---|
| 745 | // |
---|
| 746 | // Descripción: |
---|
| 747 | // Espera comando desde el Servidor de Administración para ejecutarlos |
---|
| 748 | // Parámetros: |
---|
| 749 | // Ninguno |
---|
| 750 | // Devuelve: |
---|
| 751 | // TRUE: Si el proceso es correcto |
---|
| 752 | // FALSE: En caso de ocurrir algún error |
---|
| 753 | // ________________________________________________________________________________________________________ |
---|
| 754 | void procesaComandos(TRAMA* ptrTrama) |
---|
| 755 | { |
---|
| 756 | int lon; |
---|
| 757 | SOCKET socket_c; |
---|
| 758 | char modulo[] = "procesaComandos()"; |
---|
| 759 | |
---|
| 760 | initParametros(ptrTrama,0); |
---|
| 761 | while(TRUE){ |
---|
| 762 | lon=sprintf(ptrTrama->parametros,"nfn=DisponibilidadComandos\r"); |
---|
| 763 | lon+=sprintf(ptrTrama->parametros+lon,"tpc=%s\r",CLIENTE_OPENGNSYS); // Activar disponibilidad |
---|
| 764 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_INFORMACION)){ |
---|
| 765 | errorLog(modulo,43,FALSE); |
---|
| 766 | return; |
---|
| 767 | } |
---|
| 768 | infoLog(19); // Disponibilidad de cliente activada |
---|
| 769 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 770 | if(!ptrTrama){ |
---|
| 771 | errorLog(modulo,46,FALSE); |
---|
| 772 | return; |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | close(socket_c); |
---|
| 776 | |
---|
| 777 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 778 | errorLog(modulo,39,FALSE); |
---|
| 779 | return; |
---|
| 780 | } |
---|
| 781 | if(!comandosPendientes(ptrTrama)){ |
---|
| 782 | errorLog(modulo,42,FALSE); |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | //______________________________________________________________________________________________________ |
---|
| 787 | // Función: Actualizar |
---|
| 788 | // |
---|
| 789 | // Descripción: |
---|
| 790 | // Actualiza los datos de un ordenador como si volviera a solicitar la entrada |
---|
| 791 | // en el sistema al servidor de administración |
---|
| 792 | // Parámetros: |
---|
| 793 | // ptrTrama: contenido del mensajede |
---|
| 794 | // Devuelve: |
---|
| 795 | // TRUE: Si el proceso es correcto |
---|
| 796 | // FALSE: En caso de ocurrir algún error |
---|
| 797 | //______________________________________________________________________________________________________ |
---|
| 798 | BOOLEAN Actualizar(TRAMA* ptrTrama) |
---|
| 799 | { |
---|
| 800 | char msglog[LONSTD]; |
---|
| 801 | char modulo[] = "Actualizar()"; |
---|
| 802 | |
---|
| 803 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 804 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 805 | infoDebug(msglog); |
---|
| 806 | } |
---|
| 807 | muestraMensaje(1,NULL); |
---|
| 808 | if(!comandosPendientes(ptrTrama)){ |
---|
| 809 | errorLog(modulo,84,FALSE); |
---|
| 810 | return(FALSE); |
---|
| 811 | } |
---|
| 812 | muestraMenu(); |
---|
| 813 | return(TRUE); |
---|
| 814 | } |
---|
| 815 | //______________________________________________________________________________________________________ |
---|
| 816 | // Función: Purgar |
---|
| 817 | // |
---|
| 818 | // Descripción: |
---|
| 819 | // Detiene la ejecución del browser |
---|
| 820 | // Parámetros: |
---|
| 821 | // ptrTrama: contenido del mensajede |
---|
| 822 | // Devuelve: |
---|
| 823 | // TRUE: Si el proceso es correcto |
---|
| 824 | // FALSE: En caso de ocurrir algún error |
---|
| 825 | //______________________________________________________________________________________________________ |
---|
| 826 | int Purgar(TRAMA* ptrTrama) |
---|
| 827 | { |
---|
| 828 | int resul=0; |
---|
| 829 | char modulo[] = "Purgar()"; |
---|
| 830 | |
---|
| 831 | if(pidbrowser>0) |
---|
| 832 | kill(pidbrowser,SIGQUIT); // Destruye el proceso hijo anterior y se queda sólo el actual |
---|
| 833 | |
---|
| 834 | if(pidbash>0) |
---|
| 835 | kill(pidbash,SIGQUIT); // Destruye el proceso hijo del proceso bash si existiera una conmutación |
---|
| 836 | |
---|
| 837 | sprintf(interface,"/opt/opengnsys/bin/bash"); |
---|
| 838 | if((pidbash=fork())==0){ |
---|
| 839 | /* Proceso hijo que ejecuta el script */ |
---|
| 840 | resul=execv(interface,NULL); |
---|
| 841 | exit(resul); |
---|
| 842 | } |
---|
| 843 | else { |
---|
| 844 | if (pidbash ==-1){ |
---|
| 845 | scriptLog(modulo,10); |
---|
| 846 | resul=13; |
---|
| 847 | scriptLog(modulo,resul); |
---|
| 848 | return(resul); |
---|
| 849 | } |
---|
| 850 | } |
---|
| 851 | exit(EXIT_SUCCESS); |
---|
| 852 | } |
---|
| 853 | //______________________________________________________________________________________________________ |
---|
| 854 | // Función: Sondeo |
---|
| 855 | // |
---|
| 856 | // Descripción: |
---|
| 857 | // Envía al servidor una confirmación de que está dentro del sistema |
---|
| 858 | // Parámetros: |
---|
| 859 | // ptrTrama: contenido del mensajede |
---|
| 860 | // Devuelve: |
---|
| 861 | // TRUE: Si el proceso es correcto |
---|
| 862 | // FALSE: En caso de ocurrir algún error |
---|
| 863 | //______________________________________________________________________________________________________ |
---|
| 864 | BOOLEAN Sondeo(TRAMA* ptrTrama) |
---|
| 865 | { |
---|
| 866 | return(TRUE); |
---|
| 867 | } |
---|
| 868 | //______________________________________________________________________________________________________ |
---|
| 869 | // Función: ConsolaRemota |
---|
| 870 | // |
---|
| 871 | // Descripción: |
---|
| 872 | // Ejecuta un comando de la Shell y envia el eco al servidor (Consola remota) |
---|
| 873 | // Parámetros: |
---|
| 874 | // ptrTrama: contenido del mensaje |
---|
| 875 | // Devuelve: |
---|
| 876 | // TRUE: Si el proceso es correcto |
---|
| 877 | // FALSE: En caso de ocurrir algún error |
---|
| 878 | //______________________________________________________________________________________________________ |
---|
| 879 | BOOLEAN ConsolaRemota(TRAMA* ptrTrama) |
---|
| 880 | { |
---|
| 881 | SOCKET socket_c; |
---|
| 882 | char *nfn,*ids,*scp,ecosrc[LONPRM],ecodst[LONPRM],msglog[LONSTD];; |
---|
| 883 | char modulo[] = "ConsolaRemota()"; |
---|
| 884 | |
---|
| 885 | scp=URLDecode(copiaParametro("scp",ptrTrama)); |
---|
| 886 | |
---|
| 887 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 888 | ids=copiaParametro("ids",ptrTrama); |
---|
| 889 | |
---|
| 890 | /* Nombre del archivo de script */ |
---|
| 891 | char filescript[LONPRM]; |
---|
| 892 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
| 893 | escribeArchivo(filescript,scp); |
---|
| 894 | |
---|
| 895 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 896 | sprintf(ecosrc,"/tmp/_econsola_%s",IPlocal); |
---|
| 897 | sprintf(parametros,"%s %s %s",nfn,filescript,ecosrc); |
---|
| 898 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 899 | if(herror){ |
---|
| 900 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 901 | errorInfo(modulo,msglog); |
---|
| 902 | } |
---|
| 903 | else{ |
---|
| 904 | /* Envía fichero de inventario al servidor */ |
---|
| 905 | sprintf(ecodst,"/tmp/_Seconsola_%s",IPlocal); // Nombre que tendra el archivo en el Servidor |
---|
| 906 | initParametros(ptrTrama,0); |
---|
| 907 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",ecodst); |
---|
| 908 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
| 909 | errorLog(modulo,42,FALSE); |
---|
| 910 | return(FALSE); |
---|
| 911 | } |
---|
| 912 | /* Espera señal para comenzar el envío */ |
---|
| 913 | recibeFlag(&socket_c,ptrTrama); |
---|
| 914 | /* Envía archivo */ |
---|
| 915 | if(!sendArchivo(&socket_c,ecosrc)){ |
---|
| 916 | errorLog(modulo,57, FALSE); |
---|
| 917 | herror=12; // Error de envío de fichero por la red |
---|
| 918 | } |
---|
| 919 | close(socket_c); |
---|
| 920 | } |
---|
| 921 | return(TRUE); |
---|
| 922 | } |
---|
| 923 | //_____________________________________________________________________________________________________ |
---|
| 924 | // Función: Comando |
---|
| 925 | // |
---|
| 926 | // Descripción: |
---|
| 927 | // COmando personalizado enviado desde el servidor |
---|
| 928 | // Parámetros: |
---|
| 929 | // ptrTrama: contenido del mensaje |
---|
| 930 | // Devuelve: |
---|
| 931 | // TRUE: Si el proceso es correcto |
---|
| 932 | // FALSE: En caso de ocurrir algún error |
---|
| 933 | //_____________________________________________________________________________________________________ |
---|
| 934 | BOOLEAN Comando(TRAMA* ptrTrama) |
---|
| 935 | { |
---|
| 936 | int lon; |
---|
| 937 | char *ids,*nfn,msglog[LONSTD]; |
---|
| 938 | char modulo[] = "Comando()"; |
---|
| 939 | |
---|
| 940 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 941 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 942 | infoDebug(msglog); |
---|
| 943 | } |
---|
| 944 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 945 | ids=copiaParametro("ids",ptrTrama); |
---|
| 946 | |
---|
| 947 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 948 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
| 949 | if(herror){ |
---|
| 950 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 951 | errorInfo(modulo,msglog); |
---|
| 952 | } |
---|
| 953 | /* Envia respuesta de ejecucución del comando */ |
---|
| 954 | initParametros(ptrTrama,0); |
---|
| 955 | lon=sprintf(ptrTrama->parametros,"nfn=RESPUESTA_%s\r",nfn); |
---|
| 956 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 957 | return(TRUE); |
---|
| 958 | } |
---|
| 959 | //_____________________________________________________________________________________________________ |
---|
| 960 | // Función: Arrancar |
---|
| 961 | // |
---|
| 962 | // Descripción: |
---|
| 963 | // Responde a un comando de encendido por la red |
---|
| 964 | // Parámetros: |
---|
| 965 | // ptrTrama: contenido del mensaje |
---|
| 966 | // Devuelve: |
---|
| 967 | // TRUE: Si el proceso es correcto |
---|
| 968 | // FALSE: En caso de ocurrir algún error |
---|
| 969 | //_____________________________________________________________________________________________________ |
---|
| 970 | BOOLEAN Arrancar(TRAMA* ptrTrama) |
---|
| 971 | { |
---|
| 972 | int lon; |
---|
| 973 | char *ids,msglog[LONSTD]; |
---|
| 974 | char modulo[] = "Arrancar()"; |
---|
| 975 | |
---|
| 976 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 977 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 978 | infoDebug(msglog); |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | ids=copiaParametro("ids",ptrTrama); |
---|
| 982 | |
---|
| 983 | /* Envia respuesta de ejecucución del script */ |
---|
| 984 | initParametros(ptrTrama,0); |
---|
| 985 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Arrancar"); |
---|
| 986 | lon+=sprintf(ptrTrama->parametros+lon,"tpc=%s\r",CLIENTE_OPENGNSYS); |
---|
| 987 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 988 | return(TRUE); |
---|
| 989 | } |
---|
| 990 | //_____________________________________________________________________________________________________ |
---|
| 991 | // Función: Apagar |
---|
| 992 | // |
---|
| 993 | // Descripción: |
---|
| 994 | // Apaga el cliente |
---|
| 995 | // Parámetros: |
---|
| 996 | // ptrTrama: contenido del mensaje |
---|
| 997 | // Devuelve: |
---|
| 998 | // TRUE: Si el proceso es correcto |
---|
| 999 | // FALSE: En caso de ocurrir algún error |
---|
| 1000 | //_____________________________________________________________________________________________________ |
---|
| 1001 | BOOLEAN Apagar(TRAMA* ptrTrama) |
---|
| 1002 | { |
---|
| 1003 | int lon; |
---|
| 1004 | char *ids,*nfn,msglog[LONSTD]; |
---|
| 1005 | char modulo[] = "Apagar()"; |
---|
| 1006 | |
---|
| 1007 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1008 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1009 | infoDebug(msglog); |
---|
| 1010 | } |
---|
| 1011 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1012 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1013 | |
---|
| 1014 | initParametros(ptrTrama,0); |
---|
| 1015 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Apagar"); |
---|
| 1016 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 1017 | |
---|
| 1018 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1019 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
| 1020 | if(herror){ |
---|
| 1021 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1022 | errorInfo(modulo,msglog); |
---|
| 1023 | return(FALSE); |
---|
| 1024 | } |
---|
| 1025 | return(TRUE); |
---|
| 1026 | } |
---|
| 1027 | //_____________________________________________________________________________________________________ |
---|
| 1028 | // Función: Reiniciar |
---|
| 1029 | // |
---|
| 1030 | // Descripción: |
---|
| 1031 | // Apaga el cliente |
---|
| 1032 | // Parámetros: |
---|
| 1033 | // ptrTrama: contenido del mensaje |
---|
| 1034 | // Devuelve: |
---|
| 1035 | // TRUE: Si el proceso es correcto |
---|
| 1036 | // FALSE: En caso de ocurrir algún error |
---|
| 1037 | //_____________________________________________________________________________________________________ |
---|
| 1038 | BOOLEAN Reiniciar(TRAMA* ptrTrama) |
---|
| 1039 | { |
---|
| 1040 | int lon; |
---|
| 1041 | char *nfn,*ids,msglog[LONSTD]; |
---|
| 1042 | char modulo[] = "Reiniciar()"; |
---|
| 1043 | |
---|
| 1044 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1045 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1046 | infoDebug(msglog); |
---|
| 1047 | } |
---|
| 1048 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1049 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1050 | |
---|
| 1051 | initParametros(ptrTrama,0); |
---|
| 1052 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Reiniciar"); |
---|
| 1053 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 1054 | |
---|
| 1055 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1056 | herror=interfaceAdmin(interface,NULL,NULL); |
---|
| 1057 | if(herror){ |
---|
| 1058 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1059 | errorInfo(modulo,msglog); |
---|
| 1060 | return(FALSE); |
---|
| 1061 | } |
---|
| 1062 | return(TRUE); |
---|
| 1063 | } |
---|
| 1064 | //_____________________________________________________________________________________________________ |
---|
| 1065 | // Función: IniciarSesion |
---|
| 1066 | // |
---|
| 1067 | // Descripción: |
---|
| 1068 | // Inicia sesión en el Sistema Operativo de una de las particiones |
---|
| 1069 | // Parámetros: |
---|
| 1070 | // ptrTrama: contenido del mensaje |
---|
| 1071 | // Devuelve: |
---|
| 1072 | // TRUE: Si el proceso es correcto |
---|
| 1073 | // FALSE: En caso de ocurrir algún error |
---|
| 1074 | //_____________________________________________________________________________________________________ |
---|
| 1075 | BOOLEAN IniciarSesion(TRAMA* ptrTrama) |
---|
| 1076 | { |
---|
| 1077 | int lon; |
---|
| 1078 | char *nfn,*ids,*par,msglog[LONSTD]; |
---|
| 1079 | char modulo[] = "IniciarSesion()"; |
---|
| 1080 | |
---|
| 1081 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1082 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1083 | infoDebug(msglog); |
---|
| 1084 | } |
---|
| 1085 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1086 | ids=copiaParametro("ids",ptrTrama); |
---|
[179ccd2] | 1087 | par=copiaParametro("par",ptrTrama); |
---|
| 1088 | |
---|
[3ec149c] | 1089 | initParametros(ptrTrama,0); |
---|
| 1090 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_IniciarSesion"); |
---|
| 1091 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 1092 | |
---|
| 1093 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1094 | sprintf(parametros,"%s %s",nfn,par); |
---|
| 1095 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1096 | |
---|
| 1097 | if(herror){ |
---|
| 1098 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1099 | errorInfo(modulo,msglog); |
---|
| 1100 | return(FALSE); |
---|
| 1101 | } |
---|
| 1102 | return(TRUE); |
---|
| 1103 | } |
---|
| 1104 | //______________________________________________________________________________________________________ |
---|
| 1105 | // Función: CrearImagen |
---|
| 1106 | // |
---|
| 1107 | // Descripción: |
---|
| 1108 | // Crea una imagen de una partición |
---|
| 1109 | // Parámetros: |
---|
| 1110 | // ptrTrama: contenido del mensaje |
---|
| 1111 | // Devuelve: |
---|
| 1112 | // TRUE: Si el proceso es correcto |
---|
| 1113 | // FALSE: En caso de ocurrir algún error |
---|
| 1114 | //______________________________________________________________________________________________________ |
---|
| 1115 | BOOLEAN CrearImagen(TRAMA* ptrTrama) |
---|
| 1116 | { |
---|
| 1117 | int lon; |
---|
| 1118 | char *nfn,*dsk,*par,*cpt,*idi,*ipr,*nci,*ids,msglog[LONSTD]; |
---|
| 1119 | char modulo[] = "CrearImagen()"; |
---|
| 1120 | |
---|
| 1121 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1122 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1123 | infoDebug(msglog); |
---|
| 1124 | } |
---|
| 1125 | |
---|
| 1126 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1127 | par=copiaParametro("par",ptrTrama); // Número de partición |
---|
| 1128 | cpt=copiaParametro("cpt",ptrTrama); // Código de la partición |
---|
| 1129 | idi=copiaParametro("idi",ptrTrama); // Identificador de la imagen |
---|
| 1130 | nci=copiaParametro("nci",ptrTrama); // Nombre canónico de la imagen |
---|
| 1131 | ipr=copiaParametro("ipr",ptrTrama); // Ip del repositorio |
---|
| 1132 | |
---|
| 1133 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1134 | ids=copiaParametro("ids",ptrTrama); |
---|
[eb9424f] | 1135 | muestraMensaje(7,NULL); |
---|
[3ec149c] | 1136 | if(InventariandoSoftware(ptrTrama,FALSE,"InventarioSoftware")){ // Crea inventario Software previamente |
---|
| 1137 | muestraMensaje(2,NULL); |
---|
| 1138 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1139 | sprintf(parametros,"%s %s %s %s %s",nfn,dsk,par,nci,ipr); |
---|
| 1140 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1141 | if(herror){ |
---|
| 1142 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1143 | errorInfo(modulo,msglog); |
---|
| 1144 | muestraMensaje(10,NULL); |
---|
| 1145 | } |
---|
| 1146 | else |
---|
| 1147 | muestraMensaje(9,NULL); |
---|
| 1148 | } |
---|
| 1149 | else{ |
---|
| 1150 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1151 | errorInfo(modulo,msglog); |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | muestraMenu(); |
---|
| 1155 | |
---|
| 1156 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1157 | initParametros(ptrTrama,0); |
---|
| 1158 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_CrearImagen"); |
---|
| 1159 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1160 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición de donde se creó |
---|
| 1161 | lon+=sprintf(ptrTrama->parametros+lon,"cpt=%s\r",cpt); // Tipo o código de partición |
---|
| 1162 | lon+=sprintf(ptrTrama->parametros+lon,"ipr=%s\r",ipr); // Ip del repositorio donde se alojó |
---|
| 1163 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1164 | return(TRUE); |
---|
| 1165 | } |
---|
| 1166 | //______________________________________________________________________________________________________ |
---|
| 1167 | // Función: RestaurarImagen |
---|
| 1168 | // |
---|
| 1169 | // Descripción: |
---|
| 1170 | // Restaura una imagen en una partición |
---|
| 1171 | // Parámetros: |
---|
| 1172 | // ptrTrama: contenido del mensaje |
---|
| 1173 | // Devuelve: |
---|
| 1174 | // TRUE: Si el proceso es correcto |
---|
| 1175 | // FALSE: En caso de ocurrir algún error |
---|
| 1176 | //______________________________________________________________________________________________________ |
---|
| 1177 | BOOLEAN RestaurarImagen(TRAMA* ptrTrama) |
---|
| 1178 | { |
---|
| 1179 | int lon; |
---|
| 1180 | char *nfn,*dsk,*par,*idi,*ipr,*ifs,*nci,*ids,*ptc,msglog[LONSTD]; |
---|
| 1181 | char modulo[] = "RestaurarImagen()"; |
---|
| 1182 | |
---|
| 1183 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1184 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1185 | infoDebug(msglog); |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1189 | par=copiaParametro("par",ptrTrama); |
---|
| 1190 | idi=copiaParametro("idi",ptrTrama); |
---|
| 1191 | ipr=copiaParametro("ipr",ptrTrama); |
---|
| 1192 | nci=copiaParametro("nci",ptrTrama); |
---|
| 1193 | ifs=copiaParametro("ifs",ptrTrama); |
---|
| 1194 | ptc=copiaParametro("ptc",ptrTrama); |
---|
| 1195 | |
---|
| 1196 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1197 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1198 | muestraMensaje(3,NULL); |
---|
| 1199 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
[eb9424f] | 1200 | sprintf(parametros,"%s %s %s %s %s %s",nfn,dsk,par,nci,ipr,ptc); |
---|
[3ec149c] | 1201 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1202 | if(herror){ |
---|
| 1203 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1204 | errorInfo(modulo,msglog); |
---|
| 1205 | muestraMensaje(12,NULL); |
---|
| 1206 | } |
---|
| 1207 | else |
---|
| 1208 | muestraMensaje(11,NULL); |
---|
| 1209 | |
---|
| 1210 | muestraMenu(); |
---|
| 1211 | |
---|
| 1212 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1213 | initParametros(ptrTrama,0); |
---|
| 1214 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_RestaurarImagen"); |
---|
| 1215 | lon+=sprintf(ptrTrama->parametros+lon,"idi=%s\r",idi); // Identificador de la imagen |
---|
| 1216 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); // Número de partición |
---|
| 1217 | lon+=sprintf(ptrTrama->parametros+lon,"ifs=%s\r",ifs); // Identificador del perfil software |
---|
| 1218 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1219 | return(TRUE); |
---|
| 1220 | } |
---|
| 1221 | //______________________________________________________________________________________________________ |
---|
| 1222 | // Función: Configurar |
---|
| 1223 | // |
---|
| 1224 | // Descripción: |
---|
| 1225 | // Configura la tabla de particiones y formatea |
---|
| 1226 | // Parámetros: |
---|
| 1227 | // ptrTrama: contenido del mensaje |
---|
| 1228 | // Devuelve: |
---|
| 1229 | // TRUE: Si el proceso es correcto |
---|
| 1230 | // FALSE: En caso de ocurrir algún error |
---|
| 1231 | //______________________________________________________________________________________________________ |
---|
| 1232 | BOOLEAN Configurar(TRAMA* ptrTrama) |
---|
| 1233 | { |
---|
| 1234 | int lon; |
---|
| 1235 | char *nfn,*dsk,*cfg,*ids,msglog[LONSTD]; |
---|
| 1236 | char modulo[] = "Configurar()"; |
---|
| 1237 | |
---|
| 1238 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1239 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1240 | infoDebug(msglog); |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | dsk=copiaParametro("dsk",ptrTrama); |
---|
| 1244 | cfg=copiaParametro("cfg",ptrTrama); |
---|
| 1245 | /* Sustituir caracteres */ |
---|
| 1246 | sustituir(cfg,'\n','$'); |
---|
| 1247 | sustituir(cfg,'\t','#'); |
---|
| 1248 | |
---|
| 1249 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1250 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1251 | muestraMensaje(4,NULL); |
---|
| 1252 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1253 | sprintf(parametros,"%s %s %s'",nfn,dsk,cfg); |
---|
| 1254 | |
---|
| 1255 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1256 | if(herror){ |
---|
| 1257 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1258 | errorInfo(modulo,msglog); |
---|
| 1259 | muestraMensaje(13,NULL); |
---|
| 1260 | } |
---|
| 1261 | else |
---|
| 1262 | muestraMensaje(14,NULL); |
---|
| 1263 | |
---|
| 1264 | muestraMenu(); |
---|
| 1265 | |
---|
| 1266 | cfg=LeeConfiguracion(dsk); |
---|
| 1267 | if(!cfg){ // No se puede recuperar la configuración del cliente |
---|
| 1268 | errorLog(modulo,36,FALSE); |
---|
| 1269 | return(FALSE); |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | /* Envia respuesta de ejecución del comando*/ |
---|
| 1273 | initParametros(ptrTrama,0); |
---|
| 1274 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Configurar"); |
---|
| 1275 | lon+=sprintf(ptrTrama->parametros+lon,"cfg=%s\r",cfg); // Identificador de la imagen |
---|
| 1276 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1277 | return(TRUE); |
---|
| 1278 | } |
---|
| 1279 | // ________________________________________________________________________________________________________ |
---|
| 1280 | // Función: InventarioHardware |
---|
| 1281 | // |
---|
| 1282 | // Descripción: |
---|
| 1283 | // Envia al servidor el nombre del archivo de inventario de su hardware para posteriormente |
---|
| 1284 | // esperar que éste lo solicite y enviarlo por la red. |
---|
| 1285 | // Parámetros: |
---|
| 1286 | // ptrTrama: contenido del mensaje |
---|
| 1287 | // Devuelve: |
---|
| 1288 | // TRUE: Si el proceso es correcto |
---|
| 1289 | // FALSE: En caso de ocurrir algún error |
---|
| 1290 | //______________________________________________________________________________________________________ |
---|
| 1291 | BOOLEAN InventarioHardware(TRAMA* ptrTrama) |
---|
| 1292 | { |
---|
| 1293 | int lon; |
---|
| 1294 | SOCKET socket_c; |
---|
| 1295 | char *nfn,*ids,msglog[LONSTD],hrdsrc[LONPRM],hrddst[LONPRM]; |
---|
| 1296 | char modulo[] = "InventarioHardware()"; |
---|
| 1297 | |
---|
| 1298 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1299 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1300 | infoDebug(msglog); |
---|
| 1301 | } |
---|
| 1302 | |
---|
| 1303 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1304 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1305 | muestraMensaje(6,NULL); |
---|
| 1306 | |
---|
| 1307 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1308 | sprintf(hrdsrc,"/tmp/Chrd-%s",IPlocal); // Nombre que tendra el archivo de inventario |
---|
| 1309 | sprintf(parametros,"%s %s",nfn,hrdsrc); |
---|
| 1310 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1311 | if(herror){ |
---|
| 1312 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1313 | errorInfo(modulo,msglog); |
---|
| 1314 | muestraMensaje(18,NULL); |
---|
| 1315 | } |
---|
| 1316 | else{ |
---|
| 1317 | /* Envía fichero de inventario al servidor */ |
---|
| 1318 | sprintf(hrddst,"/tmp/Shrd-%s",IPlocal); // Nombre que tendra el archivo en el Servidor |
---|
| 1319 | initParametros(ptrTrama,0); |
---|
| 1320 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",hrddst); |
---|
| 1321 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
| 1322 | errorLog(modulo,42,FALSE); |
---|
| 1323 | return(FALSE); |
---|
| 1324 | } |
---|
| 1325 | /* Espera señal para comenzar el envío */ |
---|
| 1326 | recibeFlag(&socket_c,ptrTrama); |
---|
| 1327 | /* Envía archivo */ |
---|
| 1328 | if(!sendArchivo(&socket_c,hrdsrc)){ |
---|
| 1329 | errorLog(modulo,57, FALSE); |
---|
| 1330 | herror=12; // Error de envío de fichero por la red |
---|
| 1331 | } |
---|
| 1332 | close(socket_c); |
---|
| 1333 | muestraMensaje(17,NULL); |
---|
| 1334 | } |
---|
| 1335 | muestraMenu(); |
---|
| 1336 | |
---|
| 1337 | /* Envia respuesta de ejecución de la función de interface */ |
---|
| 1338 | initParametros(ptrTrama,0); |
---|
| 1339 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioHardware"); |
---|
| 1340 | lon+=sprintf(ptrTrama->parametros+lon,"hrd=%s\r",hrddst); |
---|
| 1341 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1342 | return(TRUE); |
---|
| 1343 | } |
---|
| 1344 | // ________________________________________________________________________________________________________ |
---|
| 1345 | // Función: InventarioSoftware |
---|
| 1346 | // |
---|
| 1347 | // Descripción: |
---|
| 1348 | // Crea el inventario software de un sistema operativo instalado en una partición. |
---|
| 1349 | // Parámetros: |
---|
| 1350 | // ptrTrama: contenido del mensaje |
---|
| 1351 | // Devuelve: |
---|
| 1352 | // TRUE: Si el proceso es correcto |
---|
| 1353 | // FALSE: En caso de ocurrir algún error |
---|
| 1354 | //______________________________________________________________________________________________________ |
---|
| 1355 | BOOLEAN InventarioSoftware(TRAMA* ptrTrama) |
---|
| 1356 | { |
---|
| 1357 | char *nfn,*ids,msglog[LONSTD]; |
---|
| 1358 | char modulo[] = "InventarioSoftware()"; |
---|
| 1359 | |
---|
| 1360 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1361 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1362 | infoDebug(msglog); |
---|
| 1363 | } |
---|
| 1364 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1365 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1366 | muestraMensaje(7,NULL); |
---|
| 1367 | InventariandoSoftware(ptrTrama,TRUE,nfn); |
---|
| 1368 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1369 | muestraMenu(); |
---|
| 1370 | return(TRUE); |
---|
| 1371 | } |
---|
| 1372 | // ________________________________________________________________________________________________________ |
---|
| 1373 | // |
---|
| 1374 | // Función: InventariandoSoftware |
---|
| 1375 | // |
---|
| 1376 | // Descripción: |
---|
| 1377 | // Envia al servidor el nombre del archivo de inventario de su software para posteriormente |
---|
| 1378 | // esperar que éste lo solicite y enviarlo por la red. |
---|
| 1379 | // Parámetros: |
---|
| 1380 | // ptrTrama: contenido del mensaje |
---|
| 1381 | // sw: switch que indica si la función es llamada por el comando InventarioSoftware(true) o CrearImagen(false) |
---|
| 1382 | // nfn: Nombre de la función del Interface que implementa el comando |
---|
| 1383 | // Devuelve: |
---|
| 1384 | // TRUE: Si el proceso es correcto |
---|
| 1385 | // FALSE: En caso de ocurrir algún error |
---|
| 1386 | //______________________________________________________________________________________________________ |
---|
| 1387 | BOOLEAN InventariandoSoftware(TRAMA* ptrTrama,BOOLEAN sw,char *nfn) |
---|
| 1388 | { |
---|
| 1389 | int lon; |
---|
| 1390 | SOCKET socket_c; |
---|
| 1391 | char *dsk,*par,msglog[LONSTD],sftsrc[LONPRM],sftdst[LONPRM]; |
---|
| 1392 | char modulo[] = "InventariandoSoftware()"; |
---|
| 1393 | |
---|
| 1394 | dsk=copiaParametro("dsk",ptrTrama); // Disco |
---|
| 1395 | par=copiaParametro("par",ptrTrama); |
---|
| 1396 | |
---|
| 1397 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1398 | sprintf(sftsrc,"/tmp/CSft-%s-%s",IPlocal,par); // Nombre que tendra el archivo de inventario |
---|
| 1399 | sprintf(parametros,"%s %s %s %s",nfn,dsk,par,sftsrc); |
---|
| 1400 | |
---|
| 1401 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1402 | herror=0; |
---|
| 1403 | if(herror){ |
---|
| 1404 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1405 | errorInfo(modulo,msglog); |
---|
| 1406 | muestraMensaje(20,NULL); |
---|
| 1407 | } |
---|
| 1408 | else{ |
---|
| 1409 | /* Envía fichero de inventario al servidor */ |
---|
| 1410 | sprintf(sftdst,"/tmp/Ssft-%s-%s",IPlocal,par); // Nombre que tendra el archivo en el Servidor |
---|
| 1411 | initParametros(ptrTrama,0); |
---|
| 1412 | |
---|
| 1413 | sprintf(ptrTrama->parametros,"nfn=recibeArchivo\rnfl=%s\r",sftdst); |
---|
| 1414 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_COMANDO)){ |
---|
| 1415 | errorLog(modulo,42,FALSE); |
---|
| 1416 | return(FALSE); |
---|
| 1417 | } |
---|
| 1418 | /* Espera señal para comenzar el envío */ |
---|
| 1419 | if(!recibeFlag(&socket_c,ptrTrama)){ |
---|
| 1420 | errorLog(modulo,17,FALSE); |
---|
| 1421 | } |
---|
| 1422 | /* Envía archivo */ |
---|
| 1423 | if(!sendArchivo(&socket_c,sftsrc)){ |
---|
| 1424 | errorLog(modulo,57, FALSE); |
---|
| 1425 | herror=12; // Error de envío de fichero por la red |
---|
| 1426 | } |
---|
| 1427 | close(socket_c); |
---|
| 1428 | muestraMensaje(19,NULL); |
---|
| 1429 | } |
---|
| 1430 | initParametros(ptrTrama,0); |
---|
| 1431 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_InventarioSoftware"); |
---|
| 1432 | lon+=sprintf(ptrTrama->parametros+lon,"par=%s\r",par); |
---|
| 1433 | lon+=sprintf(ptrTrama->parametros+lon,"sft=%s\r",sftdst); |
---|
| 1434 | if(!sw) |
---|
| 1435 | respuestaEjecucionComando(ptrTrama,herror,"0"); |
---|
| 1436 | |
---|
| 1437 | return(TRUE); |
---|
| 1438 | } |
---|
| 1439 | // ________________________________________________________________________________________________________ |
---|
| 1440 | // Función: EjecutarScript |
---|
| 1441 | // |
---|
| 1442 | // Descripción: |
---|
| 1443 | // Ejecuta código de script |
---|
| 1444 | // Parámetros: |
---|
| 1445 | // ptrTrama: contenido del mensaje |
---|
| 1446 | // Devuelve: |
---|
| 1447 | // TRUE: Si el proceso es correcto |
---|
| 1448 | // FALSE: En caso de ocurrir algún error |
---|
| 1449 | //______________________________________________________________________________________________________ |
---|
| 1450 | BOOLEAN EjecutarScript(TRAMA* ptrTrama) |
---|
| 1451 | { |
---|
| 1452 | int lon; |
---|
| 1453 | char *nfn,*ids,*scp,msglog[LONSTD]; |
---|
| 1454 | char modulo[] = "EjecutarScript()"; |
---|
| 1455 | |
---|
| 1456 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 1457 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 1458 | infoDebug(msglog); |
---|
| 1459 | } |
---|
| 1460 | scp=URLDecode(copiaParametro("scp",ptrTrama)); |
---|
| 1461 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1462 | |
---|
| 1463 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 1464 | ids=copiaParametro("ids",ptrTrama); |
---|
| 1465 | muestraMensaje(8,NULL); |
---|
| 1466 | /* Nombre del archivo de script */ |
---|
| 1467 | char filescript[LONPRM]; |
---|
| 1468 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
| 1469 | escribeArchivo(filescript,scp); |
---|
| 1470 | sprintf(interface,"%s/%s",pathinterface,nfn); |
---|
| 1471 | sprintf(parametros,"%s %s",nfn,filescript); |
---|
| 1472 | herror=interfaceAdmin(interface,parametros,NULL); |
---|
| 1473 | if(herror){ |
---|
| 1474 | sprintf(msglog,"%s:%s",tbErrores[86],nfn); |
---|
| 1475 | errorInfo(modulo,msglog); |
---|
| 1476 | muestraMensaje(21,NULL); |
---|
| 1477 | } |
---|
| 1478 | else |
---|
| 1479 | muestraMensaje(22,NULL); |
---|
| 1480 | muestraMenu(); |
---|
| 1481 | //herror=ejecutarCodigoBash(scp); |
---|
| 1482 | initParametros(ptrTrama,0); |
---|
| 1483 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_EjecutarScript"); |
---|
| 1484 | respuestaEjecucionComando(ptrTrama,herror,ids); |
---|
| 1485 | return(TRUE); |
---|
| 1486 | } |
---|
| 1487 | //______________________________________________________________________________________________________ |
---|
| 1488 | // Función: respuestaEjecucionComando |
---|
| 1489 | // |
---|
| 1490 | // Descripción: |
---|
| 1491 | // Envia una respuesta a una ejecucion de comando al servidor de Administración |
---|
| 1492 | // Parámetros: |
---|
| 1493 | // - ptrTrama: contenido del mensaje |
---|
| 1494 | // - res: Resultado de la ejecución (Código de error devuelto por el script ejecutado) |
---|
| 1495 | // - ids: Identificador de la sesion (En caso de no haber seguimiento es NULO) |
---|
| 1496 | // Devuelve: |
---|
| 1497 | // TRUE: Si el proceso es correcto |
---|
| 1498 | // FALSE: En caso de ocurrir algún error |
---|
| 1499 | // ________________________________________________________________________________________________________ |
---|
| 1500 | BOOLEAN respuestaEjecucionComando(TRAMA* ptrTrama,int res,char *ids) |
---|
| 1501 | { |
---|
| 1502 | int lon; |
---|
| 1503 | SOCKET socket_c; |
---|
| 1504 | char modulo[] = "respuestaEjecucionComando()"; |
---|
| 1505 | |
---|
| 1506 | lon=strlen(ptrTrama->parametros); |
---|
| 1507 | if(ids){ // Existe seguimiento |
---|
| 1508 | lon+=sprintf(ptrTrama->parametros+lon,"ids=%s\r",ids); // Añade identificador de la sesión |
---|
| 1509 | } |
---|
| 1510 | if (res==0){ // Resultado satisfactorio |
---|
| 1511 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","1"); |
---|
| 1512 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",""); |
---|
| 1513 | } |
---|
| 1514 | else{ // Algún error |
---|
| 1515 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","2"); |
---|
| 1516 | if(res>MAXERRORSCRIPT) |
---|
| 1517 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s (Error de script:%d)\r",tbErroresScripts[MAXERRORSCRIPT],res);// Descripción del error |
---|
| 1518 | else |
---|
| 1519 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",tbErroresScripts[res]);// Descripción del error |
---|
| 1520 | } |
---|
| 1521 | if(!(enviaMensajeServidor(&socket_c,ptrTrama,MSG_NOTIFICACION))){ |
---|
| 1522 | errorLog(modulo,44,FALSE); |
---|
| 1523 | return(FALSE); |
---|
| 1524 | } |
---|
| 1525 | close(socket_c); |
---|
| 1526 | return(TRUE); |
---|
| 1527 | } |
---|
| 1528 | // ________________________________________________________________________________________________________ |
---|
| 1529 | // Función: gestionaTrama |
---|
| 1530 | // |
---|
| 1531 | // Descripción: |
---|
| 1532 | // Procesa las tramas recibidas. |
---|
| 1533 | // Parametros: |
---|
| 1534 | // ptrTrama: contenido del mensaje |
---|
| 1535 | // Devuelve: |
---|
| 1536 | // TRUE: Si el proceso es correcto |
---|
| 1537 | // FALSE: En caso de ocurrir algún error |
---|
| 1538 | // ________________________________________________________________________________________________________ |
---|
| 1539 | BOOLEAN gestionaTrama(TRAMA *ptrTrama) |
---|
| 1540 | { |
---|
| 1541 | int i, res; |
---|
| 1542 | char *nfn; |
---|
| 1543 | char modulo[] = "gestionaTrama()"; |
---|
| 1544 | |
---|
| 1545 | INTROaFINCAD(ptrTrama); |
---|
| 1546 | nfn = copiaParametro("nfn", ptrTrama); // Toma nombre de función |
---|
| 1547 | for (i = 0; i < MAXIMAS_FUNCIONES; i++) { // Recorre funciones que procesan las tramas |
---|
| 1548 | res = strcmp(tbfuncionesClient[i].nf, nfn); |
---|
| 1549 | if (res == 0) { // Encontrada la función que procesa el mensaje |
---|
| 1550 | return(tbfuncionesClient[i].fptr(ptrTrama)); // Invoca la función |
---|
| 1551 | } |
---|
| 1552 | } |
---|
| 1553 | /* Sólo puede ser un comando personalizado */ |
---|
| 1554 | if (ptrTrama->tipo==MSG_COMANDO) |
---|
| 1555 | return(Comando(ptrTrama)); |
---|
| 1556 | |
---|
| 1557 | errorLog(modulo, 18, FALSE); |
---|
| 1558 | return (FALSE); |
---|
| 1559 | } |
---|
| 1560 | //________________________________________________________________________________________________________ |
---|
| 1561 | // Función: ejecutaArchivo |
---|
| 1562 | // |
---|
| 1563 | // Descripción: |
---|
| 1564 | // Ejecuta los comando contenido en un archivo (cada comando y sus parametros separados por un |
---|
| 1565 | // salto de linea. |
---|
| 1566 | // Parámetros: |
---|
| 1567 | // filecmd: Nombre del archivo de comandos |
---|
| 1568 | // ptrTrama: Puntero a una estructura TRAMA usada en las comunicaciones por red (No debe ser NULL) |
---|
| 1569 | // Devuelve: |
---|
| 1570 | // TRUE: Si el proceso es correcto |
---|
| 1571 | // FALSE: En caso de ocurrir algún error |
---|
| 1572 | //________________________________________________________________________________________________________ |
---|
| 1573 | BOOLEAN ejecutaArchivo(char* filecmd,TRAMA *ptrTrama) |
---|
| 1574 | { |
---|
| 1575 | char* buffer,*lineas[MAXIMAS_LINEAS]; |
---|
| 1576 | int i,numlin; |
---|
| 1577 | char modulo[] = "ejecutaArchivo()"; |
---|
| 1578 | |
---|
| 1579 | buffer=leeArchivo(filecmd); |
---|
| 1580 | if(buffer){ |
---|
| 1581 | numlin = splitCadena(lineas, buffer, '@'); |
---|
| 1582 | initParametros(ptrTrama,0); |
---|
| 1583 | for (i = 0; i < numlin; i++) { |
---|
| 1584 | if(strlen(lineas[i])>0){ |
---|
| 1585 | strcpy(ptrTrama->parametros,lineas[i]); |
---|
| 1586 | strcat(ptrTrama->parametros,"\rMCDJ@"); // Fin de trama |
---|
| 1587 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 1588 | errorLog(modulo,39,FALSE); |
---|
| 1589 | //return(FALSE); |
---|
| 1590 | } |
---|
| 1591 | } |
---|
| 1592 | } |
---|
| 1593 | } |
---|
| 1594 | return(TRUE); |
---|
| 1595 | } |
---|
| 1596 | //______________________________________________________________________________________________________ |
---|
| 1597 | // Función: enviaMensajeServidor |
---|
| 1598 | // |
---|
| 1599 | // Descripción: |
---|
| 1600 | // Envia un mensaje al servidor de Administración |
---|
| 1601 | // Parámetros: |
---|
| 1602 | // - socket_c: (Salida) Socket utilizado para el envío |
---|
| 1603 | // - ptrTrama: contenido del mensaje |
---|
| 1604 | // - tipo: Tipo de mensaje |
---|
| 1605 | // C=Comando, N=Respuesta a un comando, P=Peticion,R=Respuesta a una petición, I=Informacion |
---|
| 1606 | // Devuelve: |
---|
| 1607 | // TRUE: Si el proceso es correcto |
---|
| 1608 | // FALSE: En caso de ocurrir algún error |
---|
| 1609 | // ________________________________________________________________________________________________________ |
---|
| 1610 | BOOLEAN enviaMensajeServidor(SOCKET *socket_c,TRAMA *ptrTrama,char tipo) |
---|
| 1611 | { |
---|
| 1612 | int lon; |
---|
| 1613 | char modulo[] = "enviaMensajeServidor()"; |
---|
| 1614 | |
---|
| 1615 | *socket_c=abreConexion(); |
---|
| 1616 | if(*socket_c==INVALID_SOCKET){ |
---|
| 1617 | errorLog(modulo,38,FALSE); // Error de conexión con el servidor |
---|
| 1618 | return(FALSE); |
---|
| 1619 | } |
---|
| 1620 | ptrTrama->arroba='@'; // Cabecera de la trama |
---|
| 1621 | strncpy(ptrTrama->identificador,"JMMLCAMDJ_MCDJ",14); // identificador de la trama |
---|
| 1622 | ptrTrama->tipo=tipo; // Tipo de mensaje |
---|
| 1623 | lon=strlen(ptrTrama->parametros); // Compone la trama |
---|
| 1624 | lon+=sprintf(ptrTrama->parametros+lon,"iph=%s\r",IPlocal); // Ip del ordenador |
---|
| 1625 | lon+=sprintf(ptrTrama->parametros+lon,"ido=%s\r",idordenador); // Identificador del ordenador |
---|
| 1626 | lon+=sprintf(ptrTrama->parametros+lon,"npc=%s\r",nombreordenador); // Nombre del ordenador |
---|
| 1627 | lon+=sprintf(ptrTrama->parametros+lon,"idc=%s\r",idcentro); // Identificador del centro |
---|
| 1628 | lon+=sprintf(ptrTrama->parametros+lon,"ida=%s\r",idaula); // Identificador del aula |
---|
| 1629 | |
---|
| 1630 | if (!mandaTrama(socket_c,ptrTrama)) { |
---|
| 1631 | errorLog(modulo,26,FALSE); |
---|
| 1632 | return (FALSE); |
---|
| 1633 | } |
---|
| 1634 | return(TRUE); |
---|
| 1635 | } |
---|
| 1636 | // ******************************************************************************************************** |
---|
| 1637 | // PROGRAMA PRINCIPAL (CLIENTE) |
---|
| 1638 | // ******************************************************************************************************** |
---|
| 1639 | int main(int argc, char *argv[]) |
---|
| 1640 | { |
---|
| 1641 | TRAMA *ptrTrama; |
---|
| 1642 | char modulo[] = "main()"; |
---|
| 1643 | |
---|
| 1644 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA)); |
---|
| 1645 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas |
---|
| 1646 | errorLog(modulo, 3, FALSE); |
---|
| 1647 | exit(EXIT_FAILURE); |
---|
| 1648 | } |
---|
| 1649 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1650 | Validación de parámetros de ejecución y fichero de configuración |
---|
| 1651 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1652 | if (!validacionParametros(argc, argv,3)) // Valida parámetros de ejecución |
---|
| 1653 | exit(EXIT_FAILURE); |
---|
| 1654 | |
---|
| 1655 | if (!tomaConfiguracion(szPathFileCfg)) // Toma parametros de configuración |
---|
| 1656 | exit(EXIT_FAILURE); |
---|
| 1657 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1658 | Carga catálogo de funciones que procesan las tramas |
---|
| 1659 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1660 | int cf = 0; |
---|
| 1661 | |
---|
| 1662 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_AutoexecCliente"); |
---|
| 1663 | tbfuncionesClient[cf++].fptr = &RESPUESTA_AutoexecCliente; |
---|
| 1664 | |
---|
| 1665 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_InclusionCliente"); |
---|
| 1666 | tbfuncionesClient[cf++].fptr = &RESPUESTA_InclusionCliente; |
---|
| 1667 | |
---|
| 1668 | strcpy(tbfuncionesClient[cf].nf, "NoComandosPtes"); |
---|
| 1669 | tbfuncionesClient[cf++].fptr = &NoComandosPtes; |
---|
| 1670 | |
---|
| 1671 | strcpy(tbfuncionesClient[cf].nf, "Actualizar"); |
---|
| 1672 | tbfuncionesClient[cf++].fptr = &Actualizar; |
---|
| 1673 | |
---|
| 1674 | strcpy(tbfuncionesClient[cf].nf, "Purgar"); |
---|
| 1675 | tbfuncionesClient[cf++].fptr = &Purgar; |
---|
| 1676 | |
---|
| 1677 | strcpy(tbfuncionesClient[cf].nf, "ConsolaRemota"); |
---|
| 1678 | tbfuncionesClient[cf++].fptr = &ConsolaRemota; |
---|
| 1679 | |
---|
| 1680 | strcpy(tbfuncionesClient[cf].nf, "Sondeo"); |
---|
| 1681 | tbfuncionesClient[cf++].fptr = &Sondeo; |
---|
| 1682 | |
---|
| 1683 | strcpy(tbfuncionesClient[cf].nf, "Arrancar"); |
---|
| 1684 | tbfuncionesClient[cf++].fptr = &Arrancar; |
---|
| 1685 | |
---|
| 1686 | strcpy(tbfuncionesClient[cf].nf, "Apagar"); |
---|
| 1687 | tbfuncionesClient[cf++].fptr = &Apagar; |
---|
| 1688 | |
---|
| 1689 | strcpy(tbfuncionesClient[cf].nf, "Reiniciar"); |
---|
| 1690 | tbfuncionesClient[cf++].fptr = &Reiniciar; |
---|
| 1691 | |
---|
| 1692 | strcpy(tbfuncionesClient[cf].nf, "IniciarSesion"); |
---|
| 1693 | tbfuncionesClient[cf++].fptr = &IniciarSesion; |
---|
| 1694 | |
---|
| 1695 | strcpy(tbfuncionesClient[cf].nf, "CrearImagen"); |
---|
| 1696 | tbfuncionesClient[cf++].fptr = &CrearImagen; |
---|
| 1697 | |
---|
| 1698 | strcpy(tbfuncionesClient[cf].nf, "RestaurarImagen"); |
---|
| 1699 | tbfuncionesClient[cf++].fptr = &RestaurarImagen; |
---|
| 1700 | |
---|
| 1701 | strcpy(tbfuncionesClient[cf].nf, "Configurar"); |
---|
| 1702 | tbfuncionesClient[cf++].fptr = &Configurar; |
---|
| 1703 | |
---|
| 1704 | strcpy(tbfuncionesClient[cf].nf, "EjecutarScript"); |
---|
| 1705 | tbfuncionesClient[cf++].fptr = &EjecutarScript; |
---|
| 1706 | |
---|
| 1707 | strcpy(tbfuncionesClient[cf].nf, "InventarioHardware"); |
---|
| 1708 | tbfuncionesClient[cf++].fptr = &InventarioHardware; |
---|
| 1709 | |
---|
| 1710 | strcpy(tbfuncionesClient[cf].nf, "InventarioSoftware"); |
---|
| 1711 | tbfuncionesClient[cf++].fptr = &InventarioSoftware; |
---|
| 1712 | |
---|
| 1713 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1714 | Toma dirección IP del cliente |
---|
| 1715 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1716 | if(!tomaIPlocal()){ // Error al recuperar la IP local |
---|
| 1717 | errorLog(modulo,0,FALSE); |
---|
| 1718 | exit(EXIT_FAILURE); |
---|
| 1719 | } |
---|
| 1720 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1721 | Inicio de sesión |
---|
| 1722 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1723 | infoLog(1); // Inicio de sesión |
---|
| 1724 | infoLog(3); // Abriendo sesión en el servidor de Administración; |
---|
| 1725 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1726 | Inclusión del cliente en el sistema |
---|
| 1727 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1728 | if(!inclusionCliente(ptrTrama)){ // Ha habido algún problema al abrir sesión |
---|
| 1729 | errorLog(modulo,0,FALSE); |
---|
| 1730 | exit(EXIT_FAILURE); |
---|
| 1731 | } |
---|
| 1732 | infoLog(4); // Cliente iniciado |
---|
| 1733 | |
---|
| 1734 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1735 | Procesamiento de la cache |
---|
| 1736 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1737 | infoLog(23); // Abriendo sesión en el servidor de Administración; |
---|
| 1738 | if(!cuestionCache(cache)){ |
---|
| 1739 | errorLog(modulo,0,FALSE); |
---|
| 1740 | exit(EXIT_FAILURE); |
---|
| 1741 | } |
---|
| 1742 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1743 | Ejecución del autoexec |
---|
| 1744 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1745 | if(atoi(idproautoexec)>0){ // Ejecución de procedimiento Autoexec |
---|
| 1746 | infoLog(5); |
---|
| 1747 | if(!autoexecCliente(ptrTrama)){ // Ejecución fichero autoexec |
---|
| 1748 | errorLog(modulo,0,FALSE); |
---|
| 1749 | exit(EXIT_FAILURE); |
---|
| 1750 | } |
---|
| 1751 | } |
---|
| 1752 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1753 | Comandos pendientes |
---|
| 1754 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1755 | infoLog(6); // Procesa comandos pendientes |
---|
| 1756 | if(!comandosPendientes(ptrTrama)){ // Ejecución de acciones pendientes |
---|
| 1757 | errorLog(modulo,0,FALSE); |
---|
| 1758 | exit(EXIT_FAILURE); |
---|
| 1759 | } |
---|
| 1760 | infoLog(7); // Acciones pendientes procesadas |
---|
| 1761 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1762 | Bucle de recepción de comandos |
---|
| 1763 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1764 | muestraMenu(); |
---|
| 1765 | procesaComandos(ptrTrama); // Bucle para procesar comandos interactivos |
---|
| 1766 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 1767 | Fin de la sesión |
---|
| 1768 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 1769 | exit(EXIT_SUCCESS); |
---|
| 1770 | } |
---|