[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 |
---|
[536adc4] | 1314 | lon=split_parametros(tbSoftware,sft,ch); |
---|
[5eae07e] | 1315 | |
---|
[b1f0d31] | 1316 | // Incorpora el sistema Operativo de la partición |
---|
| 1317 | sprintf(sqlstr,"SELECT idtiposo,descripcion FROM tiposos WHERE tipopar ='%s'",tfs); |
---|
| 1318 | // Ejecuta consulta |
---|
| 1319 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1320 | db.GetErrorErrStr(ErrStr); |
---|
| 1321 | pthread_mutex_unlock(&guardia); |
---|
| 1322 | return(false); |
---|
| 1323 | } |
---|
| 1324 | if(tbl.ISEOF()){ // Software NO existente |
---|
| 1325 | pthread_mutex_unlock(&guardia); |
---|
| 1326 | return(false); |
---|
| 1327 | } |
---|
| 1328 | else{ |
---|
| 1329 | if(!tbl.Get("idtiposo",auxint)){ |
---|
| 1330 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1331 | pthread_mutex_unlock(&guardia); |
---|
| 1332 | return(false); |
---|
| 1333 | } |
---|
| 1334 | idtiposo=auxint+0; // Bug Mysql |
---|
| 1335 | if(!tbl.Get("descripcion",descripso)){ |
---|
| 1336 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1337 | pthread_mutex_unlock(&guardia); |
---|
| 1338 | return(false); |
---|
| 1339 | } |
---|
| 1340 | tbSoftware[lon++]=descripso; |
---|
| 1341 | } |
---|
[5eae07e] | 1342 | // Trocea las cadenas de parametros de particin |
---|
| 1343 | for (i=0;i<lon;i++){ |
---|
[536adc4] | 1344 | sprintf(sqlstr,"SELECT idsoftware FROM softwares WHERE descripcion ='%s'",tbSoftware[i]); |
---|
[5eae07e] | 1345 | |
---|
| 1346 | // EJecuta consulta |
---|
| 1347 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1348 | db.GetErrorErrStr(ErrStr); |
---|
| 1349 | pthread_mutex_unlock(&guardia); |
---|
| 1350 | return(false); |
---|
| 1351 | } |
---|
| 1352 | if(tbl.ISEOF()){ // Software NO existente |
---|
[b1f0d31] | 1353 | if((lon-i)>1) // No es el último elemento que es el S.O. el idtiposoftware es 2 (Aplicaciones) |
---|
| 1354 | sprintf(sqlstr,"INSERT softwares (idtiposoftware,descripcion,idcentro,grupoid) VALUES(2,'%s',%d,0)",tbSoftware[i],idcentro); |
---|
| 1355 | else // Es el último elemento que es el S.O. el idtiposoftware es 1 (Sistemas operativos) |
---|
| 1356 | sprintf(sqlstr,"INSERT softwares (idtiposoftware,idtiposo,descripcion,idcentro,grupoid) VALUES(1,%d,'%s',%d,0)",idtiposo,tbSoftware[i],idcentro); |
---|
| 1357 | |
---|
[5eae07e] | 1358 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1359 | db.GetErrorErrStr(ErrStr); |
---|
| 1360 | pthread_mutex_unlock(&guardia); |
---|
| 1361 | return(false); |
---|
| 1362 | } |
---|
| 1363 | // Recupera el identificador del software |
---|
| 1364 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1365 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1366 | db.GetErrorErrStr(ErrStr); |
---|
| 1367 | pthread_mutex_unlock(&guardia); |
---|
| 1368 | return(false); |
---|
| 1369 | } |
---|
| 1370 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1371 | if(!tbl.Get("identificador",tbidsoftware[i])){ |
---|
| 1372 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1373 | pthread_mutex_unlock(&guardia); |
---|
| 1374 | return(false); |
---|
| 1375 | } |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | else{ |
---|
| 1379 | if(!tbl.Get("idsoftware",tbidsoftware[i])){ // Toma dato |
---|
| 1380 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1381 | pthread_mutex_unlock(&guardia); |
---|
| 1382 | return(false); |
---|
| 1383 | } |
---|
| 1384 | } // Fin for |
---|
| 1385 | } |
---|
| 1386 | // Comprueba existencia de perfil software y actualización de éste para el ordenador |
---|
[ec01697] | 1387 | if(!CuestionPerfilSoftware(db, tbl,idcentro,ido,tbidsoftware,i,nombreordenador,par)){ |
---|
[5eae07e] | 1388 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1389 | pthread_mutex_unlock(&guardia); |
---|
| 1390 | return(false); |
---|
| 1391 | } |
---|
| 1392 | pthread_mutex_unlock(&guardia); |
---|
| 1393 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1394 | return(true); |
---|
| 1395 | } |
---|
| 1396 | // ________________________________________________________________________________________________________ |
---|
[536adc4] | 1397 | // Funcin: CuestionPerfilSoftware |
---|
[5eae07e] | 1398 | //________________________________________________________________________________________________________/ |
---|
[ec01697] | 1399 | int CuestionPerfilSoftware(Database db, Table tbl,int idcentro,char* ido,int *tbidsoftware,int i,char *nombreordenador,char *particion){ |
---|
[5eae07e] | 1400 | char sqlstr[1000],ErrStr[200]; |
---|
| 1401 | int tbidsoftwareperfil[MAXSOFTWARE]; |
---|
| 1402 | int j=0; |
---|
| 1403 | int idperfilsoft; |
---|
| 1404 | // Busca perfil soft del ordenador |
---|
[ec01697] | 1405 | 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] | 1406 | // EJecuta consulta |
---|
| 1407 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1408 | db.GetErrorErrStr(ErrStr); |
---|
| 1409 | return(false); |
---|
| 1410 | } |
---|
[ec01697] | 1411 | while(!tbl.ISEOF()){ // Recorre software del perfils |
---|
[5eae07e] | 1412 | if(!tbl.Get("idsoftware",tbidsoftwareperfil[j++])){ // Toma dato |
---|
| 1413 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1414 | return(false); |
---|
| 1415 | } |
---|
| 1416 | tbl.MoveNext(); |
---|
| 1417 | } |
---|
| 1418 | // Comprueba si el perfil del ordenador contiene todo el software enviado |
---|
| 1419 | int k,q,sw=false; |
---|
[ec01697] | 1420 | if(i==j){ // Si son el mismo número de componenetes software ... |
---|
| 1421 | for(k=0;k<i;k++){ // Elemento software |
---|
| 1422 | for(q=0;q<j;q++){ |
---|
| 1423 | if(tbidsoftware[k]==tbidsoftwareperfil[q]){ |
---|
| 1424 | sw=true; |
---|
| 1425 | break; |
---|
| 1426 | } |
---|
[5eae07e] | 1427 | } |
---|
[ec01697] | 1428 | if(!sw) break; |
---|
[5eae07e] | 1429 | } |
---|
| 1430 | } |
---|
[ec01697] | 1431 | |
---|
[5eae07e] | 1432 | // La variable sw contiene false si se ha encontrado algún software que no está en el perfil software del ordenador |
---|
| 1433 | if(sw) return(true); // Todo el software está en el perfil actual |
---|
| 1434 | |
---|
| 1435 | // Crea perfil nuevo con todo el software inventariado |
---|
[b1f0d31] | 1436 | sprintf(sqlstr,"INSERT perfilessoft (descripcion,idcentro,grupoid) VALUES('Perfil Software (%s, Part:%s) ',%d,0)",nombreordenador,particion,idcentro); |
---|
[5eae07e] | 1437 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1438 | db.GetErrorErrStr(ErrStr); |
---|
| 1439 | return(false); |
---|
| 1440 | } |
---|
| 1441 | // Recupera el identificador del software |
---|
| 1442 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1443 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1444 | db.GetErrorErrStr(ErrStr); |
---|
| 1445 | return(false); |
---|
| 1446 | } |
---|
| 1447 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1448 | if(!tbl.Get("identificador",idperfilsoft)){ |
---|
| 1449 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1450 | return(false); |
---|
| 1451 | } |
---|
| 1452 | } |
---|
| 1453 | for(k=0;k<i;k++){ // relaciona elementos softwares con el nuevo perfil software |
---|
| 1454 | sprintf(sqlstr,"INSERT perfilessoft_softwares (idperfilsoft,idsoftware) VALUES(%d,%d)",idperfilsoft,tbidsoftware[k]); |
---|
| 1455 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1456 | db.GetErrorErrStr(ErrStr); |
---|
| 1457 | return(false); |
---|
| 1458 | } |
---|
[ec01697] | 1459 | } |
---|
| 1460 | // Busca si existe un perfil software para ese ordenador y esa partición |
---|
| 1461 | sprintf(sqlstr,"SELECT idperfilsoft FROM ordenador_perfilsoft WHERE idordenador =%s AND particion=%s",ido,particion); |
---|
| 1462 | // Ejecuta consulta |
---|
| 1463 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
[5eae07e] | 1464 | db.GetErrorErrStr(ErrStr); |
---|
| 1465 | return(false); |
---|
[ec01697] | 1466 | } |
---|
| 1467 | if(!tbl.ISEOF()){ // existe un perfilsoft que se cambia al nuevo |
---|
| 1468 | sprintf(sqlstr,"UPDATE ordenador_perfilsoft SET idperfilsoft=%d WHERE idordenador=%s AND particion=%s",idperfilsoft,ido,particion); |
---|
| 1469 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1470 | db.GetErrorErrStr(ErrStr); |
---|
| 1471 | return(false); |
---|
| 1472 | } |
---|
| 1473 | } |
---|
| 1474 | else{ |
---|
| 1475 | sprintf(sqlstr,"INSERT INTO ordenador_perfilsoft (idordenador,particion,idperfilsoft) VALUE (%s,%s,%d)",ido,particion,idperfilsoft); |
---|
| 1476 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1477 | db.GetErrorErrStr(ErrStr); |
---|
| 1478 | return(false); |
---|
| 1479 | } |
---|
| 1480 | |
---|
| 1481 | } |
---|
[5eae07e] | 1482 | return(true); |
---|
| 1483 | } |
---|
| 1484 | // ________________________________________________________________________________________________________ |
---|
| 1485 | // Funcin: actualiza_configuracion |
---|
| 1486 | // |
---|
| 1487 | // Descripcin: |
---|
| 1488 | // Esta funcin actualiza la base de datos con la configuracion de sistemas operativos y particiones de un ordenador |
---|
| 1489 | // Parnetros: |
---|
| 1490 | // - db: Objeto base de datos (ya operativo) |
---|
| 1491 | // - tbl: Objeto tabla |
---|
| 1492 | // - cfg: cadena con una configuracin |
---|
| 1493 | // - idcfgo: Identificador de la configuracin actual del ordenador |
---|
| 1494 | // - ipho: Identificador de la configuracin actual de las particiones del ordenador |
---|
| 1495 | // - ipho: Ipe del ordenador |
---|
| 1496 | // ________________________________________________________________________________________________________ |
---|
[34fc87f] | 1497 | int actualiza_configuracion(Database db, Table tbl,char* cfg,int idcfgo,int idprto,char* ipho) |
---|
| 1498 | { |
---|
| 1499 | char sqlstr[1000],ErrStr[200]; |
---|
| 1500 | int idconfiguracion,idparticion,lon; |
---|
| 1501 | char * part; |
---|
| 1502 | |
---|
| 1503 | |
---|
| 1504 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1505 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 1506 | pthread_mutex_lock(&guardia); |
---|
| 1507 | sprintf(sqlstr,"SELECT idconfiguracion FROM configuraciones WHERE configuracion LIKE '%s'",cfg); |
---|
| 1508 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1509 | db.GetErrorErrStr(ErrStr); |
---|
| 1510 | pthread_mutex_unlock(&guardia); |
---|
| 1511 | return(false); |
---|
| 1512 | } |
---|
| 1513 | if(!tbl.ISEOF()){ // Configuracin ya existente |
---|
| 1514 | if(!tbl.Get("idconfiguracion",idconfiguracion)){ // Toma dato |
---|
| 1515 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1516 | pthread_mutex_unlock(&guardia); |
---|
| 1517 | return(false); |
---|
| 1518 | } |
---|
| 1519 | } |
---|
| 1520 | else{ // Nueva configuracin |
---|
| 1521 | sprintf(sqlstr,"INSERT configuraciones (configuracion) VALUES('%s')",cfg); |
---|
| 1522 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1523 | db.GetErrorErrStr(ErrStr); |
---|
| 1524 | pthread_mutex_unlock(&guardia); |
---|
| 1525 | return(false); |
---|
| 1526 | } |
---|
| 1527 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1528 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1529 | db.GetErrorErrStr(ErrStr); |
---|
| 1530 | pthread_mutex_unlock(&guardia); |
---|
| 1531 | return(false); |
---|
| 1532 | } |
---|
| 1533 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1534 | if(!tbl.Get("identificador",idconfiguracion)){ |
---|
| 1535 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1536 | pthread_mutex_unlock(&guardia); |
---|
| 1537 | return(false); |
---|
| 1538 | } |
---|
| 1539 | } |
---|
| 1540 | } |
---|
| 1541 | // Genera cadena de particiones |
---|
| 1542 | lon=strlen(cfg); |
---|
| 1543 | part=(char*)malloc(lon); |
---|
| 1544 | TomaParticiones(cfg,part,lon); |
---|
| 1545 | sprintf(sqlstr,"SELECT idparticion FROM particiones WHERE particion LIKE '%s'",part); |
---|
| 1546 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1547 | db.GetErrorErrStr(ErrStr); |
---|
| 1548 | pthread_mutex_unlock(&guardia); |
---|
| 1549 | return(false); |
---|
| 1550 | } |
---|
| 1551 | if(!tbl.ISEOF()){ // Configuracin ya existente |
---|
| 1552 | if(!tbl.Get("idparticion",idparticion)){ // Toma dato |
---|
| 1553 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1554 | pthread_mutex_unlock(&guardia); |
---|
| 1555 | return(false); |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | else{ // Nueva particion |
---|
| 1559 | sprintf(sqlstr,"INSERT particiones (particion) VALUES('%s')",part); |
---|
| 1560 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 1561 | db.GetErrorErrStr(ErrStr); |
---|
| 1562 | pthread_mutex_unlock(&guardia); |
---|
| 1563 | return(false); |
---|
| 1564 | } |
---|
| 1565 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 1566 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1567 | db.GetErrorErrStr(ErrStr); |
---|
| 1568 | pthread_mutex_unlock(&guardia); |
---|
| 1569 | return(false); |
---|
| 1570 | } |
---|
| 1571 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 1572 | if(!tbl.Get("identificador",idparticion)){ |
---|
| 1573 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1574 | pthread_mutex_unlock(&guardia); |
---|
| 1575 | return(false); |
---|
| 1576 | } |
---|
| 1577 | } |
---|
| 1578 | } |
---|
| 1579 | if(idconfiguracion!=idcfgo || idparticion!=idprto){ // Si el odenador tiene una configuracin distinta ... |
---|
| 1580 | sprintf(sqlstr,"Update ordenadores set idconfiguracion=%d, idparticion=%d WHERE ip='%s'",idconfiguracion,idparticion,ipho); |
---|
| 1581 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 1582 | db.GetErrorErrStr(ErrStr); |
---|
| 1583 | pthread_mutex_unlock(&guardia); |
---|
| 1584 | return(false); |
---|
| 1585 | } |
---|
| 1586 | } |
---|
| 1587 | pthread_mutex_unlock(&guardia); |
---|
| 1588 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1589 | return(true); |
---|
| 1590 | } |
---|
| 1591 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1592 | // Funcin: TomaParticiones |
---|
[34fc87f] | 1593 | // |
---|
| 1594 | // Descripcin: |
---|
[277d0cd] | 1595 | // Esta funcin compone basndose en la cadena de configuracin que devuelve el ordenador, una cadena de particiones con |
---|
[34fc87f] | 1596 | // los valores "n0=PPPP;n1=PPPP..." con las duplas:el nmero de particin y el tipo, separados por coma |
---|
| 1597 | // Parnetros: |
---|
| 1598 | // - cfg: Cadena de configuracin |
---|
| 1599 | // - parts: Cadena devuelta con el formato anterior descrito |
---|
| 1600 | // - lonprt: Longitud mnmima para las cadenas |
---|
| 1601 | // ________________________________________________________________________________________________________ |
---|
| 1602 | void TomaParticiones(char* cfg, char* parts,int lonprt) |
---|
| 1603 | { |
---|
| 1604 | int i; |
---|
| 1605 | int lon=0; |
---|
| 1606 | char *tbParticiones[10]; // Para albergar hasta 10 particiones ( Normalmente Mnimo 8); |
---|
| 1607 | char *tbParticion[8]; // Para albergar hasta 8 parnetros de particin; |
---|
| 1608 | char *tbIgualdad[2]; // Para albergar hasta 8 parnetros de particin; |
---|
| 1609 | char ch[2]; // Carnter delimitador |
---|
| 1610 | char *apun; |
---|
| 1611 | int p; |
---|
| 1612 | // Toma memoria para cada elemento de particin |
---|
| 1613 | for(i=0;i<10;i++) |
---|
| 1614 | tbParticiones[i]=(char*)malloc(lonprt); |
---|
| 1615 | |
---|
| 1616 | // Toma memoria para cada parametro de particin |
---|
| 1617 | for(i=0;i<8;i++) |
---|
| 1618 | tbParticion[i]=(char*)malloc(lonprt); |
---|
| 1619 | |
---|
| 1620 | // Toma memoria para cada igualdad |
---|
| 1621 | for(i=0;i<2;i++) |
---|
| 1622 | tbIgualdad[i]=(char*)malloc(20); |
---|
| 1623 | |
---|
| 1624 | // Trocea la cadena de configuracin |
---|
| 1625 | strcpy(ch,"\t");// caracter delimitador (tabulador) |
---|
| 1626 | lonprt=split_parametros(tbParticiones,cfg,ch); |
---|
| 1627 | // Trocea las cadenas de parametros de particin |
---|
| 1628 | for (p=0;p<lonprt;p++){ |
---|
| 1629 | strcpy(ch,"\n");// caracter delimitador (salto de linea) |
---|
| 1630 | split_parametros(tbParticion,tbParticiones[p],ch); |
---|
| 1631 | strcpy(ch,"=");// caracter delimitador "=" |
---|
| 1632 | split_parametros(tbIgualdad,tbParticion[4],ch); // Nmero de particin |
---|
| 1633 | lon+=sprintf(parts+lon,"%s=",tbIgualdad[1]); |
---|
| 1634 | split_parametros(tbIgualdad,tbParticion[2],ch); // Tipo de particion |
---|
| 1635 | apun=tbIgualdad[1]; |
---|
| 1636 | //if(apun[0]=='H') apun++; // Si es oculta ... |
---|
| 1637 | lon+=sprintf(parts+lon,"%s;",apun); |
---|
| 1638 | } |
---|
| 1639 | lon+=sprintf(parts+lon,"@prt"); |
---|
| 1640 | } |
---|
| 1641 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1642 | // Funcin: ComandosPendientes |
---|
[34fc87f] | 1643 | // |
---|
| 1644 | // Descripcin: |
---|
[277d0cd] | 1645 | // Esta funcin busca en la base de datos,comandos pendientes de ejecutar por un ordenador concreto |
---|
[34fc87f] | 1646 | // Parnetros: |
---|
| 1647 | // - s: Socket del cliente |
---|
| 1648 | // - parametros: Parnetros de la trama recibida |
---|
| 1649 | // ________________________________________________________________________________________________________ |
---|
| 1650 | int ComandosPendientes(SOCKET s,char *parametros) |
---|
| 1651 | { |
---|
| 1652 | char *iph,*ido,*coletilla; |
---|
| 1653 | int ids; |
---|
| 1654 | char pids[20],ipe[16],idord[16]; |
---|
| 1655 | |
---|
| 1656 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1657 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 1658 | strcpy(ipe,iph); |
---|
| 1659 | strcpy(idord,ido); |
---|
| 1660 | |
---|
| 1661 | if(busca_comandos(ipe,idord,parametros,&ids)){ |
---|
| 1662 | Coloca_estado(ipe,CLIENTE_OCUPADO,s); |
---|
| 1663 | //Manda el comando pendiente |
---|
| 1664 | coletilla=corte_iph(parametros); |
---|
| 1665 | coletilla[0]='\0';// Corta la trama en la ip |
---|
| 1666 | sprintf(pids,"ids=%d\r",ids); |
---|
| 1667 | strcat(parametros,pids); // Le ande el identificador de la accion |
---|
| 1668 | return(manda_comando(s,parametros)); |
---|
| 1669 | } |
---|
| 1670 | NoComandosPendientes(s); // Indica al cliente rembo que ya no hay mn comandos pendientes |
---|
| 1671 | return(true); |
---|
| 1672 | } |
---|
| 1673 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1674 | // Funcin: EjecutarItem |
---|
[34fc87f] | 1675 | // |
---|
| 1676 | // Descripcin: |
---|
[277d0cd] | 1677 | // Esta funcin ejecuta un item de un men concreto solicitado por algn cliente rembo |
---|
[34fc87f] | 1678 | // Parnetros: |
---|
| 1679 | // - s: Socket del cliente |
---|
| 1680 | // - parametros: Parnetros de la trama recibida |
---|
| 1681 | // ________________________________________________________________________________________________________ |
---|
| 1682 | int EjecutarItem(SOCKET s,char *parametros) |
---|
| 1683 | { |
---|
| 1684 | char sqlstr[1000],ErrStr[200]; |
---|
| 1685 | Database db; |
---|
| 1686 | Table tbl,tbln; |
---|
| 1687 | int idtipoaccion,lon,cont_comandos=0,i,puertorepo; |
---|
| 1688 | char tipoaccion,*iph,*idt,ipe[16]; |
---|
| 1689 | char *tbComandosparametros[100]; |
---|
| 1690 | |
---|
| 1691 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1692 | idt=toma_parametro("idt",parametros); // Toma idemtificador del item |
---|
| 1693 | strcpy(ipe,iph); |
---|
| 1694 | |
---|
| 1695 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 1696 | db.GetErrorErrStr(ErrStr); |
---|
| 1697 | return(false); |
---|
| 1698 | } |
---|
| 1699 | sprintf(sqlstr,"SELECT acciones_menus.tipoaccion, acciones_menus.idtipoaccion FROM acciones_menus WHERE acciones_menus.idaccionmenu=%s",idt); |
---|
| 1700 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1701 | db.GetErrorErrStr(ErrStr); |
---|
| 1702 | return(false); |
---|
| 1703 | } |
---|
| 1704 | if(tbl.ISEOF()){ |
---|
| 1705 | return(false); // No hay comandos pendientes |
---|
| 1706 | } |
---|
| 1707 | |
---|
| 1708 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma dato |
---|
| 1709 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1710 | return(false); |
---|
| 1711 | } |
---|
| 1712 | |
---|
| 1713 | if(!tbl.Get("idtipoaccion",idtipoaccion)){ // Toma dato |
---|
| 1714 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1715 | return(false); |
---|
| 1716 | } |
---|
| 1717 | |
---|
| 1718 | switch(tipoaccion){ |
---|
| 1719 | case EJECUCION_PROCEDIMIENTO : |
---|
| 1720 | sprintf(sqlstr,"SELECT procedimientos_comandos.parametros FROM procedimientos_comandos WHERE procedimientos_comandos.idprocedimiento=%d",idtipoaccion); |
---|
| 1721 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 1722 | db.GetErrorErrStr(ErrStr); |
---|
| 1723 | return(false); |
---|
| 1724 | } |
---|
| 1725 | if(tbl.ISEOF()) // No existe procedimiento |
---|
| 1726 | return(false); |
---|
| 1727 | |
---|
| 1728 | while(!tbl.ISEOF()){ |
---|
| 1729 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 1730 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1731 | return(false); |
---|
| 1732 | } |
---|
| 1733 | lon=strlen(parametros); |
---|
| 1734 | tbComandosparametros[cont_comandos]=(char*)malloc(lon); |
---|
| 1735 | if(tbComandosparametros[cont_comandos]==NULL) |
---|
| 1736 | return(false); // No hay memoria bastante |
---|
| 1737 | strcpy(tbComandosparametros[cont_comandos++],parametros); |
---|
| 1738 | tbl.MoveNext(); |
---|
| 1739 | } |
---|
| 1740 | strcpy(parametros,tbComandosparametros[0]); |
---|
| 1741 | strcat(parametros,"iph="); |
---|
| 1742 | strcat(parametros,ipe); |
---|
| 1743 | strcat(parametros,"\r"); |
---|
| 1744 | for(i=1;i<cont_comandos;i++){ |
---|
| 1745 | strcat(parametros,"\n"); |
---|
| 1746 | strcat(parametros,tbComandosparametros[i]); |
---|
| 1747 | strcat(parametros,"iph="); |
---|
| 1748 | strcat(parametros,ipe); |
---|
| 1749 | strcat(parametros,"\r"); |
---|
| 1750 | } |
---|
| 1751 | if(TomaIPServidorRembo(ipe,&puertorepo)) |
---|
| 1752 | return(manda_trama_servidorrembo(ipe,parametros,puertorepo)); |
---|
| 1753 | break; |
---|
| 1754 | case EJECUCION_TAREA : |
---|
| 1755 | EjecutarTarea(idtipoaccion,0,0,0,db,parametros); |
---|
| 1756 | break; |
---|
| 1757 | case EJECUCION_TRABAJO : |
---|
| 1758 | EjecutarTrabajo(idtipoaccion,db,parametros); // Es una programacin de un trabajo |
---|
| 1759 | break; |
---|
| 1760 | } |
---|
| 1761 | db.Close(); |
---|
| 1762 | return(true); |
---|
| 1763 | } |
---|
| 1764 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1765 | // Funcin: DisponibilidadComandos |
---|
[34fc87f] | 1766 | // |
---|
| 1767 | // Descripcin: |
---|
[277d0cd] | 1768 | // Esta funcin habilita a un clinte rembo para recibir o no, comandos iteractivos |
---|
[34fc87f] | 1769 | // Parnetros: |
---|
| 1770 | // - s: Socket del cliente |
---|
| 1771 | // - parametros: Parmetros de la trama recibida |
---|
| 1772 | // ________________________________________________________________________________________________________ |
---|
| 1773 | int DisponibilidadComandos(SOCKET s,char *parametros) |
---|
| 1774 | { |
---|
| 1775 | char *iph,*swd; |
---|
| 1776 | int resul=0,i; |
---|
| 1777 | |
---|
| 1778 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1779 | swd=toma_parametro("swd",parametros); // Toma switch de diponibilidad |
---|
| 1780 | |
---|
| 1781 | if(strcmp(swd,"1")==0) // Cliente disponible |
---|
| 1782 | resul=Coloca_estado(iph,CLIENTE_REMBO,s); |
---|
| 1783 | else{ |
---|
| 1784 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 1785 | resul=borra_entrada(i); // Cliente apagado |
---|
| 1786 | } |
---|
| 1787 | return(resul); |
---|
| 1788 | } |
---|
| 1789 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1790 | // Funcin: Coloca_estado |
---|
[34fc87f] | 1791 | // |
---|
| 1792 | // Descripcin: |
---|
[277d0cd] | 1793 | // Esta funcin coloca el estado de un ordenador en la tabla de sockets |
---|
[34fc87f] | 1794 | // Parnetros: |
---|
| 1795 | // - iph: Ip del ordenador |
---|
| 1796 | // - e: Nuevo estado |
---|
| 1797 | // - s: Socket usado por el cliente para comunicarse con el servidor HIDRA |
---|
| 1798 | // ________________________________________________________________________________________________________ |
---|
[dad9f34] | 1799 | int Coloca_estado(char *iph,const char *e,SOCKET s) |
---|
[34fc87f] | 1800 | { |
---|
| 1801 | int i; |
---|
| 1802 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 1803 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 1804 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 1805 | strcpy(tbsockets[i].estado,e); // Cambia el estado |
---|
| 1806 | tbsockets[i].sock=s; // Guarda el socket |
---|
| 1807 | return(true); |
---|
| 1808 | } |
---|
| 1809 | } |
---|
| 1810 | } |
---|
| 1811 | return(false); |
---|
| 1812 | } |
---|
| 1813 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1814 | // Funcin: IgualIP |
---|
[34fc87f] | 1815 | // |
---|
| 1816 | // Descripcin: |
---|
| 1817 | // Comprueba si una cadena con una ipe estnincluidad en otra que contienen varias direcciones ipes separas por punto y coma |
---|
| 1818 | // Parnetros: |
---|
| 1819 | // - cadenaiph: Cadena de IPes |
---|
| 1820 | // - ipcliente: Cadena de la ip a buscar |
---|
| 1821 | // ________________________________________________________________________________________________________ |
---|
| 1822 | BOOLEAN IgualIP(char *cadenaiph,char *ipcliente) |
---|
| 1823 | { |
---|
| 1824 | char *posa,*posb; |
---|
| 1825 | int lon; |
---|
| 1826 | |
---|
| 1827 | posa=strstr(cadenaiph,ipcliente); |
---|
| 1828 | if(posa==NULL) return(FALSE); // No existe la IP en la cadena |
---|
| 1829 | posb=posa; // Iguala direcciones |
---|
| 1830 | while(TRUE){ |
---|
| 1831 | posb++; |
---|
| 1832 | if(*posb==';') break; |
---|
| 1833 | if(*posb=='\0') break; |
---|
| 1834 | if(*posb=='\r') break; |
---|
| 1835 | } |
---|
| 1836 | lon=strlen(ipcliente); |
---|
| 1837 | if((posb-posa)==lon) return(TRUE); // IP encontrada !!!! |
---|
| 1838 | |
---|
| 1839 | return(FALSE); |
---|
| 1840 | } |
---|
| 1841 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1842 | // Funcin: inclusion_srvRMB |
---|
[34fc87f] | 1843 | // |
---|
| 1844 | // Descripcin: |
---|
[277d0cd] | 1845 | // Esta funcin incorpora el socket de un nuevo servidor rembo a la tabla de sockets |
---|
[34fc87f] | 1846 | // Parnetros: |
---|
| 1847 | // - s: Socket del servidor rembo |
---|
| 1848 | // - parametros: Parnetros de la trama recibida |
---|
| 1849 | // ________________________________________________________________________________________________________ |
---|
| 1850 | int inclusion_srvRMB(char *iphsrvrmb,int puertorepo) |
---|
| 1851 | { |
---|
| 1852 | int i,idx; |
---|
| 1853 | |
---|
| 1854 | // Incluyendo al cliente en la tabla de sokets |
---|
| 1855 | if (servidorrembo_existente(iphsrvrmb,&i)){ // Si ya existe la IP ... |
---|
| 1856 | idx=i; |
---|
| 1857 | } |
---|
| 1858 | else{ |
---|
| 1859 | if (hay_huecoservidorrembo(&i)){ // Busca hueco para el nuevo cliente |
---|
| 1860 | idx=i; |
---|
| 1861 | strcpy(tbsocketsSRVRMB[idx].ip,iphsrvrmb);// Copia IP |
---|
| 1862 | tbsocketsSRVRMB[idx].puertorepo=puertorepo; |
---|
| 1863 | } |
---|
| 1864 | else |
---|
| 1865 | return(false); // No hay huecos |
---|
| 1866 | } |
---|
| 1867 | return(true); |
---|
| 1868 | } |
---|
| 1869 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1870 | // Funcin: inclusion_cliWINLNX |
---|
[34fc87f] | 1871 | // |
---|
| 1872 | // Descripcin: |
---|
[277d0cd] | 1873 | // Esta funcin incorpora el socket de un nuevo cliente rembo a la tabla de sockets |
---|
[34fc87f] | 1874 | // Parnetros: |
---|
| 1875 | // - s: Socket del servidor rembo |
---|
| 1876 | // - parametros: Parnetros de la trama recibida |
---|
| 1877 | // ________________________________________________________________________________________________________ |
---|
| 1878 | int inclusion_cliWINLNX(SOCKET s,char *parametros) |
---|
| 1879 | { |
---|
| 1880 | char *iph,*tso; |
---|
| 1881 | int i,idx; |
---|
| 1882 | |
---|
| 1883 | // Toma parnetros |
---|
| 1884 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1885 | tso=toma_parametro("tso",parametros); // Toma ip |
---|
| 1886 | // Incluyendo al cliente en la tabla de sokets |
---|
| 1887 | if (cliente_existente(iph,&i)){ // Si ya existe la IP ... |
---|
| 1888 | idx=i; |
---|
| 1889 | close(tbsockets[idx].sock); |
---|
| 1890 | } |
---|
| 1891 | else{ |
---|
| 1892 | if (hay_hueco(&i)){ // Busca hueco para el nuevo cliente |
---|
| 1893 | idx=i; |
---|
| 1894 | strcpy(tbsockets[idx].ip,iph);// Copia IP |
---|
| 1895 | } |
---|
| 1896 | else |
---|
| 1897 | return(false); // No hay huecos |
---|
| 1898 | } |
---|
| 1899 | tbsockets[idx].sock=s; // Guarda el socket |
---|
| 1900 | strcpy(tbsockets[idx].estado,tso); |
---|
| 1901 | return(true); |
---|
| 1902 | } |
---|
| 1903 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1904 | // Funcin: inclusion_REPO |
---|
[34fc87f] | 1905 | // |
---|
| 1906 | // Descripcin: |
---|
[277d0cd] | 1907 | // Esta funcin incorpora el socket de un nuevo repositorio hidra |
---|
[34fc87f] | 1908 | // ________________________________________________________________________________________________________ |
---|
| 1909 | int inclusion_REPO(SOCKET s,char *parametros) |
---|
| 1910 | { |
---|
| 1911 | char ErrStr[200],sqlstr[1000]; |
---|
| 1912 | Database db; |
---|
| 1913 | Table tbl; |
---|
| 1914 | |
---|
| 1915 | char *iph; |
---|
[df5bd24] | 1916 | char PathHidra[250],PathPXE[250]; // path al directorio base de Hidra |
---|
[34fc87f] | 1917 | int puertorepo,lon; |
---|
| 1918 | |
---|
[73ed2a1] | 1919 | |
---|
[34fc87f] | 1920 | // Toma parnetros |
---|
| 1921 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1922 | |
---|
| 1923 | // Toma las propiedades del ordenador |
---|
| 1924 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 1925 | db.GetErrorErrStr(ErrStr); |
---|
| 1926 | return(false); |
---|
| 1927 | } |
---|
| 1928 | // Recupera los datos del ordenador |
---|
[df5bd24] | 1929 | sprintf(sqlstr,"SELECT puertorepo,pathrembod,pathpxe FROM servidoresrembo WHERE ip = '%s'",iph); |
---|
[73ed2a1] | 1930 | |
---|
[34fc87f] | 1931 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 1932 | db.GetErrorErrStr(ErrStr); |
---|
| 1933 | return(false); |
---|
| 1934 | } |
---|
[73ed2a1] | 1935 | if(tbl.ISEOF()){ // Si No existe registro |
---|
| 1936 | RegistraLog("No existe el Repositorio, se rechaza la petición",false); |
---|
[34fc87f] | 1937 | return(false); |
---|
[73ed2a1] | 1938 | } |
---|
[34fc87f] | 1939 | if(!tbl.Get("puertorepo",puertorepo)){ // Toma dato |
---|
| 1940 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1941 | return(false); |
---|
| 1942 | } |
---|
| 1943 | if(!tbl.Get("pathrembod",PathHidra)){ // Toma dato |
---|
| 1944 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1945 | return(false); |
---|
| 1946 | } |
---|
[df5bd24] | 1947 | if(!tbl.Get("pathpxe",PathPXE)){ // Toma dato |
---|
| 1948 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 1949 | return(false); |
---|
| 1950 | } |
---|
[34fc87f] | 1951 | inclusion_srvRMB(iph,puertorepo); // Actualiza tabla de servidores rembo |
---|
| 1952 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 1953 | if(!trama) |
---|
| 1954 | return(false); |
---|
| 1955 | // Envia la trama |
---|
[73ed2a1] | 1956 | |
---|
[34fc87f] | 1957 | trama->arroba='@'; |
---|
| 1958 | strncpy(trama->identificador,"JMMLCAMDJ",9); |
---|
| 1959 | trama->ejecutor='1'; |
---|
| 1960 | lon=sprintf(trama->parametros,"nfn=RESPUESTA_inclusionREPO\r"); |
---|
| 1961 | lon+=sprintf(trama->parametros+lon,"prp=%d\r",puertorepo); |
---|
| 1962 | lon+=sprintf(trama->parametros+lon,"pth=%s\r",PathHidra); |
---|
[df5bd24] | 1963 | lon+=sprintf(trama->parametros+lon,"ptx=%s\r",PathPXE); |
---|
[34fc87f] | 1964 | lon+=sprintf(trama->parametros+lon,"usu=%s\r",usuario); |
---|
| 1965 | lon+=sprintf(trama->parametros+lon,"pwd=%s\r",pasguor); |
---|
| 1966 | lon+=sprintf(trama->parametros+lon,"dat=%s\r",datasource); |
---|
[73ed2a1] | 1967 | lon+=sprintf(trama->parametros+lon,"cat=%s\r",catalog); |
---|
[34fc87f] | 1968 | return(manda_trama(s,trama)); |
---|
| 1969 | } |
---|
| 1970 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 1971 | // Funcin: Sondeo |
---|
[34fc87f] | 1972 | // |
---|
| 1973 | // Descripcin: |
---|
[277d0cd] | 1974 | // Esta funcin recupera el estado de los ordenadores solicitados |
---|
[34fc87f] | 1975 | // Parnetros: |
---|
| 1976 | // - s: Socket del servidor web que envn el comando |
---|
| 1977 | // - parametros: Parnetros de la trama enviada por nte |
---|
| 1978 | // ________________________________________________________________________________________________________ |
---|
| 1979 | int Sondeo(SOCKET s,char *parametros) |
---|
| 1980 | { |
---|
| 1981 | char *iph; |
---|
| 1982 | char nwparametros[LONGITUD_PARAMETROS]; |
---|
| 1983 | int j; |
---|
| 1984 | |
---|
| 1985 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 1986 | nwparametros[0]='\0'; |
---|
| 1987 | strcat(nwparametros,"tso="); // Compone retorno tso ( sistemas operativos de los clientes ) |
---|
| 1988 | for (j=0;j<MAXIMOS_SOCKETS;j++){ |
---|
| 1989 | if (strncmp(tbsockets[j].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 1990 | if (IgualIP(iph,tbsockets[j].ip)){ // Si existe la IP en la cadena |
---|
| 1991 | strcat( nwparametros, tbsockets[j].ip); // Compone retorno |
---|
| 1992 | strcat( nwparametros,"/"); // "ip=sistemaoperatico;" |
---|
| 1993 | strcat( nwparametros, tbsockets[j].estado); |
---|
| 1994 | strcat( nwparametros,";"); |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | } |
---|
| 1998 | return(manda_comando(s,nwparametros)); |
---|
| 1999 | } |
---|
| 2000 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2001 | // Funcin: Actualizar |
---|
[34fc87f] | 2002 | // |
---|
| 2003 | // Descripcin: |
---|
[277d0cd] | 2004 | // Esta funcin actualiza la vista de ordenadores |
---|
[34fc87f] | 2005 | // Parnetros: |
---|
| 2006 | // - parametros: parametros del comando |
---|
| 2007 | // ________________________________________________________________________________________________________ |
---|
| 2008 | int Actualizar(char *parametros) |
---|
| 2009 | { |
---|
| 2010 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 2011 | if(!trama)return(false); |
---|
| 2012 | int i,estado_cliente,lon; |
---|
| 2013 | char *iph,*rmb; |
---|
| 2014 | |
---|
| 2015 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2016 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2017 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2018 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2019 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2020 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 2021 | if(estado_cliente!=0){ // Cliente NO OCUPADO ... |
---|
| 2022 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_INICIANDO); |
---|
| 2023 | if(estado_cliente!=0){ // Cliente NO INICIANDO ... |
---|
| 2024 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_REMBO); |
---|
| 2025 | if(estado_cliente!=0){ // Cliente windows o linux ... |
---|
| 2026 | lon=sprintf(trama->parametros,"nfn=Actualizar\r"); |
---|
| 2027 | manda_comando(tbsockets[i].sock,(char*)trama->parametros); |
---|
| 2028 | } |
---|
| 2029 | borra_entrada(i); |
---|
| 2030 | } |
---|
| 2031 | } |
---|
| 2032 | } |
---|
| 2033 | } |
---|
| 2034 | } |
---|
| 2035 | int j; |
---|
| 2036 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 2037 | if (strcmp(rmb,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 2038 | FINCADaINTRO(parametros,iph); |
---|
| 2039 | return(manda_trama_servidorrembo(rmb,parametros,tbsocketsSRVRMB[j].puertorepo)); |
---|
| 2040 | } |
---|
| 2041 | } |
---|
| 2042 | return(false); |
---|
| 2043 | } |
---|
| 2044 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2045 | // Funcin: FicheroOperador |
---|
[34fc87f] | 2046 | // |
---|
| 2047 | // Descripcin: |
---|
[277d0cd] | 2048 | // Esta funcin envia al servidor datos de un operador para crear fichero de login |
---|
[34fc87f] | 2049 | // Parnetros: |
---|
| 2050 | // - parametros: parametros del comando |
---|
| 2051 | // ________________________________________________________________________________________________________ |
---|
| 2052 | int FicheroOperador(char *parametros) |
---|
| 2053 | { |
---|
| 2054 | TRAMA trama; |
---|
| 2055 | SOCKET s; |
---|
| 2056 | char *rmb,*amb,*usu,*psw,*ida; |
---|
| 2057 | int resul,lon; |
---|
| 2058 | |
---|
| 2059 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2060 | |
---|
| 2061 | // Abre conexion con el servidor rembo y envia trama |
---|
| 2062 | s=AbreConexion(rmb,puerto+1); |
---|
| 2063 | if(!s){ |
---|
| 2064 | RegistraLog("Fallo al conectar con el servidor rembo para envio de tramas",true); |
---|
| 2065 | return(FALSE); |
---|
| 2066 | } |
---|
| 2067 | |
---|
| 2068 | amb=toma_parametro("amb",parametros); // Toma tipo de operacion |
---|
| 2069 | usu=toma_parametro("usu",parametros); // Toma usuario |
---|
| 2070 | psw=toma_parametro("psw",parametros); // Toma passwrod |
---|
| 2071 | ida=toma_parametro("ida",parametros); // Toma identificador del aula |
---|
| 2072 | |
---|
| 2073 | // Envia la trama |
---|
| 2074 | trama.arroba='@'; |
---|
| 2075 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 2076 | trama.ejecutor='1'; |
---|
| 2077 | lon=sprintf(trama.parametros,"nfn=FicheroOperador\r"); |
---|
| 2078 | lon+=sprintf(trama.parametros+lon,"amb=%s\r",amb); |
---|
| 2079 | lon+=sprintf(trama.parametros+lon,"usu=%s\r",usu); |
---|
| 2080 | lon+=sprintf(trama.parametros+lon,"psw=%s\r",psw); |
---|
| 2081 | lon+=sprintf(trama.parametros+lon,"ida=%s\r",ida); |
---|
| 2082 | resul=(manda_trama(s,&trama)); |
---|
| 2083 | if(!resul) |
---|
| 2084 | RegistraLog("Fallo en el envio de trama al servidor rembo",true); |
---|
| 2085 | return(resul); |
---|
| 2086 | } |
---|
| 2087 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2088 | // Funcin: Conmutar |
---|
[34fc87f] | 2089 | // |
---|
| 2090 | // Descripcin: |
---|
[277d0cd] | 2091 | // Esta funcin conmuta un cliente rembo del modo NO administrado al modo admnistrado |
---|
[34fc87f] | 2092 | // Parnetros: |
---|
| 2093 | // - parametros: parametros del comando |
---|
| 2094 | // ________________________________________________________________________________________________________ |
---|
| 2095 | int Conmutar(char *parametros) |
---|
| 2096 | { |
---|
| 2097 | TRAMA trama; |
---|
| 2098 | SOCKET s; |
---|
| 2099 | int i,estado_cliente,lon,resul; |
---|
| 2100 | char *iph,*rmb; |
---|
| 2101 | |
---|
| 2102 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2103 | rmb=toma_parametro("rmb",parametros); // Toma ipe del servidor rembo |
---|
| 2104 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2105 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2106 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2107 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_OCUPADO); |
---|
| 2108 | if(estado_cliente!=0){ // Cliente NO OCUPADO ... |
---|
| 2109 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_INICIANDO); |
---|
| 2110 | if(estado_cliente!=0){ // Cliente NO INICIANDO ... |
---|
| 2111 | estado_cliente=strcmp(tbsockets[i].estado,CLIENTE_REMBO); |
---|
| 2112 | if(estado_cliente!=0){ // Cliente windows o linux ... |
---|
| 2113 | lon=sprintf(trama.parametros,"nfn=Conmutar\r"); |
---|
| 2114 | manda_comando(tbsockets[i].sock,trama.parametros); |
---|
| 2115 | } |
---|
| 2116 | } |
---|
| 2117 | } |
---|
| 2118 | } |
---|
| 2119 | } |
---|
| 2120 | } |
---|
| 2121 | |
---|
| 2122 | // Abre conexion con el servidor rembo y envia trama |
---|
| 2123 | s=AbreConexion(rmb,puerto+1); |
---|
| 2124 | if(!s){ |
---|
| 2125 | RegistraLog("Fallo al conectar con el servidor rembo para envio de tramas",true); |
---|
| 2126 | resul=FALSE; |
---|
| 2127 | } |
---|
| 2128 | else{ |
---|
| 2129 | // Envia la trama |
---|
| 2130 | trama.arroba='@'; |
---|
| 2131 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 2132 | trama.ejecutor='2'; |
---|
| 2133 | lon=sprintf(trama.parametros,"nfn=Conmutar\r"); |
---|
| 2134 | lon+=sprintf(trama.parametros+lon,"iph=%s\r",iph); |
---|
| 2135 | resul=(manda_trama(s,&trama)); |
---|
| 2136 | if(!resul){ |
---|
| 2137 | RegistraLog("Fallo en el envio de trama al servidor rembo",true); |
---|
| 2138 | } |
---|
| 2139 | } |
---|
| 2140 | return(resul); |
---|
| 2141 | } |
---|
| 2142 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2143 | // Funcin: PurgarTablaSockets |
---|
[34fc87f] | 2144 | // |
---|
| 2145 | // Descripcin: |
---|
| 2146 | // Borra ordenadores de la tabla de sockets |
---|
| 2147 | // Parnetros: |
---|
| 2148 | // - parametros: parametros del comando |
---|
| 2149 | // ________________________________________________________________________________________________________ |
---|
| 2150 | void PurgarTablaSockets(char *parametros) |
---|
| 2151 | { |
---|
| 2152 | int i; |
---|
| 2153 | char *iph; |
---|
| 2154 | |
---|
| 2155 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2156 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 2157 | if (strncmp(tbsockets[i].ip,"\0",1)!=0){ // Si es un cliente activo |
---|
| 2158 | if (IgualIP(iph,tbsockets[i].ip)){ // Si existe la IP en la cadena |
---|
| 2159 | borra_entrada(i); |
---|
| 2160 | } |
---|
| 2161 | } |
---|
| 2162 | } |
---|
| 2163 | } |
---|
| 2164 | // _____________________________________________________________________________________________________________ |
---|
| 2165 | // Función: Arrancar |
---|
| 2166 | // |
---|
| 2167 | // Descripción: |
---|
| 2168 | // Esta función arranca los ordenadores solicitados. PAra ello le envía el comando arrancar al servidor rembo que lo controla y |
---|
| 2169 | // es éste el que le envía la trama de wake-up |
---|
| 2170 | // Parámetros: |
---|
| 2171 | // - mac: Dirección mac del cliente rembo |
---|
| 2172 | // - iph: Dirección ip del cliente rembo |
---|
| 2173 | // - rmb: ip del servidor rembo |
---|
| 2174 | // _____________________________________________________________________________________________________________ |
---|
| 2175 | int Arrancar(char *parametros) |
---|
| 2176 | { |
---|
| 2177 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 2178 | if(!trama)return(false); |
---|
| 2179 | char *iph,*rmb,*mac; |
---|
| 2180 | int j; |
---|
| 2181 | |
---|
| 2182 | rmb=toma_parametro("rmb",parametros); |
---|
| 2183 | mac=toma_parametro("mac",parametros); |
---|
| 2184 | iph=toma_parametro("iph",parametros); |
---|
| 2185 | |
---|
| 2186 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 2187 | if (strcmp(rmb,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 2188 | FINCADaINTRO(parametros,iph); |
---|
| 2189 | return(manda_trama_servidorrembo(rmb,parametros,tbsocketsSRVRMB[j].puertorepo)); |
---|
| 2190 | } |
---|
| 2191 | } |
---|
| 2192 | return(false); |
---|
| 2193 | } |
---|
| 2194 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2195 | // Funcin: RESPUESTA_Arrancar |
---|
[34fc87f] | 2196 | // |
---|
| 2197 | // Descripcin: |
---|
| 2198 | // Responde al comando Apagar |
---|
| 2199 | // Parnetros: |
---|
| 2200 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2201 | // - parametros: parametros del comando |
---|
| 2202 | // ________________________________________________________________________________________________________ |
---|
| 2203 | int RESPUESTA_Arrancar(SOCKET s,char *parametros) |
---|
| 2204 | { |
---|
| 2205 | char ErrStr[200]; |
---|
| 2206 | Database db; |
---|
| 2207 | Table tbl; |
---|
| 2208 | |
---|
| 2209 | char *res,*der,*iph,*ido,*ids; |
---|
| 2210 | |
---|
| 2211 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2212 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2213 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2214 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2215 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2216 | |
---|
| 2217 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2218 | db.GetErrorErrStr(ErrStr); |
---|
| 2219 | return(false); |
---|
| 2220 | } |
---|
| 2221 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2222 | return(false); // Error al registrar notificacion |
---|
| 2223 | } |
---|
| 2224 | db.Close(); |
---|
| 2225 | return(true); |
---|
| 2226 | } |
---|
| 2227 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2228 | // Funcin: RESPUESTA_Apagar |
---|
[34fc87f] | 2229 | // |
---|
| 2230 | // Descripcin: |
---|
| 2231 | // Responde al comando Apagar |
---|
| 2232 | // Parnetros: |
---|
| 2233 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2234 | // - parametros: parametros del comando |
---|
| 2235 | // ________________________________________________________________________________________________________ |
---|
| 2236 | int RESPUESTA_Apagar(SOCKET s,char *parametros) |
---|
| 2237 | { |
---|
| 2238 | char ErrStr[200]; |
---|
| 2239 | Database db; |
---|
| 2240 | Table tbl; |
---|
| 2241 | int i; |
---|
| 2242 | char *res,*der,*iph,*ido,*ids; |
---|
| 2243 | |
---|
| 2244 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2245 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2246 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2247 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2248 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2249 | |
---|
| 2250 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2251 | db.GetErrorErrStr(ErrStr); |
---|
| 2252 | return(false); |
---|
| 2253 | } |
---|
| 2254 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2255 | return(false); // Error al registrar notificacion |
---|
| 2256 | } |
---|
| 2257 | |
---|
| 2258 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2259 | |
---|
| 2260 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2261 | borra_entrada(i); |
---|
| 2262 | db.Close(); |
---|
| 2263 | return(true); |
---|
| 2264 | } |
---|
| 2265 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2266 | // Funcin:RESPUESTA_RemboOffline |
---|
[34fc87f] | 2267 | // |
---|
| 2268 | // Descripcin: |
---|
| 2269 | // Responde al comando Apagar |
---|
| 2270 | // Parnetros: |
---|
| 2271 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2272 | // - parametros: parametros del comando |
---|
| 2273 | // ________________________________________________________________________________________________________ |
---|
| 2274 | int RESPUESTA_RemboOffline(SOCKET s,char *parametros) |
---|
| 2275 | { |
---|
| 2276 | char ErrStr[200]; |
---|
| 2277 | Database db; |
---|
| 2278 | Table tbl; |
---|
| 2279 | int i; |
---|
| 2280 | |
---|
| 2281 | char *res,*der,*iph,*ido,*ids; |
---|
| 2282 | |
---|
| 2283 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2284 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2285 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2286 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2287 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2288 | |
---|
| 2289 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2290 | db.GetErrorErrStr(ErrStr); |
---|
| 2291 | return(false); |
---|
| 2292 | } |
---|
| 2293 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2294 | return(false); // Error al registrar notificacion |
---|
| 2295 | } |
---|
| 2296 | |
---|
| 2297 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2298 | |
---|
| 2299 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2300 | borra_entrada(i); |
---|
| 2301 | db.Close(); |
---|
| 2302 | return(true); |
---|
| 2303 | } |
---|
| 2304 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2305 | // Funcin: RESPUESTA_Reiniciar |
---|
[34fc87f] | 2306 | // |
---|
| 2307 | // Descripcin: |
---|
| 2308 | // Responde al comando Reiniciar |
---|
| 2309 | // Parnetros: |
---|
| 2310 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2311 | // - parametros: parametros del comando |
---|
| 2312 | // ________________________________________________________________________________________________________ |
---|
| 2313 | int RESPUESTA_Reiniciar(SOCKET s,char *parametros) |
---|
| 2314 | { |
---|
| 2315 | int i; |
---|
| 2316 | char ErrStr[200]; |
---|
| 2317 | Database db; |
---|
| 2318 | Table tbl; |
---|
| 2319 | |
---|
| 2320 | char *res,*der,*iph,*ido,*ids; |
---|
| 2321 | |
---|
| 2322 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2323 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2324 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2325 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2326 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2327 | |
---|
| 2328 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2329 | db.GetErrorErrStr(ErrStr); |
---|
| 2330 | return(false); |
---|
| 2331 | } |
---|
| 2332 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2333 | return(false); // Error al registrar notificacion |
---|
| 2334 | } |
---|
| 2335 | if(strcmp(res,ACCION_FALLIDA)==0) return(TRUE); // Error en la ejecucin de la accin en el cliente rembo |
---|
| 2336 | |
---|
| 2337 | if (cliente_existente(iph,&i)) // Si ya existe la IP ... |
---|
| 2338 | borra_entrada(i); |
---|
| 2339 | db.Close(); |
---|
| 2340 | return(true); |
---|
| 2341 | } |
---|
| 2342 | // ________________________________________________________________________________________________________ |
---|
| 2343 | // |
---|
[277d0cd] | 2344 | // Funcin: borra_entrada |
---|
[34fc87f] | 2345 | // |
---|
| 2346 | // Descripcin: |
---|
| 2347 | // Borra la entrada de un ordenador en la tabla de socket |
---|
| 2348 | // Parnetros: |
---|
| 2349 | // - i: Indice dentro de la tabla |
---|
| 2350 | // ________________________________________________________________________________________________________ |
---|
| 2351 | int borra_entrada(int i) |
---|
| 2352 | { |
---|
| 2353 | tbsockets[i].ip[0]=(char)NULL; |
---|
| 2354 | tbsockets[i].estado[0]=(char)NULL; |
---|
| 2355 | if(!tbsockets[i].sock) |
---|
| 2356 | close(tbsockets[i].sock); |
---|
| 2357 | tbsockets[i].sock=INVALID_SOCKET; |
---|
[51dcdc7] | 2358 | //tbsockets[i].ipsrvdhcp[0]=(char)NULL; |
---|
[34fc87f] | 2359 | tbsockets[i].ipsrvrmb[0]=(char)NULL; |
---|
| 2360 | |
---|
| 2361 | return(true); |
---|
| 2362 | } |
---|
| 2363 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2364 | // Funcin: RESPUESTA_ExecShell |
---|
[34fc87f] | 2365 | // |
---|
| 2366 | // Descripcin: |
---|
| 2367 | // Responde al comando Ejecutar script |
---|
| 2368 | // Parnetros: |
---|
| 2369 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2370 | // - parametros: parametros del comando |
---|
| 2371 | // ________________________________________________________________________________________________________ |
---|
| 2372 | int RESPUESTA_ExecShell(SOCKET s,char *parametros) |
---|
| 2373 | { |
---|
| 2374 | char ErrStr[200]; |
---|
| 2375 | Database db; |
---|
| 2376 | Table tbl; |
---|
| 2377 | |
---|
| 2378 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2379 | |
---|
| 2380 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2381 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2382 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2383 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2384 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2385 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2386 | |
---|
| 2387 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2388 | db.GetErrorErrStr(ErrStr); |
---|
| 2389 | return(false); |
---|
| 2390 | } |
---|
| 2391 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2392 | return(false); // Error al registrar notificacion |
---|
| 2393 | } |
---|
| 2394 | |
---|
| 2395 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2396 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) // El ordenador ha cambiado de configuracin |
---|
| 2397 | return(false); |
---|
| 2398 | } |
---|
| 2399 | db.Close(); |
---|
| 2400 | return(true); |
---|
| 2401 | } |
---|
| 2402 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2403 | // Funcin: RespuestaEstandar |
---|
[34fc87f] | 2404 | // |
---|
| 2405 | // Descripcin: |
---|
[277d0cd] | 2406 | // Esta funcin actualiza la base de datos con el resultado de la ejecucin de un comando con seguimiento |
---|
[34fc87f] | 2407 | // Parnetros: |
---|
| 2408 | // - res: resultado de la ejecucin del comando |
---|
| 2409 | // - der: Descripcin del error si hubiese habido |
---|
| 2410 | // - ids: identificador de la accin notificada |
---|
| 2411 | // - ido: Identificador del ordenador que notifica |
---|
| 2412 | // - db: Objeto base de datos (operativo) |
---|
| 2413 | // - tbl: Objeto tabla |
---|
| 2414 | // ________________________________________________________________________________________________________ |
---|
| 2415 | int RespuestaEstandar(char *res,char *der,char *ids,char* ido,Database db,Table tbl) |
---|
| 2416 | { |
---|
| 2417 | char ErrStr[200],sqlstr[1000]; |
---|
| 2418 | char parametros[LONGITUD_PARAMETROS]; |
---|
| 2419 | char fechareg[100]; |
---|
| 2420 | int i,resul; |
---|
| 2421 | int idaccion,accionid,idnotificador; |
---|
| 2422 | char *iph; |
---|
| 2423 | struct tm* st; |
---|
| 2424 | |
---|
| 2425 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2426 | // ACCESO atnico A TRAVEZ DE OBJETO MUTEX a este trozo de cnigo |
---|
| 2427 | pthread_mutex_lock(&guardia); |
---|
| 2428 | |
---|
| 2429 | sprintf(sqlstr,"Select * from acciones WHERE idaccion=%s",ids); |
---|
| 2430 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2431 | db.GetErrorErrStr(ErrStr); |
---|
| 2432 | pthread_mutex_unlock(&guardia); |
---|
| 2433 | return(false); |
---|
| 2434 | } |
---|
| 2435 | if(tbl.ISEOF()){ // No existe registro de acciones |
---|
| 2436 | pthread_mutex_unlock(&guardia); |
---|
| 2437 | return(true); |
---|
| 2438 | } |
---|
| 2439 | if(!tbl.Get("parametros",parametros)){ // Toma parametros de la accin |
---|
| 2440 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 2441 | pthread_mutex_unlock(&guardia); |
---|
| 2442 | return(false); |
---|
| 2443 | } |
---|
| 2444 | char resultado[2]; // comprueba si ya ha fallado la accin |
---|
| 2445 | if(!tbl.Get("resultado",resultado)){ // Toma resultado actual de la accin |
---|
| 2446 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2447 | pthread_mutex_unlock(&guardia); |
---|
| 2448 | return(false); |
---|
| 2449 | } |
---|
| 2450 | if(!tbl.Get("idaccion",idaccion)){ // Toma el identificador de la accin para tener el dato en formato "int" |
---|
| 2451 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2452 | pthread_mutex_unlock(&guardia); |
---|
| 2453 | return(false); |
---|
| 2454 | } |
---|
| 2455 | if(!tbl.Get("accionid",accionid)){ // Toma la accion padre |
---|
| 2456 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2457 | pthread_mutex_unlock(&guardia); |
---|
| 2458 | return(false); |
---|
| 2459 | } |
---|
| 2460 | if(!tbl.Get("idnotificador",idnotificador)){ // Toma el identificador del notificador |
---|
| 2461 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 2462 | pthread_mutex_unlock(&guardia); |
---|
| 2463 | return(false); |
---|
| 2464 | } |
---|
| 2465 | |
---|
| 2466 | st=TomaHora(); |
---|
| 2467 | 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); |
---|
| 2468 | |
---|
| 2469 | // Graba notificacin |
---|
| 2470 | sprintf(sqlstr,"INSERT INTO notificaciones (accionid,idnotificador,fechahorareg,resultado,descrinotificacion) VALUES (%s,%s,'%s','%s','%s')",ids,ido,fechareg,res,der); |
---|
| 2471 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2472 | db.GetErrorErrStr(ErrStr); |
---|
| 2473 | pthread_mutex_unlock(&guardia); |
---|
| 2474 | return(false); |
---|
| 2475 | } |
---|
| 2476 | |
---|
| 2477 | if(strcmp(res,ACCION_FALLIDA)==0 && strcmp(resultado,ACCION_SINERRORES)==0){ // Accion fallida en el cliente rembo |
---|
| 2478 | sprintf(sqlstr,"Update acciones set resultado='%s' WHERE idaccion=%s",ACCION_CONERRORES,ids); |
---|
| 2479 | strcpy(resultado,ACCION_CONERRORES); |
---|
| 2480 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 2481 | db.GetErrorErrStr(ErrStr); |
---|
| 2482 | pthread_mutex_unlock(&guardia); |
---|
| 2483 | return(false); |
---|
| 2484 | } |
---|
| 2485 | } |
---|
| 2486 | // Comprueba si la accin se ejecutncorrectamente para el ambito sumando notificaciones |
---|
| 2487 | INTROaFINCAD(parametros); |
---|
| 2488 | iph=toma_parametro("iph",parametros); // Toma cadenaip |
---|
| 2489 | int tbnumipes=0,totalipes=1,lon; |
---|
| 2490 | |
---|
| 2491 | lon=strlen(iph); |
---|
| 2492 | for (i=0;i<lon;i++){ |
---|
| 2493 | if(iph[i]==';') |
---|
| 2494 | totalipes++; // ip detectada |
---|
| 2495 | } |
---|
| 2496 | |
---|
| 2497 | sprintf(sqlstr,"SELECT COUNT(*) AS tbnumipes FROM notificaciones WHERE accionid=%s",ids); |
---|
| 2498 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2499 | pthread_mutex_unlock(&guardia); |
---|
| 2500 | db.GetErrorErrStr(ErrStr); |
---|
| 2501 | pthread_mutex_unlock(&guardia); |
---|
| 2502 | return(false); |
---|
| 2503 | } |
---|
| 2504 | |
---|
| 2505 | if(!tbl.Get("tbnumipes",tbnumipes)){ // Recupera el numero de ordenadores que ya han notificado |
---|
| 2506 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo |
---|
| 2507 | pthread_mutex_unlock(&guardia); |
---|
| 2508 | return(false); |
---|
| 2509 | } |
---|
| 2510 | if(tbnumipes!=totalipes){ |
---|
| 2511 | pthread_mutex_unlock(&guardia); |
---|
| 2512 | return(true); // No es el ultimo ordenador en notificar |
---|
| 2513 | } |
---|
| 2514 | |
---|
| 2515 | st=TomaHora(); |
---|
| 2516 | 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); |
---|
| 2517 | |
---|
| 2518 | // Actualizacion despues de que todos los ordenadores han notificado |
---|
| 2519 | if(strcmp(resultado,ACCION_SINERRORES)==0){ // Accion finalizada con exito |
---|
| 2520 | sprintf(sqlstr,"Update acciones set estado='%s',resultado='%s',fechahorafin='%s' WHERE idaccion=%s",ACCION_FINALIZADA,ACCION_EXITOSA,fechareg,ids); |
---|
| 2521 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 2522 | db.GetErrorErrStr(ErrStr); |
---|
| 2523 | pthread_mutex_unlock(&guardia); |
---|
| 2524 | return(false); |
---|
| 2525 | } |
---|
| 2526 | } |
---|
| 2527 | if(strcmp(resultado,ACCION_CONERRORES)==0){ // Accion finalizada con errores |
---|
| 2528 | sprintf(sqlstr,"Update acciones set estado='%s',resultado='%s',fechahorafin='%s' WHERE idaccion=%s",ACCION_FINALIZADA,ACCION_FALLIDA,fechareg,ids); |
---|
| 2529 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 2530 | db.GetErrorErrStr(ErrStr); |
---|
| 2531 | pthread_mutex_unlock(&guardia); |
---|
| 2532 | return(false); |
---|
| 2533 | } |
---|
| 2534 | } |
---|
| 2535 | resul=true; |
---|
| 2536 | if(accionid>0){ // Existe accion padre que hay que actualizar |
---|
| 2537 | resul=InsertaNotificaciones(idaccion,idnotificador,accionid,resultado,db); |
---|
| 2538 | if(resul) |
---|
| 2539 | resul=comprueba_resultados(accionid,db); |
---|
| 2540 | } |
---|
| 2541 | pthread_mutex_unlock(&guardia); |
---|
| 2542 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2543 | return(resul); |
---|
| 2544 | } |
---|
| 2545 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2546 | // Funcin: RESPUESTA_CrearPerfilSoftware |
---|
[34fc87f] | 2547 | // |
---|
| 2548 | // Descripcin: |
---|
| 2549 | // Responde al comando Crear Perfil Software |
---|
| 2550 | // Parnetros: |
---|
| 2551 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2552 | // - parametros: parametros del comando |
---|
| 2553 | // ________________________________________________________________________________________________________ |
---|
| 2554 | int RESPUESTA_CrearPerfilSoftware(SOCKET s,char *parametros) |
---|
| 2555 | { |
---|
| 2556 | char ErrStr[200],sqlstr[1000]; |
---|
| 2557 | char *res,*der,*ids,*ifh,*ifs,*iph,*ido; |
---|
| 2558 | Database db; |
---|
| 2559 | Table tbl; |
---|
| 2560 | |
---|
| 2561 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2562 | db.GetErrorErrStr(ErrStr); |
---|
| 2563 | return(false); |
---|
| 2564 | } |
---|
| 2565 | |
---|
| 2566 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2567 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2568 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2569 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2570 | ido=toma_parametro("ido",parametros); // Toma dentificador del ordenador |
---|
| 2571 | ifh=toma_parametro("ifh",parametros); // Toma idperfilhard |
---|
| 2572 | ifs=toma_parametro("ifs",parametros); // Toma idperfilsoft |
---|
| 2573 | |
---|
| 2574 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2575 | return(false); // Error al registrar notificacion |
---|
| 2576 | } |
---|
| 2577 | |
---|
| 2578 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin en el cliente rembo |
---|
| 2579 | db.Close(); |
---|
| 2580 | return(false); |
---|
| 2581 | } |
---|
| 2582 | |
---|
| 2583 | sprintf(sqlstr,"Select * from perfileshard_perfilessoft WHERE idperfilhard=%s AND idperfilsoft=%s",ifh,ifs); |
---|
| 2584 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2585 | db.GetErrorErrStr(ErrStr); |
---|
| 2586 | return(false); |
---|
| 2587 | } |
---|
| 2588 | if(!tbl.ISEOF()){ // Si ya existe el registro ... no hace falta insertarlo |
---|
| 2589 | db.Close(); |
---|
| 2590 | return(false); |
---|
| 2591 | } |
---|
| 2592 | sprintf(sqlstr,"INSERT INTO perfileshard_perfilessoft (idperfilhard,idperfilsoft) VALUES(%s,%s)",ifh,ifs); |
---|
| 2593 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2594 | db.GetErrorErrStr(ErrStr); |
---|
| 2595 | return(false); |
---|
| 2596 | } |
---|
| 2597 | db.Close(); |
---|
| 2598 | return(true); |
---|
| 2599 | } |
---|
| 2600 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2601 | // Funcin: RESPUESTA_CrearSoftwareIncremental |
---|
[34fc87f] | 2602 | // |
---|
| 2603 | // Descripcin: |
---|
[277d0cd] | 2604 | // Esta funcin responde a un comando de creacin de un software incremental. Ademn actualiza la base de datos insertando |
---|
[34fc87f] | 2605 | // en su caso la nueva combinacin de perfil software con incremental. |
---|
| 2606 | // Parnetros: |
---|
| 2607 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2608 | // - parametros: parametros del comando |
---|
| 2609 | // ________________________________________________________________________________________________________ |
---|
| 2610 | int RESPUESTA_CrearSoftwareIncremental(SOCKET s,char *parametros) |
---|
| 2611 | { |
---|
| 2612 | char ErrStr[200],sqlstr[1000]; |
---|
| 2613 | char *res,*der,*ids,*ifh,*ifs,*icr,*iph,*ido; |
---|
| 2614 | int idphardidpsoft; |
---|
| 2615 | Database db; |
---|
| 2616 | Table tbl; |
---|
| 2617 | |
---|
| 2618 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2619 | db.GetErrorErrStr(ErrStr); |
---|
| 2620 | return(false); |
---|
| 2621 | } |
---|
| 2622 | |
---|
| 2623 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2624 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2625 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2626 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2627 | ido=toma_parametro("ido",parametros); // Toma dentificador del ordenador |
---|
| 2628 | ifh=toma_parametro("ifh",parametros); // Toma idperfilhard |
---|
| 2629 | ifs=toma_parametro("ifs",parametros); // Toma idperfilsoft |
---|
| 2630 | icr=toma_parametro("icr",parametros); // Toma idsoftincremental |
---|
| 2631 | |
---|
| 2632 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2633 | return(false); // Error al registrar notificacion |
---|
| 2634 | } |
---|
| 2635 | |
---|
| 2636 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin en el cliente rembo |
---|
| 2637 | db.Close(); |
---|
| 2638 | return(false); |
---|
| 2639 | } |
---|
| 2640 | |
---|
| 2641 | sprintf(sqlstr,"Select idphardidpsoft from perfileshard_perfilessoft WHERE idperfilhard=%s AND idperfilsoft=%s",ifh,ifs); |
---|
| 2642 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2643 | db.GetErrorErrStr(ErrStr); |
---|
| 2644 | return(false); |
---|
| 2645 | } |
---|
| 2646 | |
---|
| 2647 | if(tbl.ISEOF()){ // Si no existe el registro ... |
---|
| 2648 | db.Close(); |
---|
| 2649 | return(false); |
---|
| 2650 | } |
---|
| 2651 | |
---|
| 2652 | if(!tbl.Get("idphardidpsoft",idphardidpsoft)){ // Recupera el identificador de la combinacin de perfiles |
---|
| 2653 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo |
---|
| 2654 | return(false); |
---|
| 2655 | } |
---|
| 2656 | |
---|
| 2657 | sprintf(sqlstr,"Select * from phard_psoft_softincremental WHERE idphardidpsoft=%d AND idsoftincremental=%s",idphardidpsoft,icr); |
---|
| 2658 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2659 | db.GetErrorErrStr(ErrStr); |
---|
| 2660 | return(false); |
---|
| 2661 | } |
---|
| 2662 | |
---|
| 2663 | if(!tbl.ISEOF()){ // Si ya existe el registro ... |
---|
| 2664 | db.Close(); |
---|
| 2665 | return(false); |
---|
| 2666 | } |
---|
| 2667 | |
---|
| 2668 | sprintf(sqlstr,"INSERT INTO phard_psoft_softincremental (idphardidpsoft,idsoftincremental) VALUES(%d,%s)",idphardidpsoft,icr); |
---|
| 2669 | if(!db.Execute(sqlstr,tbl)){ // Error al insertar |
---|
| 2670 | db.GetErrorErrStr(ErrStr); |
---|
| 2671 | return(false); |
---|
| 2672 | } |
---|
| 2673 | db.Close(); |
---|
| 2674 | return(true); |
---|
| 2675 | } |
---|
| 2676 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2677 | // Funcin: RESPUESTA_RestaurarImagen |
---|
[34fc87f] | 2678 | // |
---|
| 2679 | // Descripcin: |
---|
[277d0cd] | 2680 | // Esta funcin responde a un comando de restauracin de una imagen. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2681 | // Parnetros: |
---|
| 2682 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2683 | // - parametros: parametros del comando |
---|
| 2684 | // ________________________________________________________________________________________________________ |
---|
| 2685 | int RESPUESTA_RestaurarImagen(SOCKET s,char *parametros) |
---|
| 2686 | { |
---|
| 2687 | char ErrStr[200],gido[20]; |
---|
| 2688 | char *res,*der,*ids,*iph,*ido,*idi,*par,*cfg; |
---|
| 2689 | Database db; |
---|
| 2690 | Table tbl; |
---|
| 2691 | |
---|
| 2692 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2693 | db.GetErrorErrStr(ErrStr); |
---|
| 2694 | return(false); |
---|
| 2695 | } |
---|
| 2696 | |
---|
| 2697 | INTROaFINCAD(parametros); |
---|
| 2698 | |
---|
| 2699 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2700 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2701 | ids=toma_parametro("ids",parametros); // Toma identificador de la accion |
---|
| 2702 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2703 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2704 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2705 | par=toma_parametro("par",parametros); // particion |
---|
| 2706 | idi=toma_parametro("idi",parametros); // identificador de la imagen |
---|
| 2707 | |
---|
| 2708 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2709 | |
---|
| 2710 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2711 | return(false); // Error al registrar notificacion |
---|
| 2712 | } |
---|
| 2713 | if(strcmp(res,ACCION_FALLIDA)==0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2714 | db.Close(); |
---|
| 2715 | return(false); |
---|
| 2716 | } |
---|
| 2717 | |
---|
| 2718 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2719 | if(!Actualiza_ordenador_imagen(par,idi,gido,db)) return(false); |
---|
| 2720 | db.Close(); |
---|
| 2721 | return(true); |
---|
| 2722 | } |
---|
| 2723 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2724 | // Funcin: Actualiza_ordenador_imagen |
---|
[34fc87f] | 2725 | // |
---|
| 2726 | // Descripcin: |
---|
[277d0cd] | 2727 | // Esta funcin actualiza la tabla ordenador_imagen |
---|
[34fc87f] | 2728 | // Parnetros: |
---|
| 2729 | // - par: particion |
---|
| 2730 | // - idi: identificador de la imagen ( 0 ninguna ) |
---|
| 2731 | // - ido: identificador del ordenador |
---|
| 2732 | // - db: Conexin ADO operativa |
---|
| 2733 | // ________________________________________________________________________________________________________ |
---|
[dad9f34] | 2734 | int Actualiza_ordenador_imagen(char *par,const char *idi,char *ido,Database db) |
---|
[34fc87f] | 2735 | { |
---|
| 2736 | char ErrStr[200],sqlstr[1000]; |
---|
| 2737 | Table tbl; |
---|
| 2738 | int idimagen,idimagenres; |
---|
| 2739 | |
---|
| 2740 | idimagenres=atoi(idi); |
---|
| 2741 | if(idimagenres==0){ // Se ha formateado la particin y se ha borrado la imagen por tanto |
---|
| 2742 | sprintf(sqlstr,"DELETE FROM ordenador_imagen WHERE idordenador=%s AND particion=%s",ido,par); |
---|
| 2743 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2744 | db.GetErrorErrStr(ErrStr); |
---|
| 2745 | return(false); |
---|
| 2746 | } |
---|
| 2747 | return(true); |
---|
| 2748 | } |
---|
| 2749 | |
---|
| 2750 | 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); |
---|
| 2751 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 2752 | db.GetErrorErrStr(ErrStr); |
---|
| 2753 | return(false); |
---|
| 2754 | } |
---|
| 2755 | if(!tbl.ISEOF()){ // Existe registro |
---|
| 2756 | if(!tbl.Get("idimagen",idimagen)){ |
---|
| 2757 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 2758 | return(false); |
---|
| 2759 | } |
---|
| 2760 | else{ |
---|
| 2761 | if (idimagenres!=idimagen){ |
---|
| 2762 | sprintf(sqlstr,"Update ordenador_imagen set idimagen=%s WHERE idordenador=%s AND particion=%s",idi,ido,par); |
---|
| 2763 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 2764 | db.GetErrorErrStr(ErrStr); |
---|
| 2765 | return(false); |
---|
| 2766 | } |
---|
| 2767 | } |
---|
| 2768 | } |
---|
| 2769 | } |
---|
| 2770 | else{ // No existe el registro |
---|
| 2771 | sprintf(sqlstr,"INSERT INTO ordenador_imagen (idordenador,particion,idimagen) VALUES(%s,%s,%s)",ido,par,idi); |
---|
| 2772 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2773 | db.GetErrorErrStr(ErrStr); |
---|
| 2774 | return(false); |
---|
| 2775 | } |
---|
| 2776 | } |
---|
| 2777 | return(true); |
---|
| 2778 | } |
---|
| 2779 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2780 | // Funcin: RESPUESTA_ParticionaryFormatear |
---|
[34fc87f] | 2781 | // |
---|
| 2782 | // Descripcin: |
---|
[277d0cd] | 2783 | // Esta funcin responde a un comando de particionar y formatear. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2784 | // Parnetros: |
---|
| 2785 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2786 | // - parametros: parametros del comando |
---|
| 2787 | // ________________________________________________________________________________________________________ |
---|
| 2788 | int RESPUESTA_ParticionaryFormatear(SOCKET s,char *parametros) |
---|
| 2789 | { |
---|
| 2790 | char sqlstr[1000],ErrStr[200],gido[20]; |
---|
| 2791 | Database db; |
---|
| 2792 | Table tbl; |
---|
| 2793 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2794 | |
---|
| 2795 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2796 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2797 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2798 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2799 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2800 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2801 | |
---|
| 2802 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2803 | |
---|
| 2804 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2805 | db.GetErrorErrStr(ErrStr); |
---|
| 2806 | return(false); |
---|
| 2807 | } |
---|
| 2808 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2809 | return(false); // Error al registrar notificacion |
---|
| 2810 | } |
---|
| 2811 | if(strcmp(res,ACCION_FALLIDA)==0){ |
---|
| 2812 | db.Close(); |
---|
| 2813 | return(true); // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2814 | } |
---|
| 2815 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2816 | |
---|
| 2817 | // Elimina informacin sobre imagenes en este ordenador, al haber sido formateado |
---|
| 2818 | sprintf(sqlstr,"DELETE FROM ordenador_imagen WHERE idordenador=%s",gido); |
---|
| 2819 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 2820 | db.GetErrorErrStr(ErrStr); |
---|
| 2821 | return(false); |
---|
| 2822 | } |
---|
| 2823 | db.Close(); |
---|
| 2824 | return(true); |
---|
| 2825 | } |
---|
| 2826 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2827 | // Funcin: RESPUESTA_Configurar |
---|
[34fc87f] | 2828 | // |
---|
| 2829 | // Descripcin: |
---|
[277d0cd] | 2830 | // Esta funcin responde a un comando de Configurar. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2831 | // Parnetros: |
---|
| 2832 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2833 | // - parametros: parametros del comando |
---|
| 2834 | // ________________________________________________________________________________________________________ |
---|
| 2835 | int RESPUESTA_Configurar(SOCKET s,char *parametros) |
---|
| 2836 | { |
---|
| 2837 | char ErrStr[200],gids[20],gido[20]; |
---|
| 2838 | Database db; |
---|
| 2839 | Table tbl; |
---|
| 2840 | int lon,resul,i; |
---|
| 2841 | char *res,*der,*ids,*iph,*ido,*cfg,*hdc; |
---|
| 2842 | |
---|
| 2843 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2844 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2845 | ids=toma_parametro("ids",parametros); // Toma idperfilsoft |
---|
| 2846 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2847 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2848 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2849 | hdc=toma_parametro("hdc",parametros); // Toma participaciones a formatear |
---|
| 2850 | |
---|
| 2851 | strcpy(gids,ids); // Guarda el identificador de la accin |
---|
| 2852 | strcpy(gido,ido); // Guarda el identificador del ordenador |
---|
| 2853 | |
---|
| 2854 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2855 | db.GetErrorErrStr(ErrStr); |
---|
| 2856 | return(false); |
---|
| 2857 | } |
---|
| 2858 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2859 | return(false); // Error al registrar notificacion |
---|
| 2860 | } |
---|
| 2861 | |
---|
| 2862 | if(strcmp(res,ACCION_FALLIDA)==0){ |
---|
| 2863 | db.Close(); |
---|
| 2864 | return(true); // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2865 | } |
---|
| 2866 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) return(false); // Erro al actualiza la configuracin |
---|
| 2867 | |
---|
| 2868 | lon=strlen(hdc); |
---|
| 2869 | for(i=0;i<lon;i++){ |
---|
| 2870 | if(hdc[i]==';') hdc[i]='\0'; |
---|
| 2871 | } |
---|
| 2872 | for(i=0;i<lon;i++){ |
---|
| 2873 | if(*hdc!='\0'){ |
---|
| 2874 | resul=Actualiza_ordenador_imagen(hdc,"0",gido,db); |
---|
| 2875 | if(!resul){ |
---|
| 2876 | db.Close(); |
---|
| 2877 | return(false); |
---|
| 2878 | } |
---|
| 2879 | } |
---|
| 2880 | hdc++; |
---|
| 2881 | } |
---|
| 2882 | db.Close(); |
---|
| 2883 | return(true); |
---|
| 2884 | } |
---|
| 2885 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2886 | // Funcin: RESPUESTA_TomaConfiguracion |
---|
[34fc87f] | 2887 | // |
---|
| 2888 | // Descripcin: |
---|
[277d0cd] | 2889 | // Esta funcin responde a un comando de Toma Comfiguracin. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2890 | // Parnetros: |
---|
| 2891 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2892 | // - parametros: parametros del comando |
---|
| 2893 | // ________________________________________________________________________________________________________ |
---|
| 2894 | int RESPUESTA_TomaConfiguracion(SOCKET s,char *parametros) |
---|
| 2895 | { |
---|
| 2896 | char ErrStr[200]; |
---|
| 2897 | Database db; |
---|
| 2898 | Table tbl; |
---|
| 2899 | |
---|
| 2900 | char *res,*der,*ids,*iph,*ido,*cfg; |
---|
| 2901 | |
---|
| 2902 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2903 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2904 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2905 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2906 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2907 | cfg=toma_parametro("cfg",parametros); // Toma configuracin |
---|
| 2908 | |
---|
| 2909 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2910 | db.GetErrorErrStr(ErrStr); |
---|
| 2911 | return(false); |
---|
| 2912 | } |
---|
| 2913 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2914 | return(false); // Error al registrar notificacion |
---|
| 2915 | } |
---|
| 2916 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2917 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)) // El ordenador ha cambiado de configuracin |
---|
| 2918 | return(false); |
---|
| 2919 | } |
---|
| 2920 | db.Close(); |
---|
| 2921 | return(true); |
---|
| 2922 | } |
---|
| 2923 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 2924 | // Funcin: RESPUESTA_TomaHardware |
---|
[34fc87f] | 2925 | // |
---|
| 2926 | // Descripcin: |
---|
[277d0cd] | 2927 | // Esta funcin responde a un comando de Toma HArdware. Ademn actualiza la base de datos. |
---|
[34fc87f] | 2928 | // Parnetros: |
---|
| 2929 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2930 | // - parametros: parametros del comando |
---|
| 2931 | // ________________________________________________________________________________________________________ |
---|
| 2932 | int RESPUESTA_TomaHardware(SOCKET s,char *parametros) |
---|
| 2933 | { |
---|
| 2934 | char ErrStr[200]; |
---|
| 2935 | Database db; |
---|
| 2936 | Table tbl; |
---|
| 2937 | |
---|
| 2938 | char *res,*der,*ids,*iph,*ido,*hrd; |
---|
| 2939 | |
---|
| 2940 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2941 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2942 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2943 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2944 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2945 | |
---|
| 2946 | hrd=toma_parametro("hrd",parametros); // Toma configuracin |
---|
| 2947 | |
---|
| 2948 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2949 | db.GetErrorErrStr(ErrStr); |
---|
| 2950 | return(false); |
---|
| 2951 | } |
---|
| 2952 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2953 | return(false); // Error al registrar notificacion |
---|
| 2954 | } |
---|
| 2955 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
| 2956 | if(!actualiza_hardware(db,tbl,hrd,iph,ido)) // El ordenador ha cambiado de configuracin |
---|
| 2957 | return(false); |
---|
| 2958 | } |
---|
| 2959 | db.Close(); |
---|
| 2960 | return(true); |
---|
| 2961 | } |
---|
| 2962 | // ________________________________________________________________________________________________________ |
---|
[5eae07e] | 2963 | // Funcin: RESPUESTA_TomaSoftware |
---|
| 2964 | // |
---|
| 2965 | // Descripcin: |
---|
| 2966 | // Esta funcin responde a un comando de Inventario Software. Además actualiza la base de datos. |
---|
| 2967 | // Parnetros: |
---|
| 2968 | // - s: Socket que el cliente rembo usa para comunicarse con el servidor HIDRA |
---|
| 2969 | // - parametros: parametros del comando |
---|
| 2970 | // ________________________________________________________________________________________________________ |
---|
| 2971 | int RESPUESTA_TomaSoftware(SOCKET s,char *parametros) |
---|
| 2972 | { |
---|
| 2973 | char ErrStr[200]; |
---|
| 2974 | Database db; |
---|
| 2975 | Table tbl; |
---|
| 2976 | |
---|
[b1f0d31] | 2977 | char *res,*der,*ids,*iph,*ido,*sft,*par,*tfs; |
---|
[5eae07e] | 2978 | |
---|
| 2979 | res=toma_parametro("res",parametros); // Toma resultado |
---|
| 2980 | der=toma_parametro("der",parametros); // Toma descripcin del error ( si hubiera habido) |
---|
| 2981 | ids=toma_parametro("ids",parametros); // Toma identificador de la accin |
---|
| 2982 | iph=toma_parametro("iph",parametros); // Toma ip |
---|
| 2983 | ido=toma_parametro("ido",parametros); // Toma identificador del ordenador |
---|
| 2984 | |
---|
[536adc4] | 2985 | sft=toma_parametro("sft",parametros); // Toma software |
---|
| 2986 | par=toma_parametro("par",parametros); // Toma partición |
---|
[b1f0d31] | 2987 | tfs=toma_parametro("tfs",parametros); // Toma tipo partición |
---|
[5eae07e] | 2988 | |
---|
| 2989 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 2990 | db.GetErrorErrStr(ErrStr); |
---|
| 2991 | return(false); |
---|
| 2992 | } |
---|
| 2993 | if(!RespuestaEstandar(res,der,ids,ido,db,tbl)){ |
---|
| 2994 | return(false); // Error al registrar notificacion |
---|
| 2995 | } |
---|
| 2996 | if(strcmp(res,ACCION_FALLIDA)!=0) { // Ha habido algn error en la ejecucin de la accin del cliente rembo |
---|
[b1f0d31] | 2997 | if(!actualiza_software(db,tbl,sft,par,tfs,iph,ido)) // El ordenador ha cambiado de configuracin |
---|
[5eae07e] | 2998 | return(false); |
---|
| 2999 | } |
---|
| 3000 | db.Close(); |
---|
| 3001 | return(true); |
---|
| 3002 | } |
---|
| 3003 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3004 | // Funcin: busca_comandos |
---|
[34fc87f] | 3005 | // |
---|
| 3006 | // Descripcin: |
---|
[277d0cd] | 3007 | // Esta funcin busca en la base de datos,comandos pendientes de ejecutar para el ordenador cocreto |
---|
[34fc87f] | 3008 | // Parnetros: |
---|
| 3009 | // - iph: Direccin IP del ordenador |
---|
| 3010 | // - ido: Identificador del ordenador |
---|
| 3011 | // - parametros: parametros de la accin buscada |
---|
| 3012 | // - ids: Identificador de la accin |
---|
| 3013 | // ________________________________________________________________________________________________________ |
---|
| 3014 | int busca_comandos(char* iph,char *ido,char *parametros,int *ids) |
---|
| 3015 | { |
---|
| 3016 | char sqlstr[1000],ErrStr[200]; |
---|
| 3017 | Database db; |
---|
| 3018 | Table tbl,tbln; |
---|
| 3019 | |
---|
| 3020 | if(!db.Open(usuario,pasguor,datasource,catalog)){ // error de conexion |
---|
| 3021 | db.GetErrorErrStr(ErrStr); |
---|
| 3022 | return(false); |
---|
| 3023 | } |
---|
| 3024 | 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); |
---|
| 3025 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3026 | db.GetErrorErrStr(ErrStr); |
---|
| 3027 | return(false); |
---|
| 3028 | } |
---|
| 3029 | if(tbl.ISEOF()){ |
---|
| 3030 | db.Close(); |
---|
| 3031 | return(false); // No hay comandos pendientes |
---|
| 3032 | } |
---|
| 3033 | |
---|
| 3034 | while(!tbl.ISEOF()){ // Busca entre todas las acciones de diversos ambitos |
---|
| 3035 | |
---|
| 3036 | if(!tbl.Get("parametros",parametros)){ // Toma parametros |
---|
| 3037 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo parametros |
---|
| 3038 | return(false); |
---|
| 3039 | } |
---|
| 3040 | |
---|
| 3041 | if(IgualIP(parametros,iph)){ // Si existe la IP en la cadena |
---|
| 3042 | if(!tbl.Get("idaccion",*ids)){ // Toma identificador de la accin |
---|
| 3043 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3044 | return(false); |
---|
| 3045 | } |
---|
| 3046 | |
---|
| 3047 | // Comprueba que aunque el resultado es ACCION_INICIADA, este ordenador an no ha notificado |
---|
| 3048 | sprintf(sqlstr,"SELECT idnotificador FROM notificaciones WHERE accionid=%d AND idnotificador=%s",*ids,ido); |
---|
| 3049 | if(!db.Execute(sqlstr,tbln)){ // Error al leer |
---|
| 3050 | db.GetErrorErrStr(ErrStr); |
---|
| 3051 | return(false); |
---|
| 3052 | } |
---|
| 3053 | if(tbln.ISEOF()){ |
---|
| 3054 | db.Close(); |
---|
| 3055 | return(true); // No ha notificado este ordenador |
---|
| 3056 | } |
---|
| 3057 | } |
---|
| 3058 | tbl.MoveNext(); |
---|
| 3059 | } |
---|
| 3060 | db.Close(); |
---|
| 3061 | return(false); // No hay mn acciones |
---|
| 3062 | } |
---|
| 3063 | // ________________________________________________________________________________________________________ |
---|
| 3064 | int InsertaNotificaciones(int idaccion,int idnotificador, int accionid, char *resultado,Database db){ |
---|
| 3065 | |
---|
| 3066 | struct tm* st; |
---|
| 3067 | char ErrStr[200],sqlstr[1000]; |
---|
| 3068 | char fechahorareg[100]; |
---|
| 3069 | char descrinotificacion[100]; |
---|
| 3070 | |
---|
| 3071 | |
---|
| 3072 | st=TomaHora(); |
---|
| 3073 | 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); |
---|
| 3074 | |
---|
| 3075 | strcpy(descrinotificacion," "); |
---|
| 3076 | |
---|
| 3077 | if(strcmp(resultado,ACCION_CONERRORES)==0) { |
---|
| 3078 | strcpy(descrinotificacion,"Ha ocurrido algn error en la ejecucin de esta tarea."); |
---|
| 3079 | strcpy(resultado,ACCION_FALLIDA); |
---|
| 3080 | } |
---|
| 3081 | if(strcmp(resultado,ACCION_SINERRORES)==0) |
---|
| 3082 | strcpy(resultado,ACCION_EXITOSA); |
---|
| 3083 | |
---|
| 3084 | sprintf(sqlstr,"INSERT INTO notificaciones (accionid,idnotificador,fechahorareg,resultado,descrinotificacion,idaccion) VALUES (%d,%d,'%s','%s','%s',%d)",accionid,idnotificador,fechahorareg,resultado,descrinotificacion,idaccion); |
---|
| 3085 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3086 | db.GetErrorErrStr(ErrStr); |
---|
| 3087 | return(false); |
---|
| 3088 | } |
---|
| 3089 | return(true); |
---|
| 3090 | } |
---|
| 3091 | // ________________________________________________________________________________________________________ |
---|
| 3092 | int comprueba_resultados(int idaccion,Database db){ |
---|
| 3093 | |
---|
| 3094 | char ErrStr[200],sqlstr[1000]; |
---|
| 3095 | int numfallidas; |
---|
| 3096 | char finalaccion[2]; |
---|
| 3097 | Table tbl; |
---|
| 3098 | |
---|
| 3099 | sprintf(sqlstr,"SELECT COUNT(*) as numfallidas FROM notificaciones WHERE resultado='%s' AND accionid=%d",ACCION_FALLIDA,idaccion); |
---|
| 3100 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3101 | db.GetErrorErrStr(ErrStr); |
---|
| 3102 | return(false); |
---|
| 3103 | } |
---|
| 3104 | if(tbl.ISEOF()) return(false); // No existe registro de acciones |
---|
| 3105 | |
---|
| 3106 | if(!tbl.Get("numfallidas",numfallidas)){ // Toma dato |
---|
| 3107 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3108 | return(false); |
---|
| 3109 | } |
---|
| 3110 | |
---|
| 3111 | if(numfallidas>0) |
---|
| 3112 | strcpy(finalaccion,ACCION_CONERRORES); |
---|
| 3113 | else |
---|
| 3114 | strcpy(finalaccion,ACCION_SINERRORES); |
---|
| 3115 | |
---|
| 3116 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s' WHERE idaccion=%d",finalaccion,idaccion); |
---|
| 3117 | if(!db.Execute(sqlstr,tbl)){ // Error al actualizar |
---|
| 3118 | db.GetErrorErrStr(ErrStr); |
---|
| 3119 | return(false); |
---|
| 3120 | } |
---|
| 3121 | // Comprueba si ha finalizado esta accin e inserta su notificador correspondiente |
---|
| 3122 | return(comprueba_finalizada(idaccion,finalaccion,db)); |
---|
| 3123 | } |
---|
| 3124 | // ________________________________________________________________________________________________________ |
---|
| 3125 | int comprueba_finalizada(int idaccion,char *resultado,Database db){ |
---|
| 3126 | |
---|
| 3127 | char ErrStr[200],sqlstr[1000]; |
---|
| 3128 | int numnotificaciones,tipoaccion,idnotificador; |
---|
| 3129 | char parametros[LONGITUD_PARAMETROS],*cadenanot; |
---|
| 3130 | char fechareg[100]; |
---|
| 3131 | int accionid,cont,i,resul,lon; |
---|
| 3132 | Table tbl; |
---|
| 3133 | struct tm* st; |
---|
| 3134 | |
---|
| 3135 | sprintf(sqlstr,"SELECT COUNT(*) as numnotificaciones FROM notificaciones WHERE accionid=%d",idaccion); |
---|
| 3136 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3137 | db.GetErrorErrStr(ErrStr); |
---|
| 3138 | return(false); |
---|
| 3139 | } |
---|
| 3140 | if(tbl.ISEOF()) return(false); // No existe registro de acciones |
---|
| 3141 | |
---|
| 3142 | if(!tbl.Get("numnotificaciones",numnotificaciones)){ // Toma dato |
---|
| 3143 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3144 | return(false); |
---|
| 3145 | } |
---|
| 3146 | |
---|
| 3147 | sprintf(sqlstr,"SELECT tipoaccion,parametros,idnotificador,accionid FROM acciones WHERE idaccion=%d",idaccion); |
---|
| 3148 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3149 | db.GetErrorErrStr(ErrStr); |
---|
| 3150 | return(false); |
---|
| 3151 | } |
---|
| 3152 | if(tbl.ISEOF()) return(true); // No existe registro de acciones |
---|
| 3153 | |
---|
| 3154 | if(!tbl.Get("tipoaccion",tipoaccion)){ // Toma dato |
---|
| 3155 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3156 | return(false); |
---|
| 3157 | } |
---|
| 3158 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3159 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3160 | return(false); |
---|
| 3161 | } |
---|
| 3162 | if(!tbl.Get("idnotificador",idnotificador)){ // Toma dato |
---|
| 3163 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3164 | return(false); |
---|
| 3165 | } |
---|
| 3166 | if(!tbl.Get("accionid",accionid)){ // Toma dato |
---|
| 3167 | tbl.GetErrorErrStr(ErrStr); // error al recuperar el campo resultado |
---|
| 3168 | return(false); |
---|
| 3169 | } |
---|
| 3170 | |
---|
| 3171 | INTROaFINCAD(parametros); |
---|
| 3172 | switch(tipoaccion){ |
---|
| 3173 | case EJECUCION_COMANDO : |
---|
| 3174 | cadenanot=toma_parametro("iph",parametros); // Toma cadenaip |
---|
| 3175 | break; |
---|
| 3176 | case EJECUCION_TAREA : |
---|
| 3177 | cadenanot=toma_parametro("cmd",parametros); // Toma comandos |
---|
| 3178 | break; |
---|
| 3179 | case EJECUCION_TRABAJO : |
---|
| 3180 | cadenanot=toma_parametro("tsk",parametros); // Toma tareas |
---|
| 3181 | break; |
---|
| 3182 | default: |
---|
| 3183 | return(false); |
---|
| 3184 | } |
---|
| 3185 | cont=1; |
---|
| 3186 | lon=strlen(cadenanot); |
---|
| 3187 | for (i=0;i<lon;i++){ |
---|
| 3188 | if(cadenanot[i]==';') cont++; |
---|
| 3189 | } |
---|
| 3190 | resul=true; |
---|
| 3191 | if(numnotificaciones==cont){ |
---|
| 3192 | st=TomaHora(); |
---|
| 3193 | 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); |
---|
| 3194 | |
---|
| 3195 | if(strcmp(resultado,ACCION_CONERRORES)==0) |
---|
| 3196 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s',estado='%s',fechahorafin='%s' WHERE idaccion=%d",ACCION_FALLIDA,ACCION_FINALIZADA,fechareg,idaccion); |
---|
| 3197 | else |
---|
| 3198 | sprintf(sqlstr,"UPDATE acciones SET resultado='%s',estado='%s',fechahorafin='%s' WHERE idaccion=%d",ACCION_EXITOSA,ACCION_FINALIZADA,fechareg,idaccion); |
---|
| 3199 | |
---|
| 3200 | if(!db.Execute(sqlstr)){ // Error al actualizar |
---|
| 3201 | db.GetErrorErrStr(ErrStr); |
---|
| 3202 | return(false); |
---|
| 3203 | } |
---|
| 3204 | |
---|
| 3205 | if(accionid>0){ // Esto no se ejecutarnsi la tarea tiene un trabajo padre |
---|
| 3206 | resul=InsertaNotificaciones(idaccion,idnotificador,accionid,resultado,db); |
---|
| 3207 | if(resul) |
---|
| 3208 | return(comprueba_resultados(accionid,db)); |
---|
| 3209 | } |
---|
| 3210 | } |
---|
| 3211 | return(resul); |
---|
| 3212 | } |
---|
| 3213 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3214 | // Funcin: EnviaServidoresRembo |
---|
[34fc87f] | 3215 | // |
---|
| 3216 | // Descripcin: |
---|
[277d0cd] | 3217 | // Esta funcin envia una trama a un servidor rembo para que sus clientes ejecuten un comando |
---|
[34fc87f] | 3218 | // Parnetros: |
---|
| 3219 | // - parametros: parametros del comando |
---|
| 3220 | // ________________________________________________________________________________________________________ |
---|
| 3221 | void EnviaServidoresRembo(char * parametros) |
---|
| 3222 | { |
---|
| 3223 | int i,lon; |
---|
| 3224 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3225 | if (tbsocketsSRVRMB[i].swenv==1){ // El switch de envio estna uno hay que enviar al servidor trama ... |
---|
| 3226 | strcat(parametros,"iph="); |
---|
| 3227 | strcat(parametros,tbsocketsSRVRMB[i].ipes); |
---|
| 3228 | lon=strlen(parametros); |
---|
| 3229 | parametros[lon-1]='\r'; // Quita la coma final |
---|
| 3230 | manda_trama_servidorrembo(tbsocketsSRVRMB[i].ip,parametros,tbsocketsSRVRMB[i].puertorepo); |
---|
| 3231 | } |
---|
| 3232 | } |
---|
| 3233 | } |
---|
| 3234 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3235 | // Funcin: manda_comando_servidorrembo |
---|
[34fc87f] | 3236 | // |
---|
| 3237 | // Descripcin: |
---|
[277d0cd] | 3238 | // Esta funcin envia una trama a un servidor rembo para que sus clientes ejecuten un comando |
---|
[34fc87f] | 3239 | // Parnetros: |
---|
| 3240 | // - ip_srvrbm: Direccin IP del servidor REMBO |
---|
| 3241 | // - parametros: parametros del comando |
---|
| 3242 | // ________________________________________________________________________________________________________ |
---|
| 3243 | int manda_trama_servidorrembo(char* ip_srvrbm,char *parametros,int puertorepo) |
---|
| 3244 | { int ret; |
---|
| 3245 | TRAMA *trama=(TRAMA*)malloc(LONGITUD_TRAMA); |
---|
| 3246 | if(!trama) |
---|
| 3247 | return(false); |
---|
| 3248 | strcpy(trama->parametros,parametros); |
---|
| 3249 | SOCKET udpsock; |
---|
| 3250 | udpsock=UDPConnect(IPlocal); |
---|
| 3251 | if (udpsock == INVALID_SOCKET) return(false); |
---|
| 3252 | ret=envia_comandos(udpsock,trama,ip_srvrbm,puertorepo); |
---|
| 3253 | close(udpsock); |
---|
| 3254 | return(ret); |
---|
| 3255 | } |
---|
| 3256 | //_______________________________________________________________________________________________________________ |
---|
| 3257 | // |
---|
| 3258 | // Crea un socket en un puerto determinado para la conversacin UDP con el repositorio |
---|
| 3259 | // |
---|
| 3260 | //_______________________________________________________________________________________________________________ |
---|
| 3261 | SOCKET UDPConnect(char *ips) |
---|
| 3262 | { |
---|
| 3263 | SOCKET socket_c; // Socket para hebras (UDP) |
---|
| 3264 | struct sockaddr_in cliente; |
---|
| 3265 | int puerto; |
---|
| 3266 | |
---|
| 3267 | socket_c = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // Crea socket para UDP |
---|
| 3268 | |
---|
| 3269 | if (socket_c == SOCKET_ERROR) |
---|
| 3270 | return (INVALID_SOCKET); |
---|
| 3271 | |
---|
| 3272 | cliente.sin_addr.s_addr = inet_addr(ips); // selecciona interface |
---|
| 3273 | cliente.sin_family = AF_INET; |
---|
| 3274 | puerto=PUERTOMINUSER; |
---|
| 3275 | while(puerto<PUERTOMAXUSER){ // Busca puerto libre |
---|
| 3276 | cliente.sin_port = htons(puerto); // Puerto asignado |
---|
| 3277 | if (bind(socket_c,(struct sockaddr *)&cliente,sizeof(cliente)) == SOCKET_ERROR) |
---|
| 3278 | puerto++; |
---|
| 3279 | else |
---|
| 3280 | break; |
---|
| 3281 | } |
---|
| 3282 | if(puerto>=PUERTOMAXUSER){ // No hay puertos libres |
---|
| 3283 | return(INVALID_SOCKET); |
---|
| 3284 | } |
---|
| 3285 | return(socket_c); |
---|
| 3286 | } |
---|
| 3287 | //________________________________________________________________________________________________________ |
---|
[277d0cd] | 3288 | // Funcin: envia_comandos |
---|
[34fc87f] | 3289 | // |
---|
| 3290 | // Descripcin: |
---|
| 3291 | // Enva trama UDP |
---|
| 3292 | // ________________________________________________________________________________________________________ |
---|
| 3293 | int envia_comandos(SOCKET s,TRAMA* trama, char* ipsrv,int puerto) |
---|
| 3294 | { |
---|
| 3295 | int ret,lon; |
---|
| 3296 | struct sockaddr_in addrRepo; |
---|
| 3297 | |
---|
| 3298 | trama->arroba='@'; // cabecera de la trama |
---|
| 3299 | strcpy(trama->identificador,"JMMLCAMDJ"); // identificador de la trama |
---|
| 3300 | trama->ejecutor='1'; // ejecutor de la trama 1=el servidor hidra 2=el cliente hidra |
---|
| 3301 | |
---|
| 3302 | addrRepo.sin_family = AF_INET; |
---|
| 3303 | addrRepo.sin_port = htons((short)puerto); |
---|
| 3304 | addrRepo.sin_addr.s_addr = inet_addr(ipsrv); // Direccin IP repositorio |
---|
| 3305 | Encriptar((char*)trama); |
---|
| 3306 | lon=strlen((char*)trama); |
---|
| 3307 | ret = sendto(s,(char *)trama,lon,0,(struct sockaddr *)&addrRepo, sizeof(addrRepo)); |
---|
| 3308 | if (ret == SOCKET_ERROR){ |
---|
| 3309 | RegistraLog("***send() fallo en envío al repositorio",true); |
---|
| 3310 | return(FALSE); |
---|
| 3311 | } |
---|
| 3312 | return true; |
---|
| 3313 | } |
---|
| 3314 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3315 | // Funcin: DesmarcaServidoresRembo |
---|
[34fc87f] | 3316 | // |
---|
| 3317 | // Descripcin: |
---|
[277d0cd] | 3318 | // Esta funcin desmarca la tabla completa de servidores rembo para iniciar la cuesation de envio |
---|
[34fc87f] | 3319 | // ________________________________________________________________________________________________________ |
---|
| 3320 | void DesmarcaServidoresRembo(void) |
---|
| 3321 | { |
---|
| 3322 | int i; |
---|
| 3323 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3324 | tbsocketsSRVRMB[i].swenv=0; |
---|
| 3325 | tbsocketsSRVRMB[i].ipes[0]=(char)NULL; |
---|
| 3326 | } |
---|
| 3327 | } |
---|
| 3328 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3329 | // Funcin: MarcaServidoresRembo |
---|
[34fc87f] | 3330 | // |
---|
| 3331 | // Descripcin: |
---|
[277d0cd] | 3332 | // Esta funcin marca la tabla de servidores Rembo y coloca la ip del cliente en el buffer |
---|
[34fc87f] | 3333 | // Parnetros: |
---|
| 3334 | // - ipsrvrmb: ip del servidor rembo |
---|
| 3335 | // - ipclrmb: ip del cliente rembo |
---|
| 3336 | // ________________________________________________________________________________________________________ |
---|
| 3337 | void MarcaServidoresRembo(char* ipsrvrmb,char*ipclrmb) |
---|
| 3338 | { |
---|
| 3339 | int i,resul; |
---|
| 3340 | for (i=0;i<MAXIMOS_SRVRMB;i++){ |
---|
| 3341 | resul=strcmp(tbsocketsSRVRMB[i].ip,ipsrvrmb); |
---|
| 3342 | if(resul==0) {// servidor rembo encontrado |
---|
| 3343 | strcat(tbsocketsSRVRMB[i].ipes,ipclrmb); |
---|
| 3344 | strcat(tbsocketsSRVRMB[i].ipes,";"); |
---|
| 3345 | tbsocketsSRVRMB[i].swenv=1; |
---|
| 3346 | return; |
---|
| 3347 | } |
---|
| 3348 | } |
---|
| 3349 | } |
---|
| 3350 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3351 | // Funcin: TomaIPServidorRembo |
---|
[34fc87f] | 3352 | // |
---|
| 3353 | // Descripcin: |
---|
[277d0cd] | 3354 | // Esta funcin devuelve true o false dependiendo si el Servidor REMBO estnen la tabla de servidores. |
---|
[34fc87f] | 3355 | // Parnetros: |
---|
| 3356 | // - ip : La ip del servidor a buscar |
---|
| 3357 | // ________________________________________________________________________________________________________ |
---|
| 3358 | BOOLEAN TomaIPServidorRembo(char *ip,int *p) |
---|
| 3359 | { |
---|
| 3360 | int i,j; |
---|
| 3361 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 3362 | if (strcmp(ip,tbsockets[i].ip)==0){ // Si existe la IP ... |
---|
| 3363 | strcpy(ip,tbsockets[i].ipsrvrmb); |
---|
| 3364 | for (j=0;j<MAXIMOS_SRVRMB;j++){ |
---|
| 3365 | if (strcmp(ip,tbsocketsSRVRMB[j].ip)==0){ // Si existe la IP ... |
---|
| 3366 | *p=tbsocketsSRVRMB[j].puertorepo; |
---|
| 3367 | return(TRUE); |
---|
| 3368 | } |
---|
| 3369 | } |
---|
| 3370 | } |
---|
| 3371 | } |
---|
| 3372 | return(FALSE); |
---|
| 3373 | } |
---|
| 3374 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3375 | // Funcin: AbreConexion |
---|
[34fc87f] | 3376 | // |
---|
| 3377 | // Descripcin: |
---|
| 3378 | // Crea un socket y lo conecta a una interface de red. Devuelve el socket |
---|
| 3379 | // Parnetros: |
---|
| 3380 | // - ips : La direccin IP con la que se comunicarnel socket |
---|
| 3381 | // - port : Puerto para la comunicacin |
---|
| 3382 | // ________________________________________________________________________________________________________ |
---|
| 3383 | SOCKET AbreConexion(char *ips,int port) |
---|
| 3384 | { |
---|
| 3385 | struct sockaddr_in server; |
---|
| 3386 | SOCKET s; |
---|
| 3387 | |
---|
| 3388 | // Crea el socket y se intenta conectar |
---|
| 3389 | s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
---|
| 3390 | if (s == SOCKET_ERROR){ |
---|
| 3391 | RegistraLog("Error en la creacin del socket. Modulo: AbreConexion()",true); |
---|
| 3392 | return INVALID_SOCKET; |
---|
| 3393 | } |
---|
| 3394 | |
---|
| 3395 | server.sin_family = AF_INET; |
---|
| 3396 | server.sin_port = htons((short)port); |
---|
| 3397 | server.sin_addr.s_addr = inet_addr(ips); |
---|
| 3398 | |
---|
| 3399 | if (connect(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR){ |
---|
| 3400 | RegistraLog("connect() fallo",true); |
---|
| 3401 | return INVALID_SOCKET; |
---|
| 3402 | } |
---|
| 3403 | return(s); |
---|
| 3404 | |
---|
| 3405 | } |
---|
| 3406 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3407 | // Funcin: EjecutarTarea |
---|
[34fc87f] | 3408 | // |
---|
| 3409 | // Descripcin: |
---|
| 3410 | // Registra una accin (Tarea) y la envn para su ejecucin |
---|
| 3411 | // Parnetros: |
---|
| 3412 | // - idtarea : Identificador de la tarea |
---|
| 3413 | // - accionid: identificador del trabajo padre (si existe) |
---|
| 3414 | // - idnotificador: identificador del trabajo_tarea incluido en trabajo padre (si existe) |
---|
| 3415 | // - idcentro: Centro propietario del trabjo padre (si existe este trabajo) |
---|
| 3416 | // - Database: una conexion ADO operativa |
---|
| 3417 | // - parametros: parnetros de la accin |
---|
| 3418 | // ________________________________________________________________________________________________________ |
---|
| 3419 | int EjecutarTarea(int idtarea,int accionid,int idnotificador,int idcentro,Database db,char* parametros ) |
---|
| 3420 | { |
---|
| 3421 | char sqlstr[1000],ErrStr[200],ambito; |
---|
| 3422 | Table tbl; |
---|
| 3423 | int cont_comandos=0,lon; |
---|
| 3424 | int idcomando,idambito,idtareacomando,accionidcmd; |
---|
| 3425 | char wambitarea[20],ambitarea[4000]; |
---|
| 3426 | char wparamtarea[20],paramtarea[1000],pids[20]; |
---|
| 3427 | int tblon[100],tbComandosidcomando[100],tbComandosambito[100],tbComandosidnotificador[100],tbComandosidambito[100]; |
---|
| 3428 | char *tbComandosparametros[100]; |
---|
| 3429 | |
---|
| 3430 | ambitarea[0]=(char)NULL; // Inicializacin |
---|
| 3431 | strcpy(paramtarea,"cmd="); // Inicializacin |
---|
| 3432 | if(idcentro==0){ |
---|
| 3433 | // recupera el identificador del Centro propietario de la tarea |
---|
| 3434 | sprintf(sqlstr,"SELECT idcentro FROM tareas WHERE idtarea=%d",idtarea); |
---|
| 3435 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3436 | db.GetErrorErrStr(ErrStr); |
---|
| 3437 | return(false); |
---|
| 3438 | } |
---|
| 3439 | if(tbl.ISEOF()) return(true); |
---|
| 3440 | if(!tbl.Get("idcentro",idcentro)){ // Toma dato |
---|
| 3441 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3442 | return(false); |
---|
| 3443 | } |
---|
| 3444 | } |
---|
| 3445 | // Recupera los comandos que forman parte de la tarea |
---|
| 3446 | sprintf(sqlstr,"SELECT * FROM tareas_comandos WHERE idtarea=%d ORDER by orden",idtarea); |
---|
| 3447 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3448 | db.GetErrorErrStr(ErrStr); |
---|
| 3449 | return(false); |
---|
| 3450 | } |
---|
| 3451 | if(tbl.ISEOF()) return(true); |
---|
| 3452 | |
---|
| 3453 | // Recorre tareas-comandos |
---|
| 3454 | while(!tbl.ISEOF()){ |
---|
| 3455 | if(!tbl.Get("idcomando",idcomando)){ // Toma dato |
---|
| 3456 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3457 | return(false); |
---|
| 3458 | } |
---|
| 3459 | tbComandosidcomando[cont_comandos]=idcomando; |
---|
| 3460 | |
---|
| 3461 | if(!tbl.Get("ambito",ambito)){ // Toma dato |
---|
| 3462 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3463 | return(false); |
---|
| 3464 | } |
---|
| 3465 | tbComandosambito[cont_comandos]=ambito; |
---|
| 3466 | |
---|
| 3467 | if(!tbl.Get("idambito",idambito)){ // Toma dato |
---|
| 3468 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3469 | return(false); |
---|
| 3470 | } |
---|
| 3471 | tbComandosidambito[cont_comandos]=idambito; |
---|
| 3472 | |
---|
| 3473 | |
---|
| 3474 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3475 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3476 | return(false); |
---|
| 3477 | } |
---|
| 3478 | |
---|
| 3479 | lon=strlen(parametros); |
---|
| 3480 | tblon[cont_comandos]=lon; |
---|
| 3481 | tbComandosparametros[cont_comandos]=(char*)malloc(lon+20); |
---|
| 3482 | if(tbComandosparametros[cont_comandos]==NULL) |
---|
| 3483 | return(false); // No hay memoria bastante |
---|
| 3484 | |
---|
| 3485 | strcpy(tbComandosparametros[cont_comandos],parametros); |
---|
| 3486 | |
---|
| 3487 | if(!tbl.Get("idtareacomando",idtareacomando)){ // Toma dato |
---|
| 3488 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3489 | return(false); |
---|
| 3490 | } |
---|
| 3491 | tbComandosidnotificador[cont_comandos]=idtareacomando; |
---|
| 3492 | |
---|
| 3493 | sprintf(wambitarea,"%d:%d;",ambito,idambito); |
---|
| 3494 | strcat(ambitarea,wambitarea); |
---|
| 3495 | |
---|
| 3496 | sprintf(wparamtarea,"%d;",idtareacomando); |
---|
| 3497 | strcat(paramtarea,wparamtarea); |
---|
| 3498 | |
---|
| 3499 | cont_comandos++; |
---|
| 3500 | tbl.MoveNext(); |
---|
| 3501 | } |
---|
| 3502 | lon=strlen(ambitarea); |
---|
| 3503 | ambitarea[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3504 | |
---|
| 3505 | lon=strlen(paramtarea); |
---|
| 3506 | paramtarea[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3507 | |
---|
| 3508 | char _fechahorareg[100]; |
---|
| 3509 | struct tm* st; |
---|
| 3510 | st=TomaHora(); |
---|
| 3511 | 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); |
---|
| 3512 | |
---|
| 3513 | 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); |
---|
| 3514 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3515 | db.GetErrorErrStr(ErrStr); |
---|
| 3516 | return(false); |
---|
| 3517 | } |
---|
| 3518 | accionid=0; |
---|
| 3519 | // Toma identificador dela accin |
---|
| 3520 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3521 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3522 | db.GetErrorErrStr(ErrStr); |
---|
| 3523 | return(false); |
---|
| 3524 | } |
---|
| 3525 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3526 | if(!tbl.Get("identificador",accionid)){ |
---|
| 3527 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3528 | return(false); |
---|
| 3529 | } |
---|
| 3530 | } |
---|
| 3531 | int i; |
---|
| 3532 | // Insertar acciones:comandos |
---|
| 3533 | for (i=0;i<cont_comandos;i++){ |
---|
| 3534 | st=TomaHora(); |
---|
| 3535 | 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); |
---|
| 3536 | 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]); |
---|
| 3537 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3538 | db.GetErrorErrStr(ErrStr); |
---|
| 3539 | free(tbComandosparametros[i]); |
---|
| 3540 | return(false); |
---|
| 3541 | } |
---|
| 3542 | // Toma identificador dela accin |
---|
| 3543 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3544 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3545 | db.GetErrorErrStr(ErrStr); |
---|
| 3546 | return(false); |
---|
| 3547 | } |
---|
| 3548 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3549 | if(!tbl.Get("identificador",accionidcmd)){ |
---|
| 3550 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3551 | return(false); |
---|
| 3552 | } |
---|
| 3553 | } |
---|
| 3554 | sprintf(pids,"ids=%d\r",accionidcmd); |
---|
| 3555 | strcat((char*)tbComandosparametros[i],pids); // Le ande el identificador de la accion |
---|
| 3556 | envia_tarea(tbComandosparametros[i]); |
---|
| 3557 | free(tbComandosparametros[i]); |
---|
| 3558 | } |
---|
| 3559 | return(true); |
---|
| 3560 | } |
---|
| 3561 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3562 | // Funcin: manda peticin de inclusion |
---|
[34fc87f] | 3563 | // |
---|
| 3564 | // Descripcin: |
---|
[277d0cd] | 3565 | // Esta funcin envia una tarea por la red. |
---|
[34fc87f] | 3566 | // Parnetros: |
---|
| 3567 | // - parametros: El contenido de la tarea |
---|
| 3568 | // ________________________________________________________________________________________________________ |
---|
| 3569 | void envia_tarea(char* parametros) |
---|
| 3570 | { |
---|
| 3571 | TRAMA trama; |
---|
| 3572 | |
---|
| 3573 | trama.arroba='@'; |
---|
| 3574 | strncpy(trama.identificador,"JMMLCAMDJ",9); |
---|
| 3575 | trama.ejecutor=parametros[0]; |
---|
| 3576 | strcpy(trama.parametros,(char*)¶metros[1]); |
---|
| 3577 | gestiona_comando(INVALID_SOCKET,trama); |
---|
| 3578 | } |
---|
| 3579 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3580 | // Funcin: EjecutarTrabajo |
---|
[34fc87f] | 3581 | // |
---|
| 3582 | // Descripcin: |
---|
| 3583 | // Registra una accin (Trabajo y la envn para su ejecucin |
---|
| 3584 | // Parnetros: |
---|
| 3585 | // - idtrabajo : Identificador del trabajo |
---|
| 3586 | // - Database: una conexion ADO operativa |
---|
| 3587 | // - parametros: parnetros de la accin |
---|
| 3588 | // ________________________________________________________________________________________________________ |
---|
| 3589 | int EjecutarTrabajo(int idtrabajo,Database db,char*parametros ) |
---|
| 3590 | { |
---|
| 3591 | char sqlstr[1000],ErrStr[200]; |
---|
| 3592 | Table tbl; |
---|
| 3593 | int cont_tareas=0,lon; |
---|
| 3594 | int idtarea,idtrabajotarea,idcentro; |
---|
| 3595 | char wambitrabajo[500],ambitrabajo[4000]; |
---|
| 3596 | char wparamtrabajo[20],paramtrabajo[1000]; |
---|
| 3597 | int tbTareasidtarea[100],tbTareasidnotificador[100]; |
---|
| 3598 | char ambitskwrk[500]; |
---|
| 3599 | |
---|
| 3600 | ambitrabajo[0]=(char)NULL; // Inicializacin |
---|
| 3601 | strcpy(paramtrabajo,"tsk="); // Inicializacin |
---|
| 3602 | |
---|
| 3603 | // recupera el identificador del Centro propietario de la tarea |
---|
| 3604 | sprintf(sqlstr,"SELECT idcentro FROM trabajos WHERE idtrabajo=%d",idtrabajo); |
---|
| 3605 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3606 | db.GetErrorErrStr(ErrStr); |
---|
| 3607 | return(false); |
---|
| 3608 | } |
---|
| 3609 | if(tbl.ISEOF()) return(true); |
---|
| 3610 | if(!tbl.Get("idcentro",idcentro)){ // Toma dato |
---|
| 3611 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3612 | return(false); |
---|
| 3613 | } |
---|
| 3614 | // Recupera las tareas que forman parte del trabajo |
---|
| 3615 | sprintf(sqlstr,"SELECT * FROM trabajos_tareas WHERE idtrabajo=%d ORDER by orden",idtrabajo); |
---|
| 3616 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3617 | db.GetErrorErrStr(ErrStr); |
---|
| 3618 | return(false); |
---|
| 3619 | } |
---|
| 3620 | if(tbl.ISEOF()) return(true); |
---|
| 3621 | // Recorre trabajos-tareas |
---|
| 3622 | while(!tbl.ISEOF()){ |
---|
| 3623 | if(!tbl.Get("idtrabajotarea",idtrabajotarea)){ // Toma dato |
---|
| 3624 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3625 | return(false); |
---|
| 3626 | } |
---|
| 3627 | tbTareasidnotificador[cont_tareas]=idtrabajotarea; |
---|
| 3628 | |
---|
| 3629 | if(!tbl.Get("idtarea",idtarea)){ // Toma dato |
---|
| 3630 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3631 | return(false); |
---|
| 3632 | } |
---|
| 3633 | tbTareasidtarea[cont_tareas]=idtarea; |
---|
| 3634 | |
---|
| 3635 | if(!tbl.Get("parametros",parametros)){ // Toma dato |
---|
| 3636 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3637 | return(false); |
---|
| 3638 | } |
---|
| 3639 | |
---|
| 3640 | if(!tbl.Get("ambitskwrk",ambitskwrk)){ // Toma dato |
---|
| 3641 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3642 | return(false); |
---|
| 3643 | } |
---|
| 3644 | sprintf(wambitrabajo,"%s;",ambitskwrk); |
---|
| 3645 | strcat(ambitrabajo,wambitrabajo); |
---|
| 3646 | |
---|
| 3647 | sprintf(wparamtrabajo,"%d;",idtrabajotarea); |
---|
| 3648 | strcat(paramtrabajo,wparamtrabajo); |
---|
| 3649 | |
---|
| 3650 | cont_tareas++; |
---|
| 3651 | tbl.MoveNext(); |
---|
| 3652 | } |
---|
| 3653 | lon=strlen(ambitrabajo); |
---|
| 3654 | ambitrabajo[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3655 | |
---|
| 3656 | lon=strlen(paramtrabajo); |
---|
| 3657 | paramtrabajo[lon-1]=(char)NULL; // Quita la coma final |
---|
| 3658 | |
---|
| 3659 | char _fechahorareg[100]; |
---|
| 3660 | struct tm* st; |
---|
| 3661 | st=TomaHora(); |
---|
| 3662 | 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); |
---|
| 3663 | |
---|
| 3664 | 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); |
---|
| 3665 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3666 | db.GetErrorErrStr(ErrStr); |
---|
| 3667 | return(false); |
---|
| 3668 | } |
---|
| 3669 | int accionid=0; |
---|
| 3670 | // Toma identificador dela accin |
---|
| 3671 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3672 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3673 | db.GetErrorErrStr(ErrStr); |
---|
| 3674 | return(false); |
---|
| 3675 | } |
---|
| 3676 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3677 | if(!tbl.Get("identificador",accionid)){ |
---|
| 3678 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3679 | return(false); |
---|
| 3680 | } |
---|
| 3681 | } |
---|
| 3682 | int i; |
---|
| 3683 | // Insertar acciones:tareas |
---|
| 3684 | for (i=0;i<cont_tareas;i++){ |
---|
| 3685 | if(!EjecutarTarea(tbTareasidtarea[i],accionid,tbTareasidnotificador[i],idcentro,db,parametros)){ |
---|
| 3686 | return(false); |
---|
| 3687 | } |
---|
| 3688 | } |
---|
| 3689 | return(true); |
---|
| 3690 | } |
---|
| 3691 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3692 | // Funcin: cuestion_nuevoordenador |
---|
[34fc87f] | 3693 | // |
---|
| 3694 | // Descripcin: |
---|
[277d0cd] | 3695 | // Esta funcin da de alta un ordenador y un aula si el sistema estnconfigurado para ello |
---|
[34fc87f] | 3696 | // Parnetros: |
---|
| 3697 | // - db: Objeto base de datos (ya operativo) |
---|
| 3698 | // - tbl: Objeto tabla |
---|
| 3699 | // - ido: identificador del ordenador que se darnde alta automnicamente( se devuelve) |
---|
| 3700 | // - nau: Nombre del grupo donde estnel ordenador( rembo.conf) |
---|
| 3701 | // - nor: Nombre del ordenador dado por rembo(dhcpd) |
---|
| 3702 | // - iph: IP del ordenador |
---|
| 3703 | // - mac: MAC del ordenador |
---|
| 3704 | // - cfg: configuracin |
---|
| 3705 | // - ipd: ip del servidor dhcp |
---|
| 3706 | // - ipr: ip del servidor rembo |
---|
| 3707 | // ________________________________________________________________________________________________________ |
---|
| 3708 | int cuestion_nuevoordenador(Database db,Table tbl,int*ido,char *nau,char *nor,char *iph,char *mac,char*cfg,char*ipd,char*ipr) |
---|
| 3709 | { |
---|
| 3710 | char sqlstr[1000],ErrStr[200]; |
---|
| 3711 | int ida,isd,isr; |
---|
| 3712 | |
---|
| 3713 | // Recupera los datos del aula |
---|
| 3714 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE nombreaula= '%s'",nau); |
---|
| 3715 | |
---|
| 3716 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3717 | db.GetErrorErrStr(ErrStr); |
---|
| 3718 | return(false); |
---|
| 3719 | } |
---|
| 3720 | if(tbl.ISEOF()){ // Si NO existe el aula |
---|
[0d997c6] | 3721 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE nombreaula= '%s'","Default"); |
---|
| 3722 | if(!db.Execute(sqlstr,tbl)){ // Error al consultar |
---|
| 3723 | db.GetErrorErrStr(ErrStr); |
---|
| 3724 | return(false); |
---|
| 3725 | } |
---|
| 3726 | if(tbl.ISEOF()){ // Inserta el aula por defecto |
---|
| 3727 | sprintf(sqlstr,"INSERT INTO aulas (nombreaula) VALUES ('Default')"); |
---|
| 3728 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3729 | db.GetErrorErrStr(ErrStr); |
---|
| 3730 | return(false); |
---|
| 3731 | } |
---|
| 3732 | ida=0; |
---|
| 3733 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3734 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3735 | db.GetErrorErrStr(ErrStr); |
---|
| 3736 | return(false); |
---|
| 3737 | } |
---|
| 3738 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3739 | if(!tbl.Get("identificador",ida)){ |
---|
| 3740 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3741 | return(false); |
---|
| 3742 | } |
---|
| 3743 | } |
---|
| 3744 | } |
---|
[34fc87f] | 3745 | } |
---|
| 3746 | else{ |
---|
| 3747 | if(!tbl.Get("idaula",ida)){ // Toma dato |
---|
| 3748 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3749 | return(false); |
---|
| 3750 | } |
---|
| 3751 | } |
---|
| 3752 | if(!Toma_idservidorres(db,tbl,ipd,ipr,&isd,&isr)) return(false); |
---|
| 3753 | if(!alta_ordenador(db,tbl,ido,nor,iph,mac,ida,isd,isr)) return(false); // Alta del ordenador |
---|
| 3754 | if(!actualiza_configuracion(db,tbl,cfg,0,0,iph)){ // Actualiza la configuracin del ordenador |
---|
| 3755 | return(false); |
---|
| 3756 | } |
---|
| 3757 | return(true); |
---|
| 3758 | } |
---|
| 3759 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3760 | // Funcin: alta_ordenador |
---|
[34fc87f] | 3761 | // |
---|
| 3762 | // Descripcin: |
---|
[277d0cd] | 3763 | // Esta funcin da de alta un ordenador |
---|
[34fc87f] | 3764 | // Parnetros: |
---|
| 3765 | // - db: Objeto base de datos (ya operativo) |
---|
| 3766 | // - tbl: Objeto tabla |
---|
| 3767 | // - mac: MAC del ordenador |
---|
| 3768 | // - ida: Identificador del aula |
---|
| 3769 | // - isd: Identificador del servidor dhcp |
---|
| 3770 | // - isr: Identificador del servidor rembo |
---|
| 3771 | // ________________________________________________________________________________________________________ |
---|
| 3772 | int alta_ordenador(Database db,Table tbl,int* ido,char *nor,char *iph,char*mac,int ida,int isd,int isr) |
---|
| 3773 | { |
---|
| 3774 | char sqlstr[1000],ErrStr[200],strmac[20]; |
---|
| 3775 | int idordenador,lon,i,p; |
---|
| 3776 | |
---|
| 3777 | // Prepara mac |
---|
| 3778 | lon=strlen(mac); |
---|
| 3779 | p=0; |
---|
| 3780 | for (i=0;i<lon;i++){ |
---|
| 3781 | if(mac[i]!=' ') // Si no es espacio |
---|
| 3782 | strmac[p++]=mac[i]; |
---|
| 3783 | } |
---|
| 3784 | strmac[p]=(char)NULL; |
---|
| 3785 | |
---|
| 3786 | 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); |
---|
| 3787 | if(!db.Execute(sqlstr)){ // Error al insertar |
---|
| 3788 | db.GetErrorErrStr(ErrStr); |
---|
| 3789 | return(false); |
---|
| 3790 | } |
---|
| 3791 | idordenador=0; |
---|
| 3792 | // Toma identificador dela accin |
---|
| 3793 | sprintf(sqlstr,"SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3794 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3795 | db.GetErrorErrStr(ErrStr); |
---|
| 3796 | return(false); |
---|
| 3797 | } |
---|
| 3798 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3799 | if(!tbl.Get("identificador",idordenador)){ |
---|
| 3800 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3801 | return(false); |
---|
| 3802 | } |
---|
| 3803 | } |
---|
| 3804 | *ido=idordenador; |
---|
| 3805 | return(true); |
---|
| 3806 | } |
---|
| 3807 | // ________________________________________________________________________________________________________ |
---|
[277d0cd] | 3808 | // Funcin: Toma_idservidorres |
---|
[34fc87f] | 3809 | // |
---|
[277d0cd] | 3810 | // Descripcin: |
---|
| 3811 | // Esta funcin devuelve los identificadores de los servidores rembo y dhcp de un determinado ordenador |
---|
[34fc87f] | 3812 | // Parnetros: |
---|
| 3813 | // db: Objeto base de datos (ya operativo) |
---|
| 3814 | // tbl: Objeto tabla |
---|
| 3815 | // ipd: ip del servidor dhcp |
---|
| 3816 | // ipr: ip del servidor rembo |
---|
| 3817 | // isd: identificador del servidor dhcp |
---|
| 3818 | // isr: identificador del servidor rembo |
---|
| 3819 | // ________________________________________________________________________________________________________ |
---|
| 3820 | int Toma_idservidorres(Database db,Table tbl,char*ipd,char*ipr,int*isd,int*isr) |
---|
| 3821 | { |
---|
| 3822 | char sqlstr[1000],ErrStr[200]; |
---|
[51dcdc7] | 3823 | int identificador_dhcp=0; |
---|
| 3824 | int identificador_rembo; |
---|
[34fc87f] | 3825 | |
---|
[51dcdc7] | 3826 | /* Servidor dhcp |
---|
[34fc87f] | 3827 | sprintf(sqlstr,"SELECT idservidordhcp FROM servidoresdhcp where ip='%s'",ipd); |
---|
| 3828 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3829 | db.GetErrorErrStr(ErrStr); |
---|
| 3830 | return(false); |
---|
| 3831 | } |
---|
| 3832 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3833 | if(!tbl.Get("idservidordhcp",identificador_dhcp)){ |
---|
| 3834 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3835 | return(false); |
---|
| 3836 | } |
---|
| 3837 | } |
---|
[51dcdc7] | 3838 | */ |
---|
[34fc87f] | 3839 | // Servidor rembo |
---|
| 3840 | sprintf(sqlstr,"SELECT idservidorrembo FROM servidoresrembo where ip='%s'",ipr); |
---|
| 3841 | if(!db.Execute(sqlstr,tbl)){ // Error al leer |
---|
| 3842 | db.GetErrorErrStr(ErrStr); |
---|
| 3843 | return(false); |
---|
| 3844 | } |
---|
| 3845 | if(!tbl.ISEOF()){ // Si existe registro |
---|
| 3846 | if(!tbl.Get("idservidorrembo",identificador_rembo)){ |
---|
| 3847 | tbl.GetErrorErrStr(ErrStr); // error al acceder al registro |
---|
| 3848 | return(false); |
---|
| 3849 | } |
---|
| 3850 | } |
---|
| 3851 | *isd=identificador_dhcp; |
---|
| 3852 | *isr=identificador_rembo; |
---|
| 3853 | return(true); |
---|
| 3854 | } |
---|
| 3855 | //************************************************************************************************************************************************ |
---|
| 3856 | // PROGRAMA PRINCIPAL ( SERVICIO) |
---|
| 3857 | //*************************************************************************************************************************************************** |
---|
| 3858 | int main (int argc, char *argv[]) |
---|
| 3859 | { |
---|
| 3860 | SOCKET socket_s; // Socket donde escucha el servidor |
---|
| 3861 | SOCKET socket_c; // Socket de los clientes que se conectan |
---|
| 3862 | int i;// Tamao de la estructura de direccionamiento IP del cliente |
---|
| 3863 | socklen_t iAddrSize; |
---|
| 3864 | struct sockaddr_in local,cliente; |
---|
| 3865 | //pthread_t hThread; |
---|
| 3866 | //void *resul |
---|
| 3867 | // Validación de parámetros |
---|
[b25881b] | 3868 | |
---|
[df5bd24] | 3869 | strcpy(szPathFileCfg,"ogAdmServer.cfg"); |
---|
| 3870 | strcpy(szPathFileLog,"ogAdmServer.log"); |
---|
[b25881b] | 3871 | |
---|
[34fc87f] | 3872 | for(i = 1; (i+1) < argc; i+=2){ |
---|
| 3873 | if (argv[i][0] == '-'){ |
---|
| 3874 | switch (tolower(argv[i][1])){ |
---|
| 3875 | case 'f': |
---|
| 3876 | if (argv[i+1]!=NULL) |
---|
[b25881b] | 3877 | strcpy(szPathFileCfg, argv[i+1]); |
---|
[34fc87f] | 3878 | else{ |
---|
| 3879 | RegistraLog("Fallo en los parámetros: Debe especificar el fichero de configuración del servicio",false); |
---|
| 3880 | exit(EXIT_FAILURE); |
---|
| 3881 | } |
---|
| 3882 | break; |
---|
| 3883 | case 'l': |
---|
| 3884 | if (argv[i+1]!=NULL) |
---|
[b25881b] | 3885 | strcpy(szPathFileLog, argv[i+1]); |
---|
[34fc87f] | 3886 | else{ |
---|
| 3887 | RegistraLog("Fallo en los parámetros: Debe especificar el fichero de log para el servicio",false); |
---|
| 3888 | exit(EXIT_FAILURE); |
---|
| 3889 | } |
---|
| 3890 | break; |
---|
| 3891 | default: |
---|
| 3892 | RegistraLog("Fallo de sintaxis en los parámetros: Debe especificar -f nombre_del_fichero_de_configuración_del_servicio",false); |
---|
| 3893 | exit(EXIT_FAILURE); |
---|
| 3894 | break; |
---|
| 3895 | } |
---|
| 3896 | } |
---|
| 3897 | } |
---|
[b25881b] | 3898 | if (szPathFileCfg==NULL){ |
---|
| 3899 | printf ("***Error. No se ha especificado fichero de configuración\n"); |
---|
| 3900 | exit(EXIT_FAILURE); |
---|
| 3901 | } |
---|
| 3902 | if(!TomaConfiguracion(szPathFileCfg)){ // Toma parametros de configuracion |
---|
| 3903 | RegistraLog("El fichero de configuración contiene un error de sintaxis",false); |
---|
| 3904 | exit(EXIT_FAILURE); |
---|
[34fc87f] | 3905 | } |
---|
| 3906 | pthread_mutex_init(&guardia,NULL); // Creación del mutex para control de hebras |
---|
| 3907 | |
---|
| 3908 | for (i=0;i<MAXIMOS_SOCKETS;i++){ |
---|
| 3909 | tbsockets[i].ip[0]='\0'; // Inicializa IP |
---|
| 3910 | tbsockets[i].sock=INVALID_SOCKET; // Inicializa Socket |
---|
| 3911 | } |
---|
| 3912 | RegistraLog("***Inicio de sesion***",false); |
---|
| 3913 | |
---|
| 3914 | socket_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Crea socket |
---|
| 3915 | if (socket_s == SOCKET_ERROR){ |
---|
| 3916 | RegistraLog("***socket() fallo:",true); |
---|
| 3917 | } |
---|
| 3918 | local.sin_addr.s_addr = htonl(INADDR_ANY); // selecciona interface |
---|
| 3919 | local.sin_family = AF_INET; |
---|
| 3920 | local.sin_port = htons(puerto); // Puerto |
---|
| 3921 | |
---|
| 3922 | if (bind(socket_s,(struct sockaddr *)&local, // Enlaza socket |
---|
| 3923 | sizeof(local)) == SOCKET_ERROR){ |
---|
| 3924 | RegistraLog("***bind() fallo:",true); |
---|
| 3925 | } |
---|
| 3926 | |
---|
| 3927 | listen(socket_s,250); // Pone a escuchar al socket |
---|
| 3928 | iAddrSize = sizeof(cliente); |
---|
| 3929 | |
---|
| 3930 | while (true) { // Bucle para escuchar peticiones de clientes |
---|
| 3931 | socket_c = accept(socket_s, (struct sockaddr *)&cliente,&iAddrSize); |
---|
| 3932 | if (socket_c == INVALID_SOCKET){ |
---|
| 3933 | RegistraLog("***accept() fallo:",true); |
---|
| 3934 | break; |
---|
| 3935 | } |
---|
| 3936 | //resul=pthread_create(&hThread,NULL,GestionaConexion,(void*)&socket_c); |
---|
| 3937 | GestionaConexion(&socket_c); |
---|
| 3938 | /*if(resul!=0){2 |
---|
| 3939 | RegistraLog("***Fallo al crear la hebra cliente",false); |
---|
| 3940 | break; |
---|
| 3941 | } |
---|
| 3942 | */ |
---|
| 3943 | //pthread_detach(hThread); |
---|
| 3944 | close(socket_c); // Cierra la conexion con el servidor hidra |
---|
| 3945 | } |
---|
| 3946 | close(socket_s); |
---|
| 3947 | exit(EXIT_SUCCESS); |
---|
| 3948 | } |
---|