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