[34fc87f] | 1 | // **************************************************************************************************************************************************** |
---|
[0d997c6] | 2 | // Aplicación HIDRA |
---|
[277d0cd] | 3 | // Copyright 2003-2005 JosnManuel Alonso. Todos los derechos reservados. |
---|
| 4 | // Fichero: hidra.cpp |
---|
| 5 | // Descripcin: |
---|
| 6 | // Este proyecto implementa el servicio hidra en un ordenador con plataforma windows NT. Este fichero aporta las funciones de |
---|
| 7 | // envn de comandos y recepcin de respuestas |
---|
[34fc87f] | 8 | // **************************************************************************************************************************************************** |
---|
| 9 | #include "ogAdmServer.h" |
---|
[277d0cd] | 10 | #include "encriptacion.c" |
---|
| 11 | // ________________________________________________________________________________________________________ |
---|
| 12 | // Funcin: RegistraLog |
---|
| 13 | // |
---|
| 14 | // Descripción: |
---|
| 15 | // Esta funcin registra los evento de errores en un fichero log |
---|
[ec01697] | 16 | // Parametros: |
---|
[277d0cd] | 17 | // - msg : Mensage de error |
---|
| 18 | // - swerrno: Switch que indica que recupere literal de error del sistema |
---|
| 19 | // ________________________________________________________________________________________________________ |
---|
| 20 | void RegistraLog(const char *msg,int swerrno) |
---|
| 21 | { |
---|
| 22 | struct tm * timeinfo; |
---|
| 23 | timeinfo = TomaHora(); |
---|
| 24 | |
---|
[b25881b] | 25 | FLog=fopen(szPathFileLog,"at"); |
---|
[277d0cd] | 26 | if(swerrno) |
---|
| 27 | fprintf (FLog,"%02d/%02d/%d %02d:%02d ***%s:%s\n",timeinfo->tm_mday,timeinfo->tm_mon+1,timeinfo->tm_year+1900,timeinfo->tm_hour,timeinfo->tm_min,msg,strerror(errno)); |
---|
| 28 | else |
---|
| 29 | fprintf (FLog,"%02d/%02d/%d %02d:%02d ***%s\n",timeinfo->tm_mday,timeinfo->tm_mon+1,timeinfo->tm_year+1900,timeinfo->tm_hour,timeinfo->tm_min,msg); |
---|
| 30 | fclose(FLog); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | // ________________________________________________________________________________________________________ |
---|
| 34 | // Funcin: TomaHora |
---|
| 35 | // |
---|
| 36 | // Descripcin: |
---|
| 37 | // Esta funcin toma la hora actual del sistema y devuelve una estructura conlos datos |
---|
| 38 | // Parametros: |
---|
| 39 | // - msg : Mensage de error |
---|
| 40 | // - swerrno: Switch que indica que recupere literal de error del sistema |
---|
| 41 | // ________________________________________________________________________________________________________ |
---|
| 42 | struct tm * TomaHora() |
---|
| 43 | { |
---|
| 44 | time_t rawtime; |
---|
| 45 | time ( &rawtime ); |
---|
| 46 | return(gmtime(&rawtime)); |
---|
| 47 | } |
---|
[34fc87f] | 48 | //________________________________________________________________________________________________________ |
---|
| 49 | // |
---|
| 50 | // Función: TomaConfiguracion |
---|
| 51 | // |
---|
| 52 | // Descripción: |
---|
| 53 | // Esta función lee el fichero de configuración del programa hidralinuxcli y toma los parametros |
---|
| 54 | // Parametros: |
---|
| 55 | // - pathfilecfg : Ruta al fichero de configuración |
---|
| 56 | //________________________________________________________________________________________________________ |
---|
| 57 | int TomaConfiguracion(char* pathfilecfg) |
---|
| 58 | { |
---|
| 59 | long lSize; |
---|
| 60 | char * buffer,*lineas[100],*dualparametro[2]; |
---|
| 61 | char ch[2]; |
---|
| 62 | int i,numlin,resul; |
---|
| 63 | |
---|
| 64 | if(pathfilecfg==NULL) return(FALSE); // Nombre del fichero en blanco |
---|
| 65 | |
---|
| 66 | Fconfig = fopen ( pathfilecfg , "rb" ); |
---|
| 67 | if (Fconfig==NULL) return(FALSE); |
---|
| 68 | fseek (Fconfig , 0 , SEEK_END); // Obtiene tamaño del fichero. |
---|
| 69 | lSize = ftell (Fconfig); |
---|
| 70 | rewind (Fconfig); |
---|
| 71 | buffer = (char*) malloc (lSize); // Toma memoria para el buffer de lectura. |
---|
| 72 | if (buffer == NULL) return(FALSE); |
---|
| 73 | fread (buffer,1,lSize,Fconfig); // Lee contenido del fichero |
---|
| 74 | fclose(Fconfig); |
---|
| 75 | |
---|
| 76 | //inicializar |
---|
| 77 | IPlocal[0]=(char)NULL; |
---|
| 78 | servidorhidra[0]=(char)NULL; |
---|
| 79 | Puerto[0]=(char)NULL; |
---|
| 80 | usuario[0]=(char)NULL; |
---|
| 81 | pasguor[0]=(char)NULL; |
---|
| 82 | datasource[0]=(char)NULL; |
---|
| 83 | catalog[0]=(char)NULL; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | strcpy(ch,"\n");// caracter delimitador ( salto de linea) |
---|
| 87 | numlin=split_parametros(lineas,buffer,ch); |
---|
| 88 | for (i=0;i<numlin;i++){ |
---|
| 89 | strcpy(ch,"=");// caracter delimitador |
---|
| 90 | split_parametros(dualparametro,lineas[i],ch); // Toma primer nombre del parametros |
---|
| 91 | |
---|
| 92 | resul=strcmp(dualparametro[0],"IPhidra"); |
---|
| 93 | if(resul==0) strcpy(IPlocal,dualparametro[1]); |
---|
| 94 | |
---|
| 95 | resul=strcmp(dualparametro[0],"IPhidra"); |
---|
| 96 | if(resul==0) strcpy(servidorhidra,dualparametro[1]); |
---|
| 97 | |
---|
| 98 | resul=strcmp(dualparametro[0],"Puerto"); |
---|
| 99 | if(resul==0) strcpy(Puerto,dualparametro[1]); |
---|
| 100 | |
---|
| 101 | resul=strcmp(dualparametro[0],"AulaUp"); |
---|
| 102 | if(resul==0) strcpy(AulaUp,dualparametro[1]); |
---|
| 103 | |
---|
| 104 | resul=strcmp(dualparametro[0],"Usuario"); |
---|
| 105 | if(resul==0) strcpy(usuario,dualparametro[1]); |
---|
| 106 | |
---|
| 107 | resul=strcmp(dualparametro[0],"PassWord"); |
---|
| 108 | if(resul==0) strcpy(pasguor,dualparametro[1]); |
---|
| 109 | |
---|
| 110 | resul=strcmp(dualparametro[0],"DataSource"); |
---|
| 111 | if(resul==0) strcpy(datasource,dualparametro[1]); |
---|
| 112 | |
---|
| 113 | resul=strcmp(dualparametro[0],"Catalog"); |
---|
| 114 | if(resul==0) strcpy(catalog,dualparametro[1]); |
---|
| 115 | } |
---|
| 116 | if(IPlocal[0]==(char)NULL){ |
---|
| 117 | RegistraLog("IPlocal, NO se ha definido este parámetro",false); |
---|
| 118 | return(FALSE); |
---|
| 119 | } |
---|
| 120 | if(servidorhidra[0]==(char)NULL){ |
---|
| 121 | RegistraLog("IPhidra, NO se ha definido este parámetro",false); |
---|
| 122 | return(FALSE); |
---|
| 123 | } |
---|
| 124 | if(Puerto[0]==(char)NULL){ |
---|
| 125 | RegistraLog("Puerto, NO se ha definido este parámetro",false); |
---|
| 126 | return(FALSE); |
---|
| 127 | } |
---|
| 128 | puerto=atoi(Puerto); |
---|
| 129 | |
---|
| 130 | if(AulaUp[0]==(char)NULL){ |
---|
| 131 | RegistraLog("AulaUp, NO se ha definido este parámetro",false); |
---|
| 132 | return(FALSE); |
---|
| 133 | } |
---|
| 134 | aulaup=atoi(AulaUp); |
---|
| 135 | |
---|
| 136 | if(usuario[0]==(char)NULL){ |
---|
| 137 | RegistraLog("Usuario, NO se ha definido este parámetro",false); |
---|
| 138 | return(FALSE); |
---|
| 139 | } |
---|
| 140 | if(pasguor[0]==(char)NULL){ |
---|
| 141 | RegistraLog("PassWord, NO se ha definido este parámetro",false); |
---|
| 142 | return(FALSE); |
---|
| 143 | } |
---|
| 144 | if(datasource[0]==(char)NULL){ |
---|
| 145 | RegistraLog("DataSource, NO se ha definido este parámetro",false); |
---|
| 146 | return(FALSE); |
---|
| 147 | } |
---|
| 148 | if(catalog[0]==(char)NULL){ |
---|
| 149 | RegistraLog("Catalog, NO se ha definido este parámetro",false); |
---|
| 150 | return(FALSE); |
---|
| 151 | } |
---|
| 152 | return(TRUE); |
---|
| 153 | } |
---|
| 154 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 155 | // Funcin: GestionaConexion |
---|
[34fc87f] | 156 | // |
---|
| 157 | // Descripcin: |
---|
| 158 | // Esta hebra es la encargada de comunicarse con los clientes a travn del socket enviado como parnetro. |
---|
| 159 | // Parametros: |
---|
| 160 | // - lpParam : Socket usado |
---|
| 161 | // ________________________________________________________________________________________________________ |
---|
| 162 | void * GestionaConexion(void* s) |
---|
| 163 | { |
---|
| 164 | SOCKET socket_c=*(SOCKET*)s; |
---|
| 165 | TRAMA trama; |
---|
| 166 | |
---|
| 167 | if (recibe_trama(socket_c,&trama)){ |
---|
| 168 | if (strncmp(trama.identificador,"JMMLCAMDJ",9)==0) // Es una trama hidra |
---|
| 169 | gestiona_comando(socket_c,trama); |
---|
| 170 | } |
---|
| 171 | return(s); |
---|
| 172 | } |
---|
| 173 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 174 | // Funcin: gestiona_comando |
---|
[34fc87f] | 175 | // |
---|
| 176 | // Descripcin: |
---|
| 177 | // Analiza el comando enviado por el servidor web y lo reenvia al cliente rembo o lo ejecuta n mismo |
---|
| 178 | // Parametros: |
---|
| 179 | // - s : Socket usado |
---|
| 180 | // - trama : La trama con los parametrso del comando |
---|
| 181 | // ________________________________________________________________________________________________________ |
---|
| 182 | void gestiona_comando(SOCKET s,TRAMA trama) |
---|
| 183 | { |
---|
| 184 | int i,resul,idaccion,numipes,cont,estado_cliente; |
---|
| 185 | char *parametros,*nombrefuncion; |
---|
| 186 | char *iph,*ids,*coletilla; |
---|
| 187 | char pids[20],ipes[MAXLON_PARAMETROSIPH]; |
---|
| 188 | |
---|
| 189 | parametros=&trama.parametros[0]; |
---|
| 190 | |
---|
| 191 | if (trama.ejecutor=='1'){ // Debe ejecutar el servidor |
---|
| 192 | INTROaFINCAD(parametros); |
---|
| 193 | nombrefuncion=toma_parametro("nfn",parametros); |
---|
[a6b881e] | 194 | resul=strcmp(nombrefuncion,"InclusionCliente"); |
---|
[34fc87f] | 195 | if(resul==0){ |
---|
[a6b881e] | 196 | if(!InclusionCliente(s,parametros)) |
---|
[34fc87f] | 197 | respuesta_cortesia(s); |
---|
| 198 | return; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | resul=strcmp(nombrefuncion,"inclusion_cliWINLNX"); |
---|
| 202 | if(resul==0){ |
---|
| 203 | inclusion_cliWINLNX(s,parametros); |
---|
| 204 | return; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | resul=strcmp(nombrefuncion,"inclusion_REPO"); |
---|
| 208 | if(resul==0){ |
---|
| 209 | inclusion_REPO(s,parametros); |
---|
| 210 | return; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | resul=strcmp(nombrefuncion,"ComandosPendientes"); |
---|
| 214 | if(resul==0){ |
---|
| 215 | if(!ComandosPendientes(s,parametros)) |
---|
| 216 | respuesta_cortesia(s); |
---|
| 217 | return; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | resul=strcmp(nombrefuncion,"RecuperaItem"); |
---|
| 221 | if(resul==0){ |
---|
| 222 | if(!RecuperaItem(s,parametros)) |
---|
| 223 | respuesta_cortesia(s); |
---|
| 224 | return; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | resul=strcmp(nombrefuncion,"EjecutarItem"); |
---|
| 228 | if(resul==0){ |
---|
| 229 | if(!EjecutarItem(s,parametros)) |
---|
| 230 | respuesta_cortesia(s); |
---|
| 231 | return; |
---|
| 232 | } |
---|
| 233 | resul=strcmp(nombrefuncion,"DisponibilidadComandos"); |
---|
| 234 | if(resul==0){ |
---|
| 235 | DisponibilidadComandos(s,parametros); |
---|
| 236 | respuesta_cortesia(s); |
---|
| 237 | return; |
---|
| 238 | } |
---|
| 239 | resul=strcmp(nombrefuncion,"Sondeo"); |
---|
| 240 | if(resul==0){ |
---|
| 241 | Sondeo(s,parametros); |
---|
| 242 | return; |
---|
| 243 | } |
---|
| 244 | resul=strcmp(nombrefuncion,"Arrancar"); |
---|
| 245 | if(resul==0){ |
---|
| 246 | Arrancar(parametros); |
---|
| 247 | return; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | resul=strcmp(nombrefuncion,"Actualizar"); |
---|
| 251 | if(resul==0){ |
---|
| 252 | Actualizar(parametros); |
---|
| 253 | return; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | resul=strcmp(nombrefuncion,"Conmutar"); |
---|
| 257 | if(resul==0){ |
---|
| 258 | Conmutar(parametros); |
---|
| 259 | return; |
---|
| 260 | } |
---|
| 261 | resul=strcmp(nombrefuncion,"Purgar"); |
---|
| 262 | if(resul==0){ |
---|
| 263 | PurgarTablaSockets(parametros); |
---|
| 264 | return; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | resul=strcmp(nombrefuncion,"RESPUESTA_Arrancar"); |
---|
| 268 | if(resul==0){ |
---|
| 269 | RESPUESTA_Arrancar(s,parametros); |
---|
| 270 | respuesta_cortesia(s); |
---|
| 271 | return; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | resul=strcmp(nombrefuncion,"RESPUESTA_Apagar"); |
---|
| 275 | if(resul==0){ |
---|
| 276 | RESPUESTA_Apagar(s,parametros); |
---|
| 277 | respuesta_cortesia(s); |
---|
| 278 | return; |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | resul=strcmp(nombrefuncion,"RESPUESTA_RemboOffline"); |
---|
| 282 | if(resul==0){ |
---|
| 283 | RESPUESTA_RemboOffline(s,parametros); |
---|
| 284 | respuesta_cortesia(s); |
---|
| 285 | return; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | resul=strcmp(nombrefuncion,"RESPUESTA_Reiniciar"); |
---|
| 289 | if(resul==0){ |
---|
| 290 | RESPUESTA_Reiniciar(s,parametros); |
---|
| 291 | respuesta_cortesia(s); |
---|
| 292 | return; |
---|
| 293 | } |
---|
| 294 | resul=strcmp(nombrefuncion,"RESPUESTA_ExecShell"); |
---|
| 295 | if(resul==0){ |
---|
| 296 | RESPUESTA_ExecShell(s,parametros); |
---|
| 297 | respuesta_cortesia(s); |
---|
| 298 | return; |
---|
| 299 | } |
---|
| 300 | resul=strcmp(nombrefuncion,"RESPUESTA_CrearPerfilSoftware"); |
---|
| 301 | if(resul==0){ |
---|
| 302 | RESPUESTA_CrearPerfilSoftware(s,parametros); |
---|
| 303 | respuesta_cortesia(s); |
---|
| 304 | return; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | resul=strcmp(nombrefuncion,"RESPUESTA_CrearSoftwareIncremental"); |
---|
| 308 | if(resul==0){ |
---|
| 309 | RESPUESTA_CrearSoftwareIncremental(s,parametros); |
---|
| 310 | respuesta_cortesia(s); |
---|
| 311 | return; |
---|
| 312 | } |
---|
| 313 | resul=strcmp(nombrefuncion,"RESPUESTA_RestaurarImagen"); |
---|
| 314 | if(resul==0){ |
---|
| 315 | RESPUESTA_RestaurarImagen(s,parametros); |
---|
| 316 | respuesta_cortesia(s); |
---|
| 317 | return; |
---|
| 318 | } |
---|
| 319 | resul=strcmp(nombrefuncion,"RESPUESTA_ParticionaryFormatear"); |
---|
| 320 | if(resul==0){ |
---|
| 321 | RESPUESTA_ParticionaryFormatear(s,parametros); |
---|
| 322 | respuesta_cortesia(s); |
---|
| 323 | return; |
---|
| 324 | } |
---|
| 325 | resul=strcmp(nombrefuncion,"RESPUESTA_Configurar"); |
---|
| 326 | if(resul==0){ |
---|
| 327 | RESPUESTA_Configurar(s,parametros); |
---|
| 328 | respuesta_cortesia(s); |
---|
| 329 | return; |
---|
| 330 | } |
---|
| 331 | resul=strcmp(nombrefuncion,"RESPUESTA_TomaConfiguracion"); |
---|
| 332 | if(resul==0){ |
---|
| 333 | RESPUESTA_TomaConfiguracion(s,parametros); |
---|
| 334 | respuesta_cortesia(s); |
---|
| 335 | return; |
---|
| 336 | } |
---|
| 337 | resul=strcmp(nombrefuncion,"RESPUESTA_TomaHardware"); |
---|
| 338 | if(resul==0){ |
---|
| 339 | RESPUESTA_TomaHardware(s,parametros); |
---|
| 340 | respuesta_cortesia(s); |
---|
| 341 | return; |
---|
[ec01697] | 342 | } |
---|
| 343 | resul=strcmp(nombrefuncion,"RESPUESTA_TomaSoftware"); |
---|
| 344 | if(resul==0){ |
---|
| 345 | RESPUESTA_TomaSoftware(s,parametros); |
---|
| 346 | respuesta_cortesia(s); |
---|
| 347 | return; |
---|
[34fc87f] | 348 | } |
---|
| 349 | } |
---|
| 350 | else{ // Debe ejecutar elcliente rembo |
---|
| 351 | coletilla=corte_iph(parametros); // toma el puntero al comienzo del parametros iph |
---|
| 352 | INTROaFINCAD(coletilla); |
---|
| 353 | iph=toma_parametro("iph",coletilla); // Toma ipes |
---|
| 354 | ids=toma_parametro("ids",coletilla); // Toma identificador de la accion |
---|
| 355 | coletilla[0]='\0';// Corta la trama en la ip |
---|
| 356 | strcpy(ipes,iph); // Copia la cadena de ipes |
---|
| 357 | if(ids!=NULL){ |
---|
| 358 | idaccion=atoi(ids); |
---|
| 359 | sprintf(pids,"ids=%d\r",idaccion); |
---|
| 360 | strcat(parametros,pids); // Le ande el identificador de la accion |
---|
| 361 | } |
---|
| 362 | numipes=cuenta_ipes(ipes); // Numero de ipes a los que enviar las tramas |
---|
| 363 | cont=0; |
---|
| 364 | DesmarcaServidoresRembo(); |
---|
| 365 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 366 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 367 | if (IgualIP(ipes,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 368 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_REMBO); |
---|
| 369 | if(estado_cliente==0){ // Cliente Rembo ... |
---|
| 370 | strcpy(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 371 | MarcaServidoresRembo(tbsockets[i].ipsrvrmb,tbsockets[i].ip); |
---|
| 372 | } |
---|
| 373 | else{ |
---|
| 374 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 375 | if(estado_cliente!=0){ // Cliente Windows(Windows98,Windows2000,windows XP...) y Linux |
---|
| 376 | strcpy(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 377 | manda_comando(tbsockets[i].sock,parametros); |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | cont++; // Contador de envios de tramas a ordenadores |
---|
| 381 | if(cont==numipes) break; |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | EnviaServidoresRembo(parametros); |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 389 | // Funcin: manda_comando |
---|
[34fc87f] | 390 | // |
---|
| 391 | // Descripcin: |
---|
[277d0cd] | 392 | // Esta funcin envia un comando por la red (TCP) desde el servidor hidra al servidor rembo que controla al cliente que lo ejecutarn |
---|
[34fc87f] | 393 | // Parametros: |
---|
| 394 | // - sock : El socket del cliente |
---|
| 395 | // - parametros: El contenido del comando |
---|
| 396 | // ________________________________________________________________________________________________________ |
---|
| 397 | int manda_comando(SOCKET sock,char* parametros) |
---|
| 398 | { |
---|
| 399 | TRAMA trama; |
---|
| 400 | int resul; |
---|
| 401 | |
---|
| 402 | trama.arroba='@'; |
---|
| 403 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 404 | trama.ejecutor='0'; |
---|
| 405 | strcpy(trama.parametros,parametros); |
---|
| 406 | resul=manda_trama(sock,&trama); |
---|
| 407 | return(resul); |
---|
| 408 | } |
---|
| 409 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 410 | // Funcin: manda_trama |
---|
[34fc87f] | 411 | // |
---|
| 412 | // Descripcin: |
---|
[277d0cd] | 413 | // Esta funcin envia una trama por la red (TCP) |
---|
[34fc87f] | 414 | // Parametros: |
---|
| 415 | // - sock : El socket del host al que se dirige la trama |
---|
| 416 | // - trama: El contenido de la trama |
---|
| 417 | // ________________________________________________________________________________________________________ |
---|
| 418 | int manda_trama(SOCKET sock,TRAMA* trama) |
---|
| 419 | { |
---|
| 420 | int nLeft,idx,ret; |
---|
| 421 | Encriptar((char*)trama); |
---|
| 422 | nLeft = strlen((char*)trama); |
---|
| 423 | idx = 0; |
---|
| 424 | while(nLeft > 0){ |
---|
| 425 | ret = send(sock,(char*)&trama[idx], nLeft, 0); |
---|
| 426 | |
---|
| 427 | if (ret == 0){ |
---|
| 428 | break; |
---|
| 429 | } |
---|
| 430 | else |
---|
| 431 | if (ret == SOCKET_ERROR){ |
---|
| 432 | RegistraLog("***send() fallo en hebra cliente",true); |
---|
| 433 | return(FALSE); |
---|
| 434 | } |
---|
| 435 | nLeft -= ret; |
---|
| 436 | idx += ret; |
---|
| 437 | } |
---|
| 438 | return(TRUE); |
---|
| 439 | } |
---|
| 440 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 441 | // Funcin: recibe_trama |
---|
[34fc87f] | 442 | // |
---|
| 443 | // Descripcin: |
---|
[277d0cd] | 444 | // Esta funcin recibe una trama por la red (TCP) |
---|
[34fc87f] | 445 | // Parametros: |
---|
| 446 | // - sock : El socket del cliente |
---|
| 447 | // - trama: El buffer para recibir la trama |
---|
| 448 | // ________________________________________________________________________________________________________ |
---|
| 449 | int recibe_trama(SOCKET sock,TRAMA* trama) |
---|
| 450 | { |
---|
| 451 | int ret; |
---|
| 452 | |
---|
| 453 | while(1){ // Bucle para recibir datos del cliente |
---|
| 454 | ret = recv(sock,(char*)trama,LONGITUD_TRAMA,0); |
---|
| 455 | if (ret == 0) // Conexin cerrada por parte del cliente (Graceful close) |
---|
| 456 | break; |
---|
| 457 | else{ |
---|
| 458 | if (ret == SOCKET_ERROR){ |
---|
| 459 | RegistraLog("***recv() fallo en recepcion trama",true); |
---|
| 460 | return (FALSE); |
---|
| 461 | } |
---|
| 462 | else // Datos recibidos |
---|
| 463 | break; |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | Desencriptar((char*)trama); |
---|
| 467 | trama->parametros[ret-11]=(char)NULL; // Coloca caracter fin de cadena en trama |
---|
| 468 | return(TRUE); |
---|
| 469 | } |
---|
| 470 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 471 | // Funcin: hay_hueco |
---|
[34fc87f] | 472 | // |
---|
| 473 | // Descripcin: |
---|
[277d0cd] | 474 | // Esta funcin devuelve true o false dependiendo de que haya hueco en la tabla de sockets para un nuevo cliente. |
---|
[34fc87f] | 475 | // Parametros: |
---|
| 476 | // - idx: Primer indice libre que se podrn utilizar |
---|
| 477 | // ________________________________________________________________________________________________________ |
---|
| 478 | int hay_hueco(int *idx) |
---|
| 479 | { |
---|
| 480 | int i; |
---|
| 481 | |
---|
| 482 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 483 | if (strncmp(tbsockets[i].ip,"\0",1)==0){ // Hay un hueco |
---|
| 484 | *idx=i; |
---|
| 485 | return(TRUE); |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | return(FALSE); |
---|
| 489 | } |
---|
| 490 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 491 | // Funcin: cliente_existente |
---|
[34fc87f] | 492 | // |
---|
| 493 | // Descripcin: |
---|
[277d0cd] | 494 | // Esta funcin devuelve true o false dependiendo de si el cliente estnya registrado en la tabla de sockets |
---|
[34fc87f] | 495 | // Parametros: |
---|
| 496 | // - ip : La ip del cliente a buscar |
---|
| 497 | // - idx: Indice que ocuparn el cliente, de estar ya registrado |
---|
| 498 | // ________________________________________________________________________________________________________ |
---|
| 499 | BOOLEAN cliente_existente(char *ip,int* idx) |
---|
| 500 | { |
---|
| 501 | int i; |
---|
| 502 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 503 | if (strcmp(ip,tbsockets[i].ip)==0){ // Si existe la IP ... |
---|
| 504 | *idx=i; |
---|
| 505 | return(TRUE); |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | return(FALSE); |
---|
| 509 | } |
---|
| 510 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 511 | // Funcin: hay_huecoservidorrembo |
---|
[34fc87f] | 512 | // |
---|
| 513 | // Descripcin: |
---|
[277d0cd] | 514 | // Esta funcin devuelve true o false dependiendo de que haya hueco en la tabla de sockets para un nuevo servidor rembo. |
---|
[34fc87f] | 515 | // Parametros: |
---|
| 516 | // - idx: Primer indice libre que se podrn utilizar |
---|
| 517 | // ________________________________________________________________________________________________________ |
---|
| 518 | int hay_huecoservidorrembo(int *idx) |
---|
| 519 | { |
---|
| 520 | int i; |
---|
| 521 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 522 | if (strncmp(tbsocketsSRVRMB[i].ip,"\0",1)==0){ // Hay un hueco |
---|
| 523 | *idx=i; |
---|
| 524 | return(TRUE); |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | return(FALSE); |
---|
| 528 | } |
---|
| 529 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 530 | // Funcin: servidorrembo_existente |
---|
[34fc87f] | 531 | // |
---|
| 532 | // Descripcin: |
---|
[277d0cd] | 533 | // Esta funcin devuelve true o false dependiendo de si el servidor estnya registrado en la tabla de sockets |
---|
[34fc87f] | 534 | // Parametros: |
---|
| 535 | // - ip : La ip delcliente a buscar |
---|
| 536 | // - idx Indice que ocuparn el servidor, de existir |
---|
| 537 | // ________________________________________________________________________________________________________ |
---|
| 538 | BOOLEAN servidorrembo_existente(char *ip,int* idx) |
---|
| 539 | { |
---|
| 540 | int i; |
---|
| 541 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 542 | if (strcmp(ip,tbsocketsSRVRMB[i].ip)==0){ // Si existe la IP ... |
---|
| 543 | *idx=i; |
---|
| 544 | return(TRUE); |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | return(FALSE); |
---|
| 548 | } |
---|
| 549 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 550 | // Funcin: INTROaFINCAD |
---|
[34fc87f] | 551 | // |
---|
| 552 | // Descripcin: |
---|
| 553 | // Cambia INTROS por caracteres fin de cadena ('\0') en una cadena |
---|
| 554 | // Parametros: |
---|
| 555 | // - parametros : La cadena a explorar |
---|
| 556 | // ________________________________________________________________________________________________________ |
---|
| 557 | void INTROaFINCAD(char* parametros) |
---|
| 558 | { |
---|
| 559 | int lon,i; |
---|
| 560 | lon=strlen(parametros); |
---|
| 561 | for(i=0;i<lon;i++){ |
---|
| 562 | if(parametros[i]=='\r') parametros[i]='\0'; |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 566 | // Funcinn: FINCADaINTRO |
---|
[34fc87f] | 567 | // |
---|
| 568 | // Descripcinn?: |
---|
| 569 | // Cambia caracteres fin de cadena ('\0') por INTROS en una cadena |
---|
| 570 | // Parametros: |
---|
| 571 | // - parametros : La cadena a explorar |
---|
| 572 | // ________________________________________________________________________________________________________ |
---|
| 573 | void FINCADaINTRO(char* a,char *b) |
---|
| 574 | { |
---|
| 575 | char *i; |
---|
| 576 | for(i=a;i<b;i++){ // Cambia los NULOS por INTROS |
---|
| 577 | if(*i=='\0') *i='\r'; |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 581 | // Funcin: cuenta_ipes |
---|
[34fc87f] | 582 | // |
---|
| 583 | // Descripcin: |
---|
| 584 | // Cuenta las comas (caracter de separacion) de las cadenas de ipes |
---|
| 585 | // Parnetros: |
---|
| 586 | // - parametros : La cadena a explorar |
---|
| 587 | // ________________________________________________________________________________________________________ |
---|
| 588 | int cuenta_ipes(char* iph) |
---|
| 589 | { |
---|
| 590 | int lon,i,cont=1; |
---|
| 591 | lon=strlen(iph); |
---|
| 592 | for(i=0;i<lon;i++){ |
---|
| 593 | if(iph[i]==';') cont++; |
---|
| 594 | } |
---|
| 595 | return(cont); |
---|
| 596 | } |
---|
| 597 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 598 | // Funcin: toma_parametro |
---|
| 599 | // |
---|
| 600 | // Descripcin: |
---|
| 601 | // Esta funcin devuelve el valor de un parametro incluido en la trama. |
---|
| 602 | // El formato del protocolo es: "nombre_parametro=valor_parametro" |
---|
| 603 | // Parnetros: |
---|
| 604 | // - nombre_parametro: Es el nombre del parnetro a recuperar |
---|
| 605 | // - parametros: Es la matriz que contiene todos los parnetros |
---|
| 606 | // ________________________________________________________________________________________________________ |
---|
| 607 | char * toma_parametro(const char* nombre_parametro,char *parametros) |
---|
| 608 | { |
---|
| 609 | int i=0; |
---|
| 610 | char* pos; |
---|
| 611 | |
---|
| 612 | for(i=0;i<LONGITUD_PARAMETROS-4;i++){ |
---|
| 613 | if(parametros[i]==nombre_parametro[0]){ |
---|
| 614 | if(parametros[i+1]==nombre_parametro[1]){ |
---|
| 615 | if(parametros[i+2]==nombre_parametro[2]){ |
---|
| 616 | if(parametros[i+3]=='='){ |
---|
| 617 | pos=¶metros[i+4]; |
---|
| 618 | return(pos); |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | return(NULL); |
---|
| 625 | } |
---|
| 626 | // ________________________________________________________________________________________________________ |
---|
| 627 | // Funcin: split_parametros |
---|
| 628 | // |
---|
| 629 | // Descripcin: |
---|
| 630 | // Esta funcin trocea una cadena segn un carnter delimitador, Devuelve el nmero de trozos |
---|
| 631 | // Parnetros: |
---|
| 632 | // - trozos: Array de punteros a cadenas |
---|
| 633 | // - cadena: Cadena a trocear |
---|
| 634 | // - ch: Carnter delimitador |
---|
| 635 | // ________________________________________________________________________________________________________ |
---|
| 636 | int split_parametros(char **trozos,char *cadena, char * ch){ |
---|
| 637 | int w=0; |
---|
| 638 | char* token; |
---|
| 639 | |
---|
| 640 | token= strtok(cadena,ch); // Trocea segn delimitador |
---|
| 641 | while( token != NULL ){ |
---|
| 642 | trozos[w++]=token; |
---|
| 643 | token=strtok(NULL,ch); // Siguiente token |
---|
| 644 | } |
---|
| 645 | trozos[w++]=token; |
---|
| 646 | return(w-1); // Devuelve el numero de trozos |
---|
| 647 | } |
---|
| 648 | // ________________________________________________________________________________________________________ |
---|
| 649 | // Funcin: corte_iph |
---|
[34fc87f] | 650 | // |
---|
| 651 | // Descripcin: |
---|
[277d0cd] | 652 | // Esta funcin devuelve el valor del parametro iph incluido en la trama que debe ser el ltimo parnetro de la trama. |
---|
[34fc87f] | 653 | // Parnetros: |
---|
| 654 | // - parametros: Parnetros de la trama |
---|
| 655 | // ________________________________________________________________________________________________________ |
---|
| 656 | char* corte_iph(char *parametros) |
---|
| 657 | { |
---|
| 658 | int i=0; |
---|
| 659 | char nombre_parametro[5]; |
---|
| 660 | |
---|
| 661 | strcpy(nombre_parametro,"iph="); |
---|
| 662 | for(i=0;i<LONGITUD_PARAMETROS-4;i++){ |
---|
| 663 | if(parametros[i]==nombre_parametro[0]){ |
---|
| 664 | if(parametros[i+1]==nombre_parametro[1]){ |
---|
| 665 | if(parametros[i+2]==nombre_parametro[2]){ |
---|
| 666 | if(parametros[i+3]=='='){ |
---|
| 667 | return(¶metros[i]); //Devuelve la posicion de comienzo de la iph |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | return(NULL); |
---|
| 674 | } |
---|
| 675 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 676 | // Funcin: respuesta_cortesia |
---|
[34fc87f] | 677 | // |
---|
| 678 | // Descripcin: |
---|
| 679 | // Envn respuesta de cortesn al cliente rembo |
---|
| 680 | // Parnetros: |
---|
| 681 | // - s: Socket usado por el cliente para comunicarse con el servidor HIDRA |
---|
| 682 | // ________________________________________________________________________________________________________ |
---|
| 683 | int respuesta_cortesia(SOCKET s) |
---|
| 684 | { |
---|
| 685 | char nwparametros[100]; |
---|
| 686 | |
---|
| 687 | nwparametros[0]='\0'; |
---|
| 688 | strcat(nwparametros,"nfn=Cortesia"); |
---|
| 689 | strcat(nwparametros,"\r"); |
---|
| 690 | return(manda_comando(s,nwparametros)); |
---|
| 691 | } |
---|
| 692 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 693 | // Funcin: NoComandosPendientes |
---|
[34fc87f] | 694 | // |
---|
| 695 | // Descripcin: |
---|
| 696 | // Envn respuesta de cortesn al cliente rembo |
---|
| 697 | // Parnetros: |
---|
| 698 | // - s: Socket usado por el cliente para comunicarse con el servidor HIDRA |
---|
| 699 | // ________________________________________________________________________________________________________ |
---|
| 700 | int NoComandosPendientes(SOCKET s) |
---|
| 701 | { |
---|
| 702 | char nwparametros[100]; |
---|
| 703 | |
---|
| 704 | nwparametros[0]='\0'; |
---|
| 705 | strcat(nwparametros,"nfn=NoComandosPtes"); |
---|
| 706 | strcat(nwparametros,"\r"); |
---|
| 707 | return(manda_comando(s,nwparametros)); |
---|
| 708 | } |
---|
| 709 | // ________________________________________________________________________________________________________ |
---|
[a6b881e] | 710 | // Funcin: InclusionCliente |
---|
[34fc87f] | 711 | // |
---|
| 712 | // Descripcin: |
---|
[277d0cd] | 713 | // Esta funcin incorpora el socket de un nuevo cliente a la tabla de sockets y le devuelve alguna de sus propiedades: nombre, |
---|
[34fc87f] | 714 | // dentificador, perfil hardware , mens... |
---|
| 715 | // Parnetros: |
---|
| 716 | // - s: Socket del cliente |
---|
| 717 | // - parametros: Parnetros de la trama recibida |
---|
| 718 | // ________________________________________________________________________________________________________ |
---|
[a6b881e] | 719 | int InclusionCliente(SOCKET s,char *parametros) |
---|
[34fc87f] | 720 | { |
---|
| 721 | char ErrStr[200],sqlstr[1000]; |
---|
| 722 | Database db; |
---|
| 723 | Table tbl; |
---|
| 724 | |
---|
| 725 | char *iph,*cfg,*mac,*nau,*nor,*ipr,*ipd; |
---|
| 726 | int i,lon,glon,idx,resul,puertorepo; |
---|
| 727 | char nwparametros[LONGITUD_PARAMETROS]; |
---|
| 728 | char ipservidordhcp[16],ipservidorrembo[16],nombreordenador[100]; |
---|
| 729 | int idordenador,idaula,idconfiguracion,idparticion,idperfilhard,idmenu,cache; |
---|
| 730 | |
---|
| 731 | // Toma parnetros |
---|
| 732 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 733 | mac=toma_parametro("mac",parametros); // Toma mac |
---|
| 734 | cfg=toma_parametro("cfg",parametros); // Toma configuracion |
---|
| 735 | nau=toma_parametro("nau",parametros); // Toma nombre del grupo em el fichero config de rembo |
---|
| 736 | nor=toma_parametro("nor",parametros); // Toma nombre del ordenador en el fichero config de rembo |
---|
| 737 | ipd=toma_parametro("ipd",parametros); // Toma ip del servidor dhcpd |
---|
| 738 | ipr=toma_parametro("ipr",parametros); // Toma ip del servidor rembo |
---|
| 739 | |
---|
| 740 | // Toma las propiedades del ordenador |
---|
| 741 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
[a6b881e] | 742 | RegistraLog("Error de conexión con la base de datos",false); |
---|
[34fc87f] | 743 | db.GetErrorErrStr(ErrStr); |
---|
| 744 | return(false); |
---|
| 745 | } |
---|
| 746 | // Recupera los datos del ordenador |
---|
[51dcdc7] | 747 | sprintf(sqlstr,"SELECT ordenadores.idordenador,ordenadores.idaula,ordenadores.nombreordenador, ordenadores.idperfilhard, ordenadores.idconfiguracion,ordenadores.idparticion,servidoresrembo.ip AS ipservidorrembo,servidoresrembo.puertorepo, ordenadores.idmenu,ordenadores.cache FROM ordenadores INNER JOIN servidoresrembo ON ordenadores.idservidorrembo = servidoresrembo.idservidorrembo WHERE ordenadores.ip = '%s'",iph); |
---|
[34fc87f] | 748 | |
---|
| 749 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
[a6b881e] | 750 | RegistraLog("Error al ejecutar la consulta",false); |
---|
[34fc87f] | 751 | db.GetErrorErrStr(ErrStr); |
---|
| 752 | return(false); |
---|
| 753 | } |
---|
| 754 | if(tbl.ISEOF()){ // Si No existe registro |
---|
[73ed2a1] | 755 | RegistraLog("Cliente No encontrado, se rechaza la petición",false); |
---|
[34fc87f] | 756 | if(aulaup==AUTOINCORPORACION_OFF) // No estnactivada la incorporacin automnica |
---|
| 757 | return(false); |
---|
| 758 | if(!cuestion_nuevoordenador(db,tbl,&idordenador,nau,nor,iph,mac,cfg,ipd,ipr)) // Ha habido algn error en la incorporacin automnica |
---|
| 759 | return(false); |
---|
| 760 | // Valores por defecto del nuevo ordenador |
---|
| 761 | strcpy(nombreordenador,nor); |
---|
| 762 | idperfilhard=0; |
---|
| 763 | strcpy(ipservidordhcp,ipd); |
---|
| 764 | strcpy(ipservidorrembo,ipr); |
---|
| 765 | idmenu=0; |
---|
| 766 | } |
---|
| 767 | else{ |
---|
[a6b881e] | 768 | // sprintf(msglog,"Petición de Inclusión del CLiente:%s",iph); |
---|
| 769 | // RegistraLog(msglog,false); |
---|
| 770 | |
---|
[34fc87f] | 771 | if(!tbl.Get("idordenador",idordenador)){ // Toma dato |
---|
| 772 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 773 | return(false); |
---|
| 774 | } |
---|
| 775 | if(!tbl.Get("nombreordenador",nombreordenador)){ // Toma dato |
---|
| 776 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 777 | return(false); |
---|
| 778 | } |
---|
| 779 | if(!tbl.Get("idaula",idaula)){ // Toma dato |
---|
| 780 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 781 | return(false); |
---|
| 782 | } |
---|
| 783 | |
---|
| 784 | if(!tbl.Get("idconfiguracion",idconfiguracion)){ // Toma dato |
---|
| 785 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 786 | return(false); |
---|
| 787 | } |
---|
| 788 | if(!tbl.Get("idparticion",idparticion)){ // Toma dato |
---|
| 789 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 790 | return(false); |
---|
| 791 | } |
---|
| 792 | if(!tbl.Get("idperfilhard",idperfilhard)){ // Toma dato |
---|
| 793 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 794 | return(false); |
---|
| 795 | } |
---|
[51dcdc7] | 796 | /* |
---|
[34fc87f] | 797 | if(!tbl.Get("ipservidordhcp",ipservidordhcp)){ // Toma dato |
---|
| 798 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 799 | return(false); |
---|
| 800 | } |
---|
[51dcdc7] | 801 | |
---|
[34fc87f] | 802 | lon=strlen(ipservidordhcp); |
---|
| 803 | for (i=0;i<lon;i++){ |
---|
| 804 | if(ipservidordhcp[i]==' ') { |
---|
| 805 | ipservidordhcp[i]='\0'; |
---|
| 806 | break; |
---|
| 807 | } |
---|
| 808 | } |
---|
[51dcdc7] | 809 | */ |
---|
[34fc87f] | 810 | if(!tbl.Get("ipservidorrembo",ipservidorrembo)){ // Toma dato |
---|
| 811 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 812 | return(false); |
---|
| 813 | } |
---|
| 814 | lon=strlen(ipservidorrembo); |
---|
| 815 | for (i=0;i<lon;i++){ |
---|
| 816 | if(ipservidorrembo[i]==' ') { |
---|
| 817 | ipservidorrembo[i]='\0'; |
---|
| 818 | break; |
---|
| 819 | } |
---|
| 820 | } |
---|
| 821 | if(!tbl.Get("puertorepo",puertorepo)){ // Toma dato |
---|
| 822 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 823 | return(false); |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | if(!tbl.Get("idmenu",idmenu)){ // Toma dato |
---|
| 827 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 828 | return(false); |
---|
| 829 | } |
---|
| 830 | if(!tbl.Get("cache",cache)){ // Toma dato |
---|
| 831 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 832 | return(false); |
---|
| 833 | } |
---|
| 834 | resul=actualiza_configuracion(db,tbl,cfg,idconfiguracion,idparticion,iph); // Actualiza la configuracin del ordenador |
---|
| 835 | if(!resul){ |
---|
| 836 | pthread_mutex_unlock(&guardia); |
---|
| 837 | return(false); |
---|
| 838 | } |
---|
| 839 | } |
---|
| 840 | // Incluyendo al cliente en la tabla de sokets |
---|
| 841 | if (cliente_existente(iph,&i)){ // Si ya existe la IP ... |
---|
| 842 | idx=i; |
---|
| 843 | //close(tbsockets[idx].sock); |
---|
| 844 | } |
---|
| 845 | else{ |
---|
| 846 | if (hay_hueco(&i)){ // Busca hueco para el nuevo cliente |
---|
| 847 | idx=i; |
---|
| 848 | strcpy(tbsockets[idx].ip,iph);// Copia IP |
---|
| 849 | } |
---|
| 850 | else |
---|
| 851 | return(false); // No hay huecos |
---|
| 852 | } |
---|
| 853 | strcpy(tbsockets[idx].estado,CLIENTE_INICIANDO); // Actualiza el estado del cliente |
---|
| 854 | tbsockets[idx].sock=s; // Guarda el socket |
---|
[51dcdc7] | 855 | //strcpy(tbsockets[idx].ipsrvdhcp,ipservidordhcp);// Guarda IP servidor dhcp |
---|
[34fc87f] | 856 | strcpy(tbsockets[idx].ipsrvrmb,ipservidorrembo);// Guarda IP servidor rembo |
---|
| 857 | |
---|
| 858 | inclusion_srvRMB(ipservidorrembo,puertorepo); // Actualiza tabla de servidores rembo |
---|
| 859 | |
---|
| 860 | // Prepara la trama |
---|
[a6b881e] | 861 | lon=sprintf(nwparametros,"nfn=RESPUESTA_InclusionCliente\r"); |
---|
[34fc87f] | 862 | lon+=sprintf(nwparametros+lon,"ido=%d\r",idordenador); |
---|
| 863 | lon+=sprintf(nwparametros+lon,"npc=%s\r",nombreordenador); |
---|
| 864 | lon+=sprintf(nwparametros+lon,"ida=%d\r",idaula); |
---|
| 865 | lon+=sprintf(nwparametros+lon,"hrd=%s\r",servidorhidra); |
---|
| 866 | lon+=sprintf(nwparametros+lon,"prt=%d\r",puerto); |
---|
| 867 | lon+=sprintf(nwparametros+lon,"ifh=%d\r",idperfilhard); |
---|
| 868 | lon+=sprintf(nwparametros+lon,"che=%d\r",cache); |
---|
| 869 | lon+=sprintf(nwparametros+lon,"ipr=%s\r",ipservidorrembo); |
---|
| 870 | lon+=sprintf(nwparametros+lon,"rep=%d\r",puertorepo); |
---|
| 871 | glon=lon; |
---|
| 872 | if(!Toma_menu(db,tbl,nwparametros,idmenu,lon)) nwparametros[glon]=(char)NULL; |
---|
| 873 | db.Close(); |
---|
| 874 | return(manda_comando(s,nwparametros)); |
---|
| 875 | } |
---|
| 876 | // ________________________________________________________________________________________________________ |
---|
| 877 | // Función: Toma menu |
---|
| 878 | // |
---|
| 879 | // Descripcin: |
---|
[277d0cd] | 880 | // Esta funcin toma los parametros del menu inicial del cliente rembo y se los envn en el proceso de inclusin |
---|
[34fc87f] | 881 | // Parnetros: |
---|
| 882 | // - nwparametros: Cadena con los parnetros a enviar al cliente |
---|
| 883 | // - idmenu: Identificador del men |
---|
| 884 | // - lon : Longitud inicial de la cadena de parnetros |
---|
| 885 | // ________________________________________________________________________________________________________ |
---|
| 886 | int Toma_menu(Database db, Table tbl,char* nwparametros,int idmenu,int lon) |
---|
| 887 | { |
---|
| 888 | Table littbl; |
---|
| 889 | |
---|
| 890 | char sqlstr[1000],ErrStr[200],titulo[250],descripitem[250],urlimg[250]; |
---|
| 891 | int idaccionmenu,idtipoaccion,coorx,coory,idurlimg; |
---|
| 892 | int modalidad,resolucion,tipoaccion,tipoitem; |
---|
| 893 | char htmlmenupub[250],htmlmenupri[250]; |
---|
| 894 | |
---|
| 895 | sprintf(sqlstr,"SELECT menus.resolucion,menus.titulo,menus.coorx,menus.coory,menus.modalidad,menus.scoorx,menus.scoory,menus.smodalidad,menus.htmlmenupub,menus.htmlmenupri,acciones_menus.tipoaccion,acciones_menus.idaccionmenu,acciones_menus.idtipoaccion,acciones_menus.tipoitem,acciones_menus.descripitem,acciones_menus.idurlimg FROM acciones_menus INNER JOIN menus ON acciones_menus.idmenu = menus.idmenu WHERE menus.idmenu=%d order by acciones_menus.orden",idmenu); |
---|
| 896 | |
---|
| 897 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 898 | db.GetErrorErrStr(ErrStr); |
---|
| 899 | return(false); |
---|
| 900 | } |
---|
| 901 | if (tbl.ISEOF()) return(true); |
---|
| 902 | |
---|
| 903 | if(!tbl.Get("titulo",titulo)){ // Toma dato |
---|
| 904 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 905 | return(false); |
---|
| 906 | } |
---|
| 907 | if(!tbl.Get("coorx",coorx)){ // Toma dato |
---|
| 908 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 909 | return(false); |
---|
| 910 | } |
---|
| 911 | if(!tbl.Get("coory",coory)){ // Toma dato |
---|
| 912 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 913 | return(false); |
---|
| 914 | } |
---|
| 915 | if(!tbl.Get("modalidad",modalidad)){ // Toma dato |
---|
| 916 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 917 | return(false); |
---|
| 918 | } |
---|
| 919 | lon+=sprintf(nwparametros+lon,"cmn=%s&%d&%d&%d&",titulo,coorx,coory,modalidad); // Cabecera de menu |
---|
| 920 | |
---|
| 921 | if(!tbl.Get("scoorx",coorx)){ // Toma dato |
---|
| 922 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 923 | return(false); |
---|
| 924 | } |
---|
| 925 | if(!tbl.Get("scoory",coory)){ // Toma dato |
---|
| 926 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 927 | return(false); |
---|
| 928 | } |
---|
| 929 | if(!tbl.Get("smodalidad",modalidad)){ // Toma dato |
---|
| 930 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 931 | return(false); |
---|
| 932 | } |
---|
| 933 | lon+=sprintf(nwparametros+lon,"%d&%d&%d",coorx,coory,modalidad); // Cabecera de menu |
---|
| 934 | |
---|
| 935 | if(!tbl.Get("resolucion",resolucion)){ // Toma dato |
---|
| 936 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 937 | return(false); |
---|
| 938 | } |
---|
| 939 | lon+=sprintf(nwparametros+lon,"&%d\r",resolucion); // Resolucion de la pantalla |
---|
| 940 | |
---|
| 941 | if(!tbl.Get("htmlmenupub",htmlmenupub)){ // Toma dato |
---|
| 942 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 943 | return(false); |
---|
| 944 | } |
---|
| 945 | if(!tbl.Get("htmlmenupri",htmlmenupri)){ // Toma dato |
---|
| 946 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 947 | return(false); |
---|
| 948 | } |
---|
| 949 | lon+=sprintf(nwparametros+lon,"htm=%s;%s\r",htmlmenupub,htmlmenupri); // Html de menu |
---|
| 950 | |
---|
| 951 | lon+=sprintf(nwparametros+lon,"mnu="); |
---|
| 952 | while(!tbl.ISEOF()){ // Recorre acciones del menu |
---|
| 953 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma dato |
---|
| 954 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 955 | return(false); |
---|
| 956 | } |
---|
| 957 | if(!tbl.Get("tipoitem",tipoitem)){ // Toma dato |
---|
| 958 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 959 | return(false); |
---|
| 960 | } |
---|
| 961 | if(!tbl.Get("idtipoaccion",idtipoaccion)){ // Toma dato |
---|
| 962 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 963 | return(false); |
---|
| 964 | } |
---|
| 965 | if(!tbl.Get("idaccionmenu",idaccionmenu)){ // Toma dato |
---|
| 966 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 967 | return(false); |
---|
| 968 | } |
---|
| 969 | if(!tbl.Get("descripitem",descripitem)){ // Toma dato |
---|
| 970 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 971 | return(false); |
---|
| 972 | } |
---|
| 973 | if(!tbl.Get("idurlimg",idurlimg)){ // Toma dato |
---|
| 974 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 975 | return(false); |
---|
| 976 | } |
---|
| 977 | |
---|
| 978 | sprintf(sqlstr,"SELECT urlicono FROM iconos WHERE idicono=%d",idurlimg); |
---|
| 979 | if(!db.Execute(sqlstr,littbl)){ // Error al leer |
---|
| 980 | db.GetErrorErrStr(ErrStr); |
---|
| 981 | return(false); |
---|
| 982 | } |
---|
| 983 | if (!littbl.ISEOF()){ |
---|
| 984 | if(!littbl.Get("urlicono",urlimg)){ // Toma dato |
---|
| 985 | littbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 986 | return(false); |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | else |
---|
| 990 | sprintf(urlimg,"itemdefault.pcx"); |
---|
| 991 | |
---|
| 992 | lon+=sprintf(nwparametros+lon,"%d&%s&%s&%d&%d\?",idaccionmenu,urlimg,descripitem,tipoitem,tipoaccion); |
---|
| 993 | tbl.MoveNext(); |
---|
| 994 | } |
---|
| 995 | nwparametros[lon-1]='\r'; |
---|
| 996 | nwparametros[lon]=(char)NULL; |
---|
| 997 | return(true); |
---|
| 998 | } |
---|
| 999 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1000 | // Funcin:RecuperaItem |
---|
[34fc87f] | 1001 | // |
---|
| 1002 | // Descripcin: |
---|
[277d0cd] | 1003 | // Esta funcin busca en la base de datos, los parametros de un items de un menu |
---|
[34fc87f] | 1004 | // Parnetros: |
---|
| 1005 | // - s: Socket del cliente |
---|
| 1006 | // - parametros: Parnetros de la trama recibida |
---|
| 1007 | // ________________________________________________________________________________________________________ |
---|
| 1008 | int RecuperaItem(SOCKET s,char *parametros) |
---|
| 1009 | { |
---|
| 1010 | char ErrStr[200],sqlstr[1000]; |
---|
| 1011 | Database db; |
---|
| 1012 | Table tbl; |
---|
| 1013 | char *ida; |
---|
| 1014 | int idtipoaccion,tipoaccion; |
---|
| 1015 | |
---|
| 1016 | // Toma parnetros |
---|
| 1017 | ida=toma_parametro("ida",parametros); // Toma identificador de la accin |
---|
| 1018 | |
---|
| 1019 | // Abre conexin con la base de datos |
---|
| 1020 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 1021 | db.GetErrorErrStr(ErrStr); |
---|
| 1022 | return(false); |
---|
| 1023 | } |
---|
| 1024 | sprintf(sqlstr,"SELECT tipoaccion,idtipoaccion FROM acciones_menus WHERE idaccionmenu=%s",ida); |
---|
| 1025 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1026 | db.GetErrorErrStr(ErrStr); |
---|
| 1027 | return(false); |
---|
| 1028 | } |
---|
| 1029 | if (tbl.ISEOF()) return(false); |
---|
| 1030 | |
---|
| 1031 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma tipo de accin |
---|
| 1032 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1033 | return(false); |
---|
| 1034 | } |
---|
| 1035 | if(!tbl.Get("idtipoaccion",idtipoaccion)){ // Toma identificador del tipo de accin |
---|
| 1036 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1037 | return(false); |
---|
| 1038 | } |
---|
| 1039 | switch(tipoaccion){ |
---|
| 1040 | case EJECUCION_PROCEDIMIENTO : |
---|
| 1041 | sprintf(sqlstr,"SELECT procedimientos_comandos.parametros FROM procedimientos_comandos WHERE procedimientos_comandos.idprocedimiento=%d",idtipoaccion); |
---|
| 1042 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1043 | db.GetErrorErrStr(ErrStr); |
---|
| 1044 | return(false); |
---|
| 1045 | } |
---|
| 1046 | if(tbl.ISEOF()) // No existe procedimiento |
---|
| 1047 | return(false); |
---|
| 1048 | |
---|
| 1049 | while(!tbl.ISEOF()){ |
---|
| 1050 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 1051 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1052 | return(false); |
---|
| 1053 | } |
---|
| 1054 | tbl.MoveNext(); |
---|
| 1055 | } |
---|
| 1056 | break; |
---|
| 1057 | case EJECUCION_TAREA : |
---|
| 1058 | //Las tareas no se recuperan como fichero de items; |
---|
| 1059 | break; |
---|
| 1060 | case EJECUCION_TRABAJO : |
---|
| 1061 | //Los t rabajos no se recuperan como fichero de items; |
---|
| 1062 | break; |
---|
| 1063 | } |
---|
| 1064 | db.Close(); |
---|
| 1065 | return(manda_comando(s,parametros)); |
---|
| 1066 | } |
---|
| 1067 | |
---|
| 1068 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1069 | // Funcin: actualiza_configuracion |
---|
[34fc87f] | 1070 | // |
---|
| 1071 | // Descripcin: |
---|
[277d0cd] | 1072 | // Esta funcin actualiza la base de datos con la configuracion de sistemas operativos y particiones de un ordenador |
---|
[34fc87f] | 1073 | // Parnetros: |
---|
| 1074 | // - db: Objeto base de datos (ya operativo) |
---|
| 1075 | // - tbl: Objeto tabla |
---|
| 1076 | // - cfg: cadena con una configuracin |
---|
| 1077 | // - idcfgo: Identificador de la configuracin actual del ordenador |
---|
| 1078 | // - ipho: Identificador de la configuracin actual de las particiones del ordenador |
---|
| 1079 | // - ipho: Ipe del ordenador |
---|
| 1080 | // ________________________________________________________________________________________________________ |
---|
| 1081 | int actualiza_hardware(Database db, Table tbl,char* hrd,char* ip,char*ido) |
---|
| 1082 | { |
---|
[a6b881e] | 1083 | int idtipohardware; |
---|
[ae04987] | 1084 | int i,lon=0,idcentro,widcentro; |
---|
[34fc87f] | 1085 | char *tbHardware[MAXHARDWARE]; |
---|
| 1086 | int tbidhardware[MAXHARDWARE]; |
---|
| 1087 | char *dualHardware[2]; |
---|
| 1088 | char ch[2]; // Carnter delimitador |
---|
| 1089 | char sqlstr[1000],ErrStr[200],descripcion[250],nombreordenador[250]; |
---|
[de2a6d1] | 1090 | |
---|
[ae04987] | 1091 | |
---|
[34fc87f] | 1092 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1093 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 1094 | pthread_mutex_lock(&guardia); |
---|
| 1095 | |
---|
| 1096 | // Toma Centro |
---|
| 1097 | sprintf(sqlstr,"SELECT aulas.idcentro,ordenadores.nombreordenador FROM aulas INNER JOIN ordenadores ON aulas.idaula=ordenadores.idaula WHERE ordenadores.idordenador=%s",ido); |
---|
| 1098 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1099 | db.GetErrorErrStr(ErrStr); |
---|
| 1100 | pthread_mutex_unlock(&guardia); |
---|
| 1101 | return(false); |
---|
| 1102 | } |
---|
[ae04987] | 1103 | if(!tbl.Get("idcentro",widcentro)){ // Toma dato |
---|
[34fc87f] | 1104 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1105 | pthread_mutex_unlock(&guardia); |
---|
| 1106 | return(false); |
---|
| 1107 | } |
---|
[ae04987] | 1108 | idcentro=widcentro+0; // Bug Mysql |
---|
| 1109 | |
---|
[34fc87f] | 1110 | if(!tbl.Get("nombreordenador",nombreordenador)){ // Toma dato |
---|
| 1111 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1112 | pthread_mutex_unlock(&guardia); |
---|
| 1113 | return(false); |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | if(lon>MAXHARDWARE) lon=MAXHARDWARE; |
---|
| 1117 | // Trocea la cadena de configuracin |
---|
| 1118 | strcpy(ch,"\n");// caracter delimitador |
---|
| 1119 | lon=split_parametros(tbHardware,hrd,ch); |
---|
| 1120 | |
---|
| 1121 | // Trocea las cadenas de parametros de particin |
---|
| 1122 | for (i=0;i<lon;i++){ |
---|
| 1123 | strcpy(ch,"=");// caracter delimitador "=" |
---|
| 1124 | split_parametros(dualHardware,tbHardware[i],ch); // Nmero de particin |
---|
[a6b881e] | 1125 | sprintf(sqlstr,"SELECT idtipohardware,descripcion FROM tipohardwares WHERE nemonico='%s'",dualHardware[0]); |
---|
[34fc87f] | 1126 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1127 | db.GetErrorErrStr(ErrStr); |
---|
| 1128 | pthread_mutex_unlock(&guardia); |
---|
| 1129 | return(false); |
---|
| 1130 | } |
---|
| 1131 | if(tbl.ISEOF()){ // Tipo de Hardware NO existente |
---|
[de2a6d1] | 1132 | RegistraLog("Existe un tipo de hardware que no está registrado. Se rechaza proceso de inventario",false); |
---|
[34fc87f] | 1133 | pthread_mutex_unlock(&guardia); |
---|
| 1134 | return(false); |
---|
| 1135 | } |
---|
| 1136 | else{ // Tipo de Hardware Existe |
---|
[a6b881e] | 1137 | if(!tbl.Get("idtipohardware",idtipohardware)){ // Toma dato |
---|
[34fc87f] | 1138 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1139 | pthread_mutex_unlock(&guardia); |
---|
| 1140 | return(false); |
---|
| 1141 | } |
---|
[a6b881e] | 1142 | if(!tbl.Get("descripcion",descripcion)){ // Toma dato |
---|
[34fc87f] | 1143 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1144 | pthread_mutex_unlock(&guardia); |
---|
| 1145 | return(false); |
---|
[ae04987] | 1146 | } |
---|
| 1147 | |
---|
[de2a6d1] | 1148 | sprintf(sqlstr,"SELECT idhardware FROM hardwares WHERE idtipohardware=%d AND descripcion='%s'",idtipohardware,dualHardware[1]); |
---|
[34fc87f] | 1149 | |
---|
| 1150 | // EJecuta consulta |
---|
| 1151 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1152 | db.GetErrorErrStr(ErrStr); |
---|
| 1153 | pthread_mutex_unlock(&guardia); |
---|
| 1154 | return(false); |
---|
| 1155 | } |
---|
[ae04987] | 1156 | |
---|
[34fc87f] | 1157 | if(tbl.ISEOF()){ // Hardware NO existente |
---|
[77196ff] | 1158 | sprintf(sqlstr,"INSERT hardwares (idtipohardware,descripcion,idcentro,grupoid) VALUES(%d,'%s',%d,0)",idtipohardware,dualHardware[1],idcentro); |
---|
[34fc87f] | 1159 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1160 | db.GetErrorErrStr(ErrStr); |
---|
| 1161 | pthread_mutex_unlock(&guardia); |
---|
| 1162 | return(false); |
---|
| 1163 | } |
---|
| 1164 | // Recupera el identificador del hardware |
---|
| 1165 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1166 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1167 | db.GetErrorErrStr(ErrStr); |
---|
| 1168 | pthread_mutex_unlock(&guardia); |
---|
| 1169 | return(false); |
---|
| 1170 | } |
---|
| 1171 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1172 | if(!tbl.Get("identificador",tbidhardware[i])){ |
---|
| 1173 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1174 | pthread_mutex_unlock(&guardia); |
---|
| 1175 | return(false); |
---|
| 1176 | } |
---|
| 1177 | } |
---|
| 1178 | } |
---|
| 1179 | else{ |
---|
[a6b881e] | 1180 | if(!tbl.Get("idhardware",tbidhardware[i])){ // Toma dato |
---|
[34fc87f] | 1181 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1182 | pthread_mutex_unlock(&guardia); |
---|
| 1183 | return(false); |
---|
| 1184 | } |
---|
| 1185 | } |
---|
| 1186 | } // Fin for |
---|
| 1187 | } |
---|
| 1188 | // Comprueba existencia de perfil hardware y actualización de éste para el ordenador |
---|
[536adc4] | 1189 | if(!CuestionPerfilHardware(db, tbl,idcentro,ido,tbidhardware,i,nombreordenador)){ |
---|
[34fc87f] | 1190 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1191 | pthread_mutex_unlock(&guardia); |
---|
| 1192 | return(false); |
---|
| 1193 | } |
---|
| 1194 | pthread_mutex_unlock(&guardia); |
---|
| 1195 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1196 | return(true); |
---|
| 1197 | } |
---|
| 1198 | // ________________________________________________________________________________________________________ |
---|
[536adc4] | 1199 | // Funcin: CuestionPerfilHardware |
---|
[34fc87f] | 1200 | //________________________________________________________________________________________________________/ |
---|
[536adc4] | 1201 | int CuestionPerfilHardware(Database db, Table tbl,int idcentro,char* ido,int *tbidhardware,int i,char *nombreordenador){ |
---|
[34fc87f] | 1202 | char sqlstr[1000],ErrStr[200]; |
---|
| 1203 | int tbidhardwareperfil[MAXHARDWARE]; |
---|
| 1204 | int j=0; |
---|
| 1205 | int idperfilhard; |
---|
| 1206 | // Busca perfil hard del ordenador |
---|
| 1207 | sprintf(sqlstr,"SELECT perfileshard_hardwares.idhardware FROM ordenadores INNER JOIN perfileshard ON ordenadores.idperfilhard = perfileshard.idperfilhard INNER JOIN perfileshard_hardwares ON perfileshard_hardwares.idperfilhard = perfileshard.idperfilhard WHERE ordenadores.idordenador =%s",ido); |
---|
| 1208 | // EJecuta consulta |
---|
| 1209 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1210 | db.GetErrorErrStr(ErrStr); |
---|
| 1211 | return(false); |
---|
| 1212 | } |
---|
| 1213 | while(!tbl.ISEOF()){ // Recorre acciones del menu |
---|
[a6b881e] | 1214 | if(!tbl.Get("idhardware",tbidhardwareperfil[j++])){ // Toma dato |
---|
[34fc87f] | 1215 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1216 | return(false); |
---|
| 1217 | } |
---|
| 1218 | tbl.MoveNext(); |
---|
| 1219 | } |
---|
| 1220 | // Comprueba si el perfil del ordenador contiene todo el hardware enviado |
---|
| 1221 | int k,q,sw=false; |
---|
| 1222 | for(k=0;k<i;k++){ // Elemento hardware |
---|
| 1223 | for(q=0;q<j;q++){ |
---|
| 1224 | if(tbidhardware[k]==tbidhardwareperfil[q]){ |
---|
| 1225 | sw=true; |
---|
| 1226 | break; |
---|
| 1227 | } |
---|
| 1228 | } |
---|
| 1229 | if(!sw) break; |
---|
| 1230 | } |
---|
| 1231 | // La variable sw contiene false si se ha encontrado algún hardware que no está en el perfil hardware del ordenador |
---|
| 1232 | if(sw) return(true); // Todo el hardware está en el perfil actual |
---|
| 1233 | |
---|
| 1234 | // Crea perfil nuevo con todo el hardware inventariado |
---|
[b1f0d31] | 1235 | sprintf(sqlstr,"INSERT perfileshard (descripcion,idcentro,grupoid) VALUES('Perfil Hardware (%s)',%d,0)",nombreordenador,idcentro); |
---|
[34fc87f] | 1236 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1237 | db.GetErrorErrStr(ErrStr); |
---|
| 1238 | return(false); |
---|
| 1239 | } |
---|
| 1240 | // Recupera el identificador del hardware |
---|
| 1241 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1242 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1243 | db.GetErrorErrStr(ErrStr); |
---|
| 1244 | return(false); |
---|
| 1245 | } |
---|
| 1246 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1247 | if(!tbl.Get("identificador",idperfilhard)){ |
---|
| 1248 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1249 | return(false); |
---|
| 1250 | } |
---|
| 1251 | } |
---|
| 1252 | for(k=0;k<i;k++){ // relaciona elementos hardwares con el nuevo perfil hardware |
---|
| 1253 | sprintf(sqlstr,"INSERT perfileshard_hardwares (idperfilhard,idhardware) VALUES(%d,%d)",idperfilhard,tbidhardware[k]); |
---|
| 1254 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1255 | db.GetErrorErrStr(ErrStr); |
---|
| 1256 | return(false); |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | sprintf(sqlstr,"UPDATE ordenadores SET idperfilhard=%d WHERE idordenador=%s",idperfilhard,ido); |
---|
| 1260 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1261 | db.GetErrorErrStr(ErrStr); |
---|
| 1262 | return(false); |
---|
| 1263 | } |
---|
| 1264 | return(true); |
---|
| 1265 | } |
---|
| 1266 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1267 | // Funcin: actualiza_configuracion |
---|
[34fc87f] | 1268 | // |
---|
| 1269 | // Descripcin: |
---|
[277d0cd] | 1270 | // Esta funcin actualiza la base de datos con la configuracion de sistemas operativos y particiones de un ordenador |
---|
[34fc87f] | 1271 | // Parnetros: |
---|
| 1272 | // - db: Objeto base de datos (ya operativo) |
---|
| 1273 | // - tbl: Objeto tabla |
---|
| 1274 | // - cfg: cadena con una configuracin |
---|
| 1275 | // - idcfgo: Identificador de la configuracin actual del ordenador |
---|
| 1276 | // - ipho: Identificador de la configuracin actual de las particiones del ordenador |
---|
| 1277 | // - ipho: Ipe del ordenador |
---|
| 1278 | // ________________________________________________________________________________________________________ |
---|
[b1f0d31] | 1279 | int actualiza_software(Database db, Table tbl,char* sft,char* par,char* tfs,char* ip,char*ido) |
---|
[5eae07e] | 1280 | { |
---|
[b1f0d31] | 1281 | int i,lon=0,idcentro,auxint,idtiposo; |
---|
[5eae07e] | 1282 | char *tbSoftware[MAXSOFTWARE]; |
---|
[b1f0d31] | 1283 | int tbidsoftware[MAXSOFTWARE]; |
---|
| 1284 | char ch[2],descripso[50]; // Caracter delimitador y nombre del estandar sistema operativo |
---|
[536adc4] | 1285 | char sqlstr[1000],ErrStr[200],nombreordenador[250]; |
---|
[5eae07e] | 1286 | |
---|
| 1287 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1288 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 1289 | pthread_mutex_lock(&guardia); |
---|
| 1290 | |
---|
| 1291 | // Toma Centro |
---|
| 1292 | sprintf(sqlstr,"SELECT aulas.idcentro,ordenadores.nombreordenador FROM aulas INNER JOIN ordenadores ON aulas.idaula=ordenadores.idaula WHERE ordenadores.idordenador=%s",ido); |
---|
| 1293 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1294 | db.GetErrorErrStr(ErrStr); |
---|
| 1295 | pthread_mutex_unlock(&guardia); |
---|
| 1296 | return(false); |
---|
| 1297 | } |
---|
[b1f0d31] | 1298 | if(!tbl.Get("idcentro",auxint)){ // Toma dato |
---|
[5eae07e] | 1299 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1300 | pthread_mutex_unlock(&guardia); |
---|
| 1301 | return(false); |
---|
| 1302 | } |
---|
[b1f0d31] | 1303 | idcentro=auxint+0; // Bug Mysql |
---|
[5eae07e] | 1304 | |
---|
| 1305 | if(!tbl.Get("nombreordenador",nombreordenador)){ // Toma dato |
---|
| 1306 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1307 | pthread_mutex_unlock(&guardia); |
---|
| 1308 | return(false); |
---|
| 1309 | } |
---|
| 1310 | |
---|
| 1311 | if(lon>MAXSOFTWARE) lon=MAXSOFTWARE; |
---|
| 1312 | // Trocea la cadena de configuracin |
---|
| 1313 | strcpy(ch,"\n");// caracter delimitador |
---|
[00ad799] | 1314 | |
---|
| 1315 | |
---|
| 1316 | // Lee archivo de inventario software |
---|
| 1317 | FILE *Finv; |
---|
| 1318 | char *buffer; |
---|
| 1319 | long lSize; |
---|
| 1320 | Finv = fopen ( sft , "rb" ); // EL parametro sft contiene el path del archivo de inventario |
---|
| 1321 | if (Finv==NULL) return(false); |
---|
| 1322 | fseek (Finv , 0 , SEEK_END); // Obtiene tamaño del fichero. |
---|
| 1323 | lSize = ftell (Finv); |
---|
| 1324 | rewind (Finv); |
---|
| 1325 | buffer = (char*) malloc (lSize); // Toma memoria para el buffer de lectura. |
---|
| 1326 | if (buffer == NULL) return(false); |
---|
| 1327 | fread (buffer,1,lSize,Finv); // Lee contenido del fichero |
---|
| 1328 | fclose(Finv); |
---|
| 1329 | // trocea las lineas |
---|
| 1330 | lon=split_parametros(tbSoftware,buffer,ch); |
---|
| 1331 | |
---|
[b1f0d31] | 1332 | // Incorpora el sistema Operativo de la partición |
---|
| 1333 | sprintf(sqlstr,"SELECT idtiposo,descripcion FROM tiposos WHERE tipopar ='%s'",tfs); |
---|
| 1334 | // Ejecuta consulta |
---|
| 1335 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1336 | db.GetErrorErrStr(ErrStr); |
---|
| 1337 | pthread_mutex_unlock(&guardia); |
---|
| 1338 | return(false); |
---|
| 1339 | } |
---|
| 1340 | if(tbl.ISEOF()){ // Software NO existente |
---|
| 1341 | pthread_mutex_unlock(&guardia); |
---|
| 1342 | return(false); |
---|
| 1343 | } |
---|
| 1344 | else{ |
---|
| 1345 | if(!tbl.Get("idtiposo",auxint)){ |
---|
| 1346 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1347 | pthread_mutex_unlock(&guardia); |
---|
| 1348 | return(false); |
---|
| 1349 | } |
---|
| 1350 | idtiposo=auxint+0; // Bug Mysql |
---|
| 1351 | if(!tbl.Get("descripcion",descripso)){ |
---|
| 1352 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1353 | pthread_mutex_unlock(&guardia); |
---|
| 1354 | return(false); |
---|
| 1355 | } |
---|
| 1356 | tbSoftware[lon++]=descripso; |
---|
| 1357 | } |
---|
[5eae07e] | 1358 | // Trocea las cadenas de parametros de particin |
---|
| 1359 | for (i=0;i<lon;i++){ |
---|
[536adc4] | 1360 | sprintf(sqlstr,"SELECT idsoftware FROM softwares WHERE descripcion ='%s'",tbSoftware[i]); |
---|
[5eae07e] | 1361 | |
---|
| 1362 | // EJecuta consulta |
---|
| 1363 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1364 | db.GetErrorErrStr(ErrStr); |
---|
| 1365 | pthread_mutex_unlock(&guardia); |
---|
| 1366 | return(false); |
---|
| 1367 | } |
---|
| 1368 | if(tbl.ISEOF()){ // Software NO existente |
---|
[b1f0d31] | 1369 | if((lon-i)>1) // No es el último elemento que es el S.O. el idtiposoftware es 2 (Aplicaciones) |
---|
| 1370 | sprintf(sqlstr,"INSERT softwares (idtiposoftware,descripcion,idcentro,grupoid) VALUES(2,'%s',%d,0)",tbSoftware[i],idcentro); |
---|
| 1371 | else // Es el último elemento que es el S.O. el idtiposoftware es 1 (Sistemas operativos) |
---|
| 1372 | sprintf(sqlstr,"INSERT softwares (idtiposoftware,idtiposo,descripcion,idcentro,grupoid) VALUES(1,%d,'%s',%d,0)",idtiposo,tbSoftware[i],idcentro); |
---|
| 1373 | |
---|
[5eae07e] | 1374 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1375 | db.GetErrorErrStr(ErrStr); |
---|
| 1376 | pthread_mutex_unlock(&guardia); |
---|
| 1377 | return(false); |
---|
| 1378 | } |
---|
| 1379 | // Recupera el identificador del software |
---|
| 1380 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1381 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1382 | db.GetErrorErrStr(ErrStr); |
---|
| 1383 | pthread_mutex_unlock(&guardia); |
---|
| 1384 | return(false); |
---|
| 1385 | } |
---|
| 1386 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1387 | if(!tbl.Get("identificador",tbidsoftware[i])){ |
---|
| 1388 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1389 | pthread_mutex_unlock(&guardia); |
---|
| 1390 | return(false); |
---|
| 1391 | } |
---|
| 1392 | } |
---|
| 1393 | } |
---|
| 1394 | else{ |
---|
| 1395 | if(!tbl.Get("idsoftware",tbidsoftware[i])){ // Toma dato |
---|
| 1396 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1397 | pthread_mutex_unlock(&guardia); |
---|
| 1398 | return(false); |
---|
| 1399 | } |
---|
| 1400 | } // Fin for |
---|
| 1401 | } |
---|
| 1402 | // Comprueba existencia de perfil software y actualización de éste para el ordenador |
---|
[ec01697] | 1403 | if(!CuestionPerfilSoftware(db, tbl,idcentro,ido,tbidsoftware,i,nombreordenador,par)){ |
---|
[5eae07e] | 1404 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1405 | pthread_mutex_unlock(&guardia); |
---|
| 1406 | return(false); |
---|
| 1407 | } |
---|
| 1408 | pthread_mutex_unlock(&guardia); |
---|
| 1409 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1410 | return(true); |
---|
| 1411 | } |
---|
| 1412 | // ________________________________________________________________________________________________________ |
---|
[536adc4] | 1413 | // Funcin: CuestionPerfilSoftware |
---|
[5eae07e] | 1414 | //________________________________________________________________________________________________________/ |
---|
[ec01697] | 1415 | int CuestionPerfilSoftware(Database db, Table tbl,int idcentro,char* ido,int *tbidsoftware,int i,char *nombreordenador,char *particion){ |
---|
[5eae07e] | 1416 | char sqlstr[1000],ErrStr[200]; |
---|
| 1417 | int tbidsoftwareperfil[MAXSOFTWARE]; |
---|
| 1418 | int j=0; |
---|
| 1419 | int idperfilsoft; |
---|
| 1420 | // Busca perfil soft del ordenador |
---|
[ec01697] | 1421 | sprintf(sqlstr,"SELECT perfilessoft_softwares.idsoftware FROM ordenador_perfilsoft INNER JOIN perfilessoft ON ordenador_perfilsoft.idperfilsoft = perfilessoft.idperfilsoft INNER JOIN perfilessoft_softwares ON perfilessoft_softwares.idperfilsoft=perfilessoft.idperfilsoft WHERE ordenador_perfilsoft.idordenador =%s",ido); |
---|
[5eae07e] | 1422 | // EJecuta consulta |
---|
| 1423 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1424 | db.GetErrorErrStr(ErrStr); |
---|
| 1425 | return(false); |
---|
| 1426 | } |
---|
[ec01697] | 1427 | while(!tbl.ISEOF()){ // Recorre software del perfils |
---|
[5eae07e] | 1428 | if(!tbl.Get("idsoftware",tbidsoftwareperfil[j++])){ // Toma dato |
---|
| 1429 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1430 | return(false); |
---|
| 1431 | } |
---|
| 1432 | tbl.MoveNext(); |
---|
| 1433 | } |
---|
| 1434 | // Comprueba si el perfil del ordenador contiene todo el software enviado |
---|
| 1435 | int k,q,sw=false; |
---|
[ec01697] | 1436 | if(i==j){ // Si son el mismo número de componenetes software ... |
---|
| 1437 | for(k=0;k<i;k++){ // Elemento software |
---|
| 1438 | for(q=0;q<j;q++){ |
---|
| 1439 | if(tbidsoftware[k]==tbidsoftwareperfil[q]){ |
---|
| 1440 | sw=true; |
---|
| 1441 | break; |
---|
| 1442 | } |
---|
[5eae07e] | 1443 | } |
---|
[ec01697] | 1444 | if(!sw) break; |
---|
[5eae07e] | 1445 | } |
---|
| 1446 | } |
---|
[ec01697] | 1447 | |
---|
[5eae07e] | 1448 | // La variable sw contiene false si se ha encontrado algún software que no está en el perfil software del ordenador |
---|
| 1449 | if(sw) return(true); // Todo el software está en el perfil actual |
---|
| 1450 | |
---|
| 1451 | // Crea perfil nuevo con todo el software inventariado |
---|
[b1f0d31] | 1452 | sprintf(sqlstr,"INSERT perfilessoft (descripcion,idcentro,grupoid) VALUES('Perfil Software (%s, Part:%s) ',%d,0)",nombreordenador,particion,idcentro); |
---|
[5eae07e] | 1453 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1454 | db.GetErrorErrStr(ErrStr); |
---|
| 1455 | return(false); |
---|
| 1456 | } |
---|
| 1457 | // Recupera el identificador del software |
---|
| 1458 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1459 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1460 | db.GetErrorErrStr(ErrStr); |
---|
| 1461 | return(false); |
---|
| 1462 | } |
---|
| 1463 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1464 | if(!tbl.Get("identificador",idperfilsoft)){ |
---|
| 1465 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1466 | return(false); |
---|
| 1467 | } |
---|
| 1468 | } |
---|
| 1469 | for(k=0;k<i;k++){ // relaciona elementos softwares con el nuevo perfil software |
---|
| 1470 | sprintf(sqlstr,"INSERT perfilessoft_softwares (idperfilsoft,idsoftware) VALUES(%d,%d)",idperfilsoft,tbidsoftware[k]); |
---|
| 1471 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1472 | db.GetErrorErrStr(ErrStr); |
---|
| 1473 | return(false); |
---|
| 1474 | } |
---|
[ec01697] | 1475 | } |
---|
| 1476 | // Busca si existe un perfil software para ese ordenador y esa partición |
---|
| 1477 | sprintf(sqlstr,"SELECT idperfilsoft FROM ordenador_perfilsoft WHERE idordenador =%s AND particion=%s",ido,particion); |
---|
| 1478 | // Ejecuta consulta |
---|
| 1479 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
[5eae07e] | 1480 | db.GetErrorErrStr(ErrStr); |
---|
| 1481 | return(false); |
---|
[ec01697] | 1482 | } |
---|
| 1483 | if(!tbl.ISEOF()){ // existe un perfilsoft que se cambia al nuevo |
---|
| 1484 | sprintf(sqlstr,"UPDATE ordenador_perfilsoft SET idperfilsoft=%d WHERE idordenador=%s AND particion=%s",idperfilsoft,ido,particion); |
---|
| 1485 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1486 | db.GetErrorErrStr(ErrStr); |
---|
| 1487 | return(false); |
---|
| 1488 | } |
---|
| 1489 | } |
---|
| 1490 | else{ |
---|
| 1491 | sprintf(sqlstr,"INSERT INTO ordenador_perfilsoft (idordenador,particion,idperfilsoft) VALUE (%s,%s,%d)",ido,particion,idperfilsoft); |
---|
| 1492 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1493 | db.GetErrorErrStr(ErrStr); |
---|
| 1494 | return(false); |
---|
| 1495 | } |
---|
| 1496 | |
---|
| 1497 | } |
---|
[5eae07e] | 1498 | return(true); |
---|
| 1499 | } |
---|
| 1500 | // ________________________________________________________________________________________________________ |
---|
| 1501 | // Funcin: actualiza_configuracion |
---|
| 1502 | // |
---|
| 1503 | // Descripcin: |
---|
| 1504 | // Esta funcin actualiza la base de datos con la configuracion de sistemas operativos y particiones de un ordenador |
---|
| 1505 | // Parnetros: |
---|
| 1506 | // - db: Objeto base de datos (ya operativo) |
---|
| 1507 | // - tbl: Objeto tabla |
---|
| 1508 | // - cfg: cadena con una configuracin |
---|
| 1509 | // - idcfgo: Identificador de la configuracin actual del ordenador |
---|
| 1510 | // - ipho: Identificador de la configuracin actual de las particiones del ordenador |
---|
| 1511 | // - ipho: Ipe del ordenador |
---|
| 1512 | // ________________________________________________________________________________________________________ |
---|
[34fc87f] | 1513 | int actualiza_configuracion(Database db, Table tbl,char* cfg,int idcfgo,int idprto,char* ipho) |
---|
| 1514 | { |
---|
| 1515 | char sqlstr[1000],ErrStr[200]; |
---|
| 1516 | int idconfiguracion,idparticion,lon; |
---|
| 1517 | char * part; |
---|
| 1518 | |
---|
| 1519 | |
---|
| 1520 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1521 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 1522 | pthread_mutex_lock(&guardia); |
---|
| 1523 | sprintf(sqlstr,"SELECT idconfiguracion FROM configuraciones WHERE configuracion LIKE '%s'",cfg); |
---|
| 1524 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1525 | db.GetErrorErrStr(ErrStr); |
---|
| 1526 | pthread_mutex_unlock(&guardia); |
---|
| 1527 | return(false); |
---|
| 1528 | } |
---|
| 1529 | if(!tbl.ISEOF()){ // Configuracin ya existente |
---|
| 1530 | if(!tbl.Get("idconfiguracion",idconfiguracion)){ // Toma dato |
---|
| 1531 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1532 | pthread_mutex_unlock(&guardia); |
---|
| 1533 | return(false); |
---|
| 1534 | } |
---|
| 1535 | } |
---|
| 1536 | else{ // Nueva configuracin |
---|
| 1537 | sprintf(sqlstr,"INSERT configuraciones (configuracion) VALUES('%s')",cfg); |
---|
| 1538 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1539 | db.GetErrorErrStr(ErrStr); |
---|
| 1540 | pthread_mutex_unlock(&guardia); |
---|
| 1541 | return(false); |
---|
| 1542 | } |
---|
| 1543 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1544 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1545 | db.GetErrorErrStr(ErrStr); |
---|
| 1546 | pthread_mutex_unlock(&guardia); |
---|
| 1547 | return(false); |
---|
| 1548 | } |
---|
| 1549 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1550 | if(!tbl.Get("identificador",idconfiguracion)){ |
---|
| 1551 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1552 | pthread_mutex_unlock(&guardia); |
---|
| 1553 | return(false); |
---|
| 1554 | } |
---|
| 1555 | } |
---|
| 1556 | } |
---|
| 1557 | // Genera cadena de particiones |
---|
| 1558 | lon=strlen(cfg); |
---|
| 1559 | part=(char*)malloc(lon); |
---|
| 1560 | TomaParticiones(cfg,part,lon); |
---|
| 1561 | sprintf(sqlstr,"SELECT idparticion FROM particiones WHERE particion LIKE '%s'",part); |
---|
| 1562 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1563 | db.GetErrorErrStr(ErrStr); |
---|
| 1564 | pthread_mutex_unlock(&guardia); |
---|
| 1565 | return(false); |
---|
| 1566 | } |
---|
| 1567 | if(!tbl.ISEOF()){ // Configuracin ya existente |
---|
| 1568 | if(!tbl.Get("idparticion",idparticion)){ // Toma dato |
---|
| 1569 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1570 | pthread_mutex_unlock(&guardia); |
---|
| 1571 | return(false); |
---|
| 1572 | } |
---|
| 1573 | } |
---|
| 1574 | else{ // Nueva particion |
---|
| 1575 | sprintf(sqlstr,"INSERT particiones (particion) VALUES('%s')",part); |
---|
| 1576 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1577 | db.GetErrorErrStr(ErrStr); |
---|
| 1578 | pthread_mutex_unlock(&guardia); |
---|
| 1579 | return(false); |
---|
| 1580 | } |
---|
| 1581 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1582 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1583 | db.GetErrorErrStr(ErrStr); |
---|
| 1584 | pthread_mutex_unlock(&guardia); |
---|
| 1585 | return(false); |
---|
| 1586 | } |
---|
| 1587 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1588 | if(!tbl.Get("identificador",idparticion)){ |
---|
| 1589 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1590 | pthread_mutex_unlock(&guardia); |
---|
| 1591 | return(false); |
---|
| 1592 | } |
---|
| 1593 | } |
---|
| 1594 | } |
---|
| 1595 | if(idconfiguracion!=idcfgo || idparticion!=idprto){ // Si el odenador tiene una configuracin distinta ... |
---|
| 1596 | sprintf(sqlstr,"Update ordenadores set idconfiguracion=%d, idparticion=%d WHERE ip='%s'",idconfiguracion,idparticion,ipho); |
---|
| 1597 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 1598 | db.GetErrorErrStr(ErrStr); |
---|
| 1599 | pthread_mutex_unlock(&guardia); |
---|
| 1600 | return(false); |
---|
| 1601 | } |
---|
| 1602 | } |
---|
| 1603 | pthread_mutex_unlock(&guardia); |
---|
| 1604 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1605 | return(true); |
---|
| 1606 | } |
---|
| 1607 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1608 | // Funcin: TomaParticiones |
---|
[34fc87f] | 1609 | // |
---|
| 1610 | // Descripcin: |
---|
[277d0cd] | 1611 | // Esta funcin compone basndose en la cadena de configuracin que devuelve el ordenador, una cadena de particiones con |
---|
[34fc87f] | 1612 | // los valores "n0=PPPP;n1=PPPP..." con las duplas:el nmero de particin y el tipo, separados por coma |
---|
| 1613 | // Parnetros: |
---|
| 1614 | // - cfg: Cadena de configuracin |
---|
| 1615 | // - parts: Cadena devuelta con el formato anterior descrito |
---|
| 1616 | // - lonprt: Longitud mnmima para las cadenas |
---|
| 1617 | // ________________________________________________________________________________________________________ |
---|
| 1618 | void TomaParticiones(char* cfg, char* parts,int lonprt) |
---|
| 1619 | { |
---|
| 1620 | int i; |
---|
| 1621 | int lon=0; |
---|
| 1622 | char *tbParticiones[10]; // Para albergar hasta 10 particiones ( Normalmente Mnimo 8); |
---|
| 1623 | char *tbParticion[8]; // Para albergar hasta 8 parnetros de particin; |
---|
| 1624 | char *tbIgualdad[2]; // Para albergar hasta 8 parnetros de particin; |
---|
| 1625 | char ch[2]; // Carnter delimitador |
---|
| 1626 | char *apun; |
---|
| 1627 | int p; |
---|
| 1628 | // Toma memoria para cada elemento de particin |
---|
| 1629 | for(i=0;i<10;i++) |
---|
| 1630 | tbParticiones[i]=(char*)malloc(lonprt); |
---|
| 1631 | |
---|
| 1632 | // Toma memoria para cada parametro de particin |
---|
| 1633 | for(i=0;i<8;i++) |
---|
| 1634 | tbParticion[i]=(char*)malloc(lonprt); |
---|
| 1635 | |
---|
| 1636 | // Toma memoria para cada igualdad |
---|
| 1637 | for(i=0;i<2;i++) |
---|
| 1638 | tbIgualdad[i]=(char*)malloc(20); |
---|
| 1639 | |
---|
| 1640 | // Trocea la cadena de configuracin |
---|
| 1641 | strcpy(ch,"\t");// caracter delimitador (tabulador) |
---|
| 1642 | lonprt=split_parametros(tbParticiones,cfg,ch); |
---|
| 1643 | // Trocea las cadenas de parametros de particin |
---|
| 1644 | for (p=0;p<lonprt;p++){ |
---|
| 1645 | strcpy(ch,"\n");// caracter delimitador (salto de linea) |
---|
| 1646 | split_parametros(tbParticion,tbParticiones[p],ch); |
---|
| 1647 | strcpy(ch,"=");// caracter delimitador "=" |
---|
| 1648 | split_parametros(tbIgualdad,tbParticion[4],ch); // Nmero de particin |
---|
| 1649 | lon+=sprintf(parts+lon,"%s=",tbIgualdad[1]); |
---|
| 1650 | split_parametros(tbIgualdad,tbParticion[2],ch); // Tipo de particion |
---|
| 1651 | apun=tbIgualdad[1]; |
---|
| 1652 | //if(apun[0]=='H') apun++; // Si es oculta ... |
---|
| 1653 | lon+=sprintf(parts+lon,"%s;",apun); |
---|
| 1654 | } |
---|
| 1655 | lon+=sprintf(parts+lon,"@prt"); |
---|
| 1656 | } |
---|
| 1657 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1658 | // Funcin: ComandosPendientes |
---|
[34fc87f] | 1659 | // |
---|
| 1660 | // Descripcin: |
---|
[277d0cd] | 1661 | // Esta funcin busca en la base de datos,comandos pendientes de ejecutar por un ordenador concreto |
---|
[34fc87f] | 1662 | // Parnetros: |
---|
| 1663 | // - s: Socket del cliente |
---|
| 1664 | // - parametros: Parnetros de la trama recibida |
---|
| 1665 | // ________________________________________________________________________________________________________ |
---|
| 1666 | int ComandosPendientes(SOCKET s,char *parametros) |
---|
| 1667 | { |
---|
| 1668 | char *iph,*ido,*coletilla; |
---|
| 1669 | int ids; |
---|
| 1670 | char pids[20],ipe[16],idord[16]; |
---|
| 1671 | |
---|
| 1672 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1673 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 1674 | strcpy(ipe,iph); |
---|
| 1675 | strcpy(idord,ido); |
---|
| 1676 | |
---|
| 1677 | if(busca_comandos(ipe,idord,parametros,&ids)){ |
---|
| 1678 | Coloca_estado(ipe,CLIENTE_OCUPADO,s); |
---|
| 1679 | //Manda el comando pendiente |
---|
| 1680 | coletilla=corte_iph(parametros); |
---|
| 1681 | coletilla[0]='\0';// Corta la trama en la ip |
---|
| 1682 | sprintf(pids,"ids=%d\r",ids); |
---|
| 1683 | strcat(parametros,pids); // Le ande el identificador de la accion |
---|
| 1684 | return(manda_comando(s,parametros)); |
---|
| 1685 | } |
---|
| 1686 | NoComandosPendientes(s); // Indica al cliente rembo que ya no hay mn comandos pendientes |
---|
| 1687 | return(true); |
---|
| 1688 | } |
---|
| 1689 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1690 | // Funcin: EjecutarItem |
---|
[34fc87f] | 1691 | // |
---|
| 1692 | // Descripcin: |
---|
[277d0cd] | 1693 | // Esta funcin ejecuta un item de un men concreto solicitado por algn cliente rembo |
---|
[34fc87f] | 1694 | // Parnetros: |
---|
| 1695 | // - s: Socket del cliente |
---|
| 1696 | // - parametros: Parnetros de la trama recibida |
---|
| 1697 | // ________________________________________________________________________________________________________ |
---|
| 1698 | int EjecutarItem(SOCKET s,char *parametros) |
---|
| 1699 | { |
---|
| 1700 | char sqlstr[1000],ErrStr[200]; |
---|
| 1701 | Database db; |
---|
| 1702 | Table tbl,tbln; |
---|
| 1703 | int idtipoaccion,lon,cont_comandos=0,i,puertorepo; |
---|
| 1704 | char tipoaccion,*iph,*idt,ipe[16]; |
---|
| 1705 | char *tbComandosparametros[100]; |
---|
| 1706 | |
---|
| 1707 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1708 | idt=toma_parametro("idt",parametros); // Toma idemtificador del item |
---|
| 1709 | strcpy(ipe,iph); |
---|
| 1710 | |
---|
| 1711 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 1712 | db.GetErrorErrStr(ErrStr); |
---|
| 1713 | return(false); |
---|
| 1714 | } |
---|
| 1715 | sprintf(sqlstr,"SELECT acciones_menus.tipoaccion, acciones_menus.idtipoaccion FROM acciones_menus WHERE acciones_menus.idaccionmenu=%s",idt); |
---|
| 1716 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1717 | db.GetErrorErrStr(ErrStr); |
---|
| 1718 | return(false); |
---|
| 1719 | } |
---|
| 1720 | if(tbl.ISEOF()){ |
---|
| 1721 | return(false); // No hay comandos pendientes |
---|
| 1722 | } |
---|
| 1723 | |
---|
| 1724 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma dato |
---|
| 1725 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1726 | return(false); |
---|
| 1727 | } |
---|
| 1728 | |
---|
| 1729 | if(!tbl.Get("idtipoaccion",idtipoaccion)){ // Toma dato |
---|
| 1730 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1731 | return(false); |
---|
| 1732 | } |
---|
| 1733 | |
---|
| 1734 | switch(tipoaccion){ |
---|
| 1735 | case EJECUCION_PROCEDIMIENTO : |
---|
| 1736 | sprintf(sqlstr,"SELECT procedimientos_comandos.parametros FROM procedimientos_comandos WHERE procedimientos_comandos.idprocedimiento=%d",idtipoaccion); |
---|
| 1737 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1738 | db.GetErrorErrStr(ErrStr); |
---|
| 1739 | return(false); |
---|
| 1740 | } |
---|
| 1741 | if(tbl.ISEOF()) // No existe procedimiento |
---|
| 1742 | return(false); |
---|
| 1743 | |
---|
| 1744 | while(!tbl.ISEOF()){ |
---|
| 1745 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 1746 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1747 | return(false); |
---|
| 1748 | } |
---|
| 1749 | lon=strlen(parametros); |
---|
| 1750 | tbComandosparametros[cont_comandos]=(char*)malloc(lon); |
---|
| 1751 | if(tbComandosparametros[cont_comandos]==NULL) |
---|
| 1752 | return(false); // No hay memoria bastante |
---|
| 1753 | strcpy(tbComandosparametros[cont_comandos++],parametros); |
---|
| 1754 | tbl.MoveNext(); |
---|
| 1755 | } |
---|
| 1756 | strcpy(parametros,tbComandosparametros[0]); |
---|
| 1757 | strcat(parametros,"iph="); |
---|
| 1758 | strcat(parametros,ipe); |
---|
| 1759 | strcat(parametros,"\r"); |
---|
| 1760 | for(i=1;i<cont_comandos;i++){ |
---|
| 1761 | strcat(parametros,"\n"); |
---|
| 1762 | strcat(parametros,tbComandosparametros[i]); |
---|
| 1763 | strcat(parametros,"iph="); |
---|
| 1764 | strcat(parametros,ipe); |
---|
| 1765 | strcat(parametros,"\r"); |
---|
| 1766 | } |
---|
| 1767 | if(TomaIPServidorRembo(ipe,&puertorepo)) |
---|
| 1768 | return(manda_trama_servidorrembo(ipe,parametros,puertorepo)); |
---|
| 1769 | break; |
---|
| 1770 | case EJECUCION_TAREA : |
---|
| 1771 | EjecutarTarea(idtipoaccion,0,0,0,db,parametros); |
---|
| 1772 | break; |
---|
| 1773 | case EJECUCION_TRABAJO : |
---|
| 1774 | EjecutarTrabajo(idtipoaccion,db,parametros); // Es una programacin de un trabajo |
---|
| 1775 | break; |
---|
| 1776 | } |
---|
| 1777 | db.Close(); |
---|
| 1778 | return(true); |
---|
| 1779 | } |
---|
| 1780 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1781 | // Funcin: DisponibilidadComandos |
---|
[34fc87f] | 1782 | // |
---|
| 1783 | // Descripcin: |
---|
[277d0cd] | 1784 | // Esta funcin habilita a un clinte rembo para recibir o no, comandos iteractivos |
---|
[34fc87f] | 1785 | // Parnetros: |
---|
| 1786 | // - s: Socket del cliente |
---|
| 1787 | // - parametros: Parmetros de la trama recibida |
---|
| 1788 | // ________________________________________________________________________________________________________ |
---|
| 1789 | int DisponibilidadComandos(SOCKET s,char *parametros) |
---|
| 1790 | { |
---|
| 1791 | char *iph,*swd; |
---|
| 1792 | int resul=0,i; |
---|
| 1793 | |
---|
| 1794 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1795 | swd=toma_parametro("swd",parametros); // Toma switch de diponibilidad |
---|
| 1796 | |
---|
| 1797 | if(strcmp(swd,"1")==0) // Cliente disponible |
---|
| 1798 | resul=Coloca_estado(iph,CLIENTE_REMBO,s); |
---|
| 1799 | else{ |
---|
| 1800 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 1801 | resul=borra_entrada(i); // Cliente apagado |
---|
| 1802 | } |
---|
| 1803 | return(resul); |
---|
| 1804 | } |
---|
| 1805 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1806 | // Funcin: Coloca_estado |
---|
[34fc87f] | 1807 | // |
---|
| 1808 | // Descripcin: |
---|
[277d0cd] | 1809 | // Esta funcin coloca el estado de un ordenador en la tabla de sockets |
---|
[34fc87f] | 1810 | // Parnetros: |
---|
| 1811 | // - iph: Ip del ordenador |
---|
| 1812 | // - e: Nuevo estado |
---|
| 1813 | // - s: Socket usado por el cliente para comunicarse con el servidor HIDRA |
---|
| 1814 | // ________________________________________________________________________________________________________ |
---|
[dad9f34] | 1815 | int Coloca_estado(char *iph,const char *e,SOCKET s) |
---|
[34fc87f] | 1816 | { |
---|
| 1817 | int i; |
---|
| 1818 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 1819 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 1820 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 1821 | strcpy(tbsockets[i].estado,e); // Cambia el estado |
---|
| 1822 | tbsockets[i].sock=s; // Guarda el socket |
---|
| 1823 | return(true); |
---|
| 1824 | } |
---|
| 1825 | } |
---|
| 1826 | } |
---|
| 1827 | return(false); |
---|
| 1828 | } |
---|
| 1829 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1830 | // Funcin: IgualIP |
---|
[34fc87f] | 1831 | // |
---|
| 1832 | // Descripcin: |
---|
| 1833 | // Comprueba si una cadena con una ipe estnincluidad en otra que contienen varias direcciones ipes separas por punto y coma |
---|
| 1834 | // Parnetros: |
---|
| 1835 | // - cadenaiph: Cadena de IPes |
---|
| 1836 | // - ipcliente: Cadena de la ip a buscar |
---|
| 1837 | // ________________________________________________________________________________________________________ |
---|
| 1838 | BOOLEAN IgualIP(char *cadenaiph,char *ipcliente) |
---|
| 1839 | { |
---|
| 1840 | char *posa,*posb; |
---|
| 1841 | int lon; |
---|
| 1842 | |
---|
| 1843 | posa=strstr(cadenaiph,ipcliente); |
---|
| 1844 | if(posa==NULL) return(FALSE); // No existe la IP en la cadena |
---|
| 1845 | posb=posa; // Iguala direcciones |
---|
| 1846 | while(TRUE){ |
---|
| 1847 | posb++; |
---|
| 1848 | if(*posb==';') break; |
---|
| 1849 | if(*posb=='\0') break; |
---|
| 1850 | if(*posb=='\r') break; |
---|
| 1851 | } |
---|
| 1852 | lon=strlen(ipcliente); |
---|
| 1853 | if((posb-posa)==lon) return(TRUE); // IP encontrada !!!! |
---|
| 1854 | |
---|
| 1855 | return(FALSE); |
---|
| 1856 | } |
---|
| 1857 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1858 | // Funcin: inclusion_srvRMB |
---|
[34fc87f] | 1859 | // |
---|
| 1860 | // Descripcin: |
---|
[277d0cd] | 1861 | // Esta funcin incorpora el socket de un nuevo servidor rembo a la tabla de sockets |
---|
[34fc87f] | 1862 | // Parnetros: |
---|
| 1863 | // - s: Socket del servidor rembo |
---|
| 1864 | // - parametros: Parnetros de la trama recibida |
---|
| 1865 | // ________________________________________________________________________________________________________ |
---|
| 1866 | int inclusion_srvRMB(char *iphsrvrmb,int puertorepo) |
---|
| 1867 | { |
---|
| 1868 | int i,idx; |
---|
| 1869 | |
---|
| 1870 | // Incluyendo al cliente en la tabla de sokets |
---|
| 1871 | if (servidorrembo_existente(iphsrvrmb,&i)){ // Si ya existe la IP ... |
---|
| 1872 | idx=i; |
---|
| 1873 | } |
---|
| 1874 | else{ |
---|
| 1875 | if (hay_huecoservidorrembo(&i)){ // Busca hueco para el nuevo cliente |
---|
| 1876 | idx=i; |
---|
| 1877 | strcpy(tbsocketsSRVRMB[idx].ip,iphsrvrmb);// Copia IP |
---|
| 1878 | tbsocketsSRVRMB[idx].puertorepo=puertorepo; |
---|
| 1879 | } |
---|
| 1880 | else |
---|
| 1881 | return(false); // No hay huecos |
---|
| 1882 | } |
---|
| 1883 | return(true); |
---|
| 1884 | } |
---|
| 1885 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1886 | // Funcin: inclusion_cliWINLNX |
---|
[34fc87f] | 1887 | // |
---|
| 1888 | // Descripcin: |
---|
[277d0cd] | 1889 | // Esta funcin incorpora el socket de un nuevo cliente rembo a la tabla de sockets |
---|
[34fc87f] | 1890 | // Parnetros: |
---|
| 1891 | // - s: Socket del servidor rembo |
---|
| 1892 | // - parametros: Parnetros de la trama recibida |
---|
| 1893 | // ________________________________________________________________________________________________________ |
---|
| 1894 | int inclusion_cliWINLNX(SOCKET s,char *parametros) |
---|
| 1895 | { |
---|
| 1896 | char *iph,*tso; |
---|
| 1897 | int i,idx; |
---|
| 1898 | |
---|
| 1899 | // Toma parnetros |
---|
| 1900 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1901 | tso=toma_parametro("tso",parametros); // Toma ip |
---|
| 1902 | // Incluyendo al cliente en la tabla de sokets |
---|
| 1903 | if (cliente_existente(iph,&i)){ // Si ya existe la IP ... |
---|
| 1904 | idx=i; |
---|
| 1905 | close(tbsockets[idx].sock); |
---|
| 1906 | } |
---|
| 1907 | else{ |
---|
| 1908 | if (hay_hueco(&i)){ // Busca hueco para el nuevo cliente |
---|
| 1909 | idx=i; |
---|
| 1910 | strcpy(tbsockets[idx].ip,iph);// Copia IP |
---|
| 1911 | } |
---|
| 1912 | else |
---|
| 1913 | return(false); // No hay huecos |
---|
| 1914 | } |
---|
| 1915 | tbsockets[idx].sock=s; // Guarda el socket |
---|
| 1916 | strcpy(tbsockets[idx].estado,tso); |
---|
| 1917 | return(true); |
---|
| 1918 | } |
---|
| 1919 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1920 | // Funcin: inclusion_REPO |
---|
[34fc87f] | 1921 | // |
---|
| 1922 | // Descripcin: |
---|
[277d0cd] | 1923 | // Esta funcin incorpora el socket de un nuevo repositorio hidra |
---|
[34fc87f] | 1924 | // ________________________________________________________________________________________________________ |
---|
| 1925 | int inclusion_REPO(SOCKET s,char *parametros) |
---|
| 1926 | { |
---|
| 1927 | char ErrStr[200],sqlstr[1000]; |
---|
| 1928 | Database db; |
---|
| 1929 | Table tbl; |
---|
| 1930 | |
---|
| 1931 | char *iph; |
---|
[df5bd24] | 1932 | char PathHidra[250],PathPXE[250]; // path al directorio base de Hidra |
---|
[34fc87f] | 1933 | int puertorepo,lon; |
---|
| 1934 | |
---|
[73ed2a1] | 1935 | |
---|
[34fc87f] | 1936 | // Toma parnetros |
---|
| 1937 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1938 | |
---|
| 1939 | // Toma las propiedades del ordenador |
---|
| 1940 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 1941 | db.GetErrorErrStr(ErrStr); |
---|
| 1942 | return(false); |
---|
| 1943 | } |
---|
| 1944 | // Recupera los datos del ordenador |
---|
[df5bd24] | 1945 | sprintf(sqlstr,"SELECT puertorepo,pathrembod,pathpxe FROM servidoresrembo WHERE ip = '%s'",iph); |
---|
[73ed2a1] | 1946 | |
---|
[34fc87f] | 1947 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 1948 | db.GetErrorErrStr(ErrStr); |
---|
| 1949 | return(false); |
---|
| 1950 | } |
---|
[73ed2a1] | 1951 | if(tbl.ISEOF()){ // Si No existe registro |
---|
| 1952 | RegistraLog("No existe el Repositorio, se rechaza la petición",false); |
---|
[34fc87f] | 1953 | return(false); |
---|
[73ed2a1] | 1954 | } |
---|
[34fc87f] | 1955 | if(!tbl.Get("puertorepo",puertorepo)){ // Toma dato |
---|
| 1956 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1957 | return(false); |
---|
| 1958 | } |
---|
| 1959 | if(!tbl.Get("pathrembod",PathHidra)){ // Toma dato |
---|
| 1960 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1961 | return(false); |
---|
| 1962 | } |
---|
[df5bd24] | 1963 | if(!tbl.Get("pathpxe",PathPXE)){ // Toma dato |
---|
| 1964 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1965 | return(false); |
---|
| 1966 | } |
---|
[34fc87f] | 1967 | inclusion_srvRMB(iph,puertorepo); // Actualiza tabla de servidores rembo |
---|
| 1968 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 1969 | if(!trama) |
---|
| 1970 | return(false); |
---|
| 1971 | // Envia la trama |
---|
[73ed2a1] | 1972 | |
---|
[34fc87f] | 1973 | trama->arroba='@'; |
---|
| 1974 | strncpy(trama->identificador,"JMMLCAMDJ",9); |
---|
| 1975 | trama->ejecutor='1'; |
---|
| 1976 | lon=sprintf(trama->parametros,"nfn=RESPUESTA_inclusionREPO\r"); |
---|
| 1977 | lon+=sprintf(trama->parametros+lon,"prp=%d\r",puertorepo); |
---|
| 1978 | lon+=sprintf(trama->parametros+lon,"pth=%s\r",PathHidra); |
---|
[df5bd24] | 1979 | lon+=sprintf(trama->parametros+lon,"ptx=%s\r",PathPXE); |
---|
[34fc87f] | 1980 | lon+=sprintf(trama->parametros+lon,"usu=%s\r",usuario); |
---|
| 1981 | lon+=sprintf(trama->parametros+lon,"pwd=%s\r",pasguor); |
---|
| 1982 | lon+=sprintf(trama->parametros+lon,"dat=%s\r",datasource); |
---|
[73ed2a1] | 1983 | lon+=sprintf(trama->parametros+lon,"cat=%s\r",catalog); |
---|
[34fc87f] | 1984 | return(manda_trama(s,trama)); |
---|
| 1985 | } |
---|
| 1986 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1987 | // Funcin: Sondeo |
---|
[34fc87f] | 1988 | // |
---|
| 1989 | // Descripcin: |
---|
[277d0cd] | 1990 | // Esta funcin recupera el estado de los ordenadores solicitados |
---|
[34fc87f] | 1991 | // Parnetros: |
---|
| 1992 | // - s: Socket del servidor web que envn el comando |
---|
| 1993 | // - parametros: Parnetros de la trama enviada por nte |
---|
| 1994 | // ________________________________________________________________________________________________________ |
---|
| 1995 | int Sondeo(SOCKET s,char *parametros) |
---|
| 1996 | { |
---|
| 1997 | char *iph; |
---|
| 1998 | char nwparametros[LONGITUD_PARAMETROS]; |
---|
| 1999 | int j; |
---|
| 2000 | |
---|
| 2001 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2002 | nwparametros[0]='\0'; |
---|
| 2003 | strcat(nwparametros,"tso="); // Compone retorno tso ( sistemas operativos de los clientes ) |
---|
| 2004 | for (j=0;j<MAXIMOS_SOCKETS;j++){ |
---|
| 2005 | if (strncmp(tbsockets[j].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2006 | if (IgualIP(iph,tbsockets[j].ip)){ // Si existe la IP en la cadena |
---|
| 2007 | strcat( nwparametros, tbsockets[j].ip); // Compone retorno |
---|
| 2008 | strcat( nwparametros,"/"); // "ip=sistemaoperatico;" |
---|
| 2009 | strcat( nwparametros, tbsockets[j].estado); |
---|
| 2010 | strcat( nwparametros,";"); |
---|
| 2011 | } |
---|
| 2012 | } |
---|
| 2013 | } |
---|
| 2014 | return(manda_comando(s,nwparametros)); |
---|
| 2015 | } |
---|
| 2016 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2017 | // Funcin: Actualizar |
---|
[34fc87f] | 2018 | // |
---|
| 2019 | // Descripcin: |
---|
[277d0cd] | 2020 | // Esta funcin actualiza la vista de ordenadores |
---|
[34fc87f] | 2021 | // Parnetros: |
---|
| 2022 | // - parametros: parametros del comando |
---|
| 2023 | // ________________________________________________________________________________________________________ |
---|
| 2024 | int Actualizar(char *parametros) |
---|
| 2025 | { |
---|
| 2026 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 2027 | if(!trama)return(false); |
---|
| 2028 | int i,estado_cliente,lon; |
---|
| 2029 | char *iph,*rmb; |
---|
| 2030 | |
---|
| 2031 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2032 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2033 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2034 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2035 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2036 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 2037 | if(estado_cliente!=0){ // Cliente NO OCUPADO ... |
---|
| 2038 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_INICIANDO); |
---|
| 2039 | if(estado_cliente!=0){ // Cliente NO INICIANDO ... |
---|
| 2040 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_REMBO); |
---|
| 2041 | if(estado_cliente!=0){ // Cliente windows o linux ... |
---|
| 2042 | lon=sprintf(trama->parametros,"nfn=Actualizar\r"); |
---|
| 2043 | manda_comando(tbsockets[i].sock,(char*)trama->parametros); |
---|
| 2044 | } |
---|
| 2045 | borra_entrada(i); |
---|
| 2046 | } |
---|
| 2047 | } |
---|
| 2048 | } |
---|
| 2049 | } |
---|
| 2050 | } |
---|
| 2051 | int j; |
---|
| 2052 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 2053 | if (strcmp(rmb,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 2054 | FINCADaINTRO(parametros,iph); |
---|
| 2055 | return(manda_trama_servidorrembo(rmb,parametros,tbsocketsSRVRMB[j].puertorepo)); |
---|
| 2056 | } |
---|
| 2057 | } |
---|
| 2058 | return(false); |
---|
| 2059 | } |
---|
| 2060 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2061 | // Funcin: FicheroOperador |
---|
[34fc87f] | 2062 | // |
---|
| 2063 | // Descripcin: |
---|
[277d0cd] | 2064 | // Esta funcin envia al servidor datos de un operador para crear fichero de login |
---|
[34fc87f] | 2065 | // Parnetros: |
---|
| 2066 | // - parametros: parametros del comando |
---|
| 2067 | // ________________________________________________________________________________________________________ |
---|
| 2068 | int FicheroOperador(char *parametros) |
---|
| 2069 | { |
---|
| 2070 | TRAMA trama; |
---|
| 2071 | SOCKET s; |
---|
| 2072 | char *rmb,*amb,*usu,*psw,*ida; |
---|
| 2073 | int resul,lon; |
---|
| 2074 | |
---|
| 2075 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2076 | |
---|
| 2077 | // Abre conexion con el servidor rembo y envia trama |
---|
| 2078 | s=AbreConexion(rmb,puerto+1); |
---|
| 2079 | if(!s){ |
---|
| 2080 | RegistraLog("Fallo al conectar con el servidor rembo para envio de tramas",true); |
---|
| 2081 | return(FALSE); |
---|
| 2082 | } |
---|
| 2083 | |
---|
| 2084 | amb=toma_parametro("amb",parametros); // Toma tipo de operacion |
---|
| 2085 | usu=toma_parametro("usu",parametros); // Toma usuario |
---|
| 2086 | psw=toma_parametro("psw",parametros); // Toma passwrod |
---|
| 2087 | ida=toma_parametro("ida",parametros); // Toma identificador del aula |
---|
| 2088 | |
---|
| 2089 | // Envia la trama |
---|
| 2090 | trama.arroba='@'; |
---|
| 2091 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 2092 | trama.ejecutor='1'; |
---|
| 2093 | lon=sprintf(trama.parametros,"nfn=FicheroOperador\r"); |
---|
| 2094 | lon+=sprintf(trama.parametros+lon,"amb=%s\r",amb); |
---|
| 2095 | lon+=sprintf(trama.parametros+lon,"usu=%s\r",usu); |
---|
| 2096 | lon+=sprintf(trama.parametros+lon,"psw=%s\r",psw); |
---|
| 2097 | lon+=sprintf(trama.parametros+lon,"ida=%s\r",ida); |
---|
| 2098 | resul=(manda_trama(s,&trama)); |
---|
| 2099 | if(!resul) |
---|
| 2100 | RegistraLog("Fallo en el envio de trama al servidor rembo",true); |
---|
| 2101 | return(resul); |
---|
| 2102 | } |
---|
| 2103 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2104 | // Funcin: Conmutar |
---|
[34fc87f] | 2105 | // |
---|
| 2106 | // Descripcin: |
---|
[277d0cd] | 2107 | // Esta funcin conmuta un cliente rembo del modo NO administrado al modo admnistrado |
---|
[34fc87f] | 2108 | // Parnetros: |
---|
| 2109 | // - parametros: parametros del comando |
---|
| 2110 | // ________________________________________________________________________________________________________ |
---|
| 2111 | int Conmutar(char *parametros) |
---|
| 2112 | { |
---|
| 2113 | TRAMA trama; |
---|
| 2114 | SOCKET s; |
---|
| 2115 | int i,estado_cliente,lon,resul; |
---|
| 2116 | char *iph,*rmb; |
---|
| 2117 | |
---|
| 2118 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2119 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2120 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2121 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2122 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2123 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 2124 | if(estado_cliente!=0){ // Cliente NO OCUPADO ... |
---|
| 2125 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_INICIANDO); |
---|
| 2126 | if(estado_cliente!=0){ // Cliente NO INICIANDO ... |
---|
| 2127 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_REMBO); |
---|
| 2128 | if(estado_cliente!=0){ // Cliente windows o linux ... |
---|
| 2129 | lon=sprintf(trama.parametros,"nfn=Conmutar\r"); |
---|
| 2130 | manda_comando(tbsockets[i].sock,trama.parametros); |
---|
| 2131 | } |
---|
| 2132 | } |
---|
| 2133 | } |
---|
| 2134 | } |
---|
| 2135 | } |
---|
| 2136 | } |
---|
| 2137 | |
---|
| 2138 | // Abre conexion con el servidor rembo y envia trama |
---|
| 2139 | s=AbreConexion(rmb,puerto+1); |
---|
| 2140 | if(!s){ |
---|
| 2141 | RegistraLog("Fallo al conectar con el servidor rembo para envio de tramas",true); |
---|
| 2142 | resul=FALSE; |
---|
| 2143 | } |
---|
| 2144 | else{ |
---|
| 2145 | // Envia la trama |
---|
| 2146 | trama.arroba='@'; |
---|
| 2147 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 2148 | trama.ejecutor='2'; |
---|
| 2149 | lon=sprintf(trama.parametros,"nfn=Conmutar\r"); |
---|
| 2150 | lon+=sprintf(trama.parametros+lon,"iph=%s\r",iph); |
---|
| 2151 | resul=(manda_trama(s,&trama)); |
---|
| 2152 | if(!resul){ |
---|
| 2153 | RegistraLog("Fallo en el envio de trama al servidor rembo",true); |
---|
| 2154 | } |
---|
| 2155 | } |
---|
| 2156 | return(resul); |
---|
| 2157 | } |
---|
| 2158 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2159 | // Funcin: PurgarTablaSockets |
---|
[34fc87f] | 2160 | // |
---|
| 2161 | // Descripcin: |
---|
| 2162 | // Borra ordenadores de la tabla de sockets |
---|
| 2163 | // Parnetros: |
---|
| 2164 | // - parametros: parametros del comando |
---|
| 2165 | // ________________________________________________________________________________________________________ |
---|
| 2166 | void PurgarTablaSockets(char *parametros) |
---|
| 2167 | { |
---|
| 2168 | int i; |
---|
| 2169 | char *iph; |
---|
| 2170 | |
---|
| 2171 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2172 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2173 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2174 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2175 | borra_entrada(i); |
---|
| 2176 | } |
---|
| 2177 | } |
---|
| 2178 | } |
---|
| 2179 | } |
---|
| 2180 | // _____________________________________________________________________________________________________________ |
---|
| 2181 | // Función: Arrancar |
---|
| 2182 | // |
---|
| 2183 | // Descripción: |
---|
| 2184 | // Esta función arranca los ordenadores solicitados. PAra ello le envía el comando arrancar al servidor rembo que lo controla y |
---|
| 2185 | // es éste el que le envía la trama de wake-up |
---|
| 2186 | // Parámetros: |
---|
| 2187 | // - mac: Dirección mac del cliente rembo |
---|
| 2188 | // - iph: Dirección ip del cliente rembo |
---|
| 2189 | // - rmb: ip del servidor rembo |
---|
| 2190 | // _____________________________________________________________________________________________________________ |
---|
| 2191 | int Arrancar(char *parametros) |
---|
| 2192 | { |
---|
| 2193 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 2194 | if(!trama)return(false); |
---|
| 2195 | char *iph,*rmb,*mac; |
---|
| 2196 | int j; |
---|
| 2197 | |
---|
| 2198 | rmb=toma_parametro("rmb",parametros); |
---|
| 2199 | mac=toma_parametro("mac",parametros); |
---|
| 2200 | iph=toma_parametro("iph",parametros); |
---|
| 2201 | |
---|
| 2202 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 2203 | if (strcmp(rmb,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 2204 | FINCADaINTRO(parametros,iph); |
---|
| 2205 | return(manda_trama_servidorrembo(rmb,parametros,tbsocketsSRVRMB[j].puertorepo)); |
---|
| 2206 | } |
---|
| 2207 | } |
---|
| 2208 | return(false); |
---|
| 2209 | } |
---|
| 2210 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2211 | // Funcin: RESPUESTA_Arrancar |
---|
[34fc87f] | 2212 | // |
---|
| 2213 | // Descripcin: |
---|
| 2214 | // Responde al comando Apagar |
---|
| 2215 | // Parnetros: |
---|
| 2216 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2217 | // - parametros: parametros del comando |
---|
| 2218 | // ________________________________________________________________________________________________________ |
---|
| 2219 | int RESPUESTA_Arrancar(SOCKET s,char *parametros) |
---|
| 2220 | { |
---|
| 2221 | char ErrStr[200]; |
---|
| 2222 | Database db; |
---|
| 2223 | Table tbl; |
---|
| 2224 | |
---|
| 2225 | char *res,*der,*iph,*ido,*ids; |
---|
| 2226 | |
---|
| 2227 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2228 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2229 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2230 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2231 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2232 | |
---|
| 2233 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2234 | db.GetErrorErrStr(ErrStr); |
---|
| 2235 | return(false); |
---|
| 2236 | } |
---|
| 2237 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2238 | return(false); // Error al registrar notificacion |
---|
| 2239 | } |
---|
| 2240 | db.Close(); |
---|
| 2241 | return(true); |
---|
| 2242 | } |
---|
| 2243 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2244 | // Funcin: RESPUESTA_Apagar |
---|
[34fc87f] | 2245 | // |
---|
| 2246 | // Descripcin: |
---|
| 2247 | // Responde al comando Apagar |
---|
| 2248 | // Parnetros: |
---|
| 2249 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2250 | // - parametros: parametros del comando |
---|
| 2251 | // ________________________________________________________________________________________________________ |
---|
| 2252 | int RESPUESTA_Apagar(SOCKET s,char *parametros) |
---|
| 2253 | { |
---|
| 2254 | char ErrStr[200]; |
---|
| 2255 | Database db; |
---|
| 2256 | Table tbl; |
---|
| 2257 | int i; |
---|
| 2258 | char *res,*der,*iph,*ido,*ids; |
---|
| 2259 | |
---|
| 2260 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2261 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2262 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2263 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2264 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2265 | |
---|
| 2266 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2267 | db.GetErrorErrStr(ErrStr); |
---|
| 2268 | return(false); |
---|
| 2269 | } |
---|
| 2270 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2271 | return(false); // Error al registrar notificacion |
---|
| 2272 | } |
---|
| 2273 | |
---|
| 2274 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2275 | |
---|
| 2276 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2277 | borra_entrada(i); |
---|
| 2278 | db.Close(); |
---|
| 2279 | return(true); |
---|
| 2280 | } |
---|
| 2281 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2282 | // Funcin:RESPUESTA_RemboOffline |
---|
[34fc87f] | 2283 | // |
---|
| 2284 | // Descripcin: |
---|
| 2285 | // Responde al comando Apagar |
---|
| 2286 | // Parnetros: |
---|
| 2287 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2288 | // - parametros: parametros del comando |
---|
| 2289 | // ________________________________________________________________________________________________________ |
---|
| 2290 | int RESPUESTA_RemboOffline(SOCKET s,char *parametros) |
---|
| 2291 | { |
---|
| 2292 | char ErrStr[200]; |
---|
| 2293 | Database db; |
---|
| 2294 | Table tbl; |
---|
| 2295 | int i; |
---|
| 2296 | |
---|
| 2297 | char *res,*der,*iph,*ido,*ids; |
---|
| 2298 | |
---|
| 2299 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2300 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2301 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2302 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2303 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2304 | |
---|
| 2305 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2306 | db.GetErrorErrStr(ErrStr); |
---|
| 2307 | return(false); |
---|
| 2308 | } |
---|
| 2309 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2310 | return(false); // Error al registrar notificacion |
---|
| 2311 | } |
---|
| 2312 | |
---|
| 2313 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2314 | |
---|
| 2315 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2316 | borra_entrada(i); |
---|
| 2317 | db.Close(); |
---|
| 2318 | return(true); |
---|
| 2319 | } |
---|
| 2320 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2321 | // Funcin: RESPUESTA_Reiniciar |
---|
[34fc87f] | 2322 | // |
---|
| 2323 | // Descripcin: |
---|
| 2324 | // Responde al comando Reiniciar |
---|
| 2325 | // Parnetros: |
---|
| 2326 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2327 | // - parametros: parametros del comando |
---|
| 2328 | // ________________________________________________________________________________________________________ |
---|
| 2329 | int RESPUESTA_Reiniciar(SOCKET s,char *parametros) |
---|
| 2330 | { |
---|
| 2331 | int i; |
---|
| 2332 | char ErrStr[200]; |
---|
| 2333 | Database db; |
---|
| 2334 | Table tbl; |
---|
| 2335 | |
---|
| 2336 | char *res,*der,*iph,*ido,*ids; |
---|
| 2337 | |
---|
| 2338 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2339 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2340 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2341 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2342 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2343 | |
---|
| 2344 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2345 | db.GetErrorErrStr(ErrStr); |
---|
| 2346 | return(false); |
---|
| 2347 | } |
---|
| 2348 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2349 | return(false); // Error al registrar notificacion |
---|
| 2350 | } |
---|
| 2351 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2352 | |
---|
| 2353 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2354 | borra_entrada(i); |
---|
| 2355 | db.Close(); |
---|
| 2356 | return(true); |
---|
| 2357 | } |
---|
| 2358 | // ________________________________________________________________________________________________________ |
---|
| 2359 | // |
---|
[277d0cd] | 2360 | // Funcin: borra_entrada |
---|
[34fc87f] | 2361 | // |
---|
| 2362 | // Descripcin: |
---|
| 2363 | // Borra la entrada de un ordenador en la tabla de socket |
---|
| 2364 | // Parnetros: |
---|
| 2365 | // - i: Indice dentro de la tabla |
---|
| 2366 | // ________________________________________________________________________________________________________ |
---|
| 2367 | int borra_entrada(int i) |
---|
| 2368 | { |
---|
| 2369 | tbsockets[i].ip[0]=(char)NULL; |
---|
| 2370 | tbsockets[i].estado[0]=(char)NULL; |
---|
| 2371 | if(!tbsockets[i].sock) |
---|
| 2372 | close(tbsockets[i].sock); |
---|
| 2373 | tbsockets[i].sock=INVALID_SOCKET; |
---|
[51dcdc7] | 2374 | //tbsockets[i].ipsrvdhcp[0]=(char)NULL; |
---|
[34fc87f] | 2375 | tbsockets[i].ipsrvrmb[0]=(char)NULL; |
---|
| 2376 | |
---|
| 2377 | return(true); |
---|
| 2378 | } |
---|
| 2379 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2380 | // Funcin: RESPUESTA_ExecShell |
---|
[34fc87f] | 2381 | // |
---|
| 2382 | // Descripcin: |
---|
| 2383 | // Responde al comando Ejecutar script |
---|
| 2384 | // Parnetros: |
---|
| 2385 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2386 | // - parametros: parametros del comando |
---|
| 2387 | // ________________________________________________________________________________________________________ |
---|
| 2388 | int RESPUESTA_ExecShell(SOCKET s,char *parametros) |
---|
| 2389 | { |
---|
| 2390 | char ErrStr[200]; |
---|
| 2391 | Database db; |
---|
| 2392 | Table tbl; |
---|
| 2393 | |
---|
| 2394 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2395 | |
---|
| 2396 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2397 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2398 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2399 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2400 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2401 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2402 | |
---|
| 2403 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2404 | db.GetErrorErrStr(ErrStr); |
---|
| 2405 | return(false); |
---|
| 2406 | } |
---|
| 2407 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2408 | return(false); // Error al registrar notificacion |
---|
| 2409 | } |
---|
| 2410 | |
---|
| 2411 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2412 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) // El ordenador ha cambiado de configuracin |
---|
| 2413 | return(false); |
---|
| 2414 | } |
---|
| 2415 | db.Close(); |
---|
| 2416 | return(true); |
---|
| 2417 | } |
---|
| 2418 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2419 | // Funcin: RespuestaEstandar |
---|
[34fc87f] | 2420 | // |
---|
| 2421 | // Descripcin: |
---|
[277d0cd] | 2422 | // Esta funcin actualiza la base de datos con el resultado de la ejecucin de un comando con seguimiento |
---|
[34fc87f] | 2423 | // Parnetros: |
---|
| 2424 | // - res: resultado de la ejecucin del comando |
---|
| 2425 | // - der: Descripcin del error si hubiese habido |
---|
| 2426 | // - ids: identificador de la accin notificada |
---|
| 2427 | // - ido: Identificador del ordenador que notifica |
---|
| 2428 | // - db: Objeto base de datos (operativo) |
---|
| 2429 | // - tbl: Objeto tabla |
---|
| 2430 | // ________________________________________________________________________________________________________ |
---|
| 2431 | int RespuestaEstandar(char *res,char *der,char *ids,char* ido,Database db,Table tbl) |
---|
| 2432 | { |
---|
| 2433 | char ErrStr[200],sqlstr[1000]; |
---|
| 2434 | char parametros[LONGITUD_PARAMETROS]; |
---|
| 2435 | char fechareg[100]; |
---|
| 2436 | int i,resul; |
---|
| 2437 | int idaccion,accionid,idnotificador; |
---|
| 2438 | char *iph; |
---|
| 2439 | struct tm* st; |
---|
| 2440 | |
---|
| 2441 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2442 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 2443 | pthread_mutex_lock(&guardia); |
---|
| 2444 | |
---|
| 2445 | sprintf(sqlstr,"Select * from acciones WHERE idaccion=%s",ids); |
---|
| 2446 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2447 | db.GetErrorErrStr(ErrStr); |
---|
| 2448 | pthread_mutex_unlock(&guardia); |
---|
| 2449 | return(false); |
---|
| 2450 | } |
---|
| 2451 | if(tbl.ISEOF()){ // No existe registro de acciones |
---|
| 2452 | pthread_mutex_unlock(&guardia); |
---|
| 2453 | return(true); |
---|
| 2454 | } |
---|
| 2455 | if(!tbl.Get("parametros",parametros)){ // Toma parametros de la accin |
---|
| 2456 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 2457 | pthread_mutex_unlock(&guardia); |
---|
| 2458 | return(false); |
---|
| 2459 | } |
---|
| 2460 | char resultado[2]; // comprueba si ya ha fallado la accin |
---|
| 2461 | if(!tbl.Get("resultado",resultado)){ // Toma resultado actual de la accin |
---|
| 2462 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2463 | pthread_mutex_unlock(&guardia); |
---|
| 2464 | return(false); |
---|
| 2465 | } |
---|
| 2466 | if(!tbl.Get("idaccion",idaccion)){ // Toma el identificador de la accin para tener el dato en formato "int" |
---|
| 2467 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2468 | pthread_mutex_unlock(&guardia); |
---|
| 2469 | return(false); |
---|
| 2470 | } |
---|
| 2471 | if(!tbl.Get("accionid",accionid)){ // Toma la accion padre |
---|
| 2472 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2473 | pthread_mutex_unlock(&guardia); |
---|
| 2474 | return(false); |
---|
| 2475 | } |
---|
| 2476 | if(!tbl.Get("idnotificador",idnotificador)){ // Toma el identificador del notificador |
---|
| 2477 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2478 | pthread_mutex_unlock(&guardia); |
---|
| 2479 | return(false); |
---|
| 2480 | } |
---|
| 2481 | |
---|
| 2482 | st=TomaHora(); |
---|
| 2483 | sprintf(fechareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 2484 | |
---|
| 2485 | // Graba notificacin |
---|
| 2486 | sprintf(sqlstr,"INSERT INTO notificaciones (accionid,idnotificador,fechahorareg,resultado,descrinotificacion) VALUES (%s,%s,'%s','%s','%s')",ids,ido,fechareg,res,der); |
---|
| 2487 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2488 | db.GetErrorErrStr(ErrStr); |
---|
| 2489 | pthread_mutex_unlock(&guardia); |
---|
| 2490 | return(false); |
---|
| 2491 | } |
---|
| 2492 | |
---|
| 2493 | if(strcmp(res,ACCION_FALLIDA)==0 && strcmp(resultado,ACCION_SINERRORES)==0){ // Accion fallida en el cliente rembo |
---|
| 2494 | sprintf(sqlstr,"Update acciones set resultado='%s' WHERE idaccion=%s",ACCION_CONERRORES,ids); |
---|
| 2495 | strcpy(resultado,ACCION_CONERRORES); |
---|
| 2496 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 2497 | db.GetErrorErrStr(ErrStr); |
---|
| 2498 | pthread_mutex_unlock(&guardia); |
---|
| 2499 | return(false); |
---|
| 2500 | } |
---|
| 2501 | } |
---|
| 2502 | // Comprueba si la accin se ejecutncorrectamente para el ambito sumando notificaciones |
---|
| 2503 | INTROaFINCAD(parametros); |
---|
| 2504 | iph=toma_parametro("iph",parametros); // Toma cadenaip |
---|
| 2505 | int tbnumipes=0,totalipes=1,lon; |
---|
| 2506 | |
---|
| 2507 | lon=strlen(iph); |
---|
| 2508 | for (i=0;i<lon;i++){ |
---|
| 2509 | if(iph[i]==';') |
---|
| 2510 | totalipes++; // ip detectada |
---|
| 2511 | } |
---|
| 2512 | |
---|
| 2513 | sprintf(sqlstr,"SELECT COUNT(*) AS tbnumipes FROM notificaciones WHERE accionid=%s",ids); |
---|
| 2514 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2515 | pthread_mutex_unlock(&guardia); |
---|
| 2516 | db.GetErrorErrStr(ErrStr); |
---|
| 2517 | pthread_mutex_unlock(&guardia); |
---|
| 2518 | return(false); |
---|
| 2519 | } |
---|
| 2520 | |
---|
| 2521 | if(!tbl.Get("tbnumipes",tbnumipes)){ // Recupera el numero de ordenadores que ya han notificado |
---|
| 2522 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo |
---|
| 2523 | pthread_mutex_unlock(&guardia); |
---|
| 2524 | return(false); |
---|
| 2525 | } |
---|
| 2526 | if(tbnumipes!=totalipes){ |
---|
| 2527 | pthread_mutex_unlock(&guardia); |
---|
| 2528 | return(true); // No es el ultimo ordenador en notificar |
---|
| 2529 | } |
---|
| 2530 | |
---|
| 2531 | st=TomaHora(); |
---|
| 2532 | sprintf(fechareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 2533 | |
---|
| 2534 | // Actualizacion despues de que todos los ordenadores han notificado |
---|
| 2535 | if(strcmp(resultado,ACCION_SINERRORES)==0){ // Accion finalizada con exito |
---|
| 2536 | sprintf(sqlstr,"Update acciones set estado='%s',resultado='%s',fechahorafin='%s' WHERE idaccion=%s",ACCION_FINALIZADA,ACCION_EXITOSA,fechareg,ids); |
---|
| 2537 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 2538 | db.GetErrorErrStr(ErrStr); |
---|
| 2539 | pthread_mutex_unlock(&guardia); |
---|
| 2540 | return(false); |
---|
| 2541 | } |
---|
| 2542 | } |
---|
| 2543 | if(strcmp(resultado,ACCION_CONERRORES)==0){ // Accion finalizada con errores |
---|
| 2544 | sprintf(sqlstr,"Update acciones set estado='%s',resultado='%s',fechahorafin='%s' WHERE idaccion=%s",ACCION_FINALIZADA,ACCION_FALLIDA,fechareg,ids); |
---|
| 2545 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 2546 | db.GetErrorErrStr(ErrStr); |
---|
| 2547 | pthread_mutex_unlock(&guardia); |
---|
| 2548 | return(false); |
---|
| 2549 | } |
---|
| 2550 | } |
---|
| 2551 | resul=true; |
---|
| 2552 | if(accionid>0){ // Existe accion padre que hay que actualizar |
---|
| 2553 | resul=InsertaNotificaciones(idaccion,idnotificador,accionid,resultado,db); |
---|
| 2554 | if(resul) |
---|
| 2555 | resul=comprueba_resultados(accionid,db); |
---|
| 2556 | } |
---|
| 2557 | pthread_mutex_unlock(&guardia); |
---|
| 2558 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2559 | return(resul); |
---|
| 2560 | } |
---|
| 2561 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2562 | // Funcin: RESPUESTA_CrearPerfilSoftware |
---|
[34fc87f] | 2563 | // |
---|
| 2564 | // Descripcin: |
---|
| 2565 | // Responde al comando Crear Perfil Software |
---|
| 2566 | // Parnetros: |
---|
| 2567 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2568 | // - parametros: parametros del comando |
---|
| 2569 | // ________________________________________________________________________________________________________ |
---|
| 2570 | int RESPUESTA_CrearPerfilSoftware(SOCKET s,char *parametros) |
---|
| 2571 | { |
---|
| 2572 | char ErrStr[200],sqlstr[1000]; |
---|
| 2573 | char *res,*der,*ids,*ifh,*ifs,*iph,*ido; |
---|
| 2574 | Database db; |
---|
| 2575 | Table tbl; |
---|
| 2576 | |
---|
| 2577 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2578 | db.GetErrorErrStr(ErrStr); |
---|
| 2579 | return(false); |
---|
| 2580 | } |
---|
| 2581 | |
---|
| 2582 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2583 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2584 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2585 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2586 | ido=toma_parametro("ido",parametros); // Toma dentificador del ordenador |
---|
| 2587 | ifh=toma_parametro("ifh",parametros); // Toma idperfilhard |
---|
| 2588 | ifs=toma_parametro("ifs",parametros); // Toma idperfilsoft |
---|
| 2589 | |
---|
| 2590 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2591 | return(false); // Error al registrar notificacion |
---|
| 2592 | } |
---|
| 2593 | |
---|
| 2594 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin en el cliente rembo |
---|
| 2595 | db.Close(); |
---|
| 2596 | return(false); |
---|
| 2597 | } |
---|
| 2598 | |
---|
| 2599 | sprintf(sqlstr,"Select * from perfileshard_perfilessoft WHERE idperfilhard=%s AND idperfilsoft=%s",ifh,ifs); |
---|
| 2600 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2601 | db.GetErrorErrStr(ErrStr); |
---|
| 2602 | return(false); |
---|
| 2603 | } |
---|
| 2604 | if(!tbl.ISEOF()){ // Si ya existe el registro ... no hace falta insertarlo |
---|
| 2605 | db.Close(); |
---|
| 2606 | return(false); |
---|
| 2607 | } |
---|
| 2608 | sprintf(sqlstr,"INSERT INTO perfileshard_perfilessoft (idperfilhard,idperfilsoft) VALUES(%s,%s)",ifh,ifs); |
---|
| 2609 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2610 | db.GetErrorErrStr(ErrStr); |
---|
| 2611 | return(false); |
---|
| 2612 | } |
---|
| 2613 | db.Close(); |
---|
| 2614 | return(true); |
---|
| 2615 | } |
---|
| 2616 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2617 | // Funcin: RESPUESTA_CrearSoftwareIncremental |
---|
[34fc87f] | 2618 | // |
---|
| 2619 | // Descripcin: |
---|
[277d0cd] | 2620 | // Esta funcin responde a un comando de creacin de un software incremental. Ademn actualiza la base de datos insertando |
---|
[34fc87f] | 2621 | // en su caso la nueva combinacin de perfil software con incremental. |
---|
| 2622 | // Parnetros: |
---|
| 2623 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2624 | // - parametros: parametros del comando |
---|
| 2625 | // ________________________________________________________________________________________________________ |
---|
| 2626 | int RESPUESTA_CrearSoftwareIncremental(SOCKET s,char *parametros) |
---|
| 2627 | { |
---|
| 2628 | char ErrStr[200],sqlstr[1000]; |
---|
| 2629 | char *res,*der,*ids,*ifh,*ifs,*icr,*iph,*ido; |
---|
| 2630 | int idphardidpsoft; |
---|
| 2631 | Database db; |
---|
| 2632 | Table tbl; |
---|
| 2633 | |
---|
| 2634 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2635 | db.GetErrorErrStr(ErrStr); |
---|
| 2636 | return(false); |
---|
| 2637 | } |
---|
| 2638 | |
---|
| 2639 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2640 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2641 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2642 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2643 | ido=toma_parametro("ido",parametros); // Toma dentificador del ordenador |
---|
| 2644 | ifh=toma_parametro("ifh",parametros); // Toma idperfilhard |
---|
| 2645 | ifs=toma_parametro("ifs",parametros); // Toma idperfilsoft |
---|
| 2646 | icr=toma_parametro("icr",parametros); // Toma idsoftincremental |
---|
| 2647 | |
---|
| 2648 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2649 | return(false); // Error al registrar notificacion |
---|
| 2650 | } |
---|
| 2651 | |
---|
| 2652 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin en el cliente rembo |
---|
| 2653 | db.Close(); |
---|
| 2654 | return(false); |
---|
| 2655 | } |
---|
| 2656 | |
---|
| 2657 | sprintf(sqlstr,"Select idphardidpsoft from perfileshard_perfilessoft WHERE idperfilhard=%s AND idperfilsoft=%s",ifh,ifs); |
---|
| 2658 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2659 | db.GetErrorErrStr(ErrStr); |
---|
| 2660 | return(false); |
---|
| 2661 | } |
---|
| 2662 | |
---|
| 2663 | if(tbl.ISEOF()){ // Si no existe el registro ... |
---|
| 2664 | db.Close(); |
---|
| 2665 | return(false); |
---|
| 2666 | } |
---|
| 2667 | |
---|
| 2668 | if(!tbl.Get("idphardidpsoft",idphardidpsoft)){ // Recupera el identificador de la combinacin de perfiles |
---|
| 2669 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo |
---|
| 2670 | return(false); |
---|
| 2671 | } |
---|
| 2672 | |
---|
| 2673 | sprintf(sqlstr,"Select * from phard_psoft_softincremental WHERE idphardidpsoft=%d AND idsoftincremental=%s",idphardidpsoft,icr); |
---|
| 2674 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2675 | db.GetErrorErrStr(ErrStr); |
---|
| 2676 | return(false); |
---|
| 2677 | } |
---|
| 2678 | |
---|
| 2679 | if(!tbl.ISEOF()){ // Si ya existe el registro ... |
---|
| 2680 | db.Close(); |
---|
| 2681 | return(false); |
---|
| 2682 | } |
---|
| 2683 | |
---|
| 2684 | sprintf(sqlstr,"INSERT INTO phard_psoft_softincremental (idphardidpsoft,idsoftincremental) VALUES(%d,%s)",idphardidpsoft,icr); |
---|
| 2685 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2686 | db.GetErrorErrStr(ErrStr); |
---|
| 2687 | return(false); |
---|
| 2688 | } |
---|
| 2689 | db.Close(); |
---|
| 2690 | return(true); |
---|
| 2691 | } |
---|
| 2692 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2693 | // Funcin: RESPUESTA_RestaurarImagen |
---|
[34fc87f] | 2694 | // |
---|
| 2695 | // Descripcin: |
---|
[277d0cd] | 2696 | // Esta funcin responde a un comando de restauracin de una imagen. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2697 | // Parnetros: |
---|
| 2698 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2699 | // - parametros: parametros del comando |
---|
| 2700 | // ________________________________________________________________________________________________________ |
---|
| 2701 | int RESPUESTA_RestaurarImagen(SOCKET s,char *parametros) |
---|
| 2702 | { |
---|
| 2703 | char ErrStr[200],gido[20]; |
---|
| 2704 | char *res,*der,*ids,*iph,*ido,*idi,*par,*cfg; |
---|
| 2705 | Database db; |
---|
| 2706 | Table tbl; |
---|
| 2707 | |
---|
| 2708 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2709 | db.GetErrorErrStr(ErrStr); |
---|
| 2710 | return(false); |
---|
| 2711 | } |
---|
| 2712 | |
---|
| 2713 | INTROaFINCAD(parametros); |
---|
| 2714 | |
---|
| 2715 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2716 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2717 | ids=toma_parametro("ids",parametros); // Toma identificador de la accion |
---|
| 2718 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2719 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2720 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2721 | par=toma_parametro("par",parametros); // particion |
---|
| 2722 | idi=toma_parametro("idi",parametros); // identificador de la imagen |
---|
| 2723 | |
---|
| 2724 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2725 | |
---|
| 2726 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2727 | return(false); // Error al registrar notificacion |
---|
| 2728 | } |
---|
| 2729 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2730 | db.Close(); |
---|
| 2731 | return(false); |
---|
| 2732 | } |
---|
| 2733 | |
---|
| 2734 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2735 | if(!Actualiza_ordenador_imagen(par,idi,gido,db)) return(false); |
---|
| 2736 | db.Close(); |
---|
| 2737 | return(true); |
---|
| 2738 | } |
---|
| 2739 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2740 | // Funcin: Actualiza_ordenador_imagen |
---|
[34fc87f] | 2741 | // |
---|
| 2742 | // Descripcin: |
---|
[277d0cd] | 2743 | // Esta funcin actualiza la tabla ordenador_imagen |
---|
[34fc87f] | 2744 | // Parnetros: |
---|
| 2745 | // - par: particion |
---|
| 2746 | // - idi: identificador de la imagen ( 0 ninguna ) |
---|
| 2747 | // - ido: identificador del ordenador |
---|
| 2748 | // - db: Conexin ADO operativa |
---|
| 2749 | // ________________________________________________________________________________________________________ |
---|
[dad9f34] | 2750 | int Actualiza_ordenador_imagen(char *par,const char *idi,char *ido,Database db) |
---|
[34fc87f] | 2751 | { |
---|
| 2752 | char ErrStr[200],sqlstr[1000]; |
---|
| 2753 | Table tbl; |
---|
| 2754 | int idimagen,idimagenres; |
---|
| 2755 | |
---|
| 2756 | idimagenres=atoi(idi); |
---|
| 2757 | if(idimagenres==0){ // Se ha formateado la particin y se ha borrado la imagen por tanto |
---|
| 2758 | sprintf(sqlstr,"DELETE FROM ordenador_imagen WHERE idordenador=%s AND particion=%s",ido,par); |
---|
| 2759 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2760 | db.GetErrorErrStr(ErrStr); |
---|
| 2761 | return(false); |
---|
| 2762 | } |
---|
| 2763 | return(true); |
---|
| 2764 | } |
---|
| 2765 | |
---|
| 2766 | sprintf(sqlstr,"SELECT idimagen FROM ordenador_imagen INNER JOIN ordenadores ON ordenador_imagen.idordenador = ordenadores.idordenador WHERE ordenadores.idordenador = %s AND ordenador_imagen.particion = %s",ido,par); |
---|
| 2767 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2768 | db.GetErrorErrStr(ErrStr); |
---|
| 2769 | return(false); |
---|
| 2770 | } |
---|
| 2771 | if(!tbl.ISEOF()){ // Existe registro |
---|
| 2772 | if(!tbl.Get("idimagen",idimagen)){ |
---|
| 2773 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 2774 | return(false); |
---|
| 2775 | } |
---|
| 2776 | else{ |
---|
| 2777 | if (idimagenres!=idimagen){ |
---|
| 2778 | sprintf(sqlstr,"Update ordenador_imagen set idimagen=%s WHERE idordenador=%s AND particion=%s",idi,ido,par); |
---|
| 2779 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 2780 | db.GetErrorErrStr(ErrStr); |
---|
| 2781 | return(false); |
---|
| 2782 | } |
---|
| 2783 | } |
---|
| 2784 | } |
---|
| 2785 | } |
---|
| 2786 | else{ // No existe el registro |
---|
| 2787 | sprintf(sqlstr,"INSERT INTO ordenador_imagen (idordenador,particion,idimagen) VALUES(%s,%s,%s)",ido,par,idi); |
---|
| 2788 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2789 | db.GetErrorErrStr(ErrStr); |
---|
| 2790 | return(false); |
---|
| 2791 | } |
---|
| 2792 | } |
---|
| 2793 | return(true); |
---|
| 2794 | } |
---|
| 2795 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2796 | // Funcin: RESPUESTA_ParticionaryFormatear |
---|
[34fc87f] | 2797 | // |
---|
| 2798 | // Descripcin: |
---|
[277d0cd] | 2799 | // Esta funcin responde a un comando de particionar y formatear. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2800 | // Parnetros: |
---|
| 2801 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2802 | // - parametros: parametros del comando |
---|
| 2803 | // ________________________________________________________________________________________________________ |
---|
| 2804 | int RESPUESTA_ParticionaryFormatear(SOCKET s,char *parametros) |
---|
| 2805 | { |
---|
| 2806 | char sqlstr[1000],ErrStr[200],gido[20]; |
---|
| 2807 | Database db; |
---|
| 2808 | Table tbl; |
---|
| 2809 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2810 | |
---|
| 2811 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2812 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2813 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2814 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2815 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2816 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2817 | |
---|
| 2818 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2819 | |
---|
| 2820 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2821 | db.GetErrorErrStr(ErrStr); |
---|
| 2822 | return(false); |
---|
| 2823 | } |
---|
| 2824 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2825 | return(false); // Error al registrar notificacion |
---|
| 2826 | } |
---|
| 2827 | if(strcmp(res,ACCION_FALLIDA)==0){ |
---|
| 2828 | db.Close(); |
---|
| 2829 | return(true); // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2830 | } |
---|
| 2831 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2832 | |
---|
| 2833 | // Elimina informacin sobre imagenes en este ordenador, al haber sido formateado |
---|
| 2834 | sprintf(sqlstr,"DELETE FROM ordenador_imagen WHERE idordenador=%s",gido); |
---|
| 2835 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2836 | db.GetErrorErrStr(ErrStr); |
---|
| 2837 | return(false); |
---|
| 2838 | } |
---|
| 2839 | db.Close(); |
---|
| 2840 | return(true); |
---|
| 2841 | } |
---|
| 2842 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2843 | // Funcin: RESPUESTA_Configurar |
---|
[34fc87f] | 2844 | // |
---|
| 2845 | // Descripcin: |
---|
[277d0cd] | 2846 | // Esta funcin responde a un comando de Configurar. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2847 | // Parnetros: |
---|
| 2848 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2849 | // - parametros: parametros del comando |
---|
| 2850 | // ________________________________________________________________________________________________________ |
---|
| 2851 | int RESPUESTA_Configurar(SOCKET s,char *parametros) |
---|
| 2852 | { |
---|
| 2853 | char ErrStr[200],gids[20],gido[20]; |
---|
| 2854 | Database db; |
---|
| 2855 | Table tbl; |
---|
| 2856 | int lon,resul,i; |
---|
| 2857 | char *res,*der,*ids,*iph,*ido,*cfg,*hdc; |
---|
| 2858 | |
---|
| 2859 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2860 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2861 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2862 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2863 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2864 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2865 | hdc=toma_parametro("hdc",parametros); // Toma participaciones a formatear |
---|
| 2866 | |
---|
| 2867 | strcpy(gids,ids); // Guarda el identificador de la accin |
---|
| 2868 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2869 | |
---|
| 2870 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2871 | db.GetErrorErrStr(ErrStr); |
---|
| 2872 | return(false); |
---|
| 2873 | } |
---|
| 2874 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2875 | return(false); // Error al registrar notificacion |
---|
| 2876 | } |
---|
| 2877 | |
---|
| 2878 | if(strcmp(res,ACCION_FALLIDA)==0){ |
---|
| 2879 | db.Close(); |
---|
| 2880 | return(true); // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2881 | } |
---|
| 2882 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2883 | |
---|
| 2884 | lon=strlen(hdc); |
---|
| 2885 | for(i=0;i<lon;i++){ |
---|
| 2886 | if(hdc[i]==';') hdc[i]='\0'; |
---|
| 2887 | } |
---|
| 2888 | for(i=0;i<lon;i++){ |
---|
| 2889 | if(*hdc!='\0'){ |
---|
| 2890 | resul=Actualiza_ordenador_imagen(hdc,"0",gido,db); |
---|
| 2891 | if(!resul){ |
---|
| 2892 | db.Close(); |
---|
| 2893 | return(false); |
---|
| 2894 | } |
---|
| 2895 | } |
---|
| 2896 | hdc++; |
---|
| 2897 | } |
---|
| 2898 | db.Close(); |
---|
| 2899 | return(true); |
---|
| 2900 | } |
---|
| 2901 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2902 | // Funcin: RESPUESTA_TomaConfiguracion |
---|
[34fc87f] | 2903 | // |
---|
| 2904 | // Descripcin: |
---|
[277d0cd] | 2905 | // Esta funcin responde a un comando de Toma Comfiguracin. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2906 | // Parnetros: |
---|
| 2907 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2908 | // - parametros: parametros del comando |
---|
| 2909 | // ________________________________________________________________________________________________________ |
---|
| 2910 | int RESPUESTA_TomaConfiguracion(SOCKET s,char *parametros) |
---|
| 2911 | { |
---|
| 2912 | char ErrStr[200]; |
---|
| 2913 | Database db; |
---|
| 2914 | Table tbl; |
---|
| 2915 | |
---|
| 2916 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2917 | |
---|
| 2918 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2919 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2920 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2921 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2922 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2923 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2924 | |
---|
| 2925 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2926 | db.GetErrorErrStr(ErrStr); |
---|
| 2927 | return(false); |
---|
| 2928 | } |
---|
| 2929 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2930 | return(false); // Error al registrar notificacion |
---|
| 2931 | } |
---|
| 2932 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2933 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) // El ordenador ha cambiado de configuracin |
---|
| 2934 | return(false); |
---|
| 2935 | } |
---|
| 2936 | db.Close(); |
---|
| 2937 | return(true); |
---|
| 2938 | } |
---|
| 2939 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2940 | // Funcin: RESPUESTA_TomaHardware |
---|
[34fc87f] | 2941 | // |
---|
| 2942 | // Descripcin: |
---|
[277d0cd] | 2943 | // Esta funcin responde a un comando de Toma HArdware. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2944 | // Parnetros: |
---|
| 2945 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2946 | // - parametros: parametros del comando |
---|
| 2947 | // ________________________________________________________________________________________________________ |
---|
| 2948 | int RESPUESTA_TomaHardware(SOCKET s,char *parametros) |
---|
| 2949 | { |
---|
| 2950 | char ErrStr[200]; |
---|
| 2951 | Database db; |
---|
| 2952 | Table tbl; |
---|
| 2953 | |
---|
| 2954 | char *res,*der,*ids,*iph,*ido,*hrd; |
---|
| 2955 | |
---|
| 2956 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2957 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2958 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2959 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2960 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2961 | |
---|
| 2962 | hrd=toma_parametro("hrd",parametros); // Toma configuracin |
---|
| 2963 | |
---|
| 2964 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2965 | db.GetErrorErrStr(ErrStr); |
---|
| 2966 | return(false); |
---|
| 2967 | } |
---|
| 2968 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2969 | return(false); // Error al registrar notificacion |
---|
| 2970 | } |
---|
| 2971 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2972 | if(!actualiza_hardware(db,tbl,hrd,iph,ido)) // El ordenador ha cambiado de configuracin |
---|
| 2973 | return(false); |
---|
| 2974 | } |
---|
| 2975 | db.Close(); |
---|
| 2976 | return(true); |
---|
| 2977 | } |
---|
| 2978 | // ________________________________________________________________________________________________________ |
---|
[5eae07e] | 2979 | // Funcin: RESPUESTA_TomaSoftware |
---|
| 2980 | // |
---|
| 2981 | // Descripcin: |
---|
| 2982 | // Esta funcin responde a un comando de Inventario Software. Además actualiza la base de datos. |
---|
| 2983 | // Parnetros: |
---|
| 2984 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2985 | // - parametros: parametros del comando |
---|
| 2986 | // ________________________________________________________________________________________________________ |
---|
| 2987 | int RESPUESTA_TomaSoftware(SOCKET s,char *parametros) |
---|
| 2988 | { |
---|
| 2989 | char ErrStr[200]; |
---|
| 2990 | Database db; |
---|
| 2991 | Table tbl; |
---|
| 2992 | |
---|
[b1f0d31] | 2993 | char *res,*der,*ids,*iph,*ido,*sft,*par,*tfs; |
---|
[5eae07e] | 2994 | |
---|
| 2995 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2996 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2997 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2998 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2999 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 3000 | |
---|
[536adc4] | 3001 | sft=toma_parametro("sft",parametros); // Toma software |
---|
| 3002 | par=toma_parametro("par",parametros); // Toma partición |
---|
[b1f0d31] | 3003 | tfs=toma_parametro("tfs",parametros); // Toma tipo partición |
---|
[5eae07e] | 3004 | |
---|
| 3005 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 3006 | db.GetErrorErrStr(ErrStr); |
---|
| 3007 | return(false); |
---|
| 3008 | } |
---|
| 3009 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 3010 | return(false); // Error al registrar notificacion |
---|
| 3011 | } |
---|
| 3012 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
[b1f0d31] | 3013 | if(!actualiza_software(db,tbl,sft,par,tfs,iph,ido)) // El ordenador ha cambiado de configuracin |
---|
[5eae07e] | 3014 | return(false); |
---|
| 3015 | } |
---|
| 3016 | db.Close(); |
---|
| 3017 | return(true); |
---|
| 3018 | } |
---|
| 3019 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3020 | // Funcin: busca_comandos |
---|
[34fc87f] | 3021 | // |
---|
| 3022 | // Descripcin: |
---|
[277d0cd] | 3023 | // Esta funcin busca en la base de datos,comandos pendientes de ejecutar para el ordenador cocreto |
---|
[34fc87f] | 3024 | // Parnetros: |
---|
| 3025 | // - iph: Direccin IP del ordenador |
---|
| 3026 | // - ido: Identificador del ordenador |
---|
| 3027 | // - parametros: parametros de la accin buscada |
---|
| 3028 | // - ids: Identificador de la accin |
---|
| 3029 | // ________________________________________________________________________________________________________ |
---|
| 3030 | int busca_comandos(char* iph,char *ido,char *parametros,int *ids) |
---|
| 3031 | { |
---|
| 3032 | char sqlstr[1000],ErrStr[200]; |
---|
| 3033 | Database db; |
---|
| 3034 | Table tbl,tbln; |
---|
| 3035 | |
---|
| 3036 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 3037 | db.GetErrorErrStr(ErrStr); |
---|
| 3038 | return(false); |
---|
| 3039 | } |
---|
| 3040 | sprintf(sqlstr,"SELECT idaccion,resultado,estado,parametros FROM acciones WHERE tipoaccion=%d AND estado = '%s' AND (resultado='%s' OR resultado='%s') AND parametros LIKE '%c%s%c' ORDER BY idaccion",EJECUCION_COMANDO,ACCION_INICIADA,ACCION_SINERRORES,ACCION_CONERRORES,37,iph,37); |
---|
| 3041 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3042 | db.GetErrorErrStr(ErrStr); |
---|
| 3043 | return(false); |
---|
| 3044 | } |
---|
| 3045 | if(tbl.ISEOF()){ |
---|
| 3046 | db.Close(); |
---|
| 3047 | return(false); // No hay comandos pendientes |
---|
| 3048 | } |
---|
| 3049 | |
---|
| 3050 | while(!tbl.ISEOF()){ // Busca entre todas las acciones de diversos ambitos |
---|
| 3051 | |
---|
| 3052 | if(!tbl.Get("parametros",parametros)){ // Toma parametros |
---|
| 3053 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo parametros |
---|
| 3054 | return(false); |
---|
| 3055 | } |
---|
| 3056 | |
---|
| 3057 | if(IgualIP(parametros,iph)){ // Si existe la IP en la cadena |
---|
| 3058 | if(!tbl.Get("idaccion",*ids)){ // Toma identificador de la accin |
---|
| 3059 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3060 | return(false); |
---|
| 3061 | } |
---|
| 3062 | |
---|
| 3063 | // Comprueba que aunque el resultado es ACCION_INICIADA, este ordenador an no ha notificado |
---|
| 3064 | sprintf(sqlstr,"SELECT idnotificador FROM notificaciones WHERE accionid=%d AND idnotificador=%s",*ids,ido); |
---|
| 3065 | if(!db.Execute(sqlstr,tbln)){ // Error al leer |
---|
| 3066 | db.GetErrorErrStr(ErrStr); |
---|
| 3067 | return(false); |
---|
| 3068 | } |
---|
| 3069 | if(tbln.ISEOF()){ |
---|
| 3070 | db.Close(); |
---|
| 3071 | return(true); // No ha notificado este ordenador |
---|
| 3072 | } |
---|
| 3073 | } |
---|
| 3074 | tbl.MoveNext(); |
---|
| 3075 | } |
---|
| 3076 | db.Close(); |
---|
| 3077 | return(false); // No hay mn acciones |
---|
| 3078 | } |
---|
| 3079 | // ________________________________________________________________________________________________________ |
---|
| 3080 | int InsertaNotificaciones(int idaccion,int idnotificador, int accionid, char *resultado,Database db){ |
---|
| 3081 | |
---|
| 3082 | struct tm* st; |
---|
| 3083 | char ErrStr[200],sqlstr[1000]; |
---|
| 3084 | char fechahorareg[100]; |
---|
| 3085 | char descrinotificacion[100]; |
---|
| 3086 | |
---|
| 3087 | |
---|
| 3088 | st=TomaHora(); |
---|
| 3089 | sprintf(fechahorareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 3090 | |
---|
| 3091 | strcpy(descrinotificacion," "); |
---|
| 3092 | |
---|
| 3093 | if(strcmp(resultado,ACCION_CONERRORES)==0) { |
---|
| 3094 | strcpy(descrinotificacion,"Ha ocurrido algn error en la ejecucin de esta tarea."); |
---|
| 3095 | strcpy(resultado,ACCION_FALLIDA); |
---|
| 3096 | } |
---|
| 3097 | if(strcmp(resultado,ACCION_SINERRORES)==0) |
---|
| 3098 | strcpy(resultado,ACCION_EXITOSA); |
---|
| 3099 | |
---|
| 3100 | sprintf(sqlstr,"INSERT INTO notificaciones (accionid,idnotificador,fechahorareg,resultado,descrinotificacion,idaccion) VALUES (%d,%d,'%s','%s','%s',%d)",accionid,idnotificador,fechahorareg,resultado,descrinotificacion,idaccion); |
---|
| 3101 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3102 | db.GetErrorErrStr(ErrStr); |
---|
| 3103 | return(false); |
---|
| 3104 | } |
---|
| 3105 | return(true); |
---|
| 3106 | } |
---|
| 3107 | // ________________________________________________________________________________________________________ |
---|
| 3108 | int comprueba_resultados(int idaccion,Database db){ |
---|
| 3109 | |
---|
| 3110 | char ErrStr[200],sqlstr[1000]; |
---|
| 3111 | int numfallidas; |
---|
| 3112 | char finalaccion[2]; |
---|
| 3113 | Table tbl; |
---|
| 3114 | |
---|
| 3115 | sprintf(sqlstr,"SELECT COUNT(*) as numfallidas FROM notificaciones WHERE resultado='%s' AND accionid=%d",ACCION_FALLIDA,idaccion); |
---|
| 3116 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3117 | db.GetErrorErrStr(ErrStr); |
---|
| 3118 | return(false); |
---|
| 3119 | } |
---|
| 3120 | if(tbl.ISEOF()) return(false); // No existe registro de acciones |
---|
| 3121 | |
---|
| 3122 | if(!tbl.Get("numfallidas",numfallidas)){ // Toma dato |
---|
| 3123 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3124 | return(false); |
---|
| 3125 | } |
---|
| 3126 | |
---|
| 3127 | if(numfallidas>0) |
---|
| 3128 | strcpy(finalaccion,ACCION_CONERRORES); |
---|
| 3129 | else |
---|
| 3130 | strcpy(finalaccion,ACCION_SINERRORES); |
---|
| 3131 | |
---|
| 3132 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s' WHERE idaccion=%d",finalaccion,idaccion); |
---|
| 3133 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 3134 | db.GetErrorErrStr(ErrStr); |
---|
| 3135 | return(false); |
---|
| 3136 | } |
---|
| 3137 | // Comprueba si ha finalizado esta accin e inserta su notificador correspondiente |
---|
| 3138 | return(comprueba_finalizada(idaccion,finalaccion,db)); |
---|
| 3139 | } |
---|
| 3140 | // ________________________________________________________________________________________________________ |
---|
| 3141 | int comprueba_finalizada(int idaccion,char *resultado,Database db){ |
---|
| 3142 | |
---|
| 3143 | char ErrStr[200],sqlstr[1000]; |
---|
| 3144 | int numnotificaciones,tipoaccion,idnotificador; |
---|
| 3145 | char parametros[LONGITUD_PARAMETROS],*cadenanot; |
---|
| 3146 | char fechareg[100]; |
---|
| 3147 | int accionid,cont,i,resul,lon; |
---|
| 3148 | Table tbl; |
---|
| 3149 | struct tm* st; |
---|
| 3150 | |
---|
| 3151 | sprintf(sqlstr,"SELECT COUNT(*) as numnotificaciones FROM notificaciones WHERE accionid=%d",idaccion); |
---|
| 3152 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3153 | db.GetErrorErrStr(ErrStr); |
---|
| 3154 | return(false); |
---|
| 3155 | } |
---|
| 3156 | if(tbl.ISEOF()) return(false); // No existe registro de acciones |
---|
| 3157 | |
---|
| 3158 | if(!tbl.Get("numnotificaciones",numnotificaciones)){ // Toma dato |
---|
| 3159 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3160 | return(false); |
---|
| 3161 | } |
---|
| 3162 | |
---|
| 3163 | sprintf(sqlstr,"SELECT tipoaccion,parametros,idnotificador,accionid FROM acciones WHERE idaccion=%d",idaccion); |
---|
| 3164 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3165 | db.GetErrorErrStr(ErrStr); |
---|
| 3166 | return(false); |
---|
| 3167 | } |
---|
| 3168 | if(tbl.ISEOF()) return(true); // No existe registro de acciones |
---|
| 3169 | |
---|
| 3170 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma dato |
---|
| 3171 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3172 | return(false); |
---|
| 3173 | } |
---|
| 3174 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3175 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3176 | return(false); |
---|
| 3177 | } |
---|
| 3178 | if(!tbl.Get("idnotificador",idnotificador)){ // Toma dato |
---|
| 3179 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3180 | return(false); |
---|
| 3181 | } |
---|
| 3182 | if(!tbl.Get("accionid",accionid)){ // Toma dato |
---|
| 3183 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3184 | return(false); |
---|
| 3185 | } |
---|
| 3186 | |
---|
| 3187 | INTROaFINCAD(parametros); |
---|
| 3188 | switch(tipoaccion){ |
---|
| 3189 | case EJECUCION_COMANDO : |
---|
| 3190 | cadenanot=toma_parametro("iph",parametros); // Toma cadenaip |
---|
| 3191 | break; |
---|
| 3192 | case EJECUCION_TAREA : |
---|
| 3193 | cadenanot=toma_parametro("cmd",parametros); // Toma comandos |
---|
| 3194 | break; |
---|
| 3195 | case EJECUCION_TRABAJO : |
---|
| 3196 | cadenanot=toma_parametro("tsk",parametros); // Toma tareas |
---|
| 3197 | break; |
---|
| 3198 | default: |
---|
| 3199 | return(false); |
---|
| 3200 | } |
---|
| 3201 | cont=1; |
---|
| 3202 | lon=strlen(cadenanot); |
---|
| 3203 | for (i=0;i<lon;i++){ |
---|
| 3204 | if(cadenanot[i]==';') cont++; |
---|
| 3205 | } |
---|
| 3206 | resul=true; |
---|
| 3207 | if(numnotificaciones==cont){ |
---|
| 3208 | st=TomaHora(); |
---|
| 3209 | sprintf(fechareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 3210 | |
---|
| 3211 | if(strcmp(resultado,ACCION_CONERRORES)==0) |
---|
| 3212 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s',estado='%s',fechahorafin='%s' WHERE idaccion=%d",ACCION_FALLIDA,ACCION_FINALIZADA,fechareg,idaccion); |
---|
| 3213 | else |
---|
| 3214 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s',estado='%s',fechahorafin='%s' WHERE idaccion=%d",ACCION_EXITOSA,ACCION_FINALIZADA,fechareg,idaccion); |
---|
| 3215 | |
---|
| 3216 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 3217 | db.GetErrorErrStr(ErrStr); |
---|
| 3218 | return(false); |
---|
| 3219 | } |
---|
| 3220 | |
---|
| 3221 | if(accionid>0){ // Esto no se ejecutarnsi la tarea tiene un trabajo padre |
---|
| 3222 | resul=InsertaNotificaciones(idaccion,idnotificador,accionid,resultado,db); |
---|
| 3223 | if(resul) |
---|
| 3224 | return(comprueba_resultados(accionid,db)); |
---|
| 3225 | } |
---|
| 3226 | } |
---|
| 3227 | return(resul); |
---|
| 3228 | } |
---|
| 3229 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3230 | // Funcin: EnviaServidoresRembo |
---|
[34fc87f] | 3231 | // |
---|
| 3232 | // Descripcin: |
---|
[277d0cd] | 3233 | // Esta funcin envia una trama a un servidor rembo para que sus clientes ejecuten un comando |
---|
[34fc87f] | 3234 | // Parnetros: |
---|
| 3235 | // - parametros: parametros del comando |
---|
| 3236 | // ________________________________________________________________________________________________________ |
---|
| 3237 | void EnviaServidoresRembo(char * parametros) |
---|
| 3238 | { |
---|
| 3239 | int i,lon; |
---|
| 3240 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3241 | if (tbsocketsSRVRMB[i].swenv==1){ // El switch de envio estna uno hay que enviar al servidor trama ... |
---|
| 3242 | strcat(parametros,"iph="); |
---|
| 3243 | strcat(parametros,tbsocketsSRVRMB[i].ipes); |
---|
| 3244 | lon=strlen(parametros); |
---|
| 3245 | parametros[lon-1]='\r'; // Quita la coma final |
---|
| 3246 | manda_trama_servidorrembo(tbsocketsSRVRMB[i].ip,parametros,tbsocketsSRVRMB[i].puertorepo); |
---|
| 3247 | } |
---|
| 3248 | } |
---|
| 3249 | } |
---|
| 3250 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3251 | // Funcin: manda_comando_servidorrembo |
---|
[34fc87f] | 3252 | // |
---|
| 3253 | // Descripcin: |
---|
[277d0cd] | 3254 | // Esta funcin envia una trama a un servidor rembo para que sus clientes ejecuten un comando |
---|
[34fc87f] | 3255 | // Parnetros: |
---|
| 3256 | // - ip_srvrbm: Direccin IP del servidor REMBO |
---|
| 3257 | // - parametros: parametros del comando |
---|
| 3258 | // ________________________________________________________________________________________________________ |
---|
| 3259 | int manda_trama_servidorrembo(char* ip_srvrbm,char *parametros,int puertorepo) |
---|
| 3260 | { int ret; |
---|
| 3261 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 3262 | if(!trama) |
---|
| 3263 | return(false); |
---|
| 3264 | strcpy(trama->parametros,parametros); |
---|
| 3265 | SOCKET udpsock; |
---|
| 3266 | udpsock=UDPConnect(IPlocal); |
---|
| 3267 | if (udpsock == INVALID_SOCKET) return(false); |
---|
| 3268 | ret=envia_comandos(udpsock,trama,ip_srvrbm,puertorepo); |
---|
| 3269 | close(udpsock); |
---|
| 3270 | return(ret); |
---|
| 3271 | } |
---|
| 3272 | //_______________________________________________________________________________________________________________ |
---|
| 3273 | // |
---|
| 3274 | // Crea un socket en un puerto determinado para la conversacin UDP con el repositorio |
---|
| 3275 | // |
---|
| 3276 | //_______________________________________________________________________________________________________________ |
---|
| 3277 | SOCKET UDPConnect(char *ips) |
---|
| 3278 | { |
---|
| 3279 | SOCKET socket_c; // Socket para hebras (UDP) |
---|
| 3280 | struct sockaddr_in cliente; |
---|
| 3281 | int puerto; |
---|
| 3282 | |
---|
| 3283 | socket_c = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // Crea socket para UDP |
---|
| 3284 | |
---|
| 3285 | if (socket_c == SOCKET_ERROR) |
---|
| 3286 | return (INVALID_SOCKET); |
---|
| 3287 | |
---|
| 3288 | cliente.sin_addr.s_addr = inet_addr(ips); // selecciona interface |
---|
| 3289 | cliente.sin_family = AF_INET; |
---|
| 3290 | puerto=PUERTOMINUSER; |
---|
| 3291 | while(puerto<PUERTOMAXUSER){ // Busca puerto libre |
---|
| 3292 | cliente.sin_port = htons(puerto); // Puerto asignado |
---|
| 3293 | if (bind(socket_c,(struct sockaddr *)&cliente,sizeof(cliente)) == SOCKET_ERROR) |
---|
| 3294 | puerto++; |
---|
| 3295 | else |
---|
| 3296 | break; |
---|
| 3297 | } |
---|
| 3298 | if(puerto>=PUERTOMAXUSER){ // No hay puertos libres |
---|
| 3299 | return(INVALID_SOCKET); |
---|
| 3300 | } |
---|
| 3301 | return(socket_c); |
---|
| 3302 | } |
---|
| 3303 | //________________________________________________________________________________________________________ |
---|
[277d0cd] | 3304 | // Funcin: envia_comandos |
---|
[34fc87f] | 3305 | // |
---|
| 3306 | // Descripcin: |
---|
| 3307 | // Enva trama UDP |
---|
| 3308 | // ________________________________________________________________________________________________________ |
---|
| 3309 | int envia_comandos(SOCKET s,TRAMA* trama, char* ipsrv,int puerto) |
---|
| 3310 | { |
---|
| 3311 | int ret,lon; |
---|
| 3312 | struct sockaddr_in addrRepo; |
---|
| 3313 | |
---|
| 3314 | trama->arroba='@'; // cabecera de la trama |
---|
| 3315 | strcpy(trama->identificador,"JMMLCAMDJ"); // identificador de la trama |
---|
| 3316 | trama->ejecutor='1'; // ejecutor de la trama 1=el servidor hidra 2=el cliente hidra |
---|
| 3317 | |
---|
| 3318 | addrRepo.sin_family = AF_INET; |
---|
| 3319 | addrRepo.sin_port = htons((short)puerto); |
---|
| 3320 | addrRepo.sin_addr.s_addr = inet_addr(ipsrv); // Direccin IP repositorio |
---|
| 3321 | Encriptar((char*)trama); |
---|
| 3322 | lon=strlen((char*)trama); |
---|
| 3323 | ret = sendto(s,(char *)trama,lon,0,(struct sockaddr *)&addrRepo, sizeof(addrRepo)); |
---|
| 3324 | if (ret == SOCKET_ERROR){ |
---|
| 3325 | RegistraLog("***send() fallo en envío al repositorio",true); |
---|
| 3326 | return(FALSE); |
---|
| 3327 | } |
---|
| 3328 | return true; |
---|
| 3329 | } |
---|
| 3330 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3331 | // Funcin: DesmarcaServidoresRembo |
---|
[34fc87f] | 3332 | // |
---|
| 3333 | // Descripcin: |
---|
[277d0cd] | 3334 | // Esta funcin desmarca la tabla completa de servidores rembo para iniciar la cuesation de envio |
---|
[34fc87f] | 3335 | // ________________________________________________________________________________________________________ |
---|
| 3336 | void DesmarcaServidoresRembo(void) |
---|
| 3337 | { |
---|
| 3338 | int i; |
---|
| 3339 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3340 | tbsocketsSRVRMB[i].swenv=0; |
---|
| 3341 | tbsocketsSRVRMB[i].ipes[0]=(char)NULL; |
---|
| 3342 | } |
---|
| 3343 | } |
---|
| 3344 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3345 | // Funcin: MarcaServidoresRembo |
---|
[34fc87f] | 3346 | // |
---|
| 3347 | // Descripcin: |
---|
[277d0cd] | 3348 | // Esta funcin marca la tabla de servidores Rembo y coloca la ip del cliente en el buffer |
---|
[34fc87f] | 3349 | // Parnetros: |
---|
| 3350 | // - ipsrvrmb: ip del servidor rembo |
---|
| 3351 | // - ipclrmb: ip del cliente rembo |
---|
| 3352 | // ________________________________________________________________________________________________________ |
---|
| 3353 | void MarcaServidoresRembo(char* ipsrvrmb,char*ipclrmb) |
---|
| 3354 | { |
---|
| 3355 | int i,resul; |
---|
| 3356 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3357 | resul=strcmp(tbsocketsSRVRMB[i].ip,ipsrvrmb); |
---|
| 3358 | if(resul==0) {// servidor rembo encontrado |
---|
| 3359 | strcat(tbsocketsSRVRMB[i].ipes,ipclrmb); |
---|
| 3360 | strcat(tbsocketsSRVRMB[i].ipes,";"); |
---|
| 3361 | tbsocketsSRVRMB[i].swenv=1; |
---|
| 3362 | return; |
---|
| 3363 | } |
---|
| 3364 | } |
---|
| 3365 | } |
---|
| 3366 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3367 | // Funcin: TomaIPServidorRembo |
---|
[34fc87f] | 3368 | // |
---|
| 3369 | // Descripcin: |
---|
[277d0cd] | 3370 | // Esta funcin devuelve true o false dependiendo si el Servidor REMBO estnen la tabla de servidores. |
---|
[34fc87f] | 3371 | // Parnetros: |
---|
| 3372 | // - ip : La ip del servidor a buscar |
---|
| 3373 | // ________________________________________________________________________________________________________ |
---|
| 3374 | BOOLEAN TomaIPServidorRembo(char *ip,int *p) |
---|
| 3375 | { |
---|
| 3376 | int i,j; |
---|
| 3377 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 3378 | if (strcmp(ip,tbsockets[i].ip)==0){ // Si existe la IP ... |
---|
| 3379 | strcpy(ip,tbsockets[i].ipsrvrmb); |
---|
| 3380 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 3381 | if (strcmp(ip,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 3382 | *p=tbsocketsSRVRMB[j].puertorepo; |
---|
| 3383 | return(TRUE); |
---|
| 3384 | } |
---|
| 3385 | } |
---|
| 3386 | } |
---|
| 3387 | } |
---|
| 3388 | return(FALSE); |
---|
| 3389 | } |
---|
| 3390 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3391 | // Funcin: AbreConexion |
---|
[34fc87f] | 3392 | // |
---|
| 3393 | // Descripcin: |
---|
| 3394 | // Crea un socket y lo conecta a una interface de red. Devuelve el socket |
---|
| 3395 | // Parnetros: |
---|
| 3396 | // - ips : La direccin IP con la que se comunicarnel socket |
---|
| 3397 | // - port : Puerto para la comunicacin |
---|
| 3398 | // ________________________________________________________________________________________________________ |
---|
| 3399 | SOCKET AbreConexion(char *ips,int port) |
---|
| 3400 | { |
---|
| 3401 | struct sockaddr_in server; |
---|
| 3402 | SOCKET s; |
---|
| 3403 | |
---|
| 3404 | // Crea el socket y se intenta conectar |
---|
| 3405 | s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
---|
| 3406 | if (s == SOCKET_ERROR){ |
---|
| 3407 | RegistraLog("Error en la creacin del socket. Modulo: AbreConexion()",true); |
---|
| 3408 | return INVALID_SOCKET; |
---|
| 3409 | } |
---|
| 3410 | |
---|
| 3411 | server.sin_family = AF_INET; |
---|
| 3412 | server.sin_port = htons((short)port); |
---|
| 3413 | server.sin_addr.s_addr = inet_addr(ips); |
---|
| 3414 | |
---|
| 3415 | if (connect(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR){ |
---|
| 3416 | RegistraLog("connect() fallo",true); |
---|
| 3417 | return INVALID_SOCKET; |
---|
| 3418 | } |
---|
| 3419 | return(s); |
---|
| 3420 | |
---|
| 3421 | } |
---|
| 3422 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3423 | // Funcin: EjecutarTarea |
---|
[34fc87f] | 3424 | // |
---|
| 3425 | // Descripcin: |
---|
| 3426 | // Registra una accin (Tarea) y la envn para su ejecucin |
---|
| 3427 | // Parnetros: |
---|
| 3428 | // - idtarea : Identificador de la tarea |
---|
| 3429 | // - accionid: identificador del trabajo padre (si existe) |
---|
| 3430 | // - idnotificador: identificador del trabajo_tarea incluido en trabajo padre (si existe) |
---|
| 3431 | // - idcentro: Centro propietario del trabjo padre (si existe este trabajo) |
---|
| 3432 | // - Database: una conexion ADO operativa |
---|
| 3433 | // - parametros: parnetros de la accin |
---|
| 3434 | // ________________________________________________________________________________________________________ |
---|
| 3435 | int EjecutarTarea(int idtarea,int accionid,int idnotificador,int idcentro,Database db,char* parametros ) |
---|
| 3436 | { |
---|
| 3437 | char sqlstr[1000],ErrStr[200],ambito; |
---|
| 3438 | Table tbl; |
---|
| 3439 | int cont_comandos=0,lon; |
---|
| 3440 | int idcomando,idambito,idtareacomando,accionidcmd; |
---|
| 3441 | char wambitarea[20],ambitarea[4000]; |
---|
| 3442 | char wparamtarea[20],paramtarea[1000],pids[20]; |
---|
| 3443 | int tblon[100],tbComandosidcomando[100],tbComandosambito[100],tbComandosidnotificador[100],tbComandosidambito[100]; |
---|
| 3444 | char *tbComandosparametros[100]; |
---|
| 3445 | |
---|
| 3446 | ambitarea[0]=(char)NULL; // Inicializacin |
---|
| 3447 | strcpy(paramtarea,"cmd="); // Inicializacin |
---|
| 3448 | if(idcentro==0){ |
---|
| 3449 | // recupera el identificador del Centro propietario de la tarea |
---|
| 3450 | sprintf(sqlstr,"SELECT idcentro FROM tareas WHERE idtarea=%d",idtarea); |
---|
| 3451 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3452 | db.GetErrorErrStr(ErrStr); |
---|
| 3453 | return(false); |
---|
| 3454 | } |
---|
| 3455 | if(tbl.ISEOF()) return(true); |
---|
| 3456 | if(!tbl.Get("idcentro",idcentro)){ // Toma dato |
---|
| 3457 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3458 | return(false); |
---|
| 3459 | } |
---|
| 3460 | } |
---|
| 3461 | // Recupera los comandos que forman parte de la tarea |
---|
| 3462 | sprintf(sqlstr,"SELECT * FROM tareas_comandos WHERE idtarea=%d ORDER by orden",idtarea); |
---|
| 3463 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3464 | db.GetErrorErrStr(ErrStr); |
---|
| 3465 | return(false); |
---|
| 3466 | } |
---|
| 3467 | if(tbl.ISEOF()) return(true); |
---|
| 3468 | |
---|
| 3469 | // Recorre tareas-comandos |
---|
| 3470 | while(!tbl.ISEOF()){ |
---|
| 3471 | if(!tbl.Get("idcomando",idcomando)){ // Toma dato |
---|
| 3472 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3473 | return(false); |
---|
| 3474 | } |
---|
| 3475 | tbComandosidcomando[cont_comandos]=idcomando; |
---|
| 3476 | |
---|
| 3477 | if(!tbl.Get("ambito",ambito)){ // Toma dato |
---|
| 3478 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3479 | return(false); |
---|
| 3480 | } |
---|
| 3481 | tbComandosambito[cont_comandos]=ambito; |
---|
| 3482 | |
---|
| 3483 | if(!tbl.Get("idambito",idambito)){ // Toma dato |
---|
| 3484 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3485 | return(false); |
---|
| 3486 | } |
---|
| 3487 | tbComandosidambito[cont_comandos]=idambito; |
---|
| 3488 | |
---|
| 3489 | |
---|
| 3490 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3491 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3492 | return(false); |
---|
| 3493 | } |
---|
| 3494 | |
---|
| 3495 | lon=strlen(parametros); |
---|
| 3496 | tblon[cont_comandos]=lon; |
---|
| 3497 | tbComandosparametros[cont_comandos]=(char*)malloc(lon+20); |
---|
| 3498 | if(tbComandosparametros[cont_comandos]==NULL) |
---|
| 3499 | return(false); // No hay memoria bastante |
---|
| 3500 | |
---|
| 3501 | strcpy(tbComandosparametros[cont_comandos],parametros); |
---|
| 3502 | |
---|
| 3503 | if(!tbl.Get("idtareacomando",idtareacomando)){ // Toma dato |
---|
| 3504 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3505 | return(false); |
---|
| 3506 | } |
---|
| 3507 | tbComandosidnotificador[cont_comandos]=idtareacomando; |
---|
| 3508 | |
---|
| 3509 | sprintf(wambitarea,"%d:%d;",ambito,idambito); |
---|
| 3510 | strcat(ambitarea,wambitarea); |
---|
| 3511 | |
---|
| 3512 | sprintf(wparamtarea,"%d;",idtareacomando); |
---|
| 3513 | strcat(paramtarea,wparamtarea); |
---|
| 3514 | |
---|
| 3515 | cont_comandos++; |
---|
| 3516 | tbl.MoveNext(); |
---|
| 3517 | } |
---|
| 3518 | lon=strlen(ambitarea); |
---|
| 3519 | ambitarea[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3520 | |
---|
| 3521 | lon=strlen(paramtarea); |
---|
| 3522 | paramtarea[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3523 | |
---|
| 3524 | char _fechahorareg[100]; |
---|
| 3525 | struct tm* st; |
---|
| 3526 | st=TomaHora(); |
---|
| 3527 | sprintf(_fechahorareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 3528 | |
---|
| 3529 | sprintf(sqlstr,"INSERT INTO acciones (tipoaccion,idtipoaccion,cateaccion,ambito,idambito,ambitskwrk,fechahorareg,estado,resultado,idcentro,parametros,accionid,idnotificador) VALUES (%d,%d,%d,0,0,'%s','%s','%s','%s',%d,'%s',%d,%d)",EJECUCION_TAREA,idtarea,PROCESOS,ambitarea,_fechahorareg,ACCION_INICIADA,ACCION_SINERRORES,idcentro,paramtarea,accionid,idnotificador); |
---|
| 3530 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3531 | db.GetErrorErrStr(ErrStr); |
---|
| 3532 | return(false); |
---|
| 3533 | } |
---|
| 3534 | accionid=0; |
---|
| 3535 | // Toma identificador dela accin |
---|
| 3536 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3537 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3538 | db.GetErrorErrStr(ErrStr); |
---|
| 3539 | return(false); |
---|
| 3540 | } |
---|
| 3541 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3542 | if(!tbl.Get("identificador",accionid)){ |
---|
| 3543 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3544 | return(false); |
---|
| 3545 | } |
---|
| 3546 | } |
---|
| 3547 | int i; |
---|
| 3548 | // Insertar acciones:comandos |
---|
| 3549 | for (i=0;i<cont_comandos;i++){ |
---|
| 3550 | st=TomaHora(); |
---|
| 3551 | sprintf(_fechahorareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 3552 | sprintf(sqlstr,"INSERT INTO acciones (tipoaccion,idtipoaccion,cateaccion,ambito,idambito,fechahorareg,estado,resultado,idcentro,parametros,accionid,idnotificador) VALUES (%d,%d,%d,%d,%d,'%s','%s','%s',%d,'%s',%d,%d)",EJECUCION_COMANDO,tbComandosidcomando[i],PROCESOS,tbComandosambito[i],tbComandosidambito[i],_fechahorareg,ACCION_EXITOSA,ACCION_SINERRORES,idcentro,tbComandosparametros[i],accionid,tbComandosidnotificador[i]); |
---|
| 3553 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3554 | db.GetErrorErrStr(ErrStr); |
---|
| 3555 | free(tbComandosparametros[i]); |
---|
| 3556 | return(false); |
---|
| 3557 | } |
---|
| 3558 | // Toma identificador dela accin |
---|
| 3559 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3560 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3561 | db.GetErrorErrStr(ErrStr); |
---|
| 3562 | return(false); |
---|
| 3563 | } |
---|
| 3564 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3565 | if(!tbl.Get("identificador",accionidcmd)){ |
---|
| 3566 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3567 | return(false); |
---|
| 3568 | } |
---|
| 3569 | } |
---|
| 3570 | sprintf(pids,"ids=%d\r",accionidcmd); |
---|
| 3571 | strcat((char*)tbComandosparametros[i],pids); // Le ande el identificador de la accion |
---|
| 3572 | envia_tarea(tbComandosparametros[i]); |
---|
| 3573 | free(tbComandosparametros[i]); |
---|
| 3574 | } |
---|
| 3575 | return(true); |
---|
| 3576 | } |
---|
| 3577 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3578 | // Funcin: manda peticin de inclusion |
---|
[34fc87f] | 3579 | // |
---|
| 3580 | // Descripcin: |
---|
[277d0cd] | 3581 | // Esta funcin envia una tarea por la red. |
---|
[34fc87f] | 3582 | // Parnetros: |
---|
| 3583 | // - parametros: El contenido de la tarea |
---|
| 3584 | // ________________________________________________________________________________________________________ |
---|
| 3585 | void envia_tarea(char* parametros) |
---|
| 3586 | { |
---|
| 3587 | TRAMA trama; |
---|
| 3588 | |
---|
| 3589 | trama.arroba='@'; |
---|
| 3590 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 3591 | trama.ejecutor=parametros[0]; |
---|
| 3592 | strcpy(trama.parametros,(char*)¶metros[1]); |
---|
| 3593 | gestiona_comando(INVALID_SOCKET,trama); |
---|
| 3594 | } |
---|
| 3595 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3596 | // Funcin: EjecutarTrabajo |
---|
[34fc87f] | 3597 | // |
---|
| 3598 | // Descripcin: |
---|
| 3599 | // Registra una accin (Trabajo y la envn para su ejecucin |
---|
| 3600 | // Parnetros: |
---|
| 3601 | // - idtrabajo : Identificador del trabajo |
---|
| 3602 | // - Database: una conexion ADO operativa |
---|
| 3603 | // - parametros: parnetros de la accin |
---|
| 3604 | // ________________________________________________________________________________________________________ |
---|
| 3605 | int EjecutarTrabajo(int idtrabajo,Database db,char*parametros ) |
---|
| 3606 | { |
---|
| 3607 | char sqlstr[1000],ErrStr[200]; |
---|
| 3608 | Table tbl; |
---|
| 3609 | int cont_tareas=0,lon; |
---|
| 3610 | int idtarea,idtrabajotarea,idcentro; |
---|
| 3611 | char wambitrabajo[500],ambitrabajo[4000]; |
---|
| 3612 | char wparamtrabajo[20],paramtrabajo[1000]; |
---|
| 3613 | int tbTareasidtarea[100],tbTareasidnotificador[100]; |
---|
| 3614 | char ambitskwrk[500]; |
---|
| 3615 | |
---|
| 3616 | ambitrabajo[0]=(char)NULL; // Inicializacin |
---|
| 3617 | strcpy(paramtrabajo,"tsk="); // Inicializacin |
---|
| 3618 | |
---|
| 3619 | // recupera el identificador del Centro propietario de la tarea |
---|
| 3620 | sprintf(sqlstr,"SELECT idcentro FROM trabajos WHERE idtrabajo=%d",idtrabajo); |
---|
| 3621 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3622 | db.GetErrorErrStr(ErrStr); |
---|
| 3623 | return(false); |
---|
| 3624 | } |
---|
| 3625 | if(tbl.ISEOF()) return(true); |
---|
| 3626 | if(!tbl.Get("idcentro",idcentro)){ // Toma dato |
---|
| 3627 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3628 | return(false); |
---|
| 3629 | } |
---|
| 3630 | // Recupera las tareas que forman parte del trabajo |
---|
| 3631 | sprintf(sqlstr,"SELECT * FROM trabajos_tareas WHERE idtrabajo=%d ORDER by orden",idtrabajo); |
---|
| 3632 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3633 | db.GetErrorErrStr(ErrStr); |
---|
| 3634 | return(false); |
---|
| 3635 | } |
---|
| 3636 | if(tbl.ISEOF()) return(true); |
---|
| 3637 | // Recorre trabajos-tareas |
---|
| 3638 | while(!tbl.ISEOF()){ |
---|
| 3639 | if(!tbl.Get("idtrabajotarea",idtrabajotarea)){ // Toma dato |
---|
| 3640 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3641 | return(false); |
---|
| 3642 | } |
---|
| 3643 | tbTareasidnotificador[cont_tareas]=idtrabajotarea; |
---|
| 3644 | |
---|
| 3645 | if(!tbl.Get("idtarea",idtarea)){ // Toma dato |
---|
| 3646 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3647 | return(false); |
---|
| 3648 | } |
---|
| 3649 | tbTareasidtarea[cont_tareas]=idtarea; |
---|
| 3650 | |
---|
| 3651 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3652 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3653 | return(false); |
---|
| 3654 | } |
---|
| 3655 | |
---|
| 3656 | if(!tbl.Get("ambitskwrk",ambitskwrk)){ // Toma dato |
---|
| 3657 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3658 | return(false); |
---|
| 3659 | } |
---|
| 3660 | sprintf(wambitrabajo,"%s;",ambitskwrk); |
---|
| 3661 | strcat(ambitrabajo,wambitrabajo); |
---|
| 3662 | |
---|
| 3663 | sprintf(wparamtrabajo,"%d;",idtrabajotarea); |
---|
| 3664 | strcat(paramtrabajo,wparamtrabajo); |
---|
| 3665 | |
---|
| 3666 | cont_tareas++; |
---|
| 3667 | tbl.MoveNext(); |
---|
| 3668 | } |
---|
| 3669 | lon=strlen(ambitrabajo); |
---|
| 3670 | ambitrabajo[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3671 | |
---|
| 3672 | lon=strlen(paramtrabajo); |
---|
| 3673 | paramtrabajo[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3674 | |
---|
| 3675 | char _fechahorareg[100]; |
---|
| 3676 | struct tm* st; |
---|
| 3677 | st=TomaHora(); |
---|
| 3678 | sprintf(_fechahorareg,"%d/%d/%d %d:%d:%d",st->tm_year+1900,st->tm_mon+1,st->tm_mday,st->tm_hour,st->tm_min,st->tm_sec); |
---|
| 3679 | |
---|
| 3680 | sprintf(sqlstr,"INSERT INTO acciones (tipoaccion,idtipoaccion,cateaccion,ambito,idambito,ambitskwrk,fechahorareg,estado,resultado,idcentro,parametros,accionid,idnotificador) VALUES (%d,%d,%d,0,0,'%s','%s','%s','%s',%d,'%s',0,0)",EJECUCION_TRABAJO,idtrabajo,PROCESOS,ambitrabajo,_fechahorareg,ACCION_INICIADA,ACCION_SINERRORES,idcentro,paramtrabajo); |
---|
| 3681 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3682 | db.GetErrorErrStr(ErrStr); |
---|
| 3683 | return(false); |
---|
| 3684 | } |
---|
| 3685 | int accionid=0; |
---|
| 3686 | // Toma identificador dela accin |
---|
| 3687 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3688 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3689 | db.GetErrorErrStr(ErrStr); |
---|
| 3690 | return(false); |
---|
| 3691 | } |
---|
| 3692 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3693 | if(!tbl.Get("identificador",accionid)){ |
---|
| 3694 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3695 | return(false); |
---|
| 3696 | } |
---|
| 3697 | } |
---|
| 3698 | int i; |
---|
| 3699 | // Insertar acciones:tareas |
---|
| 3700 | for (i=0;i<cont_tareas;i++){ |
---|
| 3701 | if(!EjecutarTarea(tbTareasidtarea[i],accionid,tbTareasidnotificador[i],idcentro,db,parametros)){ |
---|
| 3702 | return(false); |
---|
| 3703 | } |
---|
| 3704 | } |
---|
| 3705 | return(true); |
---|
| 3706 | } |
---|
| 3707 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3708 | // Funcin: cuestion_nuevoordenador |
---|
[34fc87f] | 3709 | // |
---|
| 3710 | // Descripcin: |
---|
[277d0cd] | 3711 | // Esta funcin da de alta un ordenador y un aula si el sistema estnconfigurado para ello |
---|
[34fc87f] | 3712 | // Parnetros: |
---|
| 3713 | // - db: Objeto base de datos (ya operativo) |
---|
| 3714 | // - tbl: Objeto tabla |
---|
| 3715 | // - ido: identificador del ordenador que se darnde alta automnicamente( se devuelve) |
---|
| 3716 | // - nau: Nombre del grupo donde estnel ordenador( rembo.conf) |
---|
| 3717 | // - nor: Nombre del ordenador dado por rembo(dhcpd) |
---|
| 3718 | // - iph: IP del ordenador |
---|
| 3719 | // - mac: MAC del ordenador |
---|
| 3720 | // - cfg: configuracin |
---|
| 3721 | // - ipd: ip del servidor dhcp |
---|
| 3722 | // - ipr: ip del servidor rembo |
---|
| 3723 | // ________________________________________________________________________________________________________ |
---|
| 3724 | int cuestion_nuevoordenador(Database db,Table tbl,int*ido,char *nau,char *nor,char *iph,char *mac,char*cfg,char*ipd,char*ipr) |
---|
| 3725 | { |
---|
| 3726 | char sqlstr[1000],ErrStr[200]; |
---|
| 3727 | int ida,isd,isr; |
---|
| 3728 | |
---|
| 3729 | // Recupera los datos del aula |
---|
| 3730 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE nombreaula= '%s'",nau); |
---|
| 3731 | |
---|
| 3732 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3733 | db.GetErrorErrStr(ErrStr); |
---|
| 3734 | return(false); |
---|
| 3735 | } |
---|
| 3736 | if(tbl.ISEOF()){ // Si NO existe el aula |
---|
[0d997c6] | 3737 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE nombreaula= '%s'","Default"); |
---|
| 3738 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3739 | db.GetErrorErrStr(ErrStr); |
---|
| 3740 | return(false); |
---|
| 3741 | } |
---|
| 3742 | if(tbl.ISEOF()){ // Inserta el aula por defecto |
---|
| 3743 | sprintf(sqlstr,"INSERT INTO aulas (nombreaula) VALUES ('Default')"); |
---|
| 3744 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3745 | db.GetErrorErrStr(ErrStr); |
---|
| 3746 | return(false); |
---|
| 3747 | } |
---|
| 3748 | ida=0; |
---|
| 3749 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3750 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3751 | db.GetErrorErrStr(ErrStr); |
---|
| 3752 | return(false); |
---|
| 3753 | } |
---|
| 3754 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3755 | if(!tbl.Get("identificador",ida)){ |
---|
| 3756 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3757 | return(false); |
---|
| 3758 | } |
---|
| 3759 | } |
---|
| 3760 | } |
---|
[34fc87f] | 3761 | } |
---|
| 3762 | else{ |
---|
| 3763 | if(!tbl.Get("idaula",ida)){ // Toma dato |
---|
| 3764 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3765 | return(false); |
---|
| 3766 | } |
---|
| 3767 | } |
---|
| 3768 | if(!Toma_idservidorres(db,tbl,ipd,ipr,&isd,&isr)) return(false); |
---|
| 3769 | if(!alta_ordenador(db,tbl,ido,nor,iph,mac,ida,isd,isr)) return(false); // Alta del ordenador |
---|
| 3770 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)){ // Actualiza la configuracin del ordenador |
---|
| 3771 | return(false); |
---|
| 3772 | } |
---|
| 3773 | return(true); |
---|
| 3774 | } |
---|
| 3775 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3776 | // Funcin: alta_ordenador |
---|
[34fc87f] | 3777 | // |
---|
| 3778 | // Descripcin: |
---|
[277d0cd] | 3779 | // Esta funcin da de alta un ordenador |
---|
[34fc87f] | 3780 | // Parnetros: |
---|
| 3781 | // - db: Objeto base de datos (ya operativo) |
---|
| 3782 | // - tbl: Objeto tabla |
---|
| 3783 | // - mac: MAC del ordenador |
---|
| 3784 | // - ida: Identificador del aula |
---|
| 3785 | // - isd: Identificador del servidor dhcp |
---|
| 3786 | // - isr: Identificador del servidor rembo |
---|
| 3787 | // ________________________________________________________________________________________________________ |
---|
| 3788 | int alta_ordenador(Database db,Table tbl,int* ido,char *nor,char *iph,char*mac,int ida,int isd,int isr) |
---|
| 3789 | { |
---|
| 3790 | char sqlstr[1000],ErrStr[200],strmac[20]; |
---|
| 3791 | int idordenador,lon,i,p; |
---|
| 3792 | |
---|
| 3793 | // Prepara mac |
---|
| 3794 | lon=strlen(mac); |
---|
| 3795 | p=0; |
---|
| 3796 | for (i=0;i<lon;i++){ |
---|
| 3797 | if(mac[i]!=' ') // Si no es espacio |
---|
| 3798 | strmac[p++]=mac[i]; |
---|
| 3799 | } |
---|
| 3800 | strmac[p]=(char)NULL; |
---|
| 3801 | |
---|
| 3802 | sprintf(sqlstr,"INSERT INTO ordenadores(nombreordenador,ip,mac,idperfilhard,idservidordhcp,idservidorrembo,idmenu,idaula,grupoid,idconfiguracion) VALUES ('%s','%s','%s',0,%d,%d,0,%d,0,0)",nor,iph,strmac,isd,isr,ida); |
---|
| 3803 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3804 | db.GetErrorErrStr(ErrStr); |
---|
| 3805 | return(false); |
---|
| 3806 | } |
---|
| 3807 | idordenador=0; |
---|
| 3808 | // Toma identificador dela accin |
---|
| 3809 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3810 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3811 | db.GetErrorErrStr(ErrStr); |
---|
| 3812 | return(false); |
---|
| 3813 | } |
---|
| 3814 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3815 | if(!tbl.Get("identificador",idordenador)){ |
---|
| 3816 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3817 | return(false); |
---|
| 3818 | } |
---|
| 3819 | } |
---|
| 3820 | *ido=idordenador; |
---|
| 3821 | return(true); |
---|
| 3822 | } |
---|
| 3823 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3824 | // Funcin: Toma_idservidorres |
---|
[34fc87f] | 3825 | // |
---|
[277d0cd] | 3826 | // Descripcin: |
---|
| 3827 | // Esta funcin devuelve los identificadores de los servidores rembo y dhcp de un determinado ordenador |
---|
[34fc87f] | 3828 | // Parnetros: |
---|
| 3829 | // db: Objeto base de datos (ya operativo) |
---|
| 3830 | // tbl: Objeto tabla |
---|
| 3831 | // ipd: ip del servidor dhcp |
---|
| 3832 | // ipr: ip del servidor rembo |
---|
| 3833 | // isd: identificador del servidor dhcp |
---|
| 3834 | // isr: identificador del servidor rembo |
---|
| 3835 | // ________________________________________________________________________________________________________ |
---|
| 3836 | int Toma_idservidorres(Database db,Table tbl,char*ipd,char*ipr,int*isd,int*isr) |
---|
| 3837 | { |
---|
| 3838 | char sqlstr[1000],ErrStr[200]; |
---|
[51dcdc7] | 3839 | int identificador_dhcp=0; |
---|
| 3840 | int identificador_rembo; |
---|
[34fc87f] | 3841 | |
---|
[51dcdc7] | 3842 | /* Servidor dhcp |
---|
[34fc87f] | 3843 | sprintf(sqlstr,"SELECT idservidordhcp FROM servidoresdhcp where ip='%s'",ipd); |
---|
| 3844 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3845 | db.GetErrorErrStr(ErrStr); |
---|
| 3846 | return(false); |
---|
| 3847 | } |
---|
| 3848 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3849 | if(!tbl.Get("idservidordhcp",identificador_dhcp)){ |
---|
| 3850 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3851 | return(false); |
---|
| 3852 | } |
---|
| 3853 | } |
---|
[51dcdc7] | 3854 | */ |
---|
[34fc87f] | 3855 | // Servidor rembo |
---|
| 3856 | sprintf(sqlstr,"SELECT idservidorrembo FROM servidoresrembo where ip='%s'",ipr); |
---|
| 3857 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3858 | db.GetErrorErrStr(ErrStr); |
---|
| 3859 | return(false); |
---|
| 3860 | } |
---|
| 3861 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3862 | if(!tbl.Get("idservidorrembo",identificador_rembo)){ |
---|
| 3863 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3864 | return(false); |
---|
| 3865 | } |
---|
| 3866 | } |
---|
| 3867 | *isd=identificador_dhcp; |
---|
| 3868 | *isr=identificador_rembo; |
---|
| 3869 | return(true); |
---|
| 3870 | } |
---|
| 3871 | //************************************************************************************************************************************************ |
---|
| 3872 | // PROGRAMA PRINCIPAL ( SERVICIO) |
---|
| 3873 | //*************************************************************************************************************************************************** |
---|
| 3874 | int main (int argc, char *argv[]) |
---|
| 3875 | { |
---|
| 3876 | SOCKET socket_s; // Socket donde escucha el servidor |
---|
| 3877 | SOCKET socket_c; // Socket de los clientes que se conectan |
---|
| 3878 | int i;// Tamao de la estructura de direccionamiento IP del cliente |
---|
| 3879 | socklen_t iAddrSize; |
---|
| 3880 | struct sockaddr_in local,cliente; |
---|
| 3881 | //pthread_t hThread; |
---|
| 3882 | //void *resul |
---|
| 3883 | // Validación de parámetros |
---|
[b25881b] | 3884 | |
---|
[df5bd24] | 3885 | strcpy(szPathFileCfg,"ogAdmServer.cfg"); |
---|
| 3886 | strcpy(szPathFileLog,"ogAdmServer.log"); |
---|
[b25881b] | 3887 | |
---|
[34fc87f] | 3888 | for(i = 1; (i+1) < argc; i+=2){ |
---|
| 3889 | if (argv[i][0] == '-'){ |
---|
| 3890 | switch (tolower(argv[i][1])){ |
---|
| 3891 | case 'f': |
---|
| 3892 | if (argv[i+1]!=NULL) |
---|
[b25881b] | 3893 | strcpy(szPathFileCfg, argv[i+1]); |
---|
[34fc87f] | 3894 | else{ |
---|
| 3895 | RegistraLog("Fallo en los parámetros: Debe especificar el fichero de configuración del servicio",false); |
---|
| 3896 | exit(EXIT_FAILURE); |
---|
| 3897 | } |
---|
| 3898 | break; |
---|
| 3899 | case 'l': |
---|
| 3900 | if (argv[i+1]!=NULL) |
---|
[b25881b] | 3901 | strcpy(szPathFileLog, argv[i+1]); |
---|
[34fc87f] | 3902 | else{ |
---|
| 3903 | RegistraLog("Fallo en los parámetros: Debe especificar el fichero de log para el servicio",false); |
---|
| 3904 | exit(EXIT_FAILURE); |
---|
| 3905 | } |
---|
| 3906 | break; |
---|
| 3907 | default: |
---|
| 3908 | RegistraLog("Fallo de sintaxis en los parámetros: Debe especificar -f nombre_del_fichero_de_configuración_del_servicio",false); |
---|
| 3909 | exit(EXIT_FAILURE); |
---|
| 3910 | break; |
---|
| 3911 | } |
---|
| 3912 | } |
---|
| 3913 | } |
---|
[b25881b] | 3914 | if (szPathFileCfg==NULL){ |
---|
| 3915 | printf ("***Error. No se ha especificado fichero de configuración\n"); |
---|
| 3916 | exit(EXIT_FAILURE); |
---|
| 3917 | } |
---|
| 3918 | if(!TomaConfiguracion(szPathFileCfg)){ // Toma parametros de configuracion |
---|
| 3919 | RegistraLog("El fichero de configuración contiene un error de sintaxis",false); |
---|
| 3920 | exit(EXIT_FAILURE); |
---|
[34fc87f] | 3921 | } |
---|
| 3922 | pthread_mutex_init(&guardia,NULL); // Creación del mutex para control de hebras |
---|
| 3923 | |
---|
| 3924 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 3925 | tbsockets[i].ip[0]='\0'; // Inicializa IP |
---|
| 3926 | tbsockets[i].sock=INVALID_SOCKET; // Inicializa Socket |
---|
| 3927 | } |
---|
| 3928 | RegistraLog("***Inicio de sesion***",false); |
---|
| 3929 | |
---|
| 3930 | socket_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Crea socket |
---|
| 3931 | if (socket_s == SOCKET_ERROR){ |
---|
| 3932 | RegistraLog("***socket() fallo:",true); |
---|
| 3933 | } |
---|
| 3934 | local.sin_addr.s_addr = htonl(INADDR_ANY); // selecciona interface |
---|
| 3935 | local.sin_family = AF_INET; |
---|
| 3936 | local.sin_port = htons(puerto); // Puerto |
---|
| 3937 | |
---|
| 3938 | if (bind(socket_s,(struct sockaddr *)&local, // Enlaza socket |
---|
| 3939 | sizeof(local)) == SOCKET_ERROR){ |
---|
| 3940 | RegistraLog("***bind() fallo:",true); |
---|
| 3941 | } |
---|
| 3942 | |
---|
| 3943 | listen(socket_s,250); // Pone a escuchar al socket |
---|
| 3944 | iAddrSize = sizeof(cliente); |
---|
| 3945 | |
---|
| 3946 | while (true) { // Bucle para escuchar peticiones de clientes |
---|
| 3947 | socket_c = accept(socket_s, (struct sockaddr *)&cliente,&iAddrSize); |
---|
| 3948 | if (socket_c == INVALID_SOCKET){ |
---|
| 3949 | RegistraLog("***accept() fallo:",true); |
---|
| 3950 | break; |
---|
| 3951 | } |
---|
| 3952 | //resul=pthread_create(&hThread,NULL,GestionaConexion,(void*)&socket_c); |
---|
| 3953 | GestionaConexion(&socket_c); |
---|
| 3954 | /*if(resul!=0){2 |
---|
| 3955 | RegistraLog("***Fallo al crear la hebra cliente",false); |
---|
| 3956 | break; |
---|
| 3957 | } |
---|
| 3958 | */ |
---|
| 3959 | //pthread_detach(hThread); |
---|
| 3960 | close(socket_c); // Cierra la conexion con el servidor hidra |
---|
| 3961 | } |
---|
| 3962 | close(socket_s); |
---|
| 3963 | exit(EXIT_SUCCESS); |
---|
| 3964 | } |
---|