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