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