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 | // **************************************************************************************************************************************************** |
---|
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" |
---|
23 | #include "ogAdmLib.h" |
---|
24 | |
---|
25 | |
---|
26 | #define MAXIMOS_CLIENTES 4000 // Máximo número de clientes rembo controlados por el servidor rembo |
---|
27 | #define MAXIMAS_MULSESIONES 1000 // Máximo numero de sesiones multicast activas simultaneamente |
---|
28 | #define PUERTO_WAKEUP 9 // Puerto por defecto del wake up |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | typedef void* LPVOID; |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | // Estructura para trabajar en cada hebra con el cliente en cuestión |
---|
37 | struct TramaRepos{ |
---|
38 | SOCKET sck; |
---|
39 | struct sockaddr_in cliente; |
---|
40 | socklen_t sockaddrsize; |
---|
41 | TRAMA trama; |
---|
42 | }; |
---|
43 | |
---|
44 | FILE *FLog,*Fconfig; |
---|
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 |
---|
51 | char reposcripts[512]; // Path al directorio donde están los scripts |
---|
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 | |
---|
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]; |
---|
69 | //______________________________________________________ |
---|
70 | static pthread_mutex_t guardia; // Controla acceso exclusivo de hebras |
---|
71 | //______________________________________________________ |
---|
72 | |
---|
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 |
---|
78 | char PathIconos[250]; // path al directorio donde se depositan los iconos de los items de los menús |
---|
79 | |
---|
80 | // Prototipos de funciones |
---|
81 | |
---|
82 | |
---|
83 | int TomaConfiguracion(char* ); |
---|
84 | |
---|
85 | |
---|
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 | |
---|
96 | BOOLEAN ExisteFichero(TramaRepos *); |
---|
97 | BOOLEAN EliminaFichero(TramaRepos *); |
---|
98 | BOOLEAN LeeFicheroTexto(TramaRepos *); |
---|
99 | BOOLEAN mandaFichero(TramaRepos *); |
---|
100 | int gestiona_comando(TramaRepos *); |
---|
101 | BOOLEAN respuesta_peticion(TramaRepos *,const char*,char*,char*); |
---|
102 | |
---|
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 *); |
---|
113 | BOOLEAN sesionMulticast(TramaRepos *); |
---|
114 | BOOLEAN iniSesionMulticast(char *,char *,char *); |
---|
115 | int hay_hueco(int *idx); |
---|
116 | |
---|
117 | |
---|