[f679cf0] | 1 | // ******************************************************************************************************** |
---|
| 2 | // Cliernte: ogAdmLnxClient |
---|
| 3 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
---|
| 4 | // Fecha Creación: Febrero-2012 |
---|
| 5 | // Fecha Última modificación: Febrero-2012 |
---|
| 6 | // Nombre del fichero: ogAdmLnxClient.c |
---|
| 7 | // Descripción :Este fichero implementa el cliente windows del sistema |
---|
| 8 | // ******************************************************************************************************** |
---|
| 9 | #include "ogAdmLnxClient.h" |
---|
| 10 | #include "ogAdmLib.c" |
---|
[c69c766] | 11 | |
---|
| 12 | // ________________________________________________________________________________________________________ |
---|
| 13 | // Función: EjecutarScript |
---|
| 14 | // |
---|
| 15 | // Descripción: |
---|
| 16 | // Ejecuta código de script |
---|
| 17 | // Parámetros: |
---|
| 18 | // ptrTrama: contenido del mensaje |
---|
| 19 | // Devuelve: |
---|
| 20 | // TRUE: Si el proceso es correcto |
---|
| 21 | // FALSE: En caso de ocurrir algún error |
---|
| 22 | //______________________________________________________________________________________________________ |
---|
| 23 | BOOLEAN EjecutarScript(TRAMA* ptrTrama) |
---|
| 24 | { |
---|
| 25 | int lon,resul; |
---|
| 26 | char *nfn,*ids,*scp,msglog[LONSTD]; |
---|
| 27 | char modulo[] = "EjecutarScript()"; |
---|
| 28 | |
---|
| 29 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 30 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 31 | infoDebug(msglog); |
---|
| 32 | } |
---|
| 33 | scp=URLDecode(copiaParametro("scp",ptrTrama)); |
---|
| 34 | ids=copiaParametro("ids",ptrTrama); |
---|
| 35 | |
---|
| 36 | nfn=copiaParametro("nfn",ptrTrama); |
---|
| 37 | ids=copiaParametro("ids",ptrTrama); |
---|
| 38 | |
---|
| 39 | /* Nombre del archivo de script */ |
---|
| 40 | char filescript[LONPRM]; |
---|
| 41 | sprintf(filescript,"/tmp/_script_%s",IPlocal); |
---|
| 42 | if(!escribeArchivo(filescript,scp)){ |
---|
| 43 | errorLog(modulo, 52, FALSE); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | resul=system(filescript); |
---|
| 47 | if (resul>0) { |
---|
| 48 | errorLog(modulo, 86, FALSE); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | initParametros(ptrTrama,0); |
---|
| 52 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_EjecutarScript"); |
---|
| 53 | respuestaEjecucionComando(ptrTrama,resul,ids); |
---|
| 54 | return(TRUE); |
---|
| 55 | } |
---|
[f679cf0] | 56 | //________________________________________________________________________________________________________ |
---|
| 57 | // Función: tomaConfiguracion |
---|
| 58 | // |
---|
| 59 | // Descripción: |
---|
| 60 | // Lee el fichero de configuración del servicio |
---|
| 61 | // Parámetros: |
---|
| 62 | // filecfg : Ruta completa al fichero de configuración |
---|
| 63 | // Devuelve: |
---|
| 64 | // TRUE: Si el proceso es correcto |
---|
| 65 | // FALSE: En caso de ocurrir algún error |
---|
| 66 | //________________________________________________________________________________________________________ |
---|
| 67 | BOOLEAN tomaConfiguracion(char* filecfg) |
---|
| 68 | { |
---|
| 69 | char modulo[] = "tomaConfiguracion()"; |
---|
| 70 | |
---|
| 71 | if (filecfg == NULL || strlen(filecfg) == 0) { |
---|
| 72 | errorLog(modulo, 1, FALSE); // Fichero de configuración del cliente vacío |
---|
| 73 | return (FALSE); |
---|
| 74 | } |
---|
| 75 | FILE *fcfg; |
---|
| 76 | int lSize; |
---|
| 77 | char * buffer, *lineas[MAXPRM], *dualparametro[2]; |
---|
| 78 | int i, numlin, resul; |
---|
| 79 | |
---|
| 80 | fcfg = fopen(filecfg, "rt"); |
---|
| 81 | if (fcfg == NULL) { |
---|
| 82 | errorLog(modulo, 2, FALSE); // No existe fichero de configuración del cliente |
---|
| 83 | return (FALSE); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | fseek(fcfg, 0, SEEK_END); |
---|
| 87 | lSize = ftell(fcfg); // Obtiene tamaño del fichero. |
---|
| 88 | rewind(fcfg); |
---|
| 89 | buffer = (char*) reservaMemoria(lSize+1); // Toma memoria para el buffer de lectura. |
---|
| 90 | if (buffer == NULL) { // No hay memoria suficiente para el buffer |
---|
| 91 | errorLog(modulo, 3, FALSE); |
---|
| 92 | return (FALSE); |
---|
| 93 | } |
---|
| 94 | lSize=fread(buffer, 1, lSize, fcfg); // Lee contenido del fichero |
---|
| 95 | buffer[lSize]=CHARNULL; |
---|
| 96 | fclose(fcfg); |
---|
| 97 | |
---|
| 98 | /* Inicializar variables globales */ |
---|
| 99 | servidoradm[0]=CHARNULL; |
---|
| 100 | puerto[0] = CHARNULL; |
---|
| 101 | IPlocal[0]=CHARNULL; |
---|
| 102 | |
---|
| 103 | numlin = splitCadena(lineas, buffer, '\n'); |
---|
| 104 | for (i = 0; i < numlin; i++){ |
---|
| 105 | splitCadena(dualparametro, lineas[i], '='); |
---|
| 106 | |
---|
| 107 | resul = strcmp(StrToUpper(dualparametro[0]), "SERVIDORADM"); |
---|
| 108 | if (resul == 0) |
---|
| 109 | strcpy(servidoradm, dualparametro[1]); |
---|
| 110 | |
---|
| 111 | resul = strcmp(StrToUpper(dualparametro[0]), "PUERTO"); |
---|
| 112 | if (resul == 0) |
---|
| 113 | strcpy(puerto, dualparametro[1]); |
---|
| 114 | |
---|
| 115 | resul = strcmp(StrToUpper(dualparametro[0]), "IPLOCAL"); |
---|
| 116 | if (resul == 0) |
---|
| 117 | strcpy(IPlocal, dualparametro[1]); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | if (servidoradm[0] == CHARNULL) { |
---|
| 121 | errorLog(modulo,4, FALSE); // Falta parámetro SERVIDORADM |
---|
| 122 | return (FALSE); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if (puerto[0] == CHARNULL) { |
---|
| 126 | errorLog(modulo,5, FALSE); // Falta parámetro PUERTO |
---|
| 127 | return (FALSE); |
---|
| 128 | } |
---|
| 129 | if (IPlocal[0] == CHARNULL) { |
---|
| 130 | errorLog(modulo, 92, FALSE); // Falta parámetro IPLOCAL |
---|
| 131 | return (FALSE); |
---|
| 132 | } |
---|
| 133 | return (TRUE); |
---|
| 134 | } |
---|
| 135 | //______________________________________________________________________________________________________ |
---|
| 136 | // Función: InclusionClienteWinLnx |
---|
| 137 | // Descripción: |
---|
| 138 | // Abre una sesión en el servidor de administración y registra al cliente en el sistema |
---|
| 139 | // Parámetros: |
---|
| 140 | // Ninguno |
---|
| 141 | // Devuelve: |
---|
| 142 | // TRUE: Si el proceso es correcto |
---|
| 143 | // FALSE: En caso de ocurrir algún error |
---|
| 144 | //______________________________________________________________________________________________________ |
---|
| 145 | BOOLEAN InclusionClienteWinLnx(TRAMA* ptrTrama) |
---|
| 146 | { |
---|
| 147 | int lon; |
---|
| 148 | SOCKET socket_c; |
---|
| 149 | char modulo[] = "InclusionClienteWinLnx()"; |
---|
| 150 | |
---|
| 151 | initParametros(ptrTrama,0); |
---|
| 152 | lon=sprintf(ptrTrama->parametros,"nfn=InclusionClienteWinLnx\r"); // Nombre de la función a ejecutar en el servidor |
---|
| 153 | |
---|
| 154 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 155 | errorLog(modulo,37,FALSE); |
---|
| 156 | return(FALSE); |
---|
| 157 | } |
---|
| 158 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 159 | if(!ptrTrama){ |
---|
| 160 | errorLog(modulo,22,FALSE); |
---|
| 161 | return(FALSE); |
---|
| 162 | } |
---|
| 163 | close(socket_c); |
---|
| 164 | |
---|
| 165 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 166 | errorLog(modulo,39,FALSE); |
---|
| 167 | return(FALSE); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | return(TRUE); |
---|
| 171 | } |
---|
| 172 | //______________________________________________________________________________________________________ |
---|
| 173 | // Función: RESPUESTA_InclusionClienteWinLnx |
---|
| 174 | // |
---|
| 175 | // Descripción: |
---|
| 176 | // Respuesta del servidor de administración a la petición de inicio |
---|
| 177 | // enviando los datos identificativos del cliente |
---|
| 178 | // Parámetros: |
---|
| 179 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 180 | // Devuelve: |
---|
| 181 | // TRUE: Si el proceso es correcto |
---|
| 182 | // FALSE: En caso de ocurrir algún error |
---|
| 183 | //______________________________________________________________________________________________________ |
---|
| 184 | BOOLEAN RESPUESTA_InclusionClienteWinLnx(TRAMA* ptrTrama) |
---|
| 185 | { |
---|
| 186 | char* res; |
---|
| 187 | char modulo[] = "RESPUESTA_InclusionClienteWinLnx()"; |
---|
| 188 | int err; |
---|
| 189 | |
---|
| 190 | res=copiaParametro("res",ptrTrama); // Resultado del proceso de inclusión |
---|
| 191 | err=(int)atoi(res); // Código de error devuelto por el servidor |
---|
| 192 | if(err>0){ // Error en el proceso de inclusión |
---|
| 193 | errorLog(modulo,41,FALSE); |
---|
| 194 | errorLog(modulo,err,FALSE); |
---|
| 195 | return (FALSE); |
---|
| 196 | } |
---|
| 197 | strcpy(idordenador,copiaParametro("ido",ptrTrama)); // Identificador del ordenador |
---|
| 198 | strcpy(nombreordenador,copiaParametro("npc",ptrTrama)); // Nombre del ordenador |
---|
| 199 | |
---|
| 200 | if(idordenador==NULL || nombreordenador==NULL){ |
---|
| 201 | errorLog(modulo,40,FALSE); |
---|
| 202 | return (FALSE); |
---|
| 203 | } |
---|
| 204 | return(TRUE); |
---|
| 205 | } |
---|
| 206 | //______________________________________________________________________________________________________ |
---|
| 207 | // Función: ProcesaComandos |
---|
| 208 | // |
---|
| 209 | // Descripción: |
---|
| 210 | // Espera comando desde el Servidor de Administración para ejecutarlos |
---|
| 211 | // Parámetros: |
---|
| 212 | // Ninguno |
---|
| 213 | // Devuelve: |
---|
| 214 | // TRUE: Si el proceso es correcto |
---|
| 215 | // FALSE: En caso de ocurrir algún error |
---|
| 216 | // ________________________________________________________________________________________________________ |
---|
| 217 | void procesaComandos(TRAMA* ptrTrama) |
---|
| 218 | { |
---|
| 219 | int lon; |
---|
| 220 | SOCKET socket_c; |
---|
| 221 | char modulo[] = "procesaComandos()"; |
---|
| 222 | |
---|
| 223 | initParametros(ptrTrama,0); |
---|
| 224 | while(TRUE){ |
---|
| 225 | lon=sprintf(ptrTrama->parametros,"nfn=DisponibilidadComandos\r"); |
---|
| 226 | lon+=sprintf(ptrTrama->parametros+lon,"tpc=%s\r",CLIENTE_LNX); // Activar disponibilidad |
---|
| 227 | if(!enviaMensajeServidor(&socket_c,ptrTrama,MSG_INFORMACION)){ |
---|
| 228 | errorLog(modulo,43,FALSE); |
---|
| 229 | return; |
---|
| 230 | } |
---|
| 231 | infoLog(19); // Disponibilidad de cliente activada |
---|
| 232 | ptrTrama=recibeMensaje(&socket_c); |
---|
| 233 | if(!ptrTrama){ |
---|
| 234 | errorLog(modulo,46,FALSE); |
---|
| 235 | return; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | close(socket_c); |
---|
| 239 | |
---|
| 240 | if(!gestionaTrama(ptrTrama)){ // Análisis de la trama |
---|
| 241 | errorLog(modulo,39,FALSE); |
---|
| 242 | return; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | //_____________________________________________________________________________________________________ |
---|
| 247 | // Función: Apagar |
---|
| 248 | // |
---|
| 249 | // Descripción: |
---|
| 250 | // Apaga el cliente |
---|
| 251 | // Parámetros: |
---|
| 252 | // ptrTrama: contenido del mensaje |
---|
| 253 | // Devuelve: |
---|
| 254 | // TRUE: Si el proceso es correcto |
---|
| 255 | // FALSE: En caso de ocurrir algún error |
---|
| 256 | //_____________________________________________________________________________________________________ |
---|
| 257 | BOOLEAN Apagar(TRAMA* ptrTrama) |
---|
| 258 | { |
---|
| 259 | int lon; |
---|
| 260 | char *ids,msglog[LONSTD]; |
---|
| 261 | char modulo[] = "Apagar()"; |
---|
| 262 | |
---|
| 263 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 264 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 265 | infoDebug(msglog); |
---|
| 266 | } |
---|
| 267 | ids=copiaParametro("ids",ptrTrama); |
---|
| 268 | |
---|
| 269 | initParametros(ptrTrama,0); |
---|
| 270 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Apagar"); |
---|
| 271 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 272 | |
---|
| 273 | system("shutdown -h now"); |
---|
| 274 | return(TRUE); |
---|
| 275 | } |
---|
| 276 | //_____________________________________________________________________________________________________ |
---|
| 277 | // Función: Reiniciar |
---|
| 278 | // |
---|
| 279 | // Descripción: |
---|
| 280 | // Apaga el cliente |
---|
| 281 | // Parámetros: |
---|
| 282 | // ptrTrama: contenido del mensaje |
---|
| 283 | // Devuelve: |
---|
| 284 | // TRUE: Si el proceso es correcto |
---|
| 285 | // FALSE: En caso de ocurrir algún errorservidoradm |
---|
| 286 | //_____________________________________________________________________________________________________ |
---|
| 287 | BOOLEAN Reiniciar(TRAMA* ptrTrama) |
---|
| 288 | { |
---|
| 289 | int lon; |
---|
| 290 | char *ids,msglog[LONSTD]; |
---|
| 291 | char modulo[] = "Reiniciar()"; |
---|
| 292 | |
---|
| 293 | if (ndebug>=DEBUG_MAXIMO) { |
---|
| 294 | sprintf(msglog, "%s:%s",tbMensajes[21],modulo); |
---|
| 295 | infoDebug(msglog); |
---|
| 296 | } |
---|
| 297 | ids=copiaParametro("ids",ptrTrama); |
---|
| 298 | |
---|
| 299 | initParametros(ptrTrama,0); |
---|
| 300 | lon=sprintf(ptrTrama->parametros,"nfn=%s\r","RESPUESTA_Reiniciar"); |
---|
| 301 | respuestaEjecucionComando(ptrTrama,0,ids); |
---|
| 302 | |
---|
| 303 | system("shutdown -r now"); |
---|
| 304 | |
---|
| 305 | return(TRUE); |
---|
| 306 | } |
---|
| 307 | //______________________________________________________________________________________________________ |
---|
| 308 | // Función: Sondeo |
---|
| 309 | // |
---|
| 310 | // Descripción: |
---|
| 311 | // Envía al servidor una confirmación de que está dentro del sistema |
---|
| 312 | // Parámetros: |
---|
| 313 | // ptrTrama: contenido del mensajede |
---|
| 314 | // Devuelve: |
---|
| 315 | // TRUE: Si el proceso es correcto |
---|
| 316 | // FALSE: En caso de ocurrir algún error |
---|
| 317 | //______________________________________________________________________________________________________ |
---|
| 318 | BOOLEAN Sondeo(TRAMA* ptrTrama) |
---|
| 319 | { |
---|
| 320 | return(TRUE); |
---|
| 321 | } |
---|
| 322 | //______________________________________________________________________________________________________ |
---|
| 323 | // Función: respuestaEjecucionComando |
---|
| 324 | // |
---|
| 325 | // Descripción: |
---|
| 326 | // Envia una respuesta a una ejecucion de comando al servidor de Administración |
---|
| 327 | // Parámetros: |
---|
| 328 | // - ptrTrama: contenido del mensaje |
---|
| 329 | // - res: Resultado de la ejecución (Código de error devuelto por el script ejecutado) |
---|
| 330 | // - ids: Identificador de la sesion (En caso de no haber seguimiento es NULO) |
---|
| 331 | // Devuelve: |
---|
| 332 | // TRUE: Si el proceso es correcto |
---|
| 333 | // FALSE: En caso de ocurrir algún error |
---|
| 334 | // ________________________________________________________________________________________________________ |
---|
| 335 | BOOLEAN respuestaEjecucionComando(TRAMA* ptrTrama,int res,char *ids) |
---|
| 336 | { |
---|
| 337 | int lon; |
---|
| 338 | SOCKET socket_c; |
---|
| 339 | char modulo[] = "respuestaEjecucionComando()"; |
---|
| 340 | |
---|
| 341 | lon=strlen(ptrTrama->parametros); |
---|
| 342 | if(ids){ // Existe seguimiento |
---|
| 343 | lon+=sprintf(ptrTrama->parametros+lon,"ids=%s\r",ids); // Añade identificador de la sesión |
---|
| 344 | } |
---|
| 345 | if (res==0){ // Resultado satisfactorio |
---|
| 346 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","1"); |
---|
| 347 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",""); |
---|
| 348 | } |
---|
| 349 | else{ // Algún error |
---|
| 350 | lon+=sprintf(ptrTrama->parametros+lon,"res=%s\r","2"); |
---|
| 351 | lon+=sprintf(ptrTrama->parametros+lon,"der=%s\r",tbErrores[res]);// Descripción del error |
---|
| 352 | } |
---|
| 353 | if(!(enviaMensajeServidor(&socket_c,ptrTrama,MSG_NOTIFICACION))){ |
---|
| 354 | errorLog(modulo,44,FALSE); |
---|
| 355 | return(FALSE); |
---|
| 356 | } |
---|
| 357 | close(socket_c); |
---|
| 358 | return(TRUE); |
---|
| 359 | } |
---|
| 360 | // ________________________________________________________________________________________________________ |
---|
| 361 | // Función: gestionaTrama |
---|
| 362 | // |
---|
| 363 | // Descripción: |
---|
| 364 | // Procesa las tramas recibidas.servidoradm |
---|
| 365 | // Parametros: |
---|
| 366 | // ptrTrama: contenido del mensaje |
---|
| 367 | // Devuelve: |
---|
| 368 | // TRUE: Si el proceso es correcto |
---|
| 369 | // FALSE: En caso de ocurrir algún error |
---|
| 370 | // ________________________________________________________________________________________________________ |
---|
| 371 | BOOLEAN gestionaTrama(TRAMA *ptrTrama) |
---|
| 372 | { |
---|
| 373 | int i, res; |
---|
| 374 | char *nfn; |
---|
| 375 | char modulo[] = "gestionaTrama()"; |
---|
| 376 | |
---|
| 377 | INTROaFINCAD(ptrTrama); |
---|
| 378 | nfn = copiaParametro("nfn", ptrTrama); // Toma nombre de función |
---|
| 379 | for (i = 0; i < MAXIMAS_FUNCIONES; i++) { // Recorre funciones que procesan las tramas |
---|
| 380 | res = strcmp(tbfuncionesClient[i].nf, nfn); |
---|
| 381 | if (res == 0) { // Encontrada la función que procesa el mensaje |
---|
| 382 | return(tbfuncionesClient[i].fptr(ptrTrama)); // Invoca la función |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | errorLog(modulo, 18, FALSE); |
---|
| 386 | return (FALSE); |
---|
| 387 | } |
---|
| 388 | //______________________________________________________________________________________________________ |
---|
| 389 | // Función: enviaMensajeServidor |
---|
| 390 | // |
---|
| 391 | // Descripción: |
---|
| 392 | // Envia un mensaje al servidor de Administración |
---|
| 393 | // Parámetros: |
---|
| 394 | // - socket_c: (Salida) Socket utilizado para el envío |
---|
| 395 | // - ptrTrama: contenido del mensaje |
---|
| 396 | // - tipo: Tipo de mensaje |
---|
| 397 | // C=Comando, N=Respuesta a un comando, P=Peticion,R=Respuesta a una petición, I=Informacion |
---|
| 398 | // Devuelve: |
---|
| 399 | // TRUE: Si el proceso es correcto |
---|
| 400 | // FALSE: En caso de ocurrir algún error |
---|
| 401 | // ________________________________________________________________________________________________________ |
---|
| 402 | BOOLEAN enviaMensajeServidor(SOCKET *socket_c,TRAMA *ptrTrama,char tipo) |
---|
| 403 | { |
---|
| 404 | int lon; |
---|
| 405 | char modulo[] = "enviaMensajeServidor()"; |
---|
| 406 | |
---|
| 407 | *socket_c=abreConexion(); |
---|
| 408 | if(*socket_c==INVALID_SOCKET){ |
---|
| 409 | errorLog(modulo,38,FALSE); // Error de conexión con el servidor |
---|
| 410 | return(FALSE); |
---|
| 411 | } |
---|
| 412 | ptrTrama->arroba='@'; // Cabecera de la trama |
---|
| 413 | strncpy(ptrTrama->identificador,"JMMLCAMDJ_MCDJ",14); // identificador de la trama |
---|
| 414 | ptrTrama->tipo=tipo; // Tipo de mensaje |
---|
| 415 | lon=strlen(ptrTrama->parametros); // Compone la trama |
---|
| 416 | lon+=sprintf(ptrTrama->parametros+lon,"iph=%s\r",IPlocal); // Ip del ordenador |
---|
| 417 | lon+=sprintf(ptrTrama->parametros+lon,"ido=%s\r",idordenador); // Identificador del ordenador |
---|
| 418 | lon+=sprintf(ptrTrama->parametros+lon,"npc=%s\r",nombreordenador); // Nombre del ordenador |
---|
| 419 | |
---|
| 420 | if (!mandaTrama(socket_c,ptrTrama)) { |
---|
| 421 | errorLog(modulo,26,FALSE); |
---|
| 422 | return (FALSE); |
---|
| 423 | } |
---|
| 424 | return(TRUE); |
---|
| 425 | } |
---|
| 426 | // ******************************************************************************************************** |
---|
| 427 | // PROGRAMA PRINCIPAL (CLIENTE) |
---|
| 428 | // ******************************************************************************************************** |
---|
| 429 | int main(int argc, char *argv[]) |
---|
| 430 | { |
---|
| 431 | TRAMA *ptrTrama; |
---|
| 432 | char modulo[] = "main()"; |
---|
| 433 | |
---|
| 434 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA)); |
---|
| 435 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas |
---|
| 436 | errorLog(modulo, 3, FALSE); |
---|
| 437 | exit(EXIT_FAILURE); |
---|
| 438 | } |
---|
| 439 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 440 | Validación de parámetros de ejecución y fichero de configuración |
---|
| 441 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 442 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 443 | Validación de parámetros de ejecución y fichero de configuración |
---|
| 444 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 445 | if (!validacionParametros(argc, argv,6)) // Valida parámetros de ejecución |
---|
| 446 | exit(EXIT_FAILURE); |
---|
| 447 | |
---|
| 448 | if (!tomaConfiguracion(szPathFileCfg)) // Toma parametros de configuración |
---|
| 449 | exit(EXIT_FAILURE); |
---|
| 450 | |
---|
| 451 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 452 | Carga catálogo de funciones que procesan las tramas |
---|
| 453 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 454 | int cf = 0; |
---|
| 455 | |
---|
| 456 | strcpy(tbfuncionesClient[cf].nf, "RESPUESTA_InclusionClienteWinLnx"); |
---|
| 457 | tbfuncionesClient[cf++].fptr = &RESPUESTA_InclusionClienteWinLnx; |
---|
| 458 | |
---|
| 459 | strcpy(tbfuncionesClient[cf].nf, "Apagar"); |
---|
| 460 | tbfuncionesClient[cf++].fptr = &Apagar; |
---|
| 461 | |
---|
| 462 | strcpy(tbfuncionesClient[cf].nf, "Reiniciar"); |
---|
| 463 | tbfuncionesClient[cf++].fptr = &Reiniciar; |
---|
| 464 | |
---|
| 465 | strcpy(tbfuncionesClient[cf].nf, "Sondeo"); |
---|
| 466 | tbfuncionesClient[cf++].fptr = &Sondeo; |
---|
| 467 | |
---|
[c69c766] | 468 | strcpy(tbfuncionesClient[cf].nf, "EjecutarScript"); |
---|
| 469 | tbfuncionesClient[cf++].fptr = &EjecutarScript; |
---|
| 470 | |
---|
[f679cf0] | 471 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 472 | Inicio de sesión |
---|
| 473 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 474 | infoLog(1); // Inicio de sesión |
---|
| 475 | infoLog(3); // Abriendo sesión en el servidor de Administración; |
---|
| 476 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 477 | Inclusión del cliente en el sistema |
---|
| 478 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 479 | if(!InclusionClienteWinLnx(ptrTrama)){ // Ha habido algún problema al abrir sesión |
---|
| 480 | errorLog(modulo,0,FALSE); |
---|
| 481 | exit(EXIT_FAILURE); |
---|
| 482 | } |
---|
| 483 | infoLog(4); // Cliente iniciado |
---|
| 484 | procesaComandos(ptrTrama); // Bucle para procesar comandos interactivos |
---|
| 485 | exit(EXIT_SUCCESS); |
---|
| 486 | } |
---|