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 "encriptacion.h" |
---|
24 | |
---|
25 | #define LONGITUD_PARAMETROS 4048 // Longitud m?ima de la informacin de la trama (parametros) |
---|
26 | #define LONGITUD_TRAMA LONGITUD_PARAMETROS+8 // Longitud m?ima de la trama completa |
---|
27 | |
---|
28 | #define MAXIMOS_CLIENTES 4000 // M?imo numero de clientes rembo controlados por el servidor rembo |
---|
29 | #define MAXCNX 5 // Mximos intentos de conexin al servidor HIDRA |
---|
30 | #define PUERTO_WAKEUP 9 // Puerto por defecto del wake up |
---|
31 | |
---|
32 | #define PUERTOMINUSER 20000 |
---|
33 | #define PUERTOMAXUSER 60000 |
---|
34 | |
---|
35 | #define LEER 0 |
---|
36 | #define ESCRIBIR 1 |
---|
37 | |
---|
38 | #define TRUE 1 |
---|
39 | #define FALSE 0 |
---|
40 | |
---|
41 | #define true 1 |
---|
42 | #define false 0 |
---|
43 | |
---|
44 | #define SOCKET_ERROR (-1) |
---|
45 | #define INVALID_SOCKET (SOCKET)(~0) |
---|
46 | |
---|
47 | typedef unsigned long DWORD; |
---|
48 | typedef unsigned short WORD; |
---|
49 | typedef int BOOL; |
---|
50 | typedef char BYTE; |
---|
51 | typedef int SOCKET; |
---|
52 | typedef void* LPVOID; |
---|
53 | |
---|
54 | typedef struct{ // EstructUra de la trama recibida |
---|
55 | char arroba; // cabecera de la trama |
---|
56 | char identificador[9]; // identificador de la trama |
---|
57 | char ejecutor; // ejecutor de la trama 1=el servidor rembo 2=el cliente rembo |
---|
58 | char parametros[LONGITUD_PARAMETROS]; // Contenido de la trama (par?etros) |
---|
59 | }TRAMA; |
---|
60 | |
---|
61 | // Estructura para trabajar en cada hebra con el cliente en cuestion |
---|
62 | struct TramaRepos{ |
---|
63 | SOCKET sck; |
---|
64 | struct sockaddr_in cliente; |
---|
65 | socklen_t sockaddrsize; |
---|
66 | TRAMA trama; |
---|
67 | }; |
---|
68 | char szPathFileCfg[128],szPathFileLog[128]; |
---|
69 | FILE *FLog,*Fconfig; |
---|
70 | SOCKET sClient; |
---|
71 | |
---|
72 | char IPlocal[20]; // Ip local |
---|
73 | char servidorhidra[20]; // IP servidor HIDRA |
---|
74 | char Puerto[20]; // Puerto Unicode |
---|
75 | int puerto; // Puerto |
---|
76 | |
---|
77 | char filecmdshell[250]; |
---|
78 | char cmdshell[512]; |
---|
79 | |
---|
80 | char msglog[250]; |
---|
81 | |
---|
82 | char usuario[20]; |
---|
83 | char pasguor[20]; |
---|
84 | char datasource[20]; |
---|
85 | char catalog[50]; |
---|
86 | int puertorepo; // Puerto |
---|
87 | |
---|
88 | //______________________________________________________ |
---|
89 | static pthread_mutex_t guardia; // Controla acceso exclusivo de hebras |
---|
90 | //______________________________________________________ |
---|
91 | |
---|
92 | char PathHidra[250]; // path al directorio base de Hidra |
---|
93 | char PathPXE[250]; // path al directorio PXE |
---|
94 | |
---|
95 | char PathComandos[250]; // path al directorio donde se depositan los comandos para los clientes |
---|
96 | char PathUsuarios[250]; // path al directorio donde se depositan los ficheros de login de los operadores |
---|
97 | char PathIconos[250]; // path al directorio donde se depositan los iconos de los items de los mens |
---|
98 | |
---|
99 | // Prototipos de funciones |
---|
100 | void RegistraLog(const char *,int ); |
---|
101 | int split_parametros(char **,char *, char * ); |
---|
102 | int TomaConfiguracion(char* ); |
---|
103 | void INTROaFINCAD(char* ); |
---|
104 | void FINCADaINTRO(char*,char*); |
---|
105 | char * toma_parametro(const char* ,char *); |
---|
106 | int ClienteExistente(TramaRepos *); |
---|
107 | LPVOID GestionaServicioRepositorio(LPVOID); |
---|
108 | int Actualizar(TramaRepos*); |
---|
109 | int Arrancar(TramaRepos *); |
---|
110 | int Wake_Up(SOCKET,char *); |
---|
111 | void PasaHexBin( char *,char *); |
---|
112 | int levanta(char *); |
---|
113 | int FicheroOperador(TramaRepos *); |
---|
114 | int IconoItem(TramaRepos *); |
---|
115 | |
---|
116 | bool ExisteFichero(TramaRepos *); |
---|
117 | bool EliminaFichero(TramaRepos *); |
---|
118 | bool LeeFicheroTexto(TramaRepos *); |
---|
119 | int gestiona_comando(TramaRepos *); |
---|
120 | bool respuesta_peticion(TramaRepos *,const char*,char*,char*); |
---|
121 | SOCKET Abre_conexion(char *,int); |
---|
122 | int envia_tramas(SOCKET,TRAMA *); |
---|
123 | int recibe_tramas(SOCKET ,TRAMA *); |
---|
124 | int inclusion_REPO(); |
---|
125 | int RESPUESTA_inclusionREPO(TRAMA *); |
---|
126 | int TomaRestoConfiguracion(TRAMA *); |
---|
127 | int RegistraComando(TramaRepos *); |
---|
128 | int Apagar(TramaRepos *); |
---|
129 | char * Buffer(int ); |
---|
130 | int TomaPuertoLibre(int *); |
---|
131 | void NwGestionaServicioRepositorio(TramaRepos *); |
---|