[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" |
---|
[277d0cd] | 23 | #include "encriptacion.h" |
---|
[b609c63] | 24 | |
---|
[277d0cd] | 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; |
---|
[b609c63] | 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[1024]; // path al directorio base de Hidra |
---|
| 93 | char PathComandos[1024]; // path al directorio donde se depositan los comandos para los clientes |
---|
| 94 | char PathUsuarios[1024]; // path al directorio donde se depositan los ficheros de login de los operadores |
---|
| 95 | char PathIconos[1024]; // path al directorio donde se depositan los iconos de los items de los mens |
---|
| 96 | |
---|
| 97 | // Prototipos de funciones |
---|
[277d0cd] | 98 | void RegistraLog(const char *,int ); |
---|
[b609c63] | 99 | int split_parametros(char **,char *, char * ); |
---|
| 100 | int TomaConfiguracion(char* ); |
---|
[277d0cd] | 101 | void INTROaFINCAD(char* ); |
---|
| 102 | void FINCADaINTRO(char*,char*); |
---|
[d27f22b] | 103 | char * toma_parametro(const char* ,char *); |
---|
[b609c63] | 104 | int ClienteExistente(TramaRepos *); |
---|
| 105 | LPVOID GestionaServicioRepositorio(LPVOID); |
---|
| 106 | int Actualizar(TramaRepos*); |
---|
| 107 | int Arrancar(TramaRepos *); |
---|
| 108 | int Wake_Up(SOCKET,char *); |
---|
| 109 | void PasaHexBin( char *,char *); |
---|
| 110 | int levanta(char *); |
---|
| 111 | int FicheroOperador(TramaRepos *); |
---|
| 112 | int IconoItem(TramaRepos *); |
---|
| 113 | |
---|
| 114 | bool ExisteFichero(TramaRepos *); |
---|
| 115 | bool EliminaFichero(TramaRepos *); |
---|
| 116 | bool LeeFicheroTexto(TramaRepos *); |
---|
| 117 | int gestiona_comando(TramaRepos *); |
---|
[277d0cd] | 118 | bool respuesta_peticion(TramaRepos *,const char*,char*,char*); |
---|
[b609c63] | 119 | SOCKET Abre_conexion(char *,int); |
---|
| 120 | int envia_tramas(SOCKET,TRAMA *); |
---|
| 121 | int recibe_tramas(SOCKET ,TRAMA *); |
---|
| 122 | int inclusion_REPO(); |
---|
| 123 | int RESPUESTA_inclusionREPO(TRAMA *); |
---|
| 124 | int TomaRestoConfiguracion(TRAMA *); |
---|
| 125 | int RegistraComando(TramaRepos *); |
---|
| 126 | int Apagar(TramaRepos *); |
---|
| 127 | char * Buffer(int ); |
---|
| 128 | int TomaPuertoLibre(int *); |
---|
| 129 | void NwGestionaServicioRepositorio(TramaRepos *); |
---|