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