[f679cf0] | 1 | // ******************************************************************************************************* |
---|
[3ec149c] | 2 | // Servicio: ogAdmServer |
---|
| 3 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
---|
| 4 | // Fecha Creación: Marzo-2010 |
---|
| 5 | // Fecha Última modificación: Marzo-2010 |
---|
| 6 | // Nombre del fichero: ogAdmServer.cpp |
---|
| 7 | // Descripción :Este fichero implementa el servicio de administración general del sistema |
---|
[f679cf0] | 8 | // ******************************************************************************************************* |
---|
[3ec149c] | 9 | #include "ogAdmServer.h" |
---|
| 10 | #include "ogAdmLib.c" |
---|
| 11 | //________________________________________________________________________________________________________ |
---|
| 12 | // Función: tomaConfiguracion |
---|
| 13 | // |
---|
| 14 | // Descripción: |
---|
| 15 | // Lee el fichero de configuración del servicio |
---|
| 16 | // Parámetros: |
---|
| 17 | // filecfg : Ruta completa al fichero de configuración |
---|
| 18 | // Devuelve: |
---|
| 19 | // TRUE: Si el proceso es correcto |
---|
| 20 | // FALSE: En caso de ocurrir algún error |
---|
| 21 | //________________________________________________________________________________________________________ |
---|
| 22 | BOOLEAN tomaConfiguracion(char* filecfg) { |
---|
| 23 | char modulo[] = "tomaConfiguracion()"; |
---|
| 24 | |
---|
| 25 | if (filecfg == NULL || strlen(filecfg) == 0) { |
---|
| 26 | errorLog(modulo, 1, FALSE); // Fichero de configuración del servicio vacío |
---|
| 27 | return (FALSE); |
---|
| 28 | } |
---|
| 29 | FILE *fcfg; |
---|
| 30 | long lSize; |
---|
| 31 | char * buffer, *lineas[MAXPRM], *dualparametro[2]; |
---|
| 32 | int i, numlin, resul; |
---|
| 33 | |
---|
| 34 | fcfg = fopen(filecfg, "rt"); |
---|
| 35 | if (fcfg == NULL) { |
---|
| 36 | errorLog(modulo, 2, FALSE); // No existe fichero de configuración del servicio |
---|
| 37 | return (FALSE); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | fseek(fcfg, 0, SEEK_END); |
---|
| 41 | lSize = ftell(fcfg); // Obtiene tamaño del fichero. |
---|
| 42 | rewind(fcfg); |
---|
| 43 | buffer = (char*) reservaMemoria(lSize + 1); // Toma memoria para el buffer de lectura. |
---|
| 44 | if (buffer == NULL) { // No hay memoria suficiente para el buffer |
---|
| 45 | errorLog(modulo, 3, FALSE); |
---|
| 46 | return (FALSE); |
---|
| 47 | } |
---|
| 48 | fread(buffer, 1, lSize, fcfg); // Lee contenido del fichero |
---|
| 49 | buffer[lSize] = (char) NULL; |
---|
| 50 | fclose(fcfg); |
---|
| 51 | |
---|
| 52 | servidoradm[0] = (char) NULL; //inicializar variables globales |
---|
| 53 | puerto[0] = (char) NULL; |
---|
| 54 | usuario[0] = (char) NULL; |
---|
| 55 | pasguor[0] = (char) NULL; |
---|
| 56 | datasource[0] = (char) NULL; |
---|
| 57 | catalog[0] = (char) NULL; |
---|
| 58 | aulaup[0] = (char) NULL; |
---|
| 59 | |
---|
| 60 | numlin = splitCadena(lineas, buffer, '\n'); |
---|
| 61 | for (i = 0; i < numlin; i++) { |
---|
| 62 | splitCadena(dualparametro, lineas[i], '='); |
---|
| 63 | resul = strcmp(StrToUpper(dualparametro[0]), "SERVIDORADM"); |
---|
| 64 | if (resul == 0) |
---|
| 65 | strcpy(servidoradm, dualparametro[1]); |
---|
| 66 | resul = strcmp(StrToUpper(dualparametro[0]), "PUERTO"); |
---|
| 67 | if (resul == 0) |
---|
| 68 | strcpy(puerto, dualparametro[1]); |
---|
| 69 | resul = strcmp(StrToUpper(dualparametro[0]), "USUARIO"); |
---|
| 70 | if (resul == 0) |
---|
| 71 | strcpy(usuario, dualparametro[1]); |
---|
| 72 | resul = strcmp(StrToUpper(dualparametro[0]), "PASSWORD"); |
---|
| 73 | if (resul == 0) |
---|
| 74 | strcpy(pasguor, dualparametro[1]); |
---|
| 75 | resul = strcmp(StrToUpper(dualparametro[0]), "DATASOURCE"); |
---|
| 76 | if (resul == 0) |
---|
| 77 | strcpy(datasource, dualparametro[1]); |
---|
| 78 | resul = strcmp(StrToUpper(dualparametro[0]), "CATALOG"); |
---|
| 79 | if (resul == 0) |
---|
| 80 | strcpy(catalog, dualparametro[1]); |
---|
| 81 | resul = strcmp(StrToUpper(dualparametro[0]), "AULAUP"); |
---|
| 82 | if (resul == 0) |
---|
| 83 | strcpy(catalog, dualparametro[1]); |
---|
| 84 | } |
---|
| 85 | if (servidoradm[0] == (char) NULL) { |
---|
[0a73ecf7] | 86 | liberaMemoria(buffer); |
---|
[3ec149c] | 87 | errorLog(modulo, 4, FALSE); // Falta parámetro SERVIDORADM |
---|
| 88 | return (FALSE); |
---|
| 89 | } |
---|
| 90 | if (puerto[0] == (char) NULL) { |
---|
[0a73ecf7] | 91 | liberaMemoria(buffer); |
---|
[3ec149c] | 92 | errorLog(modulo, 5, FALSE); // Falta parámetro PUERTO |
---|
| 93 | return (FALSE); |
---|
| 94 | } |
---|
| 95 | if (usuario[0] == (char) NULL) { |
---|
[0a73ecf7] | 96 | liberaMemoria(buffer); |
---|
[3ec149c] | 97 | errorLog(modulo, 6, FALSE); // Falta parámetro USUARIO |
---|
| 98 | return (FALSE); |
---|
| 99 | } |
---|
| 100 | if (pasguor[0] == (char) NULL) { |
---|
[0a73ecf7] | 101 | liberaMemoria(buffer); |
---|
[3ec149c] | 102 | errorLog(modulo, 7, FALSE); // Falta parámetro PASSWORD |
---|
| 103 | return (FALSE); |
---|
| 104 | } |
---|
| 105 | if (datasource[0] == (char) NULL) { |
---|
[0a73ecf7] | 106 | liberaMemoria(buffer); |
---|
[3ec149c] | 107 | errorLog(modulo, 8, FALSE); // Falta parámetro DATASOURCE |
---|
| 108 | return (FALSE); |
---|
| 109 | } |
---|
| 110 | if (catalog[0] == (char) NULL) { |
---|
[0a73ecf7] | 111 | liberaMemoria(buffer); |
---|
[3ec149c] | 112 | errorLog(modulo, 9, FALSE); // Falta parámetro CATALOG |
---|
| 113 | return (FALSE); |
---|
| 114 | } |
---|
| 115 | if (aulaup[0] == (char) NULL) { |
---|
| 116 | strcpy(aulaup, "0"); // Por defecto el conmutador de registro automático esta en off |
---|
[0a73ecf7] | 117 | |
---|
[3ec149c] | 118 | } |
---|
[0a73ecf7] | 119 | liberaMemoria(buffer); |
---|
[3ec149c] | 120 | return (TRUE); |
---|
| 121 | } |
---|
| 122 | // ________________________________________________________________________________________________________ |
---|
| 123 | // Función: gestionaTrama |
---|
| 124 | // |
---|
| 125 | // Descripción: |
---|
| 126 | // Procesa las tramas recibidas . |
---|
| 127 | // Parametros: |
---|
| 128 | // - s : Socket usado para comunicaciones |
---|
| 129 | // Devuelve: |
---|
| 130 | // TRUE: Si el proceso es correcto |
---|
| 131 | // FALSE: En caso de ocurrir algún error |
---|
| 132 | // ________________________________________________________________________________________________________ |
---|
| 133 | BOOLEAN gestionaTrama(SOCKET *socket_c) |
---|
| 134 | { |
---|
| 135 | TRAMA* ptrTrama; |
---|
| 136 | int i, res; |
---|
| 137 | char *nfn; |
---|
| 138 | char modulo[] = "gestionaTrama()"; |
---|
| 139 | |
---|
| 140 | ptrTrama=recibeTrama(socket_c); |
---|
[f679cf0] | 141 | |
---|
[3ec149c] | 142 | if (ptrTrama){ |
---|
| 143 | INTROaFINCAD(ptrTrama); |
---|
[0a73ecf7] | 144 | nfn = copiaParametro("nfn",ptrTrama); // Toma nombre de la función |
---|
| 145 | |
---|
[3ec149c] | 146 | for (i = 0; i < MAXIMAS_FUNCIONES; i++) { // Recorre funciones que procesan las tramas |
---|
| 147 | res = strcmp(tbfuncionesServer[i].nf, nfn); |
---|
| 148 | if (res == 0) { // Encontrada la función que procesa el mensaje |
---|
[0a73ecf7] | 149 | liberaMemoria(nfn); |
---|
| 150 | res=tbfuncionesServer[i].fptr(socket_c, ptrTrama); // Invoca la función |
---|
| 151 | liberaMemoria(ptrTrama); |
---|
| 152 | return(res); |
---|
[3ec149c] | 153 | } |
---|
| 154 | } |
---|
[0a73ecf7] | 155 | |
---|
| 156 | /* |
---|
| 157 | Sólo puede ser un comando personalizado o su notificación |
---|
[3ec149c] | 158 | if (ptrTrama->tipo == MSG_COMANDO) |
---|
| 159 | return (Comando(socket_c, ptrTrama)); |
---|
| 160 | else { |
---|
| 161 | if (ptrTrama->tipo == MSG_NOTIFICACION) |
---|
| 162 | return (RESPUESTA_Comando(socket_c, ptrTrama)); |
---|
| 163 | else |
---|
| 164 | errorLog(modulo, 18, FALSE); // No se reconoce el mensaje |
---|
| 165 | } |
---|
[0a73ecf7] | 166 | */ |
---|
[3ec149c] | 167 | } |
---|
| 168 | else |
---|
| 169 | errorLog(modulo, 17, FALSE); // Error en la recepción |
---|
| 170 | return (TRUE); |
---|
| 171 | } |
---|
| 172 | // ________________________________________________________________________________________________________ |
---|
| 173 | // Función: Sondeo |
---|
| 174 | // |
---|
| 175 | // Descripción: |
---|
| 176 | // Solicita a los clientes su disponibiliad para recibir comandos interactivos |
---|
| 177 | // Parámetros: |
---|
| 178 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 179 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 180 | // Devuelve: |
---|
| 181 | // TRUE: Si el proceso es correcto |
---|
| 182 | // FALSE: En caso de ocurrir algún error |
---|
| 183 | // ________________________________________________________________________________________________________ |
---|
| 184 | BOOLEAN Sondeo(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 185 | char msglog[LONSTD]; |
---|
| 186 | char modulo[] = "Sondeo()"; |
---|
| 187 | |
---|
| 188 | if (!enviaComando(ptrTrama, CLIENTE_APAGADO)) { |
---|
| 189 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 190 | errorInfo(modulo, msglog); |
---|
| 191 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 192 | return (FALSE); |
---|
| 193 | } |
---|
| 194 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 195 | return (TRUE); |
---|
| 196 | } |
---|
| 197 | // ________________________________________________________________________________________________________ |
---|
| 198 | // Función: respuestaSondeo |
---|
| 199 | // |
---|
| 200 | // Descripción: |
---|
| 201 | // Recupera el estatus de los ordenadores solicitados leyendo la tabla de sockets |
---|
| 202 | // Parámetros: |
---|
| 203 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 204 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 205 | // Devuelve: |
---|
| 206 | // TRUE: Si el proceso es correcto |
---|
| 207 | // FALSE: En caso de ocurrir algún error |
---|
| 208 | // ________________________________________________________________________________________________________ |
---|
| 209 | BOOLEAN respuestaSondeo(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 210 | int i; |
---|
| 211 | long lSize; |
---|
| 212 | char *iph, *Ipes; |
---|
| 213 | char modulo[] = "respuestaSondeo()"; |
---|
| 214 | |
---|
| 215 | iph = copiaParametro("iph",ptrTrama); // Toma dirección/es IP |
---|
| 216 | lSize = strlen(iph); // Calcula longitud de la cadena de direccion/es IPE/S |
---|
| 217 | Ipes = (char*) reservaMemoria(lSize + 1); |
---|
| 218 | if (Ipes == NULL) { |
---|
| 219 | errorLog(modulo, 3, FALSE); |
---|
| 220 | return (FALSE); |
---|
| 221 | } |
---|
| 222 | strcpy(Ipes, iph); // Copia cadena de IPES |
---|
[0a73ecf7] | 223 | liberaMemoria(iph); |
---|
[3ec149c] | 224 | initParametros(ptrTrama,0); |
---|
| 225 | strcpy(ptrTrama->parametros, "tso="); // Compone retorno tso (sistemas operativos de los clientes ) |
---|
| 226 | for (i = 0; i < MAXIMOS_CLIENTES; i++) { |
---|
| 227 | if (strncmp(tbsockets[i].ip, "\0", 1) != 0) { // Si es un cliente activo |
---|
| 228 | if (contieneIP(Ipes, tbsockets[i].ip)) { // Si existe la IP en la cadena |
---|
| 229 | strcat(ptrTrama->parametros, tbsockets[i].ip); // Compone retorno |
---|
| 230 | strcat(ptrTrama->parametros, "/"); // "ip/sistema operativo;" |
---|
| 231 | strcat(ptrTrama->parametros, tbsockets[i].estado); |
---|
| 232 | strcat(ptrTrama->parametros, ";"); |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | strcat(ptrTrama->parametros, "\r"); |
---|
[fc480f2] | 237 | liberaMemoria(Ipes); |
---|
[3ec149c] | 238 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 239 | errorLog(modulo, 26, FALSE); |
---|
| 240 | return (FALSE); |
---|
| 241 | } |
---|
| 242 | return (TRUE); |
---|
| 243 | } |
---|
| 244 | // ________________________________________________________________________________________________________ |
---|
| 245 | // Función: Actualizar |
---|
| 246 | // |
---|
| 247 | // Descripción: |
---|
| 248 | // Obliga a los clientes a iniciar sesión en el sistema |
---|
| 249 | // Parámetros: |
---|
| 250 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 251 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 252 | // Devuelve: |
---|
| 253 | // TRUE: Si el proceso es correcto |
---|
| 254 | // FALSE: En caso de ocurrir algún error |
---|
| 255 | // ________________________________________________________________________________________________________ |
---|
| 256 | BOOLEAN Actualizar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 257 | char msglog[LONSTD]; |
---|
| 258 | char modulo[] = "Actualizar()"; |
---|
| 259 | |
---|
| 260 | if (!enviaComando(ptrTrama, CLIENTE_APAGADO)) { |
---|
| 261 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 262 | errorInfo(modulo, msglog); |
---|
| 263 | return (FALSE); |
---|
| 264 | } |
---|
| 265 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 266 | return (TRUE); |
---|
| 267 | } |
---|
| 268 | // ________________________________________________________________________________________________________ |
---|
| 269 | // Función: Purgar |
---|
| 270 | // |
---|
| 271 | // Descripción: |
---|
| 272 | // Detiene la ejecución del browser en el cliente |
---|
| 273 | // Parámetros: |
---|
| 274 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 275 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 276 | // Devuelve: |
---|
| 277 | // TRUE: Si el proceso es correcto |
---|
| 278 | // FALSE: En caso de ocurrir algún error |
---|
| 279 | // ________________________________________________________________________________________________________ |
---|
| 280 | BOOLEAN Purgar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 281 | char msglog[LONSTD]; |
---|
| 282 | char modulo[] = "Purgar()"; |
---|
| 283 | |
---|
| 284 | if (!enviaComando(ptrTrama, CLIENTE_APAGADO)) { |
---|
| 285 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 286 | errorInfo(modulo, msglog); |
---|
| 287 | return (FALSE); |
---|
| 288 | } |
---|
| 289 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 290 | return (TRUE); |
---|
| 291 | } |
---|
| 292 | // ________________________________________________________________________________________________________ |
---|
| 293 | // Función: ConsolaRemota |
---|
| 294 | // |
---|
| 295 | // Descripción: |
---|
| 296 | // Envia un script al cliente, éste lo ejecuta y manda el archivo que genera la salida por pantalla |
---|
| 297 | // Parámetros: |
---|
| 298 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 299 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 300 | // Devuelve: |
---|
| 301 | // TRUE: Si el proceso es correcto |
---|
| 302 | // FALSE: En caso de ocurrir algún error |
---|
| 303 | // ________________________________________________________________________________________________________ |
---|
| 304 | BOOLEAN ConsolaRemota(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 305 | { |
---|
| 306 | char *iph,fileco[LONPRM],msglog[LONSTD],*ptrIpes[MAXIMOS_CLIENTES];; |
---|
| 307 | FILE* f; |
---|
| 308 | int i,lon; |
---|
| 309 | char modulo[] = "ConsolaRemota()"; |
---|
| 310 | |
---|
| 311 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 312 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 313 | errorInfo(modulo, msglog); |
---|
| 314 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 315 | return (FALSE); |
---|
| 316 | } |
---|
| 317 | INTROaFINCAD(ptrTrama); |
---|
| 318 | /* Destruye contenido del fichero de eco anterior */ |
---|
| 319 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip del cliente |
---|
| 320 | lon = splitCadena(ptrIpes,iph,';'); |
---|
| 321 | for (i = 0; i < lon; i++) { |
---|
| 322 | sprintf(fileco,"/tmp/_Seconsola_%s",ptrIpes[i]); // Nombre que tendra el archivo en el Servidor |
---|
| 323 | f = fopen(fileco, "wt"); |
---|
| 324 | fclose(f); |
---|
| 325 | } |
---|
[0a73ecf7] | 326 | liberaMemoria(iph); |
---|
[3ec149c] | 327 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 328 | return (TRUE); |
---|
| 329 | } |
---|
| 330 | // ________________________________________________________________________________________________________ |
---|
| 331 | // Función: EcoConsola |
---|
| 332 | // |
---|
| 333 | // Descripción: |
---|
| 334 | // Solicita el eco de una consola remota almacenado en un archivo de eco |
---|
| 335 | // Parámetros: |
---|
| 336 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 337 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros del mensaje |
---|
| 338 | // Devuelve: |
---|
| 339 | // TRUE: Si el proceso es correcto |
---|
| 340 | // FALSE: En caso de ocurrir algún error |
---|
| 341 | // ________________________________________________________________________________________________________ |
---|
| 342 | BOOLEAN EcoConsola(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 343 | { |
---|
| 344 | char *iph,fileco[LONPRM],*buffer; |
---|
| 345 | int lSize; |
---|
| 346 | char modulo[] = "EcoConsola()"; |
---|
| 347 | |
---|
| 348 | INTROaFINCAD(ptrTrama); |
---|
| 349 | // Lee archivo de eco de consola |
---|
| 350 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip del cliente |
---|
| 351 | sprintf(fileco,"/tmp/_Seconsola_%s",iph); // Nombre del archivo en el Servidor |
---|
| 352 | lSize=lonArchivo(fileco); |
---|
| 353 | if(lSize>0){ // Si el fichero tiene contenido... |
---|
| 354 | initParametros(ptrTrama,lSize+LONGITUD_PARAMETROS); |
---|
| 355 | buffer=leeArchivo(fileco); |
---|
| 356 | sprintf(ptrTrama->parametros,"res=%s\r",buffer); |
---|
[0a73ecf7] | 357 | liberaMemoria(buffer); |
---|
[3ec149c] | 358 | } |
---|
| 359 | else{ |
---|
| 360 | initParametros(ptrTrama,0); |
---|
| 361 | sprintf(ptrTrama->parametros,"res=\r"); |
---|
| 362 | } |
---|
| 363 | ptrTrama->tipo=MSG_RESPUESTA; // Tipo de mensaje |
---|
| 364 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 365 | errorLog(modulo, 26, FALSE); |
---|
| 366 | return (FALSE); |
---|
| 367 | } |
---|
| 368 | return (TRUE); |
---|
| 369 | } |
---|
| 370 | // ________________________________________________________________________________________________________ |
---|
| 371 | // Función: clienteDisponible |
---|
| 372 | // |
---|
| 373 | // Descripción: |
---|
| 374 | // Comprueba la disponibilidad del cliente para recibir comandos interactivos |
---|
| 375 | // Parametros: |
---|
| 376 | // - ip : La ip del cliente a buscar |
---|
| 377 | // - idx: (Salida) Indice que ocupa el cliente, de estar ya registrado |
---|
| 378 | // Devuelve: |
---|
| 379 | // TRUE: Si el cliente está disponible |
---|
| 380 | // FALSE: En caso contrario |
---|
| 381 | // ________________________________________________________________________________________________________ |
---|
| 382 | BOOLEAN clienteDisponible(char *ip, int* idx) { |
---|
| 383 | int estado; |
---|
| 384 | |
---|
| 385 | if (clienteExistente(ip, idx)) { |
---|
| 386 | estado = strcmp(tbsockets[*idx].estado, CLIENTE_OCUPADO); // Cliente ocupado |
---|
| 387 | if (estado == 0) |
---|
| 388 | return (FALSE); |
---|
| 389 | |
---|
| 390 | estado = strcmp(tbsockets[*idx].estado, CLIENTE_APAGADO); // Cliente apagado |
---|
| 391 | if (estado == 0) |
---|
| 392 | return (FALSE); |
---|
| 393 | |
---|
| 394 | estado = strcmp(tbsockets[*idx].estado, CLIENTE_INICIANDO); // Cliente en proceso de inclusión |
---|
| 395 | if (estado == 0) |
---|
| 396 | return (FALSE); |
---|
| 397 | |
---|
| 398 | return (TRUE); // En caso contrario el cliente está disponible |
---|
| 399 | } |
---|
| 400 | return (FALSE); // Cliente no está registrado en el sistema |
---|
| 401 | } |
---|
| 402 | // ________________________________________________________________________________________________________ |
---|
| 403 | // Función: clienteExistente |
---|
| 404 | // |
---|
| 405 | // Descripción: |
---|
| 406 | // Comprueba si el cliente está registrado en la tabla de socket del sistema |
---|
| 407 | // Parametros: |
---|
| 408 | // - ip : La ip del cliente a buscar |
---|
| 409 | // - idx:(Salida) Indice que ocupa el cliente, de estar ya registrado |
---|
| 410 | // Devuelve: |
---|
| 411 | // TRUE: Si el cliente está registrado |
---|
| 412 | // FALSE: En caso contrario |
---|
| 413 | // ________________________________________________________________________________________________________ |
---|
| 414 | BOOLEAN clienteExistente(char *ip, int* idx) { |
---|
| 415 | int i; |
---|
| 416 | for (i = 0; i < MAXIMOS_CLIENTES; i++) { |
---|
| 417 | if (contieneIP(ip, tbsockets[i].ip)) { // Si existe la IP en la cadena |
---|
| 418 | *idx = i; |
---|
| 419 | return (TRUE); |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | return (FALSE); |
---|
| 423 | } |
---|
| 424 | // ________________________________________________________________________________________________________ |
---|
| 425 | // Función: hayHueco |
---|
| 426 | // |
---|
| 427 | // Descripción: |
---|
| 428 | // Esta función devuelve TRUE o FALSE dependiendo de que haya hueco en la tabla de sockets para un nuevo cliente. |
---|
| 429 | // Parametros: |
---|
| 430 | // - idx: Primer indice libre que se podrn utilizar |
---|
| 431 | // Devuelve: |
---|
| 432 | // TRUE: Si el proceso es correcto |
---|
| 433 | // FALSE: En caso de ocurrir algún error |
---|
| 434 | // ________________________________________________________________________________________________________ |
---|
| 435 | BOOLEAN hayHueco(int *idx) { |
---|
| 436 | int i; |
---|
| 437 | |
---|
| 438 | for (i = 0; i < MAXIMOS_CLIENTES; i++) { |
---|
| 439 | if (strncmp(tbsockets[i].ip, "\0", 1) == 0) { // Hay un hueco |
---|
| 440 | *idx = i; |
---|
| 441 | return (TRUE); |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | return (FALSE); |
---|
| 445 | } |
---|
| 446 | // ________________________________________________________________________________________________________ |
---|
[f679cf0] | 447 | // Función: InclusionClienteWin |
---|
| 448 | // |
---|
| 449 | // Descripción: |
---|
| 450 | // Esta función incorpora el socket de un nuevo cliente Windows o Linux a la tabla de clientes |
---|
| 451 | // Parámetros: |
---|
| 452 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 453 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 454 | // Devuelve: |
---|
| 455 | // TRUE: Si el proceso es correcto |
---|
| 456 | // FALSE: En caso de ocurrir algún error |
---|
| 457 | // ________________________________________________________________________________________________________ |
---|
| 458 | BOOLEAN InclusionClienteWinLnx(SOCKET *socket_c, TRAMA *ptrTrama) |
---|
| 459 | { |
---|
| 460 | char modulo[] = "InclusionClienteWinLnx()"; |
---|
| 461 | int res,idordenador,lon; |
---|
| 462 | char nombreordenador[LONFIL]; |
---|
| 463 | |
---|
| 464 | res=procesoInclusionClienteWinLnx(socket_c, ptrTrama,&idordenador,nombreordenador); |
---|
| 465 | |
---|
| 466 | // Prepara la trama de respuesta |
---|
| 467 | |
---|
| 468 | initParametros(ptrTrama,0); |
---|
| 469 | ptrTrama->tipo=MSG_RESPUESTA; |
---|
| 470 | lon = sprintf(ptrTrama->parametros, "nfn=RESPUESTA_InclusionClienteWinLnx\r"); |
---|
| 471 | lon += sprintf(ptrTrama->parametros + lon, "ido=%d\r", idordenador); |
---|
| 472 | lon += sprintf(ptrTrama->parametros + lon, "npc=%s\r", nombreordenador); |
---|
| 473 | lon += sprintf(ptrTrama->parametros + lon, "res=%d\r", res); |
---|
| 474 | |
---|
| 475 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 476 | errorLog(modulo, 26, FALSE); |
---|
| 477 | return (FALSE); |
---|
| 478 | } |
---|
| 479 | return (TRUE); |
---|
| 480 | } |
---|
| 481 | // ________________________________________________________________________________________________________ |
---|
| 482 | // Función: procesoInclusionClienteWinLnx |
---|
| 483 | // |
---|
| 484 | // Descripción: |
---|
| 485 | // Implementa el proceso de inclusión en el sistema del Cliente Windows o Linux |
---|
| 486 | // Parámetros de entrada: |
---|
| 487 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 488 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 489 | // Parámetros de salida: |
---|
| 490 | // - ido: Identificador del ordenador |
---|
| 491 | // - nombreordenador: Nombre del ordenador |
---|
| 492 | // Devuelve: |
---|
| 493 | // Código del error producido en caso de ocurrir algún error, 0 si el proceso es correcto |
---|
| 494 | // ________________________________________________________________________________________________________ |
---|
| 495 | BOOLEAN procesoInclusionClienteWinLnx(SOCKET *socket_c, TRAMA *ptrTrama,int *idordenador,char* nombreordenador) |
---|
| 496 | { |
---|
| 497 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 498 | Database db; |
---|
| 499 | Table tbl; |
---|
| 500 | |
---|
| 501 | char *iph; |
---|
| 502 | char modulo[] = "procesoInclusionClienteWinLnx()"; |
---|
| 503 | |
---|
| 504 | // Toma parámetros |
---|
| 505 | iph = copiaParametro("iph",ptrTrama); // Toma ip |
---|
| 506 | |
---|
| 507 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexión con la BD |
---|
| 508 | errorLog(modulo, 20, FALSE); |
---|
| 509 | db.GetErrorErrStr(msglog); |
---|
| 510 | errorInfo(modulo, msglog); |
---|
| 511 | return (20); |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | // Recupera los datos del cliente |
---|
| 515 | sprintf(sqlstr, |
---|
| 516 | "SELECT idordenador,nombreordenador FROM ordenadores " |
---|
| 517 | " WHERE ordenadores.ip = '%s'", iph); |
---|
| 518 | |
---|
| 519 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 520 | errorLog(modulo, 21, FALSE); |
---|
| 521 | db.GetErrorErrStr(msglog); |
---|
| 522 | errorInfo(modulo, msglog); |
---|
| 523 | return (21); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | if (tbl.ISEOF()) { // Si no existe el cliente |
---|
| 527 | errorLog(modulo, 22, FALSE); |
---|
| 528 | return (22); |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | if (ndebug == DEBUG_ALTO) { |
---|
| 532 | sprintf(msglog, "%s IP:%s", tbMensajes[2], iph); |
---|
| 533 | infoDebug(msglog); |
---|
| 534 | } |
---|
| 535 | if (!tbl.Get("idordenador", *idordenador)) { |
---|
| 536 | tbl.GetErrorErrStr(msglog); |
---|
| 537 | errorInfo(modulo, msglog); |
---|
| 538 | return (FALSE); |
---|
| 539 | } |
---|
| 540 | if (!tbl.Get("nombreordenador", nombreordenador)) { |
---|
| 541 | tbl.GetErrorErrStr(msglog); |
---|
| 542 | errorInfo(modulo, msglog); |
---|
| 543 | return (FALSE); |
---|
| 544 | } |
---|
| 545 | db.Close(); |
---|
| 546 | |
---|
| 547 | if (!registraCliente(iph)) { // Incluyendo al cliente en la tabla de sokets |
---|
[0a73ecf7] | 548 | liberaMemoria(iph); |
---|
[f679cf0] | 549 | errorLog(modulo, 25, FALSE); |
---|
| 550 | return (25); |
---|
| 551 | } |
---|
[0a73ecf7] | 552 | liberaMemoria(iph); |
---|
[f679cf0] | 553 | return(0); |
---|
| 554 | } |
---|
| 555 | // ________________________________________________________________________________________________________ |
---|
[3ec149c] | 556 | // Función: InclusionCliente |
---|
| 557 | // |
---|
| 558 | // Descripción: |
---|
| 559 | // Esta función incorpora el socket de un nuevo cliente a la tabla de clientes y le devuelve alguna de sus propiedades: |
---|
| 560 | // nombre, identificador, tamaño de la caché , etc ... |
---|
| 561 | // Parámetros: |
---|
| 562 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 563 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 564 | // Devuelve: |
---|
| 565 | // TRUE: Si el proceso es correcto |
---|
| 566 | // FALSE: En caso de ocurrir algún error |
---|
| 567 | // ________________________________________________________________________________________________________ |
---|
| 568 | BOOLEAN InclusionCliente(SOCKET *socket_c, TRAMA *ptrTrama) { |
---|
| 569 | char modulo[] = "InclusionCliente()"; |
---|
| 570 | |
---|
| 571 | if (!procesoInclusionCliente(socket_c, ptrTrama)) { // Ha habido algún error... |
---|
| 572 | initParametros(ptrTrama,0); |
---|
| 573 | strcpy(ptrTrama->parametros, "nfn=RESPUESTA_InclusionCliente\rres=0\r"); |
---|
| 574 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 575 | errorLog(modulo, 26, FALSE); |
---|
| 576 | return (FALSE); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | return (TRUE); |
---|
[f679cf0] | 580 | } |
---|
[3ec149c] | 581 | // ________________________________________________________________________________________________________ |
---|
| 582 | // Función: procesoInclusionCliente |
---|
| 583 | // |
---|
| 584 | // Descripción: |
---|
| 585 | // Implementa el proceso de inclusión en el sistema del Cliente |
---|
| 586 | // Parámetros: |
---|
| 587 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 588 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 589 | // Devuelve: |
---|
| 590 | // TRUE: Si el proceso es correcto |
---|
| 591 | // FALSE: En caso de ocurrir algún error |
---|
| 592 | // ________________________________________________________________________________________________________ |
---|
| 593 | BOOLEAN procesoInclusionCliente(SOCKET *socket_c, TRAMA *ptrTrama) { |
---|
| 594 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 595 | Database db; |
---|
| 596 | Table tbl; |
---|
| 597 | |
---|
| 598 | char *iph, *cfg; |
---|
| 599 | char nombreordenador[LONFIL]; |
---|
| 600 | int lon, resul, idordenador, idmenu, cache, idproautoexec, idaula, idcentro; |
---|
[f679cf0] | 601 | char modulo[] = "procesoInclusionCliente()"; |
---|
[3ec149c] | 602 | |
---|
| 603 | // Toma parámetros |
---|
| 604 | iph = copiaParametro("iph",ptrTrama); // Toma ip |
---|
| 605 | cfg = copiaParametro("cfg",ptrTrama); // Toma configuracion |
---|
| 606 | |
---|
| 607 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexión con la BD |
---|
| 608 | errorLog(modulo, 20, FALSE); |
---|
| 609 | db.GetErrorErrStr(msglog); |
---|
| 610 | errorInfo(modulo, msglog); |
---|
| 611 | return (FALSE); |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | // Recupera los datos del cliente |
---|
| 615 | sprintf(sqlstr, |
---|
| 616 | "SELECT ordenadores.*,aulas.idaula,centros.idcentro FROM ordenadores " |
---|
| 617 | " INNER JOIN aulas ON aulas.idaula=ordenadores.idaula" |
---|
| 618 | " INNER JOIN centros ON centros.idcentro=aulas.idcentro" |
---|
| 619 | " WHERE ordenadores.ip = '%s'", iph); |
---|
| 620 | |
---|
| 621 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 622 | errorLog(modulo, 21, FALSE); |
---|
| 623 | db.GetErrorErrStr(msglog); |
---|
| 624 | errorInfo(modulo, msglog); |
---|
| 625 | return (FALSE); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | if (tbl.ISEOF()) { // Si no existe el cliente |
---|
| 629 | errorLog(modulo, 22, FALSE); |
---|
| 630 | return (FALSE); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | if (ndebug == DEBUG_ALTO) { |
---|
| 634 | sprintf(msglog, "%s IP:%s", tbMensajes[2], iph); |
---|
| 635 | infoDebug(msglog); |
---|
| 636 | } |
---|
| 637 | if (!tbl.Get("idordenador", idordenador)) { |
---|
| 638 | tbl.GetErrorErrStr(msglog); |
---|
| 639 | errorInfo(modulo, msglog); |
---|
| 640 | return (FALSE); |
---|
| 641 | } |
---|
| 642 | if (!tbl.Get("nombreordenador", nombreordenador)) { |
---|
| 643 | tbl.GetErrorErrStr(msglog); |
---|
| 644 | errorInfo(modulo, msglog); |
---|
| 645 | return (FALSE); |
---|
| 646 | } |
---|
| 647 | if (!tbl.Get("idmenu", idmenu)) { |
---|
| 648 | tbl.GetErrorErrStr(msglog); |
---|
| 649 | errorInfo(modulo, msglog); |
---|
| 650 | return (FALSE); |
---|
| 651 | } |
---|
| 652 | if (!tbl.Get("cache", cache)) { |
---|
| 653 | tbl.GetErrorErrStr(msglog); |
---|
| 654 | errorInfo(modulo, msglog); |
---|
| 655 | return (FALSE); |
---|
| 656 | } |
---|
| 657 | if (!tbl.Get("idproautoexec", idproautoexec)) { |
---|
| 658 | tbl.GetErrorErrStr(msglog); |
---|
| 659 | errorInfo(modulo, msglog); |
---|
| 660 | return (FALSE); |
---|
| 661 | } |
---|
| 662 | if (!tbl.Get("idaula", idaula)) { |
---|
| 663 | tbl.GetErrorErrStr(msglog); |
---|
| 664 | errorInfo(modulo, msglog); |
---|
| 665 | return (FALSE); |
---|
| 666 | } |
---|
| 667 | if (!tbl.Get("idcentro", idcentro)) { |
---|
| 668 | tbl.GetErrorErrStr(msglog); |
---|
| 669 | errorInfo(modulo, msglog); |
---|
| 670 | return (FALSE); |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | resul = actualizaConfiguracion(db, tbl, cfg, idordenador); // Actualiza la configuración del ordenador |
---|
[0a73ecf7] | 674 | liberaMemoria(cfg); |
---|
[3ec149c] | 675 | db.Close(); |
---|
| 676 | |
---|
| 677 | if (!resul) { |
---|
[0a73ecf7] | 678 | liberaMemoria(iph); |
---|
[3ec149c] | 679 | errorLog(modulo, 29, FALSE); |
---|
| 680 | return (FALSE); |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | if (!registraCliente(iph)) { // Incluyendo al cliente en la tabla de sokets |
---|
[0a73ecf7] | 684 | liberaMemoria(iph); |
---|
[3ec149c] | 685 | errorLog(modulo, 25, FALSE); |
---|
| 686 | return (FALSE); |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | /*------------------------------------------------------------------------------------------------------------------------------ |
---|
| 690 | Prepara la trama de respuesta |
---|
| 691 | -------------------------------------------------------------------------------------------------------------------------------*/ |
---|
| 692 | initParametros(ptrTrama,0); |
---|
| 693 | ptrTrama->tipo=MSG_RESPUESTA; |
---|
| 694 | lon = sprintf(ptrTrama->parametros, "nfn=RESPUESTA_InclusionCliente\r"); |
---|
| 695 | lon += sprintf(ptrTrama->parametros + lon, "ido=%d\r", idordenador); |
---|
| 696 | lon += sprintf(ptrTrama->parametros + lon, "npc=%s\r", nombreordenador); |
---|
| 697 | lon += sprintf(ptrTrama->parametros + lon, "che=%d\r", cache); |
---|
| 698 | lon += sprintf(ptrTrama->parametros + lon, "exe=%d\r", idproautoexec); |
---|
| 699 | lon += sprintf(ptrTrama->parametros + lon, "ida=%d\r", idaula); |
---|
| 700 | lon += sprintf(ptrTrama->parametros + lon, "idc=%d\r", idcentro); |
---|
| 701 | lon += sprintf(ptrTrama->parametros + lon, "res=%d\r", 1); // Confirmación proceso correcto |
---|
| 702 | |
---|
| 703 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 704 | errorLog(modulo, 26, FALSE); |
---|
| 705 | return (FALSE); |
---|
| 706 | } |
---|
[0a73ecf7] | 707 | liberaMemoria(iph); |
---|
[3ec149c] | 708 | return (TRUE); |
---|
| 709 | } |
---|
| 710 | // ________________________________________________________________________________________________________ |
---|
| 711 | // Función: actualizaConfiguracion |
---|
| 712 | // |
---|
| 713 | // Descripción: |
---|
| 714 | // Esta función actualiza la base de datos con la configuracion de particiones de un cliente |
---|
| 715 | // Parámetros: |
---|
| 716 | // - db: Objeto base de datos (ya operativo) |
---|
| 717 | // - tbl: Objeto tabla |
---|
| 718 | // - cfg: cadena con una Configuración |
---|
| 719 | // - ido: Identificador del ordenador cliente |
---|
| 720 | // Devuelve: |
---|
| 721 | // TRUE: Si el proceso es correcto |
---|
| 722 | // FALSE: En caso de ocurrir algún error |
---|
| 723 | // Especificaciones: |
---|
| 724 | // Los parametros de la configuración son: |
---|
| 725 | // par= Número de partición |
---|
| 726 | // cpt= Codigo o tipo de partición |
---|
| 727 | // sfi= Sistema de ficheros que está implementado en la partición |
---|
| 728 | // soi= Nombre del sistema de ficheros instalado en la partición |
---|
| 729 | // tam= Tamaño de la partición |
---|
| 730 | // ________________________________________________________________________________________________________ |
---|
| 731 | BOOLEAN actualizaConfiguracion(Database db, Table tbl, char* cfg, int ido) |
---|
| 732 | { |
---|
| 733 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 734 | int lon, p, c, i, dato, swu, idsoi, idsfi,k; |
---|
[ba98026] | 735 | char *ptrPar[MAXPAR], *ptrCfg[6], *ptrDual[2], tbPar[LONSTD]; |
---|
| 736 | char *disk, *par, *cpt, *sfi, *soi, *tam; // Parametros que definen una partición |
---|
[3ec149c] | 737 | char modulo[] = "actualizaConfiguracion()"; |
---|
| 738 | |
---|
| 739 | lon = sprintf(tbPar, "("); |
---|
| 740 | p = splitCadena(ptrPar, cfg, '\n'); |
---|
| 741 | for (i = 0; i < p; i++) { |
---|
| 742 | c = splitCadena(ptrCfg, ptrPar[i], '\t'); |
---|
[ba98026] | 743 | disk = par = cpt = sfi = soi = tam = NULL; |
---|
[3ec149c] | 744 | splitCadena(ptrDual, ptrCfg[0], '='); |
---|
[ba98026] | 745 | disk = ptrDual[1]; // Número de disco |
---|
[3ec149c] | 746 | |
---|
| 747 | splitCadena(ptrDual, ptrCfg[1], '='); |
---|
[ba98026] | 748 | par = ptrDual[1]; // Número de partición |
---|
| 749 | |
---|
| 750 | splitCadena(ptrDual, ptrCfg[2], '='); |
---|
[3ec149c] | 751 | cpt = ptrDual[1]; // Código de partición |
---|
| 752 | |
---|
[ba98026] | 753 | k=splitCadena(ptrDual, ptrCfg[3], '='); |
---|
[3ec149c] | 754 | if(k==2){ |
---|
| 755 | sfi = ptrDual[1]; // Sistema de ficheros |
---|
[0a73ecf7] | 756 | /* Comprueba existencia del s0xistema de ficheros instalado */ |
---|
[3ec149c] | 757 | idsfi = checkDato(db, tbl, sfi, "sistemasficheros", "descripcion","idsistemafichero"); |
---|
| 758 | } |
---|
| 759 | else |
---|
| 760 | idsfi=0; |
---|
| 761 | |
---|
[ba98026] | 762 | k=splitCadena(ptrDual, ptrCfg[4], '='); |
---|
[3ec149c] | 763 | if(k==2){ // Sistema operativo detecdtado |
---|
| 764 | soi = ptrDual[1]; // Nombre del S.O. instalado |
---|
| 765 | /* Comprueba existencia del sistema operativo instalado */ |
---|
| 766 | idsoi = checkDato(db, tbl, soi, "nombresos", "nombreso", "idnombreso"); |
---|
| 767 | } |
---|
| 768 | else |
---|
| 769 | idsoi=0; |
---|
| 770 | |
---|
[ba98026] | 771 | splitCadena(ptrDual, ptrCfg[5], '='); |
---|
[3ec149c] | 772 | tam = ptrDual[1]; // Tamaño de la partición |
---|
| 773 | |
---|
| 774 | lon += sprintf(tbPar + lon, "%s,", par); |
---|
| 775 | |
---|
[ba98026] | 776 | sprintf(sqlstr, "SELECT numdisk,numpar,codpar,tamano,idsistemafichero,idnombreso" |
---|
| 777 | " FROM ordenadores_particiones WHERE idordenador=%d AND numdisk=%s AND numpar=%s", |
---|
| 778 | ido, disk, par); |
---|
[3ec149c] | 779 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 780 | errorLog(modulo, 21, FALSE); |
---|
| 781 | db.GetErrorErrStr(msglog); |
---|
| 782 | errorInfo(modulo, msglog); |
---|
| 783 | return (FALSE); |
---|
| 784 | } |
---|
| 785 | if (tbl.ISEOF()) { // Si no existe el registro |
---|
[ba98026] | 786 | sprintf(sqlstr, "INSERT INTO ordenadores_particiones(idordenador,numdisk,numpar,codpar,tamano,idsistemafichero,idnombreso,idimagen)" |
---|
| 787 | " VALUES(%d,%s,%s,0x%s,%s,%d,%d,0)", |
---|
| 788 | ido, disk, par, cpt, tam, idsfi, idsoi); |
---|
[3ec149c] | 789 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 790 | db.GetErrorErrStr(msglog); |
---|
| 791 | errorInfo(modulo, msglog); |
---|
| 792 | return (FALSE); |
---|
| 793 | } |
---|
| 794 | } else { // Existe el registro |
---|
| 795 | swu = TRUE; // Se supone que algún dato ha cambiado |
---|
| 796 | if (!tbl.Get("codpar", dato)) { // Toma dato |
---|
| 797 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 798 | errorInfo(modulo, msglog); |
---|
| 799 | return (FALSE); |
---|
| 800 | } |
---|
| 801 | if (atoi(cpt) == dato) {// Parámetro tipo de partición igual al almacenado |
---|
| 802 | if (!tbl.Get("tamano", dato)) { // Toma dato |
---|
| 803 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 804 | errorInfo(modulo, msglog); |
---|
| 805 | return (FALSE); |
---|
| 806 | } |
---|
| 807 | if (atoi(tam) == dato) {// Parámetro tamaño igual al almacenado |
---|
| 808 | if (!tbl.Get("idsistemafichero", dato)) { // Toma dato |
---|
| 809 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 810 | errorInfo(modulo, msglog); |
---|
| 811 | return (FALSE); |
---|
| 812 | } |
---|
| 813 | if (idsfi == dato) {// Parámetro sistema de fichero igual al almacenado |
---|
| 814 | if (!tbl.Get("idnombreso", dato)) { // Toma dato |
---|
| 815 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 816 | errorInfo(modulo, msglog); |
---|
| 817 | return (FALSE); |
---|
| 818 | } |
---|
| 819 | if (idsoi == dato) {// Parámetro sistema de fichero distinto al almacenado |
---|
| 820 | swu = FALSE; // Todos los parámetros de la partición son iguales, no se actualiza |
---|
| 821 | } |
---|
| 822 | } |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | if (swu) { // Hay que actualizar los parámetros de la partición |
---|
| 826 | sprintf(sqlstr, "UPDATE ordenadores_particiones SET " |
---|
| 827 | " codpar=0x%s," |
---|
| 828 | " tamano=%s," |
---|
| 829 | " idsistemafichero=%d," |
---|
| 830 | " idnombreso=%d," |
---|
| 831 | " idimagen=%d," |
---|
| 832 | " idperfilsoft=%d" |
---|
[ba98026] | 833 | " WHERE idordenador=%d AND numdisk=%s AND numpar=%s", |
---|
| 834 | cpt, tam, idsfi, idsoi, 0, 0, ido, disk, par); |
---|
[3ec149c] | 835 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 836 | errorLog(modulo, 21, FALSE); |
---|
| 837 | db.GetErrorErrStr(msglog); |
---|
| 838 | errorInfo(modulo, msglog); |
---|
| 839 | return (FALSE); |
---|
| 840 | } |
---|
| 841 | } |
---|
| 842 | } |
---|
| 843 | } |
---|
| 844 | lon += sprintf(tbPar + lon, "%d)", 0); |
---|
| 845 | // Eliminar particiones almacenadas que ya no existen |
---|
[ba98026] | 846 | sprintf(sqlstr, "DELETE FROM ordenadores_particiones WHERE idordenador=%d AND numdisk=%s AND numpar NOT IN %s", |
---|
| 847 | ido, disk, tbPar); |
---|
[3ec149c] | 848 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 849 | errorLog(modulo, 21, FALSE); |
---|
| 850 | db.GetErrorErrStr(msglog); |
---|
| 851 | errorInfo(modulo, msglog); |
---|
| 852 | return (FALSE); |
---|
| 853 | } |
---|
| 854 | return (TRUE); |
---|
| 855 | } |
---|
| 856 | // ________________________________________________________________________________________________________ |
---|
| 857 | // Función: checkDato |
---|
| 858 | // |
---|
| 859 | // Descripción: |
---|
| 860 | // Esta función comprueba si existe un dato en una tabla y si no es así lo incluye. devuelve en |
---|
| 861 | // cualquier caso el identificador del registro existenet o del insertado |
---|
| 862 | // Parámetros: |
---|
| 863 | // - db: Objeto base de datos (ya operativo) |
---|
| 864 | // - tbl: Objeto tabla |
---|
| 865 | // - dato: Dato |
---|
| 866 | // - tabla: Nombre de la tabla |
---|
| 867 | // - nomdato: Nombre del dato en la tabla |
---|
| 868 | // - nomidentificador: Nombre del identificador en la tabla |
---|
| 869 | // Devuelve: |
---|
| 870 | // El identificador del registro existente o el del insertado |
---|
| 871 | // |
---|
| 872 | // Especificaciones: |
---|
| 873 | // En caso de producirse algún error se devuelve el valor 0 |
---|
| 874 | // ________________________________________________________________________________________________________ |
---|
| 875 | |
---|
| 876 | int checkDato(Database db, Table tbl, char *dato, const char*tabla, |
---|
| 877 | const char* nomdato, const char *nomidentificador) { |
---|
| 878 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 879 | char modulo[] = "checkDato()"; |
---|
| 880 | int identificador; |
---|
| 881 | |
---|
| 882 | if (strlen(dato) == 0) |
---|
| 883 | return (0); // EL dato no tiene valor |
---|
| 884 | sprintf(sqlstr, "SELECT %s FROM %s WHERE %s ='%s'", nomidentificador, |
---|
| 885 | tabla, nomdato, dato); |
---|
| 886 | |
---|
| 887 | // Ejecuta consulta |
---|
| 888 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 889 | errorLog(modulo, 21, FALSE); |
---|
| 890 | db.GetErrorErrStr(msglog); |
---|
| 891 | errorInfo(modulo, msglog); |
---|
| 892 | return (0); |
---|
| 893 | } |
---|
| 894 | if (tbl.ISEOF()) { // Software NO existente |
---|
[df052e1] | 895 | sprintf(sqlstr, "INSERT INTO %s (%s) VALUES('%s')", tabla, nomdato, dato); |
---|
[3ec149c] | 896 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 897 | db.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 898 | errorInfo(modulo, msglog); |
---|
| 899 | return (0); |
---|
| 900 | } |
---|
| 901 | // Recupera el identificador del software |
---|
| 902 | sprintf(sqlstr, "SELECT LAST_INSERT_ID() as identificador"); |
---|
| 903 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 904 | db.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 905 | errorInfo(modulo, msglog); |
---|
| 906 | return (0); |
---|
| 907 | } |
---|
| 908 | if (!tbl.ISEOF()) { // Si existe registro |
---|
| 909 | if (!tbl.Get("identificador", identificador)) { |
---|
| 910 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 911 | errorInfo(modulo, msglog); |
---|
| 912 | return (0); |
---|
| 913 | } |
---|
| 914 | } |
---|
| 915 | } else { |
---|
| 916 | if (!tbl.Get(nomidentificador, identificador)) { // Toma dato |
---|
| 917 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 918 | errorInfo(modulo, msglog); |
---|
| 919 | return (0); |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | return (identificador); |
---|
| 923 | } |
---|
| 924 | // ________________________________________________________________________________________________________ |
---|
| 925 | // Función: registraCliente |
---|
| 926 | // |
---|
| 927 | // Descripción: |
---|
| 928 | // Incluye al cliente en la tabla de sokets |
---|
| 929 | // Parámetros: |
---|
| 930 | // - iph: Dirección ip del cliente |
---|
| 931 | // Devuelve: |
---|
| 932 | // TRUE: Si el proceso es correcto |
---|
| 933 | // FALSE: En caso de ocurrir algún error |
---|
| 934 | // ________________________________________________________________________________________________________ |
---|
| 935 | BOOLEAN registraCliente(char *iph) { |
---|
| 936 | int idx; |
---|
| 937 | |
---|
| 938 | if (!clienteExistente(iph, &idx)) { // Si no existe la IP ... |
---|
| 939 | if (!hayHueco(&idx)) { // Busca hueco para el nuevo cliente |
---|
| 940 | return (FALSE); // No hay huecos |
---|
| 941 | } |
---|
| 942 | } |
---|
| 943 | strcpy(tbsockets[idx].ip, iph); // Copia IP |
---|
| 944 | strcpy(tbsockets[idx].estado, CLIENTE_INICIANDO); // Actualiza el estado del cliente |
---|
| 945 | return (TRUE); |
---|
| 946 | } |
---|
| 947 | // ________________________________________________________________________________________________________ |
---|
| 948 | // Función: AutoexecCliente |
---|
| 949 | // |
---|
| 950 | // Descripción: |
---|
| 951 | // Envía archivo de autoexec al cliente |
---|
| 952 | // Parámetros: |
---|
| 953 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 954 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 955 | // Devuelve: |
---|
| 956 | // TRUE: Si el proceso es correcto |
---|
| 957 | // FALSE: En caso de ocurrir algún error |
---|
| 958 | // ________________________________________________________________________________________________________ |
---|
| 959 | BOOLEAN AutoexecCliente(SOCKET *socket_c, TRAMA *ptrTrama) { |
---|
| 960 | int lon; |
---|
| 961 | char *iph, *exe, msglog[LONSTD]; |
---|
| 962 | Database db; |
---|
| 963 | FILE *fileexe; |
---|
| 964 | char fileautoexec[LONPRM]; |
---|
| 965 | char parametros[LONGITUD_PARAMETROS]; |
---|
| 966 | char modulo[] = "AutoexecCliente()"; |
---|
| 967 | |
---|
| 968 | iph = copiaParametro("iph",ptrTrama); // Toma dirección IP del cliente |
---|
| 969 | exe = copiaParametro("exe",ptrTrama); // Toma identificador del procedimiento inicial |
---|
| 970 | |
---|
| 971 | sprintf(fileautoexec, "/tmp/Sautoexec-%s", iph); |
---|
[0a73ecf7] | 972 | liberaMemoria(iph); |
---|
[3ec149c] | 973 | fileexe = fopen(fileautoexec, "wb"); // Abre fichero de script |
---|
| 974 | if (fileexe == NULL) { |
---|
| 975 | errorLog(modulo, 52, FALSE); |
---|
| 976 | return (FALSE); |
---|
| 977 | } |
---|
| 978 | |
---|
| 979 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexión con la BD |
---|
| 980 | errorLog(modulo, 20, FALSE); |
---|
| 981 | db.GetErrorErrStr(msglog); |
---|
| 982 | errorInfo(modulo, msglog); |
---|
| 983 | return (FALSE); |
---|
| 984 | } |
---|
| 985 | initParametros(ptrTrama,0); |
---|
| 986 | if (recorreProcedimientos(db, parametros, fileexe, exe)) { |
---|
| 987 | lon = sprintf(ptrTrama->parametros, "nfn=RESPUESTA_AutoexecCliente\r"); |
---|
| 988 | lon += sprintf(ptrTrama->parametros + lon, "nfl=%s\r", fileautoexec); |
---|
| 989 | lon += sprintf(ptrTrama->parametros + lon, "res=1\r"); |
---|
| 990 | } else { |
---|
| 991 | lon = sprintf(ptrTrama->parametros, "nfn=RESPUESTA_AutoexecCliente\r"); |
---|
| 992 | lon += sprintf(ptrTrama->parametros + lon, "res=0\r"); |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | fclose(fileexe); |
---|
| 996 | |
---|
| 997 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
[0a73ecf7] | 998 | liberaMemoria(exe); |
---|
[3ec149c] | 999 | errorLog(modulo, 26, FALSE); |
---|
| 1000 | return (FALSE); |
---|
| 1001 | } |
---|
[0a73ecf7] | 1002 | liberaMemoria(exe); |
---|
[3ec149c] | 1003 | return (TRUE); |
---|
| 1004 | } |
---|
| 1005 | // ________________________________________________________________________________________________________ |
---|
| 1006 | // Función: recorreProcedimientos |
---|
| 1007 | // |
---|
| 1008 | // Descripción: |
---|
| 1009 | // Crea un archivo con el código de un procedimiento separando cada comando por un salto de linea |
---|
| 1010 | // Parámetros: |
---|
| 1011 | // Database db,char* parametros,FILE* fileexe,char* idp |
---|
| 1012 | // Devuelve: |
---|
| 1013 | // TRUE: Si el proceso es correcto |
---|
| 1014 | // FALSE: En caso de ocurrir algún error |
---|
| 1015 | // ________________________________________________________________________________________________________ |
---|
| 1016 | BOOLEAN recorreProcedimientos(Database db, char* parametros, FILE* fileexe, |
---|
| 1017 | char* idp) { |
---|
| 1018 | int procedimientoid, lsize; |
---|
| 1019 | char idprocedimiento[LONPRM], msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 1020 | Table tbl; |
---|
| 1021 | char modulo[] = "recorreProcedimientos()"; |
---|
| 1022 | |
---|
| 1023 | /* Busca procedimiento */ |
---|
| 1024 | sprintf(sqlstr, |
---|
| 1025 | "SELECT procedimientoid,parametros FROM procedimientos_acciones" |
---|
| 1026 | " WHERE idprocedimiento=%s ORDER BY orden", idp); |
---|
| 1027 | // Ejecuta consulta |
---|
| 1028 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 1029 | errorLog(modulo, 21, FALSE); |
---|
| 1030 | db.GetErrorErrStr(msglog); |
---|
| 1031 | errorInfo(modulo, msglog); |
---|
| 1032 | return (FALSE); |
---|
| 1033 | } |
---|
| 1034 | while (!tbl.ISEOF()) { // Recorre procedimientos |
---|
| 1035 | if (!tbl.Get("procedimientoid", procedimientoid)) { // Toma dato |
---|
| 1036 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1037 | errorInfo(modulo, msglog); |
---|
| 1038 | return (FALSE); |
---|
| 1039 | } |
---|
| 1040 | if (procedimientoid > 0) { // Procedimiento recursivo |
---|
| 1041 | sprintf(idprocedimiento, "%d", procedimientoid); |
---|
| 1042 | if (!recorreProcedimientos(db, parametros, fileexe, idprocedimiento)) { |
---|
| 1043 | return (FALSE); |
---|
| 1044 | } |
---|
| 1045 | } else { |
---|
| 1046 | if (!tbl.Get("parametros", parametros)) { // Toma dato |
---|
| 1047 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1048 | errorInfo(modulo, msglog); |
---|
| 1049 | return (FALSE); |
---|
| 1050 | } |
---|
| 1051 | strcat(parametros, "@"); |
---|
| 1052 | lsize = strlen(parametros); |
---|
| 1053 | fwrite(parametros, 1, lsize, fileexe); // Escribe el código a ejecutar |
---|
| 1054 | } |
---|
| 1055 | tbl.MoveNext(); |
---|
| 1056 | } |
---|
| 1057 | return (TRUE); |
---|
| 1058 | } |
---|
| 1059 | // ________________________________________________________________________________________________________ |
---|
| 1060 | // Función: ComandosPendientes |
---|
| 1061 | // |
---|
| 1062 | // Descripción: |
---|
| 1063 | // Esta función busca en la base de datos,comandos pendientes de ejecutar por un ordenador concreto |
---|
| 1064 | // Parámetros: |
---|
| 1065 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1066 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1067 | // Devuelve: |
---|
| 1068 | // TRUE: Si el proceso es correcto |
---|
| 1069 | // FALSE: En caso de ocurrir algún error |
---|
| 1070 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 1071 | BOOLEAN ComandosPendientes(SOCKET *socket_c, TRAMA *ptrTrama) |
---|
| 1072 | { |
---|
| 1073 | char *ido,*iph,pids[LONPRM]; |
---|
[3ec149c] | 1074 | int ids, idx; |
---|
| 1075 | char modulo[] = "ComandosPendientes()"; |
---|
| 1076 | |
---|
[0a73ecf7] | 1077 | iph = copiaParametro("iph",ptrTrama); // Toma dirección IP |
---|
[3ec149c] | 1078 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1079 | |
---|
| 1080 | if (!clienteExistente(iph, &idx)) { // Busca índice del cliente |
---|
[0a73ecf7] | 1081 | liberaMemoria(iph); |
---|
| 1082 | liberaMemoria(ido); |
---|
[3ec149c] | 1083 | errorLog(modulo, 47, FALSE); |
---|
| 1084 | return (FALSE); |
---|
| 1085 | } |
---|
| 1086 | if (buscaComandos(ido, ptrTrama, &ids)) { // Existen comandos pendientes |
---|
| 1087 | ptrTrama->tipo = MSG_COMANDO; |
---|
| 1088 | sprintf(pids, "\rids=%d\r", ids); |
---|
| 1089 | strcat(ptrTrama->parametros, pids); |
---|
| 1090 | strcpy(tbsockets[idx].estado, CLIENTE_OCUPADO); |
---|
| 1091 | } else { |
---|
| 1092 | initParametros(ptrTrama,0); |
---|
| 1093 | strcpy(ptrTrama->parametros, "nfn=NoComandosPtes\r"); |
---|
| 1094 | } |
---|
| 1095 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
[0a73ecf7] | 1096 | liberaMemoria(iph); |
---|
| 1097 | liberaMemoria(ido); |
---|
[3ec149c] | 1098 | errorLog(modulo, 26, FALSE); |
---|
| 1099 | return (FALSE); |
---|
| 1100 | } |
---|
[0a73ecf7] | 1101 | liberaMemoria(iph); |
---|
| 1102 | liberaMemoria(ido); |
---|
[3ec149c] | 1103 | return (TRUE); |
---|
| 1104 | } |
---|
| 1105 | // ________________________________________________________________________________________________________ |
---|
| 1106 | // Función: buscaComandos |
---|
| 1107 | // |
---|
| 1108 | // Descripción: |
---|
| 1109 | // Busca en la base de datos,comandos pendientes de ejecutar por el cliente |
---|
| 1110 | // Parámetros: |
---|
| 1111 | // - ido: Identificador del ordenador |
---|
| 1112 | // - cmd: Parámetros del comando (Salida) |
---|
[0a73ecf7] | 1113 | // - ids: Identificador de la sesion(Salida) |
---|
[3ec149c] | 1114 | // Devuelve: |
---|
| 1115 | // TRUE: Si el proceso es correcto |
---|
| 1116 | // FALSE: En caso de ocurrir algún error |
---|
| 1117 | // ________________________________________________________________________________________________________ |
---|
| 1118 | BOOLEAN buscaComandos(char *ido, TRAMA *ptrTrama, int *ids) |
---|
| 1119 | { |
---|
| 1120 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 1121 | Database db; |
---|
| 1122 | Table tbl; |
---|
| 1123 | int lonprm; |
---|
| 1124 | |
---|
| 1125 | char modulo[] = "buscaComandos()"; |
---|
| 1126 | |
---|
| 1127 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexión con la BD |
---|
| 1128 | errorLog(modulo, 20, FALSE); |
---|
| 1129 | db.GetErrorErrStr(msglog); |
---|
| 1130 | errorInfo(modulo, msglog); |
---|
| 1131 | return (FALSE); |
---|
| 1132 | } |
---|
[0a73ecf7] | 1133 | sprintf(sqlstr,"SELECT sesion,parametros,length( parametros) as lonprm"\ |
---|
[3ec149c] | 1134 | " FROM acciones WHERE idordenador=%s AND estado='%d' ORDER BY idaccion", ido, ACCION_INICIADA); |
---|
| 1135 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 1136 | errorLog(modulo, 21, FALSE); |
---|
| 1137 | db.GetErrorErrStr(msglog); |
---|
| 1138 | errorInfo(modulo, msglog); |
---|
| 1139 | return (FALSE); |
---|
| 1140 | } |
---|
| 1141 | if (tbl.ISEOF()) { |
---|
| 1142 | db.Close(); |
---|
| 1143 | return (FALSE); // No hay comandos pendientes |
---|
| 1144 | } else { // Busca entre todas las acciones de diversos ambitos |
---|
[0a73ecf7] | 1145 | if (!tbl.Get("sesion", *ids)) { // Toma identificador de la sesion |
---|
[3ec149c] | 1146 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1147 | errorInfo(modulo, msglog); |
---|
| 1148 | return (FALSE); |
---|
| 1149 | } |
---|
| 1150 | if (!tbl.Get("lonprm", lonprm)) { // Toma parámetros del comando |
---|
| 1151 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1152 | errorInfo(modulo, msglog); |
---|
| 1153 | return (FALSE); |
---|
| 1154 | } |
---|
| 1155 | if(!initParametros(ptrTrama,lonprm+LONGITUD_PARAMETROS)){ |
---|
| 1156 | db.Close(); |
---|
| 1157 | errorLog(modulo, 3, FALSE); |
---|
| 1158 | return (FALSE); |
---|
| 1159 | } |
---|
| 1160 | if (!tbl.Get("parametros", ptrTrama->parametros)) { // Toma parámetros del comando |
---|
| 1161 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1162 | errorInfo(modulo, msglog); |
---|
| 1163 | return (FALSE); |
---|
| 1164 | } |
---|
| 1165 | } |
---|
| 1166 | db.Close(); |
---|
| 1167 | return (TRUE); // Hay comandos pendientes, se toma el primero de la cola |
---|
| 1168 | } |
---|
| 1169 | // ________________________________________________________________________________________________________ |
---|
| 1170 | // Función: DisponibilidadComandos |
---|
| 1171 | // |
---|
| 1172 | // Descripción: |
---|
| 1173 | // Esta función habilita a un cliente para recibir comandos desde la consola |
---|
| 1174 | // Parámetros: |
---|
| 1175 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1176 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1177 | // Devuelve: |
---|
| 1178 | // TRUE: Si el proceso es correcto |
---|
| 1179 | // FALSE: En caso de ocurrir algún error |
---|
| 1180 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 1181 | // |
---|
| 1182 | BOOLEAN DisponibilidadComandos(SOCKET *socket_c, TRAMA *ptrTrama) |
---|
| 1183 | { |
---|
| 1184 | char *iph, *tpc; |
---|
[3ec149c] | 1185 | int idx; |
---|
| 1186 | char modulo[] = "DisponibilidadComandos()"; |
---|
| 1187 | |
---|
[0a73ecf7] | 1188 | iph = copiaParametro("iph",ptrTrama); // Toma ip |
---|
[3ec149c] | 1189 | if (!clienteExistente(iph, &idx)) { // Busca índice del cliente |
---|
[0a73ecf7] | 1190 | liberaMemoria(iph); |
---|
[3ec149c] | 1191 | errorLog(modulo, 47, FALSE); |
---|
| 1192 | return (FALSE); |
---|
| 1193 | } |
---|
[0a73ecf7] | 1194 | tpc = copiaParametro("tpc",ptrTrama); // Tipo de cliente (Plataforma y S.O.) |
---|
[3ec149c] | 1195 | strcpy(tbsockets[idx].estado, tpc); |
---|
| 1196 | tbsockets[idx].sock = *socket_c; |
---|
| 1197 | swcSocket = TRUE; // El socket permanece abierto para recibir comandos desde el servidor |
---|
[0a73ecf7] | 1198 | liberaMemoria(iph); |
---|
| 1199 | liberaMemoria(tpc); |
---|
[3ec149c] | 1200 | return (TRUE); |
---|
| 1201 | } |
---|
| 1202 | // ________________________________________________________________________________________________________ |
---|
| 1203 | // Función: respuestaEstandar |
---|
| 1204 | // |
---|
| 1205 | // Descripción: |
---|
| 1206 | // Esta función actualiza la base de datos con el resultado de la ejecución de un comando con seguimiento |
---|
| 1207 | // Parámetros: |
---|
| 1208 | // - res: resultado de la ejecución del comando |
---|
| 1209 | // - der: Descripción del error si hubiese habido |
---|
| 1210 | // - iph: Dirección IP |
---|
[0a73ecf7] | 1211 | // - ids: identificador de la sesión |
---|
[3ec149c] | 1212 | // - ido: Identificador del ordenador que notifica |
---|
| 1213 | // - db: Objeto base de datos (operativo) |
---|
| 1214 | // - tbl: Objeto tabla |
---|
| 1215 | // Devuelve: |
---|
| 1216 | // TRUE: Si el proceso es correcto |
---|
| 1217 | // FALSE: En caso de ocurrir algún error |
---|
| 1218 | // ________________________________________________________________________________________________________ |
---|
| 1219 | BOOLEAN respuestaEstandar(TRAMA *ptrTrama, char *iph, char *ido, Database db, |
---|
| 1220 | Table tbl) { |
---|
| 1221 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 1222 | char *res, *ids, *der; |
---|
| 1223 | char fechafin[LONPRM]; |
---|
| 1224 | struct tm* st; |
---|
[0a73ecf7] | 1225 | int idaccion; |
---|
[3ec149c] | 1226 | char modulo[] = "respuestaEstandar()"; |
---|
| 1227 | |
---|
| 1228 | ids = copiaParametro("ids",ptrTrama); // Toma identificador de la sesión |
---|
| 1229 | |
---|
| 1230 | if (ids == NULL) // No existe seguimiento de la acción |
---|
| 1231 | return (TRUE); |
---|
[0a73ecf7] | 1232 | |
---|
| 1233 | if (atoi(ids) == 0){ // No existe seguimiento de la acción |
---|
| 1234 | liberaMemoria(ids); |
---|
| 1235 | return (TRUE); |
---|
| 1236 | } |
---|
[3ec149c] | 1237 | |
---|
| 1238 | sprintf(sqlstr, |
---|
[0a73ecf7] | 1239 | "SELECT * FROM acciones WHERE idordenador=%s" |
---|
| 1240 | " AND sesion=%s ORDER BY idaccion", ido,ids); |
---|
| 1241 | |
---|
| 1242 | liberaMemoria(ids); |
---|
| 1243 | |
---|
[3ec149c] | 1244 | if (!db.Execute(sqlstr, tbl)) { // Error al consultar |
---|
| 1245 | errorLog(modulo, 21, FALSE); |
---|
| 1246 | db.GetErrorErrStr(msglog); |
---|
| 1247 | errorInfo(modulo, msglog); |
---|
| 1248 | return (FALSE); |
---|
| 1249 | } |
---|
| 1250 | if (tbl.ISEOF()) { // No existe registro de acciones |
---|
| 1251 | errorLog(modulo, 31, FALSE); |
---|
| 1252 | return (TRUE); |
---|
| 1253 | } |
---|
[0a73ecf7] | 1254 | if (!tbl.Get("idaccion", idaccion)) { // Toma identificador de la accion |
---|
| 1255 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1256 | errorInfo(modulo, msglog); |
---|
| 1257 | return (FALSE); |
---|
| 1258 | } |
---|
[3ec149c] | 1259 | st = tomaHora(); |
---|
| 1260 | sprintf(fechafin, "%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1, |
---|
| 1261 | st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec); |
---|
| 1262 | |
---|
[0a73ecf7] | 1263 | res = copiaParametro("res",ptrTrama); // Toma resultado |
---|
| 1264 | der = copiaParametro("der",ptrTrama); // Toma descripción del error (si hubiera habido) |
---|
| 1265 | |
---|
[3ec149c] | 1266 | sprintf( |
---|
| 1267 | sqlstr, |
---|
| 1268 | "UPDATE acciones SET resultado='%s',estado='%d',fechahorafin='%s',descrinotificacion='%s'"\ |
---|
[0a73ecf7] | 1269 | " WHERE idordenador=%s AND idaccion=%d", |
---|
| 1270 | res, ACCION_FINALIZADA, fechafin, der, ido, idaccion); |
---|
| 1271 | |
---|
[3ec149c] | 1272 | if (!db.Execute(sqlstr, tbl)) { // Error al actualizar |
---|
[0a73ecf7] | 1273 | liberaMemoria(res); |
---|
| 1274 | liberaMemoria(der); |
---|
[3ec149c] | 1275 | db.GetErrorErrStr(msglog); |
---|
| 1276 | errorInfo(modulo, msglog); |
---|
| 1277 | return (FALSE); |
---|
| 1278 | } |
---|
[0a73ecf7] | 1279 | |
---|
| 1280 | liberaMemoria(res); |
---|
| 1281 | liberaMemoria(der); |
---|
| 1282 | |
---|
[3ec149c] | 1283 | if (atoi(res) == ACCION_FALLIDA) |
---|
| 1284 | return (FALSE); // Error en la ejecución del comando |
---|
| 1285 | |
---|
| 1286 | return (TRUE); |
---|
| 1287 | } |
---|
| 1288 | // ________________________________________________________________________________________________________ |
---|
| 1289 | // Función: enviaComando |
---|
| 1290 | // |
---|
| 1291 | // Descripción: |
---|
| 1292 | // Envía un comando a los clientes |
---|
| 1293 | // Parámetros: |
---|
| 1294 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1295 | // - estado: Estado en el se deja al cliente mientras se ejecuta el comando |
---|
| 1296 | // Devuelve: |
---|
| 1297 | // TRUE: Si el proceso es correcto |
---|
| 1298 | // FALSE: En caso de ocurrir algún error |
---|
| 1299 | // ________________________________________________________________________________________________________ |
---|
[f679cf0] | 1300 | BOOLEAN enviaComando(TRAMA* ptrTrama, const char *estado) |
---|
| 1301 | { |
---|
[3ec149c] | 1302 | char *iph, *Ipes, *ptrIpes[MAXIMOS_CLIENTES]; |
---|
| 1303 | int i, idx, lon; |
---|
| 1304 | char modulo[] = "enviaComando()"; |
---|
| 1305 | |
---|
| 1306 | iph = copiaParametro("iph",ptrTrama); // Toma dirección/es IP |
---|
| 1307 | lon = strlen(iph); // Calcula longitud de la cadena de direccion/es IPE/S |
---|
| 1308 | Ipes = (char*) reservaMemoria(lon + 1); |
---|
| 1309 | if (Ipes == NULL) { |
---|
| 1310 | errorLog(modulo, 3, FALSE); |
---|
| 1311 | return (FALSE); |
---|
| 1312 | } |
---|
[0a73ecf7] | 1313 | |
---|
[3ec149c] | 1314 | strcpy(Ipes, iph); // Copia cadena de IPES |
---|
[0a73ecf7] | 1315 | liberaMemoria(iph); |
---|
| 1316 | |
---|
[3ec149c] | 1317 | lon = splitCadena(ptrIpes, Ipes, ';'); |
---|
| 1318 | FINCADaINTRO(ptrTrama); |
---|
| 1319 | for (i = 0; i < lon; i++) { |
---|
| 1320 | if (clienteDisponible(ptrIpes[i], &idx)) { // Si el cliente puede recibir comandos |
---|
| 1321 | strcpy(tbsockets[idx].estado, estado); // Actualiza el estado del cliente |
---|
| 1322 | if (!mandaTrama(&tbsockets[idx].sock, ptrTrama)) { |
---|
| 1323 | errorLog(modulo, 26, FALSE); |
---|
| 1324 | return (FALSE); |
---|
| 1325 | } |
---|
| 1326 | close(tbsockets[idx].sock); // Cierra el socket del cliente hasta nueva disponibilidad |
---|
| 1327 | } |
---|
| 1328 | } |
---|
[fc480f2] | 1329 | liberaMemoria(Ipes); |
---|
[3ec149c] | 1330 | return (TRUE); |
---|
| 1331 | } |
---|
| 1332 | //______________________________________________________________________________________________________ |
---|
| 1333 | // Función: respuestaConsola |
---|
| 1334 | // |
---|
| 1335 | // Descripción: |
---|
| 1336 | // Envia una respuesta a la consola sobre el resultado de la ejecución de un comando |
---|
| 1337 | // Parámetros: |
---|
| 1338 | // - socket_c: (Salida) Socket utilizado para el envío |
---|
| 1339 | // - res: Resultado del envío del comando |
---|
| 1340 | // Devuelve: |
---|
| 1341 | // TRUE: Si el proceso es correcto |
---|
| 1342 | // FALSE: En caso de ocurrir algún error |
---|
| 1343 | // ________________________________________________________________________________________________________ |
---|
| 1344 | BOOLEAN respuestaConsola(SOCKET *socket_c, TRAMA *ptrTrama, int res) { |
---|
| 1345 | char modulo[] = "respuestaConsola()"; |
---|
| 1346 | initParametros(ptrTrama,0); |
---|
| 1347 | sprintf(ptrTrama->parametros, "res=%d\r", res); |
---|
| 1348 | if (!mandaTrama(socket_c, ptrTrama)) { |
---|
| 1349 | errorLog(modulo, 26, FALSE); |
---|
| 1350 | return (FALSE); |
---|
| 1351 | } |
---|
| 1352 | return (TRUE); |
---|
| 1353 | } |
---|
| 1354 | // ________________________________________________________________________________________________________ |
---|
| 1355 | // Función: Arrancar |
---|
| 1356 | // |
---|
| 1357 | // Descripción: |
---|
| 1358 | // Procesa el comando Apagar |
---|
| 1359 | // Parámetros: |
---|
| 1360 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1361 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1362 | // Devuelve: |
---|
| 1363 | // TRUE: Si el proceso es correcto |
---|
| 1364 | // FALSE: En caso de ocurrir algún error |
---|
| 1365 | // ________________________________________________________________________________________________________ |
---|
| 1366 | BOOLEAN Arrancar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1367 | char *mac, msglog[LONSTD]; |
---|
| 1368 | char modulo[] = "Arrancar()"; |
---|
| 1369 | |
---|
| 1370 | mac = copiaParametro("mac",ptrTrama); // Toma dirección/es MAC |
---|
| 1371 | if (!Levanta(mac)) { |
---|
[0a73ecf7] | 1372 | liberaMemoria(mac); |
---|
[3ec149c] | 1373 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1374 | errorInfo(modulo, msglog); |
---|
| 1375 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1376 | return (FALSE); |
---|
| 1377 | } |
---|
[0a73ecf7] | 1378 | |
---|
| 1379 | liberaMemoria(mac); |
---|
| 1380 | |
---|
[3ec149c] | 1381 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1382 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1383 | errorInfo(modulo, msglog); |
---|
| 1384 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1385 | return (FALSE); |
---|
| 1386 | } |
---|
| 1387 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1388 | return (TRUE); |
---|
| 1389 | } |
---|
| 1390 | // ________________________________________________________________________________________________________ |
---|
| 1391 | // Función: Levanta |
---|
| 1392 | // |
---|
| 1393 | // Descripción: |
---|
| 1394 | // Enciende ordenadores a través de la red cuyas macs se pasan como parámetro |
---|
| 1395 | // Parámetros: |
---|
| 1396 | // - mac: Cadena de direcciones mac separadas por ";" |
---|
| 1397 | // Devuelve: |
---|
| 1398 | // TRUE: Si el proceso es correcto |
---|
| 1399 | // FALSE: En caso de ocurrir algún error |
---|
| 1400 | // ________________________________________________________________________________________________________ |
---|
| 1401 | BOOLEAN Levanta(char *mac) { |
---|
| 1402 | char *ptrMacs[MAXIMOS_CLIENTES]; |
---|
| 1403 | int i, lon, res; |
---|
| 1404 | SOCKET s; |
---|
| 1405 | BOOLEAN bOpt; |
---|
| 1406 | sockaddr_in local; |
---|
| 1407 | char modulo[] = "Levanta()"; |
---|
| 1408 | |
---|
| 1409 | /* Creación de socket para envío de magig packet */ |
---|
| 1410 | s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
---|
| 1411 | if (s == SOCKET_ERROR) { // Error al crear el socket del servicio |
---|
| 1412 | errorLog(modulo, 13, TRUE); |
---|
| 1413 | return (FALSE); |
---|
| 1414 | } |
---|
| 1415 | bOpt = TRUE; // Pone el socket en modo Broadcast |
---|
| 1416 | res = setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *) &bOpt, sizeof(bOpt)); |
---|
| 1417 | if (res == SOCKET_ERROR) { |
---|
| 1418 | errorLog(modulo, 48, TRUE); |
---|
| 1419 | return (FALSE); |
---|
| 1420 | } |
---|
| 1421 | local.sin_family = AF_INET; |
---|
| 1422 | local.sin_port = htons((short) PUERTO_WAKEUP); |
---|
| 1423 | local.sin_addr.s_addr = htonl(INADDR_ANY); // cualquier interface |
---|
| 1424 | if (bind(s, (sockaddr *) &local, sizeof(local)) == SOCKET_ERROR) { |
---|
| 1425 | errorLog(modulo, 14, TRUE); |
---|
| 1426 | exit(EXIT_FAILURE); |
---|
| 1427 | } |
---|
| 1428 | /* fin creación de socket */ |
---|
| 1429 | lon = splitCadena(ptrMacs, mac, ';'); |
---|
| 1430 | for (i = 0; i < lon; i++) { |
---|
| 1431 | if (!WakeUp(&s, ptrMacs[i])) { |
---|
| 1432 | errorLog(modulo, 49, TRUE); |
---|
| 1433 | close(s); |
---|
| 1434 | return (FALSE); |
---|
| 1435 | } |
---|
| 1436 | } |
---|
| 1437 | close(s); |
---|
| 1438 | return (TRUE); |
---|
| 1439 | } |
---|
| 1440 | //_____________________________________________________________________________________________________________ |
---|
| 1441 | // Función: WakeUp |
---|
| 1442 | // |
---|
| 1443 | // Descripción: |
---|
| 1444 | // Enciende el ordenador cuya MAC se pasa como parámetro |
---|
| 1445 | // Parámetros: |
---|
| 1446 | // - s : Socket para enviar trama magic packet |
---|
| 1447 | // - mac : Cadena con la dirección mac en formato XXXXXXXXXXXX |
---|
| 1448 | // Devuelve: |
---|
| 1449 | // TRUE: Si el proceso es correcto |
---|
| 1450 | // FALSE: En caso de ocurrir algún error |
---|
| 1451 | //_____________________________________________________________________________________________________________ |
---|
| 1452 | BOOLEAN WakeUp(SOCKET *s, char *mac) { |
---|
| 1453 | int i, res; |
---|
| 1454 | char HDaddress_bin[6]; |
---|
| 1455 | struct { |
---|
| 1456 | BYTE secuencia_FF[6]; |
---|
| 1457 | char macbin[16][6]; |
---|
| 1458 | } Trama_WakeUp; |
---|
| 1459 | sockaddr_in WakeUpCliente; |
---|
| 1460 | char modulo[] = "WakeUp()"; |
---|
| 1461 | |
---|
| 1462 | for (i = 0; i < 6; i++) // Primera secuencia de la trama Wake Up (0xFFFFFFFFFFFF) |
---|
| 1463 | Trama_WakeUp.secuencia_FF[i] = 0xFF; |
---|
| 1464 | |
---|
| 1465 | PasaHexBin(mac, HDaddress_bin); // Pasa a binario la MAC |
---|
| 1466 | |
---|
| 1467 | for (i = 0; i < 16; i++) // Segunda secuencia de la trama Wake Up , repetir 16 veces su la MAC |
---|
| 1468 | memcpy(&Trama_WakeUp.macbin[i][0], &HDaddress_bin, 6); |
---|
| 1469 | |
---|
| 1470 | /* Creación de socket del cliente que recibe la trama magic packet */ |
---|
| 1471 | WakeUpCliente.sin_family = AF_INET; |
---|
| 1472 | WakeUpCliente.sin_port = htons((short) PUERTO_WAKEUP); |
---|
| 1473 | WakeUpCliente.sin_addr.s_addr = htonl(INADDR_BROADCAST); // Para hacerlo con broadcast |
---|
| 1474 | |
---|
| 1475 | res = sendto(*s, (char *) &Trama_WakeUp, sizeof(Trama_WakeUp), 0, |
---|
| 1476 | (sockaddr *) &WakeUpCliente, sizeof(WakeUpCliente)); |
---|
| 1477 | if (res == SOCKET_ERROR) { |
---|
| 1478 | errorLog(modulo, 26, FALSE); |
---|
| 1479 | return (FALSE); |
---|
| 1480 | } |
---|
| 1481 | return (TRUE); |
---|
| 1482 | } |
---|
| 1483 | //_____________________________________________________________________________________________________________ |
---|
| 1484 | // Función: PasaHexBin |
---|
| 1485 | // |
---|
| 1486 | // Descripción: |
---|
| 1487 | // Convierte a binario una dirección mac desde una cadena con formato XXXXXXXXXXXX |
---|
| 1488 | // |
---|
| 1489 | // Parámetros de entrada: |
---|
| 1490 | // - cadena : Cadena con el contenido de la mac |
---|
| 1491 | // - numero : la dirección mac convertida a binario (6 bytes) |
---|
| 1492 | //_____________________________________________________________________________________________________________ |
---|
| 1493 | void PasaHexBin(char *cadena, char *numero) { |
---|
| 1494 | int i, j, p; |
---|
| 1495 | char matrizHex[] = "0123456789ABCDEF"; |
---|
| 1496 | char Ucadena[12], aux; |
---|
| 1497 | |
---|
| 1498 | for (i = 0; i < 12; i++) |
---|
| 1499 | Ucadena[i] = toupper(cadena[i]); |
---|
| 1500 | p = 0; |
---|
| 1501 | for (i = 0; i < 12; i++) { |
---|
| 1502 | for (j = 0; j < 16; j++) { |
---|
| 1503 | if (Ucadena[i] == matrizHex[j]) { |
---|
| 1504 | if (i % 2) { |
---|
| 1505 | aux = numero[p]; |
---|
| 1506 | aux = (aux << 4); |
---|
| 1507 | numero[p] = j; |
---|
| 1508 | numero[p] = numero[p] | aux; |
---|
| 1509 | p++; |
---|
| 1510 | } else |
---|
| 1511 | numero[p] = j; |
---|
| 1512 | break; |
---|
| 1513 | } |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | } |
---|
| 1517 | // ________________________________________________________________________________________________________ |
---|
| 1518 | // Función: RESPUESTA_Arrancar |
---|
| 1519 | // |
---|
| 1520 | // Descripción: |
---|
| 1521 | // Respuesta del cliente al comando Apagar |
---|
| 1522 | // Parámetros: |
---|
| 1523 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1524 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1525 | // Devuelve: |
---|
| 1526 | // TRUE: Si el proceso es correcto |
---|
| 1527 | // FALSE: En caso de ocurrir algún error |
---|
| 1528 | // ________________________________________________________________________________________________________ |
---|
| 1529 | BOOLEAN RESPUESTA_Arrancar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1530 | char msglog[LONSTD]; |
---|
| 1531 | Database db; |
---|
| 1532 | Table tbl; |
---|
| 1533 | int i; |
---|
| 1534 | char *iph, *ido; |
---|
| 1535 | char *tpc; |
---|
| 1536 | char modulo[] = "RESPUESTA_Arrancar()"; |
---|
| 1537 | |
---|
| 1538 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1539 | errorLog(modulo, 20, FALSE); |
---|
| 1540 | db.GetErrorErrStr(msglog); |
---|
| 1541 | errorInfo(modulo, msglog); |
---|
| 1542 | return (FALSE); |
---|
| 1543 | } |
---|
| 1544 | |
---|
| 1545 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1546 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1547 | |
---|
| 1548 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1549 | liberaMemoria(iph); |
---|
| 1550 | liberaMemoria(ido); |
---|
[3ec149c] | 1551 | errorLog(modulo, 30, FALSE); |
---|
| 1552 | return (FALSE); // Error al registrar notificacion |
---|
| 1553 | } |
---|
| 1554 | |
---|
| 1555 | tpc = copiaParametro("tpc",ptrTrama); // Tipo de cliente (Plataforma y S.O.) |
---|
| 1556 | if (clienteExistente(iph, &i)) // Actualiza estado |
---|
| 1557 | strcpy(tbsockets[i].estado, tpc); |
---|
[0a73ecf7] | 1558 | |
---|
| 1559 | liberaMemoria(iph); |
---|
| 1560 | liberaMemoria(ido); |
---|
| 1561 | liberaMemoria(tpc); |
---|
| 1562 | |
---|
[3ec149c] | 1563 | db.Close(); // Cierra conexión |
---|
| 1564 | return (TRUE); |
---|
| 1565 | } |
---|
| 1566 | // ________________________________________________________________________________________________________ |
---|
| 1567 | // Función: Comando |
---|
| 1568 | // |
---|
| 1569 | // Descripción: |
---|
| 1570 | // Procesa un comando personalizado |
---|
| 1571 | // Parámetros: |
---|
| 1572 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1573 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1574 | // Devuelve: |
---|
| 1575 | // TRUE: Si el proceso es correcto |
---|
| 1576 | // FALSE: En caso de ocurrir algún error |
---|
| 1577 | // ________________________________________________________________________________________________________ |
---|
| 1578 | BOOLEAN Comando(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1579 | char msglog[LONSTD]; |
---|
| 1580 | char modulo[] = "Comando()"; |
---|
| 1581 | |
---|
| 1582 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1583 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1584 | errorInfo(modulo, msglog); |
---|
| 1585 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1586 | return (FALSE); |
---|
| 1587 | } |
---|
| 1588 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1589 | return (TRUE); |
---|
| 1590 | } |
---|
| 1591 | // ________________________________________________________________________________________________________ |
---|
| 1592 | // Función: RESPUESTA_Comando |
---|
| 1593 | // |
---|
| 1594 | // Descripción: |
---|
| 1595 | // Respuesta del cliente al un comando personalizado |
---|
| 1596 | // Parámetros: |
---|
| 1597 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1598 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1599 | // Devuelve: |
---|
| 1600 | // TRUE: Si el proceso es correcto |
---|
| 1601 | // FALSE: En caso de ocurrir algún error |
---|
| 1602 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 1603 | BOOLEAN RESPUESTA_Comando(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 1604 | { |
---|
[3ec149c] | 1605 | char msglog[LONSTD]; |
---|
| 1606 | Database db; |
---|
| 1607 | Table tbl; |
---|
| 1608 | char *iph, *ido; |
---|
| 1609 | char modulo[] = "RESPUESTA_Comando()"; |
---|
| 1610 | |
---|
| 1611 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1612 | errorLog(modulo, 20, FALSE); |
---|
| 1613 | db.GetErrorErrStr(msglog); |
---|
| 1614 | errorInfo(modulo, msglog); |
---|
| 1615 | return (FALSE); |
---|
| 1616 | } |
---|
| 1617 | |
---|
| 1618 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1619 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1620 | |
---|
| 1621 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1622 | liberaMemoria(iph); |
---|
| 1623 | liberaMemoria(ido); |
---|
[3ec149c] | 1624 | errorLog(modulo, 30, FALSE); |
---|
| 1625 | return (FALSE); // Error al registrar notificacion |
---|
| 1626 | } |
---|
[0a73ecf7] | 1627 | liberaMemoria(iph); |
---|
| 1628 | liberaMemoria(ido); |
---|
[3ec149c] | 1629 | db.Close(); // Cierra conexión |
---|
| 1630 | return (TRUE); |
---|
| 1631 | } |
---|
| 1632 | // ________________________________________________________________________________________________________ |
---|
| 1633 | // Función: Apagar |
---|
| 1634 | // |
---|
| 1635 | // Descripción: |
---|
| 1636 | // Procesa el comando Apagar |
---|
| 1637 | // Parámetros: |
---|
| 1638 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1639 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1640 | // Devuelve: |
---|
| 1641 | // TRUE: Si el proceso es correcto |
---|
| 1642 | // FALSE: En caso de ocurrir algún error |
---|
| 1643 | // ________________________________________________________________________________________________________ |
---|
| 1644 | BOOLEAN Apagar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1645 | char msglog[LONSTD]; |
---|
| 1646 | char modulo[] = "Apagar()"; |
---|
| 1647 | |
---|
| 1648 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1649 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1650 | errorInfo(modulo, msglog); |
---|
| 1651 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1652 | return (FALSE); |
---|
| 1653 | } |
---|
| 1654 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1655 | return (TRUE); |
---|
| 1656 | } |
---|
| 1657 | // ________________________________________________________________________________________________________ |
---|
| 1658 | // Función: RESPUESTA_Apagar |
---|
| 1659 | // |
---|
| 1660 | // Descripción: |
---|
| 1661 | // Respuesta del cliente al comando Apagar |
---|
| 1662 | // Parámetros: |
---|
| 1663 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1664 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1665 | // Devuelve: |
---|
| 1666 | // TRUE: Si el proceso es correcto |
---|
| 1667 | // FALSE: En caso de ocurrir algún error |
---|
| 1668 | // ________________________________________________________________________________________________________ |
---|
| 1669 | BOOLEAN RESPUESTA_Apagar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1670 | char msglog[LONSTD]; |
---|
| 1671 | Database db; |
---|
| 1672 | Table tbl; |
---|
| 1673 | int i; |
---|
| 1674 | char *iph, *ido; |
---|
| 1675 | char modulo[] = "RESPUESTA_Apagar()"; |
---|
| 1676 | |
---|
| 1677 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1678 | errorLog(modulo, 20, FALSE); |
---|
| 1679 | db.GetErrorErrStr(msglog); |
---|
| 1680 | errorInfo(modulo, msglog); |
---|
| 1681 | return (FALSE); |
---|
| 1682 | } |
---|
| 1683 | |
---|
| 1684 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1685 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1686 | |
---|
| 1687 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1688 | liberaMemoria(iph); |
---|
| 1689 | liberaMemoria(ido); |
---|
[3ec149c] | 1690 | errorLog(modulo, 30, FALSE); |
---|
| 1691 | return (FALSE); // Error al registrar notificacion |
---|
| 1692 | } |
---|
| 1693 | |
---|
| 1694 | if (clienteExistente(iph, &i)) // Actualiza estado |
---|
| 1695 | strcpy(tbsockets[i].estado, CLIENTE_APAGADO); |
---|
[0a73ecf7] | 1696 | |
---|
| 1697 | liberaMemoria(iph); |
---|
| 1698 | liberaMemoria(ido); |
---|
| 1699 | |
---|
[3ec149c] | 1700 | db.Close(); // Cierra conexión |
---|
| 1701 | return (TRUE); |
---|
| 1702 | } |
---|
| 1703 | // ________________________________________________________________________________________________________ |
---|
| 1704 | // Función: Reiniciar |
---|
| 1705 | // |
---|
| 1706 | // Descripción: |
---|
| 1707 | // Procesa el comando Reiniciar |
---|
| 1708 | // Parámetros: |
---|
| 1709 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1710 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1711 | // Devuelve: |
---|
| 1712 | // TRUE: Si el proceso es correcto |
---|
| 1713 | // FALSE: En caso de ocurrir algún error |
---|
| 1714 | // ________________________________________________________________________________________________________ |
---|
| 1715 | BOOLEAN Reiniciar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1716 | char msglog[LONSTD]; |
---|
| 1717 | char modulo[] = "Reiniciar()"; |
---|
| 1718 | |
---|
| 1719 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1720 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1721 | errorInfo(modulo, msglog); |
---|
| 1722 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1723 | return (FALSE); |
---|
| 1724 | } |
---|
| 1725 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1726 | return (TRUE); |
---|
| 1727 | } |
---|
| 1728 | // ________________________________________________________________________________________________________ |
---|
| 1729 | // Función: RESPUESTA_Reiniciar |
---|
| 1730 | // |
---|
| 1731 | // Descripción: |
---|
| 1732 | // Respuesta del cliente al comando Reiniciar |
---|
| 1733 | // Parámetros: |
---|
| 1734 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1735 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1736 | // Devuelve: |
---|
| 1737 | // TRUE: Si el proceso es correcto |
---|
| 1738 | // FALSE: En caso de ocurrir algún error |
---|
| 1739 | // ________________________________________________________________________________________________________ |
---|
| 1740 | BOOLEAN RESPUESTA_Reiniciar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1741 | char msglog[LONSTD]; |
---|
| 1742 | Database db; |
---|
| 1743 | Table tbl; |
---|
| 1744 | int i; |
---|
| 1745 | char *iph, *ido; |
---|
| 1746 | char modulo[] = "RESPUESTA_Reiniciar()"; |
---|
| 1747 | |
---|
| 1748 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1749 | errorLog(modulo, 20, FALSE); |
---|
| 1750 | db.GetErrorErrStr(msglog); |
---|
| 1751 | errorInfo(modulo, msglog); |
---|
| 1752 | return (FALSE); |
---|
| 1753 | } |
---|
| 1754 | |
---|
| 1755 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1756 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1757 | |
---|
| 1758 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1759 | liberaMemoria(iph); |
---|
| 1760 | liberaMemoria(ido); |
---|
[3ec149c] | 1761 | errorLog(modulo, 30, FALSE); |
---|
| 1762 | return (FALSE); // Error al registrar notificacion |
---|
| 1763 | } |
---|
| 1764 | |
---|
| 1765 | if (clienteExistente(iph, &i)) // Actualiza estado |
---|
| 1766 | strcpy(tbsockets[i].estado, CLIENTE_APAGADO); |
---|
[0a73ecf7] | 1767 | |
---|
| 1768 | liberaMemoria(iph); |
---|
| 1769 | liberaMemoria(ido); |
---|
[3ec149c] | 1770 | |
---|
| 1771 | db.Close(); // Cierra conexión |
---|
| 1772 | return (TRUE); |
---|
| 1773 | } |
---|
| 1774 | // ________________________________________________________________________________________________________ |
---|
| 1775 | // Función: IniciarSesion |
---|
| 1776 | // |
---|
| 1777 | // Descripción: |
---|
| 1778 | // Procesa el comando Iniciar Sesión |
---|
| 1779 | // Parámetros: |
---|
| 1780 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1781 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1782 | // Devuelve: |
---|
| 1783 | // TRUE: Si el proceso es correcto |
---|
| 1784 | // FALSE: En caso de ocurrir algún error |
---|
| 1785 | // ________________________________________________________________________________________________________ |
---|
| 1786 | BOOLEAN IniciarSesion(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1787 | char msglog[LONSTD]; |
---|
| 1788 | char modulo[] = "IniciarSesion()"; |
---|
| 1789 | |
---|
| 1790 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1791 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1792 | errorInfo(modulo, msglog); |
---|
| 1793 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1794 | return (FALSE); |
---|
| 1795 | } |
---|
| 1796 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1797 | return (TRUE); |
---|
| 1798 | } |
---|
| 1799 | // ________________________________________________________________________________________________________ |
---|
| 1800 | // Función: RESPUESTA_IniciarSesion |
---|
| 1801 | // |
---|
| 1802 | // Descripción: |
---|
| 1803 | // Respuesta del cliente al comando Iniciar Sesión |
---|
| 1804 | // Parámetros: |
---|
| 1805 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1806 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1807 | // Devuelve: |
---|
| 1808 | // TRUE: Si el proceso es correcto |
---|
| 1809 | // FALSE: En caso de ocurrir algún error |
---|
| 1810 | // ________________________________________________________________________________________________________ |
---|
| 1811 | BOOLEAN RESPUESTA_IniciarSesion(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1812 | char msglog[LONSTD]; |
---|
| 1813 | Database db; |
---|
| 1814 | Table tbl; |
---|
| 1815 | int i; |
---|
| 1816 | char *iph, *ido; |
---|
| 1817 | char modulo[] = "RESPUESTA_IniciarSesion()"; |
---|
| 1818 | |
---|
| 1819 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1820 | errorLog(modulo, 20, FALSE); |
---|
| 1821 | db.GetErrorErrStr(msglog); |
---|
| 1822 | errorInfo(modulo, msglog); |
---|
| 1823 | return (FALSE); |
---|
| 1824 | } |
---|
| 1825 | |
---|
| 1826 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1827 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1828 | |
---|
| 1829 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1830 | liberaMemoria(iph); |
---|
| 1831 | liberaMemoria(ido); |
---|
[3ec149c] | 1832 | errorLog(modulo, 30, FALSE); |
---|
| 1833 | return (FALSE); // Error al registrar notificacion |
---|
| 1834 | } |
---|
| 1835 | |
---|
| 1836 | if (clienteExistente(iph, &i)) // Actualiza estado |
---|
| 1837 | strcpy(tbsockets[i].estado, CLIENTE_APAGADO); |
---|
[0a73ecf7] | 1838 | |
---|
| 1839 | liberaMemoria(iph); |
---|
| 1840 | liberaMemoria(ido); |
---|
| 1841 | |
---|
[3ec149c] | 1842 | db.Close(); // Cierra conexión |
---|
| 1843 | return (TRUE); |
---|
| 1844 | } |
---|
| 1845 | // ________________________________________________________________________________________________________ |
---|
| 1846 | // Función: CrearImagen |
---|
| 1847 | // |
---|
| 1848 | // Descripción: |
---|
| 1849 | // Crea una imagen de una partición de un disco y la guarda o bien en un repositorio |
---|
| 1850 | // Parámetros: |
---|
| 1851 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 1852 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1853 | // Devuelve: |
---|
| 1854 | // TRUE: Si el proceso es correcto |
---|
| 1855 | // FALSE: En caso de ocurrir algún error |
---|
| 1856 | // ________________________________________________________________________________________________________ |
---|
| 1857 | BOOLEAN CrearImagen(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 1858 | char msglog[LONSTD]; |
---|
| 1859 | char modulo[] = "CrearImagen()"; |
---|
| 1860 | |
---|
| 1861 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 1862 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 1863 | errorInfo(modulo, msglog); |
---|
| 1864 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 1865 | return (FALSE); |
---|
| 1866 | } |
---|
| 1867 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 1868 | return (TRUE); |
---|
| 1869 | } |
---|
| 1870 | // ________________________________________________________________________________________________________ |
---|
| 1871 | // Función: RESPUESTA_CrearImagen |
---|
| 1872 | // |
---|
| 1873 | // Descripción: |
---|
| 1874 | // Respuesta del cliente al comando CrearImagen |
---|
| 1875 | // Parámetros: |
---|
| 1876 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 1877 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 1878 | // Devuelve: |
---|
| 1879 | // TRUE: Si el proceso es correcto |
---|
| 1880 | // FALSE: En caso de ocurrir algún error |
---|
| 1881 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 1882 | BOOLEAN RESPUESTA_CrearImagen(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 1883 | { |
---|
[3ec149c] | 1884 | char msglog[LONSTD]; |
---|
| 1885 | Database db; |
---|
| 1886 | Table tbl; |
---|
| 1887 | char *iph, *par, *cpt, *ipr, *ido; |
---|
| 1888 | char *idi; |
---|
[0a73ecf7] | 1889 | BOOLEAN res; |
---|
[3ec149c] | 1890 | char modulo[] = "RESPUESTA_CrearImagen()"; |
---|
| 1891 | |
---|
| 1892 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 1893 | errorLog(modulo, 20, FALSE); |
---|
| 1894 | db.GetErrorErrStr(msglog); |
---|
| 1895 | errorInfo(modulo, msglog); |
---|
| 1896 | return (FALSE); |
---|
| 1897 | } |
---|
| 1898 | |
---|
| 1899 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 1900 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 1901 | |
---|
| 1902 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 1903 | liberaMemoria(iph); |
---|
| 1904 | liberaMemoria(ido); |
---|
[3ec149c] | 1905 | errorLog(modulo, 30, FALSE); |
---|
| 1906 | return (FALSE); // Error al registrar notificacion |
---|
| 1907 | } |
---|
| 1908 | |
---|
| 1909 | // Acciones posteriores |
---|
| 1910 | idi = copiaParametro("idi",ptrTrama); |
---|
| 1911 | par = copiaParametro("par",ptrTrama); |
---|
| 1912 | cpt = copiaParametro("cpt",ptrTrama); |
---|
| 1913 | ipr = copiaParametro("ipr",ptrTrama); |
---|
| 1914 | |
---|
[0a73ecf7] | 1915 | res=actualizaCreacionImagen(db, tbl, idi, par, cpt, ipr, ido); |
---|
| 1916 | |
---|
| 1917 | liberaMemoria(idi); |
---|
| 1918 | liberaMemoria(par); |
---|
| 1919 | liberaMemoria(cpt); |
---|
| 1920 | liberaMemoria(ipr); |
---|
| 1921 | |
---|
| 1922 | if(!res){ |
---|
| 1923 | errorLog(modulo, 94, FALSE); |
---|
[3ec149c] | 1924 | db.Close(); // Cierra conexión |
---|
| 1925 | return (FALSE); |
---|
| 1926 | } |
---|
| 1927 | |
---|
| 1928 | db.Close(); // Cierra conexión |
---|
| 1929 | return (TRUE); |
---|
| 1930 | } |
---|
| 1931 | // ________________________________________________________________________________________________________ |
---|
| 1932 | // Función: actualizaCreacionImagen |
---|
| 1933 | // |
---|
| 1934 | // Descripción: |
---|
| 1935 | // Esta función actualiza la base de datos con el resultado de la creación de una imagen |
---|
| 1936 | // Parámetros: |
---|
| 1937 | // - db: Objeto base de datos (ya operativo) |
---|
| 1938 | // - tbl: Objeto tabla |
---|
| 1939 | // - idi: Identificador de la imagen |
---|
| 1940 | // - par: Partición de donde se creó |
---|
| 1941 | // - cpt: Código de partición |
---|
| 1942 | // - ipr: Ip del repositorio |
---|
| 1943 | // - ido: Identificador del ordenador modelo |
---|
| 1944 | // Devuelve: |
---|
| 1945 | // TRUE: Si el proceso es correcto |
---|
| 1946 | // FALSE: En caso de ocurrir algún error |
---|
| 1947 | // ________________________________________________________________________________________________________ |
---|
| 1948 | BOOLEAN actualizaCreacionImagen(Database db, Table tbl, char* idi, char* par, |
---|
[0a73ecf7] | 1949 | char* cpt, char* ipr, char *ido) { |
---|
[3ec149c] | 1950 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 1951 | char modulo[] = "actualizaCreacionImagen()"; |
---|
| 1952 | int idr,ifs; |
---|
| 1953 | |
---|
| 1954 | /* Toma identificador del repositorio */ |
---|
| 1955 | sprintf(sqlstr, "SELECT idrepositorio FROM repositorios WHERE ip='%s'", ipr); |
---|
| 1956 | |
---|
| 1957 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 1958 | errorLog(modulo, 21, FALSE); |
---|
| 1959 | db.GetErrorErrStr(msglog); |
---|
| 1960 | errorInfo(modulo, msglog); |
---|
| 1961 | return (FALSE); |
---|
| 1962 | } |
---|
| 1963 | if (!tbl.Get("idrepositorio", idr)) { // Toma dato |
---|
| 1964 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1965 | errorInfo(modulo, msglog); |
---|
| 1966 | return (FALSE); |
---|
| 1967 | } |
---|
| 1968 | |
---|
| 1969 | /* Toma identificador del perfilsoftware */ |
---|
[0a73ecf7] | 1970 | sprintf(sqlstr,"SELECT idperfilsoft FROM ordenadores_particiones WHERE idordenador=%s AND numpar=%s", ido,par); |
---|
[3ec149c] | 1971 | |
---|
| 1972 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 1973 | errorLog(modulo, 21, FALSE); |
---|
| 1974 | db.GetErrorErrStr(msglog); |
---|
| 1975 | errorInfo(modulo, msglog); |
---|
| 1976 | return (FALSE); |
---|
| 1977 | } |
---|
| 1978 | if (!tbl.Get("idperfilsoft", ifs)) { // Toma dato |
---|
| 1979 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 1980 | errorInfo(modulo, msglog); |
---|
| 1981 | return (FALSE); |
---|
| 1982 | } |
---|
| 1983 | |
---|
| 1984 | /* Actualizar los datos de la imagen */ |
---|
| 1985 | sprintf(sqlstr, |
---|
| 1986 | "UPDATE imagenes SET numpar=%s,codpar=%s,idperfilsoft=%d,idrepositorio='%d'" |
---|
| 1987 | " WHERE idimagen=%s", par, cpt, ifs, idr, idi); |
---|
| 1988 | |
---|
| 1989 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 1990 | errorLog(modulo, 21, FALSE); |
---|
| 1991 | db.GetErrorErrStr(msglog); |
---|
| 1992 | errorInfo(modulo, msglog); |
---|
| 1993 | return (FALSE); |
---|
| 1994 | } |
---|
| 1995 | return (TRUE); |
---|
| 1996 | } |
---|
| 1997 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 1998 | // Función: CrearImagenBasica |
---|
| 1999 | // |
---|
| 2000 | // Descripción: |
---|
| 2001 | // Crea una imagen basica usando sincronización |
---|
| 2002 | // Parámetros: |
---|
| 2003 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2004 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2005 | // Devuelve: |
---|
| 2006 | // TRUE: Si el proceso es correcto |
---|
| 2007 | // FALSE: En caso de ocurrir algún error |
---|
| 2008 | // ________________________________________________________________________________________________________ |
---|
| 2009 | BOOLEAN CrearImagenBasica(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2010 | char msglog[LONSTD]; |
---|
| 2011 | char modulo[] = "CrearImagenBasica()"; |
---|
| 2012 | |
---|
| 2013 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2014 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2015 | errorInfo(modulo, msglog); |
---|
| 2016 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2017 | return (FALSE); |
---|
| 2018 | } |
---|
| 2019 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2020 | return (TRUE); |
---|
| 2021 | } |
---|
| 2022 | // ________________________________________________________________________________________________________ |
---|
| 2023 | // Función: RESPUESTA_CrearImagenBasica |
---|
| 2024 | // |
---|
| 2025 | // Descripción: |
---|
| 2026 | // Respuesta del cliente al comando CrearImagenBasica |
---|
| 2027 | // Parámetros: |
---|
| 2028 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2029 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2030 | // Devuelve: |
---|
| 2031 | // TRUE: Si el proceso es correcto |
---|
| 2032 | // FALSE: En caso de ocurrir algún error |
---|
| 2033 | // ________________________________________________________________________________________________________ |
---|
| 2034 | BOOLEAN RESPUESTA_CrearImagenBasica(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2035 | return(RESPUESTA_CrearImagen(socket_c,ptrTrama)); // La misma respuesta que la creación de imagen monolítica |
---|
| 2036 | } |
---|
| 2037 | // ________________________________________________________________________________________________________ |
---|
| 2038 | // Función: CrearSoftIncremental |
---|
| 2039 | // |
---|
| 2040 | // Descripción: |
---|
| 2041 | // Crea una imagen incremental entre una partición de un disco y una imagen ya creada guardandola en el |
---|
| 2042 | // mismo repositorio y en la misma carpeta donde está la imagen básica |
---|
| 2043 | // Parámetros: |
---|
| 2044 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2045 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2046 | // Devuelve: |
---|
| 2047 | // TRUE: Si el proceso es correcto |
---|
| 2048 | // FALSE: En caso de ocurrir algún error |
---|
| 2049 | // ________________________________________________________________________________________________________ |
---|
| 2050 | BOOLEAN CrearSoftIncremental(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2051 | char msglog[LONSTD]; |
---|
| 2052 | char modulo[] = "CrearSoftIncremental()"; |
---|
| 2053 | |
---|
| 2054 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2055 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2056 | errorInfo(modulo, msglog); |
---|
| 2057 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2058 | return (FALSE); |
---|
| 2059 | } |
---|
| 2060 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2061 | return (TRUE); |
---|
| 2062 | } |
---|
| 2063 | // ________________________________________________________________________________________________________ |
---|
| 2064 | // Función: RESPUESTA_CrearSoftIncremental |
---|
| 2065 | // |
---|
| 2066 | // Descripción: |
---|
| 2067 | // Respuesta del cliente al comando crearImagenDiferencial |
---|
| 2068 | // Parámetros: |
---|
| 2069 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2070 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2071 | // Devuelve: |
---|
| 2072 | // TRUE: Si el proceso es correcto |
---|
| 2073 | // FALSE: En caso de ocurrir algún error |
---|
| 2074 | // ________________________________________________________________________________________________________ |
---|
| 2075 | BOOLEAN RESPUESTA_CrearSoftIncremental(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 2076 | { |
---|
| 2077 | Database db; |
---|
| 2078 | Table tbl; |
---|
| 2079 | char *iph,*par,*ido,*idf; |
---|
| 2080 | int ifs; |
---|
| 2081 | char msglog[LONSTD],sqlstr[LONSQL]; |
---|
| 2082 | char modulo[] = "RESPUESTA_CrearSoftIncremental()"; |
---|
| 2083 | |
---|
| 2084 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2085 | errorLog(modulo, 20, FALSE); |
---|
| 2086 | db.GetErrorErrStr(msglog); |
---|
| 2087 | errorInfo(modulo, msglog); |
---|
| 2088 | return (FALSE); |
---|
| 2089 | } |
---|
| 2090 | |
---|
| 2091 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 2092 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 2093 | |
---|
| 2094 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
| 2095 | liberaMemoria(iph); |
---|
| 2096 | liberaMemoria(ido); |
---|
| 2097 | errorLog(modulo, 30, FALSE); |
---|
| 2098 | return (FALSE); // Error al registrar notificacion |
---|
| 2099 | } |
---|
| 2100 | |
---|
| 2101 | par = copiaParametro("par",ptrTrama); |
---|
| 2102 | |
---|
| 2103 | /* Toma identificador del perfilsoftware creado por el inventario de software */ |
---|
| 2104 | sprintf(sqlstr,"SELECT idperfilsoft FROM ordenadores_particiones WHERE idordenador=%s AND numpar=%s",ido,par); |
---|
| 2105 | |
---|
| 2106 | liberaMemoria(iph); |
---|
| 2107 | liberaMemoria(ido); |
---|
| 2108 | liberaMemoria(par); |
---|
| 2109 | |
---|
| 2110 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2111 | errorLog(modulo, 21, FALSE); |
---|
| 2112 | db.GetErrorErrStr(msglog); |
---|
| 2113 | errorInfo(modulo, msglog); |
---|
| 2114 | return (FALSE); |
---|
| 2115 | } |
---|
| 2116 | if (!tbl.Get("idperfilsoft", ifs)) { // Toma dato |
---|
| 2117 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2118 | errorInfo(modulo, msglog); |
---|
| 2119 | return (FALSE); |
---|
| 2120 | } |
---|
| 2121 | |
---|
| 2122 | /* Actualizar los datos de la imagen */ |
---|
| 2123 | idf = copiaParametro("idf",ptrTrama); |
---|
| 2124 | sprintf(sqlstr,"UPDATE imagenes SET idperfilsoft=%d WHERE idimagen=%s",ifs,idf); |
---|
| 2125 | liberaMemoria(idf); |
---|
| 2126 | |
---|
| 2127 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 2128 | errorLog(modulo, 21, FALSE); |
---|
| 2129 | db.GetErrorErrStr(msglog); |
---|
| 2130 | errorInfo(modulo, msglog); |
---|
| 2131 | return (FALSE); |
---|
| 2132 | } |
---|
| 2133 | db.Close(); // Cierra conexión |
---|
| 2134 | return (TRUE); |
---|
| 2135 | } |
---|
| 2136 | // ________________________________________________________________________________________________________ |
---|
| 2137 | // Función: actualizaCreacionSoftIncremental |
---|
| 2138 | // |
---|
| 2139 | // Descripción: |
---|
| 2140 | // Esta función actualiza la base de datos con el resultado de la creación de software incremental |
---|
| 2141 | // Parámetros: |
---|
| 2142 | // - db: Objeto base de datos (ya operativo) |
---|
| 2143 | // - tbl: Objeto tabla |
---|
| 2144 | // - idi: Identificador de la imagen |
---|
| 2145 | // - idf: Identificador del software incremental |
---|
| 2146 | // Devuelve: |
---|
| 2147 | // TRUE: Si el proceso es correcto |
---|
| 2148 | // FALSE: En caso de ocurrir algún error |
---|
| 2149 | // ________________________________________________________________________________________________________ |
---|
| 2150 | BOOLEAN actualizaCreacionSoftIncremental(Database db, Table tbl, char* idi,char* idf) |
---|
| 2151 | { |
---|
| 2152 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 2153 | char modulo[] = "actualizaCreacionSoftIncremental()"; |
---|
| 2154 | |
---|
| 2155 | |
---|
| 2156 | /* Comprueba si existe ya relación entre la imagen y el software incremental */ |
---|
| 2157 | sprintf(sqlstr, "SELECT * FROM imagenes_softincremental" |
---|
| 2158 | " WHERE idimagen=%s AND idsoftincremental=%s", idi,idf); |
---|
| 2159 | |
---|
| 2160 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2161 | errorLog(modulo, 21, FALSE); |
---|
| 2162 | db.GetErrorErrStr(msglog); |
---|
| 2163 | errorInfo(modulo, msglog); |
---|
| 2164 | return (FALSE); |
---|
| 2165 | } |
---|
| 2166 | if (!tbl.ISEOF()) |
---|
| 2167 | return (TRUE); // Ya existe relación |
---|
| 2168 | |
---|
| 2169 | // Crea relación entre la imagen y el software incremental |
---|
| 2170 | sprintf(sqlstr,"INSERT INTO imagenes_softincremental (idimagen,idsoftincremental) VALUES (%s,%s)",idi,idf); |
---|
| 2171 | if (!db.Execute(sqlstr, tbl)) { // Error al ejecutar la sentencia |
---|
| 2172 | errorLog(modulo, 21, FALSE); |
---|
| 2173 | db.GetErrorErrStr(msglog); |
---|
| 2174 | errorInfo(modulo, msglog); |
---|
| 2175 | return (FALSE); |
---|
| 2176 | } |
---|
| 2177 | return (TRUE); |
---|
| 2178 | } |
---|
| 2179 | // ________________________________________________________________________________________________________ |
---|
[3ec149c] | 2180 | // Función: RestaurarImagen |
---|
| 2181 | // |
---|
| 2182 | // Descripción: |
---|
| 2183 | // Restaura una imagen en una partición |
---|
| 2184 | // Parámetros: |
---|
| 2185 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2186 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2187 | // Devuelve: |
---|
| 2188 | // TRUE: Si el proceso es correcto |
---|
| 2189 | // FALSE: En caso de ocurrir algún error |
---|
| 2190 | // ________________________________________________________________________________________________________ |
---|
| 2191 | BOOLEAN RestaurarImagen(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2192 | char msglog[LONSTD]; |
---|
| 2193 | char modulo[] = "RestaurarImagen()"; |
---|
| 2194 | |
---|
| 2195 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2196 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2197 | errorInfo(modulo, msglog); |
---|
| 2198 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2199 | return (FALSE); |
---|
| 2200 | } |
---|
| 2201 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2202 | return (TRUE); |
---|
| 2203 | } |
---|
| 2204 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 2205 | // Función: RestaurarImagenBasica |
---|
| 2206 | // |
---|
| 2207 | // Descripción: |
---|
| 2208 | // Restaura una imagen básica en una partición |
---|
| 2209 | // Parámetros: |
---|
| 2210 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2211 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2212 | // Devuelve: |
---|
| 2213 | // TRUE: Si el proceso es correcto |
---|
| 2214 | // FALSE: En caso de ocurrir algún error |
---|
| 2215 | // ________________________________________________________________________________________________________ |
---|
| 2216 | BOOLEAN RestaurarImagenBasica(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2217 | char msglog[LONSTD]; |
---|
| 2218 | char modulo[] = "RestaurarImagenBasica()"; |
---|
| 2219 | |
---|
| 2220 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2221 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2222 | errorInfo(modulo, msglog); |
---|
| 2223 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2224 | return (FALSE); |
---|
| 2225 | } |
---|
| 2226 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2227 | return (TRUE); |
---|
| 2228 | } |
---|
| 2229 | // ________________________________________________________________________________________________________ |
---|
| 2230 | // Función: RestaurarSoftIncremental |
---|
| 2231 | // |
---|
| 2232 | // Descripción: |
---|
| 2233 | // Restaura una imagen básica junto con software incremental en una partición |
---|
| 2234 | // Parámetros: |
---|
| 2235 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2236 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2237 | // Devuelve: |
---|
| 2238 | // TRUE: Si el proceso es correcto |
---|
| 2239 | // FALSE: En caso de ocurrir algún error |
---|
| 2240 | // ________________________________________________________________________________________________________ |
---|
| 2241 | BOOLEAN RestaurarSoftIncremental(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2242 | char msglog[LONSTD]; |
---|
| 2243 | char modulo[] = "RestaurarSoftIncremental()"; |
---|
| 2244 | |
---|
| 2245 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2246 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2247 | errorInfo(modulo, msglog); |
---|
| 2248 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2249 | return (FALSE); |
---|
| 2250 | } |
---|
| 2251 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2252 | return (TRUE); |
---|
| 2253 | } |
---|
| 2254 | // ________________________________________________________________________________________________________ |
---|
[3ec149c] | 2255 | // Función: RESPUESTA_RestaurarImagen |
---|
| 2256 | // |
---|
| 2257 | // Descripción: |
---|
| 2258 | // Respuesta del cliente al comando RestaurarImagen |
---|
| 2259 | // Parámetros: |
---|
| 2260 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2261 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2262 | // Devuelve: |
---|
| 2263 | // TRUE: Si el proceso es correcto |
---|
| 2264 | // FALSE: En caso de ocurrir algún error |
---|
| 2265 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 2266 | // |
---|
| 2267 | BOOLEAN RESPUESTA_RestaurarImagen(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 2268 | { |
---|
[3ec149c] | 2269 | char msglog[LONSTD]; |
---|
| 2270 | Database db; |
---|
| 2271 | Table tbl; |
---|
[0a73ecf7] | 2272 | BOOLEAN res; |
---|
[3ec149c] | 2273 | char *iph, *ido, *idi, *par, *ifs; |
---|
| 2274 | char modulo[] = "RESPUESTA_RestaurarImagen()"; |
---|
| 2275 | |
---|
| 2276 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2277 | errorLog(modulo, 20, FALSE); |
---|
| 2278 | db.GetErrorErrStr(msglog); |
---|
| 2279 | errorInfo(modulo, msglog); |
---|
| 2280 | return (FALSE); |
---|
| 2281 | } |
---|
| 2282 | |
---|
| 2283 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 2284 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 2285 | |
---|
| 2286 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 2287 | liberaMemoria(iph); |
---|
| 2288 | liberaMemoria(ido); |
---|
[3ec149c] | 2289 | errorLog(modulo, 30, FALSE); |
---|
| 2290 | return (FALSE); // Error al registrar notificacion |
---|
| 2291 | } |
---|
| 2292 | |
---|
| 2293 | // Acciones posteriores |
---|
| 2294 | idi = copiaParametro("idi",ptrTrama); // Toma identificador de la imagen |
---|
| 2295 | par = copiaParametro("par",ptrTrama); // Número de partición |
---|
| 2296 | ifs = copiaParametro("ifs",ptrTrama); // Identificador del perfil software contenido |
---|
[0a73ecf7] | 2297 | |
---|
| 2298 | res=actualizaRestauracionImagen(db, tbl, idi, par, ido, ifs); |
---|
| 2299 | |
---|
| 2300 | liberaMemoria(iph); |
---|
| 2301 | liberaMemoria(ido); |
---|
| 2302 | liberaMemoria(idi); |
---|
| 2303 | liberaMemoria(par); |
---|
| 2304 | liberaMemoria(ifs); |
---|
| 2305 | |
---|
| 2306 | if(!res){ |
---|
| 2307 | errorLog(modulo, 95, FALSE); |
---|
[3ec149c] | 2308 | db.Close(); // Cierra conexión |
---|
| 2309 | return (FALSE); |
---|
| 2310 | } |
---|
| 2311 | |
---|
| 2312 | db.Close(); // Cierra conexión |
---|
| 2313 | return (TRUE); |
---|
| 2314 | } |
---|
| 2315 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 2316 | // |
---|
| 2317 | // Función: RESPUESTA_RestaurarImagenBasica |
---|
| 2318 | // |
---|
| 2319 | // Descripción: |
---|
| 2320 | // Respuesta del cliente al comando RestaurarImagen |
---|
| 2321 | // Parámetros: |
---|
| 2322 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2323 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2324 | // Devuelve: |
---|
| 2325 | // TRUE: Si el proceso es correcto |
---|
| 2326 | // FALSE: En caso de ocurrir algún error |
---|
| 2327 | // ________________________________________________________________________________________________________ |
---|
| 2328 | // |
---|
| 2329 | BOOLEAN RESPUESTA_RestaurarImagenBasica(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2330 | return(RESPUESTA_RestaurarImagen(socket_c,ptrTrama)); |
---|
| 2331 | } |
---|
| 2332 | // ________________________________________________________________________________________________________ |
---|
| 2333 | // Función: RESPUESTA_RestaurarSoftIncremental |
---|
| 2334 | // |
---|
| 2335 | // Descripción: |
---|
| 2336 | // Respuesta del cliente al comando RestaurarSoftIncremental |
---|
| 2337 | // Parámetros: |
---|
| 2338 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2339 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2340 | // Devuelve: |
---|
| 2341 | // TRUE: Si el proceso es correcto |
---|
| 2342 | // FALSE: En caso de ocurrir algún error |
---|
| 2343 | // ________________________________________________________________________________________________________ |
---|
| 2344 | BOOLEAN RESPUESTA_RestaurarSoftIncremental(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2345 | return(RESPUESTA_RestaurarImagen(socket_c,ptrTrama)); |
---|
| 2346 | } |
---|
| 2347 | // ________________________________________________________________________________________________________ |
---|
[3ec149c] | 2348 | // Función: actualizaRestauracionImagen |
---|
| 2349 | // |
---|
| 2350 | // Descripción: |
---|
[0a73ecf7] | 2351 | // Esta función actualiza la base de datos con el resultado de la restauración de una imagen |
---|
[3ec149c] | 2352 | // Parámetros: |
---|
| 2353 | // - db: Objeto base de datos (ya operativo) |
---|
| 2354 | // - tbl: Objeto tabla |
---|
| 2355 | // - idi: Identificador de la imagen |
---|
| 2356 | // - par: Partición de donde se restauró |
---|
| 2357 | // - ido: Identificador del cliente donde se restauró |
---|
| 2358 | // - ifs: Identificador del perfil software contenido en la imagen |
---|
| 2359 | // Devuelve: |
---|
| 2360 | // TRUE: Si el proceso es correcto |
---|
| 2361 | // FALSE: En caso de ocurrir algún error |
---|
| 2362 | // ________________________________________________________________________________________________________ |
---|
| 2363 | BOOLEAN actualizaRestauracionImagen(Database db, Table tbl, char* idi, |
---|
[0a73ecf7] | 2364 | char* par, char* ido, char* ifs) { |
---|
[3ec149c] | 2365 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 2366 | char modulo[] = "actualizaRestauracionImagen()"; |
---|
| 2367 | |
---|
| 2368 | /* Actualizar los datos de la imagen */ |
---|
| 2369 | sprintf(sqlstr, |
---|
| 2370 | "UPDATE ordenadores_particiones SET idimagen=%s,idperfilsoft=%s" |
---|
| 2371 | " WHERE idordenador=%s AND numpar=%s", idi, ifs, ido, par); |
---|
| 2372 | |
---|
| 2373 | if (!db.Execute(sqlstr, tbl)) { // Error al recuperar los datos |
---|
| 2374 | errorLog(modulo, 21, FALSE); |
---|
| 2375 | db.GetErrorErrStr(msglog); |
---|
| 2376 | errorInfo(modulo, msglog); |
---|
| 2377 | return (FALSE); |
---|
| 2378 | } |
---|
| 2379 | return (TRUE); |
---|
| 2380 | } |
---|
| 2381 | // ________________________________________________________________________________________________________ |
---|
| 2382 | // Función: Configurar |
---|
| 2383 | // |
---|
| 2384 | // Descripción: |
---|
| 2385 | // Configura la tabla de particiones |
---|
| 2386 | // Parámetros: |
---|
| 2387 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2388 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2389 | // Devuelve: |
---|
| 2390 | // TRUE: Si el proceso es correcto |
---|
| 2391 | // FALSE: En caso de ocurrir algún error |
---|
| 2392 | // ________________________________________________________________________________________________________ |
---|
| 2393 | BOOLEAN Configurar(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2394 | char msglog[LONSTD]; |
---|
| 2395 | char modulo[] = "Configurar()"; |
---|
| 2396 | |
---|
| 2397 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2398 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2399 | errorInfo(modulo, msglog); |
---|
| 2400 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2401 | return (FALSE); |
---|
| 2402 | } |
---|
| 2403 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2404 | return (TRUE); |
---|
| 2405 | } |
---|
| 2406 | // ________________________________________________________________________________________________________ |
---|
| 2407 | // Función: RESPUESTA_Configurar |
---|
| 2408 | // |
---|
| 2409 | // Descripción: |
---|
| 2410 | // Respuesta del cliente al comando Configurar |
---|
| 2411 | // Parámetros: |
---|
| 2412 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2413 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2414 | // Devuelve: |
---|
| 2415 | // TRUE: Si el proceso es correcto |
---|
| 2416 | // FALSE: En caso de ocurrir algún error |
---|
| 2417 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 2418 | // |
---|
| 2419 | BOOLEAN RESPUESTA_Configurar(SOCKET *socket_c, TRAMA* ptrTrama) |
---|
| 2420 | { |
---|
[3ec149c] | 2421 | char msglog[LONSTD]; |
---|
| 2422 | Database db; |
---|
| 2423 | Table tbl; |
---|
[0a73ecf7] | 2424 | BOOLEAN res; |
---|
[3ec149c] | 2425 | char *iph, *ido,*cfg; |
---|
| 2426 | char modulo[] = "RESPUESTA_Configurar()"; |
---|
| 2427 | |
---|
| 2428 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2429 | errorLog(modulo, 20, FALSE); |
---|
| 2430 | db.GetErrorErrStr(msglog); |
---|
| 2431 | errorInfo(modulo, msglog); |
---|
| 2432 | return (FALSE); |
---|
| 2433 | } |
---|
| 2434 | |
---|
| 2435 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 2436 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 2437 | |
---|
| 2438 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 2439 | liberaMemoria(iph); |
---|
| 2440 | liberaMemoria(ido); |
---|
[3ec149c] | 2441 | errorLog(modulo, 30, FALSE); |
---|
| 2442 | return (FALSE); // Error al registrar notificacion |
---|
| 2443 | } |
---|
| 2444 | |
---|
| 2445 | cfg = copiaParametro("cfg",ptrTrama); // Toma configuración de particiones |
---|
[0a73ecf7] | 2446 | res=actualizaConfiguracion(db, tbl, cfg, atoi(ido)); // Actualiza la configuración del ordenador |
---|
| 2447 | |
---|
| 2448 | liberaMemoria(iph); |
---|
| 2449 | liberaMemoria(ido); |
---|
| 2450 | liberaMemoria(cfg); |
---|
| 2451 | |
---|
| 2452 | if(!res){ |
---|
[3ec149c] | 2453 | errorLog(modulo, 24, FALSE); |
---|
| 2454 | return (FALSE); // Error al registrar notificacion |
---|
| 2455 | } |
---|
[0a73ecf7] | 2456 | |
---|
[3ec149c] | 2457 | db.Close(); // Cierra conexión |
---|
| 2458 | return (TRUE); |
---|
| 2459 | } |
---|
| 2460 | // ________________________________________________________________________________________________________ |
---|
| 2461 | // Función: EjecutarScript |
---|
| 2462 | // |
---|
| 2463 | // Descripción: |
---|
| 2464 | // Ejecuta un script de código |
---|
| 2465 | // Parámetros: |
---|
| 2466 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2467 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2468 | // Devuelve: |
---|
| 2469 | // TRUE: Si el proceso es correcto |
---|
| 2470 | // FALSE: En caso de ocurrir algún error |
---|
| 2471 | // ________________________________________________________________________________________________________ |
---|
| 2472 | BOOLEAN EjecutarScript(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2473 | char msglog[LONSTD]; |
---|
| 2474 | char modulo[] = "EjecutarScript()"; |
---|
| 2475 | |
---|
| 2476 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2477 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2478 | errorInfo(modulo, msglog); |
---|
| 2479 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2480 | return (FALSE); |
---|
| 2481 | } |
---|
| 2482 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2483 | return (TRUE); |
---|
| 2484 | } |
---|
| 2485 | // ________________________________________________________________________________________________________ |
---|
| 2486 | // Función: RESPUESTA_EjecutarScript |
---|
| 2487 | // |
---|
| 2488 | // Descripción: |
---|
| 2489 | // Respuesta del cliente al comando EjecutarScript |
---|
| 2490 | // Parámetros: |
---|
| 2491 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2492 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2493 | // Devuelve: |
---|
| 2494 | // TRUE: Si el proceso es correcto |
---|
| 2495 | // FALSE: En caso de ocurrir algún error |
---|
| 2496 | // ________________________________________________________________________________________________________ |
---|
| 2497 | BOOLEAN RESPUESTA_EjecutarScript(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2498 | char msglog[LONSTD]; |
---|
| 2499 | Database db; |
---|
| 2500 | Table tbl; |
---|
| 2501 | char *iph, *ido; |
---|
| 2502 | |
---|
| 2503 | char modulo[] = "RESPUESTA_EjecutarScript()"; |
---|
| 2504 | |
---|
| 2505 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2506 | errorLog(modulo, 20, FALSE); |
---|
| 2507 | db.GetErrorErrStr(msglog); |
---|
| 2508 | errorInfo(modulo, msglog); |
---|
| 2509 | return (FALSE); |
---|
| 2510 | } |
---|
| 2511 | |
---|
| 2512 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 2513 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 2514 | |
---|
| 2515 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 2516 | liberaMemoria(iph); |
---|
| 2517 | liberaMemoria(ido); |
---|
[3ec149c] | 2518 | errorLog(modulo, 30, FALSE); |
---|
| 2519 | return (FALSE); // Error al registrar notificacion |
---|
| 2520 | } |
---|
[0a73ecf7] | 2521 | |
---|
| 2522 | liberaMemoria(iph); |
---|
| 2523 | liberaMemoria(ido); |
---|
| 2524 | |
---|
[3ec149c] | 2525 | db.Close(); // Cierra conexión |
---|
| 2526 | return (TRUE); |
---|
| 2527 | } |
---|
| 2528 | // ________________________________________________________________________________________________________ |
---|
| 2529 | // Función: InventarioHardware |
---|
| 2530 | // |
---|
| 2531 | // Descripción: |
---|
| 2532 | // Solicita al cliente un inventario de su hardware |
---|
| 2533 | // Parámetros: |
---|
| 2534 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2535 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2536 | // Devuelve: |
---|
| 2537 | // TRUE: Si el proceso es correcto |
---|
| 2538 | // FALSE: En caso de ocurrir algún error |
---|
| 2539 | // ________________________________________________________________________________________________________ |
---|
| 2540 | BOOLEAN InventarioHardware(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2541 | char msglog[LONSTD]; |
---|
| 2542 | char modulo[] = "InventarioHardware()"; |
---|
| 2543 | |
---|
| 2544 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2545 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2546 | errorInfo(modulo, msglog); |
---|
| 2547 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2548 | return (FALSE); |
---|
| 2549 | } |
---|
| 2550 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2551 | return (TRUE); |
---|
| 2552 | } |
---|
| 2553 | // ________________________________________________________________________________________________________ |
---|
| 2554 | // Función: RESPUESTA_InventarioHardware |
---|
| 2555 | // |
---|
| 2556 | // Descripción: |
---|
| 2557 | // Respuesta del cliente al comando InventarioHardware |
---|
| 2558 | // Parámetros: |
---|
| 2559 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2560 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2561 | // Devuelve: |
---|
| 2562 | // TRUE: Si el proceso es correcto |
---|
| 2563 | // FALSE: En caso de ocurrir algún error |
---|
| 2564 | // ________________________________________________________________________________________________________ |
---|
| 2565 | BOOLEAN RESPUESTA_InventarioHardware(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2566 | char msglog[LONSTD]; |
---|
| 2567 | Database db; |
---|
| 2568 | Table tbl; |
---|
[0a73ecf7] | 2569 | BOOLEAN res; |
---|
[3ec149c] | 2570 | char *iph, *ido, *idc, *npc, *hrd, *buffer; |
---|
| 2571 | char modulo[] = "RESPUESTA_InventarioHardware()"; |
---|
| 2572 | |
---|
| 2573 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2574 | errorLog(modulo, 20, FALSE); |
---|
| 2575 | db.GetErrorErrStr(msglog); |
---|
| 2576 | errorInfo(modulo, msglog); |
---|
| 2577 | return (FALSE); |
---|
| 2578 | } |
---|
[0a73ecf7] | 2579 | |
---|
[3ec149c] | 2580 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip del cliente |
---|
| 2581 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del cliente |
---|
| 2582 | |
---|
| 2583 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 2584 | liberaMemoria(iph); |
---|
| 2585 | liberaMemoria(ido); |
---|
[3ec149c] | 2586 | errorLog(modulo, 30, FALSE); |
---|
| 2587 | return (FALSE); // Error al registrar notificacion |
---|
| 2588 | } |
---|
| 2589 | // Lee archivo de inventario enviado anteriormente |
---|
| 2590 | hrd = copiaParametro("hrd",ptrTrama); |
---|
| 2591 | buffer = rTrim(leeArchivo(hrd)); |
---|
[0a73ecf7] | 2592 | |
---|
| 2593 | npc = copiaParametro("npc",ptrTrama); |
---|
| 2594 | idc = copiaParametro("idc",ptrTrama); // Toma identificador del Centro |
---|
| 2595 | |
---|
| 2596 | if (buffer) |
---|
| 2597 | res=actualizaHardware(db, tbl, buffer, ido, npc, idc); |
---|
| 2598 | |
---|
| 2599 | liberaMemoria(iph); |
---|
| 2600 | liberaMemoria(ido); |
---|
| 2601 | liberaMemoria(npc); |
---|
| 2602 | liberaMemoria(idc); |
---|
| 2603 | liberaMemoria(buffer); |
---|
| 2604 | |
---|
| 2605 | if(!res){ |
---|
| 2606 | errorLog(modulo, 53, FALSE); |
---|
| 2607 | return (FALSE); |
---|
[3ec149c] | 2608 | } |
---|
[0a73ecf7] | 2609 | |
---|
[3ec149c] | 2610 | db.Close(); // Cierra conexión |
---|
| 2611 | return (TRUE); |
---|
| 2612 | } |
---|
| 2613 | // ________________________________________________________________________________________________________ |
---|
| 2614 | // Función: actualizaHardware |
---|
| 2615 | // |
---|
| 2616 | // Descripción: |
---|
| 2617 | // Actualiza la base de datos con la configuracion hardware del cliente |
---|
| 2618 | // Parámetros: |
---|
| 2619 | // - db: Objeto base de datos (ya operativo) |
---|
| 2620 | // - tbl: Objeto tabla |
---|
| 2621 | // - hrd: cadena con el inventario hardware |
---|
| 2622 | // - ido: Identificador del ordenador |
---|
| 2623 | // - npc: Nombre del ordenador |
---|
| 2624 | // - idc: Identificador del centro o Unidad organizativa |
---|
| 2625 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 2626 | // |
---|
| 2627 | BOOLEAN actualizaHardware(Database db, Table tbl, char* hrd, char*ido,char* npc, char *idc) |
---|
| 2628 | { |
---|
[3ec149c] | 2629 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 2630 | int idtipohardware, idperfilhard; |
---|
| 2631 | int lon, i, j, aux; |
---|
[fc480f2] | 2632 | bool retval; |
---|
[0a73ecf7] | 2633 | char *whard; |
---|
[3ec149c] | 2634 | int tbidhardware[MAXHARDWARE]; |
---|
[0a73ecf7] | 2635 | char *tbHardware[MAXHARDWARE],*dualHardware[2], descripcion[250], strInt[LONINT], *idhardwares; |
---|
[3ec149c] | 2636 | char modulo[] = "actualizaHardware()"; |
---|
| 2637 | |
---|
| 2638 | /* Toma Centro (Unidad Organizativa) */ |
---|
| 2639 | sprintf(sqlstr, "SELECT * FROM ordenadores WHERE idordenador=%s", ido); |
---|
| 2640 | |
---|
| 2641 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2642 | errorLog(modulo, 21, FALSE); |
---|
| 2643 | db.GetErrorErrStr(msglog); |
---|
| 2644 | errorInfo(modulo, msglog); |
---|
| 2645 | return (FALSE); |
---|
| 2646 | } |
---|
| 2647 | if (!tbl.Get("idperfilhard", idperfilhard)) { // Toma dato |
---|
| 2648 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2649 | errorInfo(modulo, msglog); |
---|
| 2650 | return (FALSE); |
---|
| 2651 | } |
---|
[0a73ecf7] | 2652 | whard=escaparCadena(hrd); // Codificar comillas simples |
---|
| 2653 | if(!whard) |
---|
[3ec149c] | 2654 | return (FALSE); |
---|
| 2655 | /* Recorre componentes hardware*/ |
---|
[0a73ecf7] | 2656 | lon = splitCadena(tbHardware, whard, '\n'); |
---|
[3ec149c] | 2657 | if (lon > MAXHARDWARE) |
---|
| 2658 | lon = MAXHARDWARE; // Limita el número de componentes hardware |
---|
| 2659 | /* |
---|
| 2660 | for (i=0;i<lon;i++){ |
---|
| 2661 | sprintf(msglog,"Linea de inventario: %s",tbHardware[i]); |
---|
| 2662 | RegistraLog(msglog,FALSE); |
---|
| 2663 | } |
---|
| 2664 | */ |
---|
| 2665 | for (i = 0; i < lon; i++) { |
---|
| 2666 | splitCadena(dualHardware, rTrim(tbHardware[i]), '='); |
---|
| 2667 | //sprintf(msglog,"nemonico: %s",dualHardware[0]); |
---|
| 2668 | //RegistraLog(msglog,FALSE); |
---|
| 2669 | //sprintf(msglog,"valor: %s",dualHardware[1]); |
---|
| 2670 | //RegistraLog(msglog,FALSE); |
---|
| 2671 | sprintf(sqlstr, "SELECT idtipohardware,descripcion FROM tipohardwares " |
---|
| 2672 | " WHERE nemonico='%s'", dualHardware[0]); |
---|
| 2673 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2674 | errorLog(modulo, 21, FALSE); |
---|
| 2675 | db.GetErrorErrStr(msglog); |
---|
| 2676 | errorInfo(modulo, msglog); |
---|
| 2677 | return (FALSE); |
---|
| 2678 | } |
---|
| 2679 | if (tbl.ISEOF()) { // Tipo de Hardware NO existente |
---|
| 2680 | sprintf(msglog, "%s: %s)", tbErrores[54], dualHardware[0]); |
---|
| 2681 | errorInfo(modulo, msglog); |
---|
| 2682 | return (FALSE); |
---|
| 2683 | } else { // Tipo de Hardware Existe |
---|
| 2684 | if (!tbl.Get("idtipohardware", idtipohardware)) { // Toma dato |
---|
| 2685 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2686 | errorInfo(modulo, msglog); |
---|
| 2687 | return (FALSE); |
---|
| 2688 | } |
---|
| 2689 | if (!tbl.Get("descripcion", descripcion)) { // Toma dato |
---|
| 2690 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2691 | errorInfo(modulo, msglog); |
---|
| 2692 | return (FALSE); |
---|
| 2693 | } |
---|
| 2694 | |
---|
| 2695 | sprintf(sqlstr, "SELECT idhardware FROM hardwares " |
---|
| 2696 | " WHERE idtipohardware=%d AND descripcion='%s'", |
---|
| 2697 | idtipohardware, dualHardware[1]); |
---|
| 2698 | |
---|
| 2699 | // Ejecuta consulta |
---|
| 2700 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2701 | errorLog(modulo, 21, FALSE); |
---|
| 2702 | db.GetErrorErrStr(msglog); |
---|
| 2703 | errorInfo(modulo, msglog); |
---|
| 2704 | return (FALSE); |
---|
| 2705 | } |
---|
| 2706 | |
---|
| 2707 | if (tbl.ISEOF()) { // Hardware NO existente |
---|
[df052e1] | 2708 | sprintf(sqlstr, "INSERT hardwares (idtipohardware,descripcion,idcentro,grupoid) " |
---|
[3ec149c] | 2709 | " VALUES(%d,'%s',%s,0)", idtipohardware, |
---|
| 2710 | dualHardware[1], idc); |
---|
| 2711 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2712 | db.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2713 | errorInfo(modulo, msglog); |
---|
| 2714 | return (FALSE); |
---|
| 2715 | } |
---|
| 2716 | // Recupera el identificador del hardware |
---|
| 2717 | sprintf(sqlstr, "SELECT LAST_INSERT_ID() as identificador"); |
---|
| 2718 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2719 | errorLog(modulo, 21, FALSE); |
---|
| 2720 | db.GetErrorErrStr(msglog); |
---|
| 2721 | errorInfo(modulo, msglog); |
---|
| 2722 | return (FALSE); |
---|
| 2723 | } |
---|
| 2724 | if (!tbl.ISEOF()) { // Si existe registro |
---|
| 2725 | if (!tbl.Get("identificador", tbidhardware[i])) { |
---|
| 2726 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2727 | errorInfo(modulo, msglog); |
---|
| 2728 | return (FALSE); |
---|
| 2729 | } |
---|
| 2730 | } |
---|
| 2731 | } else { |
---|
| 2732 | if (!tbl.Get("idhardware", tbidhardware[i])) { // Toma dato |
---|
| 2733 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 2734 | errorInfo(modulo, msglog); |
---|
| 2735 | return (FALSE); |
---|
| 2736 | } |
---|
| 2737 | } |
---|
| 2738 | } |
---|
| 2739 | } |
---|
| 2740 | // Ordena tabla de identificadores para cosultar si existe un pefil con esas especificaciones |
---|
| 2741 | |
---|
| 2742 | for (i = 0; i < lon - 1; i++) { |
---|
| 2743 | for (j = i + 1; j < lon; j++) { |
---|
| 2744 | if (tbidhardware[i] > tbidhardware[j]) { |
---|
| 2745 | aux = tbidhardware[i]; |
---|
| 2746 | tbidhardware[i] = tbidhardware[j]; |
---|
| 2747 | tbidhardware[j] = aux; |
---|
| 2748 | } |
---|
| 2749 | } |
---|
| 2750 | } |
---|
| 2751 | /* Crea cadena de identificadores de componentes hardware separados por coma */ |
---|
| 2752 | sprintf(strInt, "%d", tbidhardware[lon - 1]); // Pasa a cadena el último identificador que es de mayor longitud |
---|
| 2753 | aux = strlen(strInt); // Calcula longitud de cadena para reservar espacio a todos los perfiles |
---|
| 2754 | idhardwares = reservaMemoria(sizeof(aux) * lon + lon); |
---|
| 2755 | if (idhardwares == NULL) { |
---|
| 2756 | errorLog(modulo, 3, FALSE); |
---|
| 2757 | return (FALSE); |
---|
| 2758 | } |
---|
| 2759 | aux = sprintf(idhardwares, "%d", tbidhardware[0]); |
---|
| 2760 | for (i = 1; i < lon; i++) |
---|
| 2761 | aux += sprintf(idhardwares + aux, ",%d", tbidhardware[i]); |
---|
| 2762 | |
---|
| 2763 | if (!cuestionPerfilHardware(db, tbl, idc, ido, idperfilhard, idhardwares, |
---|
| 2764 | npc, tbidhardware, lon)) { |
---|
| 2765 | errorLog(modulo, 55, FALSE); |
---|
| 2766 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2767 | retval=FALSE; |
---|
[3ec149c] | 2768 | } |
---|
[fc480f2] | 2769 | else { |
---|
| 2770 | retval=TRUE; |
---|
| 2771 | } |
---|
[0a73ecf7] | 2772 | liberaMemoria(whard); |
---|
[fc480f2] | 2773 | liberaMemoria(idhardwares); |
---|
| 2774 | return (retval); |
---|
[3ec149c] | 2775 | } |
---|
| 2776 | // ________________________________________________________________________________________________________ |
---|
| 2777 | // Función: cuestionPerfilHardware |
---|
| 2778 | // |
---|
| 2779 | // Descripción: |
---|
| 2780 | // Comprueba existencia de perfil hardware y actualización de éste para el ordenador |
---|
| 2781 | // Parámetros: |
---|
| 2782 | // - db: Objeto base de datos (ya operativo) |
---|
| 2783 | // - tbl: Objeto tabla |
---|
| 2784 | // - idc: Identificador de la Unidad organizativa donde se encuentra el cliente |
---|
| 2785 | // - ido: Identificador del ordenador |
---|
| 2786 | // - tbidhardware: Identificador del tipo de hardware |
---|
| 2787 | // - con: Número de componentes detectados para configurar un el perfil hardware |
---|
| 2788 | // - npc: Nombre del cliente |
---|
| 2789 | // ________________________________________________________________________________________________________ |
---|
| 2790 | BOOLEAN cuestionPerfilHardware(Database db, Table tbl, char* idc, char* ido, |
---|
| 2791 | int idperfilhardware, char*idhardwares, char *npc, int *tbidhardware, |
---|
| 2792 | int lon) |
---|
| 2793 | { |
---|
| 2794 | char msglog[LONSTD], *sqlstr; |
---|
| 2795 | int i; |
---|
| 2796 | int nwidperfilhard; |
---|
| 2797 | char modulo[] = "cuestionPerfilHardware()"; |
---|
| 2798 | |
---|
| 2799 | sqlstr = reservaMemoria(strlen(idhardwares)+LONSQL); // Reserva para escribir sentencia SQL |
---|
| 2800 | if (sqlstr == NULL) { |
---|
| 2801 | errorLog(modulo, 3, FALSE); |
---|
| 2802 | return (FALSE); |
---|
| 2803 | } |
---|
| 2804 | // Busca perfil hard del ordenador que contenga todos los componentes hardware encontrados |
---|
| 2805 | sprintf(sqlstr, "SELECT idperfilhard FROM" |
---|
| 2806 | " (SELECT perfileshard_hardwares.idperfilhard as idperfilhard," |
---|
| 2807 | " group_concat(cast(perfileshard_hardwares.idhardware AS char( 11) )" |
---|
| 2808 | " ORDER BY perfileshard_hardwares.idhardware SEPARATOR ',' ) AS idhardwares" |
---|
| 2809 | " FROM perfileshard_hardwares" |
---|
| 2810 | " GROUP BY perfileshard_hardwares.idperfilhard) AS temp" |
---|
| 2811 | " WHERE idhardwares LIKE '%s'", idhardwares); |
---|
| 2812 | // Ejecuta consulta |
---|
| 2813 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2814 | errorLog(modulo, 21, FALSE); |
---|
| 2815 | db.GetErrorErrStr(msglog); |
---|
| 2816 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2817 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2818 | return (false); |
---|
| 2819 | } |
---|
| 2820 | if (tbl.ISEOF()) { // No existe un perfil hardware con esos componentes de componentes hardware, lo crea |
---|
| 2821 | sprintf(sqlstr, "INSERT perfileshard (descripcion,idcentro,grupoid)" |
---|
[df052e1] | 2822 | " VALUES('Perfil hardware (%s) ',%s,0)", npc, idc); |
---|
[3ec149c] | 2823 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2824 | db.GetErrorErrStr(msglog); |
---|
| 2825 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2826 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2827 | return (false); |
---|
| 2828 | } |
---|
| 2829 | // Recupera el identificador del nuevo perfil hardware |
---|
| 2830 | sprintf(sqlstr, "SELECT LAST_INSERT_ID() as identificador"); |
---|
| 2831 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 2832 | db.GetErrorErrStr(msglog); |
---|
| 2833 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2834 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2835 | return (false); |
---|
| 2836 | } |
---|
| 2837 | if (!tbl.ISEOF()) { // Si existe registro |
---|
| 2838 | if (!tbl.Get("identificador", nwidperfilhard)) { |
---|
| 2839 | tbl.GetErrorErrStr(msglog); |
---|
| 2840 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2841 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2842 | return (false); |
---|
| 2843 | } |
---|
| 2844 | } |
---|
| 2845 | // Crea la relación entre perfiles y componenetes hardware |
---|
| 2846 | for (i = 0; i < lon; i++) { |
---|
[df052e1] | 2847 | sprintf(sqlstr, "INSERT perfileshard_hardwares (idperfilhard,idhardware)" |
---|
[3ec149c] | 2848 | " VALUES(%d,%d)", nwidperfilhard, tbidhardware[i]); |
---|
| 2849 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2850 | db.GetErrorErrStr(msglog); |
---|
| 2851 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2852 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2853 | return (false); |
---|
| 2854 | } |
---|
| 2855 | } |
---|
| 2856 | } else { // Existe un perfil con todos esos componentes |
---|
| 2857 | if (!tbl.Get("idperfilhard", nwidperfilhard)) { |
---|
| 2858 | tbl.GetErrorErrStr(msglog); |
---|
| 2859 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2860 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2861 | return (false); |
---|
| 2862 | } |
---|
| 2863 | } |
---|
| 2864 | if (idperfilhardware != nwidperfilhard) { // No coinciden los perfiles |
---|
| 2865 | // Actualiza el identificador del perfil hardware del ordenador |
---|
| 2866 | sprintf(sqlstr, "UPDATE ordenadores SET idperfilhard=%d" |
---|
| 2867 | " WHERE idordenador=%s", nwidperfilhard, ido); |
---|
| 2868 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2869 | db.GetErrorErrStr(msglog); |
---|
| 2870 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2871 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2872 | return (false); |
---|
| 2873 | } |
---|
| 2874 | } |
---|
| 2875 | /* Eliminar Relación de hardwares con Perfiles hardware que quedan húerfanos */ |
---|
| 2876 | sprintf(sqlstr, "DELETE FROM perfileshard_hardwares WHERE idperfilhard IN " |
---|
| 2877 | " (SELECT idperfilhard FROM perfileshard WHERE idperfilhard NOT IN" |
---|
| 2878 | " (SELECT DISTINCT idperfilhard from ordenadores))"); |
---|
| 2879 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2880 | db.GetErrorErrStr(msglog); |
---|
| 2881 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2882 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2883 | return (false); |
---|
| 2884 | } |
---|
| 2885 | |
---|
| 2886 | /* Eliminar Perfiles hardware que quedan húerfanos */ |
---|
| 2887 | sprintf(sqlstr, "DELETE FROM perfileshard WHERE idperfilhard NOT IN" |
---|
[fc480f2] | 2888 | " (SELECT DISTINCT idperfilhard FROM ordenadores)"); |
---|
[3ec149c] | 2889 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2890 | db.GetErrorErrStr(msglog); |
---|
| 2891 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2892 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2893 | return (false); |
---|
| 2894 | } |
---|
| 2895 | /* Eliminar Relación de hardwares con Perfiles hardware que quedan húerfanos */ |
---|
[fc480f2] | 2896 | sprintf(sqlstr, "DELETE FROM perfileshard_hardwares WHERE idperfilhard NOT IN" |
---|
| 2897 | " (SELECT idperfilhard FROM perfileshard)"); |
---|
[3ec149c] | 2898 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 2899 | db.GetErrorErrStr(msglog); |
---|
| 2900 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 2901 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2902 | return (false); |
---|
| 2903 | } |
---|
[fc480f2] | 2904 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 2905 | return (TRUE); |
---|
| 2906 | } |
---|
| 2907 | // ________________________________________________________________________________________________________ |
---|
| 2908 | // Función: InventarioSoftware |
---|
| 2909 | // |
---|
| 2910 | // Descripción: |
---|
| 2911 | // Solicita al cliente un inventario de su software |
---|
| 2912 | // Parámetros: |
---|
| 2913 | // - socket_c: Socket de la consola al envió el mensaje |
---|
| 2914 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2915 | // Devuelve: |
---|
| 2916 | // TRUE: Si el proceso es correcto |
---|
| 2917 | // FALSE: En caso de ocurrir algún error |
---|
| 2918 | // ________________________________________________________________________________________________________ |
---|
| 2919 | BOOLEAN InventarioSoftware(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2920 | char msglog[LONSTD]; |
---|
| 2921 | char modulo[] = "InventarioSoftware()"; |
---|
| 2922 | |
---|
| 2923 | if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { |
---|
| 2924 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 2925 | errorInfo(modulo, msglog); |
---|
| 2926 | respuestaConsola(socket_c, ptrTrama, FALSE); |
---|
| 2927 | return (FALSE); |
---|
| 2928 | } |
---|
| 2929 | respuestaConsola(socket_c, ptrTrama, TRUE); |
---|
| 2930 | return (TRUE); |
---|
| 2931 | } |
---|
| 2932 | // ________________________________________________________________________________________________________ |
---|
| 2933 | // Función: RESPUESTA_InventarioSoftware |
---|
| 2934 | // |
---|
| 2935 | // Descripción: |
---|
| 2936 | // Respuesta del cliente al comando InventarioSoftware |
---|
| 2937 | // Parámetros: |
---|
| 2938 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 2939 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 2940 | // Devuelve: |
---|
| 2941 | // TRUE: Si el proceso es correcto |
---|
| 2942 | // FALSE: En caso de ocurrir algún error |
---|
| 2943 | // ________________________________________________________________________________________________________ |
---|
| 2944 | BOOLEAN RESPUESTA_InventarioSoftware(SOCKET *socket_c, TRAMA* ptrTrama) { |
---|
| 2945 | char msglog[LONSTD]; |
---|
| 2946 | Database db; |
---|
| 2947 | Table tbl; |
---|
[0a73ecf7] | 2948 | BOOLEAN res; |
---|
[3ec149c] | 2949 | char *iph, *ido, *npc, *idc, *par, *sft, *buffer; |
---|
| 2950 | char modulo[] = "RESPUESTA_InventarioSoftware()"; |
---|
| 2951 | |
---|
| 2952 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 2953 | errorLog(modulo, 20, FALSE); |
---|
| 2954 | db.GetErrorErrStr(msglog); |
---|
| 2955 | errorInfo(modulo, msglog); |
---|
| 2956 | return (FALSE); |
---|
| 2957 | } |
---|
| 2958 | |
---|
| 2959 | iph = copiaParametro("iph",ptrTrama); // Toma dirección ip |
---|
| 2960 | ido = copiaParametro("ido",ptrTrama); // Toma identificador del ordenador |
---|
| 2961 | |
---|
| 2962 | if (!respuestaEstandar(ptrTrama, iph, ido, db, tbl)) { |
---|
[0a73ecf7] | 2963 | liberaMemoria(iph); |
---|
| 2964 | liberaMemoria(ido); |
---|
[3ec149c] | 2965 | errorLog(modulo, 30, FALSE); |
---|
| 2966 | return (FALSE); // Error al registrar notificacion |
---|
| 2967 | } |
---|
[0a73ecf7] | 2968 | |
---|
| 2969 | npc = copiaParametro("npc",ptrTrama); |
---|
| 2970 | idc = copiaParametro("idc",ptrTrama); // Toma identificador del Centro |
---|
[3ec149c] | 2971 | par = copiaParametro("par",ptrTrama); |
---|
| 2972 | sft = copiaParametro("sft",ptrTrama); |
---|
| 2973 | |
---|
| 2974 | buffer = rTrim(leeArchivo(sft)); |
---|
[0a73ecf7] | 2975 | if (buffer) |
---|
| 2976 | res=actualizaSoftware(db, tbl, buffer, par, ido, npc, idc); |
---|
| 2977 | |
---|
| 2978 | liberaMemoria(iph); |
---|
| 2979 | liberaMemoria(ido); |
---|
| 2980 | liberaMemoria(npc); |
---|
| 2981 | liberaMemoria(idc); |
---|
| 2982 | liberaMemoria(par); |
---|
| 2983 | liberaMemoria(sft); |
---|
| 2984 | |
---|
| 2985 | if(!res){ |
---|
| 2986 | errorLog(modulo, 82, FALSE); |
---|
| 2987 | return (FALSE); |
---|
| 2988 | } |
---|
| 2989 | |
---|
[3ec149c] | 2990 | db.Close(); // Cierra conexión |
---|
| 2991 | return (TRUE); |
---|
| 2992 | } |
---|
| 2993 | // ________________________________________________________________________________________________________ |
---|
| 2994 | // Función: actualizaSoftware |
---|
| 2995 | // |
---|
| 2996 | // Descripción: |
---|
| 2997 | // Actualiza la base de datos con la configuración software del cliente |
---|
| 2998 | // Parámetros: |
---|
| 2999 | // - db: Objeto base de datos (ya operativo) |
---|
| 3000 | // - tbl: Objeto tabla |
---|
| 3001 | // - sft: cadena con el inventario software |
---|
| 3002 | // - par: Número de la partición |
---|
| 3003 | // - ido: Identificador del ordenador del cliente en la tabla |
---|
| 3004 | // - npc: Nombre del ordenador |
---|
| 3005 | // - idc: Identificador del centro o Unidad organizativa |
---|
| 3006 | // Devuelve: |
---|
| 3007 | // TRUE: Si el proceso es correcto |
---|
| 3008 | // FALSE: En caso de ocurrir algún error |
---|
| 3009 | // ________________________________________________________________________________________________________ |
---|
[0a73ecf7] | 3010 | BOOLEAN actualizaSoftware(Database db, Table tbl, char* sft, char* par,char* ido, char* npc, char* idc) |
---|
| 3011 | { |
---|
[3ec149c] | 3012 | int i, j, lon, aux, idperfilsoft; |
---|
[fc480f2] | 3013 | bool retval; |
---|
[0a73ecf7] | 3014 | char *wsft; |
---|
[3ec149c] | 3015 | int tbidsoftware[MAXSOFTWARE]; |
---|
[0a73ecf7] | 3016 | char *tbSoftware[MAXSOFTWARE],msglog[LONSTD], sqlstr[LONSQL], strInt[LONINT], *idsoftwares; |
---|
[3ec149c] | 3017 | char modulo[] = "actualizaSoftware()"; |
---|
| 3018 | |
---|
| 3019 | /* Toma Centro (Unidad Organizativa) y perfil software */ |
---|
| 3020 | sprintf(sqlstr, "SELECT idperfilsoft,numpar" |
---|
| 3021 | " FROM ordenadores_particiones" |
---|
| 3022 | " WHERE idordenador=%s", ido); |
---|
| 3023 | |
---|
| 3024 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3025 | errorLog(modulo, 21, FALSE); |
---|
| 3026 | db.GetErrorErrStr(msglog); |
---|
| 3027 | errorInfo(modulo, msglog); |
---|
| 3028 | return (FALSE); |
---|
| 3029 | } |
---|
| 3030 | idperfilsoft = 0; // Por defecto se supone que el ordenador no tiene aún detectado el perfil software |
---|
| 3031 | while (!tbl.ISEOF()) { // Recorre particiones |
---|
| 3032 | if (!tbl.Get("numpar", aux)) { |
---|
| 3033 | tbl.GetErrorErrStr(msglog); |
---|
| 3034 | errorInfo(modulo, msglog); |
---|
| 3035 | return (FALSE); |
---|
| 3036 | } |
---|
| 3037 | if (aux == atoi(par)) { // Se encuentra la partición |
---|
| 3038 | if (!tbl.Get("idperfilsoft", idperfilsoft)) { |
---|
| 3039 | tbl.GetErrorErrStr(msglog); |
---|
| 3040 | errorInfo(modulo, msglog); |
---|
| 3041 | return (FALSE); |
---|
| 3042 | } |
---|
| 3043 | break; |
---|
| 3044 | } |
---|
| 3045 | tbl.MoveNext(); |
---|
| 3046 | } |
---|
[0a73ecf7] | 3047 | wsft=escaparCadena(sft); // Codificar comillas simples |
---|
| 3048 | if(!wsft) |
---|
[3ec149c] | 3049 | return (FALSE); |
---|
| 3050 | |
---|
| 3051 | /* Recorre componentes software*/ |
---|
[0a73ecf7] | 3052 | lon = splitCadena(tbSoftware, wsft, '\n'); |
---|
| 3053 | |
---|
[3ec149c] | 3054 | if (lon == 0) |
---|
| 3055 | return (true); // No hay lineas que procesar |
---|
| 3056 | if (lon > MAXSOFTWARE) |
---|
| 3057 | lon = MAXSOFTWARE; // Limita el número de componentes software |
---|
| 3058 | |
---|
| 3059 | for (i = 0; i < lon; i++) { |
---|
| 3060 | sprintf(sqlstr, |
---|
| 3061 | "SELECT idsoftware FROM softwares WHERE descripcion ='%s'", |
---|
| 3062 | rTrim(tbSoftware[i])); |
---|
| 3063 | |
---|
| 3064 | // Ejecuta consulta |
---|
| 3065 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3066 | errorLog(modulo, 21, FALSE); |
---|
| 3067 | db.GetErrorErrStr(msglog); |
---|
| 3068 | errorInfo(modulo, msglog); |
---|
| 3069 | return (FALSE); |
---|
| 3070 | } |
---|
| 3071 | |
---|
| 3072 | if (tbl.ISEOF()) { // Software NO existente |
---|
[df052e1] | 3073 | sprintf(sqlstr, "INSERT INTO softwares (idtiposoftware,descripcion,idcentro,grupoid)" |
---|
[3ec149c] | 3074 | " VALUES(2,'%s',%s,0)", tbSoftware[i], idc); |
---|
| 3075 | |
---|
| 3076 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3077 | db.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 3078 | errorInfo(modulo, msglog); |
---|
| 3079 | return (FALSE); |
---|
| 3080 | } |
---|
| 3081 | // Recupera el identificador del software |
---|
| 3082 | sprintf(sqlstr, "SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3083 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3084 | db.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 3085 | errorInfo(modulo, msglog); |
---|
| 3086 | return (FALSE); |
---|
| 3087 | } |
---|
| 3088 | if (!tbl.ISEOF()) { // Si existe registro |
---|
| 3089 | if (!tbl.Get("identificador", tbidsoftware[i])) { |
---|
| 3090 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 3091 | errorInfo(modulo, msglog); |
---|
| 3092 | return (FALSE); |
---|
| 3093 | } |
---|
| 3094 | } |
---|
| 3095 | } else { |
---|
| 3096 | if (!tbl.Get("idsoftware", tbidsoftware[i])) { // Toma dato |
---|
| 3097 | tbl.GetErrorErrStr(msglog); // Error al acceder al registro |
---|
| 3098 | errorInfo(modulo, msglog); |
---|
| 3099 | return (FALSE); |
---|
| 3100 | } |
---|
| 3101 | } |
---|
| 3102 | } |
---|
| 3103 | |
---|
| 3104 | // Ordena tabla de identificadores para cosultar si existe un pefil con esas especificaciones |
---|
| 3105 | |
---|
| 3106 | for (i = 0; i < lon - 1; i++) { |
---|
| 3107 | for (j = i + 1; j < lon; j++) { |
---|
| 3108 | if (tbidsoftware[i] > tbidsoftware[j]) { |
---|
| 3109 | aux = tbidsoftware[i]; |
---|
| 3110 | tbidsoftware[i] = tbidsoftware[j]; |
---|
| 3111 | tbidsoftware[j] = aux; |
---|
| 3112 | } |
---|
| 3113 | } |
---|
| 3114 | } |
---|
| 3115 | /* Crea cadena de identificadores de componentes software separados por coma */ |
---|
| 3116 | sprintf(strInt, "%d", tbidsoftware[lon - 1]); // Pasa a cadena el último identificador que es de mayor longitud |
---|
| 3117 | aux = strlen(strInt); // Calcula longitud de cadena para reservar espacio a todos los perfiles |
---|
| 3118 | idsoftwares = reservaMemoria((sizeof(aux)+1) * lon + lon); |
---|
| 3119 | if (idsoftwares == NULL) { |
---|
| 3120 | errorLog(modulo, 3, FALSE); |
---|
| 3121 | return (FALSE); |
---|
| 3122 | } |
---|
| 3123 | aux = sprintf(idsoftwares, "%d", tbidsoftware[0]); |
---|
| 3124 | for (i = 1; i < lon; i++) |
---|
| 3125 | aux += sprintf(idsoftwares + aux, ",%d", tbidsoftware[i]); |
---|
| 3126 | |
---|
| 3127 | // Comprueba existencia de perfil software y actualización de éste para el ordenador |
---|
| 3128 | if (!cuestionPerfilSoftware(db, tbl, idc, ido, idperfilsoft, idsoftwares, |
---|
| 3129 | npc, par, tbidsoftware, lon)) { |
---|
| 3130 | errorLog(modulo, 83, FALSE); |
---|
| 3131 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3132 | retval=FALSE; |
---|
[3ec149c] | 3133 | } |
---|
[fc480f2] | 3134 | else { |
---|
| 3135 | retval=TRUE; |
---|
| 3136 | } |
---|
[0a73ecf7] | 3137 | liberaMemoria(wsft); |
---|
[fc480f2] | 3138 | liberaMemoria(idsoftwares); |
---|
| 3139 | return (retval); |
---|
[3ec149c] | 3140 | } |
---|
| 3141 | // ________________________________________________________________________________________________________ |
---|
| 3142 | // Función: CuestionPerfilSoftware |
---|
| 3143 | // |
---|
| 3144 | // Parámetros: |
---|
| 3145 | // - db: Objeto base de datos (ya operativo) |
---|
| 3146 | // - tbl: Objeto tabla |
---|
| 3147 | // - idcentro: Identificador del centro en la tabla |
---|
| 3148 | // - ido: Identificador del ordenador del cliente en la tabla |
---|
| 3149 | // - idsoftwares: Cadena con los identificadores de componentes software separados por comas |
---|
| 3150 | // - npc: Nombre del ordenador del cliente |
---|
| 3151 | // - particion: Número de la partición |
---|
| 3152 | // - tbidsoftware: Array con los identificadores de componentes software |
---|
| 3153 | // - lon: Número de componentes |
---|
| 3154 | // Devuelve: |
---|
| 3155 | // TRUE: Si el proceso es correcto |
---|
| 3156 | // FALSE: En caso de ocurrir algún error |
---|
| 3157 | //________________________________________________________________________________________________________/ |
---|
| 3158 | BOOLEAN cuestionPerfilSoftware(Database db, Table tbl, char* idc, char* ido, |
---|
| 3159 | int idperfilsoftware, char *idsoftwares, char *npc, char *par, |
---|
| 3160 | int *tbidsoftware, int lon) { |
---|
| 3161 | char *sqlstr, msglog[LONSTD]; |
---|
| 3162 | int i, nwidperfilsoft; |
---|
| 3163 | char modulo[] = "cuestionPerfilSoftware()"; |
---|
| 3164 | |
---|
| 3165 | sqlstr = reservaMemoria(strlen(idsoftwares)+LONSQL); // Reserva para escribir sentencia SQL |
---|
| 3166 | if (sqlstr == NULL) { |
---|
| 3167 | errorLog(modulo, 3, FALSE); |
---|
| 3168 | return (FALSE); |
---|
| 3169 | } |
---|
| 3170 | // Busca perfil soft del ordenador que contenga todos los componentes software encontrados |
---|
| 3171 | sprintf(sqlstr, "SELECT idperfilsoft FROM" |
---|
| 3172 | " (SELECT perfilessoft_softwares.idperfilsoft as idperfilsoft," |
---|
| 3173 | " group_concat(cast(perfilessoft_softwares.idsoftware AS char( 11) )" |
---|
| 3174 | " ORDER BY perfilessoft_softwares.idsoftware SEPARATOR ',' ) AS idsoftwares" |
---|
| 3175 | " FROM perfilessoft_softwares" |
---|
| 3176 | " GROUP BY perfilessoft_softwares.idperfilsoft) AS temp" |
---|
| 3177 | " WHERE idsoftwares LIKE '%s'", idsoftwares); |
---|
| 3178 | // Ejecuta consulta |
---|
| 3179 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3180 | errorLog(modulo, 21, FALSE); |
---|
| 3181 | db.GetErrorErrStr(msglog); |
---|
| 3182 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3183 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3184 | return (false); |
---|
| 3185 | } |
---|
| 3186 | if (tbl.ISEOF()) { // No existe un perfil software con esos componentes de componentes software, lo crea |
---|
| 3187 | sprintf(sqlstr, "INSERT perfilessoft (descripcion,idcentro,grupoid)" |
---|
[df052e1] | 3188 | " VALUES('Perfil Software (%s, Part:%s) ',%s,0)", npc, par, idc); |
---|
[3ec149c] | 3189 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3190 | db.GetErrorErrStr(msglog); |
---|
| 3191 | errorInfo(modulo, msglog); |
---|
| 3192 | return (false); |
---|
| 3193 | } |
---|
| 3194 | // Recupera el identificador del nuevo perfil software |
---|
| 3195 | sprintf(sqlstr, "SELECT LAST_INSERT_ID() as identificador"); |
---|
| 3196 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3197 | tbl.GetErrorErrStr(msglog); |
---|
| 3198 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3199 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3200 | return (false); |
---|
| 3201 | } |
---|
| 3202 | if (!tbl.ISEOF()) { // Si existe registro |
---|
| 3203 | if (!tbl.Get("identificador", nwidperfilsoft)) { |
---|
| 3204 | tbl.GetErrorErrStr(msglog); |
---|
| 3205 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3206 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3207 | return (false); |
---|
| 3208 | } |
---|
| 3209 | } |
---|
| 3210 | // Crea la relación entre perfiles y componenetes software |
---|
| 3211 | for (i = 0; i < lon; i++) { |
---|
[fc480f2] | 3212 | sprintf(sqlstr, "INSERT perfilessoft_softwares (idperfilsoft,idsoftware)" |
---|
[3ec149c] | 3213 | " VALUES(%d,%d)", nwidperfilsoft, tbidsoftware[i]); |
---|
| 3214 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3215 | db.GetErrorErrStr(msglog); |
---|
| 3216 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3217 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3218 | return (false); |
---|
| 3219 | } |
---|
| 3220 | } |
---|
| 3221 | } else { // Existe un perfil con todos esos componentes |
---|
| 3222 | if (!tbl.Get("idperfilsoft", nwidperfilsoft)) { |
---|
| 3223 | tbl.GetErrorErrStr(msglog); |
---|
| 3224 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3225 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3226 | return (false); |
---|
| 3227 | } |
---|
| 3228 | } |
---|
| 3229 | |
---|
| 3230 | if (idperfilsoftware != nwidperfilsoft) { // No coinciden los perfiles |
---|
| 3231 | // Actualiza el identificador del perfil software del ordenador |
---|
[fc480f2] | 3232 | sprintf(sqlstr, "UPDATE ordenadores_particiones SET idperfilsoft=%d,idimagen=0" |
---|
| 3233 | " WHERE idordenador=%s AND numpar=%s", nwidperfilsoft, ido, par); |
---|
[3ec149c] | 3234 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3235 | db.GetErrorErrStr(msglog); |
---|
| 3236 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3237 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3238 | return (false); |
---|
| 3239 | } |
---|
| 3240 | } |
---|
| 3241 | |
---|
| 3242 | /* DEPURACIÓN DE PERFILES SOFTWARE */ |
---|
| 3243 | |
---|
| 3244 | /* Eliminar Relación de softwares con Perfiles software que quedan húerfanos */ |
---|
| 3245 | sprintf(sqlstr, "DELETE FROM perfilessoft_softwares WHERE idperfilsoft IN "\ |
---|
| 3246 | " (SELECT idperfilsoft FROM perfilessoft WHERE idperfilsoft NOT IN"\ |
---|
| 3247 | " (SELECT DISTINCT idperfilsoft from ordenadores_particiones) AND idperfilsoft NOT IN"\ |
---|
| 3248 | " (SELECT DISTINCT idperfilsoft from imagenes))"); |
---|
| 3249 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3250 | db.GetErrorErrStr(msglog); |
---|
| 3251 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3252 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3253 | return (false); |
---|
| 3254 | } |
---|
| 3255 | /* Eliminar Perfiles software que quedan húerfanos */ |
---|
| 3256 | sprintf(sqlstr, "DELETE FROM perfilessoft WHERE idperfilsoft NOT IN" |
---|
| 3257 | " (SELECT DISTINCT idperfilsoft from ordenadores_particiones)"\ |
---|
| 3258 | " AND idperfilsoft NOT IN"\ |
---|
| 3259 | " (SELECT DISTINCT idperfilsoft from imagenes)"); |
---|
| 3260 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3261 | db.GetErrorErrStr(msglog); |
---|
| 3262 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3263 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3264 | return (false); |
---|
| 3265 | } |
---|
| 3266 | /* Eliminar Relación de softwares con Perfiles software que quedan húerfanos */ |
---|
[fc480f2] | 3267 | sprintf(sqlstr, "DELETE FROM perfilessoft_softwares WHERE idperfilsoft NOT IN" |
---|
| 3268 | " (SELECT idperfilsoft from perfilessoft)"); |
---|
[3ec149c] | 3269 | if (!db.Execute(sqlstr, tbl)) { // Error al insertar |
---|
| 3270 | db.GetErrorErrStr(msglog); |
---|
| 3271 | errorInfo(modulo, msglog); |
---|
[fc480f2] | 3272 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3273 | return (false); |
---|
| 3274 | } |
---|
[fc480f2] | 3275 | liberaMemoria(sqlstr); |
---|
[3ec149c] | 3276 | return (TRUE); |
---|
| 3277 | } |
---|
| 3278 | // ________________________________________________________________________________________________________ |
---|
| 3279 | // Función: enviaArchivo |
---|
| 3280 | // |
---|
| 3281 | // Descripción: |
---|
| 3282 | // Envia un archivo por la red, por bloques |
---|
| 3283 | // Parámetros: |
---|
| 3284 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 3285 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 3286 | // Devuelve: |
---|
| 3287 | // TRUE: Si el proceso es correcto |
---|
| 3288 | // FALSE: En caso de ocurrir algún error |
---|
| 3289 | // ________________________________________________________________________________________________________ |
---|
| 3290 | BOOLEAN enviaArchivo(SOCKET *socket_c, TRAMA *ptrTrama) { |
---|
| 3291 | char *nfl; |
---|
| 3292 | char modulo[] = "enviaArchivo()"; |
---|
| 3293 | |
---|
| 3294 | // Toma parámetros |
---|
| 3295 | nfl = copiaParametro("nfl",ptrTrama); // Toma nombre completo del archivo |
---|
| 3296 | if (!sendArchivo(socket_c, nfl)) { |
---|
[0a73ecf7] | 3297 | liberaMemoria(nfl); |
---|
[3ec149c] | 3298 | errorLog(modulo, 57, FALSE); |
---|
| 3299 | return (FALSE); |
---|
| 3300 | } |
---|
[0a73ecf7] | 3301 | liberaMemoria(nfl); |
---|
[3ec149c] | 3302 | return (TRUE); |
---|
| 3303 | } |
---|
| 3304 | // ________________________________________________________________________________________________________ |
---|
| 3305 | // Función: enviaArchivo |
---|
| 3306 | // |
---|
| 3307 | // Descripción: |
---|
| 3308 | // Envia un archivo por la red, por bloques |
---|
| 3309 | // Parámetros: |
---|
| 3310 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 3311 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 3312 | // Devuelve: |
---|
| 3313 | // TRUE: Si el proceso es correcto |
---|
| 3314 | // FALSE: En caso de ocurrir algún error |
---|
| 3315 | // ________________________________________________________________________________________________________ |
---|
| 3316 | BOOLEAN recibeArchivo(SOCKET *socket_c, TRAMA *ptrTrama) { |
---|
| 3317 | char *nfl; |
---|
| 3318 | char modulo[] = "recibeArchivo()"; |
---|
| 3319 | |
---|
| 3320 | // Toma parámetros |
---|
| 3321 | nfl = copiaParametro("nfl",ptrTrama); // Toma nombre completo del archivo |
---|
| 3322 | ptrTrama->tipo = MSG_NOTIFICACION; |
---|
| 3323 | enviaFlag(socket_c, ptrTrama); |
---|
| 3324 | if (!recArchivo(socket_c, nfl)) { |
---|
[0a73ecf7] | 3325 | liberaMemoria(nfl); |
---|
[3ec149c] | 3326 | errorLog(modulo, 58, FALSE); |
---|
| 3327 | return (FALSE); |
---|
| 3328 | } |
---|
[0a73ecf7] | 3329 | liberaMemoria(nfl); |
---|
[3ec149c] | 3330 | return (TRUE); |
---|
| 3331 | } |
---|
| 3332 | // ________________________________________________________________________________________________________ |
---|
| 3333 | // Función: envioProgramacion |
---|
| 3334 | // |
---|
| 3335 | // Descripción: |
---|
| 3336 | // Envia un comando de actualización a todos los ordenadores que han sido programados con |
---|
| 3337 | // alguna acción para que entren en el bucle de comandos pendientes y las ejecuten |
---|
| 3338 | // Parámetros: |
---|
| 3339 | // - socket_c: Socket del cliente que envió el mensaje |
---|
| 3340 | // - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros |
---|
| 3341 | // Devuelve: |
---|
| 3342 | // TRUE: Si el proceso es correcto |
---|
| 3343 | // FALSE: En caso de ocurrir algún error |
---|
| 3344 | // ________________________________________________________________________________________________________ |
---|
| 3345 | BOOLEAN envioProgramacion(SOCKET *socket_c, TRAMA *ptrTrama) |
---|
| 3346 | { |
---|
| 3347 | char sqlstr[LONSQL], msglog[LONSTD]; |
---|
| 3348 | char *idp,iph[LONIP],mac[LONMAC]; |
---|
| 3349 | Database db; |
---|
| 3350 | Table tbl; |
---|
| 3351 | int idx,idcomando; |
---|
| 3352 | char modulo[] = "envioProgramacion()"; |
---|
| 3353 | |
---|
| 3354 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 3355 | errorLog(modulo, 20, FALSE); |
---|
| 3356 | db.GetErrorErrStr(msglog); |
---|
| 3357 | errorInfo(modulo, msglog); |
---|
| 3358 | return (FALSE); |
---|
| 3359 | } |
---|
| 3360 | |
---|
[0a73ecf7] | 3361 | idp = copiaParametro("idp",ptrTrama); // Toma identificador de la programación de la tabla acciones |
---|
[3ec149c] | 3362 | |
---|
| 3363 | sprintf(sqlstr, "SELECT ordenadores.ip,ordenadores.mac,acciones.idcomando FROM acciones "\ |
---|
| 3364 | " INNER JOIN ordenadores ON ordenadores.ip=acciones.ip"\ |
---|
| 3365 | " WHERE acciones.idprogramacion=%s",idp); |
---|
[0a73ecf7] | 3366 | |
---|
| 3367 | liberaMemoria(idp); |
---|
| 3368 | |
---|
[3ec149c] | 3369 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 3370 | errorLog(modulo, 21, FALSE); |
---|
| 3371 | db.GetErrorErrStr(msglog); |
---|
| 3372 | errorInfo(modulo, msglog); |
---|
| 3373 | return (FALSE); |
---|
| 3374 | } |
---|
| 3375 | if(tbl.ISEOF()) |
---|
| 3376 | return (TRUE); // No existen registros |
---|
| 3377 | |
---|
| 3378 | /* Prepara la trama de actualizacion */ |
---|
| 3379 | |
---|
| 3380 | initParametros(ptrTrama,0); |
---|
| 3381 | ptrTrama->tipo=MSG_COMANDO; |
---|
| 3382 | sprintf(ptrTrama->parametros, "nfn=Actualizar\r"); |
---|
| 3383 | |
---|
| 3384 | while (!tbl.ISEOF()) { // Recorre particiones |
---|
| 3385 | if (!tbl.Get("ip", iph)) { |
---|
| 3386 | tbl.GetErrorErrStr(msglog); |
---|
| 3387 | errorInfo(modulo, msglog); |
---|
| 3388 | return (FALSE); |
---|
| 3389 | } |
---|
| 3390 | if (!tbl.Get("idcomando", idcomando)) { |
---|
| 3391 | tbl.GetErrorErrStr(msglog); |
---|
| 3392 | errorInfo(modulo, msglog); |
---|
| 3393 | return (FALSE); |
---|
| 3394 | } |
---|
| 3395 | if(idcomando==1){ // Arrancar |
---|
| 3396 | if (!tbl.Get("mac", mac)) { |
---|
| 3397 | tbl.GetErrorErrStr(msglog); |
---|
| 3398 | errorInfo(modulo, msglog); |
---|
| 3399 | return (FALSE); |
---|
| 3400 | } |
---|
| 3401 | if (!Levanta(mac)) { |
---|
| 3402 | sprintf(msglog, "%s:%s", tbErrores[32], modulo); |
---|
| 3403 | errorInfo(modulo, msglog); |
---|
| 3404 | return (FALSE); |
---|
| 3405 | } |
---|
| 3406 | } |
---|
| 3407 | if (clienteDisponible(iph, &idx)) { // Si el cliente puede recibir comandos |
---|
| 3408 | strcpy(tbsockets[idx].estado, CLIENTE_OCUPADO); // Actualiza el estado del cliente |
---|
| 3409 | if (!mandaTrama(&tbsockets[idx].sock, ptrTrama)) { |
---|
| 3410 | errorLog(modulo, 26, FALSE); |
---|
| 3411 | return (FALSE); |
---|
| 3412 | } |
---|
| 3413 | close(tbsockets[idx].sock); // Cierra el socket del cliente hasta nueva disponibilidad |
---|
| 3414 | } |
---|
| 3415 | tbl.MoveNext(); |
---|
| 3416 | } |
---|
| 3417 | return (TRUE); // No existen registros |
---|
| 3418 | } |
---|
| 3419 | // ******************************************************************************************************** |
---|
| 3420 | // PROGRAMA PRINCIPAL (SERVICIO) |
---|
| 3421 | // ******************************************************************************************************** |
---|
| 3422 | int main(int argc, char *argv[]) { |
---|
| 3423 | int i; |
---|
| 3424 | SOCKET socket_s; // Socket donde escucha el servidor |
---|
| 3425 | SOCKET socket_c; // Socket de los clientes que se conectan |
---|
| 3426 | socklen_t iAddrSize; |
---|
| 3427 | struct sockaddr_in local, cliente; |
---|
| 3428 | char modulo[] = "main()"; |
---|
| 3429 | |
---|
| 3430 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3431 | Validación de parámetros de ejecución y lectura del fichero de configuración del servicio |
---|
| 3432 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3433 | if (!validacionParametros(argc, argv, 1)) // Valida parámetros de ejecución |
---|
| 3434 | exit(EXIT_FAILURE); |
---|
| 3435 | |
---|
| 3436 | if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion |
---|
| 3437 | exit(EXIT_FAILURE); |
---|
| 3438 | } |
---|
| 3439 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3440 | Carga del catálogo de funciones que procesan las tramas (referencia directa por puntero a función) |
---|
| 3441 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3442 | int cf = 0; |
---|
| 3443 | |
---|
| 3444 | strcpy(tbfuncionesServer[cf].nf, "Sondeo"); |
---|
| 3445 | tbfuncionesServer[cf++].fptr = &Sondeo; |
---|
| 3446 | strcpy(tbfuncionesServer[cf].nf, "respuestaSondeo"); |
---|
| 3447 | tbfuncionesServer[cf++].fptr = &respuestaSondeo; |
---|
| 3448 | |
---|
| 3449 | strcpy(tbfuncionesServer[cf].nf, "ConsolaRemota"); |
---|
| 3450 | tbfuncionesServer[cf++].fptr = &ConsolaRemota; |
---|
| 3451 | |
---|
| 3452 | strcpy(tbfuncionesServer[cf].nf, "EcoConsola"); |
---|
| 3453 | tbfuncionesServer[cf++].fptr = &EcoConsola; |
---|
| 3454 | |
---|
| 3455 | strcpy(tbfuncionesServer[cf].nf, "Actualizar"); |
---|
| 3456 | tbfuncionesServer[cf++].fptr = &Actualizar; |
---|
| 3457 | |
---|
| 3458 | strcpy(tbfuncionesServer[cf].nf, "Purgar"); |
---|
| 3459 | tbfuncionesServer[cf++].fptr = &Purgar; |
---|
| 3460 | |
---|
| 3461 | strcpy(tbfuncionesServer[cf].nf, "InclusionCliente"); |
---|
| 3462 | tbfuncionesServer[cf++].fptr = &InclusionCliente; |
---|
| 3463 | |
---|
[f679cf0] | 3464 | strcpy(tbfuncionesServer[cf].nf, "InclusionClienteWinLnx"); |
---|
| 3465 | tbfuncionesServer[cf++].fptr = &InclusionClienteWinLnx; |
---|
| 3466 | |
---|
[3ec149c] | 3467 | strcpy(tbfuncionesServer[cf].nf, "AutoexecCliente"); |
---|
| 3468 | tbfuncionesServer[cf++].fptr = &AutoexecCliente; |
---|
| 3469 | |
---|
| 3470 | strcpy(tbfuncionesServer[cf].nf, "ComandosPendientes"); |
---|
| 3471 | tbfuncionesServer[cf++].fptr = &ComandosPendientes; |
---|
| 3472 | |
---|
| 3473 | strcpy(tbfuncionesServer[cf].nf, "DisponibilidadComandos"); |
---|
| 3474 | tbfuncionesServer[cf++].fptr = &DisponibilidadComandos; |
---|
| 3475 | |
---|
| 3476 | strcpy(tbfuncionesServer[cf].nf, "Arrancar"); |
---|
| 3477 | tbfuncionesServer[cf++].fptr = &Arrancar; |
---|
| 3478 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_Arrancar"); |
---|
| 3479 | tbfuncionesServer[cf++].fptr = &RESPUESTA_Arrancar; |
---|
| 3480 | |
---|
| 3481 | strcpy(tbfuncionesServer[cf].nf, "Apagar"); |
---|
| 3482 | tbfuncionesServer[cf++].fptr = &Apagar; |
---|
| 3483 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_Apagar"); |
---|
| 3484 | tbfuncionesServer[cf++].fptr = &RESPUESTA_Apagar; |
---|
| 3485 | |
---|
| 3486 | strcpy(tbfuncionesServer[cf].nf, "Reiniciar"); |
---|
| 3487 | tbfuncionesServer[cf++].fptr = &Reiniciar; |
---|
| 3488 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_Reiniciar"); |
---|
| 3489 | tbfuncionesServer[cf++].fptr = &RESPUESTA_Reiniciar; |
---|
| 3490 | |
---|
| 3491 | strcpy(tbfuncionesServer[cf].nf, "IniciarSesion"); |
---|
| 3492 | tbfuncionesServer[cf++].fptr = &IniciarSesion; |
---|
| 3493 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_IniciarSesion"); |
---|
| 3494 | tbfuncionesServer[cf++].fptr = &RESPUESTA_IniciarSesion; |
---|
| 3495 | |
---|
| 3496 | strcpy(tbfuncionesServer[cf].nf, "CrearImagen"); |
---|
| 3497 | tbfuncionesServer[cf++].fptr = &CrearImagen; |
---|
| 3498 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_CrearImagen"); |
---|
| 3499 | tbfuncionesServer[cf++].fptr = &RESPUESTA_CrearImagen; |
---|
| 3500 | |
---|
[0a73ecf7] | 3501 | strcpy(tbfuncionesServer[cf].nf, "CrearImagenBasica"); |
---|
| 3502 | tbfuncionesServer[cf++].fptr = &CrearImagenBasica; |
---|
| 3503 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_CrearImagenBasica"); |
---|
| 3504 | tbfuncionesServer[cf++].fptr = &RESPUESTA_CrearImagenBasica; |
---|
| 3505 | |
---|
| 3506 | strcpy(tbfuncionesServer[cf].nf, "CrearSoftIncremental"); |
---|
| 3507 | tbfuncionesServer[cf++].fptr = &CrearSoftIncremental; |
---|
| 3508 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_CrearSoftIncremental"); |
---|
| 3509 | tbfuncionesServer[cf++].fptr = &RESPUESTA_CrearSoftIncremental; |
---|
| 3510 | |
---|
[3ec149c] | 3511 | strcpy(tbfuncionesServer[cf].nf, "RestaurarImagen"); |
---|
| 3512 | tbfuncionesServer[cf++].fptr = &RestaurarImagen; |
---|
| 3513 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_RestaurarImagen"); |
---|
| 3514 | tbfuncionesServer[cf++].fptr = &RESPUESTA_RestaurarImagen; |
---|
| 3515 | |
---|
[0a73ecf7] | 3516 | strcpy(tbfuncionesServer[cf].nf, "RestaurarImagenBasica"); |
---|
| 3517 | tbfuncionesServer[cf++].fptr = &RestaurarImagenBasica; |
---|
| 3518 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_RestaurarImagenBasica"); |
---|
| 3519 | tbfuncionesServer[cf++].fptr = &RESPUESTA_RestaurarImagenBasica; |
---|
| 3520 | |
---|
| 3521 | strcpy(tbfuncionesServer[cf].nf, "RestaurarSoftIncremental"); |
---|
| 3522 | tbfuncionesServer[cf++].fptr = &RestaurarSoftIncremental; |
---|
| 3523 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_RestaurarSoftIncremental"); |
---|
| 3524 | tbfuncionesServer[cf++].fptr = &RESPUESTA_RestaurarSoftIncremental; |
---|
| 3525 | |
---|
[3ec149c] | 3526 | strcpy(tbfuncionesServer[cf].nf, "Configurar"); |
---|
| 3527 | tbfuncionesServer[cf++].fptr = &Configurar; |
---|
| 3528 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_Configurar"); |
---|
| 3529 | tbfuncionesServer[cf++].fptr = &RESPUESTA_Configurar; |
---|
| 3530 | |
---|
| 3531 | strcpy(tbfuncionesServer[cf].nf, "EjecutarScript"); |
---|
| 3532 | tbfuncionesServer[cf++].fptr = &EjecutarScript; |
---|
| 3533 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_EjecutarScript"); |
---|
| 3534 | tbfuncionesServer[cf++].fptr = &RESPUESTA_EjecutarScript; |
---|
| 3535 | |
---|
| 3536 | strcpy(tbfuncionesServer[cf].nf, "InventarioHardware"); |
---|
| 3537 | tbfuncionesServer[cf++].fptr = &InventarioHardware; |
---|
| 3538 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_InventarioHardware"); |
---|
| 3539 | tbfuncionesServer[cf++].fptr = &RESPUESTA_InventarioHardware; |
---|
| 3540 | |
---|
| 3541 | strcpy(tbfuncionesServer[cf].nf, "InventarioSoftware"); |
---|
| 3542 | tbfuncionesServer[cf++].fptr = &InventarioSoftware; |
---|
| 3543 | strcpy(tbfuncionesServer[cf].nf, "RESPUESTA_InventarioSoftware"); |
---|
| 3544 | tbfuncionesServer[cf++].fptr = &RESPUESTA_InventarioSoftware; |
---|
| 3545 | |
---|
| 3546 | strcpy(tbfuncionesServer[cf].nf, "enviaArchivo"); |
---|
| 3547 | tbfuncionesServer[cf++].fptr = &enviaArchivo; |
---|
| 3548 | |
---|
| 3549 | strcpy(tbfuncionesServer[cf].nf, "recibeArchivo"); |
---|
| 3550 | tbfuncionesServer[cf++].fptr = &recibeArchivo; |
---|
| 3551 | |
---|
| 3552 | strcpy(tbfuncionesServer[cf].nf, "envioProgramacion"); |
---|
| 3553 | tbfuncionesServer[cf++].fptr = &envioProgramacion; |
---|
| 3554 | |
---|
| 3555 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3556 | // Inicializa array de información de los clientes |
---|
| 3557 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3558 | for (i = 0; i < MAXIMOS_CLIENTES; i++) { |
---|
| 3559 | tbsockets[i].ip[0] = '\0'; |
---|
| 3560 | tbsockets[i].sock = INVALID_SOCKET; |
---|
| 3561 | } |
---|
| 3562 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3563 | Creación y configuración del socket del servicio |
---|
| 3564 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3565 | socket_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Crea socket del servicio |
---|
| 3566 | if (socket_s == SOCKET_ERROR) { // Error al crear el socket del servicio |
---|
| 3567 | errorLog(modulo, 13, TRUE); |
---|
| 3568 | exit(EXIT_FAILURE); |
---|
| 3569 | } |
---|
| 3570 | |
---|
| 3571 | local.sin_addr.s_addr = htonl(INADDR_ANY); // Configura el socket del servicio |
---|
| 3572 | local.sin_family = AF_INET; |
---|
| 3573 | local.sin_port = htons(atoi(puerto)); |
---|
| 3574 | |
---|
| 3575 | if (bind(socket_s, (struct sockaddr *) &local, sizeof(local)) |
---|
| 3576 | == SOCKET_ERROR) { // Enlaza socket |
---|
| 3577 | errorLog(modulo, 14, TRUE); |
---|
| 3578 | exit(EXIT_FAILURE); |
---|
| 3579 | } |
---|
| 3580 | |
---|
| 3581 | listen(socket_s, 250); // Pone a escuchar al socket |
---|
| 3582 | iAddrSize = sizeof(cliente); |
---|
| 3583 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3584 | Bucle para acceptar conexiones |
---|
| 3585 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3586 | infoLog(1); // Inicio de sesión |
---|
| 3587 | while (TRUE) { |
---|
| 3588 | socket_c = accept(socket_s, (struct sockaddr *) &cliente, &iAddrSize); |
---|
| 3589 | if (socket_c == INVALID_SOCKET) { |
---|
| 3590 | errorLog(modulo, 15, TRUE); |
---|
| 3591 | exit(EXIT_FAILURE); |
---|
| 3592 | } |
---|
| 3593 | swcSocket = FALSE; // Por defecto se cerrara el socket de cliente después del anális de la trama |
---|
| 3594 | if (!gestionaTrama(&socket_c)) { |
---|
| 3595 | errorLog(modulo, 39, TRUE); |
---|
[0a73ecf7] | 3596 | //close(socket_c);/tmp/ |
---|
[3ec149c] | 3597 | //break; |
---|
| 3598 | } |
---|
| 3599 | if (!swcSocket) // Sólo se cierra cuando el cliente NO espera comandos ineractivos |
---|
| 3600 | close(socket_c); |
---|
| 3601 | } |
---|
| 3602 | /*-------------------------------------------------------------------------------------------------------- |
---|
| 3603 | Fin del servicio |
---|
| 3604 | ---------------------------------------------------------------------------------------------------------*/ |
---|
| 3605 | close(socket_s); |
---|
| 3606 | exit(EXIT_SUCCESS); |
---|
| 3607 | } |
---|