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