[85179ef] | 1 | //**************************************************************************************************************************************************** |
---|
| 2 | // Aplicación OpenGNSys |
---|
| 3 | // Autor: José Manuel Alonso. |
---|
| 4 | // Licencia: Open Source |
---|
| 5 | // Fichero: ogAdmServer.cpp |
---|
| 6 | // Descripción: |
---|
| 7 | // Este módulo de la aplicación OpenGNSys implementa las comunicaciones con el Repositorio. |
---|
| 8 | // **************************************************************************************************************************************************** |
---|
[b609c63] | 9 | #include <sys/types.h> |
---|
| 10 | #include <sys/socket.h> |
---|
| 11 | #include <arpa/inet.h> |
---|
| 12 | #include <stdio.h> |
---|
| 13 | #include <stdlib.h> |
---|
| 14 | #include <string.h> |
---|
| 15 | #include <errno.h> |
---|
| 16 | #include <unistd.h> |
---|
| 17 | #include <ctype.h> |
---|
| 18 | #include <time.h> |
---|
| 19 | #include </usr/include/mysql/mysql.h> |
---|
| 20 | #include <pthread.h> |
---|
| 21 | #include <signal.h> |
---|
| 22 | #include "Database.h" |
---|
[08b717f5] | 23 | #include "ogAdmLib.h" |
---|
[b609c63] | 24 | |
---|
[90f061f6] | 25 | |
---|
[08b717f5] | 26 | #define MAXIMOS_CLIENTES 4000 // Máximo número de clientes rembo controlados por el servidor rembo |
---|
[90f061f6] | 27 | #define MAXIMAS_MULSESIONES 1000 // Máximo numero de sesiones multicast activas simultaneamente |
---|
[277d0cd] | 28 | #define PUERTO_WAKEUP 9 // Puerto por defecto del wake up |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | typedef void* LPVOID; |
---|
| 33 | |
---|
| 34 | |
---|
[08b717f5] | 35 | |
---|
| 36 | // Estructura para trabajar en cada hebra con el cliente en cuestión |
---|
[277d0cd] | 37 | struct TramaRepos{ |
---|
| 38 | SOCKET sck; |
---|
| 39 | struct sockaddr_in cliente; |
---|
| 40 | socklen_t sockaddrsize; |
---|
| 41 | TRAMA trama; |
---|
| 42 | }; |
---|
[08b717f5] | 43 | |
---|
[277d0cd] | 44 | FILE *FLog,*Fconfig; |
---|
[b609c63] | 45 | SOCKET sClient; |
---|
| 46 | |
---|
| 47 | char IPlocal[20]; // Ip local |
---|
| 48 | char servidorhidra[20]; // IP servidor HIDRA |
---|
| 49 | char Puerto[20]; // Puerto Unicode |
---|
| 50 | int puerto; // Puerto |
---|
[90f061f6] | 51 | char reposcripts[512]; // Path al directorio donde están los scripts |
---|
[b609c63] | 52 | |
---|
| 53 | char filecmdshell[250]; |
---|
| 54 | char cmdshell[512]; |
---|
| 55 | |
---|
| 56 | char msglog[250]; |
---|
| 57 | |
---|
| 58 | char usuario[20]; |
---|
| 59 | char pasguor[20]; |
---|
| 60 | char datasource[20]; |
---|
| 61 | char catalog[50]; |
---|
| 62 | int puertorepo; // Puerto |
---|
| 63 | |
---|
[90f061f6] | 64 | struct s_inisesionMulticast{ // Estructura usada para guardar información sesiones multicast |
---|
| 65 | char ides[32]; // Identificador sesión multicast |
---|
| 66 | char *ipes; // Ipes de los clientes necesarios para la sesión |
---|
| 67 | }; |
---|
| 68 | struct s_inisesionMulticast tbsmul[MAXIMAS_MULSESIONES]; |
---|
[b609c63] | 69 | //______________________________________________________ |
---|
| 70 | static pthread_mutex_t guardia; // Controla acceso exclusivo de hebras |
---|
| 71 | //______________________________________________________ |
---|
| 72 | |
---|
[df5bd24] | 73 | char PathHidra[250]; // path al directorio base de Hidra |
---|
| 74 | char PathPXE[250]; // path al directorio PXE |
---|
| 75 | |
---|
| 76 | char PathComandos[250]; // path al directorio donde se depositan los comandos para los clientes |
---|
| 77 | char PathUsuarios[250]; // path al directorio donde se depositan los ficheros de login de los operadores |
---|
[08b717f5] | 78 | char PathIconos[250]; // path al directorio donde se depositan los iconos de los items de los menús |
---|
[b609c63] | 79 | |
---|
| 80 | // Prototipos de funciones |
---|
[08b717f5] | 81 | |
---|
| 82 | |
---|
[b609c63] | 83 | int TomaConfiguracion(char* ); |
---|
[08b717f5] | 84 | |
---|
| 85 | |
---|
[b609c63] | 86 | int ClienteExistente(TramaRepos *); |
---|
| 87 | LPVOID GestionaServicioRepositorio(LPVOID); |
---|
| 88 | int Actualizar(TramaRepos*); |
---|
| 89 | int Arrancar(TramaRepos *); |
---|
| 90 | int Wake_Up(SOCKET,char *); |
---|
| 91 | void PasaHexBin( char *,char *); |
---|
| 92 | int levanta(char *); |
---|
| 93 | int FicheroOperador(TramaRepos *); |
---|
| 94 | int IconoItem(TramaRepos *); |
---|
| 95 | |
---|
[08b717f5] | 96 | BOOLEAN ExisteFichero(TramaRepos *); |
---|
| 97 | BOOLEAN EliminaFichero(TramaRepos *); |
---|
| 98 | BOOLEAN LeeFicheroTexto(TramaRepos *); |
---|
| 99 | BOOLEAN mandaFichero(TramaRepos *); |
---|
[b609c63] | 100 | int gestiona_comando(TramaRepos *); |
---|
[08b717f5] | 101 | BOOLEAN respuesta_peticion(TramaRepos *,const char*,char*,char*); |
---|
| 102 | |
---|
[b609c63] | 103 | int envia_tramas(SOCKET,TRAMA *); |
---|
| 104 | int recibe_tramas(SOCKET ,TRAMA *); |
---|
| 105 | int inclusion_REPO(); |
---|
| 106 | int RESPUESTA_inclusionREPO(TRAMA *); |
---|
| 107 | int TomaRestoConfiguracion(TRAMA *); |
---|
| 108 | int RegistraComando(TramaRepos *); |
---|
| 109 | int Apagar(TramaRepos *); |
---|
| 110 | char * Buffer(int ); |
---|
| 111 | int TomaPuertoLibre(int *); |
---|
| 112 | void NwGestionaServicioRepositorio(TramaRepos *); |
---|
[08b717f5] | 113 | BOOLEAN sesionMulticast(TramaRepos *); |
---|
| 114 | BOOLEAN iniSesionMulticast(char *,char *,char *); |
---|
[90f061f6] | 115 | int hay_hueco(int *idx); |
---|
[08b717f5] | 116 | |
---|
| 117 | |
---|